Linux Netfilter discussions
 help / color / mirror / Atom feed
* RE: Fairly complex multi-ISP firewall/router problem
@ 2004-04-02 23:45 Daniel Chemko
  2004-04-03  3:31 ` Bill Davidsen
  0 siblings, 1 reply; 11+ messages in thread
From: Daniel Chemko @ 2004-04-02 23:45 UTC (permalink / raw)
  To: netfilter

Antony Stone wrote:
> On Friday 02 April 2004 10:36 pm, John A. Sullivan III wrote:
> 
>> On Fri, 2004-04-02 at 15:57, Bill Davidsen wrote:
>>> 
>>> All I want to do is send packets out the interface which matches the
>>> source IP, and I don't think there's any reasonable way to get there
>>> without patches or BSD.
>> 
>> Hmmm . . . I admit to not having tried this and only giving it five
>> minute's thought but I'm not sure I see the problem.  Well, I see why
>> one can't be guaranteed to send the packet out the same interface but
>> I'm not sure why that is a problem.
> 
> Some ISPs block packets with source addresses not matching their own
> network range, as a contribution to blocking spoofed packets.

This is a very real issue, especially when they're only consumer grade.

What I've used to fix the problem is to use the CONNMARK extension on
the PREROUTING step of mangle. Here, I can set the appropriate routes
and everything that uses CONNMARK will work fine.

Eg:
IPT_NOMARK="-m mark --mark 0"
IPT_MARKED="-m mark ! --mark 0"

${IPTABLES} -t mangle -A PREROUTING -j CONNMARK --restore-mark
# MARK packets that are inbound from INET3/INET4 to leave the same
interface
# You also get related traffic leaving the related session's route for
free
${IPTABLES} -t mangle -A PREROUTING ${IPT_NOMARK} -i ${IF_INET3} -j MARK
--set-mark ${RTABLE_INET3}
${IPTABLES} -t mangle -A PREROUTING ${IPT_NOMARK} -i ${IF_INET4} -j MARK
--set-mark ${RTABLE_INET4}
${IPTABLES} -t mangle -A PREROUTING -j CONNMARK --save-mark

You can setup something similar for outgoing sessions. I don't do it,
but there's nothing stopping you from it.


>> In the case of an interface or ISP failure, I assume you would
>> disable the interface which would eliminate the route.
> 
> That's not necessarily a difficult task (bringing it back up again
> afterwards is not entirely trivial, however), but if the problem can
> be solved without sending all outbound traffic across a single
> connection, and leaving the other one largely idle, it would be a
> better solution. 

As described above, you can use typical iptables matching to do policy
routing based on any layer supported by iptables.

This example would create equalized load balancing based on NEW sessions
${IPTABLES} -t mangle -A PREROUTING ${IPT_NOMARK} -i ${IF_INTERNAL} -m
nth --every 2 --packet 0 -j MARK --set-mark ${RTABLE_INET3}
${IPTABLES} -t mangle -A PREROUTING ${IPT_NOMARK} -i ${IF_INTERNAL} -m
nth --every 2 --packet 1 -j MARK --set-mark ${RTABLE_INET4}

My RTABLES have all the rules from my main table, with the exception of
the default route. This allows for overly broad iptables connmark rules
without breaking the routing of other interfaces.

This is my routing table builder:

function route_builder
{
   if [ "${OPT_SYS_ROUTER}" = "0" -o "${OPT_ROUTER_POLICYROUTING}" = "0"
]; then
      info "route_builder: Policy Routing is disabled. Skipping."
      return 1
   fi
   _table_id=${1}
   _table_gateway=${2}
   _table_source=${3}
   if [ "${1}" != "" -a "${2}" != "" ]; then
      ${IP} rule del fwmark ${_table_id} table ${_table_id}
      ${IP} rule add fwmark ${_table_id} table ${_table_id}
      ${IP} route flush table ${_table_id}
      ${IP} route show table main | grep -Ev ^default
\
      | while read ROUTE ; do
         ${IP} route add table ${_table_id} $ROUTE
      done
      ${IP} route add table ${_table_id} default via ${_table_gateway}
\
         src ${_table_source}
   else
      info "route_builder: Invalid arguments specified."
   fi
}


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Fairly complex multi-ISP firewall/router problem
@ 2004-04-02 20:57 Bill Davidsen
  2004-04-02 21:06 ` Antony Stone
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Bill Davidsen @ 2004-04-02 20:57 UTC (permalink / raw)
  To: netfilter

I am trying to set up a single Linux router, RH9.0, for a non-profit I 
am supporting with some free consulting. They have two ISP lines, each 
of which has a three bit CIDR block, and an internal network.

Part one:

I want to have an IP for each of the services, mail and http, on each 
ISP, so that is DSL is down I can use cable, and vice-versa. I will do 
NAT in the firewall, and forward the packets to the actual server. 
Eventually the servers will move to a DMZ after the other stuff settles 
down.

The problem is that a packet can come from any IP outside, and when the 
reply packet is sent out, it may go out either NIC. And that's the root 
of the problem, getting the source IP to match the NIC. I've added rules 
to the mangle table to MARK the packets, that just doesn't seem to work 
reliably.

I want very much to do this without patching the kernel, I have two 
patches which seem to solve the problem on other systems, but 
maintaining a patched kernel long term is really undesirable, and makes 
it hard to turn over the job in the future.

All I want to do is send packets out the interface which matches the 
source IP, and I don't think there's any reasonable way to get there 
without patches or BSD.

Yes, I know about the lartc docs, nano.txt and several other things. The 
problem is that the marks don't reliably WORK, routing by destination IP 
is being used in some cases (but not all, which is really odd).

-- 
bill davidsen <davidsen@tmr.com>
   CTO TMR Associates, Inc
   Doing interesting things with small computers since 1979


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-04-13  9:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-02 23:45 Fairly complex multi-ISP firewall/router problem Daniel Chemko
2004-04-03  3:31 ` Bill Davidsen
  -- strict thread matches above, loose matches on Subject: below --
2004-04-02 20:57 Bill Davidsen
2004-04-02 21:06 ` Antony Stone
2004-04-03  3:24   ` Bill Davidsen
2004-04-02 21:32 ` Cedric Blancher
2004-04-02 21:36 ` John A. Sullivan III
2004-04-02 21:50   ` Antony Stone
2004-04-02 22:07     ` Joe Thompson
2004-04-03  3:17       ` Bill Davidsen
2004-04-13  9:29 ` Tarek W.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox