/*
- * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
static struct dadq *nd6_dad_attach(struct dadq *, struct ifaddr *);
static void nd6_dad_detach(struct dadq *, struct ifaddr *);
-static int dad_maxtry = 15; /* max # of *tries* to transmit DAD packet */
+static int dad_maxtry = 15; /* max # of *tries* to transmit DAD packet */
-static unsigned int dad_size; /* size of zone element */
-static struct zone *dad_zone; /* zone for dadq */
+static unsigned int dad_size; /* size of zone element */
+static struct zone *dad_zone; /* zone for dadq */
-#define DAD_ZONE_MAX 64 /* maximum elements in zone */
-#define DAD_ZONE_NAME "nd6_dad" /* zone name */
+#define DAD_ZONE_MAX 64 /* maximum elements in zone */
+#define DAD_ZONE_NAME "nd6_dad" /* zone name */
-#define DAD_LOCK_ASSERT_HELD(_dp) \
+#define DAD_LOCK_ASSERT_HELD(_dp) \
LCK_MTX_ASSERT(&(_dp)->dad_lock, LCK_MTX_ASSERT_OWNED)
-#define DAD_LOCK_ASSERT_NOTHELD(_dp) \
+#define DAD_LOCK_ASSERT_NOTHELD(_dp) \
LCK_MTX_ASSERT(&(_dp)->dad_lock, LCK_MTX_ASSERT_NOTOWNED)
-#define DAD_LOCK(_dp) \
+#define DAD_LOCK(_dp) \
lck_mtx_lock(&(_dp)->dad_lock)
-#define DAD_LOCK_SPIN(_dp) \
+#define DAD_LOCK_SPIN(_dp) \
lck_mtx_lock_spin(&(_dp)->dad_lock)
-#define DAD_CONVERT_LOCK(_dp) do { \
- DAD_LOCK_ASSERT_HELD(_dp); \
- lck_mtx_convert_spin(&(_dp)->dad_lock); \
+#define DAD_CONVERT_LOCK(_dp) do { \
+ DAD_LOCK_ASSERT_HELD(_dp); \
+ lck_mtx_convert_spin(&(_dp)->dad_lock); \
} while (0)
-#define DAD_UNLOCK(_dp) \
+#define DAD_UNLOCK(_dp) \
lck_mtx_unlock(&(_dp)->dad_lock)
-#define DAD_ADDREF(_dp) \
+#define DAD_ADDREF(_dp) \
dad_addref(_dp, 0)
-#define DAD_ADDREF_LOCKED(_dp) \
+#define DAD_ADDREF_LOCKED(_dp) \
dad_addref(_dp, 1)
-#define DAD_REMREF(_dp) \
+#define DAD_REMREF(_dp) \
dad_remref(_dp)
extern lck_mtx_t *dad6_mutex;
extern lck_mtx_t *nd6_mutex;
-static int nd6_llreach_base = 30; /* seconds */
+static int nd6_llreach_base = 30; /* seconds */
static struct sockaddr_in6 hostrtmask;
if (nd6_llreach_base != 0 &&
(ln->ln_expire != 0 || (ifp->if_eflags & IFEF_IPV6_ND6ALT) != 0) &&
!(rt->rt_ifp->if_flags & IFF_LOOPBACK) &&
- ifp->if_addrlen == IF_LLREACH_MAXLEN && /* Ethernet */
+ ifp->if_addrlen == IF_LLREACH_MAXLEN && /* Ethernet */
alen == ifp->if_addrlen) {
struct if_llreach *lr;
const char *why = NULL, *type = "";
why = " for different target HW address; "
"using new llreach record";
} else {
- lr->lr_probes = 0; /* reset probe count */
+ lr->lr_probes = 0; /* reset probe count */
IFLR_UNLOCK(lr);
if (solicited) {
why = " for same target HW address; "
lr = ln->ln_llreach = ifnet_llreach_alloc(ifp,
ETHERTYPE_IPV6, addr, alen, nd6_llreach_base);
if (lr != NULL) {
- lr->lr_probes = 0; /* reset probe count */
- if (why == NULL)
+ lr->lr_probes = 0; /* reset probe count */
+ if (why == NULL) {
why = "creating new llreach record";
+ }
}
}
nd6log((LOG_DEBUG, "%s: %s%s for %s\n", if_name(ifp),
type, why, inet_ntop(AF_INET6,
- &SIN6(rt_key(rt))->sin6_addr, tmp, sizeof (tmp))));
+ &SIN6(rt_key(rt))->sin6_addr, tmp, sizeof(tmp))));
}
}
}
void
nd6_llreach_use(struct llinfo_nd6 *ln)
{
- if (ln->ln_llreach != NULL)
+ if (ln->ln_llreach != NULL) {
ln->ln_lastused = net_uptime();
+ }
}
/*
/* Expect 32-bit aligned data pointer on strict-align platforms */
MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(m);
- IP6_EXTHDR_CHECK(m, off, icmp6len, return);
+ IP6_EXTHDR_CHECK(m, off, icmp6len, return );
nd_ns = (struct nd_neighbor_solicit *)((caddr_t)ip6 + off);
m->m_pkthdr.pkt_flags |= PKTF_INET6_RESOLVE;
ip6 = mtod(m, struct ip6_hdr *); /* adjust pointer for safety */
taddr6 = nd_ns->nd_ns_target;
- if (in6_setscope(&taddr6, ifp, NULL) != 0)
+ if (in6_setscope(&taddr6, ifp, NULL) != 0) {
goto bad;
+ }
if (ip6->ip6_hlim != IPV6_MAXHLIM) {
nd6log((LOG_ERR,
; /* good */
} else {
nd6log((LOG_INFO, "nd6_ns_input: bad DAD packet "
- "(wrong ip6 dst)\n"));
+ "(wrong ip6 dst)\n"));
goto bad;
}
} else if (!nd6_onlink_ns_rfc4861) {
src_sa6.sin6_addr = saddr6;
if (!nd6_is_addr_neighbor(&src_sa6, ifp, 0)) {
nd6log((LOG_INFO, "nd6_ns_input: "
- "NS packet from non-neighbor\n"));
+ "NS packet from non-neighbor\n"));
goto bad;
}
}
* In implementation, we add target link-layer address by default.
* We do not add one in MUST NOT cases.
*/
- if (!IN6_IS_ADDR_MULTICAST(&daddr6))
+ if (!IN6_IS_ADDR_MULTICAST(&daddr6)) {
tlladdr = 0;
- else
+ } else {
tlladdr = 1;
+ }
/*
* Target address (taddr6) must be either:
* proxy NDP for single entry
*/
ifa = (struct ifaddr *)in6ifa_ifpforlinklocal(
- ifp, IN6_IFF_NOTREADY|IN6_IFF_ANYCAST);
+ ifp, IN6_IFF_NOTREADY | IN6_IFF_ANYCAST);
if (ifa) {
proxy = 1;
proxydl = *SDL(rt->rt_gateway);
*
* Forwarding associated with NDPRF_PRPROXY may apply.
*/
- if (ip6_forwarding && nd6_prproxy)
+ if (ip6_forwarding && nd6_prproxy) {
nd6_prproxy_ns_input(ifp, &saddr6, lladdr,
lladdrlen, &daddr6, &taddr6,
(ndopts.nd_opts_nonce == NULL) ? NULL :
ndopts.nd_opts_nonce->nd_opt_nonce);
+ }
goto freeit;
}
IFA_LOCK(ifa);
nd6log((LOG_INFO,
"nd6_ns_input: lladdrlen mismatch for %s "
"(if %d, NS packet %d)\n",
- ip6_sprintf(&taddr6), ifp->if_addrlen, lladdrlen - 2));
+ ip6_sprintf(&taddr6), ifp->if_addrlen, lladdrlen - 2));
goto bad;
}
if (IN6_ARE_ADDR_EQUAL(&myaddr6, &saddr6)) {
nd6log((LOG_INFO,
- "nd6_ns_input: duplicate IP6 address %s\n",
- ip6_sprintf(&saddr6)));
+ "nd6_ns_input: duplicate IP6 address %s\n",
+ ip6_sprintf(&saddr6)));
goto freeit;
}
if (!is_dad_probe && (dadprogress & IN6_IFF_OPTIMISTIC) != 0) {
oflgclr = 1;
} else {
- if (is_dad_probe)
+ if (is_dad_probe) {
nd6_dad_ns_input(ifa, lladdr, lladdrlen, ndopts.nd_opts_nonce);
+ }
goto freeit;
}
*/
if (is_dad_probe) {
saddr6 = in6addr_linklocal_allnodes;
- if (in6_setscope(&saddr6, ifp, NULL) != 0)
+ if (in6_setscope(&saddr6, ifp, NULL) != 0) {
goto bad;
- if ((dadprogress & IN6_IFF_OPTIMISTIC) == 0)
+ }
+ if ((dadprogress & IN6_IFF_OPTIMISTIC) == 0) {
nd6_na_output(ifp, &saddr6, &taddr6,
((anycast || proxy || !tlladdr) ? 0 :
ND_NA_FLAG_OVERRIDE) | (advrouter ?
ND_NA_FLAG_ROUTER : 0), tlladdr, proxy ?
(struct sockaddr *)&proxydl : NULL);
+ }
goto freeit;
}
((anycast || proxy || !tlladdr || oflgclr) ? 0 : ND_NA_FLAG_OVERRIDE) |
(advrouter ? ND_NA_FLAG_ROUTER : 0) | ND_NA_FLAG_SOLICITED,
tlladdr, proxy ? (struct sockaddr *)&proxydl : NULL);
- freeit:
+freeit:
m_freem(m);
- if (ifa != NULL)
+ if (ifa != NULL) {
IFA_REMREF(ifa);
+ }
return;
- bad:
+bad:
nd6log((LOG_ERR, "nd6_ns_input: src=%s\n", ip6_sprintf(&saddr6)));
nd6log((LOG_ERR, "nd6_ns_input: dst=%s\n", ip6_sprintf(&daddr6)));
nd6log((LOG_ERR, "nd6_ns_input: tgt=%s\n", ip6_sprintf(&taddr6)));
icmp6stat.icp6s_badns++;
m_freem(m);
- if (ifa != NULL)
+ if (ifa != NULL) {
IFA_REMREF(ifa);
+ }
}
/*
struct ifnet *ifp,
const struct in6_addr *daddr6,
const struct in6_addr *taddr6,
- struct llinfo_nd6 *ln, /* for source address determination */
- uint8_t *nonce) /* duplicated address detection */
+ struct llinfo_nd6 *ln, /* for source address determination */
+ uint8_t *nonce) /* duplicated address detection */
{
struct mbuf *m;
struct ip6_hdr *ip6;
struct in6_ifaddr *ia = NULL;
struct in6_addr *src, src_in, src_storage;
struct ip6_moptions *im6o = NULL;
- struct ifnet *outif = NULL;
+ struct ifnet *outif = NULL;
int icmp6len;
int maxlen;
int flags;
struct ip6_out_args ip6oa;
u_int32_t rtflags = 0;
- if ((ifp->if_eflags & IFEF_IPV6_ND6ALT) || IN6_IS_ADDR_MULTICAST(taddr6))
+ if ((ifp->if_eflags & IFEF_IPV6_ND6ALT) || IN6_IS_ADDR_MULTICAST(taddr6)) {
return;
+ }
bzero(&ro, sizeof(ro));
bzero(&ip6oa, sizeof(ip6oa));
return;
}
- MGETHDR(m, M_DONTWAIT, MT_DATA); /* XXXMAC: mac_create_mbuf_linklayer() probably */
+ MGETHDR(m, M_DONTWAIT, MT_DATA); /* XXXMAC: mac_create_mbuf_linklayer() probably */
if (m && max_linkhdr + maxlen >= MHLEN) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
m = NULL;
}
}
- if (m == NULL)
+ if (m == NULL) {
return;
+ }
m->m_pkthdr.rcvif = NULL;
if (daddr6 == NULL || IN6_IS_ADDR_MULTICAST(daddr6)) {
icmp6len = sizeof(*nd_ns);
m->m_pkthdr.len = m->m_len = sizeof(*ip6) + icmp6len;
- m->m_data += max_linkhdr; /* or MH_ALIGN() equivalent? */
+ m->m_data += max_linkhdr; /* or MH_ALIGN() equivalent? */
/* fill neighbor solicitation packet */
ip6 = mtod(m, struct ip6_hdr *);
/* ip6->ip6_plen will be set later */
ip6->ip6_nxt = IPPROTO_ICMPV6;
ip6->ip6_hlim = IPV6_MAXHLIM;
- if (daddr6)
+ if (daddr6) {
ip6->ip6_dst = *daddr6;
- else {
+ } else {
ip6->ip6_dst.s6_addr16[0] = IPV6_ADDR_INT16_MLL;
ip6->ip6_dst.s6_addr16[1] = 0;
ip6->ip6_dst.s6_addr32[1] = 0;
ip6->ip6_dst.s6_addr32[2] = IPV6_ADDR_INT32_ONE;
ip6->ip6_dst.s6_addr32[3] = taddr6->s6_addr32[3];
ip6->ip6_dst.s6_addr8[12] = 0xff;
- if (in6_setscope(&ip6->ip6_dst, ifp, NULL) != 0)
+ if (in6_setscope(&ip6->ip6_dst, ifp, NULL) != 0) {
goto bad;
+ }
}
if (nonce == NULL) {
/*
* - saddr6 belongs to the outgoing interface.
* Otherwise, we perform the source address selection as usual.
*/
- struct ip6_hdr *hip6; /* hold ip6 */
+ struct ip6_hdr *hip6; /* hold ip6 */
struct in6_addr *hsrc = NULL;
/* Caller holds ref on this route */
if (ln->ln_hold != NULL) {
hip6 = mtod(ln->ln_hold, struct ip6_hdr *);
/* XXX pullup? */
- if (sizeof (*hip6) < ln->ln_hold->m_len)
+ if (sizeof(*hip6) < ln->ln_hold->m_len) {
hsrc = &hip6->ip6_src;
- else
+ } else {
hsrc = NULL;
+ }
}
/* Update probe count, if applicable */
if (ln->ln_llreach != NULL) {
ip6->ip6_plen = htons((u_short)icmp6len);
nd_ns->nd_ns_cksum = 0;
nd_ns->nd_ns_cksum
- = in6_cksum(m, IPPROTO_ICMPV6, sizeof(*ip6), icmp6len);
+ = in6_cksum(m, IPPROTO_ICMPV6, sizeof(*ip6), icmp6len);
flags = nonce ? IPV6_UNSPECSRC : 0;
flags |= IPV6_OUTARGS;
* the packet accordingly so that the driver can find out,
* in case it needs to perform driver-specific action(s).
*/
- if (rtflags & RTF_ROUTER)
+ if (rtflags & RTF_ROUTER) {
m->m_pkthdr.pkt_flags |= PKTF_RESOLVE_RTR;
+ }
if (ifp->if_eflags & IFEF_TXSTART) {
/*
icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]++;
exit:
- if (im6o != NULL)
+ if (im6o != NULL) {
IM6O_REMREF(im6o);
+ }
- ROUTE_RELEASE(&ro); /* we don't cache this route. */
+ ROUTE_RELEASE(&ro); /* we don't cache this route. */
- if (ia != NULL)
+ if (ia != NULL) {
IFA_REMREF(&ia->ia_ifa);
+ }
return;
bad:
if ((ifp->if_eflags & IFEF_IPV6_ND6ALT) != 0) {
nd6log((LOG_INFO, "nd6_na_input: on ND6ALT interface!\n"));
- return;
+ goto freeit;
}
/* Expect 32-bit aligned data pointer on strict-align platforms */
goto bad;
}
- IP6_EXTHDR_CHECK(m, off, icmp6len, return);
+ IP6_EXTHDR_CHECK(m, off, icmp6len, return );
nd_na = (struct nd_neighbor_advert *)((caddr_t)ip6 + off);
m->m_pkthdr.pkt_flags |= PKTF_INET6_RESOLVE;
is_override = ((flags & ND_NA_FLAG_OVERRIDE) != 0);
taddr6 = nd_na->nd_na_target;
- if (in6_setscope(&taddr6, ifp, NULL))
- goto bad; /* XXX: impossible */
-
+ if (in6_setscope(&taddr6, ifp, NULL)) {
+ goto bad; /* XXX: impossible */
+ }
if (IN6_IS_ADDR_MULTICAST(&taddr6)) {
nd6log((LOG_ERR,
"nd6_na_input: invalid target address %s\n",
ip6_sprintf(&taddr6)));
goto bad;
}
- if (IN6_IS_ADDR_MULTICAST(&daddr6))
+ if (IN6_IS_ADDR_MULTICAST(&daddr6)) {
if (is_solicited) {
nd6log((LOG_ERR,
"nd6_na_input: a solicited adv is multicasted\n"));
goto bad;
}
+ }
icmp6len -= sizeof(*nd_na);
nd6_option_init(nd_na + 1, icmp6len, &ndopts);
nd6log((LOG_INFO,
"nd6_na_input: lladdrlen mismatch for %s "
"(if %d, NA packet %d)\n",
- ip6_sprintf(&taddr6), ifp->if_addrlen,
- lladdrlen - 2));
+ ip6_sprintf(&taddr6), ifp->if_addrlen,
+ lladdrlen - 2));
goto bad;
}
}
m = nd6_dad_na_input(m, ifp, &taddr6, lladdr, lladdrlen);
- if (m == NULL)
+ if (m == NULL) {
return;
+ }
/* Forwarding associated with NDPRF_PRPROXY may apply. */
- if (ip6_forwarding && nd6_prproxy)
+ if (ip6_forwarding && nd6_prproxy) {
nd6_prproxy_na_input(ifp, &saddr6, &daddr6, &taddr6, flags);
+ }
/*
* If no neighbor cache entry is found, NA SHOULD silently be
* another interface (in case we are doing prefix proxying.)
*/
if ((rt = nd6_lookup(&taddr6, 0, ifp, 0)) == NULL) {
- if (!ip6_forwarding || !nd6_prproxy)
+ if (!ip6_forwarding || !nd6_prproxy) {
goto freeit;
+ }
- if ((rt = nd6_lookup(&taddr6, 0, NULL, 0)) == NULL)
+ if ((rt = nd6_lookup(&taddr6, 0, NULL, 0)) == NULL) {
goto freeit;
+ }
RT_LOCK_ASSERT_HELD(rt);
if (rt->rt_ifp != ifp) {
/*
* Purge any link-layer info caching.
*/
- if (rt->rt_llinfo_purge != NULL)
+ if (rt->rt_llinfo_purge != NULL) {
rt->rt_llinfo_purge(rt);
+ }
/* Adjust route ref count for the interfaces */
if (rt->rt_if_ref_fn != NULL) {
* If rmx_mtu is not locked, update it
* to the MTU used by the new interface.
*/
- if (!(rt->rt_rmx.rmx_locks & RTV_MTU))
+ if (!(rt->rt_rmx.rmx_locks & RTV_MTU)) {
rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu;
+ }
}
}
lck_mtx_lock(rnh_lock);
rnh = rt_tables[AF_INET6];
- if (rnh != NULL)
+ if (rnh != NULL) {
(void) rnh->rnh_walktree(rnh, route_event_walktree,
(void *)&rt_ev);
+ }
lck_mtx_unlock(rnh_lock);
lck_mtx_lock(nd6_mutex);
pfxlist_onlink_check();
/*
* Check if the link-layer address has changed or not.
*/
- if (lladdr == NULL)
+ if (lladdr == NULL) {
llchange = 0;
- else {
+ } else {
if (sdl->sdl_alen) {
- if (bcmp(lladdr, LLADDR(sdl), ifp->if_addrlen))
+ if (bcmp(lladdr, LLADDR(sdl), ifp->if_addrlen)) {
llchange = 1;
- else
+ } else {
llchange = 0;
- } else
+ }
+ } else {
llchange = 1;
+ }
}
/*
RT_REMREF_LOCKED(rt);
RT_UNLOCK(rt);
goto freeit;
- } else if (is_override /* (2a) */
- || (!is_override && (lladdr && !llchange)) /* (2b) */
- || !lladdr) { /* (2c) */
+ } else if (is_override /* (2a) */
+ || (!is_override && (lladdr && !llchange)) /* (2b) */
+ || !lladdr) { /* (2c) */
/*
* Update link-local address, if any.
*/
lck_mtx_lock(rnh_lock);
rnh = rt_tables[AF_INET6];
- if (rnh != NULL)
+ if (rnh != NULL) {
(void) rnh->rnh_walktree(rnh, route_event_walktree,
(void *)&rt_ev);
+ }
lck_mtx_unlock(rnh_lock);
RT_LOCK(rt);
}
sizeof(nd6_ndalive.link_data.if_name));
ev_msg.dv[0].data_ptr = &nd6_ndalive;
ev_msg.dv[0].data_length =
- sizeof(nd6_ndalive);
+ sizeof(nd6_ndalive);
dlil_post_complete_msg(NULL, &ev_msg);
}
*/
m_hold = ln->ln_hold;
ln->ln_hold = NULL;
- for ( ; m_hold; m_hold = m_hold_next) {
+ for (; m_hold; m_hold = m_hold_next) {
m_hold_next = m_hold->m_nextpkt;
m_hold->m_nextpkt = NULL;
/*
const struct in6_addr *daddr6_0,
const struct in6_addr *taddr6,
uint32_t flags,
- int tlladdr, /* 1 if include target link-layer address */
- struct sockaddr *sdl0) /* sockaddr_dl (= proxy NA) or NULL */
+ int tlladdr, /* 1 if include target link-layer address */
+ struct sockaddr *sdl0) /* sockaddr_dl (= proxy NA) or NULL */
{
struct mbuf *m;
struct ip6_hdr *ip6;
struct in6_ifaddr *ia;
struct sockaddr_in6 dst_sa;
int icmp6len, maxlen, error;
- struct ifnet *outif = NULL;
+ struct ifnet *outif = NULL;
struct ip6_out_args ip6oa;
bzero(&ro, sizeof(ro));
- daddr6 = *daddr6_0; /* make a local copy for modification */
+ daddr6 = *daddr6_0; /* make a local copy for modification */
bzero(&ip6oa, sizeof(ip6oa));
ip6oa.ip6oa_boundif = ifp->if_index;
return;
}
- MGETHDR(m, M_DONTWAIT, MT_DATA); /* XXXMAC: mac_create_mbuf_linklayer() probably */
+ MGETHDR(m, M_DONTWAIT, MT_DATA); /* XXXMAC: mac_create_mbuf_linklayer() probably */
if (m && max_linkhdr + maxlen >= MHLEN) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
m = NULL;
}
}
- if (m == NULL)
+ if (m == NULL) {
return;
+ }
m->m_pkthdr.rcvif = NULL;
if (IN6_IS_ADDR_MULTICAST(&daddr6)) {
icmp6len = sizeof(*nd_na);
m->m_pkthdr.len = m->m_len = sizeof(struct ip6_hdr) + icmp6len;
- m->m_data += max_linkhdr; /* or MH_ALIGN() equivalent? */
+ m->m_data += max_linkhdr; /* or MH_ALIGN() equivalent? */
/* fill neighbor advertisement packet */
ip6 = mtod(m, struct ip6_hdr *);
daddr6.s6_addr32[1] = 0;
daddr6.s6_addr32[2] = 0;
daddr6.s6_addr32[3] = IPV6_ADDR_INT32_ONE;
- if (in6_setscope(&daddr6, ifp, NULL))
+ if (in6_setscope(&daddr6, ifp, NULL)) {
goto bad;
+ }
flags &= ~ND_NA_FLAG_SOLICITED;
- } else
+ } else {
ip6->ip6_dst = daddr6;
+ }
bzero(&dst_sa, sizeof(struct sockaddr_in6));
dst_sa.sin6_family = AF_INET6;
*/
ia = in6ifa_ifpwithaddr(ifp, src);
if (ia != NULL) {
- if (ia->ia6_flags & IN6_IFF_OPTIMISTIC)
+ if (ia->ia6_flags & IN6_IFF_OPTIMISTIC) {
flags &= ~ND_NA_FLAG_OVERRIDE;
+ }
IFA_REMREF(&ia->ia_ifa);
}
* lladdr in sdl0. If we are not proxying (sending NA for
* my address) use lladdr configured for the interface.
*/
- if (sdl0 == NULL)
+ if (sdl0 == NULL) {
mac = nd6_ifptomac(ifp);
- else if (sdl0->sa_family == AF_LINK) {
+ } else if (sdl0->sa_family == AF_LINK) {
struct sockaddr_dl *sdl;
sdl = (struct sockaddr_dl *)(void *)sdl0;
- if (sdl->sdl_alen == ifp->if_addrlen)
+ if (sdl->sdl_alen == ifp->if_addrlen) {
mac = LLADDR(sdl);
+ }
}
}
if (tlladdr && mac) {
nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
nd_opt->nd_opt_len = optlen >> 3;
bcopy(mac, (caddr_t)(nd_opt + 1), ifp->if_addrlen);
- } else
+ } else {
flags &= ~ND_NA_FLAG_OVERRIDE;
+ }
ip6->ip6_plen = htons((u_short)icmp6len);
nd_na->nd_na_flags_reserved = flags;
nd_na->nd_na_cksum = 0;
nd_na->nd_na_cksum =
- in6_cksum(m, IPPROTO_ICMPV6, sizeof(struct ip6_hdr), icmp6len);
+ in6_cksum(m, IPPROTO_ICMPV6, sizeof(struct ip6_hdr), icmp6len);
m->m_pkthdr.pkt_flags |= PKTF_INET6_RESOLVE;
icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]++;
exit:
- if (im6o != NULL)
+ if (im6o != NULL) {
IM6O_REMREF(im6o);
+ }
ROUTE_RELEASE(&ro);
return;
#endif
case IFT_BRIDGE:
case IFT_ISO88025:
- return ((caddr_t)IF_LLADDR(ifp));
+ return (caddr_t)IF_LLADDR(ifp);
default:
return NULL;
}
TAILQ_HEAD(dadq_head, dadq);
struct dadq {
decl_lck_mtx_data(, dad_lock);
- u_int32_t dad_refcount; /* reference count */
+ u_int32_t dad_refcount; /* reference count */
int dad_attached;
TAILQ_ENTRY(dadq) dad_list;
struct ifaddr *dad_ifa;
- int dad_count; /* max NS to send */
- int dad_ns_tcount; /* # of trials to send NS */
- int dad_ns_ocount; /* NS sent so far */
+ int dad_count; /* max NS to send */
+ int dad_ns_tcount; /* # of trials to send NS */
+ int dad_ns_ocount; /* NS sent so far */
int dad_ns_icount;
int dad_na_icount;
- int dad_ns_lcount; /* looped back NS */
+ int dad_ns_lcount; /* looped back NS */
int dad_loopbackprobe; /* probing state for loopback detection */
uint8_t dad_lladdr[ETHER_ADDR_LEN];
uint8_t dad_lladdrlen;
-#define ND_OPT_NONCE_LEN32 \
+#define ND_OPT_NONCE_LEN32 \
((ND_OPT_NONCE_LEN + sizeof(uint32_t) - 1)/sizeof(uint32_t))
uint32_t dad_nonce[ND_OPT_NONCE_LEN32];
};
TAILQ_INIT(&dadq);
- dad_size = sizeof (struct dadq);
+ dad_size = sizeof(struct dadq);
dad_zone = zinit(dad_size, DAD_ZONE_MAX * dad_size, 0, DAD_ZONE_NAME);
if (dad_zone == NULL) {
panic("%s: failed allocating %s", __func__, DAD_ZONE_NAME);
bzero(&hostrtmask, sizeof hostrtmask);
hostrtmask.sin6_family = AF_INET6;
hostrtmask.sin6_len = sizeof hostrtmask;
- for (i = 0; i < sizeof hostrtmask.sin6_addr; ++i)
+ for (i = 0; i < sizeof hostrtmask.sin6_addr; ++i) {
hostrtmask.sin6_addr.s6_addr[i] = 0xff;
+ }
}
static struct dadq *
break;
}
lck_mtx_unlock(dad6_mutex);
- return (dp);
+ return dp;
}
void
nd6_dad_stoptimer(
struct ifaddr *ifa)
{
-
untimeout((void (*)(void *))nd6_dad_timer, (void *)ifa);
}
void
nd6_dad_start(
struct ifaddr *ifa,
- int *tick_delay) /* minimum delay ticks for IFF_UP event */
+ int *tick_delay) /* minimum delay ticks for IFF_UP event */
{
struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa;
struct dadq *dp;
IFA_LOCK(&ia->ia_ifa);
if (!(ia->ia6_flags & IN6_IFF_DADPROGRESS)) {
nd6log0((LOG_DEBUG,
- "nd6_dad_start: not a tentative or optimistic address "
- "%s(%s)\n",
- ip6_sprintf(&ia->ia_addr.sin6_addr),
- ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???"));
+ "nd6_dad_start: not a tentative or optimistic address "
+ "%s(%s)\n",
+ ip6_sprintf(&ia->ia_addr.sin6_addr),
+ ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???"));
IFA_UNLOCK(&ia->ia_ifa);
return;
}
return;
}
IFA_UNLOCK(&ia->ia_ifa);
- if (ifa->ifa_ifp == NULL)
+ if (ifa->ifa_ifp == NULL) {
panic("nd6_dad_start: ifa->ifa_ifp == NULL");
+ }
if (!(ifa->ifa_ifp->if_flags & IFF_UP) ||
(ifa->ifa_ifp->if_eflags & IFEF_IPV6_ND6ALT)) {
return;
dp = zalloc(dad_zone);
if (dp == NULL) {
nd6log0((LOG_ERR, "nd6_dad_start: memory allocation failed for "
- "%s(%s)\n",
- ip6_sprintf(&ia->ia_addr.sin6_addr),
- ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???"));
+ "%s(%s)\n",
+ ip6_sprintf(&ia->ia_addr.sin6_addr),
+ ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???"));
return;
}
bzero(dp, dad_size);
} else {
int ntick;
- if (*tick_delay == 0)
+ if (*tick_delay == 0) {
ntick = random() % (MAX_RTR_SOLICITATION_DELAY * hz);
- else
+ } else {
ntick = *tick_delay + random() % (hz / 2);
+ }
*tick_delay = ntick;
timeout((void (*)(void *))nd6_dad_timer, (void *)ifa,
- ntick);
+ ntick);
}
- DAD_REMREF(dp); /* drop our reference */
+ DAD_REMREF(dp); /* drop our reference */
}
static struct dadq *
lck_mtx_lock(dad6_mutex);
DAD_LOCK(dp);
dp->dad_ifa = ifa;
- IFA_ADDREF(ifa); /* for dad_ifa */
+ IFA_ADDREF(ifa); /* for dad_ifa */
dp->dad_count = ip6_dad_count;
dp->dad_ns_icount = dp->dad_na_icount = 0;
dp->dad_ns_ocount = dp->dad_ns_tcount = 0;
VERIFY(!dp->dad_attached);
dp->dad_attached = 1;
dp->dad_lladdrlen = 0;
- DAD_ADDREF_LOCKED(dp); /* for caller */
- DAD_ADDREF_LOCKED(dp); /* for dadq_head list */
+ DAD_ADDREF_LOCKED(dp); /* for caller */
+ DAD_ADDREF_LOCKED(dp); /* for dadq_head list */
TAILQ_INSERT_TAIL(&dadq, (struct dadq *)dp, dad_list);
DAD_UNLOCK(dp);
lck_mtx_unlock(dad6_mutex);
- return (dp);
+ return dp;
}
static void
DAD_UNLOCK(dp);
lck_mtx_unlock(dad6_mutex);
if (detached) {
- DAD_REMREF(dp); /* drop dadq_head reference */
+ DAD_REMREF(dp); /* drop dadq_head reference */
}
}
untimeout((void (*)(void *))nd6_dad_timer, (void *)ifa);
nd6_dad_detach(dp, ifa);
- DAD_REMREF(dp); /* drop our reference */
+ DAD_REMREF(dp); /* drop our reference */
}
static void
if ((ifp->if_flags & IFF_UP) == 0 ||
(ifp->if_flags & IFF_RUNNING) == 0 ||
- (ifp->if_eflags & IFEF_IPV6_ND6ALT) != 0)
+ (ifp->if_eflags & IFEF_IPV6_ND6ALT) != 0) {
return;
+ }
IFA_LOCK_SPIN(&ia->ia_ifa);
taddr6 = ia->ia_addr.sin6_addr;
IFA_UNLOCK(&ia->ia_ifa);
- if (in6_setscope(&taddr6, ifp, NULL) != 0)
+ if (in6_setscope(&taddr6, ifp, NULL) != 0) {
return;
+ }
saddr6 = in6addr_linklocal_allnodes;
- if (in6_setscope(&saddr6, ifp, NULL) != 0)
+ if (in6_setscope(&saddr6, ifp, NULL) != 0) {
return;
+ }
nd6log((LOG_INFO, "%s: sending unsolicited NA\n",
if_name(ifa->ifa_ifp)));
IFA_LOCK(&ia->ia_ifa);
if (ia->ia6_flags & IN6_IFF_DUPLICATED) {
nd6log0((LOG_ERR, "nd6_dad_timer: called with duplicated address "
- "%s(%s)\n",
- ip6_sprintf(&ia->ia_addr.sin6_addr),
- ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???"));
+ "%s(%s)\n",
+ ip6_sprintf(&ia->ia_addr.sin6_addr),
+ ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???"));
IFA_UNLOCK(&ia->ia_ifa);
goto done;
}
if ((ia->ia6_flags & IN6_IFF_DADPROGRESS) == 0) {
nd6log0((LOG_ERR, "nd6_dad_timer: not a tentative or optimistic "
- "address %s(%s)\n",
- ip6_sprintf(&ia->ia_addr.sin6_addr),
- ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???"));
+ "address %s(%s)\n",
+ ip6_sprintf(&ia->ia_addr.sin6_addr),
+ ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???"));
IFA_UNLOCK(&ia->ia_ifa);
goto done;
}
if (dp->dad_ns_tcount > dad_maxtry) {
DAD_UNLOCK(dp);
nd6log0((LOG_INFO, "%s: could not run DAD, driver problem?\n",
- if_name(ifa->ifa_ifp)));
+ if_name(ifa->ifa_ifp)));
nd6_dad_detach(dp, ifa);
goto done;
* See what we've got.
*/
if (dp->dad_na_icount > 0 || dp->dad_ns_icount) {
- /* We've seen NS or NA, means DAD has failed. */
+ /* We've seen NS or NA, means DAD has failed. */
DAD_UNLOCK(dp);
nd6log0((LOG_INFO,
"%s: duplicate IPv6 address %s [timer]\n",
dp->dad_ns_lcount > dp->dad_loopbackprobe) {
dp->dad_loopbackprobe = dp->dad_ns_lcount;
dp->dad_count =
- dp->dad_ns_ocount + dad_maxtry - 1;
+ dp->dad_ns_ocount + dad_maxtry - 1;
DAD_UNLOCK(dp);
ndi = ND_IFINFO(ifa->ifa_ifp);
VERIFY(ndi != NULL && ndi->initialized);
lck_mtx_unlock(&ndi->lock);
/*
- * Sec. 4.1 in RFC 7527 requires transmission of
- * additional probes until the loopback condition
- * becomes clear when a looped back probe is detected.
- */
+ * Sec. 4.1 in RFC 7527 requires transmission of
+ * additional probes until the loopback condition
+ * becomes clear when a looped back probe is detected.
+ */
nd6log0((LOG_INFO,
"%s: a looped back NS message is "
"detected during DAD for %s. "
ip6_sprintf(&ia->ia_addr.sin6_addr),
txunsolna ? ", tx unsolicited NA with O=1" : "."));
- if (dp->dad_ns_lcount > 0)
+ if (dp->dad_ns_lcount > 0) {
nd6log0((LOG_DEBUG,
"%s: DAD completed while "
"a looped back NS message is detected "
__func__,
ip6_sprintf(&ia->ia_addr.sin6_addr),
if_name(ia->ia_ifp)));
+ }
in6_post_msg(ia->ia_ifp, KEV_INET6_NEW_USER_ADDR, ia,
dp->dad_lladdr);
}
done:
- if (dp != NULL)
- DAD_REMREF(dp); /* drop our reference */
+ if (dp != NULL) {
+ DAD_REMREF(dp); /* drop our reference */
+ }
}
void
* very sure that hardware addresses are supposed to be unique.
*/
switch (ifp->if_type) {
- case IFT_BRIDGE:
- case IFT_ETHER:
- case IFT_FDDI:
- case IFT_ATM:
- case IFT_IEEE1394:
+ case IFT_BRIDGE:
+ case IFT_ETHER:
+ case IFT_FDDI:
+ case IFT_ATM:
+ case IFT_IEEE1394:
#ifdef IFT_IEEE80211
- case IFT_IEEE80211:
+ case IFT_IEEE80211:
#endif
+ /*
+ * Check if our hardware address matches the
+ * link layer information received in the
+ * NS/NA
+ */
+ llifa = ifp->if_lladdr;
+ IFA_LOCK(llifa);
+ sdl = (struct sockaddr_dl *)(void *)
+ llifa->ifa_addr;
+ if (lladdrlen == sdl->sdl_alen &&
+ bcmp(lladdr, LLADDR(sdl), lladdrlen) == 0) {
+ candisable = TRUE;
+ }
+ IFA_UNLOCK(llifa);
+
+ in6 = ia->ia_addr.sin6_addr;
+ if (in6_iid_from_hw(ifp, &in6) != 0) {
+ break;
+ }
+
+ /* Refine decision about whether IPv6 can be disabled */
+ if (candisable &&
+ !IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr, &in6)) {
/*
- * Check if our hardware address matches the
- * link layer information received in the
- * NS/NA
+ * Apply this logic only to the embedded MAC
+ * address form of link-local IPv6 address.
*/
- llifa = ifp->if_lladdr;
- IFA_LOCK(llifa);
- sdl = (struct sockaddr_dl *)(void *)
- llifa->ifa_addr;
- if (lladdrlen == sdl->sdl_alen &&
- bcmp(lladdr, LLADDR(sdl), lladdrlen) == 0)
- candisable = TRUE;
- IFA_UNLOCK(llifa);
-
- in6 = ia->ia_addr.sin6_addr;
- if (in6_iid_from_hw(ifp, &in6) != 0)
- break;
-
- /* Refine decision about whether IPv6 can be disabled */
- if (candisable &&
- !IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr, &in6)) {
- /*
- * Apply this logic only to the embedded MAC
- * address form of link-local IPv6 address.
- */
- candisable = FALSE;
- } else if (lladdr == NULL &&
- IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr, &in6)) {
- /*
- * We received a NA with no target link-layer
- * address option. This means that someone else
- * has our address. Mark it as a hardware
- * duplicate so we disable IPv6 later on.
- */
- candisable = TRUE;
- }
- break;
- default:
- break;
+ candisable = FALSE;
+ } else if (lladdr == NULL &&
+ IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr, &in6)) {
+ /*
+ * We received a NA with no target link-layer
+ * address option. This means that someone else
+ * has our address. Mark it as a hardware
+ * duplicate so we disable IPv6 later on.
+ */
+ candisable = TRUE;
+ }
+ break;
+ default:
+ break;
}
}
DAD_UNLOCK(dp);
*/
in6_post_msg(ifp, KEV_INET6_NEW_USER_ADDR, ia, dp->dad_lladdr);
nd6_dad_detach(dp, ifa);
- DAD_REMREF(dp); /* drop our reference */
+ DAD_REMREF(dp); /* drop our reference */
}
static void
taddr6 = ia->ia_addr.sin6_addr;
IFA_UNLOCK(&ia->ia_ifa);
if (dad_enhanced != 0 && !(ifp->if_flags & IFF_POINTOPOINT)) {
- for (i = 0; i < ND_OPT_NONCE_LEN32; i++)
+ for (i = 0; i < ND_OPT_NONCE_LEN32; i++) {
dp->dad_nonce[i] = RandomULong();
+ }
/*
* XXXHRS: Note that in the case that
* DupAddrDetectTransmits > 1, multiple NS messages with
VERIFY(ifa != NULL);
/* Ignore Nonce option when Enhanced DAD is disabled. */
- if (dad_enhanced == 0)
+ if (dad_enhanced == 0) {
ndopt_nonce = NULL;
+ }
dp = nd6_dad_find(ifa, ndopt_nonce);
- if (dp == NULL)
+ if (dp == NULL) {
return;
+ }
DAD_LOCK(dp);
++dp->dad_ns_icount;
*
* @param m is the pointer to the packet's mbuf
* @param ifp is the pointer to the interface on which packet
- * was receicved.
+ * was receicved.
* @param taddr is pointer to target's IPv6 address
* @param lladdr is target's link layer information
* @param lladdrlen is target's linklayer length
*
* @return NULL if the packet is consumed by DAD processing, else
- * pointer to the mbuf.
+ * pointer to the mbuf.
*/
static struct mbuf *
nd6_dad_na_input(struct mbuf *m, struct ifnet *ifp, struct in6_addr *taddr,
boolean_t replicated;
ifa = (struct ifaddr *) in6ifa_ifpwithaddr(ifp, taddr);
- if (ifa == NULL)
+ if (ifa == NULL) {
return m;
+ }
replicated = FALSE;
if (lladdr != NULL && lladdrlen >= ETHER_ADDR_LEN) {
struct ip6aux *ip6a = ip6_findaux(m);
if (ip6a && (ip6a->ip6a_flags & IP6A_HASEEN) != 0 &&
- bcmp(ip6a->ip6a_ehsrc, lladdr, ETHER_ADDR_LEN) != 0) {
+ bcmp(ip6a->ip6a_ehsrc, lladdr, ETHER_ADDR_LEN) != 0) {
IFA_UNLOCK(ifa);
nd6log((LOG_ERR, "%s: ignoring duplicate NA on %s "
"[eh_src != tgtlladdr]\n", __func__, if_name(ifp)));
static void
dad_addref(struct dadq *dp, int locked)
{
- if (!locked)
+ if (!locked) {
DAD_LOCK_SPIN(dp);
- else
+ } else {
DAD_LOCK_ASSERT_HELD(dp);
+ }
if (++dp->dad_refcount == 0) {
panic("%s: dad %p wraparound refcnt\n", __func__, dp);
/* NOTREACHED */
}
- if (!locked)
+ if (!locked) {
DAD_UNLOCK(dp);
+ }
}
static void
struct ifaddr *ifa;
DAD_LOCK_SPIN(dp);
- if (dp->dad_refcount == 0)
+ if (dp->dad_refcount == 0) {
panic("%s: dad %p negative refcnt\n", __func__, dp);
+ }
--dp->dad_refcount;
if (dp->dad_refcount > 0) {
DAD_UNLOCK(dp);
}
if ((ifa = dp->dad_ifa) != NULL) {
- IFA_REMREF(ifa); /* drop dad_ifa reference */
+ IFA_REMREF(ifa); /* drop dad_ifa reference */
dp->dad_ifa = NULL;
}
nd6_llreach_set_reachable(struct ifnet *ifp, void *addr, unsigned int alen)
{
/* Nothing more to do if it's disabled */
- if (nd6_llreach_base == 0)
+ if (nd6_llreach_base == 0) {
return;
+ }
ifnet_llreach_set_reachable(ifp, ETHERTYPE_IPV6, addr, alen);
}
bcopy(sa, sdl, sa->sa_len);
sin6->sin6_scope_id = sdla->sdl_index;
- if (sin6->sin6_scope_id == 0)
+ if (sin6->sin6_scope_id == 0) {
sin6->sin6_scope_id = ifp->if_index;
+ }
in6->s6_addr[0] = 0xfe;
in6->s6_addr[1] = 0x80;
- if (sdla->sdl_alen == EUI64_LENGTH)
+ if (sdla->sdl_alen == EUI64_LENGTH) {
bcopy(lla, &in6->s6_addr[8], EUI64_LENGTH);
- else {
+ } else {
VERIFY(sdla->sdl_alen == ETHER_ADDR_LEN);
in6->s6_addr[8] = ((uint8_t) lla[0] ^ ND6_EUI64_UBIT);
{
struct rtentry *rt;
struct llinfo_nd6 *ln;
- struct if_llreach *lr = NULL;
+ struct if_llreach *lr = NULL;
const uint16_t temp_embedded_id = sin6->sin6_addr.s6_addr16[1];
if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr) &&
- (temp_embedded_id == 0))
+ (temp_embedded_id == 0)) {
sin6->sin6_addr.s6_addr16[1] = htons(ifp->if_index);
+ }
nd6_cache_lladdr(ifp, &sin6->sin6_addr, LLADDR(sdl), sdl->sdl_alen,
ND_NEIGHBOR_ADVERT, 0);
ifp->if_index);
/* Restore the address that was passed to us */
- if (temp_embedded_id == 0)
+ if (temp_embedded_id == 0) {
sin6->sin6_addr.s6_addr16[1] = 0;
+ }
if (rt != NULL) {
RT_LOCK(rt);
ip6_sprintf(&sin6->sin6_addr)));
if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr) &&
- (temp_embedded_id == 0))
+ (temp_embedded_id == 0)) {
sin6->sin6_addr.s6_addr16[1] = htons(ifp->if_index);
+ }
LCK_MTX_ASSERT(rnh_lock, LCK_MTX_ASSERT_NOTOWNED);
lck_mtx_lock(rnh_lock);
rt = rtalloc1_scoped_locked((struct sockaddr *)sin6, 0, 0,
ifp->if_index);
- /* Restore the address that was passed to us */
- if (temp_embedded_id == 0)
+ /* Restore the address that was passed to us */
+ if (temp_embedded_id == 0) {
sin6->sin6_addr.s6_addr16[1] = 0;
+ }
if (rt != NULL) {
RT_LOCK(rt);
- if (!(rt->rt_flags & (RTF_CLONING|RTF_PRCLONING)) &&
- (rt->rt_flags & (RTF_HOST|RTF_LLINFO|RTF_WASCLONED)) ==
- (RTF_HOST|RTF_LLINFO|RTF_WASCLONED)) {
+ if (!(rt->rt_flags & (RTF_CLONING | RTF_PRCLONING)) &&
+ (rt->rt_flags & (RTF_HOST | RTF_LLINFO | RTF_WASCLONED)) ==
+ (RTF_HOST | RTF_LLINFO | RTF_WASCLONED)) {
rt->rt_flags |= RTF_CONDEMNED;
RT_UNLOCK(rt);