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)
This commit is contained in:
Robert Watson 2003-08-20 17:09:01 +00:00
parent a19f8dda70
commit 6c4b2ad305
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=119180
2 changed files with 23 additions and 27 deletions

View File

@ -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);
}

View File

@ -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;
};
/*