Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 May 2011 14:40:21 +0000 (UTC)
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r222527 - head/sbin/ifconfig
Message-ID:  <201105311440.p4VEeL5u027792@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bz
Date: Tue May 31 14:40:21 2011
New Revision: 222527
URL: http://svn.freebsd.org/changeset/base/222527

Log:
  Conditionally compile in the af_inet and af_inet6, af_nd6 modules.
  If compiled in for dual-stack use, test with feature_present(3)
  to see if we should register the IPv4/IPv6 address family related
  options.
  
  In case there is no "inet" support we would love to go with the
  usage() and make the address family mandatory (as it is for anything
  but inet in theory).  Unfortunately people are used to
    ifconfig IF up/down
  etc. as well, so use a fallback of "link".  Adjust the man page
  to reflect these minor details.
  
  Improve error handling printing a warning in addition to the usage
  telling that we do not know the given address family in two places.
  
  Reviewed by:	hrs, rwatson
  Sponsored by:	The FreeBSD Foundation
  Sponsored by:	iXsystems
  MFC after:	2 weeks

Modified:
  head/sbin/ifconfig/Makefile
  head/sbin/ifconfig/af_inet.c
  head/sbin/ifconfig/af_inet6.c
  head/sbin/ifconfig/af_nd6.c
  head/sbin/ifconfig/ifconfig.8
  head/sbin/ifconfig/ifconfig.c

Modified: head/sbin/ifconfig/Makefile
==============================================================================
--- head/sbin/ifconfig/Makefile	Tue May 31 14:18:10 2011	(r222526)
+++ head/sbin/ifconfig/Makefile	Tue May 31 14:40:21 2011	(r222527)
@@ -15,10 +15,16 @@ SRCS=	ifconfig.c		# base support
 #     of the toolchain.
 #
 SRCS+=	af_link.c		# LLC support
+.if ${MK_INET_SUPPORT} != "no"
 SRCS+=	af_inet.c		# IPv4 support
+.endif
+.if ${MK_INET6_SUPPORT} != "no"
 SRCS+=	af_inet6.c		# IPv6 support
+.endif
 SRCS+=	af_atalk.c		# AppleTalk support
+.if ${MK_INET6_SUPPORT} != "no"
 SRCS+=	af_nd6.c		# ND6 support
+.endif
 
 SRCS+=	ifclone.c		# clone device support
 SRCS+=	ifmac.c			# MAC support
@@ -38,6 +44,12 @@ SRCS+=	ifpfsync.c		# pfsync(4) support
 SRCS+=	ifbridge.c		# bridge support
 SRCS+=	iflagg.c		# lagg support
 
+.if ${MK_INET6_SUPPORT} != "no"
+CFLAGS+= -DINET6
+.endif
+.if ${MK_INET_SUPPORT} != "no"
+CFLAGS+= -DINET
+.endif
 .if ${MK_IPX_SUPPORT} != "no" && !defined(RELEASE_CRUNCH)
 SRCS+=	af_ipx.c		# IPX support
 DPADD+=	${LIBIPX}

Modified: head/sbin/ifconfig/af_inet.c
==============================================================================
--- head/sbin/ifconfig/af_inet.c	Tue May 31 14:18:10 2011	(r222526)
+++ head/sbin/ifconfig/af_inet.c	Tue May 31 14:40:21 2011	(r222527)
@@ -200,5 +200,7 @@ static struct afswtch af_inet = {
 static __constructor void
 inet_ctor(void)
 {
+	if (!feature_present("inet"))
+		return;
 	af_register(&af_inet);
 }

Modified: head/sbin/ifconfig/af_inet6.c
==============================================================================
--- head/sbin/ifconfig/af_inet6.c	Tue May 31 14:18:10 2011	(r222526)
+++ head/sbin/ifconfig/af_inet6.c	Tue May 31 14:40:21 2011	(r222527)
@@ -541,6 +541,9 @@ inet6_ctor(void)
 #define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
+	if (!feature_present("inet6"))
+		return;
+
 	for (i = 0; i < N(inet6_cmds);  i++)
 		cmd_register(&inet6_cmds[i]);
 	af_register(&af_inet6);

Modified: head/sbin/ifconfig/af_nd6.c
==============================================================================
--- head/sbin/ifconfig/af_nd6.c	Tue May 31 14:18:10 2011	(r222526)
+++ head/sbin/ifconfig/af_nd6.c	Tue May 31 14:40:21 2011	(r222527)
@@ -225,5 +225,9 @@ static struct afswtch af_nd6 = {
 static __constructor void
 nd6_ctor(void)
 {
+
+	if (!feature_present("inet6"))
+		return;
+
 	af_register(&af_nd6);
 }

Modified: head/sbin/ifconfig/ifconfig.8
==============================================================================
--- head/sbin/ifconfig/ifconfig.8	Tue May 31 14:18:10 2011	(r222526)
+++ head/sbin/ifconfig/ifconfig.8	Tue May 31 14:40:21 2011	(r222527)
@@ -28,7 +28,7 @@
 .\"     From: @(#)ifconfig.8	8.3 (Berkeley) 1/5/94
 .\" $FreeBSD$
 .\"
-.Dd March 20, 2011
+.Dd May 31, 2011
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -42,7 +42,7 @@
 .Op Fl n
 .Ar interface
 .Op Cm create
-.Op Ar address_family
+.Ar address_family
 .Oo
 .Ar address
 .Op Ar dest_address
@@ -165,8 +165,10 @@ and
 .Dq link .
 .\" and
 .\" .Dq ns .
-The default is
-.Dq inet .
+The default if available is
+.Dq inet
+or otherwise
+.Dq link .
 .Dq ether
 and
 .Dq lladdr

Modified: head/sbin/ifconfig/ifconfig.c
==============================================================================
--- head/sbin/ifconfig/ifconfig.c	Tue May 31 14:18:10 2011	(r222526)
+++ head/sbin/ifconfig/ifconfig.c	Tue May 31 14:40:21 2011	(r222527)
@@ -220,8 +220,10 @@ main(int argc, char *argv[])
 		ifindex = 0;
 		if (argc == 1) {
 			afp = af_getbyname(*argv);
-			if (afp == NULL)
+			if (afp == NULL) {
+				warnx("Address family '%s' unknown.", *argv);
 				usage();
+			}
 			if (afp->af_name != NULL)
 				argc--, argv++;
 			/* leave with afp non-zero */
@@ -484,7 +486,28 @@ ifconfig(int argc, char *const *argv, in
 	int s;
 
 	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
-	afp = uafp != NULL ? uafp : af_getbyname("inet");
+	afp = NULL;
+	if (uafp != NULL)
+		afp = uafp;
+	/*
+	 * This is the historical "accident" allowing users to configure IPv4
+	 * addresses without the "inet" keyword which while a nice feature has
+	 * proven to complicate other things.  We cannot remove this but only
+	 * make sure we will never have a similar implicit default for IPv6 or
+	 * any other address familiy.  We need a fallback though for
+	 * ifconfig IF up/down etc. to work without INET support as people
+	 * never used ifconfig IF link up/down, etc. either.
+	 */
+#ifdef INET
+	if (afp == NULL && feature_present("inet"))
+		afp = af_getbyname("inet");
+#endif
+	if (afp == NULL)
+		afp = af_getbyname("link");
+	if (afp == NULL) {
+		warnx("Please specify an address_family.");
+		usage();
+	}
 top:
 	ifr.ifr_addr.sa_family =
 		afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ?



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