diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-01-10 14:29:09 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-01-10 14:29:09 +0000 |
commit | 516cde13c43142bb82ac64ccd3ca0e5f5513c488 (patch) | |
tree | 48caa1a97b1e6e37c460a09b9a27454fd0de7ebb | |
parent | 069b4d43595c0715c1476f22c97d78b56c0306f5 (diff) |
replace the rest of the obsolete radix macros
sprinkle 0 -> NULL where obvious
ok millert mpi
-rw-r--r-- | sys/net/radix.c | 66 | ||||
-rw-r--r-- | sys/net/radix.h | 19 | ||||
-rw-r--r-- | sys/net/route.c | 16 | ||||
-rw-r--r-- | sys/net/rtsock.c | 32 | ||||
-rw-r--r-- | sys/netinet/if_ether.c | 14 | ||||
-rw-r--r-- | sys/netinet6/nd6.c | 7 | ||||
-rw-r--r-- | sys/netinet6/nd6_rtr.c | 20 |
7 files changed, 83 insertions, 91 deletions
diff --git a/sys/net/radix.c b/sys/net/radix.c index 15ffac833d5..a8f74b00929 100644 --- a/sys/net/radix.c +++ b/sys/net/radix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radix.c,v 1.33 2014/01/09 21:57:51 tedu Exp $ */ +/* $OpenBSD: radix.c,v 1.34 2014/01/10 14:29:08 tedu Exp $ */ /* $NetBSD: radix.c,v 1.20 2003/08/07 16:32:56 agc Exp $ */ /* @@ -64,8 +64,6 @@ static char normal_chars[] = {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, -1}; static char *rn_zeros, *rn_ones; #define rn_masktop (mask_rnhead->rnh_treetop) -#undef Bcmp -#define Bcmp(a, b, l) (l == 0 ? 0 : bcmp((caddr_t)(a), (caddr_t)(b), (u_long)l)) static int rn_satisfies_leaf(char *, struct radix_node *, int); static int rn_lexobetter(void *, void *); @@ -78,6 +76,20 @@ struct radix_node *rn_newpair(void *, int, struct radix_node[2]); struct radix_node *rn_search(void *, struct radix_node *); struct radix_node *rn_search_m(void *, struct radix_node *, void *); +#define MKGet(m) do { \ + if (rn_mkfreelist) { \ + m = rn_mkfreelist; \ + rn_mkfreelist = (m)->rm_mklist; \ + } else \ + m = malloc(sizeof (*(m)), M_RTABLE, M_NOWAIT); \ +} while (0) + +#define MKFree(m) do { \ + (m)->rm_mklist = rn_mkfreelist; \ + rn_mkfreelist = (m); \ +} while (0) + + /* * The data structure for the keys is a radix tree with one way * branching removed. The index rn_b at an internal node n represents a bit @@ -176,7 +188,8 @@ rn_lookup(void *v_arg, void *m_arg, struct radix_node_head *head) caddr_t netmask = 0; if (m_arg) { - if ((x = rn_addmask(m_arg, 1, head->rnh_treetop->rn_off)) == 0) + x = rn_addmask(m_arg, 1, head->rnh_treetop->rn_off); + if (x == NULL) return (0); netmask = x->rn_key; } @@ -195,7 +208,7 @@ rn_satisfies_leaf(char *trial, struct radix_node *leaf, int skip) char *cplim; int length = min(*(u_char *)cp, *(u_char *)cp2); - if (cp3 == 0) + if (cp3 == NULL) cp3 = rn_ones; else length = min(length, *(u_char *)cp3); @@ -261,7 +274,8 @@ on1: /* * If there is a host route in a duped-key chain, it will be first. */ - if ((saved_t = t)->rn_mask == 0) + saved_t = t; + if (t->rn_mask == NULL) t = t->rn_dupedkey; for (; t; t = t->rn_dupedkey) /* @@ -434,23 +448,22 @@ rn_addmask(void *n_arg, int search, int skip) return (mask_rnhead->rnh_nodes); } if (m0 < last_zeroed) - Bzero(addmask_key + m0, last_zeroed - m0); + memset(addmask_key + m0, 0, last_zeroed - m0); *addmask_key = last_zeroed = mlen; x = rn_search(addmask_key, rn_masktop); - if (Bcmp(addmask_key, x->rn_key, mlen) != 0) + if (memcmp(addmask_key, x->rn_key, mlen) != 0) x = 0; if (x || search) return (x); - R_Malloc(x, struct radix_node *, max_keylen + 2 * sizeof (*x)); - if ((saved_x = x) == 0) + x = malloc(max_keylen + 2 * sizeof (*x), M_RTABLE, M_NOWAIT | M_ZERO); + if ((saved_x = x) == NULL) return (0); - Bzero(x, max_keylen + 2 * sizeof (*x)); netmask = cp = (caddr_t)(x + 2); - memmove(cp, addmask_key, mlen); + memcpy(cp, addmask_key, mlen); x = rn_insert(cp, mask_rnhead, &maskduplicated, x); if (maskduplicated) { log(LOG_ERR, "rn_addmask: mask impossibly already in tree\n"); - Free(saved_x); + free(saved_x, M_RTABLE); return (x); } /* @@ -501,11 +514,11 @@ rn_new_radix_mask(struct radix_node *tt, struct radix_mask *next) struct radix_mask *m; MKGet(m); - if (m == 0) { + if (m == NULL) { log(LOG_ERR, "Mask for route not entered\n"); return (0); } - Bzero(m, sizeof *m); + memset(m, 0, sizeof *m); m->rm_b = tt->rn_b; m->rm_flags = tt->rn_flags; if (tt->rn_flags & RNF_NORMAL) @@ -770,28 +783,28 @@ rn_delete(void *v_arg, void *netmask_arg, struct radix_node_head *head, vlen = *(u_char *)v; saved_tt = tt; top = x; - if (tt == 0 || - Bcmp(v + head_off, tt->rn_key + head_off, vlen - head_off)) + if (tt == NULL || + memcmp(v + head_off, tt->rn_key + head_off, vlen - head_off)) return (0); /* * Delete our route from mask lists. */ if (netmask) { - if ((x = rn_addmask(netmask, 1, head_off)) == 0) + if ((x = rn_addmask(netmask, 1, head_off)) == NULL) return (0); netmask = x->rn_key; while (tt->rn_mask != netmask) - if ((tt = tt->rn_dupedkey) == 0) + if ((tt = tt->rn_dupedkey) == NULL) return (0); } #ifndef SMALL_KERNEL if (rn) { while (tt != rn) - if ((tt = tt->rn_dupedkey) == 0) + if ((tt = tt->rn_dupedkey) == NULL) return (0); } #endif - if (tt->rn_mask == 0 || (saved_m = m = tt->rn_mklist) == 0) + if (tt->rn_mask == NULL || (saved_m = m = tt->rn_mklist) == NULL) goto on1; if (tt->rn_flags & RNF_NORMAL) { if (m->rm_leaf != tt && m->rm_refs == 0) { @@ -838,7 +851,7 @@ rn_delete(void *v_arg, void *netmask_arg, struct radix_node_head *head, MKFree(m); break; } - if (m == 0) { + if (m == NULL) { log(LOG_ERR, "rn_delete: couldn't find our annotation\n"); if (tt->rn_flags & RNF_NORMAL) return (0); /* Dangling ref to us */ @@ -1008,8 +1021,8 @@ rn_inithead(void **head, int off) if (*head) return (1); - R_Malloc(rnh, struct radix_node_head *, sizeof (*rnh)); - if (rnh == 0) + rnh = malloc(sizeof(*rnh), M_RTABLE, M_NOWAIT); + if (rnh == NULL) return (0); *head = rnh; return rn_inithead0(rnh, off); @@ -1020,7 +1033,7 @@ rn_inithead0(struct radix_node_head *rnh, int off) { struct radix_node *t, *tt, *ttt; - Bzero(rnh, sizeof (*rnh)); + memset(rnh, 0, sizeof(*rnh)); t = rn_newpair(rn_zeros, off, rnh->rnh_nodes); ttt = rnh->rnh_nodes + 2; t->rn_r = ttt; @@ -1055,10 +1068,9 @@ rn_init() "rn_init: radix functions require max_keylen be set\n"); return; } - R_Malloc(rn_zeros, char *, 3 * max_keylen); + rn_zeros = malloc(3 * max_keylen, M_RTABLE, M_NOWAIT | M_ZERO); if (rn_zeros == NULL) panic("rn_init"); - Bzero(rn_zeros, 3 * max_keylen); rn_ones = cp = rn_zeros + max_keylen; addmask_key = cplim = rn_ones + max_keylen; while (cp < cplim) diff --git a/sys/net/radix.h b/sys/net/radix.h index e8f27581714..4d7c54577ad 100644 --- a/sys/net/radix.h +++ b/sys/net/radix.h @@ -1,4 +1,4 @@ -/* $OpenBSD: radix.h,v 1.21 2014/01/09 21:57:51 tedu Exp $ */ +/* $OpenBSD: radix.h,v 1.22 2014/01/10 14:29:08 tedu Exp $ */ /* $NetBSD: radix.h,v 1.8 1996/02/13 22:00:37 christos Exp $ */ /* @@ -93,19 +93,6 @@ extern struct radix_mask { #define rm_mask rm_rmu.rmu_mask #define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */ -#define MKGet(m) do { \ - if (rn_mkfreelist) { \ - m = rn_mkfreelist; \ - rn_mkfreelist = (m)->rm_mklist; \ - } else \ - R_Malloc(m, struct radix_mask *, sizeof (*(m))); \ -} while (0) - -#define MKFree(m) do { \ - (m)->rm_mklist = rn_mkfreelist; \ - rn_mkfreelist = (m); \ -} while (0) - struct radix_node_head { struct radix_node *rnh_treetop; int rnh_addrsize; /* permit, but not require fixed keys */ @@ -132,10 +119,6 @@ struct radix_node_head { }; #ifdef _KERNEL -#define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n)) -#define Bzero(p, n) bzero((caddr_t)(p), (unsigned)(n)); -#define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_NOWAIT)) -#define Free(p) free((caddr_t)p, M_RTABLE); void rn_init(void); int rn_inithead(void **, int); diff --git a/sys/net/route.c b/sys/net/route.c index 8097142d49b..b024f73c6de 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.148 2014/01/09 21:57:52 tedu Exp $ */ +/* $OpenBSD: route.c,v 1.149 2014/01/10 14:29:08 tedu Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -406,7 +406,7 @@ rtfree(struct rtentry *rt) if (rt->rt_flags & RTF_MPLS) free(rt->rt_llinfo, M_TEMP); #endif - Free(rt_key(rt)); + free(rt_key(rt), M_RTABLE); pool_put(&rtentry_pool, rt); } } @@ -853,7 +853,7 @@ rtrequest1(int req, struct rt_addrinfo *info, u_int8_t prio, info->rti_flags & RTF_MPATH)) { if (rt->rt_gwroute) rtfree(rt->rt_gwroute); - Free(rt_key(rt)); + free(rt_key(rt), M_RTABLE); pool_put(&rtentry_pool, rt); senderr(EEXIST); } @@ -884,13 +884,13 @@ rtrequest1(int req, struct rt_addrinfo *info, u_int8_t prio, sa_mpls = (struct sockaddr_mpls *) info->rti_info[RTAX_SRC]; - rt->rt_llinfo = (caddr_t)malloc(sizeof(struct rt_mpls), + rt->rt_llinfo = malloc(sizeof(struct rt_mpls), M_TEMP, M_NOWAIT|M_ZERO); if (rt->rt_llinfo == NULL) { if (rt->rt_gwroute) rtfree(rt->rt_gwroute); - Free(rt_key(rt)); + free(rt_key(rt), M_RTABLE); pool_put(&rtentry_pool, rt); senderr(ENOMEM); } @@ -960,7 +960,7 @@ rtrequest1(int req, struct rt_addrinfo *info, u_int8_t prio, rtfree(rt->rt_parent); if (rt->rt_gwroute) rtfree(rt->rt_gwroute); - Free(rt_key(rt)); + free(rt_key(rt), M_RTABLE); pool_put(&rtentry_pool, rt); senderr(EEXIST); } @@ -1006,7 +1006,7 @@ rt_setgate(struct rtentry *rt, struct sockaddr *dst, struct sockaddr *gate, if (rt->rt_gateway == NULL || glen > ROUNDUP(rt->rt_gateway->sa_len)) { old = (caddr_t)rt_key(rt); - R_Malloc(new, caddr_t, dlen + glen); + new = malloc(dlen + glen, M_RTABLE, M_NOWAIT); if (new == NULL) return 1; rt->rt_nodes->rn_key = new; @@ -1018,7 +1018,7 @@ rt_setgate(struct rtentry *rt, struct sockaddr *dst, struct sockaddr *gate, memmove(rt->rt_gateway, gate, glen); if (old) { memmove(new, dst, dlen); - Free(old); + free(old, M_RTABLE); } if (rt->rt_gwroute != NULL) { RTFREE(rt->rt_gwroute); diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index e46f1c3f259..3926fd83808 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.132 2014/01/09 21:57:52 tedu Exp $ */ +/* $OpenBSD: rtsock.c,v 1.133 2014/01/10 14:29:08 tedu Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -514,8 +514,8 @@ route_output(struct mbuf *m, ...) error = EMSGSIZE; goto fail; } - R_Malloc(rtm, struct rt_msghdr *, len); - if (rtm == 0) { + rtm = malloc(len, M_RTABLE, M_NOWAIT); + if (rtm == NULL) { error = ENOBUFS; goto fail; } @@ -598,7 +598,7 @@ route_output(struct mbuf *m, ...) t = rn_addmask(genmask, 0, 1); if (t && genmask->sa_len >= ((struct sockaddr *)t->rn_key)->sa_len && - Bcmp((caddr_t *)genmask + 1, (caddr_t *)t->rn_key + 1, + memcmp((caddr_t *)genmask + 1, (caddr_t *)t->rn_key + 1, ((struct sockaddr *)t->rn_key)->sa_len) - 1) genmask = (struct sockaddr *)(t->rn_key); else { @@ -762,13 +762,14 @@ report: NULL); if (len > rtm->rtm_msglen) { struct rt_msghdr *new_rtm; - R_Malloc(new_rtm, struct rt_msghdr *, len); - if (new_rtm == 0) { + new_rtm = malloc(len, M_RTABLE, M_NOWAIT); + if (new_rtm == NULL) { error = ENOBUFS; goto flush; } memcpy(new_rtm, rtm, rtm->rtm_msglen); - Free(rtm); rtm = new_rtm; + free(rtm, M_RTABLE); + rtm = new_rtm; } rt_msg2(rtm->rtm_type, RTM_VERSION, &info, (caddr_t)rtm, NULL); @@ -831,7 +832,7 @@ report: info.rti_info[RTAX_SRC]; if (rt->rt_llinfo == NULL) { - rt->rt_llinfo = (caddr_t) + rt->rt_llinfo = malloc(sizeof(struct rt_mpls), M_TEMP, M_NOWAIT|M_ZERO); } @@ -916,8 +917,7 @@ flush: if (!(so->so_options & SO_USELOOPBACK)) { if (route_cb.any_count <= 1) { fail: - if (rtm) - Free(rtm); + free(rtm, M_RTABLE); m_freem(m); return (error); } @@ -944,7 +944,7 @@ fail: m = NULL; } else if (m->m_pkthdr.len > rtm->rtm_msglen) m_adj(m, rtm->rtm_msglen - m->m_pkthdr.len); - Free(rtm); + free(rtm, M_RTABLE); } if (m) route_input(m, &route_proto, &route_src, &route_dst); @@ -1114,8 +1114,7 @@ again: rw->w_needed += len; if (rw->w_needed <= 0 && rw->w_where) { if (rw->w_tmemsize < len) { - if (rw->w_tmem) - free(rw->w_tmem, M_RTABLE); + free(rw->w_tmem, M_RTABLE); rw->w_tmem = malloc(len, M_RTABLE, M_NOWAIT); if (rw->w_tmem) rw->w_tmemsize = len; @@ -1558,8 +1557,7 @@ sysctl_rtable(int *name, u_int namelen, void *where, size_t *given, void *new, return (error); } splx(s); - if (w.w_tmem) - free(w.w_tmem, M_RTABLE); + free(w.w_tmem, M_RTABLE); w.w_needed += w.w_given; if (where) { *given = w.w_where - (caddr_t)where; @@ -1579,7 +1577,7 @@ rtmsg_4to5(struct mbuf *m, int *len) struct rt_omsghdr ortm; *len += sizeof(struct rt_msghdr) - sizeof(struct rt_omsghdr); - R_Malloc(rtm, struct rt_msghdr *, *len); + rtm = malloc(*len, M_RTABLE, M_NOWAIT); if (rtm == NULL) return (NULL); bzero(rtm, sizeof(struct rt_msghdr)); @@ -1622,7 +1620,7 @@ rtmsg_5to4(struct rt_msghdr *rtm) len = rtm->rtm_msglen + sizeof(struct rt_omsghdr) - sizeof(struct rt_msghdr); - R_Malloc(ortm, struct rt_omsghdr *, len); + ortm = malloc(len, M_RTABLE, M_NOWAIT); if (ortm == NULL) return (NULL); bzero(ortm, sizeof(struct rt_omsghdr)); diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index 2b8fa15f28b..a5655821f4e 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ether.c,v 1.116 2014/01/09 21:57:52 tedu Exp $ */ +/* $OpenBSD: if_ether.c,v 1.117 2014/01/10 14:29:08 tedu Exp $ */ /* $NetBSD: if_ether.c,v 1.31 1996/05/11 12:59:58 mycroft Exp $ */ /* @@ -216,14 +216,14 @@ arp_rtrequest(int req, struct rtentry *rt) * Case 2: This route may come from cloning, or a manual route * add with a LL address. */ - R_Malloc(la, struct llinfo_arp *, sizeof(*la)); + la = malloc(sizeof(*la), M_RTABLE, M_NOWAIT | M_ZERO); rt->rt_llinfo = (caddr_t)la; - if (la == 0) { + if (la == NULL) { log(LOG_DEBUG, "arp_rtrequest: malloc failed\n"); break; } - arp_inuse++, arp_allocated++; - Bzero(la, sizeof(*la)); + arp_inuse++; + arp_allocated++; la->la_rt = rt; rt->rt_flags |= RTF_LLINFO; LIST_INSERT_HEAD(&llinfo_arp, la, la_list); @@ -284,7 +284,7 @@ arp_rtrequest(int req, struct rtentry *rt) la_hold_total--; m_freem(m); } - Free((caddr_t)la); + free(la, M_RTABLE); } } @@ -772,7 +772,7 @@ arptfree(struct llinfo_arp *la) struct rt_addrinfo info; u_int tid = 0; - if (rt == 0) + if (rt == NULL) panic("arptfree"); if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) && sdl->sdl_family == AF_LINK) { diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 87606c4da3c..03a8bf648ed 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.107 2014/01/09 21:57:52 tedu Exp $ */ +/* $OpenBSD: nd6.c,v 1.108 2014/01/10 14:29:08 tedu Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -1080,7 +1080,7 @@ nd6_rtrequest(int req, struct rtentry *rt) * Case 2: This route may come from cloning, or a manual route * add with a LL address. */ - R_Malloc(ln, struct llinfo_nd6 *, sizeof(*ln)); + ln = malloc(sizeof(*ln), M_RTABLE, M_NOWAIT | M_ZERO); rt->rt_llinfo = (caddr_t)ln; if (!ln) { log(LOG_DEBUG, "nd6_rtrequest: malloc failed\n"); @@ -1088,7 +1088,6 @@ nd6_rtrequest(int req, struct rtentry *rt) } nd6_inuse++; nd6_allocated++; - Bzero(ln, sizeof(*ln)); ln->ln_rt = rt; timeout_set(&ln->ln_timer_ch, nd6_llinfo_timer, ln); /* this is required for "ndp" command. - shin */ @@ -1232,7 +1231,7 @@ nd6_rtrequest(int req, struct rtentry *rt) rt->rt_flags &= ~RTF_LLINFO; if (ln->ln_hold) m_freem(ln->ln_hold); - Free((caddr_t)ln); + free(ln, M_RTABLE); } } diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 2b0d123f792..5779c4ab37e 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.75 2014/01/07 17:07:46 mikeb Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.76 2014/01/10 14:29:08 tedu Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -242,7 +242,7 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len) struct nd_defrouter dr0; u_int32_t advreachable = nd_ra->nd_ra_reachable; - Bzero(&dr0, sizeof(dr0)); + memset(&dr0, 0, sizeof(dr0)); dr0.rtaddr = saddr6; dr0.flags = nd_ra->nd_ra_flags_reserved; dr0.rtlifetime = ntohs(nd_ra->nd_ra_router_lifetime); @@ -455,10 +455,10 @@ defrouter_addreq(struct nd_defrouter *new) int s; int error; - Bzero(&def, sizeof(def)); - Bzero(&mask, sizeof(mask)); - Bzero(&gate, sizeof(gate)); /* for safety */ - Bzero(&info, sizeof(info)); + memset(&def, 0, sizeof(def)); + memset(&mask, 0, sizeof(mask)); + memset(&gate, 0, sizeof(gate)); /* for safety */ + memset(&info, 0, sizeof(info)); def.sin6_len = mask.sin6_len = gate.sin6_len = sizeof(struct sockaddr_in6); @@ -560,10 +560,10 @@ defrouter_delreq(struct nd_defrouter *dr) panic("dr == NULL in defrouter_delreq"); #endif - Bzero(&info, sizeof(info)); - Bzero(&def, sizeof(def)); - Bzero(&mask, sizeof(mask)); - Bzero(&gw, sizeof(gw)); /* for safety */ + memset(&info, 0, sizeof(info)); + memset(&def, 0, sizeof(def)); + memset(&mask, 0, sizeof(mask)); + memset(&gw, 0, sizeof(gw)); /* for safety */ def.sin6_len = mask.sin6_len = gw.sin6_len = sizeof(struct sockaddr_in6); |