| Summary: | /sbin/route bug | ||
|---|---|---|---|
| Product: | Base System | Reporter: | dwcjr <dwcjr> |
| Component: | kern | Assignee: | ru <ru> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | Unspecified | ||
| Hardware: | Any | ||
| OS: | Any | ||
Responsible Changed From-To: freebsd-bugs->ru Will look into this next week. On Fri, Jun 22, 2001 at 10:38:56PM -0700, David W. Chapman Jr. wrote: > > I want internet traffic to come from source ip 66.64.12.249 when > using internet from router. > > >How-To-Repeat: > route add default 66.64.6.1 -ifa 66.64.12.249 > >Fix: > temp workaround: > > route add default 66.64.6.1 > route change default -ifa 66.64.12.249 > This isn't a bug in the route(8) command. Kernel routing code (in rtsock.c) checks for -ifa address only when processing the RTM_CHANGE command. Look here (from the route(8) manpage): : In a change or add command where the destination and gateway ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ : are not sufficient to specify the route (as in the ISO case ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ : where several interfaces may have the same address), the -ifp : or -ifa modifiers may be used to determine the interface or : interface address. But I agree that having such a functionality in `route add' would be useful too. The following patch duplicates some code from RTM_CHANGE. Please test. (The `ifp' part should probably be duplicated too.) Index: rtsock.c =================================================================== RCS file: /home/ncvs/src/sys/net/rtsock.c,v retrieving revision 1.44.2.2 diff -u -p -r1.44.2.2 rtsock.c --- rtsock.c 2000/08/03 00:09:34 1.44.2.2 +++ rtsock.c 2001/06/23 11:35:38 @@ -282,7 +282,7 @@ route_output(m, so) struct rt_addrinfo info; int len, error = 0; struct ifnet *ifp = 0; - struct ifaddr *ifa = 0; + struct ifaddr *ifa = 0, *oifa; #define senderr(e) { error = e; goto flush;} if (m == 0 || ((m->m_len < sizeof(long)) && @@ -332,6 +332,18 @@ route_output(m, so) error = rtrequest(RTM_ADD, dst, gate, netmask, rtm->rtm_flags, &saved_nrt); if (error == 0 && saved_nrt) { + if (ifaaddr && (ifa = ifa_ifwithaddr(ifaaddr))) { + oifa = saved_nrt->rt_ifa; + if (oifa != ifa) { + if (oifa && oifa->ifa_rtrequest) + oifa->ifa_rtrequest(RTM_DELETE, + saved_nrt, gate); + IFAFREE(saved_nrt->rt_ifa); + saved_nrt->rt_ifa = ifa; + ifa->ifa_refcnt++; + saved_nrt->rt_ifp = ifa->ifa_ifp; + } + } rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx, &saved_nrt->rt_rmx); saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits); @@ -424,7 +436,7 @@ route_output(m, so) rt_key(rt), gate)))) ifp = ifa->ifa_ifp; if (ifa) { - register struct ifaddr *oifa = rt->rt_ifa; + oifa = rt->rt_ifa; if (oifa != ifa) { if (oifa && oifa->ifa_rtrequest) oifa->ifa_rtrequest(RTM_DELETE, Cheers, -- Ruslan Ermilov Oracle Developer/DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age I must have misplaced my reply. This patch works great! I forget, what is the reason this hasn't been in -current yet? On Sun, Sep 23, 2001 at 01:00:33PM -0500, David W. Chapman Jr. wrote: > I forget, what is the reason this hasn't been in -current yet? > NetBSD has a more generic solution to this problem, which also allows the -ifp to be specified with RTM_ADD. This is very useful in the IPv6 case. This requires some substantial changes to sys/net/rtsock.c, and I haven't yet found the time to do it. Sorry for the delay, but please be patient. Thanks, -- Ruslan Ermilov Oracle Developer/DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age State Changed From-To: open->closed Fixed in 5.0-CURRENT, sys/net/rtsock.c,v 1.61. MFC after 1 month. |
BACKGROUND: 2 nics, one wan and one lan wan has 66.64.6.25/26 to get to default gateway and 66.64.12.249/32 lan has 66.64.12.248/29 and 192.168.0.0/24 I want internet traffic to come from source ip 66.64.12.249 when using internet from router. Fix: temp workaround: route add default 66.64.6.1 route change default -ipa 66.64.12.249 How-To-Repeat: route add default 66.64.6.1 -ifa 66.64.12.249