+# additional iptables chains where sliceip inserts its rules
+NAT_POSTROUTING="sliceip"
+MANGLE_OUTPUT="sliceip_output"
+MANGLE_POSTROUTING="sliceip_postrouting"
+
+# create the chains
+check_chains(){
+ first_time=0
+
+ #create the chain where SNAT is performed
+ if iptables -t nat -N $NAT_POSTROUTING >/dev/null 2>&1; then
+ #it's the first time sliceip is called, the chain was not defined
+ first_time=1
+
+ #create a chain where the netfilter mark is set
+ exec "iptables -t mangle -N $MANGLE_OUTPUT"
+
+ #create a chain where the netfilter mark for some packets is restored (see set_routes)
+ exec "iptables -t mangle -N $MANGLE_POSTROUTING"
+
+ #add the rules to take packets to the previously defined chains
+ exec "iptables -t nat -A POSTROUTING -j $NAT_POSTROUTING"
+ exec "iptables -t mangle -A OUTPUT -j $MANGLE_OUTPUT"
+ exec "iptables -t mangle -I POSTROUTING 1 -j $MANGLE_POSTROUTING"
+
+ #cleaning up
+ clean_iproute_conf
+ fi
+}
+