diff options
author | rwatson <rwatson@FreeBSD.org> | 2003-08-20 17:09:01 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2003-08-20 17:09:01 +0000 |
commit | 606a0352a58a53667a9af4588472a0002575ba1a (patch) | |
tree | 96dc58dc003bfab3398ac1c3bbe36adeaad337f9 | |
parent | d7f84d803459d4a77abedf57f27d98ab99f7b5c9 (diff) | |
download | FreeBSD-src-606a0352a58a53667a9af4588472a0002575ba1a.zip FreeBSD-src-606a0352a58a53667a9af4588472a0002575ba1a.tar.gz |
Move from a custom-crafted singly-linked list to the SLIST_* macros
from queue(3).
Improve vertical compactness by using a IGMP_PRINTF() macro rather
than #ifdefing IGMP_DEBUG a large number of debugging printfs.
Reviewed by: mdodd (SLIST changes)
-rw-r--r-- | sys/netinet/igmp.c | 48 | ||||
-rw-r--r-- | sys/netinet/in_var.h | 2 |
2 files changed, 23 insertions, 27 deletions
diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c index 929d456..4e75d622 100644 --- a/sys/netinet/igmp.c +++ b/sys/netinet/igmp.c @@ -88,10 +88,16 @@ static int igmp_timers_are_running; static u_long igmp_all_hosts_group; static u_long igmp_all_rtrs_group; static struct mbuf *router_alert; -static struct router_info *Head; +static SLIST_HEAD(, router_info) router_info_head; static void igmp_sendpkt(struct in_multi *, int, unsigned long); +#ifdef IGMP_DEBUG +#define IGMP_PRINTF(x) printf(x) +#else +#define IGMP_PRINTF(x) +#endif + void igmp_init() { @@ -117,36 +123,31 @@ igmp_init() ra->ipopt_list[3] = 0x00; router_alert->m_len = sizeof(ra->ipopt_dst) + ra->ipopt_list[1]; - Head = (struct router_info *) 0; + SLIST_INIT(&router_info_head); } static struct router_info * find_rti(ifp) struct ifnet *ifp; { - register struct router_info *rti = Head; + struct router_info *rti; -#ifdef IGMP_DEBUG - printf("[igmp.c, _find_rti] --> entering \n"); -#endif - while (rti) { - if (rti->rti_ifp == ifp) { -#ifdef IGMP_DEBUG - printf("[igmp.c, _find_rti] --> found old entry \n"); -#endif + rti = SLIST_FIRST(&router_info_head); + IGMP_PRINTF("[igmp.c, _find_rti] --> entering \n"); + SLIST_FOREACH(rti, &router_info_head, rti_list) { + if (rti->rti_ifp == ifp) { + IGMP_PRINTF( + "[igmp.c, _find_rti] --> found old entry \n"); return rti; } - rti = rti->rti_next; } MALLOC(rti, struct router_info *, sizeof *rti, M_IGMP, M_NOWAIT); rti->rti_ifp = ifp; rti->rti_type = IGMP_V2_ROUTER; rti->rti_time = 0; - rti->rti_next = Head; - Head = rti; -#ifdef IGMP_DEBUG - printf("[igmp.c, _find_rti] --> created an entry \n"); -#endif + SLIST_INSERT_HEAD(&router_info_head, rti, rti_list); + + IGMP_PRINTF("[igmp.c, _find_rti] --> created an entry \n"); return rti; } @@ -412,23 +413,18 @@ void igmp_slowtimo() { int s = splnet(); - register struct router_info *rti = Head; + struct router_info *rti; -#ifdef IGMP_DEBUG - printf("[igmp.c,_slowtimo] -- > entering \n"); -#endif - while (rti) { + IGMP_PRINTF("[igmp.c,_slowtimo] -- > entering \n"); + SLIST_FOREACH(rti, &router_info_head, rti_list) { if (rti->rti_type == IGMP_V1_ROUTER) { rti->rti_time++; if (rti->rti_time >= IGMP_AGE_THRESHOLD) { rti->rti_type = IGMP_V2_ROUTER; } } - rti = rti->rti_next; } -#ifdef IGMP_DEBUG - printf("[igmp.c,_slowtimo] -- > exiting \n"); -#endif + IGMP_PRINTF("[igmp.c,_slowtimo] -- > exiting \n"); splx(s); } diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h index c3ff684..d1b818c 100644 --- a/sys/netinet/in_var.h +++ b/sys/netinet/in_var.h @@ -140,7 +140,7 @@ struct router_info { struct ifnet *rti_ifp; int rti_type; /* type of router which is querier on this interface */ int rti_time; /* # of slow timeouts since last old query */ - struct router_info *rti_next; + SLIST_ENTRY(router_info) rti_list; }; /* |