Subject: Patch to fix namespace lossage in fast-ipsec
To: None <tech-net@netbsd.org>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: tech-net
Date: 11/10/2003 19:15:45
sys/netipsec uses certain FreeBSD-style names, with macros in
sys/netipsec/ipsec_osdep.h to hide various FreeBSD-vs-NetBSD
differences.  Some (not-so-)recent changes (in_ifaddr naming) broke
one of those macros.

Anyone strenuous objections to fixing that lossage as below?

Index: netinet/in_var.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/in_var.h,v
retrieving revision 1.49
diff -u -r1.49 in_var.h
--- netinet/in_var.h	2003/08/18 22:28:51	1.49
+++ netinet/in_var.h	2003/11/10 20:47:21
@@ -141,7 +141,7 @@
 extern	u_long in_ifaddrhash;			/* size of hash table - 1 */
 extern	int	in_ifaddrentries;		/* total number of addrs */
 extern  struct in_ifaddrhashhead *in_ifaddrhashtbl;	/* Hash table head */
-extern  struct in_ifaddrhead in_ifaddr;		/* List head (in ip_input) */
+extern  struct in_ifaddrhead in_ifaddrhead;		/* List head (in ip_input) */
 
 extern	u_long in_multihash;			/* size of hash table - 1 */
 extern	int	in_multientries;		/* total number of addrs */
Index: netinet/in.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/in.c,v
retrieving revision 1.91
diff -u -r1.91 in.c
--- netinet/in.c	2003/08/16 11:30:35	1.91
+++ netinet/in.c	2003/11/10 20:47:22
@@ -170,11 +170,11 @@
 	struct in_ifaddr *ia;
 
 	if (subnetsarelocal) {
-		TAILQ_FOREACH(ia, &in_ifaddr, ia_list)
+		TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list)
 			if ((in.s_addr & ia->ia_netmask) == ia->ia_net)
 				return (1);
 	} else {
-		TAILQ_FOREACH(ia, &in_ifaddr, ia_list)
+		TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list)
 			if ((in.s_addr & ia->ia_subnetmask) == ia->ia_subnet)
 				return (1);
 	}
@@ -254,7 +254,7 @@
 	struct ifnet *ifp;
 	unsigned long maxmtu = 0;
 
-	TAILQ_FOREACH(ia, &in_ifaddr, ia_list) {
+	TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
 		if ((ifp = ia->ia_ifp) == 0)
 			continue;
 		if ((ifp->if_flags & (IFF_UP|IFF_LOOPBACK)) != IFF_UP)
@@ -385,7 +385,7 @@
 			if (ia == 0)
 				return (ENOBUFS);
 			bzero((caddr_t)ia, sizeof *ia);
-			TAILQ_INSERT_TAIL(&in_ifaddr, ia, ia_list);
+			TAILQ_INSERT_TAIL(&in_ifaddrhead, ia, ia_list);
 			IFAREF(&ia->ia_ifa);
 			TAILQ_INSERT_TAIL(&ifp->if_addrlist, &ia->ia_ifa,
 			    ifa_list);
@@ -580,7 +580,7 @@
 	LIST_REMOVE(ia, ia_hash);
 	TAILQ_REMOVE(&ifp->if_addrlist, &ia->ia_ifa, ifa_list);
 	IFAFREE(&ia->ia_ifa);
-	TAILQ_REMOVE(&in_ifaddr, ia, ia_list);
+	TAILQ_REMOVE(&in_ifaddrhead, ia, ia_list);
 	if (ia->ia_allhosts != NULL)
 		in_delmulti(ia->ia_allhosts);
 	IFAFREE(&ia->ia_ifa);
@@ -929,7 +929,7 @@
 		prefix.s_addr &= mask.s_addr;
 	}
 
