diff options
author | 2015-10-22 15:37:47 +0000 | |
---|---|---|
committer | 2015-10-22 15:37:47 +0000 | |
commit | c7b7b779a1a65d391467ec9504adbab88ccea96d (patch) | |
tree | 2fd4870ad35da77bf29098637713164b2a6380e8 /sys/netinet6 | |
parent | Final removal of EXTERN. (diff) | |
download | wireguard-openbsd-c7b7b779a1a65d391467ec9504adbab88ccea96d.tar.xz wireguard-openbsd-c7b7b779a1a65d391467ec9504adbab88ccea96d.zip |
Inspired by satosin(), use inline functions to convert sockaddr dl.
Instead of casts they check wether the incoming object has the
expected type. So introduce satosdl() and sdltosa() in the kernel.
OK mpi@
Diffstat (limited to 'sys/netinet6')
-rw-r--r-- | sys/netinet6/icmp6.c | 4 | ||||
-rw-r--r-- | sys/netinet6/in6_ifattach.c | 4 | ||||
-rw-r--r-- | sys/netinet6/nd6.c | 17 | ||||
-rw-r--r-- | sys/netinet6/nd6_nbr.c | 14 | ||||
-rw-r--r-- | sys/netinet6/nd6_rtr.c | 4 |
5 files changed, 18 insertions, 25 deletions
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 42dc651222d..4f7034cbb84 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.173 2015/10/19 12:11:28 mpi Exp $ */ +/* $OpenBSD: icmp6.c,v 1.174 2015/10/22 15:37:47 bluhm Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -1693,7 +1693,7 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt) if ((nrt != NULL) && (nrt->rt_flags & (RTF_GATEWAY|RTF_LLINFO)) == RTF_LLINFO && (nrt->rt_gateway->sa_family == AF_LINK) && - (sdl = (struct sockaddr_dl *)nrt->rt_gateway) && + (sdl = satosdl(nrt->rt_gateway)) && sdl->sdl_alen) { nd_opt = (struct nd_opt_hdr *)p; nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR; diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index 461e2a381b7..ef4ed7a871f 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_ifattach.c,v 1.96 2015/09/12 20:50:17 mpi Exp $ */ +/* $OpenBSD: in6_ifattach.c,v 1.97 2015/10/22 15:37:47 bluhm Exp $ */ /* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */ /* @@ -144,7 +144,7 @@ get_hw_ifid(struct ifnet *ifp, struct in6_addr *in6) static u_int8_t allone[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - sdl = (struct sockaddr_dl *)ifp->if_sadl; + sdl = ifp->if_sadl; if (sdl == NULL || sdl->sdl_alen == 0) return -1; diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 0083b44acad..41be0601bff 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.156 2015/10/22 10:27:22 mpi Exp $ */ +/* $OpenBSD: nd6.c,v 1.157 2015/10/22 15:37:47 bluhm Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -64,8 +64,6 @@ #define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */ #define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */ -#define SDL(s) ((struct sockaddr_dl *)s) - /* timer values */ int nd6_prune = 1; /* walk list every 1 seconds */ int nd6_delay = 5; /* delay first probe time 5 second */ @@ -608,7 +606,7 @@ nd6_purge(struct ifnet *ifp) rt = ln->ln_rt; if (rt && rt->rt_gateway && rt->rt_gateway->sa_family == AF_LINK) { - sdl = (struct sockaddr_dl *)rt->rt_gateway; + sdl = satosdl(rt->rt_gateway); if (sdl->sdl_index == ifp->if_index) nln = nd6_free(rt, 0); } @@ -669,8 +667,7 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp, bzero(&info, sizeof(info)); info.rti_flags = RTF_HOST | RTF_LLINFO; info.rti_info[RTAX_DST] = sin6tosa(&sin6); - info.rti_info[RTAX_GATEWAY] = - (struct sockaddr *)ifp->if_sadl; + info.rti_info[RTAX_GATEWAY] = sdltosa(ifp->if_sadl); error = rtrequest1(RTM_ADD, &info, RTP_CONNECTED, &rt, rtableid); if (error) @@ -1023,8 +1020,8 @@ nd6_rtrequest(int req, struct rtentry *rt) __func__, ifp->if_xname); break; } - SDL(gate)->sdl_type = ifp->if_type; - SDL(gate)->sdl_index = ifp->if_index; + satosdl(gate)->sdl_type = ifp->if_type; + satosdl(gate)->sdl_index = ifp->if_index; if (ln != NULL) break; /* This happens on a route change */ /* @@ -1360,7 +1357,7 @@ fail: goto fail; if (rt->rt_gateway->sa_family != AF_LINK) goto fail; - sdl = SDL(rt->rt_gateway); + sdl = satosdl(rt->rt_gateway); olladdr = (sdl->sdl_alen) ? 1 : 0; if (olladdr && lladdr) { @@ -1765,7 +1762,7 @@ nd6_storelladdr(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m, m_freem(m); return (EINVAL); } - sdl = SDL(rt->rt_gateway); + sdl = satosdl(rt->rt_gateway); if (sdl->sdl_alen != ETHER_ADDR_LEN) { char addr[INET6_ADDRSTRLEN]; log(LOG_DEBUG, "%s: %s: incorrect nd6 information\n", __func__, diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index c578e844b8f..9a0694b03c6 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_nbr.c,v 1.96 2015/09/18 14:26:22 mpi Exp $ */ +/* $OpenBSD: nd6_nbr.c,v 1.97 2015/10/22 15:37:47 bluhm Exp $ */ /* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */ /* @@ -61,8 +61,6 @@ #include <netinet/ip_carp.h> #endif -#define SDL(s) ((struct sockaddr_dl *)s) - TAILQ_HEAD(dadq_head, dadq); struct dadq { TAILQ_ENTRY(dadq) dad_list; @@ -242,7 +240,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) IN6_IFF_NOTREADY | IN6_IFF_ANYCAST)->ia_ifa; if (ifa) { proxy = 1; - proxydl = SDL(rt->rt_gateway); + proxydl = satosdl(rt->rt_gateway); router = 0; /* XXX */ } } @@ -317,7 +315,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) nd6_na_output(ifp, &saddr6, &taddr6, ((anycast || proxy || !tlladdr) ? 0 : ND_NA_FLAG_OVERRIDE) | (router ? ND_NA_FLAG_ROUTER : 0), - tlladdr, (struct sockaddr *)proxydl); + tlladdr, sdltosa(proxydl)); goto freeit; } @@ -326,7 +324,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) nd6_na_output(ifp, &saddr6, &taddr6, ((anycast || proxy || !tlladdr) ? 0 : ND_NA_FLAG_OVERRIDE) | (router ? ND_NA_FLAG_ROUTER : 0) | ND_NA_FLAG_SOLICITED, - tlladdr, (struct sockaddr *)proxydl); + tlladdr, sdltosa(proxydl)); freeit: m_freem(m); if_put(ifp); @@ -711,7 +709,7 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len) rt = nd6_lookup(&taddr6, 0, ifp, ifp->if_rdomain); if ((rt == NULL) || ((ln = (struct llinfo_nd6 *)rt->rt_llinfo) == NULL) || - ((sdl = SDL(rt->rt_gateway)) == NULL)) + ((sdl = satosdl(rt->rt_gateway)) == NULL)) goto freeit; if (ln->ln_state == ND6_LLINFO_INCOMPLETE) { @@ -1033,7 +1031,7 @@ nd6_na_output(struct ifnet *ifp, struct in6_addr *daddr6, mac = nd6_ifptomac(ifp); } else if (sdl0->sa_family == AF_LINK) { struct sockaddr_dl *sdl; - sdl = (struct sockaddr_dl *)sdl0; + sdl = satosdl(sdl0); if (sdl->sdl_alen == ifp->if_addrlen) mac = LLADDR(sdl); } diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 4bc7686c840..6e85e6c3893 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.125 2015/09/18 14:26:22 mpi Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.126 2015/10/22 15:37:47 bluhm Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -58,8 +58,6 @@ #include <netinet6/nd6.h> #include <netinet/icmp6.h> -#define SDL(s) ((struct sockaddr_dl *)s) - int rtpref(struct nd_defrouter *); struct nd_defrouter *defrtrlist_update(struct nd_defrouter *); struct in6_ifaddr *in6_ifadd(struct nd_prefix *, int); |