-/* $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 $ */
/*
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 *);
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
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;
}
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);
/*
* 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)
/*
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);
}
/*
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)
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) {
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 */
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);
{
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;
"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)
-/* $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 $ */
/*
#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 */
};
#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);
-/* $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 $ */
/*
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);
}
}
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);
}
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);
}
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);
}
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;
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);
-/* $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 $ */
/*
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;
}
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 {
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);
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);
}
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);
}
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);
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;
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;
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));
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));
-/* $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 $ */
/*
* 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);
la_hold_total--;
m_freem(m);
}
- Free((caddr_t)la);
+ free(la, M_RTABLE);
}
}
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) {
-/* $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 $ */
/*
* 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");
}
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 */
rt->rt_flags &= ~RTF_LLINFO;
if (ln->ln_hold)
m_freem(ln->ln_hold);
- Free((caddr_t)ln);
+ free(ln, M_RTABLE);
}
}
-/* $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 $ */
/*
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);
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);
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);