svn commit: r190711 - head/sbin/routed

Poul-Henning Kamp phk at FreeBSD.org
Sun Apr 5 07:01:40 PDT 2009


Author: phk
Date: Sun Apr  5 14:01:39 2009
New Revision: 190711
URL: http://svn.freebsd.org/changeset/base/190711

Log:
  Use <sys/queue.h> to manage the interface list.

Modified:
  head/sbin/routed/defs.h
  head/sbin/routed/if.c
  head/sbin/routed/main.c
  head/sbin/routed/output.c
  head/sbin/routed/parms.c
  head/sbin/routed/rdisc.c
  head/sbin/routed/table.c
  head/sbin/routed/trace.c

Modified: head/sbin/routed/defs.h
==============================================================================
--- head/sbin/routed/defs.h	Sun Apr  5 13:48:06 2009	(r190710)
+++ head/sbin/routed/defs.h	Sun Apr  5 14:01:39 2009	(r190711)
@@ -80,6 +80,7 @@
 #include <sys/ioctl.h>
 #include <sys/sysctl.h>
 #include <sys/socket.h>
+#include <sys/queue.h>
 #ifdef sgi
 #define _USER_ROUTE_TREE
 #include <net/radix.h>
@@ -262,7 +263,7 @@ struct rt_entry {
  * handles "logical" or "IS_REMOTE" interfaces (remote gateways).
  */
 struct interface {
-	struct interface *int_next, **int_prev;
+	LIST_ENTRY(interface)		int_list;
 	struct interface *int_ahash, **int_ahash_prev;
 	struct interface *int_bhash, **int_bhash_prev;
 	struct interface *int_rlink, **int_rlink_prev;
@@ -353,6 +354,7 @@ struct interface {
 
 #define iff_up(f) ((f) & IFF_UP)
 
+LIST_HEAD(ifhead, interface);
 
 /* Information for aggregating routes */
 #define NUM_AG_SLOTS	32
@@ -483,7 +485,7 @@ extern struct timeval ifinit_timer;	/* t
 extern naddr	loopaddr;		/* our address on loopback */
 extern int	tot_interfaces;		/* # of remote and local interfaces */
 extern int	rip_interfaces;		/* # of interfaces doing RIP */
-extern struct interface *ifnet;		/* all interfaces */
+extern struct ifhead ifnet;		/* all interfaces */
 extern struct interface *remote_if;	/* remote interfaces */
 extern int	have_ripv1_out;		/* have a RIPv1 interface */
 extern int	have_ripv1_in;

Modified: head/sbin/routed/if.c
==============================================================================
--- head/sbin/routed/if.c	Sun Apr  5 13:48:06 2009	(r190710)
+++ head/sbin/routed/if.c	Sun Apr  5 14:01:39 2009	(r190711)
@@ -41,7 +41,7 @@ __RCSID("$Revision: 2.27 $");
 #ident "$Revision: 2.27 $"
 #endif
 
-struct interface *ifnet;		/* all interfaces */
+struct ifhead ifnet = LIST_HEAD_INITIALIZER(ifnet);	/* all interfaces */
 
 /* hash table for all interfaces, big enough to tolerate ridiculous
  * numbers of IP aliases.  Crazy numbers of aliases such as 7000
@@ -101,11 +101,7 @@ if_link(struct interface *ifp)
 {
 	struct interface **hifp;
 
-	ifp->int_prev = &ifnet;
-	ifp->int_next = ifnet;
-	if (ifnet != 0)
-		ifnet->int_prev = &ifp->int_next;
-	ifnet = ifp;
+	LIST_INSERT_HEAD(&ifnet, ifp, int_list);
 
 	hifp = AHASH(ifp->int_addr);
 	ifp->int_ahash_prev = hifp;
@@ -217,7 +213,7 @@ ifwithindex(u_short ifindex,
 	struct interface *ifp;
 
 	for (;;) {
-		for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) {
+		LIST_FOREACH(ifp, &ifnet, int_list) {
 			if (ifp->int_index == ifindex)
 				return ifp;
 		}
@@ -245,7 +241,7 @@ iflookup(naddr addr)
 
 	maybe = 0;
 	for (;;) {
-		for (ifp = ifnet; ifp; ifp = ifp->int_next) {
+		LIST_FOREACH(ifp, &ifnet, int_list) {
 			if (ifp->int_if_flags & IFF_POINTOPOINT) {
 				/* finished with a match */
 				if (ifp->int_dstaddr == addr)
@@ -322,7 +318,7 @@ ripv1_mask_net(naddr addr,		/* in networ
 		 * such interface, prefer the interface with the longest
 		 * match.
 		 */
-		for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
+		LIST_FOREACH(ifp, &ifnet, int_list) {
 			if (on_net(addr, ifp->int_std_net, ifp->int_std_mask)
 			    && ifp->int_ripv1_mask > mask
 			    && ifp->int_ripv1_mask != HOST_MASK)
@@ -394,7 +390,7 @@ check_dup(naddr addr,			/* IP address, s
 {
 	struct interface *ifp;
 
-	for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		if (ifp->int_mask != mask)
 			continue;
 
@@ -459,11 +455,7 @@ ifdel(struct interface *ifp)
 
 	ifp->int_state |= IS_BROKE;
 
-	/* unlink the interface
-	 */
-	*ifp->int_prev = ifp->int_next;
-	if (ifp->int_next != 0)
-		ifp->int_next->int_prev = ifp->int_prev;
+	LIST_REMOVE(ifp, int_list);
 	*ifp->int_ahash_prev = ifp->int_ahash;
 	if (ifp->int_ahash != 0)
 		ifp->int_ahash->int_ahash_prev = ifp->int_ahash_prev;
@@ -484,7 +476,7 @@ ifdel(struct interface *ifp)
 	if (!(ifp->int_state & IS_ALIAS)) {
 		/* delete aliases when the main interface dies
 		 */
-		for (ifp1 = ifnet; 0 != ifp1; ifp1 = ifp1->int_next) {
+		LIST_FOREACH(ifp1, &ifnet, int_list) {
 			if (ifp1 != ifp
 			    && !strcmp(ifp->int_name, ifp1->int_name))
 				ifdel(ifp1);
@@ -570,7 +562,7 @@ if_bad(struct interface *ifp)
 	trace_if("Chg", ifp);
 
 	if (!(ifp->int_state & IS_ALIAS)) {
-		for (ifp1 = ifnet; 0 != ifp1; ifp1 = ifp1->int_next) {
+		LIST_FOREACH(ifp1, &ifnet, int_list) {
 			if (ifp1 != ifp
 			    && !strcmp(ifp->int_name, ifp1->int_name))
 				if_bad(ifp1);
@@ -606,7 +598,7 @@ if_ok(struct interface *ifp,
 	ifp->int_data.ts = 0;
 
 	if (!(ifp->int_state & IS_ALIAS)) {
-		for (ifp1 = ifnet; 0 != ifp1; ifp1 = ifp1->int_next) {
+		LIST_FOREACH(ifp1, &ifnet, int_list) {
 			if (ifp1 != ifp
 			    && !strcmp(ifp->int_name, ifp1->int_name))
 				if_ok(ifp1, type);
@@ -687,7 +679,7 @@ ifinit(void)
 					    : CHECK_QUIET_INTERVAL);
 
 	/* mark all interfaces so we can get rid of those that disappear */
-	for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next)
+	LIST_FOREACH(ifp, &ifnet, int_list)
 		ifp->int_state &= ~(IS_CHECKED | IS_DUP);
 
 	/* Fetch the interface list, without too many system calls
@@ -1111,7 +1103,7 @@ ifinit(void)
 		if (!(prev_complaints & COMP_NETMASK)
 		    && !(ifp->int_if_flags & IFF_POINTOPOINT)
 		    && ifp->int_addr != RIP_DEFAULT) {
-			for (ifp1 = ifnet; 0 != ifp1; ifp1 = ifp1->int_next) {
+			LIST_FOREACH(ifp1, &ifnet, int_list) {
 				if (ifp1->int_mask == ifp->int_mask)
 					continue;
 				if (ifp1->int_if_flags & IFF_POINTOPOINT)
@@ -1188,9 +1180,7 @@ ifinit(void)
 		}
 	}
 
-	for (ifp = ifnet; ifp != 0; ifp = ifp1) {
-		ifp1 = ifp->int_next;	/* because we may delete it */
-
+	LIST_FOREACH_SAFE(ifp, &ifnet, int_list, ifp1) {
 		/* Forget any interfaces that have disappeared.
 		 */
 		if (!(ifp->int_state & (IS_CHECKED | IS_REMOTE))) {
@@ -1213,7 +1203,7 @@ ifinit(void)
 			have_ripv1_in = 1;
 	}
 
-	for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		/* Ensure there is always a network route for interfaces,
 		 * after any dead interfaces have been deleted, which
 		 * might affect routes for point-to-point links.

Modified: head/sbin/routed/main.c
==============================================================================
--- head/sbin/routed/main.c	Sun Apr  5 13:48:06 2009	(r190710)
+++ head/sbin/routed/main.c	Sun Apr  5 14:01:39 2009	(r190711)
@@ -529,7 +529,9 @@ usage:
 			n--;
 		}
 
-		for (ifp = ifnet; n > 0 && 0 != ifp; ifp = ifp->int_next) {
+		LIST_FOREACH(ifp, &ifnet, int_list) {
+			if (n <= 0)
+				break;
 			if (ifp->int_rip_sock >= 0
 			    && FD_ISSET(ifp->int_rip_sock, &ibits)) {
 				read_rip(ifp->int_rip_sock, ifp);
@@ -578,7 +580,7 @@ fix_select(void)
 		if (sock_max <= rip_sock)
 			sock_max = rip_sock+1;
 	}
-	for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		if (ifp->int_rip_sock >= 0) {
 			FD_SET(ifp->int_rip_sock, &fdbits);
 			if (sock_max <= ifp->int_rip_sock)
@@ -690,7 +692,7 @@ rip_off(void)
 
 		/* get non-broadcast sockets to listen to queries.
 		 */
-		for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
+		LIST_FOREACH(ifp, &ifnet, int_list) {
 			if (ifp->int_state & IS_REMOTE)
 				continue;
 			if (ifp->int_rip_sock < 0) {
@@ -761,7 +763,7 @@ rip_on(struct interface *ifp)
 		 * since that would let two daemons bind to the broadcast
 		 * socket.
 		 */
-		for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
+		LIST_FOREACH(ifp, &ifnet, int_list) {
 			if (ifp->int_rip_sock >= 0) {
 				(void)close(ifp->int_rip_sock);
 				ifp->int_rip_sock = -1;
@@ -776,7 +778,7 @@ rip_on(struct interface *ifp)
 		if (next_bcast.tv_sec < now.tv_sec+MIN_WAITTIME)
 			next_bcast.tv_sec = now.tv_sec+MIN_WAITTIME;
 
-		for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
+		LIST_FOREACH(ifp, &ifnet, int_list) {
 			ifp->int_query_time = NEVER;
 			rip_mcast_on(ifp);
 		}

Modified: head/sbin/routed/output.c
==============================================================================
--- head/sbin/routed/output.c	Sun Apr  5 13:48:06 2009	(r190710)
+++ head/sbin/routed/output.c	Sun Apr  5 14:01:39 2009	(r190711)
@@ -833,7 +833,7 @@ rip_bcast(int flash)
 		  flash ? "dynamic update" : "all routes",
 		  rtime.tv_sec + ((float)rtime.tv_usec)/1000000.0);
 
-	for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		/* Skip interfaces not doing RIP.
 		 * Do try broken interfaces to see if they have healed.
 		 */
@@ -907,7 +907,7 @@ rip_query(void)
 
 	memset(&buf, 0, sizeof(buf));
 
-	for (ifp = ifnet; ifp; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		/* Skip interfaces those already queried.
 		 * Do not ask via interfaces through which we don't
 		 * accept input.  Do not ask via interfaces that cannot

Modified: head/sbin/routed/parms.c
==============================================================================
--- head/sbin/routed/parms.c	Sun Apr  5 13:48:06 2009	(r190710)
+++ head/sbin/routed/parms.c	Sun Apr  5 14:01:39 2009	(r190711)
@@ -350,7 +350,7 @@ gwkludge(void)
 	/* After all of the parameter lines have been read,
 	 * apply them to any remote interfaces.
 	 */
-	for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		get_parms(ifp);
 
 		tot_interfaces++;

Modified: head/sbin/routed/rdisc.c
==============================================================================
--- head/sbin/routed/rdisc.c	Sun Apr  5 13:48:06 2009	(r190710)
+++ head/sbin/routed/rdisc.c	Sun Apr  5 14:01:39 2009	(r190711)
@@ -278,7 +278,7 @@ set_supplier(void)
 	/* Switch router discovery multicast groups from soliciting
 	 * to advertising.
 	 */
-	for (ifp = ifnet; ifp; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		if (ifp->int_state & IS_BROKE)
 			continue;
 		ifp->int_rdisc_cnt = 0;
@@ -817,7 +817,7 @@ rdisc_adv(void)
 
 	rdisc_timer.tv_sec = now.tv_sec + NEVER;
 
-	for (ifp = ifnet; ifp; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		if (0 != (ifp->int_state & (IS_NO_ADV_OUT | IS_BROKE)))
 			continue;
 
@@ -859,7 +859,7 @@ rdisc_sol(void)
 
 	rdisc_timer.tv_sec = now.tv_sec + NEVER;
 
-	for (ifp = ifnet; ifp; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		if (0 != (ifp->int_state & (IS_NO_SOL_OUT | IS_BROKE))
 		    || ifp->int_rdisc_cnt >= MAX_SOLICITATIONS)
 			continue;

Modified: head/sbin/routed/table.c
==============================================================================
--- head/sbin/routed/table.c	Sun Apr  5 13:48:06 2009	(r190710)
+++ head/sbin/routed/table.c	Sun Apr  5 14:01:39 2009	(r190711)
@@ -1918,7 +1918,7 @@ rtbad_sub(struct rt_entry *rt)
 		 * If so, see if it is used by any other interfaces, such
 		 * as a point-to-point interface with the same local address.
 		 */
-		for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
+		LIST_FOREACH(ifp, &ifnet, int_list) {
 			/* Retain it if another interface needs it.
 			 */
 			if (ifp->int_addr == rt->rt_ifp->int_addr) {
@@ -1935,7 +1935,7 @@ rtbad_sub(struct rt_entry *rt)
 		 * interface that justifies it.
 		 */
 		if (rt->rt_state & RS_NET_SYN) {
-			for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
+			LIST_FOREACH(ifp, &ifnet, int_list) {
 				if ((ifp->int_state & IS_NEED_NET_SYN)
 				    && rt->rt_mask == ifp->int_std_mask
 				    && rt->rt_dst == ifp->int_std_addr) {
@@ -2105,7 +2105,7 @@ age(naddr bad_gate)
 	/* Check for dead IS_REMOTE interfaces by timing their
 	 * transmissions.
 	 */
-	for (ifp = ifnet; ifp; ifp = ifp->int_next) {
+	LIST_FOREACH(ifp, &ifnet, int_list) {
 		if (!(ifp->int_state & IS_REMOTE))
 			continue;
 

Modified: head/sbin/routed/trace.c
==============================================================================
--- head/sbin/routed/trace.c	Sun Apr  5 13:48:06 2009	(r190710)
+++ head/sbin/routed/trace.c	Sun Apr  5 14:01:39 2009	(r190711)
@@ -870,7 +870,7 @@ trace_dump(void)
 	lastlog();
 
 	(void)fputs("current daemon state:\n", ftrace);
-	for (ifp = ifnet; ifp != 0; ifp = ifp->int_next)
+	LIST_FOREACH(ifp, &ifnet, int_list) 
 		trace_if("", ifp);
 	(void)rn_walktree(rhead, walk_trace, 0);
 }


More information about the svn-src-all mailing list