Subject: Re: Routing by source address
To: None <>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-net
Date: 08/24/2006 19:08:32
> Therefore, I have to tell NetBSD that it should route all packets
> originating from the IP of ISP #1 through the gateway of ISP #1 and
> so on (some kind of routing by source address).

I found myself wanting to do this, so I created something that did it.

It's a pseudo-interface called srt (for Source RouTing).  You point
your route out the srt interface and then use srtconfig to tell the srt
code where to send packets based on their ip_src fields.

Here, for example, is an excerpt from one of my house machines' startup
scripts.  This machine is on the house LAN, where the main
house uplink is managed by; it also has the backup house
netlink on ppp0, where its address is and the other end of
the PPP link is is overlaid with, with the same third octet, and it has another Ethernet on
the house non-routed subnet

srtconfig srt0 set 0 /32 de0
srtconfig srt0 set 1 /32 ppp0
srtconfig srt0 set 2 /32 de0
srtconfig srt0 set 3 /8 ex0
ifconfig srt0 netmask up
route add default

Thus, the packet flow is:

packet emitted
-> default route to
-> sends it out srt0, which ignores the next-hop address (
-> the srt code checks ip_src against, in order  -> send it out de0, addressed to -> send it out ppp0, addressed to    -> send it out de0, addressed to
  10/8           -> send it out ex0, addressed to
  anything else  -> drop it on the floor

Order is important here, because the srt code checks in order.  If I
found myself using it for anything big, I'd probably steal the radix
tree code and give each srt interface its own radix tree, and pick the
most specific route rather than defining it to check them in order.

You probably can't use the code directly, because it's for 1.4T, but
you're welcome to use the idea.  (For that matter you're welcome to use
the code too, if you find any use for it.)

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B