Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Apr 2024 15:39:13 -0700 (PDT)
From:      "Rodney W. Grimes" <freebsd-rwg@gndrsh.dnsmgr.net>
To:        Gregory Shapiro <gshapiro@FreeBSD.org>
Cc:        Paul Vixie <paul@redbarn.org>, freebsd-net@FreeBSD.org
Subject:   Re: Source IPv4 address selection vs BGP IX connection
Message-ID:  <202404252239.43PMdD4f060095@gndrsh.dnsmgr.net>
In-Reply-To: <muipeuskrjbeb6krnprphzpfh5idf2xe4nxzmciocjccgrh2x7@kwv3gunsn5gp>

next in thread | previous in thread | raw e-mail | index | archive | help
> > of course, gethostid(3) is now deprecated in favour of sysctl(3), and the
> > hostid(8) command is gone, and there's now more than one flavour of
> > Internet-capable UNIX in the world, and there's more than one Internet
> > address family now. so what i did in 1990 is a guide only inasmuch as some
> > way should exist to change the default local address of a socket so that it
> > isn't the address of the interface used for the destination. if that happens
> > i hope we coordinate with Linux and with the other BSD's.
> 
> Linux already has a model to give a hint for source address selection via
> route table "hints".  When adding routes (either manually via `ip route'
> or via things like bird2 BGP daemon), Linux supports setting a source IP
> for when that route is used.
> 
> Interestingly, JunOS (which I believe is based on FreeBSD) also supports
> a way to specify a default IPv4 source address, preferring the primary address
> on lo0 that is not 127.0.0.1.

The part of JunOS which is FreeBSD based runs inside a VM on Juniper
routers and is a control plane only thing, what your probably
seing is an artifact of the switch to Linux by Juniper.

> It is a common practice for BGP systems to
> attach their announced IPs to the loopback interface.
These routers are almost always reject type routes and used to
hold the routes 'UP' even if the IGP of an AS flaps them.
This is not done to effect source IP address selection.

> 
> https://www.juniper.net/documentation/us/en/software/junos/cli-reference/topics/ref/statement/default-address-selection-edit-system.html
> 
> For the Linux and bird (BGP) documentation:
> 
> Linux
> -----
> http://linux-ip.net/html/tools-ip-route.html#ex-tools-ip-route-add-src
> 
> "The src option provides a hint to the kernel for source address selection. When you are working with multiple routing tables and different classes of traffic, you can ease your administrative burden, by hosting several different IPs on your linux machine and setting the source address differently, depending on the type of traffic.
> 
> In the example below, let's assume that our masquerading host also runs a DNS resolver for the internal network and we have selected all of the outbound DNS packets to be routed according to table 7 [53]. Now, any packet which originates on this box (or is masqueraded through this table) will have its source IP set to 205.254.211.198.

This is in effect what someone else suggested using multiple route tables in freeBSD and ipfw rules, iirc.

> 
> Example D.19. Using src in a routing command with route add
> 
> [root@masq-gw]# ip route add default via 205.254.211.254 src 205.254.211.198 table 7
> "
> 
> man ip-route
> 
> "src ADDRESS
>       the source address to prefer when sending to the
>       destinations covered by the route prefix."
> 
> 
> Bird (BGP Daemon)
> ----
> "The Kernel protocol defines several attributes. These attributes are translated to appropriate system (and OS-specific) route attributes. We support these attributes:
> ..
> ip krt_prefsrc
> (Linux) The preferred source address. Used in source address selection for outgoing packets. Has to be one of the IP addresses of the router."

This is for the purpose of bird process only and does not effect other processes.  This is mainly used to control the source addressed used for eBGP sessions, though this can fail misserably when you have multiple interfaces speaking eBGP.

Though I can see some merit in what your suggesting to do, I also know that it comes with a many problems as it might solve, like ping would stop working on a local link if the assigned "src IP" is not routable by the entity your trying to ping, which for me would be the case in many places as the IX IP only appears on the IX interface and nothing any place inside or outside my AS has a route to it.  I believe this is the intent of the IX IP policy on use of unrouteable IP addresses.

-- 
Rod Grimes                                                 rgrimes@freebsd.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202404252239.43PMdD4f060095>