Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Feb 2000 03:31:48 +0900
From:      Yoshinobu Inoue <shin@nd.net.fujitsu.co.jp>
To:        freebsd-current@freebsd.org, freebsd-alpha@freebsd.org
Subject:   patches for SIOCGIFCONF
Message-ID:  <20000228033148B.shin@nd.net.fujitsu.co.jp>

next in thread | raw e-mail | index | archive | help
Hi,

I checked apps under /usr/src which are using SIOCGIFCONF, and
might have some effect on INET6 enabled kernel, and created
patches for them. (Some of the patches are not directly
related to SIOCGIFCONF)

These are build checked on i386, but not actually confirmed on
alpha.

Please review this, and if someone have time to test it on
INET6 enabled alpha, it is very appreciated.

  usr.sbin/xntpd/xntpd:
  lib/libc/rpc:
  crypto/kerberosIV/lib/krb:
  contrib/ntp/ntpd:
    Doing structure copy ifreq obtained by SIOCGIFCONF.
    This might cause unaligend access trap, and thus cause
    some performance issue.

  contrib/bind/lib/irs:
    Copying the contents of ifreq obtained by SIOCGIFCONF
    into local ifreq var. And doing IPv6 related operation with it.
    This cause problem because IPv6 info don't fit into ifreq
    structure.


These are not SIOCGIFCONF problem.

  usr.sbin/timed/timed:
  usr.sbin/arp:
    Using u_long to keep in_addr.s_addr, and doing some
    operation with such values.
    This might not be acutally problem but better to be fixed.

  contrib/amd/libamu:
    Using u_long to keep in_addr.s_addr value in many place.
    I'm not sure if this really cause problem on alpha,
    but I am afraid that ntohl() is done on some of such vars.


Thanks,
Yoshinobu Inoue    =


--- usr.sbin/xntpd/xntpd/ntp_io.c.orig	Mon Feb 28 01:53:00 2000
+++ usr.sbin/xntpd/xntpd/ntp_io.c	Mon Feb 28 01:53:30 2000
@@ -285,7 +285,7 @@
 		n -=3D size;
 		if (ifr->ifr_addr.sa_family !=3D AF_INET)
 			continue;
-		ifreq =3D *ifr;
+		memcpy(&ifreq, ifr, sizeof(ifreq));
 #ifdef STREAMS_TLI
 		ioc.ic_cmd =3D SIOCGIFFLAGS;
 		ioc.ic_timout =3D 0;
