Creating iptables filter rules applicable to both FORWARD and OUTPUT chains

Hi all,

I have a script which permits users to access to a large list of IP ranges. Before, access to these ranges was granted by using a shell script to perform the necessary FORWARD chain command to allow traffic coming from the br0 interface and exiting the WAN interface, since br0 was the only interface which would access these ranges.

iptables -I FORWARD 6 -i br0 -d $CIDR -o $WAN_IFACE -j ACCEPT

However I have now implemented a caching proxy on the local gateway, and so I need to permit access to the IP ranges on the OUTPUT chain.

iptables -I OUTPUT 8 -d $CIDR -o $WAN_IFACE -j ACCEPT

However, the proxy will not always be running, in which case, the standard FORWARD command will still be needed. The problem I have is that by having several thousand ranges to add, having both these commands run for each range effectively doubles the time taken for the script to run. I was wondering if it is possible to combine these 2 commands in some way to allow both FORWARD and OUTPUT access to the IP ranges in only 1 command? Or am I stuck having to do both commands every single time?

Thanks in advance for any help.