From b7af10cfe3902b3d9301096c8887e0509a3ac9bc Mon Sep 17 00:00:00 2001 From: ume Date: Thu, 17 Jan 2013 16:39:21 +0000 Subject: [PATCH] MFC r245230: Add no_prefer_iface option. It stops treating the address on the interface as special by source address selection rule even when the interface is outgoing interface. This is desired in some situation. git-svn-id: svn://svn.freebsd.org/base/stable/9@245555 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sbin/ifconfig/af_inet6.c | 2 ++ sbin/ifconfig/af_nd6.c | 2 +- sbin/ifconfig/ifconfig.8 | 9 ++++++++- sys/netinet6/in6_src.c | 10 ++++++---- sys/netinet6/nd6.h | 1 + usr.sbin/ndp/ndp.8 | 11 ++++++++++- usr.sbin/ndp/ndp.c | 7 +++++++ 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index e39c1c8cf..c4591fb05 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -511,6 +511,8 @@ static struct cmd inet6_cmds[] = { DEF_CMD("-prefer_source",-ND6_IFF_PREFER_SOURCE,setnd6flags), DEF_CMD("auto_linklocal",ND6_IFF_AUTO_LINKLOCAL,setnd6flags), DEF_CMD("-auto_linklocal",-ND6_IFF_AUTO_LINKLOCAL,setnd6flags), + DEF_CMD("no_prefer_iface",ND6_IFF_NO_PREFER_IFACE,setnd6flags), + DEF_CMD("-no_prefer_iface",-ND6_IFF_NO_PREFER_IFACE,setnd6flags), DEF_CMD_ARG("pltime", setip6pltime), DEF_CMD_ARG("vltime", setip6vltime), DEF_CMD("eui64", 0, setip6eui64), diff --git a/sbin/ifconfig/af_nd6.c b/sbin/ifconfig/af_nd6.c index 654e2d97f..b50763850 100644 --- a/sbin/ifconfig/af_nd6.c +++ b/sbin/ifconfig/af_nd6.c @@ -58,7 +58,7 @@ static const char rcsid[] = #define MAX_SYSCTL_TRY 5 #define ND6BITS "\020\001PERFORMNUD\002ACCEPT_RTADV\003PREFER_SOURCE" \ "\004IFDISABLED\005DONT_SET_IFROUTE\006AUTO_LINKLOCAL" \ - "\007NO_RADR\020DEFAULTIF" + "\007NO_RADR\010NO_PREFER_IFACE\020DEFAULTIF" static int isnd6defif(int); void setnd6flags(const char *, int, int, const struct afswtch *); diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index 64e3423e5..9f762f109 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -28,7 +28,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD$ .\" -.Dd November 7, 2012 +.Dd January 10, 2013 .Dt IFCONFIG 8 .Os .Sh NAME @@ -722,6 +722,13 @@ source address for outgoing packets. .It Cm -prefer_source Clear a flag .Cm prefer_source . +.It Cm no_prefer_iface +Set a flag to not prefer address on the interface as candidates of the +source address for outgoing packets, even when the interface is +outgoing interface. +.It Cm -no_prefer_iface +Clear a flag +.Cm no_prefer_iface . .El .Pp The following parameters are specific to cloning diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 6dea0b460..593f8bf62 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -383,10 +383,12 @@ in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, */ /* Rule 5: Prefer outgoing interface */ - if (ia_best->ia_ifp == ifp && ia->ia_ifp != ifp) - NEXT(5); - if (ia_best->ia_ifp != ifp && ia->ia_ifp == ifp) - REPLACE(5); + if (!(ND_IFINFO(ifp)->flags & ND6_IFF_NO_PREFER_IFACE)) { + if (ia_best->ia_ifp == ifp && ia->ia_ifp != ifp) + NEXT(5); + if (ia_best->ia_ifp != ifp && ia->ia_ifp == ifp) + REPLACE(5); + } /* * Rule 6: Prefer matching label diff --git a/sys/netinet6/nd6.h b/sys/netinet6/nd6.h index cb64cd910..79e41e38e 100644 --- a/sys/netinet6/nd6.h +++ b/sys/netinet6/nd6.h @@ -86,6 +86,7 @@ struct nd_ifinfo { #define ND6_IFF_DONT_SET_IFROUTE 0x10 #define ND6_IFF_AUTO_LINKLOCAL 0x20 #define ND6_IFF_NO_RADR 0x40 +#define ND6_IFF_NO_PREFER_IFACE 0x80 /* XXX: not related to ND. */ #define ND6_CREATE LLE_CREATE #define ND6_EXCLUSIVE LLE_EXCLUSIVE diff --git a/usr.sbin/ndp/ndp.8 b/usr.sbin/ndp/ndp.8 index 9506171a0..cb3ac2ae4 100644 --- a/usr.sbin/ndp/ndp.8 +++ b/usr.sbin/ndp/ndp.8 @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 2, 2009 +.Dd Jan 10, 2013 .Dt NDP 8 .Os .\" @@ -201,6 +201,15 @@ For more details about the entire algorithm of source address selection, see the .Pa IMPLEMENTATION file supplied with the KAME kit. +.It Ic no_prefer_iface +The address on the outgoing interface is preferred by source addess +selection rule. +If this flag is set, stop treating the address on the +.Ar interface +as special even when the +.Ar interface +is outgoing interface. +The default value of this flag is off. .It Ic disabled Disable IPv6 operation on the interface. When disabled, the interface discards any IPv6 packets diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c index e245ac297..fa087c431 100644 --- a/usr.sbin/ndp/ndp.c +++ b/usr.sbin/ndp/ndp.c @@ -1010,6 +1010,9 @@ ifinfo(ifname, argc, argv) #endif #ifdef ND6_IFF_PREFER_SOURCE SETFLAG("prefer_source", ND6_IFF_PREFER_SOURCE); +#endif +#ifdef ND6_IFF_NO_PREFER_IFACE + SETFLAG("no_prefer_iface", ND6_IFF_NO_PREFER_IFACE); #endif SETVALUE("basereachable", ND.basereachable); SETVALUE("retrans", ND.retrans); @@ -1087,6 +1090,10 @@ ifinfo(ifname, argc, argv) #ifdef ND6_IFF_PREFER_SOURCE if ((ND.flags & ND6_IFF_PREFER_SOURCE)) printf("prefer_source "); +#endif +#ifdef ND6_IFF_NO_PREFER_IFACE + if ((ND.flags & ND6_IFF_NO_PREFER_IFACE)) + printf("no_prefer_iface "); #endif } putc('\n', stdout); -- 2.45.0