-/* $OpenBSD: if.c,v 1.390 2015/10/22 10:46:26 mpi Exp $ */
+/* $OpenBSD: if.c,v 1.391 2015/10/22 15:37:47 bluhm Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
case SIOCSIFLLADDR:
if ((error = suser(p, 0)))
return (error);
- sdl = (struct sockaddr_dl *)ifp->if_sadl;
+ sdl = ifp->if_sadl;
if (sdl == NULL)
return (EINVAL);
if (ifr->ifr_addr.sa_len != ETHER_ADDR_LEN)
-/* $OpenBSD: if_dl.h,v 1.9 2015/09/15 09:13:33 guenther Exp $ */
+/* $OpenBSD: if_dl.h,v 1.10 2015/10/22 15:37:47 bluhm Exp $ */
/* $NetBSD: if_dl.h,v 1.8 1995/03/26 20:30:13 jtc Exp $ */
/*
#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
-#ifndef _KERNEL
+#ifdef _KERNEL
+
+static __inline struct sockaddr_dl *
+satosdl(struct sockaddr *sa)
+{
+ return ((struct sockaddr_dl *)(sa));
+}
+
+static __inline struct sockaddr *
+sdltosa(struct sockaddr_dl *sdl)
+{
+ return ((struct sockaddr *)(sdl));
+}
+
+#else /* _KERNEL */
__BEGIN_DECLS
char *link_ntoa(const struct sockaddr_dl *);
-/* $OpenBSD: if_enc.c,v 1.60 2015/03/14 03:38:51 jsg Exp $ */
+/* $OpenBSD: if_enc.c,v 1.61 2015/10/22 15:37:47 bluhm Exp $ */
/*
* Copyright (c) 2010 Reyk Floeter <reyk@vantronix.net>
#include <sys/mbuf.h>
#include <net/if.h>
+#include <net/if_dl.h>
#include <net/if_var.h>
#include <net/if_enc.h>
#include <net/if_types.h>
if_alloc_sadl(ifp);
sc->sc_ifa.ifa_ifp = ifp;
sc->sc_ifa.ifa_rtrequest = link_rtrequest;
- sc->sc_ifa.ifa_addr = (struct sockaddr *)ifp->if_sadl;
+ sc->sc_ifa.ifa_addr = sdltosa(ifp->if_sadl);
sc->sc_ifa.ifa_netmask = NULL;
#if NBPFILTER > 0
-/* $OpenBSD: if_ethersubr.c,v 1.228 2015/09/29 10:11:40 deraadt Exp $ */
+/* $OpenBSD: if_ethersubr.c,v 1.229 2015/10/22 15:37:47 bluhm Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */
/*
switch (dst->sa_family) {
case AF_LINK:
- if (((struct sockaddr_dl *)dst)->sdl_alen <
- sizeof(edst))
+ if (satosdl(dst)->sdl_alen < sizeof(edst))
senderr(EHOSTUNREACH);
- memcpy(edst, LLADDR((struct sockaddr_dl *)dst),
+ memcpy(edst, LLADDR(satosdl(dst)),
sizeof(edst));
break;
case AF_INET:
-/* $OpenBSD: if_mpe.c,v 1.47 2015/09/12 20:50:17 mpi Exp $ */
+/* $OpenBSD: if_mpe.c,v 1.48 2015/10/22 15:37:47 bluhm Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@spootnik.org>
#include <sys/ioctl.h>
#include <net/if.h>
+#include <net/if_dl.h>
#include <net/if_var.h>
#include <net/if_types.h>
#include <net/netisr.h>
mpeif->sc_ifa.ifa_ifp = ifp;
mpeif->sc_ifa.ifa_rtrequest = link_rtrequest;
- mpeif->sc_ifa.ifa_addr = (struct sockaddr *) ifp->if_sadl;
+ mpeif->sc_ifa.ifa_addr = sdltosa(ifp->if_sadl);
mpeif->sc_smpls.smpls_len = sizeof(mpeif->sc_smpls);
mpeif->sc_smpls.smpls_family = AF_MPLS;
-/* $OpenBSD: if_mpw.c,v 1.6 2015/09/12 20:50:17 mpi Exp $ */
+/* $OpenBSD: if_mpw.c,v 1.7 2015/10/22 15:37:47 bluhm Exp $ */
/*
* Copyright (c) 2015 Rafael Zalamena <rzalamena@openbsd.org>
#include <sys/errno.h>
#include <net/if.h>
+#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/route.h>
sc->sc_ifa.ifa_ifp = ifp;
sc->sc_ifa.ifa_rtrequest = link_rtrequest;
- sc->sc_ifa.ifa_addr = (struct sockaddr *) ifp->if_sadl;
+ sc->sc_ifa.ifa_addr = sdltosa(ifp->if_sadl);
sc->sc_smpls.smpls_len = sizeof(sc->sc_smpls);
sc->sc_smpls.smpls_family = AF_MPLS;
-/* $OpenBSD: route.c,v 1.254 2015/10/21 08:21:06 mpi Exp $ */
+/* $OpenBSD: route.c,v 1.255 2015/10/22 15:37:47 bluhm Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
info.rti_info[RTAX_LABEL] = rtlabel_id2sa(rt->rt_labelid, &sa_rl);
if (rt->rt_ifp != NULL) {
- info.rti_info[RTAX_IFP] =(struct sockaddr *)rt->rt_ifp->if_sadl;
+ info.rti_info[RTAX_IFP] = sdltosa(rt->rt_ifp->if_sadl);
info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
}
}
if (ifa == NULL) {
if (gateway->sa_family == AF_LINK) {
- struct sockaddr_dl *sdl = (struct sockaddr_dl *)gateway;
+ struct sockaddr_dl *sdl = satosdl(gateway);
struct ifnet *ifp = if_get(sdl->sdl_index);
if (ifp != NULL)
if (info->rti_info[RTAX_IFP] != NULL) {
struct sockaddr_dl *sdl;
- sdl = (struct sockaddr_dl *)info->rti_info[RTAX_IFP];
+ sdl = satosdl(info->rti_info[RTAX_IFP]);
ifp = if_get(sdl->sdl_index);
}
info->rti_flags = rt->rt_flags | (RTF_CLONED|RTF_HOST);
info->rti_flags &= ~(RTF_CLONING|RTF_CONNECTED|RTF_STATIC);
- info->rti_info[RTAX_GATEWAY] = (struct sockaddr *)&sa_dl;
+ info->rti_info[RTAX_GATEWAY] = sdltosa(&sa_dl);
info->rti_info[RTAX_LABEL] =
rtlabel_id2sa(rt->rt_labelid, &sa_rl2);
/* FALLTHROUGH */
info.rti_flags = flags | RTF_MPATH;
info.rti_info[RTAX_DST] = dst;
if (flags & RTF_LLINFO)
- info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)ifp->if_sadl;
+ info.rti_info[RTAX_GATEWAY] = sdltosa(ifp->if_sadl);
else
info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
info.rti_info[RTAX_LABEL] = rtlabel_id2sa(ifp->if_rtlabelid, &sa_rl);
-/* $OpenBSD: rtsock.c,v 1.171 2015/09/21 11:27:08 mpi Exp $ */
+/* $OpenBSD: rtsock.c,v 1.172 2015/10/22 15:37:47 bluhm Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
#include <sys/protosw.h>
#include <net/if.h>
+#include <net/if_dl.h>
#include <net/if_var.h>
#include <net/route.h>
#include <net/raw_cb.h>
info.rti_info[RTAX_IFA] = NULL;
if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA) &&
(ifp = rt->rt_ifp) != NULL) {
- info.rti_info[RTAX_IFP] =
- (struct sockaddr *)ifp->if_sadl;
+ info.rti_info[RTAX_IFP] = sdltosa(ifp->if_sadl);
info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
if (ifp->if_flags & IFF_POINTOPOINT)
info.rti_info[RTAX_BRD] =
memset(&info, 0, sizeof(info));
info.rti_info[RTAX_IFA] = ifa->ifa_addr;
- info.rti_info[RTAX_IFP] = (struct sockaddr *)ifp->if_sadl;
+ info.rti_info[RTAX_IFP] = sdltosa(ifp->if_sadl);
info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
if ((m = rt_msg1(cmd, &info)) == NULL)
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
if (rt->rt_ifp) {
- info.rti_info[RTAX_IFP] =
- (struct sockaddr *)rt->rt_ifp->if_sadl;
+ info.rti_info[RTAX_IFP] = sdltosa(rt->rt_ifp->if_sadl);
info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
if (rt->rt_ifp->if_flags & IFF_POINTOPOINT)
info.rti_info[RTAX_BRD] = rt->rt_ifa->ifa_dstaddr;
if (w->w_arg && w->w_arg != ifp->if_index)
continue;
/* Copy the link-layer address first */
- info.rti_info[RTAX_IFP] = (struct sockaddr *)ifp->if_sadl;
+ info.rti_info[RTAX_IFP] = sdltosa(ifp->if_sadl);
len = rt_msg2(RTM_IFINFO, RTM_VERSION, &info, 0, w);
if (w->w_where && w->w_tmem && w->w_needed <= 0) {
struct if_msghdr *ifm;
-/* $OpenBSD: if_ether.c,v 1.173 2015/10/22 13:30:29 mpi Exp $ */
+/* $OpenBSD: if_ether.c,v 1.174 2015/10/22 15:37:47 bluhm Exp $ */
/* $NetBSD: if_ether.c,v 1.31 1996/05/11 12:59:58 mycroft Exp $ */
/*
#include <net/if_bridge.h>
#endif
-#define SDL(s) ((struct sockaddr_dl *)s)
-
/*
* ARP trailer negotiation. Trailer protocol is not IP specific,
* but ARP request/response use IP addresses.
arprequest(ifp,
&satosin(rt_key(rt))->sin_addr.s_addr,
&satosin(rt_key(rt))->sin_addr.s_addr,
- (u_char *)LLADDR(SDL(gate)));
+ (u_char *)LLADDR(satosdl(gate)));
/*FALLTHROUGH*/
case RTM_RESOLVE:
if (gate->sa_family != AF_LINK ||
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 (la != 0)
break; /* This happens on a route change */
/*
}
if (la == NULL || rt == NULL)
goto bad;
- sdl = SDL(rt->rt_gateway);
+ sdl = satosdl(rt->rt_gateway);
if (sdl->sdl_alen > 0 && sdl->sdl_alen != ETHER_ADDR_LEN) {
log(LOG_DEBUG, "%s: %s: incorrect arp information\n", __func__,
inet_ntop(AF_INET, &satosin(dst)->sin_addr,
}
rt = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0,
rtable_l2(m->m_pkthdr.ph_rtableid));
- if (rt != NULL && (sdl = SDL(rt->rt_gateway)) != NULL) {
+ if (rt != NULL && (sdl = satosdl(rt->rt_gateway)) != NULL) {
la = (struct llinfo_arp *)rt->rt_llinfo;
if (sdl->sdl_alen) {
if (memcmp(ea->arp_sha, LLADDR(sdl), sdl->sdl_alen)) {
if (rt->rt_ifp->if_type == IFT_CARP && ifp->if_type != IFT_CARP)
goto out;
memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
- sdl = SDL(rt->rt_gateway);
+ sdl = satosdl(rt->rt_gateway);
memcpy(ea->arp_sha, LLADDR(sdl), sizeof(ea->arp_sha));
rtfree(rt);
}
arptfree(struct rtentry *rt)
{
struct llinfo_arp *la = (struct llinfo_arp *)rt->rt_llinfo;
- struct sockaddr_dl *sdl = SDL(rt->rt_gateway);
+ struct sockaddr_dl *sdl = satosdl(rt->rt_gateway);
if ((sdl != NULL) && (sdl->sdl_family == AF_LINK)) {
sdl->sdl_alen = 0;
return (0);
/* Check that arp information are correct. */
- sdl = (struct sockaddr_dl *)rt->rt_gateway;
+ sdl = satosdl(rt->rt_gateway);
if (sdl->sdl_alen != ETHER_ADDR_LEN) {
rtfree(rt);
return (0);
-/* $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 $ */
/*
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;
-/* $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 $ */
/*
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;
-/* $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 $ */
/*
#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 */
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);
}
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)
__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 */
/*
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) {
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__,
-/* $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 $ */
/*
#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;
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 */
}
}
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;
}
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);
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) {
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);
}
-/* $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 $ */
/*
#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);