Subject: ifconfig(8) and netmask setting
To: None <tech-net@netbsd.org>
From: Arnaud LACOMBE <arnaud.lacombe.1@ulaval.ca>
List: tech-net
Date: 01/17/2007 19:40:01
--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

Is it OK to force the user to specify an address when (s)he wants to change
the netmask (or broadcast) of a given interface ?

Currently, if no address is specified, ifconfig(8) silently fails (in
fact... not really as it does nothing :/). On FreeBSD, if no address are
specified, the netmask of the default address is updated.

The attached patch fix bin/10911 and part of bin/31940 by making the
address mandatory when changing netmask/broadcast address (tested for
INET, not INET6 or ISO).

any comments ?

 - Arnaud


--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ifconfig-10911.diff"

Index: ifconfig.c
===================================================================
RCS file: /data/netbsd/cvsroot/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.177
diff -u -r1.177 ifconfig.c
--- ifconfig.c	16 Oct 2006 02:52:43 -0000	1.177
+++ ifconfig.c	17 Jan 2007 23:05:08 -0000
@@ -130,7 +130,7 @@
 u_short	flags;
 int	setaddr, doalias;
 u_long	metric, mtu;
-int	clearaddr, s;
+int	s, clearaddr = 0;
 int	newaddr = -1;
 int	conflicting = 0;
 int	check_up_state = -1;
@@ -861,12 +861,18 @@
 void
 setifnetmask(const char *addr, int d)
 {
+	if (clearaddr == 0 && newaddr == -1 )
+		errx(EXIT_FAILURE, "No address specified");
+
 	(*afp->af_getaddr)(addr, MASK);
 }
 
 void
 setifbroadaddr(const char *addr, int d)
 {
+	if (clearaddr == 0 && newaddr == -1 )
+		errx(EXIT_FAILURE, "No address specified");
+
 	(*afp->af_getaddr)(addr, DSTADDR);
 }
 

--VS++wcV0S1rZb1Fb--