aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2009-04-05 14:01:39 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2009-04-05 14:01:39 +0000
commit38ae65235e00a1e87239372f973d057aeff1f2d8 (patch)
tree941da68a6a83f1d57f1b0b6cf171466b57b6d190 /sbin
parent3b3e61faa1eed8e917926c8c74a4acbe709e1dd2 (diff)
downloadsrc-38ae65235e00a1e87239372f973d057aeff1f2d8.tar.gz
src-38ae65235e00a1e87239372f973d057aeff1f2d8.zip
Use <sys/queue.h> to manage the interface list.
Notes
Notes: svn path=/head/; revision=190711
Diffstat (limited to 'sbin')
-rw-r--r--sbin/routed/defs.h6
-rw-r--r--sbin/routed/if.c38
-rw-r--r--sbin/routed/main.c12
-rw-r--r--sbin/routed/output.c4
-rw-r--r--sbin/routed/parms.c2
-rw-r--r--sbin/routed/rdisc.c6
-rw-r--r--sbin/routed/table.c6
-rw-r--r--sbin/routed/trace.c2
8 files changed, 35 insertions, 41 deletions
diff --git a/sbin/routed/defs.h b/sbin/routed/defs.h
index ff6e8ab6b01e..9c44bbda679a 100644
--- a/sbin/routed/defs.h
+++ b/sbin/routed/defs.h
@@ -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; /* time to check interfaces */
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;
diff --git a/sbin/routed/if.c b/sbin/routed/if.c
index 09b03afe5de4..77277d95876b 100644
--- a/sbin/routed/if.c
+++ b/sbin/routed/if.c
@@ -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 network byte order */
* 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, so network byte order */
{
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.
diff --git a/sbin/routed/main.c b/sbin/routed/main.c
index a70e66f61239..570f2e03dadf 100644
--- a/sbin/routed/main.c
+++ b/sbin/routed/main.c
@@ -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);
}
diff --git a/sbin/routed/output.c b/sbin/routed/output.c
index a8f092b08b76..f89db5ddd74e 100644
--- a/sbin/routed/output.c
+++ b/sbin/routed/output.c
@@ -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
diff --git a/sbin/routed/parms.c b/sbin/routed/parms.c
index 356ac8e9da36..f7cbf9bf4ae9 100644
--- a/sbin/routed/parms.c
+++ b/sbin/routed/parms.c
@@ -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++;
diff --git a/sbin/routed/rdisc.c b/sbin/routed/rdisc.c
index 496f212601d5..8452650ca88d 100644
--- a/sbin/routed/rdisc.c
+++ b/sbin/routed/rdisc.c
@@ -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;
diff --git a/sbin/routed/table.c b/sbin/routed/table.c
index 9fd4cb816a1c..7e30ebd1595c 100644
--- a/sbin/routed/table.c
+++ b/sbin/routed/table.c
@@ -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;
diff --git a/sbin/routed/trace.c b/sbin/routed/trace.c
index 320056f76c8f..574b65c19a96 100644
--- a/sbin/routed/trace.c
+++ b/sbin/routed/trace.c
@@ -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);
}