--- lib/libc/rpc/get_myaddress.c.orig	Fri Jan 28 10:12:00 2000
+++ lib/libc/rpc/get_myaddress.c	Mon Feb 28 02:16:35 2000
@@ -81,7 +81,7 @@
 	end =3D (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
 =

 	while (ifr < end) {
-		ifreq =3D *ifr;
+		memcpy(&ifreq, ifr, sizeof(ifreq));
 		if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
 			_close(s);
 			return(-1);
--- lib/libc/rpc/pmap_rmt.c.orig	Mon Feb 28 02:16:13 2000
+++ lib/libc/rpc/pmap_rmt.c	Mon Feb 28 02:12:33 2000
@@ -189,7 +189,7 @@
 		ifr =3D (struct ifreq *)cp;
 		if (ifr->ifr_addr.sa_family !=3D AF_INET)
 			continue;
-		memcpy(&ifreq, ifr, sizeof(ifreq));
+		ifreq =3D *ifr;
                 if (ioctl(sock, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
                         perror("broadcast: ioctl (get interface flags)"=
);
                         continue;
--- crypto/kerberosIV/lib/krb/getaddrs.c.orig	Sun Jan  9 19:49:00 2000
+++ crypto/kerberosIV/lib/krb/getaddrs.c	Mon Feb 28 02:24:18 2000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska H=F6gsk=
olan
+ * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska H=0Bsko=
lan
  * (Royal Institute of Technology, Stockholm, Sweden).
  * All rights reserved.
  * =

@@ -128,7 +128,7 @@
 		      continue;
 		  (*l)[j++] =3D ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr;
 	       }
-	      ifreq =3D *ifr;
+	      memcpy(&ifreq, ifr, sizeof(ifreq));
 	  }
      }
      if (j !=3D num) {
--- contrib/ntp/ntpd/ntp_io.c.orig	Fri Jan 28 15:44:00 2000
+++ contrib/ntp/ntpd/ntp_io.c	Mon Feb 28 02:26:46 2000
@@ -444,7 +444,7 @@
 			continue;
 		}
 # endif /* SYS_WINNT */
-		ifreq =3D *ifr;
+		memcpy(&ifreq, ifr, sizeof(ifreq));
 		inter_list[i].flags =3D 0;
 		/* is it broadcast capable? */
 # ifndef SYS_WINNT
--- contrib/bind/lib/irs/gethostent.c.orig	Tue Nov 30 15:38:00 1999
+++ contrib/bind/lib/irs/gethostent.c	Mon Feb 28 02:43:39 2000
@@ -462,13 +462,16 @@
 static int
 scan_interfaces(int *have_v4, int *have_v6) {
 	struct ifconf ifc;
-	struct ifreq ifreq;
+	struct ifreq* ifreqp;
 	struct in_addr in4;
 	struct in6_addr in6;
 	char *buf =3D NULL, *cp, *cplim;
+	char ifreqbuf[IFNAMSIZ + sizeof(struct sockaddr_storage)];
 	static int bufsiz =3D 4095;
 	int s, cpsize, n;
 =

+	ifreqp =3D (struct ifreq *)ifreqbuf;
+
 	/* Set to zero.  Used as loop terminators below. */
 	*have_v4 =3D *have_v6 =3D 0;
 =

@@ -504,7 +507,7 @@
 			 * buffer we will grow it just in case and
 			 * retry.
 			 */
-			if (ifc.ifc_len + 2 * sizeof(ifreq) < bufsiz)
+			if (ifc.ifc_len + 2 * sizeof(*ifreqp) < bufsiz)
 				break;
 		}
 #endif
@@ -523,40 +526,40 @@
 	for (cp =3D buf;
 	     (*have_v4 =3D=3D 0 || *have_v6 =3D=3D 0) && cp < cplim;
 	     cp +=3D cpsize) {
-		memcpy(&ifreq, cp, sizeof ifreq);
+		memcpy(ifreqp, cp, sizeof *ifreqp);
 #ifdef HAVE_SA_LEN
 #ifdef FIX_ZERO_SA_LEN
-		if (ifreq.ifr_addr.sa_len =3D=3D 0)
-			ifreq.ifr_addr.sa_len =3D 16;
+		if (ifreqp->ifr_addr.sa_len =3D=3D 0)
+			ifreqp->ifr_addr.sa_len =3D 16;
 #endif
 #ifdef HAVE_MINIMUM_IFREQ
-		cpsize =3D sizeof ifreq;
-		if (ifreq.ifr_addr.sa_len > sizeof (struct sockaddr))
-			cpsize +=3D (int)ifreq.ifr_addr.sa_len -
+		cpsize =3D sizeof *ifreqp;
+		if (ifreqp->ifr_addr.sa_len > sizeof (struct sockaddr))
+			cpsize +=3D (int)ifreqp->ifr_addr.sa_len -
 				(int)(sizeof (struct sockaddr));
 #else
-		cpsize =3D sizeof ifreq.ifr_name + ifreq.ifr_addr.sa_len;
+		cpsize =3D sizeof ifreqp->ifr_name + ifreqp->ifr_addr.sa_len;
 #endif /* HAVE_MINIMUM_IFREQ */
 #elif defined SIOCGIFCONF_ADDR
-		cpsize =3D sizeof ifreq;
+		cpsize =3D sizeof *ifreqp;
 #else
-		cpsize =3D sizeof ifreq.ifr_name;
+		cpsize =3D sizeof ifreq->ifr_name;
 		/* XXX maybe this should be a hard error? */
-		if (ioctl(s, SIOCGIFADDR, (char *)&ifreq) < 0)
+		if (ioctl(s, SIOCGIFADDR, (char *)ifreqp) < 0)
 			continue;
 #endif
-		switch (ifreq.ifr_addr.sa_family) {
+		switch (ifreqp->ifr_addr.sa_family) {
 		case AF_INET:
 			if (*have_v4 =3D=3D 0) {
 				memcpy(&in4,
 				       &((struct sockaddr_in *)
-				       &ifreq.ifr_addr)->sin_addr, sizeof in4);
+				       &ifreqp->ifr_addr)->sin_addr, sizeof in4);
 				if (in4.s_addr =3D=3D INADDR_ANY)
 					break;
-				n =3D ioctl(s, SIOCGIFFLAGS, (char *)&ifreq);
+				n =3D ioctl(s, SIOCGIFFLAGS, (char *)ifreqp);
 				if (n < 0)
 					break;
-				if ((ifreq.ifr_flags & IFF_UP) =3D=3D 0)
+				if ((ifreqp->ifr_flags & IFF_UP) =3D=3D 0)
 					break;
 				*have_v4 =3D 1;
 			} =

@@ -565,13 +568,13 @@
 			if (*have_v6 =3D=3D 0) {
 				memcpy(&in6,
 				       &((struct sockaddr_in6 *)
-				       &ifreq.ifr_addr)->sin6_addr, sizeof in6);
+				       &ifreqp->ifr_addr)->sin6_addr, sizeof in6);
 				if (memcmp(&in6, &in6addr_any, sizeof in6) =3D=3D 0)
 					break;
-				n =3D ioctl(s, SIOCGIFFLAGS, (char *)&ifreq);
+				n =3D ioctl(s, SIOCGIFFLAGS, (char *)ifreqp);
 				if (n < 0)
 					break;
-				if ((ifreq.ifr_flags & IFF_UP) =3D=3D 0)
+				if ((ifreqp->ifr_flags & IFF_UP) =3D=3D 0)
 					break;
 				*have_v6 =3D 1;
 			}
