Add in6_prepare_ifra() function to ease preparing in-kernel IPv6
address requests. MFC after: 2 weeks
This commit is contained in:
parent
86fa24710e
commit
9080e7d023
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=260860
@ -1036,6 +1036,27 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra,
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill in basic IPv6 address request info
|
||||
*/
|
||||
void
|
||||
in6_prepare_ifra(struct in6_aliasreq *ifra, const struct in6_addr *addr,
|
||||
const struct in6_addr *mask)
|
||||
{
|
||||
|
||||
memset(ifra, 0, sizeof(struct in6_aliasreq));
|
||||
|
||||
ifra->ifra_addr.sin6_family = AF_INET6;
|
||||
ifra->ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
|
||||
if (addr != NULL)
|
||||
ifra->ifra_addr.sin6_addr = *addr;
|
||||
|
||||
ifra->ifra_prefixmask.sin6_family = AF_INET6;
|
||||
ifra->ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
|
||||
if (mask != NULL)
|
||||
ifra->ifra_prefixmask.sin6_addr = *mask;
|
||||
}
|
||||
|
||||
static int
|
||||
in6_validate_ifra(struct ifnet *ifp, struct in6_aliasreq *ifra,
|
||||
struct in6_ifaddr *ia, int flags)
|
||||
|
@ -460,16 +460,8 @@ in6_ifattach_linklocal(struct ifnet *ifp, struct ifnet *altifp)
|
||||
/*
|
||||
* configure link-local address.
|
||||
*/
|
||||
bzero(&ifra, sizeof(ifra));
|
||||
in6_prepare_ifra(&ifra, NULL, &in6mask64);
|
||||
|
||||
/*
|
||||
* in6_update_ifa() does not use ifra_name, but we accurately set it
|
||||
* for safety.
|
||||
*/
|
||||
strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
|
||||
|
||||
ifra.ifra_addr.sin6_family = AF_INET6;
|
||||
ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
|
||||
ifra.ifra_addr.sin6_addr.s6_addr32[0] = htonl(0xfe800000);
|
||||
ifra.ifra_addr.sin6_addr.s6_addr32[1] = 0;
|
||||
if ((ifp->if_flags & IFF_LOOPBACK) != 0) {
|
||||
@ -485,9 +477,6 @@ in6_ifattach_linklocal(struct ifnet *ifp, struct ifnet *altifp)
|
||||
if (in6_setscope(&ifra.ifra_addr.sin6_addr, ifp, NULL))
|
||||
return (-1);
|
||||
|
||||
ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
|
||||
ifra.ifra_prefixmask.sin6_family = AF_INET6;
|
||||
ifra.ifra_prefixmask.sin6_addr = in6mask64;
|
||||
/* link-local addresses should NEVER expire. */
|
||||
ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
|
||||
ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
|
||||
@ -565,17 +554,7 @@ in6_ifattach_loopback(struct ifnet *ifp)
|
||||
struct in6_aliasreq ifra;
|
||||
int error;
|
||||
|
||||
bzero(&ifra, sizeof(ifra));
|
||||
|
||||
/*
|
||||
* in6_update_ifa() does not use ifra_name, but we accurately set it
|
||||
* for safety.
|
||||
*/
|
||||
strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
|
||||
|
||||
ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
|
||||
ifra.ifra_prefixmask.sin6_family = AF_INET6;
|
||||
ifra.ifra_prefixmask.sin6_addr = in6mask128;
|
||||
in6_prepare_ifra(&ifra, &in6addr_loopback, &in6mask128);
|
||||
|
||||
/*
|
||||
* Always initialize ia_dstaddr (= broadcast address) to loopback
|
||||
@ -585,10 +564,6 @@ in6_ifattach_loopback(struct ifnet *ifp)
|
||||
ifra.ifra_dstaddr.sin6_family = AF_INET6;
|
||||
ifra.ifra_dstaddr.sin6_addr = in6addr_loopback;
|
||||
|
||||
ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
|
||||
ifra.ifra_addr.sin6_family = AF_INET6;
|
||||
ifra.ifra_addr.sin6_addr = in6addr_loopback;
|
||||
|
||||
/* the loopback address should NEVER expire. */
|
||||
ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
|
||||
ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
|
||||
|
@ -799,6 +799,8 @@ int in6_control(struct socket *, u_long, caddr_t, struct ifnet *,
|
||||
struct thread *);
|
||||
int in6_update_ifa(struct ifnet *, struct in6_aliasreq *,
|
||||
struct in6_ifaddr *, int);
|
||||
void in6_prepare_ifra(struct in6_aliasreq *, const struct in6_addr *,
|
||||
const struct in6_addr *);
|
||||
void in6_purgeaddr(struct ifaddr *);
|
||||
int in6if_do_dad(struct ifnet *);
|
||||
void in6_purgeif(struct ifnet *);
|
||||
|
@ -1829,19 +1829,9 @@ in6_ifadd(struct nd_prefixctl *pr, int mcast)
|
||||
}
|
||||
|
||||
/* make ifaddr */
|
||||
in6_prepare_ifra(&ifra, &pr->ndpr_prefix.sin6_addr, &mask);
|
||||
|
||||
bzero(&ifra, sizeof(ifra));
|
||||
/*
|
||||
* in6_update_ifa() does not use ifra_name, but we accurately set it
|
||||
* for safety.
|
||||
*/
|
||||
strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
|
||||
ifra.ifra_addr.sin6_family = AF_INET6;
|
||||
ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
|
||||
/* prefix */
|
||||
ifra.ifra_addr.sin6_addr = pr->ndpr_prefix.sin6_addr;
|
||||
IN6_MASK_ADDR(&ifra.ifra_addr.sin6_addr, &mask);
|
||||
|
||||
/* interface ID */
|
||||
ifra.ifra_addr.sin6_addr.s6_addr32[0] |=
|
||||
(ib->ia_addr.sin6_addr.s6_addr32[0] & ~mask.s6_addr32[0]);
|
||||
@ -1853,12 +1843,6 @@ in6_ifadd(struct nd_prefixctl *pr, int mcast)
|
||||
(ib->ia_addr.sin6_addr.s6_addr32[3] & ~mask.s6_addr32[3]);
|
||||
ifa_free(ifa);
|
||||
|
||||
/* new prefix mask. */
|
||||
ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
|
||||
ifra.ifra_prefixmask.sin6_family = AF_INET6;
|
||||
bcopy(&mask, &ifra.ifra_prefixmask.sin6_addr,
|
||||
sizeof(ifra.ifra_prefixmask.sin6_addr));
|
||||
|
||||
/* lifetimes. */
|
||||
ifra.ifra_lifetime.ia6t_vltime = pr->ndpr_vltime;
|
||||
ifra.ifra_lifetime.ia6t_pltime = pr->ndpr_pltime;
|
||||
@ -1923,11 +1907,10 @@ in6_tmpifadd(const struct in6_ifaddr *ia0, int forcegen, int delay)
|
||||
u_int32_t randid[2];
|
||||
time_t vltime0, pltime0;
|
||||
|
||||
bzero(&ifra, sizeof(ifra));
|
||||
strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
|
||||
ifra.ifra_addr = ia0->ia_addr;
|
||||
/* copy prefix mask */
|
||||
ifra.ifra_prefixmask = ia0->ia_prefixmask;
|
||||
in6_prepare_ifra(&ifra, &ia0->ia_addr.sin6_addr,
|
||||
&ia0->ia_prefixmask.sin6_addr);
|
||||
|
||||
ifra.ifra_addr = ia0->ia_addr; /* XXX: do we need this ? */
|
||||
/* clear the old IFID */
|
||||
IN6_MASK_ADDR(&ifra.ifra_addr.sin6_addr,
|
||||
&ifra.ifra_prefixmask.sin6_addr);
|
||||
|
Loading…
Reference in New Issue
Block a user