diff options
author | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2008-04-23 10:17:51 +0000 |
---|---|---|
committer | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2008-04-23 10:17:51 +0000 |
commit | c2bd86fcf91d1dc754b836bc3830b8dc96aca040 (patch) | |
tree | eb5071fee2f1bc199fdd9ee81d708cc7a6b1fe1e /usr.sbin | |
parent | bfe419bcccde4cdfa4c1c826447c0295171f35c3 (diff) |
Replace handrolled lists with SLISTs or TAILQs.
Timers remain and will be handled later.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rtadvd/config.c | 25 | ||||
-rw-r--r-- | usr.sbin/rtadvd/dump.c | 10 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rrenum.c | 5 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.c | 82 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.h | 14 |
5 files changed, 66 insertions, 70 deletions
diff --git a/usr.sbin/rtadvd/config.c b/usr.sbin/rtadvd/config.c index b344b51f13a..d536071c278 100644 --- a/usr.sbin/rtadvd/config.c +++ b/usr.sbin/rtadvd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.25 2008/04/21 20:40:55 rainer Exp $ */ +/* $OpenBSD: config.c,v 1.26 2008/04/23 10:17:50 pyr Exp $ */ /* $KAME: config.c,v 1.62 2002/05/29 10:13:10 itojun Exp $ */ /* @@ -66,7 +66,7 @@ static void makeentry(char *, size_t, int, char *); static int getinet6sysctl(int); -extern struct rainfo *ralist; +extern struct ralist ralist; void getconfig(intface) @@ -105,12 +105,11 @@ getconfig(intface) " Treat it as default", intface); } - tmp = (struct rainfo *)malloc(sizeof(*ralist)); - if (tmp == NULL) + if ((tmp = calloc(1, sizeof(*tmp))) == NULL) fatal("malloc"); - memset(tmp, 0, sizeof(*tmp)); - tmp->prefix.next = tmp->prefix.prev = &tmp->prefix; + TAILQ_INIT(&tmp->prefixes); + SLIST_INIT(&tmp->soliciters); /* check if we are allowed to forward packets (if not determined) */ if (forwarding < 0) { @@ -247,7 +246,7 @@ getconfig(intface) memset(pfx, 0, sizeof(*pfx)); /* link into chain */ - insque(pfx, &tmp->prefix); + TAILQ_INSERT_TAIL(&tmp->prefixes, pfx, entry); tmp->pfxs++; pfx->origin = PREFIX_FROM_CONFIG; @@ -351,8 +350,7 @@ getconfig(intface) log_info("route information option is not available"); /* okey */ - tmp->next = ralist; - ralist = tmp; + SLIST_INSERT_HEAD(&ralist, tmp, entry); /* construct the sending packet */ make_packet(tmp); @@ -430,7 +428,7 @@ get_prefix(struct rainfo *rai) pp->origin = PREFIX_FROM_KERNEL; /* link into chain */ - insque(pp, &rai->prefix); + TAILQ_INSERT_TAIL(&rai->prefixes, pp, entry); /* counter increment */ rai->pfxs++; @@ -479,7 +477,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr) prefix->autoconfflg = ipr->ipr_raf_auto; prefix->origin = PREFIX_FROM_DYNAMIC; - insque(prefix, &rai->prefix); + TAILQ_INSERT_TAIL(&rai->prefixes, prefix, entry); log_debug("new prefix %s/%d was added on %s", inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, @@ -512,7 +510,7 @@ delete_prefix(struct rainfo *rai, struct prefix *prefix) { u_char ntopbuf[INET6_ADDRSTRLEN]; - remque(prefix); + TAILQ_REMOVE(&rai->prefixes, prefix, entry); log_debug("prefix %s/%d was deleted on %s", inet_ntop(AF_INET6, &prefix->prefix, ntopbuf, INET6_ADDRSTRLEN), prefix->prefixlen, rai->ifname); @@ -667,8 +665,7 @@ make_packet(struct rainfo *rainfo) - for (pfx = rainfo->prefix.next; - pfx != &rainfo->prefix; pfx = pfx->next) { + TAILQ_FOREACH(pfx, &rainfo->prefixes, entry) { u_int32_t vltime, pltime; struct timeval now; diff --git a/usr.sbin/rtadvd/dump.c b/usr.sbin/rtadvd/dump.c index d6263f79935..2c06a58fa0c 100644 --- a/usr.sbin/rtadvd/dump.c +++ b/usr.sbin/rtadvd/dump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dump.c,v 1.7 2008/04/21 20:40:55 rainer Exp $ */ +/* $OpenBSD: dump.c,v 1.8 2008/04/23 10:17:50 pyr Exp $ */ /* $KAME: dump.c,v 1.27 2002/05/29 14:23:55 itojun Exp $ */ /* @@ -59,7 +59,7 @@ static FILE *fp; -extern struct rainfo *ralist; +extern struct ralist ralist; static char *ether_str(struct sockaddr_dl *); static void if_dump(void); @@ -98,7 +98,7 @@ if_dump() struct timeval now; gettimeofday(&now, NULL); /* XXX: unused in most cases */ - for (rai = ralist; rai; rai = rai->next) { + SLIST_FOREACH(rai, &ralist, entry) { fprintf(fp, "%s:\n", rai->ifname); fprintf(fp, " Status: %s\n", @@ -151,8 +151,8 @@ if_dump() if (rai->clockskew) fprintf(fp, " Clock skew: %ldsec\n", rai->clockskew); - for (first = 1, pfx = rai->prefix.next; pfx != &rai->prefix; - pfx = pfx->next) { + first = 1; + TAILQ_FOREACH(pfx, &rai->prefixes, entry) { if (first) { fprintf(fp, " Prefixes:\n"); first = 0; diff --git a/usr.sbin/rtadvd/rrenum.c b/usr.sbin/rtadvd/rrenum.c index 4664ff2baad..08783e6a173 100644 --- a/usr.sbin/rtadvd/rrenum.c +++ b/usr.sbin/rtadvd/rrenum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rrenum.c,v 1.11 2008/04/21 20:40:55 rainer Exp $ */ +/* $OpenBSD: rrenum.c,v 1.12 2008/04/23 10:17:50 pyr Exp $ */ /* $KAME: rrenum.c,v 1.11 2002/05/21 14:26:55 itojun Exp $ */ /* @@ -200,8 +200,7 @@ do_use_prefix(int len, struct rr_pco_match *rpm, if ((rai = if_indextorainfo(ifindex)) == NULL) continue; /* non-advertising IF */ - for (pp = rai->prefix.next; pp != &rai->prefix; - pp = pp->next) { + TAILQ_FOREACH(pp, &rai->prefixes, entry) { struct timeval now; if (prefix_match(&pp->prefix, pp->prefixlen, diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c index 7640c8793b5..88e19cfec24 100644 --- a/usr.sbin/rtadvd/rtadvd.c +++ b/usr.sbin/rtadvd/rtadvd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtadvd.c,v 1.32 2008/04/21 20:40:55 rainer Exp $ */ +/* $OpenBSD: rtadvd.c,v 1.33 2008/04/23 10:17:50 pyr Exp $ */ /* $KAME: rtadvd.c,v 1.66 2002/05/29 14:18:36 itojun Exp $ */ /* @@ -88,11 +88,13 @@ int log_perror = 0; u_char *conffile = NULL; -struct rainfo *ralist = NULL; -struct nd_optlist { - struct nd_optlist *next; - struct nd_opt_hdr *opt; +struct ralist ralist; + +struct nd_opt { + SLIST_ENTRY(nd_opt) entry; + struct nd_opt_hdr *opt; }; + union nd_opts { struct nd_opt_hdr *nd_opt_array[9]; struct { @@ -102,7 +104,7 @@ union nd_opts { struct nd_opt_prefix_info *pi; struct nd_opt_rd_hdr *rh; struct nd_opt_mtu *mtu; - struct nd_optlist *list; + SLIST_HEAD(nd_optlist, nd_opt) list; } nd_opt_each; }; #define nd_opts_src_lladdr nd_opt_each.src_lladdr @@ -189,6 +191,8 @@ main(argc, argv) exit(1); } + SLIST_INIT(&ralist); + /* timer initialization */ rtadvd_timer_init(); @@ -300,12 +304,12 @@ die() if (dflag) log_debug("cease to be an advertising router"); - for (ra = ralist; ra; ra = ra->next) { + SLIST_FOREACH(ra, &ralist, entry) { ra->lifetime = 0; make_packet(ra); } for (i = 0; i < retrans; i++) { - for (ra = ralist; ra; ra = ra->next) + SLIST_FOREACH(ra, &ralist, entry) ra_output(ra); sleep(MIN_DELAY_BETWEEN_RAS); } @@ -657,6 +661,7 @@ rs_input(int len, struct nd_router_solicit *rs, /* ND option check */ memset(&ndopts, 0, sizeof(ndopts)); + SLIST_INIT(&ndopts.nd_opts_list); if (nd6_options((struct nd_opt_hdr *)(rs + 1), len - sizeof(struct nd_router_solicit), &ndopts, NDOPT_FLAG_SRCLINKADDR)) { @@ -680,11 +685,9 @@ rs_input(int len, struct nd_router_solicit *rs, goto done; } - ra = ralist; - while (ra != NULL) { + SLIST_FOREACH(ra, &ralist, entry) { if (pi->ipi6_ifindex == ra->ifindex) break; - ra = ra->next; } if (ra == NULL) { log_info("RS received on non advertising interface(%s)", @@ -711,8 +714,7 @@ rs_input(int len, struct nd_router_solicit *rs, sol->addr = *from; /*XXX RFC2553 need clarification on flowinfo */ sol->addr.sin6_flowinfo = 0; - sol->next = ra->soliciter; - ra->soliciter = sol; + SLIST_INSERT_HEAD(&ra->soliciters, sol, entry); } /* @@ -781,6 +783,7 @@ ra_input(int len, struct nd_router_advert *ra, /* ND option check */ memset(&ndopts, 0, sizeof(ndopts)); + SLIST_INIT(&ndopts.nd_opts_list); if (nd6_options((struct nd_opt_hdr *)(ra + 1), len - sizeof(struct nd_router_advert), &ndopts, NDOPT_FLAG_SRCLINKADDR | @@ -875,16 +878,15 @@ ra_input(int len, struct nd_router_advert *ra, } /* Preferred and Valid Lifetimes for prefixes */ { - struct nd_optlist *optp = ndopts.nd_opts_list; + struct nd_opt *optp; if (ndopts.nd_opts_pi) if (prefix_check(ndopts.nd_opts_pi, rai, from)) inconsistent++; - while (optp) { + SLIST_FOREACH(optp, &ndopts.nd_opts_list, entry) { if (prefix_check((struct nd_opt_prefix_info *)optp->opt, rai, from)) inconsistent++; - optp = optp->next; } } @@ -1018,7 +1020,7 @@ find_prefix(struct rainfo *rai, struct in6_addr *prefix, int plen) int bytelen, bitlen; u_char bitmask; - for (pp = rai->prefix.next; pp != &rai->prefix; pp = pp->next) { + TAILQ_FOREACH(pp, &rai->prefixes, entry) { if (plen != pp->prefixlen) continue; bytelen = plen / 8; @@ -1123,20 +1125,20 @@ nd6_options(struct nd_opt_hdr *hdr, int limit, break; case ND_OPT_PREFIX_INFORMATION: { - struct nd_optlist *pfxlist; - + struct nd_opt *pfx; + if (ndopts->nd_opts_pi == 0) { ndopts->nd_opts_pi = (struct nd_opt_prefix_info *)hdr; continue; } - if ((pfxlist = malloc(sizeof(*pfxlist))) == NULL) { + if ((pfx = malloc(sizeof(*pfx))) == NULL) { log_warn("malloc"); goto bad; } - pfxlist->next = ndopts->nd_opts_list; - pfxlist->opt = hdr; - ndopts->nd_opts_list = pfxlist; + + pfx->opt = hdr; + SLIST_INSERT_HEAD(&ndopts->nd_opts_list, pfx, entry); break; } @@ -1156,21 +1158,21 @@ nd6_options(struct nd_opt_hdr *hdr, int limit, static void free_ndopts(union nd_opts *ndopts) { - struct nd_optlist *opt = ndopts->nd_opts_list, *next; + struct nd_opt *opt; - while (opt) { - next = opt->next; + while (!SLIST_EMPTY(&ndopts->nd_opts_list)) { + opt = SLIST_FIRST(&ndopts->nd_opts_list); + SLIST_REMOVE_HEAD(&ndopts->nd_opts_list, entry); free(opt); - opt = next; } } void sock_open() { + struct rainfo *ra; struct icmp6_filter filt; struct ipv6_mreq mreq; - struct rainfo *ra = ralist; int on; /* XXX: should be max MTU attached to the node */ static u_char answer[1500]; @@ -1218,16 +1220,17 @@ sock_open() &mreq.ipv6mr_multiaddr.s6_addr) != 1) fatal("inet_pton failed(library bug?)"); - while (ra) { + SLIST_FOREACH(ra, &ralist, entry) { mreq.ipv6mr_interface = ra->ifindex; if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0) { log_warn("IPV6_JOIN_GROUP(link) on %s", ra->ifname); exit(1); } - ra = ra->next; } + ra = SLIST_FIRST(&ralist); + /* * When attending router renumbering, join all-routers site-local * multicast group. @@ -1244,11 +1247,11 @@ sock_open() exit(1); } } else - mreq.ipv6mr_interface = ralist->ifindex; + mreq.ipv6mr_interface = ra->ifindex; if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0) { log_warn("IPV6_JOIN_GROUP(site) on %s", - mcastif ? mcastif : ralist->ifname); + mcastif ? mcastif : ra->ifname); exit(1); } } @@ -1284,9 +1287,9 @@ rtsock_open() struct rainfo * if_indextorainfo(int index) { - struct rainfo *rai = ralist; + struct rainfo *rai; - for (rai = ralist; rai; rai = rai->next) { + SLIST_FOREACH(rai, &ralist, entry) { if (rai->ifindex == index) return(rai); } @@ -1301,7 +1304,7 @@ struct rainfo *rainfo; int i; struct cmsghdr *cm; struct in6_pktinfo *pi; - struct soliciter *sol, *nextsol; + struct soliciter *sol; if ((iflist[rainfo->ifindex]->ifm_flags & IFF_UP) == 0) { log_debug("%s is not up, skip sending RA", rainfo->ifname); @@ -1348,9 +1351,9 @@ struct rainfo *rainfo; * XXX commented out. reason: though spec does not forbit it, unicast * advert does not really help */ - for (sol = rainfo->soliciter; sol; sol = nextsol) { - nextsol = sol->next; - + while (!SLIST_EMPTY(&rainfo->soliciters)) { + sol = SLIST_FIRST(&rainfo->soliciters); + SLIST_REMOVE_HEAD(&rainfo->soliciters, entry); #if 0 sndmhdr.msg_name = (caddr_t)&sol->addr; i = sendmsg(sock, &sndmhdr, 0); @@ -1359,11 +1362,8 @@ struct rainfo *rainfo; log_warn("unicast sendmsg on %s", rainfo->ifname); #endif - - sol->next = NULL; free(sol); } - rainfo->soliciter = NULL; /* update counter */ if (rainfo->initcounter < MAX_INITIAL_RTR_ADVERTISEMENTS) diff --git a/usr.sbin/rtadvd/rtadvd.h b/usr.sbin/rtadvd/rtadvd.h index 403d0e991d9..6d4b941a5c5 100644 --- a/usr.sbin/rtadvd/rtadvd.h +++ b/usr.sbin/rtadvd/rtadvd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rtadvd.h,v 1.9 2002/05/29 14:34:05 itojun Exp $ */ +/* $OpenBSD: rtadvd.h,v 1.10 2008/04/23 10:17:50 pyr Exp $ */ /* $KAME: rtadvd.h,v 1.20 2002/05/29 10:13:10 itojun Exp $ */ /* @@ -67,8 +67,7 @@ #define PREFIX_FROM_DYNAMIC 3 struct prefix { - struct prefix *next; /* forward link */ - struct prefix *prev; /* previous link */ + TAILQ_ENTRY(prefix) entry; u_int32_t validlifetime; /* AdvValidLifetime */ long vltimeexpire; /* expiration of vltime; decrement case only */ @@ -83,13 +82,13 @@ struct prefix { struct soliciter { - struct soliciter *next; + SLIST_ENTRY(soliciter) entry; struct sockaddr_in6 addr; }; struct rainfo { /* pointer for list */ - struct rainfo *next; + SLIST_ENTRY(rainfo) entry; /* timer related parameters */ struct rtadvd_timer *timer; @@ -115,7 +114,7 @@ struct rainfo { u_int32_t reachabletime; /* AdvReachableTime */ u_int32_t retranstimer; /* AdvRetransTimer */ u_int hoplimit; /* AdvCurHopLimit */ - struct prefix prefix; /* AdvPrefixList(link head) */ + TAILQ_HEAD(prefixlist, prefix) prefixes; /* AdvPrefixList(link head) */ int pfxs; /* number of prefixes */ long clockskew; /* used for consisitency check of lifetimes */ @@ -131,8 +130,9 @@ struct rainfo { u_quad_t rsinput; /* number of RSs received */ /* info about soliciter */ - struct soliciter *soliciter; /* recent solication source */ + SLIST_HEAD(, soliciter) soliciters; /* recent solication source */ }; +SLIST_HEAD(ralist, rainfo); void ra_timeout(void *); void ra_timer_update(void *, struct timeval *); |