Introduce IN6_MASK_ADDR() macro to unify various hand-rolled code
to do IPv6 addr & mask in different places. MFC after: 2 weeks
This commit is contained in:
parent
6d40361585
commit
1dc8f6a82c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=260458
@ -635,7 +635,6 @@ in6_control(struct socket *so, u_long cmd, caddr_t data,
|
||||
|
||||
case SIOCAIFADDR_IN6:
|
||||
{
|
||||
int i;
|
||||
struct nd_prefixctl pr0;
|
||||
struct nd_prefix *pr;
|
||||
|
||||
@ -688,10 +687,9 @@ in6_control(struct socket *so, u_long cmd, caddr_t data,
|
||||
}
|
||||
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.
|
||||
|
@ -455,7 +455,7 @@ in6_ifattach_linklocal(struct ifnet *ifp, struct ifnet *altifp)
|
||||
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, struct ifnet *altifp)
|
||||
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.
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -858,7 +858,6 @@ nd6_prelist_add(struct nd_prefixctl *pr, struct nd_defrouter *dr,
|
||||
{
|
||||
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, struct nd_defrouter *dr,
|
||||
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 mcast)
|
||||
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 *ia0, int forcegen, int delay)
|
||||
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 *ia0, int forcegen, int delay)
|
||||
/* 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,
|
||||
|
Loading…
Reference in New Issue
Block a user