Date: Sat, 23 Jun 2001 14:44:06 +0300 From: Ruslan Ermilov <ru@FreeBSD.org> To: "David W. Chapman Jr." <dwcjr@FreeBSD.org> Cc: bug-followup@FreeBSD.org, net@FreeBSD.org Subject: Re: misc/28360: /sbin/route bug Message-ID: <20010623144406.A43141@sunbay.com> In-Reply-To: <200106230538.f5N5cuH35571@freefall.freebsd.org>; from dwcjr@inethouston.net on Fri, Jun 22, 2001 at 10:38:56PM -0700 References: <200106230538.f5N5cuH35571@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010623144406.A43141>