From owner-svn-src-head@FreeBSD.ORG Tue May 31 14:40:22 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 36DAD1065673; Tue, 31 May 2011 14:40:22 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 271818FC1B; Tue, 31 May 2011 14:40:22 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p4VEeMP2027799; Tue, 31 May 2011 14:40:22 GMT (envelope-from bz@svn.freebsd.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p4VEeL5u027792; Tue, 31 May 2011 14:40:21 GMT (envelope-from bz@svn.freebsd.org) Message-Id: <201105311440.p4VEeL5u027792@svn.freebsd.org> From: "Bjoern A. Zeeb" Date: Tue, 31 May 2011 14:40:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222527 - head/sbin/ifconfig X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2011 14:40:22 -0000 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 ?