Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Aug 2002 21:43:01 +0300
From:      Maxim Sobolev <sobomax@FreeBSD.org>
To:        hackers@FreeBSD.org, net@FreeBSD.org
Subject:   Increasing size of if_flags field in the ifnet structure [patch for  review]
Message-ID:  <3D5BF635.3764C796@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------6E58B69EA83C65AC034DB0DB
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: 7bit

Folks,

When implementing ability to switch interface into promisc mode using
ifconfig(8) I've stumbled into the problem with already exhausted
space in the `short if_flags' field in the ifnet structure. I need to
allocate one new flag, while we already have 16 IFF_* flags, and even
one additional flag which is implemented using currently free
if_ipending field of the said structure. Attached patch is aimed at
increasing size of if_flags to 32 bits, as well as to clean-up
if_ipending abuse. Granted, it will break backward ABI compatibility,
but IMO it is not a big problem.

Comments and suggestions are greatly appreciated. Thanks!

-Maxim
--------------6E58B69EA83C65AC034DB0DB
Content-Type: text/plain; charset=koi8-r;
 name="if_flags.32bit.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="if_flags.32bit.patch"

Index: src/share/man/man4/netintro.4
===================================================================
RCS file: /home/ncvs/src/share/man/man4/netintro.4,v
retrieving revision 1.20
diff -d -u -r1.20 netintro.4
--- src/share/man/man4/netintro.4	18 Mar 2002 12:39:32 -0000	1.20
+++ src/share/man/man4/netintro.4	15 Aug 2002 18:33:42 -0000
@@ -197,7 +197,7 @@
         struct    sockaddr ifru_addr;
         struct    sockaddr ifru_dstaddr;
         struct    sockaddr ifru_broadaddr;
-        short     ifru_flags;
+        int       ifru_flags;
         int       ifru_metric;
         int       ifru_mtu;
         int       ifru_phys;
Index: src/share/man/man9/ifnet.9
===================================================================
RCS file: /home/ncvs/src/share/man/man9/ifnet.9,v
retrieving revision 1.25
diff -d -u -r1.25 ifnet.9
--- src/share/man/man9/ifnet.9	10 Jan 2002 11:57:10 -0000	1.25
+++ src/share/man/man9/ifnet.9	15 Aug 2002 18:33:43 -0000
@@ -284,7 +284,7 @@
 (Set by driver,
 decremented by generic watchdog code.)
 .It Va if_flags
-.Pq Vt short
+.Pq Vt int
 Flags describing operational parameters of this interface (see below).
 (Manipulated by both driver and generic code.)
 .It Va if_capabilities
Index: src/sys/compat/linux/linux_ioctl.c
===================================================================
RCS file: /home/ncvs/src/sys/compat/linux/linux_ioctl.c,v
retrieving revision 1.86
diff -d -u -r1.86 linux_ioctl.c
--- src/sys/compat/linux/linux_ioctl.c	26 Jun 2002 15:53:11 -0000	1.86
+++ src/sys/compat/linux/linux_ioctl.c	15 Aug 2002 18:33:45 -0000
@@ -1963,7 +1963,7 @@
 {
 	l_short flags;
 
-	flags = ifp->if_flags;
+	flags = ifp->if_flags & 0xffff;
 	/* these flags have no Linux equivalent */
 	flags &= ~(IFF_SMART|IFF_OACTIVE|IFF_SIMPLEX|
 	    IFF_LINK0|IFF_LINK1|IFF_LINK2);
Index: src/sys/dev/fxp/if_fxp.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/fxp/if_fxp.c,v
retrieving revision 1.138
diff -d -u -r1.138 if_fxp.c
--- src/sys/dev/fxp/if_fxp.c	9 Aug 2002 01:48:28 -0000	1.138
+++ src/sys/dev/fxp/if_fxp.c	15 Aug 2002 18:33:46 -0000
@@ -1193,7 +1193,7 @@
 #ifdef DEVICE_POLLING
 	struct ifnet *ifp = &sc->sc_if;
 
-	if (ifp->if_ipending & IFF_POLLING)
+	if (ifp->if_flags & IFF_POLLING)
 		return;
 	if (ether_poll_register(fxp_poll, ifp)) {
 		/* disable interrupts */
@@ -1785,7 +1785,7 @@
 	 * ... but only do that if we are not polling. And because (presumably)
 	 * the default is interrupts on, we need to disable them explicitly!
 	 */
-	if ( ifp->if_ipending & IFF_POLLING )
+	if ( ifp->if_flags & IFF_POLLING )
 		CSR_WRITE_1(sc, FXP_CSR_SCB_INTRCNTL, FXP_SCB_INTR_DISABLE);
 	else
 #endif /* DEVICE_POLLING */
Index: src/sys/dev/vx/if_vx.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/vx/if_vx.c,v
retrieving revision 1.36
diff -d -u -r1.36 if_vx.c
--- src/sys/dev/vx/if_vx.c	20 Mar 2002 02:07:47 -0000	1.36
+++ src/sys/dev/vx/if_vx.c	15 Aug 2002 18:33:47 -0000
@@ -285,7 +285,7 @@
     register struct ifnet *ifp = &sc->arpcom.ac_if;  
     int i, j, k;
     char *reason, *warning;
-    static short prev_flags;
+    static int prev_flags;
     static char prev_conn = -1;
 
     if (prev_conn == -1) {
Index: src/sys/kern/kern_poll.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_poll.c,v
retrieving revision 1.9
diff -d -u -r1.9 kern_poll.c
--- src/sys/kern/kern_poll.c	4 Aug 2002 21:00:49 -0000	1.9
+++ src/sys/kern/kern_poll.c	15 Aug 2002 18:33:48 -0000
@@ -383,7 +383,7 @@
 		for (i = 0 ; i < poll_handlers ; i++) {
 			if (pr[i].handler &&
 			    pr[i].ifp->if_flags & IFF_RUNNING) {
-				pr[i].ifp->if_ipending &= ~IFF_POLLING;
+				pr[i].ifp->if_flags &= ~IFF_POLLING;
 				pr[i].handler(pr[i].ifp, POLL_DEREGISTER, 1);
 			}
 			pr[i].handler=NULL;
@@ -415,7 +415,7 @@
 		return 0;
 	if ( !(ifp->if_flags & IFF_UP) )	/* must be up		*/
 		return 0;
-	if (ifp->if_ipending & IFF_POLLING)	/* already polling	*/
+	if (ifp->if_flags & IFF_POLLING)	/* already polling	*/
 		return 0;
 
 	s = splhigh();
@@ -440,7 +440,7 @@
 	pr[poll_handlers].handler = h;
 	pr[poll_handlers].ifp = ifp;
 	poll_handlers++;
-	ifp->if_ipending |= IFF_POLLING;
+	ifp->if_flags |= IFF_POLLING;
 	splx(s);
 	if (idlepoll_sleeping)
 		wakeup(&idlepoll_sleeping);
@@ -459,14 +459,14 @@
 	int i;
 
 	mtx_lock(&Giant);
-	if ( !ifp || !(ifp->if_ipending & IFF_POLLING) ) {
+	if ( !ifp || !(ifp->if_flags & IFF_POLLING) ) {
 		mtx_unlock(&Giant);
 		return 0;
 	}
 	for (i = 0 ; i < poll_handlers ; i++)
 		if (pr[i].ifp == ifp) /* found it */
 			break;
-	ifp->if_ipending &= ~IFF_POLLING; /* found or not... */
+	ifp->if_flags &= ~IFF_POLLING; /* found or not... */
 	if (i == poll_handlers) {
 		mtx_unlock(&Giant);
 		printf("ether_poll_deregister: ifp not found!!!\n");
Index: src/sys/net/if.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if.c,v
retrieving revision 1.144
diff -d -u -r1.144 if.c
--- src/sys/net/if.c	1 Aug 2002 21:15:53 -0000	1.144
+++ src/sys/net/if.c	15 Aug 2002 18:33:48 -0000
@@ -1438,7 +1438,7 @@
 	struct ifnet *ifp;
 	struct ifreq *ifr;
 	int error;
-	short oif_flags;
+	int oif_flags;
 
 	switch (cmd) {
 	case SIOCGIFCONF:
Index: src/sys/net/if.h
===================================================================
RCS file: /home/ncvs/src/sys/net/if.h,v
retrieving revision 1.73
diff -d -u -r1.73 if.h
--- src/sys/net/if.h	25 May 2002 20:17:04 -0000	1.73
+++ src/sys/net/if.h	15 Aug 2002 18:33:49 -0000
@@ -139,14 +139,6 @@
 #define	IFF_LINK2	0x4000		/* per link layer defined bit */
 #define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
 #define	IFF_MULTICAST	0x8000		/* supports multicast */
-
-/*
- * The following flag(s) ought to go in if_flags, but we cannot change
- * struct ifnet because of binary compatibility, so we store them in
- * if_ipending, which is not used so far.
- * If possible, make sure the value is not conflicting with other
- * IFF flags, so we have an easier time when we want to merge them.
- */
 #define	IFF_POLLING	0x10000		/* Interface is in polling mode. */
 
 /* flags set internally only: */
@@ -232,7 +224,7 @@
 		struct	sockaddr ifru_addr;
 		struct	sockaddr ifru_dstaddr;
 		struct	sockaddr ifru_broadaddr;
-		short	ifru_flags[2];
+		int	ifru_flags[2];
 		short	ifru_index;
 		int	ifru_metric;
 		int	ifru_mtu;
Index: src/sys/net/if_tap.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_tap.c,v
retrieving revision 1.19
diff -d -u -r1.19 if_tap.c
--- src/sys/net/if_tap.c	6 May 2002 19:31:28 -0000	1.19
+++ src/sys/net/if_tap.c	15 Aug 2002 18:33:49 -0000
@@ -654,7 +654,7 @@
 	struct ifnet		*ifp = &tp->tap_if;
  	struct tapinfo		*tapp = NULL;
 	int			 s;
-	short			 f;
+	int			 f;
 
 	switch (cmd) {
  		case TAPSIFINFO:
@@ -728,7 +728,7 @@
 			break;
 
 		case VMIO_SIOCSIFFLAGS: /* VMware/VMnet SIOCSIFFLAGS */
-			f = *(short *)data;
+			f = *(int *)data;
 			f &= 0x0fff;
 			f &= ~IFF_CANTCHANGE;
 			f |= IFF_UP;
Index: src/sys/net/if_var.h
===================================================================
RCS file: /home/ncvs/src/sys/net/if_var.h,v
retrieving revision 1.48
diff -d -u -r1.48 if_var.h
--- src/sys/net/if_var.h	14 Aug 2002 01:37:22 -0000	1.48
+++ src/sys/net/if_var.h	15 Aug 2002 18:33:50 -0000
@@ -138,7 +138,7 @@
 	u_short	if_index;		/* numeric abbreviation for this if  */
 	short	if_unit;		/* sub-unit for lower level driver */
 	short	if_timer;		/* time 'til if_watchdog called */
-	short	if_flags;		/* up/down, broadcast, etc. */
+	int	if_flags;		/* up/down, broadcast, etc. */
 	int	if_capabilities;	/* interface capabilities */
 	int	if_capenable;		/* enabled features */
 	int	if_ipending;		/* interrupts pending */
Index: src/sys/net/rtsock.c
===================================================================
RCS file: /home/ncvs/src/sys/net/rtsock.c,v
retrieving revision 1.75
diff -d -u -r1.75 rtsock.c
--- src/sys/net/rtsock.c	18 Jun 2002 07:42:01 -0000	1.75
+++ src/sys/net/rtsock.c	15 Aug 2002 18:33:51 -0000
@@ -757,7 +757,7 @@
 		return;
 	ifm = mtod(m, struct if_msghdr *);
 	ifm->ifm_index = ifp->if_index;
-	ifm->ifm_flags = (u_short)ifp->if_flags;
+	ifm->ifm_flags = ifp->if_flags;
 	ifm->ifm_data = ifp->if_data;
 	ifm->ifm_addrs = 0;
 	route_proto.sp_protocol = 0;
@@ -958,7 +958,7 @@
 
 			ifm = (struct if_msghdr *)w->w_tmem;
 			ifm->ifm_index = ifp->if_index;
-			ifm->ifm_flags = (u_short)ifp->if_flags;
+			ifm->ifm_flags = ifp->if_flags;
 			ifm->ifm_data = ifp->if_data;
 			ifm->ifm_addrs = info.rti_addrs;
 			error = SYSCTL_OUT(w->w_req,(caddr_t)ifm, len);
Index: src/sys/netatm/atm_if.c
===================================================================
RCS file: /home/ncvs/src/sys/netatm/atm_if.c,v
retrieving revision 1.14
diff -d -u -r1.14 atm_if.c
--- src/sys/netatm/atm_if.c	14 Jun 2002 16:59:38 -0000	1.14
+++ src/sys/netatm/atm_if.c	15 Aug 2002 18:33:51 -0000
@@ -1057,7 +1057,7 @@
 		break;
 
 	case SIOCGIFFLAGS:
-		*(short *)data = ifp->if_flags;
+		*(int *)data = ifp->if_flags;
 		break;
 
 	case SIOCSIFFLAGS:
Index: src/sys/netinet6/in6_var.h
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/in6_var.h,v
retrieving revision 1.10
diff -d -u -r1.10 in6_var.h
--- src/sys/netinet6/in6_var.h	19 Apr 2002 04:46:22 -0000	1.10
+++ src/sys/netinet6/in6_var.h	15 Aug 2002 18:33:51 -0000
@@ -234,7 +234,7 @@
 	union {
 		struct	sockaddr_in6 ifru_addr;
 		struct	sockaddr_in6 ifru_dstaddr;
-		short	ifru_flags;
+		int	ifru_flags;
 		int	ifru_flags6;
 		int	ifru_metric;
 		caddr_t	ifru_data;
Index: src/sys/nfsclient/bootp_subr.c
===================================================================
RCS file: /home/ncvs/src/sys/nfsclient/bootp_subr.c,v
retrieving revision 1.41
diff -d -u -r1.41 bootp_subr.c
--- src/sys/nfsclient/bootp_subr.c	31 May 2002 11:52:34 -0000	1.41
+++ src/sys/nfsclient/bootp_subr.c	15 Aug 2002 18:33:53 -0000
@@ -385,7 +385,7 @@
 	printf("%s%d flags %x, addr ",
 	       ifp->if_name,
 	       ifp->if_unit,
-	       (unsigned short) ifp->if_flags);
+	       ifp->if_flags);
 	print_sin_addr((struct sockaddr_in *) ifa->ifa_addr);
 	printf(", broadcast ");
 	print_sin_addr((struct sockaddr_in *) ifa->ifa_dstaddr);
Index: src/sys/pci/if_dc.c
===================================================================
RCS file: /home/ncvs/src/sys/pci/if_dc.c,v
retrieving revision 1.74
diff -d -u -r1.74 if_dc.c
--- src/sys/pci/if_dc.c	30 Jun 2002 22:05:46 -0000	1.74
+++ src/sys/pci/if_dc.c	15 Aug 2002 18:33:55 -0000
@@ -2483,7 +2483,7 @@
 	while(!(sc->dc_ldata->dc_rx_list[i].dc_status & DC_RXSTAT_OWN)) {
 
 #ifdef DEVICE_POLLING
-		if (ifp->if_ipending & IFF_POLLING) {
+		if (ifp->if_flags & IFF_POLLING) {
 			if (sc->rxcycles <= 0)
 				break;
 			sc->rxcycles--;
@@ -2885,7 +2885,7 @@
 	DC_LOCK(sc);
 	ifp = &sc->arpcom.ac_if;
 #ifdef DEVICE_POLLING
-	if (ifp->if_ipending & IFF_POLLING)
+	if (ifp->if_flags & IFF_POLLING)
 		goto done;
 	if (ether_poll_register(dc_poll, ifp)) { /* ok, disable interrupts */
 		CSR_WRITE_4(sc, DC_IMR, 0x00000000);
@@ -3265,7 +3265,7 @@
 	 * the case of polling. Some cards (e.g. fxp) turn interrupts on
 	 * after a reset.
 	 */
-	if (ifp->if_ipending & IFF_POLLING)
+	if (ifp->if_flags & IFF_POLLING)
 		CSR_WRITE_4(sc, DC_IMR, 0x00000000);
 	else
 #endif
Index: src/sys/pci/if_rl.c
===================================================================
RCS file: /home/ncvs/src/sys/pci/if_rl.c,v
retrieving revision 1.72
diff -d -u -r1.72 if_rl.c
--- src/sys/pci/if_rl.c	30 Jul 2002 17:31:42 -0000	1.72
+++ src/sys/pci/if_rl.c	15 Aug 2002 18:33:56 -0000
@@ -1187,7 +1187,7 @@
 
 	while((CSR_READ_1(sc, RL_COMMAND) & RL_CMD_EMPTY_RXBUF) == 0) {
 #ifdef DEVICE_POLLING
-		if (ifp->if_ipending & IFF_POLLING) {
+		if (ifp->if_flags & IFF_POLLING) {
 			if (sc->rxcycles <= 0)
 				break;
 			sc->rxcycles--;
@@ -1416,7 +1416,7 @@
 	ifp = &sc->arpcom.ac_if;
 
 #ifdef DEVICE_POLLING
-	if  (ifp->if_ipending & IFF_POLLING)
+	if  (ifp->if_flags & IFF_POLLING)
 		goto done;
 	if (ether_poll_register(rl_poll, ifp)) { /* ok, disable interrupts */
 		CSR_WRITE_2(sc, RL_IMR, 0x0000);
@@ -1654,7 +1654,7 @@
 	/*
 	 * Disable interrupts if we are polling.
 	 */
-	if (ifp->if_ipending & IFF_POLLING)
+	if (ifp->if_flags & IFF_POLLING)
 		CSR_WRITE_2(sc, RL_IMR, 0);
 	else	/* otherwise ... */
 #endif /* DEVICE_POLLING */
Index: src/sys/pci/if_sis.c
===================================================================
RCS file: /home/ncvs/src/sys/pci/if_sis.c,v
retrieving revision 1.53
diff -d -u -r1.53 if_sis.c
--- src/sys/pci/if_sis.c	7 Aug 2002 16:08:54 -0000	1.53
+++ src/sys/pci/if_sis.c	15 Aug 2002 18:33:57 -0000
@@ -1285,7 +1285,7 @@
 	while(SIS_OWNDESC(&sc->sis_ldata.sis_rx_list[i])) {
 
 #ifdef DEVICE_POLLING
-		if (ifp->if_ipending & IFF_POLLING) {
+		if (ifp->if_flags & IFF_POLLING) {
 			if (sc->rxcycles <= 0)
 				break;
 			sc->rxcycles--;
@@ -1508,7 +1508,7 @@
 
 	SIS_LOCK(sc);
 #ifdef DEVICE_POLLING
-	if (ifp->if_ipending & IFF_POLLING)
+	if (ifp->if_flags & IFF_POLLING)
 		goto done;
 	if (ether_poll_register(sis_poll, ifp)) { /* ok, disable interrupts */
 		CSR_WRITE_4(sc, SIS_IER, 0);
@@ -1810,7 +1810,7 @@
 	 * ... only enable interrupts if we are not polling, make sure
 	 * they are off otherwise.
 	 */
-	if (ifp->if_ipending & IFF_POLLING)
+	if (ifp->if_flags & IFF_POLLING)
 		CSR_WRITE_4(sc, SIS_IER, 0);
 	else
 #endif /* DEVICE_POLLING */
Index: src/usr.sbin/mrouted/config.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/mrouted/config.c,v
retrieving revision 1.14
diff -d -u -r1.14 config.c
--- src/usr.sbin/mrouted/config.c	28 Aug 1999 01:17:03 -0000	1.14
+++ src/usr.sbin/mrouted/config.c	15 Aug 2002 18:33:57 -0000
@@ -32,7 +32,7 @@
     register vifi_t vifi;
     int n;
     u_int32 addr, mask, subnet;
-    short flags;
+    int flags;
     int num_ifreq = 32;
 
     ifc.ifc_len = num_ifreq * sizeof(struct ifreq);


--------------6E58B69EA83C65AC034DB0DB--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D5BF635.3764C796>