-	TAILQ_FOREACH(ia, &in_ifaddr, ia_list) {
+	TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
 		if (rtinitflags(ia))
 			p = ia->ia_dstaddr.sin_addr;
 		else {
@@ -981,7 +981,7 @@
 		prefix.s_addr &= mask.s_addr;
 	}
 
-	TAILQ_FOREACH(ia, &in_ifaddr, ia_list) {
+	TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
 		if (rtinitflags(ia))
 			p = ia->ia_dstaddr.sin_addr;
 		else {
Index: netinet/in_gif.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/in_gif.c,v
retrieving revision 1.33
diff -u -r1.33 in_gif.c
--- netinet/in_gif.c	2003/08/22 21:53:03	1.33
+++ netinet/in_gif.c	2003/11/10 20:47:22
@@ -336,7 +336,7 @@
 		return 0;
 	}
 	/* reject packets with broadcast on source */
-	TAILQ_FOREACH(ia4, &in_ifaddr, ia_list) {
+	TAILQ_FOREACH(ia4, &in_ifaddrhead, ia_list) {
 		if ((ia4->ia_ifa.ifa_ifp->if_flags & IFF_BROADCAST) == 0)
 			continue;
 		if (ip->ip_src.s_addr == ia4->ia_broadaddr.sin_addr.s_addr)
Index: netinet/in_pcb.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/in_pcb.c,v
retrieving revision 1.88
diff -u -r1.88 in_pcb.c
--- netinet/in_pcb.c	2003/09/04 09:16:57	1.88
+++ netinet/in_pcb.c	2003/11/10 20:47:23
@@ -232,7 +232,7 @@
 	if (inp->inp_af != AF_INET)
 		return (EINVAL);
 
-	if (TAILQ_FIRST(&in_ifaddr) == 0)
+	if (TAILQ_FIRST(&in_ifaddrhead) == 0)
 		return (EADDRNOTAVAIL);
 	if (inp->inp_lport || !in_nullhost(inp->inp_laddr))
 		return (EINVAL);
@@ -399,7 +399,7 @@
 		return (EAFNOSUPPORT);
 	if (sin->sin_port == 0)
 		return (EADDRNOTAVAIL);
-	if (TAILQ_FIRST(&in_ifaddr) != 0) {
+	if (TAILQ_FIRST(&in_ifaddrhead) != 0) {
 		/*
 		 * If the destination address is INADDR_ANY,
 		 * use any local address (likely loopback).
@@ -410,9 +410,9 @@
 
 		if (in_nullhost(sin->sin_addr)) {
 			sin->sin_addr =
-			    TAILQ_FIRST(&in_ifaddr)->ia_addr.sin_addr;
+			    TAILQ_FIRST(&in_ifaddrhead)->ia_addr.sin_addr;
 		} else if (sin->sin_addr.s_addr == INADDR_BROADCAST) {
-			TAILQ_FOREACH(ia, &in_ifaddr, ia_list) {
+			TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
 				if (ia->ia_ifp->if_flags & IFF_BROADCAST) {
 					sin->sin_addr =
 					    ia->ia_broadaddr.sin_addr;
@@ -1007,7 +1007,7 @@
 		sin->sin_port = fport;
 		if (ia == 0) {
 			/* Find 1st non-loopback AF_INET address */
-			TAILQ_FOREACH(ia, &in_ifaddr, ia_list) {
+			TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
 				if (!(ia->ia_ifp->if_flags & IFF_LOOPBACK))
 					break;
 			}
Index: netinet/ip_icmp.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.78
diff -u -r1.78 ip_icmp.c
--- netinet/ip_icmp.c	2003/08/22 22:00:36	1.78
+++ netinet/ip_icmp.c	2003/11/10 20:47:23
@@ -744,7 +744,7 @@
 	 * interface.
 	 */
 	if (sin == (struct sockaddr_in *)0)
-		TAILQ_FOREACH(ia, &in_ifaddr, ia_list) {
+		TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
 			if (ia->ia_ifp->if_flags & IFF_LOOPBACK)
 				continue;
 			sin = &ia->ia_addr;
Index: netinet/ip_input.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_input.c,v
retrieving revision 1.180
diff -u -r1.180 ip_input.c
--- netinet/ip_input.c	2003/11/10 20:03:29	1.180
+++ netinet/ip_input.c	2003/11/10 20:47:24
@@ -219,7 +219,7 @@
 int	ipqmaxlen = IFQ_MAXLEN;
 u_long	in_ifaddrhash;				/* size of hash table - 1 */
 int	in_ifaddrentries;			/* total number of addrs */
-struct	in_ifaddrhead in_ifaddr;
+struct in_ifaddrhead in_ifaddrhead;	
 struct	in_ifaddrhashhead *in_ifaddrhashtbl;
 u_long	in_multihash;				/* size of hash table - 1 */
 int	in_multientries;			/* total number of addrs */
@@ -360,7 +360,7 @@
 			ip_protox[pr->pr_protocol] = pr - inetsw;
 	LIST_INIT(&ipq);
 	ipintrq.ifq_maxlen = ipqmaxlen;
-	TAILQ_INIT(&in_ifaddr);
+	TAILQ_INIT(&in_ifaddrhead);
 	in_ifaddrhashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, M_IFADDR,
 	    M_WAITOK, &in_ifaddrhash);
 	in_multihashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, M_IPMADDR,
@@ -448,7 +448,7 @@
 	 * If no IP addresses have been set yet but the interfaces
 	 * are receiving, can't do anything with incoming packets yet.
 	 */
-	if (TAILQ_FIRST(&in_ifaddr) == 0)
+	if (TAILQ_FIRST(&in_ifaddrhead) == 0)
 		goto bad;
 	ipstat.ips_total++;
 	/*
Index: netipsec/ipsec_osdep.h
===================================================================
RCS file: /cvsroot/src/sys/netipsec/ipsec_osdep.h,v
retrieving revision 1.3
diff -u -r1.3 ipsec_osdep.h
--- netipsec/ipsec_osdep.h	2003/10/06 22:05:15	1.3
+++ netipsec/ipsec_osdep.h	2003/11/10 20:47:24
@@ -2,6 +2,9 @@
 
 #ifndef NETIPSEC_OSDEP_H
 #define NETIPSEC_OSDEP_H
+#include <sys/systm.h>
+#undef bcopy
+#define bcopy(src, dst, len) memmove((dst), (src), (len))
 
 /* 
  *  Hide porting differences across different 4.4BSD-derived platforms.
@@ -214,7 +217,7 @@
 
 /*
  * 10. List of all known network interfaces.
- * FreeBSD has listhead in_ifaddread, with ia_link as link.
+ * FreeBSD has listhead in_ifaddrhead, with ia_link as link.
  * NetBSD has listhead in_ifaddr, with ia_list as link.
  * No name-clahses, so just #define the appropriate names on NetBSD.
  * NB: Is it worth introducing iterator (find-first-list/find-next-list)
@@ -224,8 +227,6 @@
 /* nothing to do for raw interface list */
 #endif	/* FreeBSD */
 #ifdef __NetBSD__
-/* For now, use FreeBSD-compatible names for raw interface list. */
-#define in_ifaddrhead in_ifaddr
 #define ia_link ia_list
 #endif	/* __NetBSD__ */
 
Index: netccitt/if_x25subr.c
===================================================================
RCS file: /cvsroot/src/sys/netccitt/if_x25subr.c,v
retrieving revision 1.32
diff -u -r1.32 if_x25subr.c
--- netccitt/if_x25subr.c	2003/08/07 16:33:01	1.32
+++ netccitt/if_x25subr.c	2003/11/10 20:47:24
@@ -622,7 +622,7 @@
 			 */
 			struct in_ifaddr *ina;
 
-			for (ina = in_ifaddr.tqh_first; ina != 0;
+			for (ina = in_ifaddrhead.tqh_first; ina != 0;
 			     ina = ina->ia_list.tqe_next)
 				if (ina->ia_ifp == ia->ia_ifp) {
 					my_addr = ina->ia_addr.sin_addr;