From 7566c552e54be591cd5c3a70836b713a8da75698 Mon Sep 17 00:00:00 2001 From: Alexander Bluhm Date: Thu, 4 May 2017 15:00:25 +0000 Subject: Introduce sstosa() for converting sockaddr_storage with a type safe inline function instead of casting it to sockaddr. While there, use inline instead of __inline for all these conversions. Some struct sockaddr casts can be avoided completely. OK dhill@ mpi@ --- sys/net/bpf.c | 6 +++--- sys/net/bridgectl.c | 4 ++-- sys/net/if.c | 4 ++-- sys/net/if_dl.h | 6 +++--- sys/net/if_gif.c | 14 +++++--------- sys/net/if_mpe.c | 4 ++-- sys/net/if_mpw.c | 9 ++++----- sys/net/if_pppx.c | 4 ++-- sys/net/if_vxlan.c | 17 ++++++++--------- sys/net/pf.c | 6 +++--- sys/net/pipex.c | 12 +++++------- sys/net/pipex_local.h | 3 ++- sys/netinet/in.c | 13 ++++++------- sys/netinet/in.h | 8 ++++---- sys/netinet/ip_ipip.c | 5 ++--- sys/netinet/tcp_subr.c | 5 ++--- sys/netinet6/in6.c | 13 ++++++------- sys/netinet6/in6.h | 8 ++++---- sys/sys/socket.h | 10 +++++++++- 19 files changed, 74 insertions(+), 77 deletions(-) (limited to 'sys') diff --git a/sys/net/bpf.c b/sys/net/bpf.c index f71eff16e3c..eba0501de7c 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.161 2017/04/20 14:13:00 visa Exp $ */ +/* $OpenBSD: bpf.c,v 1.162 2017/05/04 15:00:24 bluhm Exp $ */ /* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */ /* @@ -610,7 +610,7 @@ bpfwrite(dev_t dev, struct uio *uio, int ioflag) dlt = d->bd_bif->bif_dlt; - error = bpf_movein(uio, dlt, &m, (struct sockaddr *)&dst, fcode); + error = bpf_movein(uio, dlt, &m, sstosa(&dst), fcode); if (error) goto out; @@ -627,7 +627,7 @@ bpfwrite(dev_t dev, struct uio *uio, int ioflag) dst.ss_family = pseudo_AF_HDRCMPLT; NET_LOCK(s); - error = ifp->if_output(ifp, m, (struct sockaddr *)&dst, NULL); + error = ifp->if_output(ifp, m, sstosa(&dst), NULL); NET_UNLOCK(s); out: diff --git a/sys/net/bridgectl.c b/sys/net/bridgectl.c index 9d80fb3fb1a..86949163bf8 100644 --- a/sys/net/bridgectl.c +++ b/sys/net/bridgectl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bridgectl.c,v 1.5 2017/01/11 08:47:48 mpi Exp $ */ +/* $OpenBSD: bridgectl.c,v 1.6 2017/05/04 15:00:24 bluhm Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -479,7 +479,7 @@ bridge_rtfind(struct bridge_softc *sc, struct ifbaconf *baconf) bcopy(&n->brt_addr, &bareq.ifba_dst, sizeof(bareq.ifba_dst)); bridge_copyaddr(&n->brt_tunnel.brtag_peer.sa, - (struct sockaddr *)&bareq.ifba_dstsa); + sstosa(&bareq.ifba_dstsa)); bareq.ifba_age = n->brt_age; bareq.ifba_flags = n->brt_flags; error = copyout((caddr_t)&bareq, diff --git a/sys/net/if.c b/sys/net/if.c index 3e95ef495dc..ef0c7e172b1 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.493 2017/04/14 15:11:31 bluhm Exp $ */ +/* $OpenBSD: if.c,v 1.494 2017/05/04 15:00:24 bluhm Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -1325,7 +1325,7 @@ if_congested(void) #define equal(a1, a2) \ (bcmp((caddr_t)(a1), (caddr_t)(a2), \ - ((struct sockaddr *)(a1))->sa_len) == 0) + (a1)->sa_len) == 0) /* * Locate an interface based on a complete address. diff --git a/sys/net/if_dl.h b/sys/net/if_dl.h index d0c3d05f041..229cdad5ace 100644 --- a/sys/net/if_dl.h +++ b/sys/net/if_dl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_dl.h,v 1.11 2017/01/24 10:08:30 krw Exp $ */ +/* $OpenBSD: if_dl.h,v 1.12 2017/05/04 15:00:24 bluhm Exp $ */ /* $NetBSD: if_dl.h,v 1.8 1995/03/26 20:30:13 jtc Exp $ */ /* @@ -73,13 +73,13 @@ struct sockaddr_dl { #ifdef _KERNEL -static __inline struct sockaddr_dl * +static inline struct sockaddr_dl * satosdl(struct sockaddr *sa) { return ((struct sockaddr_dl *)(sa)); } -static __inline struct sockaddr * +static inline struct sockaddr * sdltosa(struct sockaddr_dl *sdl) { return ((struct sockaddr *)(sdl)); diff --git a/sys/net/if_gif.c b/sys/net/if_gif.c index 71e7d5b25ea..c28a089d632 100644 --- a/sys/net/if_gif.c +++ b/sys/net/if_gif.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_gif.c,v 1.93 2017/04/14 20:50:35 bluhm Exp $ */ +/* $OpenBSD: if_gif.c,v 1.94 2017/05/04 15:00:24 bluhm Exp $ */ /* $KAME: if_gif.c,v 1.43 2001/02/20 08:51:07 itojun Exp $ */ /* @@ -358,10 +358,8 @@ gif_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) break; #endif case SIOCSLIFPHYADDR: - src = (struct sockaddr *) - &(((struct if_laddrreq *)data)->addr); - dst = (struct sockaddr *) - &(((struct if_laddrreq *)data)->dstaddr); + src = sstosa(&(((struct if_laddrreq *)data)->addr)); + dst = sstosa(&(((struct if_laddrreq *)data)->dstaddr)); break; default: return (EINVAL); @@ -557,8 +555,7 @@ gif_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) /* copy src */ src = sc->gif_psrc; - dst = (struct sockaddr *) - &(((struct if_laddrreq *)data)->addr); + dst = sstosa(&(((struct if_laddrreq *)data)->addr)); size = sizeof(((struct if_laddrreq *)data)->addr); if (src->sa_len > size) return (EINVAL); @@ -566,8 +563,7 @@ gif_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) /* copy dst */ src = sc->gif_pdst; - dst = (struct sockaddr *) - &(((struct if_laddrreq *)data)->dstaddr); + dst = sstosa(&(((struct if_laddrreq *)data)->dstaddr)); size = sizeof(((struct if_laddrreq *)data)->dstaddr); if (src->sa_len > size) return (EINVAL); diff --git a/sys/net/if_mpe.c b/sys/net/if_mpe.c index cfd89dd9a26..5586a30f54a 100644 --- a/sys/net/if_mpe.c +++ b/sys/net/if_mpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_mpe.c,v 1.58 2017/01/24 10:08:30 krw Exp $ */ +/* $OpenBSD: if_mpe.c,v 1.59 2017/05/04 15:00:24 bluhm Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard @@ -139,7 +139,7 @@ void mpestart(struct ifnet *ifp0) { struct mbuf *m; - struct sockaddr *sa = (struct sockaddr *)&mpedst; + struct sockaddr *sa = sstosa(&mpedst); sa_family_t af; struct rtentry *rt; struct ifnet *ifp; diff --git a/sys/net/if_mpw.c b/sys/net/if_mpw.c index ba963281a6e..e9fada6c395 100644 --- a/sys/net/if_mpw.c +++ b/sys/net/if_mpw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_mpw.c,v 1.20 2017/03/02 03:09:50 renato Exp $ */ +/* $OpenBSD: if_mpw.c,v 1.21 2017/05/04 15:00:24 bluhm Exp $ */ /* * Copyright (c) 2015 Rafael Zalamena @@ -379,8 +379,7 @@ mpw_start(struct ifnet *ifp) return; } - rt = rtalloc((struct sockaddr *)&sc->sc_nexthop, RT_RESOLVE, - ifp->if_rdomain); + rt = rtalloc(sstosa(&sc->sc_nexthop), RT_RESOLVE, ifp->if_rdomain); if (!rtisvalid(rt)) { IFQ_PURGE(&ifp->if_snd); goto rtfree; @@ -397,7 +396,7 @@ mpw_start(struct ifnet *ifp) * the right place. */ memcpy(&ss, &sc->sc_nexthop, sizeof(sc->sc_nexthop)); - ((struct sockaddr *)&ss)->sa_family = AF_MPLS; + ss.ss_family = AF_MPLS; while ((m = ifq_dequeue(&ifp->if_snd)) != NULL) { #if NBPFILTER > 0 @@ -438,7 +437,7 @@ mpw_start(struct ifnet *ifp) m->m_pkthdr.ph_rtableid = ifp->if_rdomain; - mpls_output(p, m, (struct sockaddr *)&ss, rt); + mpls_output(p, m, sstosa(&ss), rt); } if_put(p); diff --git a/sys/net/if_pppx.c b/sys/net/if_pppx.c index 8153eb84e69..dacbc678740 100644 --- a/sys/net/if_pppx.c +++ b/sys/net/if_pppx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pppx.c,v 1.57 2017/01/24 10:08:30 krw Exp $ */ +/* $OpenBSD: if_pppx.c,v 1.58 2017/05/04 15:00:24 bluhm Exp $ */ /* * Copyright (c) 2010 Claudio Jeker @@ -855,7 +855,7 @@ pppx_add_session(struct pppx_dev *pxd, struct pipex_session_req *req) case PIPEX_PROTO_PPTP: case PIPEX_PROTO_L2TP: chain = PIPEX_PEER_ADDR_HASHTABLE( - pipex_sockaddr_hash_key((struct sockaddr *)&session->peer)); + pipex_sockaddr_hash_key(&session->peer.sa)); LIST_INSERT_HEAD(chain, session, peer_addr_chain); break; } diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c index 1f6928cd292..ec28e4a9754 100644 --- a/sys/net/if_vxlan.c +++ b/sys/net/if_vxlan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vxlan.c,v 1.59 2017/04/11 14:43:49 dhill Exp $ */ +/* $OpenBSD: if_vxlan.c,v 1.60 2017/05/04 15:00:24 bluhm Exp $ */ /* * Copyright (c) 2013 Reyk Floeter @@ -334,8 +334,8 @@ vxlan_config(struct ifnet *ifp, struct sockaddr *src, struct sockaddr *dst) } else { /* Reset current configuration */ af = sc->sc_src.ss_family; - src = (struct sockaddr *)&sc->sc_src; - dst = (struct sockaddr *)&sc->sc_dst; + src = sstosa(&sc->sc_src); + dst = sstosa(&sc->sc_dst); reset = 1; } @@ -418,8 +418,8 @@ vxlanioctl(struct ifnet *ifp, u_long cmd, caddr_t data) case SIOCSLIFPHYADDR: error = vxlan_config(ifp, - (struct sockaddr *)&lifr->addr, - (struct sockaddr *)&lifr->dstaddr); + sstosa(&lifr->addr), + sstosa(&lifr->dstaddr)); break; case SIOCDIFPHYADDR: @@ -616,8 +616,7 @@ vxlan_lookup(struct mbuf *m, struct udphdr *uh, int iphlen, vni == sc->sc_vnetid && sc->sc_rdomain == rtable_l2(m->m_pkthdr.ph_rtableid)) { sc_cand = sc; - if (vxlan_sockaddr_cmp(srcsa, - (struct sockaddr *)&sc->sc_dst) == 0) + if (vxlan_sockaddr_cmp(srcsa, sstosa(&sc->sc_dst)) == 0) goto found; } } @@ -805,8 +804,8 @@ vxlan_output(struct ifnet *ifp, struct mbuf *m) m->m_len = sizeof(*vu); m->m_pkthdr.len += sizeof(*vu); - src = (struct sockaddr *)&sc->sc_src; - dst = (struct sockaddr *)&sc->sc_dst; + src = sstosa(&sc->sc_src); + dst = sstosa(&sc->sc_dst); af = src->sa_family; vu = mtod(m, struct vxlanudphdr *); diff --git a/sys/net/pf.c b/sys/net/pf.c index 39f005b066b..02af280c9ec 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.1019 2017/03/17 17:19:16 mpi Exp $ */ +/* $OpenBSD: pf.c,v 1.1020 2017/05/04 15:00:24 bluhm Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -5691,7 +5691,7 @@ pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif, if (kif != NULL && kif->pfik_ifp->if_type == IFT_ENC) goto out; - rt = rtalloc((struct sockaddr *)&ss, 0, rtableid); + rt = rtalloc(sstosa(&ss), 0, rtableid); if (rt != NULL) { /* No interface given, this is a no-route check */ if (kif == NULL) @@ -5758,7 +5758,7 @@ pf_rtlabel_match(struct pf_addr *addr, sa_family_t af, struct pf_addr_wrap *aw, #endif /* INET6 */ } - rt = rtalloc((struct sockaddr *)&ss, RT_RESOLVE, rtableid); + rt = rtalloc(sstosa(&ss), RT_RESOLVE, rtableid); if (rt != NULL) { if (rt->rt_labelid == aw->v.rtlabel) ret = 1; diff --git a/sys/net/pipex.c b/sys/net/pipex.c index 5a29b0280bd..389aa9ba8df 100644 --- a/sys/net/pipex.c +++ b/sys/net/pipex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pipex.c,v 1.93 2017/04/18 01:24:47 yasuoka Exp $ */ +/* $OpenBSD: pipex.c,v 1.94 2017/05/04 15:00:24 bluhm Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. @@ -471,7 +471,7 @@ pipex_add_session(struct pipex_session_req *req, case PIPEX_PROTO_PPTP: case PIPEX_PROTO_L2TP: chain = PIPEX_PEER_ADDR_HASHTABLE( - pipex_sockaddr_hash_key((struct sockaddr *)&session->peer)); + pipex_sockaddr_hash_key(&session->peer.sa)); LIST_INSERT_HEAD(chain, session, peer_addr_chain); } @@ -1412,7 +1412,7 @@ pipex_pppoe_output(struct mbuf *m0, struct pipex_session *session) session->stat.opackets++; session->stat.obytes += len; - over_ifp->if_output(over_ifp, m0, (struct sockaddr *)&session->peer, + over_ifp->if_output(over_ifp, m0, &session->peer.sa, NULL); } #endif /* PIPEX_PPPOE */ @@ -1779,8 +1779,7 @@ pipex_pptp_userland_lookup_session(struct mbuf *m0, struct sockaddr *sa) list = PIPEX_PEER_ADDR_HASHTABLE(pipex_sockaddr_hash_key(sa)); LIST_FOREACH(session, list, peer_addr_chain) { - if (pipex_sockaddr_compar_addr( - (struct sockaddr *)&session->peer, sa) != 0) + if (pipex_sockaddr_compar_addr(&session->peer.sa, sa) != 0) continue; if (session->peer_session_id == id) break; @@ -2217,8 +2216,7 @@ pipex_l2tp_userland_lookup_session(struct mbuf *m0, struct sockaddr *sa) list = PIPEX_PEER_ADDR_HASHTABLE(pipex_sockaddr_hash_key(sa)); LIST_FOREACH(session, list, peer_addr_chain) { - if (pipex_sockaddr_compar_addr( - (struct sockaddr *)&session->peer, sa) != 0) + if (pipex_sockaddr_compar_addr(&session->peer.sa, sa) != 0) continue; if (session->proto.l2tp.peer_tunnel_id != tunnel_id) continue; diff --git a/sys/net/pipex_local.h b/sys/net/pipex_local.h index f3f0e6886f4..378b39042c8 100644 --- a/sys/net/pipex_local.h +++ b/sys/net/pipex_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pipex_local.h,v 1.24 2017/01/24 10:08:30 krw Exp $ */ +/* $OpenBSD: pipex_local.h,v 1.25 2017/05/04 15:00:24 bluhm Exp $ */ /* * Copyright (c) 2009 Internet Initiative Japan Inc. @@ -203,6 +203,7 @@ struct pipex_session { char _proto_unknown[0]; } proto; union { + struct sockaddr sa; struct sockaddr_in sin4; struct sockaddr_in6 sin6; struct sockaddr_dl sdl; diff --git a/sys/netinet/in.c b/sys/netinet/in.c index dfbc491ed26..7a20e768887 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in.c,v 1.136 2017/03/27 09:38:03 rzalamena Exp $ */ +/* $OpenBSD: in.c,v 1.137 2017/05/04 15:00:24 bluhm Exp $ */ /* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */ /* @@ -434,13 +434,13 @@ in_lifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged) case SIOCALIFADDR: case SIOCDLIFADDR: /* address must be specified on ADD and DELETE */ - sa = (struct sockaddr *)&iflr->addr; + sa = sstosa(&iflr->addr); if (sa->sa_family != AF_INET) return EINVAL; if (sa->sa_len != sizeof(struct sockaddr_in)) return EINVAL; /* XXX need improvement */ - sa = (struct sockaddr *)&iflr->dstaddr; + sa = sstosa(&iflr->dstaddr); if (sa->sa_family && sa->sa_family != AF_INET) return EINVAL; @@ -471,12 +471,11 @@ in_lifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged) memcpy(ifra.ifra_name, iflr->iflr_name, sizeof(ifra.ifra_name)); - memcpy(&ifra.ifra_addr, &iflr->addr, - ((struct sockaddr *)&iflr->addr)->sa_len); + memcpy(&ifra.ifra_addr, &iflr->addr, iflr->addr.ss_len); - if (((struct sockaddr *)&iflr->dstaddr)->sa_family) { /*XXX*/ + if (iflr->dstaddr.ss_family) { /*XXX*/ memcpy(&ifra.ifra_dstaddr, &iflr->dstaddr, - ((struct sockaddr *)&iflr->dstaddr)->sa_len); + iflr->dstaddr.ss_len); } ifra.ifra_mask.sin_family = AF_INET; diff --git a/sys/netinet/in.h b/sys/netinet/in.h index ab2c9ca63b9..aae85fc430a 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in.h,v 1.121 2017/02/04 02:54:33 guenther Exp $ */ +/* $OpenBSD: in.h,v 1.122 2017/05/04 15:00:24 bluhm Exp $ */ /* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ /* @@ -834,19 +834,19 @@ const char *sockaddr_ntop(struct sockaddr *, char *, size_t); * casts or defines. */ -static __inline struct sockaddr_in * +static inline struct sockaddr_in * satosin(struct sockaddr *sa) { return ((struct sockaddr_in *)(sa)); } -static __inline struct sockaddr * +static inline struct sockaddr * sintosa(struct sockaddr_in *sin) { return ((struct sockaddr *)(sin)); } -static __inline struct in_ifaddr * +static inline struct in_ifaddr * ifatoia(struct ifaddr *ifa) { return ((struct in_ifaddr *)(ifa)); diff --git a/sys/netinet/ip_ipip.c b/sys/netinet/ip_ipip.c index 45e6e3722d3..8b4b0c54609 100644 --- a/sys/netinet/ip_ipip.c +++ b/sys/netinet/ip_ipip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipip.c,v 1.74 2017/04/14 20:46:31 bluhm Exp $ */ +/* $OpenBSD: ip_ipip.c,v 1.75 2017/05/04 15:00:24 bluhm Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -294,8 +294,7 @@ ipip_input(struct mbuf **mp, int *offp, struct ifnet *gifp, int proto) sin6->sin6_addr = ip6->ip6_src; #endif /* INET6 */ } - rt = rtalloc((struct sockaddr *)&ss, 0, - m->m_pkthdr.ph_rtableid); + rt = rtalloc(sstosa(&ss), 0, m->m_pkthdr.ph_rtableid); if ((rt != NULL) && (rt->rt_flags & RTF_LOCAL)) { ipipstat_inc(ipips_spoof); m_freem(m); diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 931b8ec3d59..d3d33fec7a0 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_subr.c,v 1.161 2017/04/19 15:21:54 bluhm Exp $ */ +/* $OpenBSD: tcp_subr.c,v 1.162 2017/05/04 15:00:24 bluhm Exp $ */ /* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */ /* @@ -694,8 +694,7 @@ tcp6_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *d) * payload. */ inp = in6_pcbhashlookup(&tcbtable, &sa6->sin6_addr, - th.th_dport, (struct in6_addr *)&sa6_src->sin6_addr, - th.th_sport, rdomain); + th.th_dport, &sa6_src->sin6_addr, th.th_sport, rdomain); if (cmd == PRC_MSGSIZE) { /* * Depending on the value of "valid" and routing table diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index ff005676845..70a504b77ae 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.202 2017/04/17 10:29:01 florian Exp $ */ +/* $OpenBSD: in6.c,v 1.203 2017/05/04 15:00:24 bluhm Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -970,13 +970,13 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged) case SIOCALIFADDR: case SIOCDLIFADDR: /* address must be specified on ADD and DELETE */ - sa = (struct sockaddr *)&iflr->addr; + sa = sstosa(&iflr->addr); if (sa->sa_family != AF_INET6) return EINVAL; if (sa->sa_len != sizeof(struct sockaddr_in6)) return EINVAL; /* XXX need improvement */ - sa = (struct sockaddr *)&iflr->dstaddr; + sa = sstosa(&iflr->dstaddr); if (sa->sa_family && sa->sa_family != AF_INET6) return EINVAL; if (sa->sa_len && sa->sa_len != sizeof(struct sockaddr_in6)) @@ -1031,8 +1031,7 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged) bzero(&ifra, sizeof(ifra)); bcopy(iflr->iflr_name, ifra.ifra_name, sizeof(ifra.ifra_name)); - bcopy(&iflr->addr, &ifra.ifra_addr, - ((struct sockaddr *)&iflr->addr)->sa_len); + bcopy(&iflr->addr, &ifra.ifra_addr, iflr->addr.ss_len); if (hostid) { /* fill in hostid part */ ifra.ifra_addr.sin6_addr.s6_addr32[2] = @@ -1041,9 +1040,9 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged) hostid->s6_addr32[3]; } - if (((struct sockaddr *)&iflr->dstaddr)->sa_family) { /*XXX*/ + if (iflr->dstaddr.ss_family) { /*XXX*/ bcopy(&iflr->dstaddr, &ifra.ifra_dstaddr, - ((struct sockaddr *)&iflr->dstaddr)->sa_len); + iflr->dstaddr.ss_len); if (hostid) { ifra.ifra_dstaddr.sin6_addr.s6_addr32[2] = hostid->s6_addr32[2]; diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h index 6f12fe5e3c1..53ac30ddc48 100644 --- a/sys/netinet6/in6.h +++ b/sys/netinet6/in6.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.h,v 1.93 2017/02/22 13:46:53 renato Exp $ */ +/* $OpenBSD: in6.h,v 1.94 2017/05/04 15:00:24 bluhm Exp $ */ /* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */ /* @@ -438,19 +438,19 @@ struct in6_ifaddr; * casts or defines. */ -static __inline struct sockaddr_in6 * +static inline struct sockaddr_in6 * satosin6(struct sockaddr *sa) { return ((struct sockaddr_in6 *)(sa)); } -static __inline struct sockaddr * +static inline struct sockaddr * sin6tosa(struct sockaddr_in6 *sin6) { return ((struct sockaddr *)(sin6)); } -static __inline struct in6_ifaddr * +static inline struct in6_ifaddr * ifatoia6(struct ifaddr *ifa) { return ((struct in6_ifaddr *)(ifa)); diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 54acd64d357..27cd9b5962e 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socket.h,v 1.93 2016/11/14 10:32:46 mpi Exp $ */ +/* $OpenBSD: socket.h,v 1.94 2017/05/04 15:00:24 bluhm Exp $ */ /* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */ /* @@ -532,7 +532,15 @@ int setrtable(int); __END_DECLS #else + void pfctlinput(int, struct sockaddr *); + +static inline struct sockaddr * +sstosa(struct sockaddr_storage *ss) +{ + return ((struct sockaddr *)(ss)); +} + #endif /* !_KERNEL */ #endif /* !_SYS_SOCKET_H_ */ -- cgit v1.2.3