I'm working on an application where we use IPtables and IProute2 to setup a situation (similar to a firewall), where we have setup multiple routing tables and have some rules that direct traffic to different interfaces depending on the port number.

It generally works well, but I've come across a strange situation. The routing tables are sending a packet to interface #2, but the source IP address in the packet is that of interface #1. I suspect that the application is binding to interface #1 and that the source IP is being set before the routing rules get the packet.

Two questions:
1) Is this a likely explanation (why or why not).
2) How can I tell if this is the case (I don't have the source to the app).

I know the rules are working, because if I take out the IPtables line for the port I'm using, the traffic goes out the bond2 port. If I put the rule in, the packet goes out bond1. Either way the packet has a source IP of!

Any info/ideas appreciated,

Here's some config information:
Output from "ip rule list":
0: from all lookup 255
2000: from all fwmark 0x1 lookup 1
32766: from all lookup main
32767: from all lookup default
"iptables -L -n -t mangle":
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
MARK tcp -- tcp spt:21 MARK set 0x1
MARK udp -- udp spt:21 MARK set 0x1
MARK tcp -- tcp spt:22 MARK set 0x1
MARK udp -- udp spt:22 MARK set 0x1
MARK tcp -- tcp spt:23 MARK set 0x1
MARK udp -- udp spt:23 MARK set 0x1
MARK tcp -- tcp spt:162 MARK set 0x1
MARK udp -- udp spt:162 MARK set 0x1
Output from "ip route show table 1": dev bond2 scope link src
default via dev bond2 src

Here's the weird thing. Here's a line from the output of "ip route show cache" from via dev bond2
cache (null) 1500 ssthresh 1460 advmss 64

Note that the "from" address is not the same network as the "via" address.