svn commit: r197141 - head/usr.sbin/rtsold

Hiroki Sato hrs at FreeBSD.org
Sat Sep 12 22:14:58 UTC 2009


Author: hrs
Date: Sat Sep 12 22:14:58 2009
New Revision: 197141
URL: http://svn.freebsd.org/changeset/base/197141

Log:
  Add support for ND6_IFF_IFDISABLED and ND6_IFF_ACCEPT_RTADV to
  the -F flag.
  
  MFC after:	3 days

Modified:
  head/usr.sbin/rtsold/if.c
  head/usr.sbin/rtsold/rtsold.8
  head/usr.sbin/rtsold/rtsold.c
  head/usr.sbin/rtsold/rtsold.h

Modified: head/usr.sbin/rtsold/if.c
==============================================================================
--- head/usr.sbin/rtsold/if.c	Sat Sep 12 22:14:21 2009	(r197140)
+++ head/usr.sbin/rtsold/if.c	Sat Sep 12 22:14:58 2009	(r197141)
@@ -48,6 +48,7 @@
 #include <netinet/icmp6.h>
 
 #include <netinet6/in6_var.h>
+#include <netinet6/nd6.h>
 
 #include <stdio.h>
 #include <unistd.h>
@@ -78,9 +79,15 @@ int
 interface_up(char *name)
 {
 	struct ifreq ifr;
+	struct in6_ndireq nd;
 	int llflag;
+	int s;
+	int error;
 
+	memset(&ifr, 0, sizeof(ifr));
 	strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+	memset(&nd, 0, sizeof(nd));
+	strlcpy(nd.ifname, name, sizeof(nd.ifname));
 
 	if (ioctl(ifsock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
 		warnmsg(LOG_WARNING, __func__, "ioctl(SIOCGIFFLAGS): %s",
@@ -94,9 +101,56 @@ interface_up(char *name)
 			    "ioctl(SIOCSIFFLAGS): %s", strerror(errno));
 		return(-1);
 	}
+	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+		warnmsg(LOG_WARNING, __func__, "socket(AF_INET6, SOCK_DGRAM): %s",
+		    strerror(errno));
+		return(-1);
+	}
+	if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {
+		warnmsg(LOG_WARNING, __func__, "ioctl(SIOCGIFINFO_IN6): %s",
+		    strerror(errno));
+		close(s);
+		return(-1);
+	}
 
 	warnmsg(LOG_DEBUG, __func__, "checking if %s is ready...", name);
 
+	if (nd.ndi.flags & ND6_IFF_IFDISABLED) {
+		if (Fflag) {
+			nd.ndi.flags &= ~ND6_IFF_IFDISABLED;
+			if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd)) {
+				warnmsg(LOG_WARNING, __func__,
+				    "ioctl(SIOCSIFINFO_IN6): %s",
+		    		    strerror(errno));
+				close(s);
+				return(-1);
+			}
+		} else {
+			warnmsg(LOG_WARNING, __func__,
+			    "%s is disabled.", name);
+			close(s);
+			return(-1);
+		}
+	}
+	if (!(nd.ndi.flags & ND6_IFF_ACCEPT_RTADV)) {
+		if (Fflag) {
+			nd.ndi.flags |= ND6_IFF_ACCEPT_RTADV;
+			if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd)) {
+				warnmsg(LOG_WARNING, __func__,
+				    "ioctl(SIOCSIFINFO_IN6): %s",
+		    		    strerror(errno));
+				close(s);
+				return(-1);
+			}
+		} else {
+			warnmsg(LOG_WARNING, __func__,
+			    "%s does not accept Router Advertisement.", name);
+			close(s);
+			return(-1);
+		}
+	}
+	close(s);
+
 	llflag = get_llflag(name);
 	if (llflag < 0) {
 		warnmsg(LOG_WARNING, __func__,

Modified: head/usr.sbin/rtsold/rtsold.8
==============================================================================
--- head/usr.sbin/rtsold/rtsold.8	Sat Sep 12 22:14:21 2009	(r197140)
+++ head/usr.sbin/rtsold/rtsold.8	Sat Sep 12 22:14:58 2009	(r197141)
@@ -29,7 +29,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 17, 1998
+.Dd September 2, 2009
 .Dt RTSOLD 8
 .Os
 .\"
@@ -186,7 +186,9 @@ if they are incompatible with proper ope
 warning messages will be generated,
 but Router Solicitations will still be sent.
 The settings may be changed manually with
-.Xr sysctl 8 .
+.Xr sysctl 8
+and
+.Xr ifconfig 8 .
 .It Fl m
 Enable mobility support.
 If this option is specified,

Modified: head/usr.sbin/rtsold/rtsold.c
==============================================================================
--- head/usr.sbin/rtsold/rtsold.c	Sat Sep 12 22:14:21 2009	(r197140)
+++ head/usr.sbin/rtsold/rtsold.c	Sat Sep 12 22:14:58 2009	(r197141)
@@ -62,8 +62,8 @@ struct ifinfo *iflist;
 struct timeval tm_max =	{0x7fffffff, 0x7fffffff};
 static int log_upto = 999;
 static int fflag = 0;
-static int Fflag = 0;	/* force setting sysctl parameters */
 
+int Fflag = 0;	/* force setting sysctl parameters */
 int aflag = 0;
 int dflag = 0;
 
@@ -197,12 +197,8 @@ main(int argc, char **argv)
 #endif
 
 	if (Fflag) {
-		setinet6sysctl(IPV6CTL_ACCEPT_RTADV, 1);
 		setinet6sysctl(IPV6CTL_FORWARDING, 0);
 	} else {
-		/* warn if accept_rtadv is down */
-		if (!getinet6sysctl(IPV6CTL_ACCEPT_RTADV))
-			warnx("kernel is configured not to accept RAs");
 		/* warn if forwarding is up */
 		if (getinet6sysctl(IPV6CTL_FORWARDING))
 			warnx("kernel is configured as a router, not a host");

Modified: head/usr.sbin/rtsold/rtsold.h
==============================================================================
--- head/usr.sbin/rtsold/rtsold.h	Sat Sep 12 22:14:21 2009	(r197140)
+++ head/usr.sbin/rtsold/rtsold.h	Sat Sep 12 22:14:58 2009	(r197141)
@@ -67,6 +67,7 @@ struct ifinfo {
 extern struct timeval tm_max;
 extern int dflag;
 extern int aflag;
+extern int Fflag;
 extern char *otherconf_script;
 extern int ifconfig(char *);
 extern void iflist_init(void);


More information about the svn-src-all mailing list