--- usr.sbin/timed/timed/globals.h.orig	Wed Nov 24 01:51:00 1999
+++ usr.sbin/timed/timed/globals.h	Mon Feb 28 00:56:24 2000
@@ -137,7 +137,7 @@
 struct netinfo {
 	struct	netinfo *next;
 	struct	in_addr net;
-	u_long	mask;
+	u_int32_t	mask;
 	struct	in_addr my_addr;
 	struct	sockaddr_in dest_addr;	/* broadcast addr or point-point */
 	long	status;
--- usr.sbin/arp/arp.c.orig	Mon Jan 17 19:37:00 2000
+++ usr.sbin/arp/arp.c	Mon Feb 28 01:56:17 2000
@@ -96,7 +96,7 @@
 void getsocket(void);
 int my_ether_aton(char *a, u_char *n);
 int rtmsg(int cmd);
-int get_ether_addr(u_long ipaddr, u_char *hwaddr);
+int get_ether_addr(u_int32_t ipaddr, u_char *hwaddr);
 =

 static int pid;
 static int nflag;	/* no reverse dns lookups */
@@ -641,10 +641,10 @@
 #define MAX_IFS		32
 =

 int
-get_ether_addr(u_long ipaddr, u_char *hwaddr)
+get_ether_addr(u_int32_t ipaddr, u_char *hwaddr)
 {
 	struct ifreq *ifr, *ifend, *ifp;
-	u_long ina, mask;
+	u_int32_t ina, mask;
 	struct sockaddr_dl *dla;
 	struct ifreq ifreq;
 	struct ifconf ifc;
--- contrib/amd/include/am_utils.h.orig	Wed Sep 15 02:50:00 1999
+++ contrib/amd/include/am_utils.h	Mon Feb 28 02:57:23 2000
@@ -556,7 +556,7 @@
 extern char **strsplit(char *, int, int);
 extern char *expand_key(char *);
 extern char *get_version_string(void);
-extern char *inet_dquad(char *, u_long);
+extern char *inet_dquad(char *, u_int32_t);
 extern char *print_wires(void);
 extern char *str3cat(char *, char *, char *, char *);
 extern char *strealloc(char *, char *);
@@ -576,7 +576,7 @@
 extern int get_amd_program_number(void);
 extern int hasmntval(mntent_t *, char *);
 extern int is_network_member(const char *net);
-extern int islocalnet(u_long);
+extern int islocalnet(u_int32_t);
 extern int make_nfs_auth(void);
 extern int make_rpc_packet(char *, int, u_long, struct rpc_msg *, voidp=
, XDRPROC_T_TYPE, AUTH *);
 extern int mapc_keyiter(mnt_map *, void(*)(char *, voidp), voidp);
--- contrib/amd/libamu/wire.c.orig	Wed Sep 15 02:50:00 1999
+++ contrib/amd/libamu/wire.c	Mon Feb 28 02:55:47 2000
@@ -75,8 +75,8 @@
 typedef struct addrlist addrlist;
 struct addrlist {
   addrlist *ip_next;
-  u_long ip_addr;		/* address of network */
-  u_long ip_mask;
+  u_int32_t ip_addr;		/* address of network */
+  u_int32_t ip_mask;
   char *ip_net_num;		/* number of network */
   char *ip_net_name;		/* name of network */
 };
@@ -133,10 +133,10 @@
 =

 =

 static struct addrlist *
-getwire_lookup(u_long address, u_long netmask, int ishost)
+getwire_lookup(u_int32_t address, u_int32_t netmask, int ishost)
 {
   struct addrlist *al;
-  u_long subnet;
+  u_int32_t subnet;
   char netNumberBuf[64];
   char buf[GFBUFLEN], *s;
 #ifdef HAVE_IRS_H
@@ -161,10 +161,10 @@
     np =3D NULL;
   else {
 #ifdef HAVE_IRS_H
-    u_long mask =3D ntohl(netmask);
+    u_int32_t mask =3D ntohl(netmask);
     static struct irs_acc *irs_gen;
     static struct irs_nw *irs_nw;
-    u_long net;
+    u_int32_t net;
     int maskbits;
     u_char addr[4];
 =

@@ -189,7 +189,7 @@
      * shift the subnet way from zeros and try again.
      */
     if (!np) {
-      u_long short_subnet =3D subnet;
+      u_int32_t short_subnet =3D subnet;
       while(short_subnet && (short_subnet & 0x000000ff) =3D=3D 0)
 	short_subnet >>=3D 8;
       np =3D getnetbyaddr(short_subnet, AF_INET);
@@ -244,7 +244,7 @@
  * sizeof(buf) needs to be at least 16.
  */
 char *
-inet_dquad(char *buf, u_long addr)
+inet_dquad(char *buf, u_int32_t addr)
 {
   addr =3D ntohl(addr);
   sprintf(buf, "%ld.%ld.%ld.%ld",
@@ -261,7 +261,7 @@
  * (addr) is in network byte order.
  */
 int
-islocalnet(u_long addr)
+islocalnet(u_int32_t addr)
 {
   addrlist *al;
 #ifdef DEBUG
@@ -379,13 +379,13 @@
   struct ifreq *ifr;
   caddr_t cp, cplim;
   int fd =3D -1;
-  u_long address;
+  u_int32_t address;
   addrlist *al =3D NULL, *tail =3D NULL;
   char buf[GFBUFLEN];
 #if 0
-  u_long net;
-  u_long mask;
-  u_long subnetshift;
+  u_int32_t net;
+  u_int32_t mask;
+  u_int32_t subnetshift;
   char buf[GFBUFLEN], *s;
 #endif
 =





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




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