Date: Wed, 8 Jan 2014 22:13:32 +0000 (UTC) From: "Alexander V. Chernikov" <melifaro@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r260458 - head/sys/netinet6 Message-ID: <201401082213.s08MDWaO092524@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: melifaro Date: Wed Jan 8 22:13:32 2014 New Revision: 260458 URL: http://svnweb.freebsd.org/changeset/base/260458 Log: Introduce IN6_MASK_ADDR() macro to unify various hand-rolled code to do IPv6 addr & mask in different places. MFC after: 2 weeks Modified: head/sys/netinet6/in6.c head/sys/netinet6/in6_ifattach.c head/sys/netinet6/in6_src.c head/sys/netinet6/in6_var.h head/sys/netinet6/nd6_rtr.c Modified: head/sys/netinet6/in6.c ============================================================================== --- head/sys/netinet6/in6.c Wed Jan 8 21:04:12 2014 (r260457) +++ head/sys/netinet6/in6.c Wed Jan 8 22:13:32 2014 (r260458) @@ -635,7 +635,6 @@ in6_control(struct socket *so, u_long cm case SIOCAIFADDR_IN6: { - int i; struct nd_prefixctl pr0; struct nd_prefix *pr; @@ -688,10 +687,9 @@ in6_control(struct socket *so, u_long cm } pr0.ndpr_prefix = ifra->ifra_addr; /* apply the mask for safety. */ - for (i = 0; i < 4; i++) { - pr0.ndpr_prefix.sin6_addr.s6_addr32[i] &= - ifra->ifra_prefixmask.sin6_addr.s6_addr32[i]; - } + IN6_MASK_ADDR(&pr0.ndpr_prefix.sin6_addr, + &ifra->ifra_prefixmask.sin6_addr); + /* * XXX: since we don't have an API to set prefix (not address) * lifetimes, we just use the same lifetimes as addresses. Modified: head/sys/netinet6/in6_ifattach.c ============================================================================== --- head/sys/netinet6/in6_ifattach.c Wed Jan 8 21:04:12 2014 (r260457) +++ head/sys/netinet6/in6_ifattach.c Wed Jan 8 22:13:32 2014 (r260458) @@ -455,7 +455,7 @@ in6_ifattach_linklocal(struct ifnet *ifp struct in6_ifaddr *ia; struct in6_aliasreq ifra; struct nd_prefixctl pr0; - int i, error; + int error; /* * configure link-local address. @@ -532,10 +532,7 @@ in6_ifattach_linklocal(struct ifnet *ifp pr0.ndpr_plen = in6_mask2len(&ifra.ifra_prefixmask.sin6_addr, NULL); pr0.ndpr_prefix = ifra.ifra_addr; /* apply the mask for safety. (nd6_prelist_add will apply it again) */ - for (i = 0; i < 4; i++) { - pr0.ndpr_prefix.sin6_addr.s6_addr32[i] &= - in6mask64.s6_addr32[i]; - } + IN6_MASK_ADDR(&pr0.ndpr_prefix.sin6_addr, &in6mask64); /* * Initialize parameters. The link-local prefix must always be * on-link, and its lifetimes never expire. Modified: head/sys/netinet6/in6_src.c ============================================================================== --- head/sys/netinet6/in6_src.c Wed Jan 8 21:04:12 2014 (r260457) +++ head/sys/netinet6/in6_src.c Wed Jan 8 22:13:32 2014 (r260458) @@ -995,7 +995,6 @@ in6_src_sysctl(SYSCTL_HANDLER_ARGS) int in6_src_ioctl(u_long cmd, caddr_t data) { - int i; struct in6_addrpolicy ent0; if (cmd != SIOCAADDRCTL_POLICY && cmd != SIOCDADDRCTL_POLICY) @@ -1009,10 +1008,7 @@ in6_src_ioctl(u_long cmd, caddr_t data) if (in6_mask2len(&ent0.addrmask.sin6_addr, NULL) < 0) return (EINVAL); /* clear trailing garbages (if any) of the prefix address. */ - for (i = 0; i < 4; i++) { - ent0.addr.sin6_addr.s6_addr32[i] &= - ent0.addrmask.sin6_addr.s6_addr32[i]; - } + IN6_MASK_ADDR(&ent0.addr.sin6_addr, &ent0.addrmask.sin6_addr); ent0.use = 0; switch (cmd) { Modified: head/sys/netinet6/in6_var.h ============================================================================== --- head/sys/netinet6/in6_var.h Wed Jan 8 21:04:12 2014 (r260457) +++ head/sys/netinet6/in6_var.h Wed Jan 8 22:13:32 2014 (r260458) @@ -409,6 +409,12 @@ struct in6_rrenumreq { (((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \ (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \ (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 ) +#define IN6_MASK_ADDR(a, m) do { \ + (a)->s6_addr32[0] &= (m)->s6_addr32[0]; \ + (a)->s6_addr32[1] &= (m)->s6_addr32[1]; \ + (a)->s6_addr32[2] &= (m)->s6_addr32[2]; \ + (a)->s6_addr32[3] &= (m)->s6_addr32[3]; \ +} while (0) #endif #define SIOCSIFADDR_IN6 _IOW('i', 12, struct in6_ifreq) Modified: head/sys/netinet6/nd6_rtr.c ============================================================================== --- head/sys/netinet6/nd6_rtr.c Wed Jan 8 21:04:12 2014 (r260457) +++ head/sys/netinet6/nd6_rtr.c Wed Jan 8 22:13:32 2014 (r260458) @@ -858,7 +858,6 @@ nd6_prelist_add(struct nd_prefixctl *pr, { struct nd_prefix *new = NULL; int error = 0; - int i; char ip6buf[INET6_ADDRSTRLEN]; new = (struct nd_prefix *)malloc(sizeof(*new), M_IP6NDP, M_NOWAIT); @@ -883,9 +882,7 @@ nd6_prelist_add(struct nd_prefixctl *pr, LIST_INIT(&new->ndpr_advrtrs); in6_prefixlen2mask(&new->ndpr_mask, new->ndpr_plen); /* make prefix in the canonical form */ - for (i = 0; i < 4; i++) - new->ndpr_prefix.sin6_addr.s6_addr32[i] &= - new->ndpr_mask.s6_addr32[i]; + IN6_MASK_ADDR(&new->ndpr_prefix.sin6_addr, &new->ndpr_mask); /* link ndpr_entry to nd_prefix list */ LIST_INSERT_HEAD(&V_nd_prefix, new, ndpr_entry); @@ -1843,10 +1840,7 @@ in6_ifadd(struct nd_prefixctl *pr, int m ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6); /* prefix */ ifra.ifra_addr.sin6_addr = pr->ndpr_prefix.sin6_addr; - ifra.ifra_addr.sin6_addr.s6_addr32[0] &= mask.s6_addr32[0]; - ifra.ifra_addr.sin6_addr.s6_addr32[1] &= mask.s6_addr32[1]; - ifra.ifra_addr.sin6_addr.s6_addr32[2] &= mask.s6_addr32[2]; - ifra.ifra_addr.sin6_addr.s6_addr32[3] &= mask.s6_addr32[3]; + IN6_MASK_ADDR(&ifra.ifra_addr.sin6_addr, &mask); /* interface ID */ ifra.ifra_addr.sin6_addr.s6_addr32[0] |= @@ -1923,7 +1917,7 @@ in6_tmpifadd(const struct in6_ifaddr *ia struct ifnet *ifp = ia0->ia_ifa.ifa_ifp; struct in6_ifaddr *newia, *ia; struct in6_aliasreq ifra; - int i, error; + int error; int trylimit = 3; /* XXX: adhoc value */ int updateflags; u_int32_t randid[2]; @@ -1935,10 +1929,8 @@ in6_tmpifadd(const struct in6_ifaddr *ia /* copy prefix mask */ ifra.ifra_prefixmask = ia0->ia_prefixmask; /* clear the old IFID */ - for (i = 0; i < 4; i++) { - ifra.ifra_addr.sin6_addr.s6_addr32[i] &= - ifra.ifra_prefixmask.sin6_addr.s6_addr32[i]; - } + IN6_MASK_ADDR(&ifra.ifra_addr.sin6_addr, + &ifra.ifra_prefixmask.sin6_addr); again: if (in6_get_tmpifid(ifp, (u_int8_t *)randid,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201401082213.s08MDWaO092524>