]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netinet6/icmp6.c
xnu-4903.270.47.tar.gz
[apple/xnu.git] / bsd / netinet6 / icmp6.c
index f80a4154aa04abf5d0cda74d66ac9aa9335a7a0c..f1d66606e8947ba511fd5772d5e28a8d5a9d8c8e 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2000-2017 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
@@ -160,14 +160,14 @@ static void icmp6_errcount(struct icmp6errstat *, int, int);
 static int icmp6_rip6_input(struct mbuf **, int);
 static int icmp6_ratelimit(const struct in6_addr *, const int, const int);
 static const char *icmp6_redirect_diag(struct in6_addr *,
 static int icmp6_rip6_input(struct mbuf **, int);
 static int icmp6_ratelimit(const struct in6_addr *, const int, const int);
 static const char *icmp6_redirect_diag(struct in6_addr *,
-       struct in6_addr *, struct in6_addr *);
+    struct in6_addr *, struct in6_addr *);
 static struct mbuf *ni6_input(struct mbuf *, int);
 static struct mbuf *ni6_nametodns(const char *, int, int);
 static int ni6_dnsmatch(const char *, int, const char *, int);
 static int ni6_addrs(struct icmp6_nodeinfo *,
 static struct mbuf *ni6_input(struct mbuf *, int);
 static struct mbuf *ni6_nametodns(const char *, int, int);
 static int ni6_dnsmatch(const char *, int, const char *, int);
 static int ni6_addrs(struct icmp6_nodeinfo *,
-                         struct ifnet **, char *);
+    struct ifnet **, char *);
 static int ni6_store_addrs(struct icmp6_nodeinfo *, struct icmp6_nodeinfo *,
 static int ni6_store_addrs(struct icmp6_nodeinfo *, struct icmp6_nodeinfo *,
-                               struct ifnet *, int);
+    struct ifnet *, int);
 static int icmp6_notify_error(struct mbuf *, int, int, int);
 
 
 static int icmp6_notify_error(struct mbuf *, int, int, int);
 
 
@@ -180,7 +180,7 @@ icmp6_init(struct ip6protosw *pp, struct domain *dp)
 
        /* Also called from ip6_init() without pp */
        VERIFY(pp == NULL ||
 
        /* Also called from ip6_init() without pp */
        VERIFY(pp == NULL ||
-           (pp->pr_flags & (PR_INITIALIZED|PR_ATTACHED)) == PR_ATTACHED);
+           (pp->pr_flags & (PR_INITIALIZED | PR_ATTACHED)) == PR_ATTACHED);
 
        /* This gets called by more than one protocols, so initialize once */
        if (!icmp6_initialized) {
 
        /* This gets called by more than one protocols, so initialize once */
        if (!icmp6_initialized) {
@@ -255,25 +255,29 @@ icmp6_error2(struct mbuf *m, int type, int code, int param,
 {
        struct ip6_hdr *ip6;
 
 {
        struct ip6_hdr *ip6;
 
-       if (ifp == NULL)
+       if (ifp == NULL) {
                return;
                return;
+       }
 
 #ifndef PULLDOWN_TEST
 
 #ifndef PULLDOWN_TEST
-       IP6_EXTHDR_CHECK(m, 0, sizeof(struct ip6_hdr),return );
+       IP6_EXTHDR_CHECK(m, 0, sizeof(struct ip6_hdr), return );
 #else
        if (m->m_len < sizeof(struct ip6_hdr)) {
                m = m_pullup(m, sizeof(struct ip6_hdr));
 #else
        if (m->m_len < sizeof(struct ip6_hdr)) {
                m = m_pullup(m, sizeof(struct ip6_hdr));
-               if (m == NULL)
+               if (m == NULL) {
                        return;
                        return;
+               }
        }
 #endif
 
        ip6 = mtod(m, struct ip6_hdr *);
 
        }
 #endif
 
        ip6 = mtod(m, struct ip6_hdr *);
 
-       if (in6_setscope(&ip6->ip6_src, ifp, NULL) != 0)
+       if (in6_setscope(&ip6->ip6_src, ifp, NULL) != 0) {
                return;
                return;
-       if (in6_setscope(&ip6->ip6_dst, ifp, NULL) != 0)
+       }
+       if (in6_setscope(&ip6->ip6_dst, ifp, NULL) != 0) {
                return;
                return;
+       }
 
        icmp6_error(m, type, code, param);
 }
 
        icmp6_error(m, type, code, param);
 }
@@ -282,11 +286,13 @@ icmp6_error2(struct mbuf *m, int type, int code, int param,
  * Generate an error packet of type error in response to bad IP6 packet.
  */
 void
  * Generate an error packet of type error in response to bad IP6 packet.
  */
 void
-icmp6_error(struct mbuf *m, int type, int code, int param) {
+icmp6_error(struct mbuf *m, int type, int code, int param)
+{
        icmp6_error_flag(m, type, code, param, ICMP6_ERROR_RST_MRCVIF);
 }
 
        icmp6_error_flag(m, type, code, param, ICMP6_ERROR_RST_MRCVIF);
 }
 
-void icmp6_error_flag (struct mbuf *m, int type, int code, int param, int flags)
+void
+icmp6_error_flag(struct mbuf *m, int type, int code, int param, int flags)
 {
        struct ip6_hdr *oip6, *nip6;
        struct icmp6_hdr *icmp6;
 {
        struct ip6_hdr *oip6, *nip6;
        struct icmp6_hdr *icmp6;
@@ -299,7 +305,7 @@ void icmp6_error_flag (struct mbuf *m, int type, int code, int param, int flags)
        /* count per-type-code statistics */
        icmp6_errcount(&icmp6stat.icp6s_outerrhist, type, code);
 
        /* count per-type-code statistics */
        icmp6_errcount(&icmp6stat.icp6s_outerrhist, type, code);
 
-#ifdef M_DECRYPTED     /*not openbsd*/
+#ifdef M_DECRYPTED      /*not openbsd*/
        if (m->m_flags & M_DECRYPTED) {
                icmp6stat.icp6s_canterror++;
                goto freeit;
        if (m->m_flags & M_DECRYPTED) {
                icmp6stat.icp6s_canterror++;
                goto freeit;
@@ -307,12 +313,13 @@ void icmp6_error_flag (struct mbuf *m, int type, int code, int param, int flags)
 #endif
 
 #ifndef PULLDOWN_TEST
 #endif
 
 #ifndef PULLDOWN_TEST
-       IP6_EXTHDR_CHECK(m, 0, sizeof(struct ip6_hdr), return);
+       IP6_EXTHDR_CHECK(m, 0, sizeof(struct ip6_hdr), return );
 #else
        if (m->m_len < sizeof(struct ip6_hdr)) {
                m = m_pullup(m, sizeof(struct ip6_hdr));
 #else
        if (m->m_len < sizeof(struct ip6_hdr)) {
                m = m_pullup(m, sizeof(struct ip6_hdr));
-               if (m == NULL)
+               if (m == NULL) {
                        return;
                        return;
+               }
        }
 #endif
        oip6 = mtod(m, struct ip6_hdr *);
        }
 #endif
        oip6 = mtod(m, struct ip6_hdr *);
@@ -328,20 +335,22 @@ void icmp6_error_flag (struct mbuf *m, int type, int code, int param, int flags)
         *   in the option type field.  This check has been done in
         *   ip6_unknown_opt(), so we can just check the type and code.
         */
         *   in the option type field.  This check has been done in
         *   ip6_unknown_opt(), so we can just check the type and code.
         */
-       if ((m->m_flags & (M_BCAST|M_MCAST) ||
-            IN6_IS_ADDR_MULTICAST(&oip6->ip6_dst)) &&
+       if ((m->m_flags & (M_BCAST | M_MCAST) ||
+           IN6_IS_ADDR_MULTICAST(&oip6->ip6_dst)) &&
            (type != ICMP6_PACKET_TOO_BIG &&
            (type != ICMP6_PACKET_TOO_BIG &&
-            (type != ICMP6_PARAM_PROB ||
-             code != ICMP6_PARAMPROB_OPTION)))
+           (type != ICMP6_PARAM_PROB ||
+           code != ICMP6_PARAMPROB_OPTION))) {
                goto freeit;
                goto freeit;
+       }
 
        /*
         * RFC 2463, 2.4 (e.5): source address check.
         * XXX: the case of anycast source?
         */
        if (IN6_IS_ADDR_UNSPECIFIED(&oip6->ip6_src) ||
 
        /*
         * RFC 2463, 2.4 (e.5): source address check.
         * XXX: the case of anycast source?
         */
        if (IN6_IS_ADDR_UNSPECIFIED(&oip6->ip6_src) ||
-           IN6_IS_ADDR_MULTICAST(&oip6->ip6_src))
+           IN6_IS_ADDR_MULTICAST(&oip6->ip6_src)) {
                goto freeit;
                goto freeit;
+       }
 
        /*
         * If we are about to send ICMPv6 against ICMPv6 error/redirect,
 
        /*
         * If we are about to send ICMPv6 against ICMPv6 error/redirect,
@@ -353,11 +362,11 @@ void icmp6_error_flag (struct mbuf *m, int type, int code, int param, int flags)
                struct icmp6_hdr *icp;
 
 #ifndef PULLDOWN_TEST
                struct icmp6_hdr *icp;
 
 #ifndef PULLDOWN_TEST
-               IP6_EXTHDR_CHECK(m, 0, off + sizeof(struct icmp6_hdr), return);
+               IP6_EXTHDR_CHECK(m, 0, off + sizeof(struct icmp6_hdr), return );
                icp = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
 #else
                IP6_EXTHDR_GET(icp, struct icmp6_hdr *, m, off,
                icp = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
 #else
                IP6_EXTHDR_GET(icp, struct icmp6_hdr *, m, off,
-                       sizeof(*icp));
+                   sizeof(*icp));
                if (icp == NULL) {
                        icmp6stat.icp6s_tooshort++;
                        return;
                if (icp == NULL) {
                        icmp6stat.icp6s_tooshort++;
                        return;
@@ -391,13 +400,15 @@ void icmp6_error_flag (struct mbuf *m, int type, int code, int param, int flags)
         * OK, ICMP6 can be generated.
         */
 
         * OK, ICMP6 can be generated.
         */
 
-       if (m->m_pkthdr.len >= ICMPV6_PLD_MAXLEN)
+       if (m->m_pkthdr.len >= ICMPV6_PLD_MAXLEN) {
                m_adj(m, ICMPV6_PLD_MAXLEN - m->m_pkthdr.len);
                m_adj(m, ICMPV6_PLD_MAXLEN - m->m_pkthdr.len);
+       }
 
        preplen = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr);
        M_PREPEND(m, preplen, M_DONTWAIT, 1);
 
        preplen = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr);
        M_PREPEND(m, preplen, M_DONTWAIT, 1);
-       if (m && m->m_len < preplen)
+       if (m && m->m_len < preplen) {
                m = m_pullup(m, preplen);
                m = m_pullup(m, preplen);
+       }
        if (m == NULL) {
                nd6log((LOG_DEBUG, "ENOBUFS in icmp6_error %d\n", __LINE__));
                return;
        if (m == NULL) {
                nd6log((LOG_DEBUG, "ENOBUFS in icmp6_error %d\n", __LINE__));
                return;
@@ -431,7 +442,7 @@ void icmp6_error_flag (struct mbuf *m, int type, int code, int param, int flags)
 
        return;
 
 
        return;
 
-  freeit:
+freeit:
        /*
         * If we can't tell whether or not we can generate ICMP6, free it.
         */
        /*
         * If we can't tell whether or not we can generate ICMP6, free it.
         */
@@ -514,7 +525,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
         * Note: SSM filters are not applied for ICMPv6 traffic.
         */
        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
         * Note: SSM filters are not applied for ICMPv6 traffic.
         */
        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
-               struct in6_multi        *inm;
+               struct in6_multi        *inm;
 
                in6_multihead_lock_shared();
                IN6_LOOKUP_MULTI(&ip6->ip6_dst, ifp, inm);
 
                in6_multihead_lock_shared();
                IN6_LOOKUP_MULTI(&ip6->ip6_dst, ifp, inm);
@@ -566,15 +577,16 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
 
        icmp6stat.icp6s_inhist[icmp6->icmp6_type]++;
        icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_msg);
 
        icmp6stat.icp6s_inhist[icmp6->icmp6_type]++;
        icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_msg);
-       if (icmp6->icmp6_type < ICMP6_INFOMSG_MASK)
+       if (icmp6->icmp6_type < ICMP6_INFOMSG_MASK) {
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_error);
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_error);
+       }
 
        switch (icmp6->icmp6_type) {
        case ICMP6_DST_UNREACH:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_dstunreach);
                switch (code) {
                case ICMP6_DST_UNREACH_NOROUTE:
 
        switch (icmp6->icmp6_type) {
        case ICMP6_DST_UNREACH:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_dstunreach);
                switch (code) {
                case ICMP6_DST_UNREACH_NOROUTE:
-               case ICMP6_DST_UNREACH_ADDR:    /* PRC_HOSTDEAD is a DOS */
+               case ICMP6_DST_UNREACH_ADDR:    /* PRC_HOSTDEAD is a DOS */
                        code = PRC_UNREACH_NET;
                        break;
                case ICMP6_DST_UNREACH_ADMIN:
                        code = PRC_UNREACH_NET;
                        break;
                case ICMP6_DST_UNREACH_ADMIN:
@@ -635,15 +647,16 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
 
        case ICMP6_ECHO_REQUEST:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_echo);
 
        case ICMP6_ECHO_REQUEST:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_echo);
-               if (code != 0)
+               if (code != 0) {
                        goto badcode;
                        goto badcode;
+               }
 
                if ((n = m_copy(m, 0, M_COPYALL)) == NULL) {
                        /* Give up remote */
                        goto rate_limit_checked;
                }
                if ((n->m_flags & M_EXT) != 0
 
                if ((n = m_copy(m, 0, M_COPYALL)) == NULL) {
                        /* Give up remote */
                        goto rate_limit_checked;
                }
                if ((n->m_flags & M_EXT) != 0
-                || n->m_len < off + sizeof(struct icmp6_hdr)) {
+                   || n->m_len < off + sizeof(struct icmp6_hdr)) {
                        struct mbuf *n0 = n;
                        const int maxlen = sizeof(*nip6) + sizeof(*nicmp6);
 
                        struct mbuf *n0 = n;
                        const int maxlen = sizeof(*nip6) + sizeof(*nicmp6);
 
@@ -656,7 +669,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
                                m_freem(n0);
                                goto rate_limit_checked;
                        }
                                m_freem(n0);
                                goto rate_limit_checked;
                        }
-                       MGETHDR(n, M_DONTWAIT, n0->m_type);     /* MAC-OK */
+                       MGETHDR(n, M_DONTWAIT, n0->m_type);     /* MAC-OK */
                        if (n && maxlen >= MHLEN) {
                                MCLGET(n, M_DONTWAIT);
                                if ((n->m_flags & M_EXT) == 0) {
                        if (n && maxlen >= MHLEN) {
                                MCLGET(n, M_DONTWAIT);
                                if ((n->m_flags & M_EXT) == 0) {
@@ -679,7 +692,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
                        bcopy(icmp6, nicmp6, sizeof(struct icmp6_hdr));
                        noff = sizeof(struct ip6_hdr);
                        n->m_pkthdr.len = n->m_len =
                        bcopy(icmp6, nicmp6, sizeof(struct icmp6_hdr));
                        noff = sizeof(struct ip6_hdr);
                        n->m_pkthdr.len = n->m_len =
-                               noff + sizeof(struct icmp6_hdr);
+                           noff + sizeof(struct icmp6_hdr);
                        /*
                         * Adjust mbuf. ip6_plen will be adjusted in
                         * ip6_output().
                        /*
                         * Adjust mbuf. ip6_plen will be adjusted in
                         * ip6_output().
@@ -691,12 +704,12 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
                } else {
                        nip6 = mtod(n, struct ip6_hdr *);
                        IP6_EXTHDR_GET(nicmp6, struct icmp6_hdr *, n, off,
                } else {
                        nip6 = mtod(n, struct ip6_hdr *);
                        IP6_EXTHDR_GET(nicmp6, struct icmp6_hdr *, n, off,
-                               sizeof(*nicmp6));
+                           sizeof(*nicmp6));
                        noff = off;
                }
                        noff = off;
                }
-               if(nicmp6 == NULL)
+               if (nicmp6 == NULL) {
                        panic("nicmp6 is NULL in %s, which isn't good!\n", __FUNCTION__);
                        panic("nicmp6 is NULL in %s, which isn't good!\n", __FUNCTION__);
-               else {
+               else {
                        nicmp6->icmp6_type = ICMP6_ECHO_REPLY;
                        nicmp6->icmp6_code = 0;
                }
                        nicmp6->icmp6_type = ICMP6_ECHO_REPLY;
                        nicmp6->icmp6_code = 0;
                }
@@ -709,62 +722,72 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
 
        case ICMP6_ECHO_REPLY:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_echoreply);
 
        case ICMP6_ECHO_REPLY:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_echoreply);
-               if (code != 0)
+               if (code != 0) {
                        goto badcode;
                        goto badcode;
+               }
                break;
 
        case MLD_LISTENER_QUERY:
        case MLD_LISTENER_REPORT:
 
                break;
 
        case MLD_LISTENER_QUERY:
        case MLD_LISTENER_REPORT:
 
-               if (icmp6len < sizeof(struct mld_hdr))
+               if (icmp6len < sizeof(struct mld_hdr)) {
                        goto badlen;
                        goto badlen;
-               if (icmp6->icmp6_type == MLD_LISTENER_QUERY) /* XXX: ugly... */
+               }
+               if (icmp6->icmp6_type == MLD_LISTENER_QUERY) { /* XXX: ugly... */
                        icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldquery);
                        icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldquery);
-               else
+               } else {
                        icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldreport);
                        icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldreport);
+               }
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
-                       if (mld_input(m, off, icmp6len) == IPPROTO_DONE)
+                       if (mld_input(m, off, icmp6len) == IPPROTO_DONE) {
                                m = NULL;
                                m = NULL;
+                       }
                        goto freeit;
                }
                        goto freeit;
                }
-               if (mld_input(n, off, icmp6len) != IPPROTO_DONE)
+               if (mld_input(n, off, icmp6len) != IPPROTO_DONE) {
                        m_freem(n);
                        m_freem(n);
+               }
                /* m stays. */
                goto rate_limit_checked;
 
        case MLD_LISTENER_DONE:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mlddone);
                /* m stays. */
                goto rate_limit_checked;
 
        case MLD_LISTENER_DONE:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mlddone);
-               if (icmp6len < sizeof(struct mld_hdr))  /* necessary? */
+               if (icmp6len < sizeof(struct mld_hdr)) { /* necessary? */
                        goto badlen;
                        goto badlen;
-               break;          /* nothing to be done in kernel */
+               }
+               break;          /* nothing to be done in kernel */
 
        case MLD_MTRACE_RESP:
        case MLD_MTRACE:
                /* XXX: these two are experimental.  not officially defined. */
                /* XXX: per-interface statistics? */
 
        case MLD_MTRACE_RESP:
        case MLD_MTRACE:
                /* XXX: these two are experimental.  not officially defined. */
                /* XXX: per-interface statistics? */
-               break;          /* just pass it to applications */
+               break;          /* just pass it to applications */
 
        case ICMP6_NI_QUERY:
 
        case ICMP6_NI_QUERY:
-               if (!icmp6_nodeinfo)
+               if (!icmp6_nodeinfo) {
                        break;
                        break;
+               }
 //### LD 10/20 Check fbsd differences here. Not sure we're more advanced or not.
                /* By RFC 4620 refuse to answer queries from global scope addresses */
 //### LD 10/20 Check fbsd differences here. Not sure we're more advanced or not.
                /* By RFC 4620 refuse to answer queries from global scope addresses */
-               if ((icmp6_nodeinfo & 8) != 8 && in6_addrscope(&ip6->ip6_src) == IPV6_ADDR_SCOPE_GLOBAL)
+               if ((icmp6_nodeinfo & 8) != 8 && in6_addrscope(&ip6->ip6_src) == IPV6_ADDR_SCOPE_GLOBAL) {
                        break;
                        break;
+               }
 
 
-               if (icmp6len < sizeof(struct icmp6_nodeinfo))
+               if (icmp6len < sizeof(struct icmp6_nodeinfo)) {
                        goto badlen;
                        goto badlen;
+               }
 
 #ifndef PULLDOWN_TEST
                IP6_EXTHDR_CHECK(m, off, sizeof(struct icmp6_nodeinfo),
 
 #ifndef PULLDOWN_TEST
                IP6_EXTHDR_CHECK(m, off, sizeof(struct icmp6_nodeinfo),
-                                return IPPROTO_DONE);
+                   return IPPROTO_DONE);
 #endif
 
                n = m_copy(m, 0, M_COPYALL);
 #endif
 
                n = m_copy(m, 0, M_COPYALL);
-               if (n)
+               if (n) {
                        n = ni6_input(n, off);
                        n = ni6_input(n, off);
+               }
                if (n) {
                        noff = sizeof(struct ip6_hdr);
                        icmp6stat.icp6s_reflect++;
                if (n) {
                        noff = sizeof(struct ip6_hdr);
                        icmp6stat.icp6s_reflect++;
@@ -774,16 +797,19 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
                goto rate_limit_checked;
 
        case ICMP6_WRUREPLY:
                goto rate_limit_checked;
 
        case ICMP6_WRUREPLY:
-               if (code != 0)
+               if (code != 0) {
                        goto badcode;
                        goto badcode;
+               }
                break;
 
        case ND_ROUTER_SOLICIT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routersolicit);
                break;
 
        case ND_ROUTER_SOLICIT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routersolicit);
-               if (code != 0)
+               if (code != 0) {
                        goto badcode;
                        goto badcode;
-               if (icmp6len < sizeof(struct nd_router_solicit))
+               }
+               if (icmp6len < sizeof(struct nd_router_solicit)) {
                        goto badlen;
                        goto badlen;
+               }
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
@@ -797,10 +823,12 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
 
        case ND_ROUTER_ADVERT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routeradvert);
 
        case ND_ROUTER_ADVERT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routeradvert);
-               if (code != 0)
+               if (code != 0) {
                        goto badcode;
                        goto badcode;
-               if (icmp6len < sizeof(struct nd_router_advert))
+               }
+               if (icmp6len < sizeof(struct nd_router_advert)) {
                        goto badlen;
                        goto badlen;
+               }
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
@@ -814,10 +842,12 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
 
        case ND_NEIGHBOR_SOLICIT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighborsolicit);
 
        case ND_NEIGHBOR_SOLICIT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighborsolicit);
-               if (code != 0)
+               if (code != 0) {
                        goto badcode;
                        goto badcode;
-               if (icmp6len < sizeof(struct nd_neighbor_solicit))
+               }
+               if (icmp6len < sizeof(struct nd_neighbor_solicit)) {
                        goto badlen;
                        goto badlen;
+               }
 
                if (proxy ||
                    ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL)) {
 
                if (proxy ||
                    ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL)) {
@@ -832,10 +862,12 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
 
        case ND_NEIGHBOR_ADVERT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighboradvert);
 
        case ND_NEIGHBOR_ADVERT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighboradvert);
-               if (code != 0)
+               if (code != 0) {
                        goto badcode;
                        goto badcode;
-               if (icmp6len < sizeof(struct nd_neighbor_advert))
+               }
+               if (icmp6len < sizeof(struct nd_neighbor_advert)) {
                        goto badlen;
                        goto badlen;
+               }
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
@@ -849,10 +881,12 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
 
        case ND_REDIRECT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_redirect);
 
        case ND_REDIRECT:
                icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_redirect);
-               if (code != 0)
+               if (code != 0) {
                        goto badcode;
                        goto badcode;
-               if (icmp6len < sizeof(struct nd_redirect))
+               }
+               if (icmp6len < sizeof(struct nd_redirect)) {
                        goto badlen;
                        goto badlen;
+               }
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
 
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
@@ -866,10 +900,12 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
 
        case ICMP6_ROUTER_RENUMBERING:
                if (code != ICMP6_ROUTER_RENUMBERING_COMMAND &&
 
        case ICMP6_ROUTER_RENUMBERING:
                if (code != ICMP6_ROUTER_RENUMBERING_COMMAND &&
-                   code != ICMP6_ROUTER_RENUMBERING_RESULT)
+                   code != ICMP6_ROUTER_RENUMBERING_RESULT) {
                        goto badcode;
                        goto badcode;
-               if (icmp6len < sizeof(struct icmp6_router_renum))
+               }
+               if (icmp6len < sizeof(struct icmp6_router_renum)) {
                        goto badlen;
                        goto badlen;
+               }
                break;
 
        default:
                break;
 
        default:
@@ -886,18 +922,18 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
                        /* ICMPv6 informational: MUST not deliver */
                        goto rate_limit_checked;
                }
                        /* ICMPv6 informational: MUST not deliver */
                        goto rate_limit_checked;
                }
-       deliver:
+deliver:
                if (icmp6_notify_error(m, off, icmp6len, code)) {
                        /* In this case, m should've been freed. */
                if (icmp6_notify_error(m, off, icmp6len, code)) {
                        /* In this case, m should've been freed. */
-                       return(IPPROTO_DONE);
+                       return IPPROTO_DONE;
                }
                break;
 
                }
                break;
 
-       badcode:
+badcode:
                icmp6stat.icp6s_badcode++;
                break;
 
                icmp6stat.icp6s_badcode++;
                break;
 
-       badlen:
+badlen:
                icmp6stat.icp6s_badlen++;
                break;
        }
                icmp6stat.icp6s_badlen++;
                break;
        }
@@ -925,15 +961,15 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
        }
 #ifndef PULLDOWN_TEST
        IP6_EXTHDR_CHECK(m, off,
        }
 #ifndef PULLDOWN_TEST
        IP6_EXTHDR_CHECK(m, off,
-                        sizeof(struct icmp6_hdr) + sizeof(struct ip6_hdr),
-                        return -1);
+           sizeof(struct icmp6_hdr) + sizeof(struct ip6_hdr),
+           return -1);
        icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
 #else
        IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off,
        icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
 #else
        IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off,
-                      sizeof(*icmp6) + sizeof(struct ip6_hdr));
+           sizeof(*icmp6) + sizeof(struct ip6_hdr));
        if (icmp6 == NULL) {
                icmp6stat.icp6s_tooshort++;
        if (icmp6 == NULL) {
                icmp6stat.icp6s_tooshort++;
-               return(-1);
+               return -1;
        }
 #endif
        eip6 = (struct ip6_hdr *)(icmp6 + 1);
        }
 #endif
        eip6 = (struct ip6_hdr *)(icmp6 + 1);
@@ -943,7 +979,7 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                void (*ctlfunc)(int, struct sockaddr *, void *, struct ifnet *);
                u_int8_t nxt = eip6->ip6_nxt;
                int eoff = off + sizeof(struct icmp6_hdr) +
                void (*ctlfunc)(int, struct sockaddr *, void *, struct ifnet *);
                u_int8_t nxt = eip6->ip6_nxt;
                int eoff = off + sizeof(struct icmp6_hdr) +
-                       sizeof(struct ip6_hdr);
+                   sizeof(struct ip6_hdr);
                struct ip6ctlparam ip6cp;
                struct in6_addr *finaldst = NULL;
                int icmp6type = icmp6->icmp6_type;
                struct ip6ctlparam ip6cp;
                struct in6_addr *finaldst = NULL;
                int icmp6type = icmp6->icmp6_type;
@@ -960,24 +996,24 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                        case IPPROTO_DSTOPTS:
                        case IPPROTO_AH:
 #ifndef PULLDOWN_TEST
                        case IPPROTO_DSTOPTS:
                        case IPPROTO_AH:
 #ifndef PULLDOWN_TEST
-                               IP6_EXTHDR_CHECK(m, 0, eoff +
-                                                sizeof(struct ip6_ext),
-                                                return -1);
+                               IP6_EXTHDR_CHECK(m, 0,
+                                   eoff + sizeof(struct ip6_ext), return -1);
                                eh = (struct ip6_ext *)(mtod(m, caddr_t)
                                eh = (struct ip6_ext *)(mtod(m, caddr_t)
-                                                       + eoff);
+                                   + eoff);
 #else
                                IP6_EXTHDR_GET(eh, struct ip6_ext *, m,
 #else
                                IP6_EXTHDR_GET(eh, struct ip6_ext *, m,
-                                              eoff, sizeof(*eh));
+                                   eoff, sizeof(*eh));
                                if (eh == NULL) {
                                        icmp6stat.icp6s_tooshort++;
                                if (eh == NULL) {
                                        icmp6stat.icp6s_tooshort++;
-                                       return(-1);
+                                       return -1;
                                }
 #endif
 
                                }
 #endif
 
-                               if (nxt == IPPROTO_AH)
+                               if (nxt == IPPROTO_AH) {
                                        eoff += (eh->ip6e_len + 2) << 2;
                                        eoff += (eh->ip6e_len + 2) << 2;
-                               else
+                               } else {
                                        eoff += (eh->ip6e_len + 1) << 3;
                                        eoff += (eh->ip6e_len + 1) << 3;
+                               }
                                nxt = eh->ip6e_nxt;
                                break;
                        case IPPROTO_ROUTING:
                                nxt = eh->ip6e_nxt;
                                break;
                        case IPPROTO_ROUTING:
@@ -991,15 +1027,15 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                                 */
 #ifndef PULLDOWN_TEST
                                IP6_EXTHDR_CHECK(m, 0, eoff + sizeof(*rth),
                                 */
 #ifndef PULLDOWN_TEST
                                IP6_EXTHDR_CHECK(m, 0, eoff + sizeof(*rth),
-                                                return -1);
-                               rth = (struct ip6_rthdr *)(mtod(m, caddr_t)
-                                                          + eoff);
+                                   return -1);
+                               rth = (struct ip6_rthdr *)
+                                   (mtod(m, caddr_t) + eoff);
 #else
                                IP6_EXTHDR_GET(rth, struct ip6_rthdr *, m,
 #else
                                IP6_EXTHDR_GET(rth, struct ip6_rthdr *, m,
-                                              eoff, sizeof(*rth));
+                                   eoff, sizeof(*rth));
                                if (rth == NULL) {
                                        icmp6stat.icp6s_tooshort++;
                                if (rth == NULL) {
                                        icmp6stat.icp6s_tooshort++;
-                                       return(-1);
+                                       return -1;
                                }
 #endif
                                rthlen = (rth->ip6r_len + 1) << 3;
                                }
 #endif
                                rthlen = (rth->ip6r_len + 1) << 3;
@@ -1017,21 +1053,22 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
 
 #ifndef PULLDOWN_TEST
                                        IP6_EXTHDR_CHECK(m, 0, eoff + rthlen,
 
 #ifndef PULLDOWN_TEST
                                        IP6_EXTHDR_CHECK(m, 0, eoff + rthlen,
-                                                        return -1);
+                                           return -1);
                                        rth0 = (struct ip6_rthdr0 *)(mtod(m, caddr_t) + eoff);
 #else
                                        IP6_EXTHDR_GET(rth0,
                                        rth0 = (struct ip6_rthdr0 *)(mtod(m, caddr_t) + eoff);
 #else
                                        IP6_EXTHDR_GET(rth0,
-                                                      struct ip6_rthdr0 *, m,
-                                                      eoff, rthlen);
+                                           struct ip6_rthdr0 *, m,
+                                           eoff, rthlen);
                                        if (rth0 == NULL) {
                                                icmp6stat.icp6s_tooshort++;
                                        if (rth0 == NULL) {
                                                icmp6stat.icp6s_tooshort++;
-                                               return(-1);
+                                               return -1;
                                        }
 #endif
                                        /* just ignore a bogus header */
                                        if ((rth0->ip6r0_len % 2) == 0 &&
                                        }
 #endif
                                        /* just ignore a bogus header */
                                        if ((rth0->ip6r0_len % 2) == 0 &&
-                                           (hops = rth0->ip6r0_len/2))
+                                           (hops = rth0->ip6r0_len / 2)) {
                                                finaldst = (struct in6_addr *)(void *)(rth0 + 1) + (hops - 1);
                                                finaldst = (struct in6_addr *)(void *)(rth0 + 1) + (hops - 1);
+                                       }
                                }
                                eoff += rthlen;
                                nxt = rth->ip6r_nxt;
                                }
                                eoff += rthlen;
                                nxt = rth->ip6r_nxt;
@@ -1039,16 +1076,16 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                        case IPPROTO_FRAGMENT:
 #ifndef PULLDOWN_TEST
                                IP6_EXTHDR_CHECK(m, 0, eoff +
                        case IPPROTO_FRAGMENT:
 #ifndef PULLDOWN_TEST
                                IP6_EXTHDR_CHECK(m, 0, eoff +
-                                                sizeof(struct ip6_frag),
-                                                return -1);
+                                   sizeof(struct ip6_frag),
+                                   return -1);
                                fh = (struct ip6_frag *)(mtod(m, caddr_t)
                                fh = (struct ip6_frag *)(mtod(m, caddr_t)
-                                                        + eoff);
+                                   + eoff);
 #else
                                IP6_EXTHDR_GET(fh, struct ip6_frag *, m,
 #else
                                IP6_EXTHDR_GET(fh, struct ip6_frag *, m,
-                                              eoff, sizeof(*fh));
+                                   eoff, sizeof(*fh));
                                if (fh == NULL) {
                                        icmp6stat.icp6s_tooshort++;
                                if (fh == NULL) {
                                        icmp6stat.icp6s_tooshort++;
-                                       return (-1);
+                                       return -1;
                                }
 #endif
                                /*
                                }
 #endif
                                /*
@@ -1057,8 +1094,9 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                                 * we'll go to the notify label for path MTU
                                 * discovery.
                                 */
                                 * we'll go to the notify label for path MTU
                                 * discovery.
                                 */
-                               if (fh->ip6f_offlg & IP6F_OFF_MASK)
+                               if (fh->ip6f_offlg & IP6F_OFF_MASK) {
                                        goto notify;
                                        goto notify;
+                               }
 
                                eoff += sizeof(struct ip6_frag);
                                nxt = fh->ip6f_nxt;
 
                                eoff += sizeof(struct ip6_frag);
                                nxt = fh->ip6f_nxt;
@@ -1075,7 +1113,7 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                                goto notify;
                        }
                }
                                goto notify;
                        }
                }
-         notify:
+notify:
 #ifndef PULLDOWN_TEST
                icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
 #else
 #ifndef PULLDOWN_TEST
                icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
 #else
@@ -1083,7 +1121,7 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                    sizeof(*icmp6) + sizeof(struct ip6_hdr));
                if (icmp6 == NULL) {
                        icmp6stat.icp6s_tooshort++;
                    sizeof(*icmp6) + sizeof(struct ip6_hdr));
                if (icmp6 == NULL) {
                        icmp6stat.icp6s_tooshort++;
-                       return (-1);
+                       return -1;
                }
 #endif
 
                }
 #endif
 
@@ -1100,23 +1138,27 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                bzero(&icmp6dst, sizeof(icmp6dst));
                icmp6dst.sin6_len = sizeof(struct sockaddr_in6);
                icmp6dst.sin6_family = AF_INET6;
                bzero(&icmp6dst, sizeof(icmp6dst));
                icmp6dst.sin6_len = sizeof(struct sockaddr_in6);
                icmp6dst.sin6_family = AF_INET6;
-               if (finaldst == NULL)
+               if (finaldst == NULL) {
                        icmp6dst.sin6_addr = eip6->ip6_dst;
                        icmp6dst.sin6_addr = eip6->ip6_dst;
-               else
+               } else {
                        icmp6dst.sin6_addr = *finaldst;
                        icmp6dst.sin6_addr = *finaldst;
-               if (in6_setscope(&icmp6dst.sin6_addr, m->m_pkthdr.rcvif, NULL))
+               }
+               if (in6_setscope(&icmp6dst.sin6_addr, m->m_pkthdr.rcvif, NULL)) {
                        goto freeit;
                        goto freeit;
+               }
                bzero(&icmp6src, sizeof(icmp6src));
                icmp6src.sin6_len = sizeof(struct sockaddr_in6);
                icmp6src.sin6_family = AF_INET6;
                icmp6src.sin6_addr = eip6->ip6_src;
                bzero(&icmp6src, sizeof(icmp6src));
                icmp6src.sin6_len = sizeof(struct sockaddr_in6);
                icmp6src.sin6_family = AF_INET6;
                icmp6src.sin6_addr = eip6->ip6_src;
-               if (in6_setscope(&icmp6src.sin6_addr, m->m_pkthdr.rcvif, NULL))
+               if (in6_setscope(&icmp6src.sin6_addr, m->m_pkthdr.rcvif, NULL)) {
                        goto freeit;
                        goto freeit;
+               }
                icmp6src.sin6_flowinfo =
                    (eip6->ip6_flow & IPV6_FLOWLABEL_MASK);
 
                icmp6src.sin6_flowinfo =
                    (eip6->ip6_flow & IPV6_FLOWLABEL_MASK);
 
-               if (finaldst == NULL)
+               if (finaldst == NULL) {
                        finaldst = &eip6->ip6_dst;
                        finaldst = &eip6->ip6_dst;
+               }
                ip6cp.ip6c_m = m;
                ip6cp.ip6c_icmp6 = icmp6;
                ip6cp.ip6c_ip6 = (struct ip6_hdr *)(icmp6 + 1);
                ip6cp.ip6c_m = m;
                ip6cp.ip6c_icmp6 = icmp6;
                ip6cp.ip6c_ip6 = (struct ip6_hdr *)(icmp6 + 1);
@@ -1128,7 +1170,7 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                if (icmp6type == ICMP6_PACKET_TOO_BIG) {
                        notifymtu = ntohl(icmp6->icmp6_mtu);
                        ip6cp.ip6c_cmdarg = (void *)&notifymtu;
                if (icmp6type == ICMP6_PACKET_TOO_BIG) {
                        notifymtu = ntohl(icmp6->icmp6_mtu);
                        ip6cp.ip6c_cmdarg = (void *)&notifymtu;
-                       icmp6_mtudisc_update(&ip6cp, 1);        /*XXX*/
+                       icmp6_mtudisc_update(&ip6cp, 1);        /*XXX*/
                }
 
                ctlfunc = ip6_protox[nxt]->pr_ctlinput;
                }
 
                ctlfunc = ip6_protox[nxt]->pr_ctlinput;
@@ -1143,11 +1185,11 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
                        lck_mtx_lock(inet6_domain_mutex);
                }
        }
                        lck_mtx_lock(inet6_domain_mutex);
                }
        }
-       return(0);
+       return 0;
 
 freeit:
        m_freem(m);
 
 freeit:
        m_freem(m);
-       return(-1);
+       return -1;
 }
 
 void
 }
 
 void
@@ -1155,7 +1197,7 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated)
 {
        struct in6_addr *dst = ip6cp->ip6c_finaldst;
        struct icmp6_hdr *icmp6 = ip6cp->ip6c_icmp6;
 {
        struct in6_addr *dst = ip6cp->ip6c_finaldst;
        struct icmp6_hdr *icmp6 = ip6cp->ip6c_icmp6;
-       struct mbuf *m = ip6cp->ip6c_m; /* will be necessary for scope issue */
+       struct mbuf *m = ip6cp->ip6c_m; /* will be necessary for scope issue */
        u_int mtu = ntohl(icmp6->icmp6_mtu);
        struct rtentry *rt = NULL;
        struct sockaddr_in6 sin6;
        u_int mtu = ntohl(icmp6->icmp6_mtu);
        struct rtentry *rt = NULL;
        struct sockaddr_in6 sin6;
@@ -1163,11 +1205,13 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated)
         * we reject ICMPv6 too big with abnormally small value.
         * XXX what is the good definition of "abnormally small"?
         */
         * we reject ICMPv6 too big with abnormally small value.
         * XXX what is the good definition of "abnormally small"?
         */
-       if (mtu < sizeof(struct ip6_hdr) + sizeof(struct ip6_frag) + 8)
+       if (mtu < sizeof(struct ip6_hdr) + sizeof(struct ip6_frag) + 8) {
                return;
                return;
+       }
 
 
-       if (!validated)
+       if (!validated) {
                return;
                return;
+       }
 
        /*
         * In case the suggested mtu is less than IPV6_MMTU, we
 
        /*
         * In case the suggested mtu is less than IPV6_MMTU, we
@@ -1175,8 +1219,9 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated)
         * "alwaysfrag" case.
         * Try to be as close to the spec as possible.
         */
         * "alwaysfrag" case.
         * Try to be as close to the spec as possible.
         */
-       if (mtu < IPV6_MMTU)
+       if (mtu < IPV6_MMTU) {
                mtu = IPV6_MMTU - 8;
                mtu = IPV6_MMTU - 8;
+       }
 
        bzero(&sin6, sizeof(sin6));
        sin6.sin6_family = PF_INET6;
 
        bzero(&sin6, sizeof(sin6));
        sin6.sin6_family = PF_INET6;
@@ -1222,7 +1267,7 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated)
  * - joins NI group address at in6_ifattach() time only, does not cope
  *   with hostname changes by sethostname(3)
  */
  * - joins NI group address at in6_ifattach() time only, does not cope
  *   with hostname changes by sethostname(3)
  */
-#define hostnamelen    strlen(hostname)
+#define hostnamelen     strlen(hostname)
 static struct mbuf *
 ni6_input(struct mbuf *m, int off)
 {
 static struct mbuf *
 ni6_input(struct mbuf *m, int off)
 {
@@ -1232,12 +1277,12 @@ ni6_input(struct mbuf *m, int off)
        int subjlen;
        int replylen = sizeof(struct ip6_hdr) + sizeof(struct icmp6_nodeinfo);
        struct ni_reply_fqdn *fqdn;
        int subjlen;
        int replylen = sizeof(struct ip6_hdr) + sizeof(struct icmp6_nodeinfo);
        struct ni_reply_fqdn *fqdn;
-       int addrs;              /* for NI_QTYPE_NODEADDR */
+       int addrs;              /* for NI_QTYPE_NODEADDR */
        struct ifnet *ifp = NULL; /* for NI_QTYPE_NODEADDR */
        struct sockaddr_in6 sin6; /* double meaning; ip6_dst and subjectaddr */
        struct sockaddr_in6 sin6_d; /* XXX: we should retrieve this from m_aux */
        struct ip6_hdr *ip6;
        struct ifnet *ifp = NULL; /* for NI_QTYPE_NODEADDR */
        struct sockaddr_in6 sin6; /* double meaning; ip6_dst and subjectaddr */
        struct sockaddr_in6 sin6_d; /* XXX: we should retrieve this from m_aux */
        struct ip6_hdr *ip6;
-       int oldfqdn = 0;        /* if 1, return pascal string (03 draft) */
+       int oldfqdn = 0;        /* if 1, return pascal string (03 draft) */
        char *subj = NULL;
 
        ip6 = mtod(m, struct ip6_hdr *);
        char *subj = NULL;
 
        ip6 = mtod(m, struct ip6_hdr *);
@@ -1247,7 +1292,7 @@ ni6_input(struct mbuf *m, int off)
        IP6_EXTHDR_GET(ni6, struct icmp6_nodeinfo *, m, off, sizeof(*ni6));
        if (ni6 == NULL) {
                /* m is already reclaimed */
        IP6_EXTHDR_GET(ni6, struct icmp6_nodeinfo *, m, off, sizeof(*ni6));
        if (ni6 == NULL) {
                /* m is already reclaimed */
-               return (NULL);
+               return NULL;
        }
 #endif
 
        }
 #endif
 
@@ -1266,8 +1311,9 @@ ni6_input(struct mbuf *m, int off)
         */
        if ((icmp6_nodeinfo & ICMP6_NODEINFO_GLOBALOK) == 0 &&
            !IN6_IS_ADDR_LOOPBACK(&ip6->ip6_src) &&
         */
        if ((icmp6_nodeinfo & ICMP6_NODEINFO_GLOBALOK) == 0 &&
            !IN6_IS_ADDR_LOOPBACK(&ip6->ip6_src) &&
-           !IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src))
+           !IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src)) {
                goto bad;
                goto bad;
+       }
 
        /*
         * Validate IPv6 destination address.
 
        /*
         * Validate IPv6 destination address.
@@ -1278,20 +1324,21 @@ ni6_input(struct mbuf *m, int off)
         * [RFC4602, Section 5.]
         */
        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
         * [RFC4602, Section 5.]
         */
        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
-               if (!IN6_IS_ADDR_MC_LINKLOCAL(&ip6->ip6_dst))
+               if (!IN6_IS_ADDR_MC_LINKLOCAL(&ip6->ip6_dst)) {
                        goto bad;
                        goto bad;
+               }
                /* else it's a link-local multicast, fine */
                /* else it's a link-local multicast, fine */
-       } else {                /* unicast or anycast */
+       } else {                /* unicast or anycast */
                uint32_t ia6_flags;
 
                uint32_t ia6_flags;
 
-               if (ip6_getdstifaddr_info(m, NULL, &ia6_flags) != 0)
+               if (ip6_getdstifaddr_info(m, NULL, &ia6_flags) != 0) {
                        goto bad; /* XXX impossible */
                        goto bad; /* XXX impossible */
-
+               }
                if ((ia6_flags & IN6_IFF_TEMPORARY) &&
                    !(icmp6_nodeinfo & ICMP6_NODEINFO_TMPADDROK)) {
                        nd6log((LOG_DEBUG, "ni6_input: ignore node info to "
                if ((ia6_flags & IN6_IFF_TEMPORARY) &&
                    !(icmp6_nodeinfo & ICMP6_NODEINFO_TMPADDROK)) {
                        nd6log((LOG_DEBUG, "ni6_input: ignore node info to "
-                               "a temporary address in %s:%d",
-                              __func__, __LINE__));
+                           "a temporary address in %s:%d",
+                           __func__, __LINE__));
                        goto bad;
                }
        }
                        goto bad;
                }
        }
@@ -1303,9 +1350,10 @@ ni6_input(struct mbuf *m, int off)
        case NI_QTYPE_NOOP:
        case NI_QTYPE_SUPTYPES:
                /* 07 draft */
        case NI_QTYPE_NOOP:
        case NI_QTYPE_SUPTYPES:
                /* 07 draft */
-               if (ni6->ni_code == ICMP6_NI_SUBJ_FQDN && subjlen == 0)
+               if (ni6->ni_code == ICMP6_NI_SUBJ_FQDN && subjlen == 0) {
                        break;
                        break;
-               /* FALLTHROUGH */
+               }
+       /* FALLTHROUGH */
        case NI_QTYPE_FQDN:
        case NI_QTYPE_NODEADDR:
        case NI_QTYPE_IPV4ADDR:
        case NI_QTYPE_FQDN:
        case NI_QTYPE_NODEADDR:
        case NI_QTYPE_IPV4ADDR:
@@ -1324,12 +1372,14 @@ ni6_input(struct mbuf *m, int off)
                                break;
                        }
 #if ICMP6_NI_SUBJ_IPV6 != 0
                                break;
                        }
 #if ICMP6_NI_SUBJ_IPV6 != 0
-                       if (ni6->ni_code != ICMP6_NI_SUBJ_IPV6)
+                       if (ni6->ni_code != ICMP6_NI_SUBJ_IPV6) {
                                goto bad;
                                goto bad;
+                       }
 #endif
 
 #endif
 
-                       if (subjlen != sizeof(struct in6_addr))
+                       if (subjlen != sizeof(struct in6_addr)) {
                                goto bad;
                                goto bad;
+                       }
 
                        /*
                         * Validate Subject address.
 
                        /*
                         * Validate Subject address.
@@ -1349,7 +1399,7 @@ ni6_input(struct mbuf *m, int off)
                        m_copydata(m, off + sizeof(struct icmp6_nodeinfo),
                            subjlen, (caddr_t)&sin6.sin6_addr);
                        sin6.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif,
                        m_copydata(m, off + sizeof(struct icmp6_nodeinfo),
                            subjlen, (caddr_t)&sin6.sin6_addr);
                        sin6.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif,
-                                                             &sin6.sin6_addr);
+                           &sin6.sin6_addr);
                        in6_embedscope(&sin6.sin6_addr, &sin6, NULL, NULL,
                            NULL);
                        bzero(&sin6_d, sizeof(sin6_d));
                        in6_embedscope(&sin6.sin6_addr, &sin6, NULL, NULL,
                            NULL);
                        bzero(&sin6_d, sizeof(sin6_d));
@@ -1357,12 +1407,13 @@ ni6_input(struct mbuf *m, int off)
                        sin6_d.sin6_len = sizeof(sin6_d); /* ditto */
                        sin6_d.sin6_addr = ip6->ip6_dst;
                        sin6_d.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif,
                        sin6_d.sin6_len = sizeof(sin6_d); /* ditto */
                        sin6_d.sin6_addr = ip6->ip6_dst;
                        sin6_d.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.rcvif,
-                                                               &ip6->ip6_dst);
+                           &ip6->ip6_dst);
                        in6_embedscope(&sin6_d.sin6_addr, &sin6_d, NULL, NULL,
                            NULL);
                        subj = (char *)&sin6;
                        in6_embedscope(&sin6_d.sin6_addr, &sin6_d, NULL, NULL,
                            NULL);
                        subj = (char *)&sin6;
-                       if (SA6_ARE_ADDR_EQUAL(&sin6, &sin6_d))
+                       if (SA6_ARE_ADDR_EQUAL(&sin6, &sin6_d)) {
                                break;
                                break;
+                       }
 
                        /*
                         * XXX if we are to allow other cases, we should really
 
                        /*
                         * XXX if we are to allow other cases, we should really
@@ -1388,21 +1439,23 @@ ni6_input(struct mbuf *m, int off)
                         *   truncated hostname.
                         */
                        n = ni6_nametodns(hostname, hostnamelen, 0);
                         *   truncated hostname.
                         */
                        n = ni6_nametodns(hostname, hostnamelen, 0);
-                       if (!n || n->m_next || n->m_len == 0)
+                       if (!n || n->m_next || n->m_len == 0) {
                                goto bad;
                                goto bad;
+                       }
                        IP6_EXTHDR_GET(subj, char *, m,
                            off + sizeof(struct icmp6_nodeinfo), subjlen);
                        IP6_EXTHDR_GET(subj, char *, m,
                            off + sizeof(struct icmp6_nodeinfo), subjlen);
-                       if (subj == NULL)
+                       if (subj == NULL) {
                                goto bad;
                                goto bad;
+                       }
                        if (!ni6_dnsmatch(subj, subjlen, mtod(n, const char *),
                        if (!ni6_dnsmatch(subj, subjlen, mtod(n, const char *),
-                                       n->m_len)) {
+                           n->m_len)) {
                                goto bad;
                        }
                        m_freem(n);
                        n = NULL;
                        break;
 
                                goto bad;
                        }
                        m_freem(n);
                        n = NULL;
                        break;
 
-               case ICMP6_NI_SUBJ_IPV4:        /* XXX: to be implemented? */
+               case ICMP6_NI_SUBJ_IPV4:        /* XXX: to be implemented? */
                default:
                        goto bad;
                }
                default:
                        goto bad;
                }
@@ -1412,20 +1465,22 @@ ni6_input(struct mbuf *m, int off)
        /* refuse based on configuration.  XXX ICMP6_NI_REFUSED? */
        switch (qtype) {
        case NI_QTYPE_FQDN:
        /* refuse based on configuration.  XXX ICMP6_NI_REFUSED? */
        switch (qtype) {
        case NI_QTYPE_FQDN:
-               if ((icmp6_nodeinfo & ICMP6_NODEINFO_FQDNOK) == 0)
+               if ((icmp6_nodeinfo & ICMP6_NODEINFO_FQDNOK) == 0) {
                        goto bad;
                        goto bad;
+               }
                break;
        case NI_QTYPE_NODEADDR:
        case NI_QTYPE_IPV4ADDR:
                break;
        case NI_QTYPE_NODEADDR:
        case NI_QTYPE_IPV4ADDR:
-               if ((icmp6_nodeinfo & ICMP6_NODEINFO_NODEADDROK) == 0)
+               if ((icmp6_nodeinfo & ICMP6_NODEINFO_NODEADDROK) == 0) {
                        goto bad;
                        goto bad;
+               }
                break;
        }
 
        /* guess reply length */
        switch (qtype) {
        case NI_QTYPE_NOOP:
                break;
        }
 
        /* guess reply length */
        switch (qtype) {
        case NI_QTYPE_NOOP:
-               break;          /* no reply data */
+               break;          /* no reply data */
        case NI_QTYPE_SUPTYPES:
                replylen += sizeof(u_int32_t);
                break;
        case NI_QTYPE_SUPTYPES:
                replylen += sizeof(u_int32_t);
                break;
@@ -1436,8 +1491,9 @@ ni6_input(struct mbuf *m, int off)
        case NI_QTYPE_NODEADDR:
                addrs = ni6_addrs(ni6, &ifp, subj);
                if ((replylen += addrs * (sizeof(struct in6_addr) +
        case NI_QTYPE_NODEADDR:
                addrs = ni6_addrs(ni6, &ifp, subj);
                if ((replylen += addrs * (sizeof(struct in6_addr) +
-                   sizeof(u_int32_t))) > MCLBYTES)
+                   sizeof(u_int32_t))) > MCLBYTES) {
                        replylen = MCLBYTES; /* XXX: will truncate pkt later */
                        replylen = MCLBYTES; /* XXX: will truncate pkt later */
+               }
                break;
        case NI_QTYPE_IPV4ADDR:
                /* unsupported - should respond with unknown Qtype? */
                break;
        case NI_QTYPE_IPV4ADDR:
                /* unsupported - should respond with unknown Qtype? */
@@ -1460,12 +1516,13 @@ ni6_input(struct mbuf *m, int off)
        }
 
        /* allocate an mbuf to reply. */
        }
 
        /* allocate an mbuf to reply. */
-       MGETHDR(n, M_DONTWAIT, m->m_type);      /* MAC-OK */
+       MGETHDR(n, M_DONTWAIT, m->m_type);      /* MAC-OK */
        if (n == NULL) {
                m_freem(m);
        if (n == NULL) {
                m_freem(m);
-               if (ifp != NULL)
+               if (ifp != NULL) {
                        ifnet_release(ifp);
                        ifnet_release(ifp);
-               return (NULL);
+               }
+               return NULL;
        }
        M_COPY_PKTHDR(n, m); /* just for recvif */
        if (replylen > MHLEN) {
        }
        M_COPY_PKTHDR(n, m); /* just for recvif */
        if (replylen > MHLEN) {
@@ -1498,7 +1555,7 @@ ni6_input(struct mbuf *m, int off)
        {
                u_int32_t v;
                nni6->ni_code = ICMP6_NI_SUCCESS;
        {
                u_int32_t v;
                nni6->ni_code = ICMP6_NI_SUCCESS;
-               nni6->ni_flags = htons(0x0000); /* raw bitmap */
+               nni6->ni_flags = htons(0x0000); /* raw bitmap */
                /* supports NOOP, SUPTYPES, FQDN, and NODEADDR */
                v = (u_int32_t)htonl(0x0000000f);
                bcopy(&v, nni6 + 1, sizeof(u_int32_t));
                /* supports NOOP, SUPTYPES, FQDN, and NODEADDR */
                v = (u_int32_t)htonl(0x0000000f);
                bcopy(&v, nni6 + 1, sizeof(u_int32_t));
@@ -1507,19 +1564,21 @@ ni6_input(struct mbuf *m, int off)
        case NI_QTYPE_FQDN:
                nni6->ni_code = ICMP6_NI_SUCCESS;
                fqdn = (struct ni_reply_fqdn *)(mtod(n, caddr_t) +
        case NI_QTYPE_FQDN:
                nni6->ni_code = ICMP6_NI_SUCCESS;
                fqdn = (struct ni_reply_fqdn *)(mtod(n, caddr_t) +
-                                               sizeof(struct ip6_hdr) +
-                                               sizeof(struct icmp6_nodeinfo));
+                   sizeof(struct ip6_hdr) +
+                   sizeof(struct icmp6_nodeinfo));
                nni6->ni_flags = 0; /* XXX: meaningless TTL */
                nni6->ni_flags = 0; /* XXX: meaningless TTL */
-               fqdn->ni_fqdn_ttl = 0;  /* ditto. */
+               fqdn->ni_fqdn_ttl = 0;  /* ditto. */
                /*
                 * XXX do we really have FQDN in variable "hostname"?
                 */
                n->m_next = ni6_nametodns(hostname, hostnamelen, oldfqdn);
                /*
                 * XXX do we really have FQDN in variable "hostname"?
                 */
                n->m_next = ni6_nametodns(hostname, hostnamelen, oldfqdn);
-               if (n->m_next == NULL)
+               if (n->m_next == NULL) {
                        goto bad;
                        goto bad;
+               }
                /* XXX we assume that n->m_next is not a chain */
                /* XXX we assume that n->m_next is not a chain */
-               if (n->m_next->m_next != NULL)
+               if (n->m_next->m_next != NULL) {
                        goto bad;
                        goto bad;
+               }
                n->m_pkthdr.len += n->m_next->m_len;
                break;
        case NI_QTYPE_NODEADDR:
                n->m_pkthdr.len += n->m_next->m_len;
                break;
        case NI_QTYPE_NODEADDR:
@@ -1533,26 +1592,29 @@ ni6_input(struct mbuf *m, int off)
                copied = ni6_store_addrs(ni6, nni6, ifp, lenlim);
                /* XXX: reset mbuf length */
                n->m_pkthdr.len = n->m_len = sizeof(struct ip6_hdr) +
                copied = ni6_store_addrs(ni6, nni6, ifp, lenlim);
                /* XXX: reset mbuf length */
                n->m_pkthdr.len = n->m_len = sizeof(struct ip6_hdr) +
-                       sizeof(struct icmp6_nodeinfo) + copied;
+                   sizeof(struct icmp6_nodeinfo) + copied;
                break;
        }
        default:
                break;
        }
        default:
-               break;          /* XXX impossible! */
+               break;          /* XXX impossible! */
        }
 
        nni6->ni_type = ICMP6_NI_REPLY;
        m_freem(m);
        }
 
        nni6->ni_type = ICMP6_NI_REPLY;
        m_freem(m);
-       if (ifp != NULL)
+       if (ifp != NULL) {
                ifnet_release(ifp);
                ifnet_release(ifp);
-       return (n);
+       }
+       return n;
 
 bad:
        m_freem(m);
 
 bad:
        m_freem(m);
-       if (n)
+       if (n) {
                m_freem(n);
                m_freem(n);
-       if (ifp != NULL)
+       }
+       if (ifp != NULL) {
                ifnet_release(ifp);
                ifnet_release(ifp);
-       return (NULL);
+       }
+       return NULL;
 }
 #undef hostnamelen
 
 }
 #undef hostnamelen
 
@@ -1566,27 +1628,30 @@ static struct mbuf *
 ni6_nametodns(
        const char *name,
        int namelen,
 ni6_nametodns(
        const char *name,
        int namelen,
-       int old)        /* return pascal string if non-zero */
+       int old)        /* return pascal string if non-zero */
 {
        struct mbuf *m;
        char *cp, *ep;
        const char *p, *q;
        int i, len, nterm;
 
 {
        struct mbuf *m;
        char *cp, *ep;
        const char *p, *q;
        int i, len, nterm;
 
-       if (old)
+       if (old) {
                len = namelen + 1;
                len = namelen + 1;
-       else
+       } else {
                len = MCLBYTES;
                len = MCLBYTES;
+       }
 
        /* because MAXHOSTNAMELEN is usually 256, we use cluster mbuf */
        MGET(m, M_DONTWAIT, MT_DATA);
        if (m && len > MLEN) {
                MCLGET(m, M_DONTWAIT);
 
        /* because MAXHOSTNAMELEN is usually 256, we use cluster mbuf */
        MGET(m, M_DONTWAIT, MT_DATA);
        if (m && len > MLEN) {
                MCLGET(m, M_DONTWAIT);
-               if ((m->m_flags & M_EXT) == 0)
+               if ((m->m_flags & M_EXT) == 0) {
                        goto fail;
                        goto fail;
+               }
        }
        }
-       if (!m)
+       if (!m) {
                goto fail;
                goto fail;
+       }
        m->m_next = NULL;
 
        if (old) {
        m->m_next = NULL;
 
        if (old) {
@@ -1600,8 +1665,9 @@ ni6_nametodns(
                ep = mtod(m, char *) + M_TRAILINGSPACE(m);
 
                /* if not certain about my name, return empty buffer */
                ep = mtod(m, char *) + M_TRAILINGSPACE(m);
 
                /* if not certain about my name, return empty buffer */
-               if (namelen == 0)
+               if (namelen == 0) {
                        return m;
                        return m;
+               }
 
                /*
                 * guess if it looks like shortened hostname, or FQDN.
 
                /*
                 * guess if it looks like shortened hostname, or FQDN.
@@ -1609,41 +1675,49 @@ ni6_nametodns(
                 */
                i = 0;
                for (p = name; p < name + namelen; p++) {
                 */
                i = 0;
                for (p = name; p < name + namelen; p++) {
-                       if (*p && *p == '.')
+                       if (*p && *p == '.') {
                                i++;
                                i++;
+                       }
                }
                }
-               if (i < 2)
+               if (i < 2) {
                        nterm = 2;
                        nterm = 2;
-               else
+               } else {
                        nterm = 1;
                        nterm = 1;
+               }
 
                p = name;
                while (cp < ep && p < name + namelen) {
                        i = 0;
 
                p = name;
                while (cp < ep && p < name + namelen) {
                        i = 0;
-                       for (q = p; q < name + namelen && *q && *q != '.'; q++)
+                       for (q = p; q < name + namelen && *q && *q != '.'; q++) {
                                i++;
                                i++;
+                       }
                        /* result does not fit into mbuf */
                        /* result does not fit into mbuf */
-                       if (cp + i + 1 >= ep)
+                       if (cp + i + 1 >= ep) {
                                goto fail;
                                goto fail;
+                       }
                        /*
                         * DNS label length restriction, RFC1035 page 8.
                         * "i == 0" case is included here to avoid returning
                         * 0-length label on "foo..bar".
                         */
                        /*
                         * DNS label length restriction, RFC1035 page 8.
                         * "i == 0" case is included here to avoid returning
                         * 0-length label on "foo..bar".
                         */
-                       if (i <= 0 || i >= 64)
+                       if (i <= 0 || i >= 64) {
                                goto fail;
                                goto fail;
+                       }
                        *cp++ = i;
                        bcopy(p, cp, i);
                        cp += i;
                        p = q;
                        *cp++ = i;
                        bcopy(p, cp, i);
                        cp += i;
                        p = q;
-                       if (p < name + namelen && *p == '.')
+                       if (p < name + namelen && *p == '.') {
                                p++;
                                p++;
+                       }
                }
                /* termination */
                }
                /* termination */
-               if (cp + nterm >= ep)
+               if (cp + nterm >= ep) {
                        goto fail;
                        goto fail;
-               while (nterm-- > 0)
+               }
+               while (nterm-- > 0) {
                        *cp++ = '\0';
                        *cp++ = '\0';
+               }
                m->m_len = cp - mtod(m, char *);
                return m;
        }
                m->m_len = cp - mtod(m, char *);
                return m;
        }
@@ -1651,9 +1725,10 @@ ni6_nametodns(
        panic("should not reach here");
        /* NOTREACHED */
 
        panic("should not reach here");
        /* NOTREACHED */
 
- fail:
-       if (m)
+fail:
+       if (m) {
                m_freem(m);
                m_freem(m);
+       }
        return NULL;
 }
 
        return NULL;
 }
 
@@ -1669,54 +1744,67 @@ ni6_dnsmatch(const char *a, int alen, const char *b, int blen)
        int l;
 
        /* simplest case - need validation? */
        int l;
 
        /* simplest case - need validation? */
-       if (alen == blen && bcmp(a, b, alen) == 0)
+       if (alen == blen && bcmp(a, b, alen) == 0) {
                return 1;
                return 1;
+       }
 
        a0 = a;
        b0 = b;
 
        /* termination is mandatory */
 
        a0 = a;
        b0 = b;
 
        /* termination is mandatory */
-       if (alen < 2 || blen < 2)
+       if (alen < 2 || blen < 2) {
                return 0;
                return 0;
-       if (a0[alen - 1] != '\0' || b0[blen - 1] != '\0')
+       }
+       if (a0[alen - 1] != '\0' || b0[blen - 1] != '\0') {
                return 0;
                return 0;
+       }
        alen--;
        blen--;
 
        while (a - a0 < alen && b - b0 < blen) {
        alen--;
        blen--;
 
        while (a - a0 < alen && b - b0 < blen) {
-               if (a - a0 + 1 > alen || b - b0 + 1 > blen)
+               if (a - a0 + 1 > alen || b - b0 + 1 > blen) {
                        return 0;
                        return 0;
+               }
 
 
-               if ((signed char)a[0] < 0 || (signed char)b[0] < 0)
+               if ((signed char)a[0] < 0 || (signed char)b[0] < 0) {
                        return 0;
                        return 0;
+               }
                /* we don't support compression yet */
                /* we don't support compression yet */
-               if (a[0] >= 64 || b[0] >= 64)
+               if (a[0] >= 64 || b[0] >= 64) {
                        return 0;
                        return 0;
+               }
 
                /* truncated case */
 
                /* truncated case */
-               if (a[0] == 0 && a - a0 == alen - 1)
+               if (a[0] == 0 && a - a0 == alen - 1) {
                        return 1;
                        return 1;
-               if (b[0] == 0 && b - b0 == blen - 1)
+               }
+               if (b[0] == 0 && b - b0 == blen - 1) {
                        return 1;
                        return 1;
-               if (a[0] == 0 || b[0] == 0)
+               }
+               if (a[0] == 0 || b[0] == 0) {
                        return 0;
                        return 0;
+               }
 
 
-               if (a[0] != b[0])
+               if (a[0] != b[0]) {
                        return 0;
                        return 0;
+               }
                l = a[0];
                l = a[0];
-               if (a - a0 + 1 + l > alen || b - b0 + 1 + l > blen)
+               if (a - a0 + 1 + l > alen || b - b0 + 1 + l > blen) {
                        return 0;
                        return 0;
-               if (bcmp(a + 1, b + 1, l) != 0)
+               }
+               if (bcmp(a + 1, b + 1, l) != 0) {
                        return 0;
                        return 0;
+               }
 
                a += 1 + l;
                b += 1 + l;
        }
 
 
                a += 1 + l;
                b += 1 + l;
        }
 
-       if (a - a0 == alen && b - b0 == blen)
+       if (a - a0 == alen && b - b0 == blen) {
                return 1;
                return 1;
-       else
+       } else {
                return 0;
                return 0;
+       }
 }
 
 /*
 }
 
 /*
@@ -1732,14 +1820,16 @@ ni6_addrs(struct icmp6_nodeinfo *ni6, struct ifnet **ifpp, char *subj)
        int addrs = 0, addrsofif, iffound = 0;
        int niflags = ni6->ni_flags;
 
        int addrs = 0, addrsofif, iffound = 0;
        int niflags = ni6->ni_flags;
 
-       if (ifpp != NULL)
+       if (ifpp != NULL) {
                *ifpp = NULL;
                *ifpp = NULL;
+       }
 
        if ((niflags & NI_NODEADDR_FLAG_ALL) == 0) {
                switch (ni6->ni_code) {
                case ICMP6_NI_SUBJ_IPV6:
 
        if ((niflags & NI_NODEADDR_FLAG_ALL) == 0) {
                switch (ni6->ni_code) {
                case ICMP6_NI_SUBJ_IPV6:
-                       if (subj == NULL) /* must be impossible... */
-                               return(0);
+                       if (subj == NULL) { /* must be impossible... */
+                               return 0;
+                       }
                        subj_ip6 = (struct sockaddr_in6 *)(void *)subj;
                        break;
                default:
                        subj_ip6 = (struct sockaddr_in6 *)(void *)subj;
                        break;
                default:
@@ -1747,7 +1837,7 @@ ni6_addrs(struct icmp6_nodeinfo *ni6, struct ifnet **ifpp, char *subj)
                         * XXX: we only support IPv6 subject address for
                         * this Qtype.
                         */
                         * XXX: we only support IPv6 subject address for
                         * this Qtype.
                         */
-                       return (0);
+                       return 0;
                }
        }
 
                }
        }
 
@@ -1766,8 +1856,9 @@ ni6_addrs(struct icmp6_nodeinfo *ni6, struct ifnet **ifpp, char *subj)
 
                        if ((niflags & NI_NODEADDR_FLAG_ALL) == 0 &&
                            IN6_ARE_ADDR_EQUAL(&subj_ip6->sin6_addr,
 
                        if ((niflags & NI_NODEADDR_FLAG_ALL) == 0 &&
                            IN6_ARE_ADDR_EQUAL(&subj_ip6->sin6_addr,
-                                              &ifa6->ia_addr.sin6_addr))
+                           &ifa6->ia_addr.sin6_addr)) {
                                iffound = 1;
                                iffound = 1;
+                       }
 
                        /*
                         * IPv4-mapped addresses can only be returned by a
 
                        /*
                         * IPv4-mapped addresses can only be returned by a
@@ -1828,19 +1919,19 @@ ni6_addrs(struct icmp6_nodeinfo *ni6, struct ifnet **ifpp, char *subj)
                                ifnet_reference(ifp);
                        }
                        ifnet_head_done();
                                ifnet_reference(ifp);
                        }
                        ifnet_head_done();
-                       return(addrsofif);
+                       return addrsofif;
                }
 
                addrs += addrsofif;
        }
        ifnet_head_done();
 
                }
 
                addrs += addrsofif;
        }
        ifnet_head_done();
 
-       return (addrs);
+       return addrs;
 }
 
 static int
 ni6_store_addrs(struct icmp6_nodeinfo *ni6, struct icmp6_nodeinfo *nni6,
 }
 
 static int
 ni6_store_addrs(struct icmp6_nodeinfo *ni6, struct icmp6_nodeinfo *nni6,
-               struct ifnet *ifp0, int resid)
+    struct ifnet *ifp0, int resid)
 {
        struct ifnet *ifp = ifp0;
        struct in6_ifaddr *ifa6;
 {
        struct ifnet *ifp = ifp0;
        struct in6_ifaddr *ifa6;
@@ -1852,19 +1943,20 @@ ni6_store_addrs(struct icmp6_nodeinfo *ni6, struct icmp6_nodeinfo *nni6,
        u_int32_t ltime;
        uint64_t now = net_uptime();
 
        u_int32_t ltime;
        uint64_t now = net_uptime();
 
-       if (ifp0 == NULL && !(niflags & NI_NODEADDR_FLAG_ALL))
-               return (0);     /* needless to copy */
-
-  again:
+       if (ifp0 == NULL && !(niflags & NI_NODEADDR_FLAG_ALL)) {
+               return 0;     /* needless to copy */
+       }
+again:
 
        ifnet_head_lock_shared();
 
        ifnet_head_lock_shared();
-       if (ifp == NULL)
+       if (ifp == NULL) {
                ifp = TAILQ_FIRST(&ifnet_head);
                ifp = TAILQ_FIRST(&ifnet_head);
+       }
 
        for (; ifp; ifp = TAILQ_NEXT(ifp, if_list)) {
                ifnet_lock_shared(ifp);
                for (ifa = ifp->if_addrlist.tqh_first; ifa;
 
        for (; ifp; ifp = TAILQ_NEXT(ifp, if_list)) {
                ifnet_lock_shared(ifp);
                for (ifa = ifp->if_addrlist.tqh_first; ifa;
-                    ifa = ifa->ifa_list.tqe_next) {
+                   ifa = ifa->ifa_list.tqe_next) {
                        struct in6_addrlifetime_i *lt;
 
                        IFA_LOCK(ifa);
                        struct in6_addrlifetime_i *lt;
 
                        IFA_LOCK(ifa);
@@ -1882,8 +1974,9 @@ ni6_store_addrs(struct icmp6_nodeinfo *ni6, struct icmp6_nodeinfo *nni6,
                                 */
 
                                /* record the interface for later search */
                                 */
 
                                /* record the interface for later search */
-                               if (ifp_dep == NULL)
+                               if (ifp_dep == NULL) {
                                        ifp_dep = ifp;
                                        ifp_dep = ifp;
+                               }
 
                                IFA_UNLOCK(ifa);
                                continue;
 
                                IFA_UNLOCK(ifa);
                                continue;
@@ -1941,10 +2034,10 @@ ni6_store_addrs(struct icmp6_nodeinfo *ni6, struct icmp6_nodeinfo *nni6,
                                 * Set the truncate flag and return.
                                 */
                                nni6->ni_flags |=
                                 * Set the truncate flag and return.
                                 */
                                nni6->ni_flags |=
-                                       NI_NODEADDR_FLAG_TRUNCATE;
+                                   NI_NODEADDR_FLAG_TRUNCATE;
                                ifnet_lock_done(ifp);
                                ifnet_head_done();
                                ifnet_lock_done(ifp);
                                ifnet_head_done();
-                               return(copied);
+                               return copied;
                        }
 
                        /*
                        }
 
                        /*
@@ -1966,10 +2059,11 @@ ni6_store_addrs(struct icmp6_nodeinfo *ni6, struct icmp6_nodeinfo *nni6,
                        if (lt->ia6ti_expire == 0) {
                                ltime = ND6_INFINITE_LIFETIME;
                        } else {
                        if (lt->ia6ti_expire == 0) {
                                ltime = ND6_INFINITE_LIFETIME;
                        } else {
-                               if (lt->ia6ti_expire > now)
+                               if (lt->ia6ti_expire > now) {
                                        ltime = htonl(lt->ia6ti_expire - now);
                                        ltime = htonl(lt->ia6ti_expire - now);
-                               else
+                               } else {
                                        ltime = 0;
                                        ltime = 0;
+                               }
                        }
 
                        bcopy(&ltime, cp, sizeof(u_int32_t));
                        }
 
                        bcopy(&ltime, cp, sizeof(u_int32_t));
@@ -1977,20 +2071,22 @@ ni6_store_addrs(struct icmp6_nodeinfo *ni6, struct icmp6_nodeinfo *nni6,
 
                        /* copy the address itself */
                        bcopy(&ifa6->ia_addr.sin6_addr, cp,
 
                        /* copy the address itself */
                        bcopy(&ifa6->ia_addr.sin6_addr, cp,
-                             sizeof(struct in6_addr));
+                           sizeof(struct in6_addr));
                        /* XXX: KAME link-local hack; remove ifindex */
                        /* XXX: KAME link-local hack; remove ifindex */
-                       if (IN6_IS_ADDR_LINKLOCAL(&ifa6->ia_addr.sin6_addr))
+                       if (IN6_IS_ADDR_LINKLOCAL(&ifa6->ia_addr.sin6_addr)) {
                                ((struct in6_addr *)(void *)cp)->s6_addr16[1] = 0;
                                ((struct in6_addr *)(void *)cp)->s6_addr16[1] = 0;
+                       }
                        cp += sizeof(struct in6_addr);
 
                        resid -= (sizeof(struct in6_addr) + sizeof(u_int32_t));
                        copied += (sizeof(struct in6_addr) +
                        cp += sizeof(struct in6_addr);
 
                        resid -= (sizeof(struct in6_addr) + sizeof(u_int32_t));
                        copied += (sizeof(struct in6_addr) +
-                                  sizeof(u_int32_t));
+                           sizeof(u_int32_t));
                        IFA_UNLOCK(ifa);
                }
                ifnet_lock_done(ifp);
                        IFA_UNLOCK(ifa);
                }
                ifnet_lock_done(ifp);
-               if (ifp0)       /* we need search only on the specified IF */
+               if (ifp0) {     /* we need search only on the specified IF */
                        break;
                        break;
+               }
        }
        ifnet_head_done();
 
        }
        ifnet_head_done();
 
@@ -2001,7 +2097,7 @@ ni6_store_addrs(struct icmp6_nodeinfo *ni6, struct icmp6_nodeinfo *nni6,
                goto again;
        }
 
                goto again;
        }
 
-       return(copied);
+       return copied;
 }
 
 /*
 }
 
 /*
@@ -2039,36 +2135,44 @@ icmp6_rip6_input(struct mbuf **mp, int off)
        rip6src.sin6_family = AF_INET6;
        rip6src.sin6_len = sizeof(struct sockaddr_in6);
        rip6src.sin6_addr = ip6->ip6_src;
        rip6src.sin6_family = AF_INET6;
        rip6src.sin6_len = sizeof(struct sockaddr_in6);
        rip6src.sin6_addr = ip6->ip6_src;
-       if (sa6_recoverscope(&rip6src, TRUE))
-               return (IPPROTO_DONE);
+       if (sa6_recoverscope(&rip6src, TRUE)) {
+               return IPPROTO_DONE;
+       }
 
        lck_rw_lock_shared(ripcbinfo.ipi_lock);
        LIST_FOREACH(in6p, &ripcb, inp_list)
        {
 
        lck_rw_lock_shared(ripcbinfo.ipi_lock);
        LIST_FOREACH(in6p, &ripcb, inp_list)
        {
-               if ((in6p->inp_vflag & INP_IPV6) == 0)
+               if ((in6p->inp_vflag & INP_IPV6) == 0) {
                        continue;
                        continue;
-               if (in6p->in6p_ip6_nxt != IPPROTO_ICMPV6)
+               }
+               if (in6p->in6p_ip6_nxt != IPPROTO_ICMPV6) {
                        continue;
                        continue;
+               }
                if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) &&
                if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) &&
-                  !IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &ip6->ip6_dst))
+                   !IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &ip6->ip6_dst)) {
                        continue;
                        continue;
+               }
                if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr) &&
                if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr) &&
-                  !IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, &ip6->ip6_src))
+                   !IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, &ip6->ip6_src)) {
                        continue;
                        continue;
+               }
                if (in6p->in6p_icmp6filt
                    && ICMP6_FILTER_WILLBLOCK(icmp6->icmp6_type,
                if (in6p->in6p_icmp6filt
                    && ICMP6_FILTER_WILLBLOCK(icmp6->icmp6_type,
-                                in6p->in6p_icmp6filt))
+                   in6p->in6p_icmp6filt)) {
                        continue;
                        continue;
+               }
 
 
-               if (inp_restricted_recv(in6p, ifp))
+               if (inp_restricted_recv(in6p, ifp)) {
                        continue;
                        continue;
+               }
 
                if (last) {
 
                if (last) {
-                       struct  mbuf *n;
+                       struct  mbuf *n;
                        if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
                                if ((last->in6p_flags & INP_CONTROLOPTS) != 0 ||
                                    (last->in6p_socket->so_options & SO_TIMESTAMP) != 0 ||
                        if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
                                if ((last->in6p_flags & INP_CONTROLOPTS) != 0 ||
                                    (last->in6p_socket->so_options & SO_TIMESTAMP) != 0 ||
-                                   (last->in6p_socket->so_options & SO_TIMESTAMP_MONOTONIC) != 0) {
+                                   (last->in6p_socket->so_options & SO_TIMESTAMP_MONOTONIC) != 0 ||
+                                   (last->in6p_socket->so_options & SO_TIMESTAMP_CONTINUOUS) != 0) {
                                        ret = ip6_savecontrol(last, n, &opts);
                                        if (ret != 0) {
                                                m_freem(n);
                                        ret = ip6_savecontrol(last, n, &opts);
                                        if (ret != 0) {
                                                m_freem(n);
@@ -2081,8 +2185,8 @@ icmp6_rip6_input(struct mbuf **mp, int off)
                                m_adj(n, off);
                                so_recv_data_stat(last->in6p_socket, m, 0);
                                if (sbappendaddr(&last->in6p_socket->so_rcv,
                                m_adj(n, off);
                                so_recv_data_stat(last->in6p_socket, m, 0);
                                if (sbappendaddr(&last->in6p_socket->so_rcv,
-                                                (struct sockaddr *)&rip6src,
-                                                n, opts, NULL) != 0) {
+                                   (struct sockaddr *)&rip6src,
+                                   n, opts, NULL) != 0) {
                                        sorwakeup(last->in6p_socket);
                                }
                                opts = NULL;
                                        sorwakeup(last->in6p_socket);
                                }
                                opts = NULL;
@@ -2093,7 +2197,8 @@ icmp6_rip6_input(struct mbuf **mp, int off)
        if (last) {
                if ((last->in6p_flags & INP_CONTROLOPTS) != 0 ||
                    (last->in6p_socket->so_options & SO_TIMESTAMP) != 0 ||
        if (last) {
                if ((last->in6p_flags & INP_CONTROLOPTS) != 0 ||
                    (last->in6p_socket->so_options & SO_TIMESTAMP) != 0 ||
-                   (last->in6p_socket->so_options & SO_TIMESTAMP_MONOTONIC) != 0) {
+                   (last->in6p_socket->so_options & SO_TIMESTAMP_MONOTONIC) != 0 ||
+                   (last->in6p_socket->so_options & SO_TIMESTAMP_CONTINUOUS) != 0) {
                        ret = ip6_savecontrol(last, m, &opts);
                        if (ret != 0) {
                                goto error;
                        ret = ip6_savecontrol(last, m, &opts);
                        if (ret != 0) {
                                goto error;
@@ -2103,7 +2208,7 @@ icmp6_rip6_input(struct mbuf **mp, int off)
                m_adj(m, off);
                so_recv_data_stat(last->in6p_socket, m, 0);
                if (sbappendaddr(&last->in6p_socket->so_rcv,
                m_adj(m, off);
                so_recv_data_stat(last->in6p_socket, m, 0);
                if (sbappendaddr(&last->in6p_socket->so_rcv,
-                                (struct sockaddr *)&rip6src, m, opts, NULL) != 0) {
+                   (struct sockaddr *)&rip6src, m, opts, NULL) != 0) {
                        sorwakeup(last->in6p_socket);
                }
        } else {
                        sorwakeup(last->in6p_socket);
                }
        } else {
@@ -2138,10 +2243,14 @@ icmp6_reflect(struct mbuf *m, size_t off)
        struct sockaddr_in6 sa6_src, sa6_dst;
        struct nd_ifinfo *ndi = NULL;
        u_int32_t oflow;
        struct sockaddr_in6 sa6_src, sa6_dst;
        struct nd_ifinfo *ndi = NULL;
        u_int32_t oflow;
-       struct ip6_out_args ip6oa = { IFSCOPE_NONE, { 0 },
-           IP6OAF_SELECT_SRCIF | IP6OAF_BOUND_SRCADDR |
-           IP6OAF_INTCOPROC_ALLOWED | IP6OAF_AWDL_UNRESTRICTED, 0,
-           SO_TC_UNSPEC, _NET_SERVICE_TYPE_UNSPEC };
+       struct ip6_out_args ip6oa;
+
+       bzero(&ip6oa, sizeof(ip6oa));
+       ip6oa.ip6oa_boundif = IFSCOPE_NONE;
+       ip6oa.ip6oa_flags = IP6OAF_SELECT_SRCIF | IP6OAF_BOUND_SRCADDR |
+           IP6OAF_INTCOPROC_ALLOWED | IP6OAF_AWDL_UNRESTRICTED;
+       ip6oa.ip6oa_sotc = SO_TC_UNSPEC;
+       ip6oa.ip6oa_netsvctype = _NET_SERVICE_TYPE_UNSPEC;
 
        if (!(m->m_pkthdr.pkt_flags & PKTF_LOOP) && m->m_pkthdr.rcvif != NULL) {
                ip6oa.ip6oa_boundif = m->m_pkthdr.rcvif->if_index;
 
        if (!(m->m_pkthdr.pkt_flags & PKTF_LOOP) && m->m_pkthdr.rcvif != NULL) {
                ip6oa.ip6oa_boundif = m->m_pkthdr.rcvif->if_index;
@@ -2170,16 +2279,18 @@ icmp6_reflect(struct mbuf *m, size_t off)
                m_adj(m, l);
                l = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr);
                if (m->m_len < l) {
                m_adj(m, l);
                l = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr);
                if (m->m_len < l) {
-                       if ((m_ip6hdr = m_pulldown(m, 0, l, NULL)) == NULL)
+                       if ((m_ip6hdr = m_pulldown(m, 0, l, NULL)) == NULL) {
                                return;
                                return;
+                       }
                }
                bcopy((caddr_t)&nip6, mtod(m, caddr_t), sizeof(nip6));
                }
                bcopy((caddr_t)&nip6, mtod(m, caddr_t), sizeof(nip6));
-       } else /* off == sizeof(struct ip6_hdr) */ {
+       } else { /* off == sizeof(struct ip6_hdr) */
                size_t l;
                l = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr);
                if (m->m_len < l) {
                size_t l;
                l = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr);
                if (m->m_len < l) {
-                       if ((m_ip6hdr = m_pulldown(m, 0, l, NULL)) == NULL)
+                       if ((m_ip6hdr = m_pulldown(m, 0, l, NULL)) == NULL) {
                                return;
                                return;
+                       }
                }
        }
        plen = m->m_pkthdr.len - sizeof(struct ip6_hdr);
                }
        }
        plen = m->m_pkthdr.len - sizeof(struct ip6_hdr);
@@ -2228,7 +2339,7 @@ icmp6_reflect(struct mbuf *m, size_t off)
        for (ia = in6_ifaddrs; ia; ia = ia->ia_next) {
                IFA_LOCK(&ia->ia_ifa);
                if (IN6_ARE_ADDR_EQUAL(&t, &ia->ia_addr.sin6_addr) &&
        for (ia = in6_ifaddrs; ia; ia = ia->ia_next) {
                IFA_LOCK(&ia->ia_ifa);
                if (IN6_ARE_ADDR_EQUAL(&t, &ia->ia_addr.sin6_addr) &&
-                   (ia->ia6_flags & (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY)) == 0) {
+                   (ia->ia6_flags & (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY | IN6_IFF_CLAT46)) == 0) {
                        IFA_UNLOCK(&ia->ia_ifa);
                        src = &t;
                        break;
                        IFA_UNLOCK(&ia->ia_ifa);
                        src = &t;
                        break;
@@ -2313,7 +2424,7 @@ icmp6_reflect(struct mbuf *m, size_t off)
        /*
         * XXX option handling
         */
        /*
         * XXX option handling
         */
-       m->m_flags &= ~(M_BCAST|M_MCAST);
+       m->m_flags &= ~(M_BCAST | M_MCAST);
 
        if (outif != NULL) {
                ifnet_release(outif);
 
        if (outif != NULL) {
                ifnet_release(outif);
@@ -2331,19 +2442,20 @@ icmp6_reflect(struct mbuf *m, size_t off)
 
 bad:
        m_freem(m);
 
 bad:
        m_freem(m);
-       if (outif != NULL)
+       if (outif != NULL) {
                ifnet_release(outif);
                ifnet_release(outif);
+       }
        return;
 }
 
 static const char *
 icmp6_redirect_diag(struct in6_addr *src6,
        return;
 }
 
 static const char *
 icmp6_redirect_diag(struct in6_addr *src6,
-                   struct in6_addr *dst6,
-                   struct in6_addr *tgt6)
+    struct in6_addr *dst6,
+    struct in6_addr *tgt6)
 {
        static char buf[1024];
        snprintf(buf, sizeof(buf), "(src=%s dst=%s tgt=%s)",
 {
        static char buf[1024];
        snprintf(buf, sizeof(buf), "(src=%s dst=%s tgt=%s)",
-               ip6_sprintf(src6), ip6_sprintf(dst6), ip6_sprintf(tgt6));
+           ip6_sprintf(src6), ip6_sprintf(dst6), ip6_sprintf(tgt6));
        return buf;
 }
 
        return buf;
 }
 
@@ -2366,20 +2478,23 @@ icmp6_redirect_input(struct mbuf *m, int off)
        struct in6_addr reddst6;
        union nd_opts ndopts;
 
        struct in6_addr reddst6;
        union nd_opts ndopts;
 
-       if (!m || !ifp)
+       if (!m || !ifp) {
                return;
                return;
+       }
 
        /*
         * If we are an advertising router on this interface,
         * don't update route by icmp6 redirect.
         */
 
        /*
         * If we are an advertising router on this interface,
         * don't update route by icmp6 redirect.
         */
-       if (ifp->if_eflags & IFEF_IPV6_ROUTER)
+       if (ifp->if_eflags & IFEF_IPV6_ROUTER) {
                goto freeit;
                goto freeit;
-       if (!icmp6_rediraccept)
+       }
+       if (!icmp6_rediraccept) {
                goto freeit;
                goto freeit;
+       }
 
 #ifndef PULLDOWN_TEST
 
 #ifndef PULLDOWN_TEST
-       IP6_EXTHDR_CHECK(m, off, icmp6len, return);
+       IP6_EXTHDR_CHECK(m, off, icmp6len, return );
        nd_rd = (struct nd_redirect *)((caddr_t)ip6 + off);
 #else
        IP6_EXTHDR_GET(nd_rd, struct nd_redirect *, m, off, icmp6len);
        nd_rd = (struct nd_redirect *)((caddr_t)ip6 + off);
 #else
        IP6_EXTHDR_GET(nd_rd, struct nd_redirect *, m, off, icmp6len);
@@ -2399,82 +2514,84 @@ icmp6_redirect_input(struct mbuf *m, int off)
        /* validation */
        if (!IN6_IS_ADDR_LINKLOCAL(&src6)) {
                nd6log((LOG_ERR,
        /* validation */
        if (!IN6_IS_ADDR_LINKLOCAL(&src6)) {
                nd6log((LOG_ERR,
-                       "ICMP6 redirect sent from %s rejected; "
-                       "must be from linklocal\n", ip6_sprintf(&src6)));
+                   "ICMP6 redirect sent from %s rejected; "
+                   "must be from linklocal\n", ip6_sprintf(&src6)));
                goto bad;
        }
        if (ip6->ip6_hlim != 255) {
                nd6log((LOG_ERR,
                goto bad;
        }
        if (ip6->ip6_hlim != 255) {
                nd6log((LOG_ERR,
-                       "ICMP6 redirect sent from %s rejected; "
-                       "hlim=%d (must be 255)\n",
-                       ip6_sprintf(&src6), ip6->ip6_hlim));
+                   "ICMP6 redirect sent from %s rejected; "
+                   "hlim=%d (must be 255)\n",
+                   ip6_sprintf(&src6), ip6->ip6_hlim));
                goto bad;
        }
                goto bad;
        }
-    {
-       /* ip6->ip6_src must be equal to gw for icmp6->icmp6_reddst */
-       struct sockaddr_in6 sin6;
-       struct in6_addr *gw6;
+       {
+               /* ip6->ip6_src must be equal to gw for icmp6->icmp6_reddst */
+               struct sockaddr_in6 sin6;
+               struct in6_addr *gw6;
 
 
-       bzero(&sin6, sizeof(sin6));
-       sin6.sin6_family = AF_INET6;
-       sin6.sin6_len = sizeof(struct sockaddr_in6);
-       bcopy(&reddst6, &sin6.sin6_addr, sizeof(reddst6));
-       rt = rtalloc1_scoped((struct sockaddr *)&sin6, 0, 0, ifp->if_index);
-       if (rt) {
-               RT_LOCK(rt);
-               if (rt->rt_gateway == NULL ||
-                   rt->rt_gateway->sa_family != AF_INET6) {
-                       nd6log((LOG_ERR,
-                           "ICMP6 redirect rejected; no route "
-                           "with inet6 gateway found for redirect dst: %s\n",
-                           icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
-                       RT_UNLOCK(rt);
-                       rtfree(rt);
-                       goto bad;
-               }
+               bzero(&sin6, sizeof(sin6));
+               sin6.sin6_family = AF_INET6;
+               sin6.sin6_len = sizeof(struct sockaddr_in6);
+               bcopy(&reddst6, &sin6.sin6_addr, sizeof(reddst6));
+               rt = rtalloc1_scoped((struct sockaddr *)&sin6, 0, 0, ifp->if_index);
+               if (rt) {
+                       RT_LOCK(rt);
+                       if (rt->rt_gateway == NULL ||
+                           rt->rt_gateway->sa_family != AF_INET6) {
+                               nd6log((LOG_ERR,
+                                   "ICMP6 redirect rejected; no route "
+                                   "with inet6 gateway found for redirect dst: %s\n",
+                                   icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
+                               RT_UNLOCK(rt);
+                               rtfree(rt);
+                               goto bad;
+                       }
 
 
-               gw6 = &(((struct sockaddr_in6 *)(void *)
-                   rt->rt_gateway)->sin6_addr);
-               if (bcmp(&src6, gw6, sizeof(struct in6_addr)) != 0) {
+                       gw6 = &(((struct sockaddr_in6 *)(void *)
+                           rt->rt_gateway)->sin6_addr);
+                       if (bcmp(&src6, gw6, sizeof(struct in6_addr)) != 0) {
+                               nd6log((LOG_ERR,
+                                   "ICMP6 redirect rejected; "
+                                   "not equal to gw-for-src=%s (must be same): "
+                                   "%s\n",
+                                   ip6_sprintf(gw6),
+                                   icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
+                               RT_UNLOCK(rt);
+                               rtfree(rt);
+                               goto bad;
+                       }
+               } else {
                        nd6log((LOG_ERR,
                        nd6log((LOG_ERR,
-                               "ICMP6 redirect rejected; "
-                               "not equal to gw-for-src=%s (must be same): "
-                               "%s\n",
-                               ip6_sprintf(gw6),
-                               icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
-                       RT_UNLOCK(rt);
-                       rtfree(rt);
+                           "ICMP6 redirect rejected; "
+                           "no route found for redirect dst: %s\n",
+                           icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
                        goto bad;
                }
                        goto bad;
                }
-       } else {
-               nd6log((LOG_ERR,
-                       "ICMP6 redirect rejected; "
-                       "no route found for redirect dst: %s\n",
-                       icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
-               goto bad;
+               RT_UNLOCK(rt);
+               rtfree(rt);
+               rt = NULL;
        }
        }
-       RT_UNLOCK(rt);
-       rtfree(rt);
-       rt = NULL;
-    }
        if (IN6_IS_ADDR_MULTICAST(&reddst6)) {
                nd6log((LOG_ERR,
        if (IN6_IS_ADDR_MULTICAST(&reddst6)) {
                nd6log((LOG_ERR,
-                       "ICMP6 redirect rejected; "
-                       "redirect dst must be unicast: %s\n",
-                       icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
+                   "ICMP6 redirect rejected; "
+                   "redirect dst must be unicast: %s\n",
+                   icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
                goto bad;
        }
 
        is_router = is_onlink = 0;
                goto bad;
        }
 
        is_router = is_onlink = 0;
-       if (IN6_IS_ADDR_LINKLOCAL(&redtgt6))
-               is_router = 1;  /* router case */
-       if (bcmp(&redtgt6, &reddst6, sizeof(redtgt6)) == 0)
-               is_onlink = 1;  /* on-link destination case */
+       if (IN6_IS_ADDR_LINKLOCAL(&redtgt6)) {
+               is_router = 1;  /* router case */
+       }
+       if (bcmp(&redtgt6, &reddst6, sizeof(redtgt6)) == 0) {
+               is_onlink = 1;  /* on-link destination case */
+       }
        if (!is_router && !is_onlink) {
                nd6log((LOG_ERR,
        if (!is_router && !is_onlink) {
                nd6log((LOG_ERR,
-                       "ICMP6 redirect rejected; "
-                       "neither router case nor onlink case: %s\n",
-                       icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
+                   "ICMP6 redirect rejected; "
+                   "neither router case nor onlink case: %s\n",
+                   icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
                goto bad;
        }
        /* validation passed */
                goto bad;
        }
        /* validation passed */
@@ -2483,8 +2600,8 @@ icmp6_redirect_input(struct mbuf *m, int off)
        nd6_option_init(nd_rd + 1, icmp6len, &ndopts);
        if (nd6_options(&ndopts) < 0) {
                nd6log((LOG_INFO, "icmp6_redirect_input: "
        nd6_option_init(nd_rd + 1, icmp6len, &ndopts);
        if (nd6_options(&ndopts) < 0) {
                nd6log((LOG_INFO, "icmp6_redirect_input: "
-                       "invalid ND option, rejected: %s\n",
-                       icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
+                   "invalid ND option, rejected: %s\n",
+                   icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
                /* nd6_options have incremented stats */
                goto freeit;
        }
                /* nd6_options have incremented stats */
                goto freeit;
        }
@@ -2501,18 +2618,18 @@ icmp6_redirect_input(struct mbuf *m, int off)
 
        if (lladdr && ((ifp->if_addrlen + 2 + 7) & ~7) != lladdrlen) {
                nd6log((LOG_INFO,
 
        if (lladdr && ((ifp->if_addrlen + 2 + 7) & ~7) != lladdrlen) {
                nd6log((LOG_INFO,
-                       "icmp6_redirect_input: lladdrlen mismatch for %s "
-                       "(if %d, icmp6 packet %d): %s\n",
-                       ip6_sprintf(&redtgt6), ifp->if_addrlen, lladdrlen - 2,
-                       icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
+                   "icmp6_redirect_input: lladdrlen mismatch for %s "
+                   "(if %d, icmp6 packet %d): %s\n",
+                   ip6_sprintf(&redtgt6), ifp->if_addrlen, lladdrlen - 2,
+                   icmp6_redirect_diag(&src6, &reddst6, &redtgt6)));
                goto bad;
        }
 
        /* RFC 2461 8.3 */
        nd6_cache_lladdr(ifp, &redtgt6, lladdr, lladdrlen, ND_REDIRECT,
                goto bad;
        }
 
        /* RFC 2461 8.3 */
        nd6_cache_lladdr(ifp, &redtgt6, lladdr, lladdrlen, ND_REDIRECT,
-                        is_onlink ? ND_REDIRECT_ONLINK : ND_REDIRECT_ROUTER);
+           is_onlink ? ND_REDIRECT_ONLINK : ND_REDIRECT_ROUTER);
 
 
-       if (!is_onlink) {       /* better router case.  perform rtredirect. */
+       if (!is_onlink) {       /* better router case.  perform rtredirect. */
                /* perform rtredirect */
                struct sockaddr_in6 sdst;
                struct sockaddr_in6 sgw;
                /* perform rtredirect */
                struct sockaddr_in6 sdst;
                struct sockaddr_in6 sgw;
@@ -2523,7 +2640,7 @@ icmp6_redirect_input(struct mbuf *m, int off)
                bzero(&ssrc, sizeof(ssrc));
                sdst.sin6_family = sgw.sin6_family = ssrc.sin6_family = AF_INET6;
                sdst.sin6_len = sgw.sin6_len = ssrc.sin6_len =
                bzero(&ssrc, sizeof(ssrc));
                sdst.sin6_family = sgw.sin6_family = ssrc.sin6_family = AF_INET6;
                sdst.sin6_len = sgw.sin6_len = ssrc.sin6_len =
-                       sizeof(struct sockaddr_in6);
+                   sizeof(struct sockaddr_in6);
                bcopy(&redtgt6, &sgw.sin6_addr, sizeof(struct in6_addr));
                bcopy(&reddst6, &sdst.sin6_addr, sizeof(struct in6_addr));
                bcopy(&src6, &ssrc.sin6_addr, sizeof(struct in6_addr));
                bcopy(&redtgt6, &sgw.sin6_addr, sizeof(struct in6_addr));
                bcopy(&reddst6, &sdst.sin6_addr, sizeof(struct in6_addr));
                bcopy(&src6, &ssrc.sin6_addr, sizeof(struct in6_addr));
@@ -2532,25 +2649,25 @@ icmp6_redirect_input(struct mbuf *m, int off)
                    (struct sockaddr *)&ssrc, NULL);
        }
        /* finally update cached route in each socket via pfctlinput */
                    (struct sockaddr *)&ssrc, NULL);
        }
        /* finally update cached route in each socket via pfctlinput */
-    {
-       struct sockaddr_in6 sdst;
+       {
+               struct sockaddr_in6 sdst;
 
 
-       bzero(&sdst, sizeof(sdst));
-       sdst.sin6_family = AF_INET6;
-       sdst.sin6_len = sizeof(struct sockaddr_in6);
-       bcopy(&reddst6, &sdst.sin6_addr, sizeof(struct in6_addr));
+               bzero(&sdst, sizeof(sdst));
+               sdst.sin6_family = AF_INET6;
+               sdst.sin6_len = sizeof(struct sockaddr_in6);
+               bcopy(&reddst6, &sdst.sin6_addr, sizeof(struct in6_addr));
 
 
-       pfctlinput(PRC_REDIRECT_HOST, (struct sockaddr *)&sdst);
+               pfctlinput(PRC_REDIRECT_HOST, (struct sockaddr *)&sdst);
 #if IPSEC
 #if IPSEC
-       key_sa_routechange((struct sockaddr *)&sdst);
+               key_sa_routechange((struct sockaddr *)&sdst);
 #endif
 #endif
-    }
+       }
 
 
- freeit:
+freeit:
        m_freem(m);
        return;
 
        m_freem(m);
        return;
 
- bad:
+bad:
        icmp6stat.icp6s_badredirect++;
        m_freem(m);
 }
        icmp6stat.icp6s_badredirect++;
        m_freem(m);
 }
@@ -2558,36 +2675,43 @@ icmp6_redirect_input(struct mbuf *m, int off)
 void
 icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
 {
 void
 icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
 {
-       struct ifnet *ifp;      /* my outgoing interface */
+       struct ifnet *ifp;      /* my outgoing interface */
        struct in6_addr ifp_ll6;
        struct in6_addr *router_ll6;
        struct in6_addr ifp_ll6;
        struct in6_addr *router_ll6;
-       struct ip6_hdr *sip6;   /* m0 as struct ip6_hdr */
-       struct mbuf *m = NULL;  /* newly allocated one */
-       struct ip6_hdr *ip6;    /* m as struct ip6_hdr */
+       struct ip6_hdr *sip6;   /* m0 as struct ip6_hdr */
+       struct mbuf *m = NULL;  /* newly allocated one */
+       struct ip6_hdr *ip6;    /* m as struct ip6_hdr */
        struct nd_redirect *nd_rd;
        size_t maxlen;
        u_char *p;
        struct ifnet *outif = NULL;
        struct sockaddr_in6 src_sa;
        struct nd_redirect *nd_rd;
        size_t maxlen;
        u_char *p;
        struct ifnet *outif = NULL;
        struct sockaddr_in6 src_sa;
-       struct ip6_out_args ip6oa = { IFSCOPE_NONE, { 0 },
-           IP6OAF_SELECT_SRCIF | IP6OAF_BOUND_SRCADDR, 0,
-           SO_TC_UNSPEC, _NET_SERVICE_TYPE_UNSPEC };
+       struct ip6_out_args ip6oa;
+
+       bzero(&ip6oa, sizeof(ip6oa));
+       ip6oa.ip6oa_boundif = IFSCOPE_NONE;
+       ip6oa.ip6oa_flags = IP6OAF_SELECT_SRCIF | IP6OAF_BOUND_SRCADDR;
+       ip6oa.ip6oa_sotc = SO_TC_UNSPEC;
+       ip6oa.ip6oa_netsvctype = _NET_SERVICE_TYPE_UNSPEC;
 
        icmp6_errcount(&icmp6stat.icp6s_outerrhist, ND_REDIRECT, 0);
 
 
        icmp6_errcount(&icmp6stat.icp6s_outerrhist, ND_REDIRECT, 0);
 
-       if (rt != NULL)
+       if (rt != NULL) {
                RT_LOCK(rt);
                RT_LOCK(rt);
+       }
 
        /* sanity check */
 
        /* sanity check */
-       if (!m0 || !rt || !(rt->rt_flags & RTF_UP) || !(ifp = rt->rt_ifp))
+       if (!m0 || !rt || !(rt->rt_flags & RTF_UP) || !(ifp = rt->rt_ifp)) {
                goto fail;
                goto fail;
+       }
 
        /*
         * If we are not a router to begin with, or not an advertising
         * router on this interface, don't send icmp6 redirect.
         */
 
        /*
         * If we are not a router to begin with, or not an advertising
         * router on this interface, don't send icmp6 redirect.
         */
-       if (!ip6_forwarding || !(ifp->if_eflags & IFEF_IPV6_ROUTER))
+       if (!ip6_forwarding || !(ifp->if_eflags & IFEF_IPV6_ROUTER)) {
                goto fail;
                goto fail;
+       }
 
        /*
         * Address check:
 
        /*
         * Address check:
@@ -2609,12 +2733,13 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
                goto fail;
        }
        RT_LOCK(rt);
                goto fail;
        }
        RT_LOCK(rt);
-       if (IN6_IS_ADDR_MULTICAST(&sip6->ip6_dst))
-               goto fail;      /* what should we do here? */
-
+       if (IN6_IS_ADDR_MULTICAST(&sip6->ip6_dst)) {
+               goto fail;      /* what should we do here? */
+       }
        /* rate limit */
        /* rate limit */
-       if (icmp6_ratelimit(&sip6->ip6_src, ND_REDIRECT, 0))
+       if (icmp6_ratelimit(&sip6->ip6_src, ND_REDIRECT, 0)) {
                goto fail;
                goto fail;
+       }
 
        /*
         * Since we are going to append up to 1280 bytes (= IPV6_MMTU),
 
        /*
         * Since we are going to append up to 1280 bytes (= IPV6_MMTU),
@@ -2624,11 +2749,13 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
 #if IPV6_MMTU >= MCLBYTES
 # error assumption failed about IPV6_MMTU and MCLBYTES
 #endif
 #if IPV6_MMTU >= MCLBYTES
 # error assumption failed about IPV6_MMTU and MCLBYTES
 #endif
-       MGETHDR(m, M_DONTWAIT, MT_HEADER);      /* MAC-OK */
-       if (m && IPV6_MMTU >= MHLEN)
+       MGETHDR(m, M_DONTWAIT, MT_HEADER);      /* MAC-OK */
+       if (m && IPV6_MMTU >= MHLEN) {
                MCLGET(m, M_DONTWAIT);
                MCLGET(m, M_DONTWAIT);
-       if (!m)
+       }
+       if (!m) {
                goto fail;
                goto fail;
+       }
        m->m_pkthdr.rcvif = NULL;
        m->m_len = 0;
        maxlen = M_TRAILINGSPACE(m);
        m->m_pkthdr.rcvif = NULL;
        m->m_len = 0;
        maxlen = M_TRAILINGSPACE(m);
@@ -2643,9 +2770,10 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
                /* get ip6 linklocal address for ifp(my outgoing interface). */
                struct in6_ifaddr *ia;
                if ((ia = in6ifa_ifpforlinklocal(ifp,
                /* get ip6 linklocal address for ifp(my outgoing interface). */
                struct in6_ifaddr *ia;
                if ((ia = in6ifa_ifpforlinklocal(ifp,
-                                                IN6_IFF_NOTREADY|
-                                                IN6_IFF_ANYCAST)) == NULL)
+                   IN6_IFF_NOTREADY |
+                   IN6_IFF_ANYCAST)) == NULL) {
                        goto fail;
                        goto fail;
+               }
                IFA_LOCK(&ia->ia_ifa);
                ifp_ll6 = ia->ia_addr.sin6_addr;
                IFA_UNLOCK(&ia->ia_ifa);
                IFA_LOCK(&ia->ia_ifa);
                ifp_ll6 = ia->ia_addr.sin6_addr;
                IFA_UNLOCK(&ia->ia_ifa);
@@ -2657,10 +2785,12 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
                struct sockaddr_in6 *sin6;
                sin6 = (struct sockaddr_in6 *)(void *)rt->rt_gateway;
                router_ll6 = &sin6->sin6_addr;
                struct sockaddr_in6 *sin6;
                sin6 = (struct sockaddr_in6 *)(void *)rt->rt_gateway;
                router_ll6 = &sin6->sin6_addr;
-               if (!IN6_IS_ADDR_LINKLOCAL(router_ll6))
+               if (!IN6_IS_ADDR_LINKLOCAL(router_ll6)) {
                        router_ll6 = (struct in6_addr *)NULL;
                        router_ll6 = (struct in6_addr *)NULL;
-       } else
+               }
+       } else {
                router_ll6 = (struct in6_addr *)NULL;
                router_ll6 = (struct in6_addr *)NULL;
+       }
 
        /* ip6 */
        ip6 = mtod(m, struct ip6_hdr *);
 
        /* ip6 */
        ip6 = mtod(m, struct ip6_hdr *);
@@ -2684,26 +2814,28 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
                 * nd_rd->nd_rd_target must be a link-local address in
                 * better router cases.
                 */
                 * nd_rd->nd_rd_target must be a link-local address in
                 * better router cases.
                 */
-               if (!router_ll6)
+               if (!router_ll6) {
                        goto fail;
                        goto fail;
+               }
                bcopy(router_ll6, &nd_rd->nd_rd_target,
                bcopy(router_ll6, &nd_rd->nd_rd_target,
-                     sizeof(nd_rd->nd_rd_target));
+                   sizeof(nd_rd->nd_rd_target));
                bcopy(&sip6->ip6_dst, &nd_rd->nd_rd_dst,
                bcopy(&sip6->ip6_dst, &nd_rd->nd_rd_dst,
-                     sizeof(nd_rd->nd_rd_dst));
+                   sizeof(nd_rd->nd_rd_dst));
        } else {
                /* make sure redtgt == reddst */
                bcopy(&sip6->ip6_dst, &nd_rd->nd_rd_target,
        } else {
                /* make sure redtgt == reddst */
                bcopy(&sip6->ip6_dst, &nd_rd->nd_rd_target,
-                     sizeof(nd_rd->nd_rd_target));
+                   sizeof(nd_rd->nd_rd_target));
                bcopy(&sip6->ip6_dst, &nd_rd->nd_rd_dst,
                bcopy(&sip6->ip6_dst, &nd_rd->nd_rd_dst,
-                     sizeof(nd_rd->nd_rd_dst));
+                   sizeof(nd_rd->nd_rd_dst));
        }
        RT_UNLOCK(rt);
        rt = NULL;
 
        p = (u_char *)(nd_rd + 1);
 
        }
        RT_UNLOCK(rt);
        rt = NULL;
 
        p = (u_char *)(nd_rd + 1);
 
-       if (!router_ll6)
+       if (!router_ll6) {
                goto nolladdropt;
                goto nolladdropt;
+       }
 
        {
                /* target lladdr option */
 
        {
                /* target lladdr option */
@@ -2715,11 +2847,12 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
 
                /* Callee returns a locked route upon success */
                rt_router = nd6_lookup(router_ll6, 0, ifp, 0);
 
                /* Callee returns a locked route upon success */
                rt_router = nd6_lookup(router_ll6, 0, ifp, 0);
-               if (!rt_router)
+               if (!rt_router) {
                        goto nolladdropt;
                        goto nolladdropt;
+               }
                RT_LOCK_ASSERT_HELD(rt_router);
                len = sizeof(*nd_opt) + ifp->if_addrlen;
                RT_LOCK_ASSERT_HELD(rt_router);
                len = sizeof(*nd_opt) + ifp->if_addrlen;
-               len = (len + 7) & ~7;   /* round by 8 */
+               len = (len + 7) & ~7;   /* round by 8 */
                /* safety check */
                if (len + (p - (u_char *)ip6) > maxlen) {
                        RT_REMREF_LOCKED(rt_router);
                /* safety check */
                if (len + (p - (u_char *)ip6) > maxlen) {
                        RT_REMREF_LOCKED(rt_router);
@@ -2728,16 +2861,16 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
                }
 
                if (!(rt_router->rt_flags & RTF_GATEWAY) &&
                }
 
                if (!(rt_router->rt_flags & RTF_GATEWAY) &&
-                       (rt_router->rt_flags & RTF_LLINFO) &&
-                       (rt_router->rt_gateway->sa_family == AF_LINK) &&
-                       (sdl = (struct sockaddr_dl *)(void *)
-                       rt_router->rt_gateway) && sdl->sdl_alen) {
-                               nd_opt = (struct nd_opt_hdr *)p;
-                               nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
-                               nd_opt->nd_opt_len = len >> 3;
-                               lladdr = (char *)(nd_opt + 1);
-                               bcopy(LLADDR(sdl), lladdr, ifp->if_addrlen);
-                               p += len;
+                   (rt_router->rt_flags & RTF_LLINFO) &&
+                   (rt_router->rt_gateway->sa_family == AF_LINK) &&
+                   (sdl = (struct sockaddr_dl *)(void *)
+                   rt_router->rt_gateway) && sdl->sdl_alen) {
+                       nd_opt = (struct nd_opt_hdr *)p;
+                       nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
+                       nd_opt->nd_opt_len = len >> 3;
+                       lladdr = (char *)(nd_opt + 1);
+                       bcopy(LLADDR(sdl), lladdr, ifp->if_addrlen);
+                       p += len;
                }
                RT_REMREF_LOCKED(rt_router);
                RT_UNLOCK(rt_router);
                }
                RT_REMREF_LOCKED(rt_router);
                RT_UNLOCK(rt_router);
@@ -2748,82 +2881,85 @@ nolladdropt:;
        m->m_pkthdr.len = m->m_len = p - (u_char *)ip6;
 
        /* just to be safe */
        m->m_pkthdr.len = m->m_len = p - (u_char *)ip6;
 
        /* just to be safe */
-#ifdef M_DECRYPTED     /*not openbsd*/
-       if (m0->m_flags & M_DECRYPTED)
+#ifdef M_DECRYPTED      /*not openbsd*/
+       if (m0->m_flags & M_DECRYPTED) {
                goto noredhdropt;
                goto noredhdropt;
+       }
 #endif
 #endif
-       if (p - (u_char *)ip6 > maxlen)
+       if (p - (u_char *)ip6 > maxlen) {
                goto noredhdropt;
                goto noredhdropt;
+       }
 
 
-    {
-       /* redirected header option */
-       int len;
-       struct nd_opt_rd_hdr *nd_opt_rh;
-
-       /*
-        * compute the maximum size for icmp6 redirect header option.
-        * XXX room for auth header?
-        */
-       len = maxlen - (p - (u_char *)ip6);
-       len &= ~7;
+       {
+               /* redirected header option */
+               int len;
+               struct nd_opt_rd_hdr *nd_opt_rh;
 
 
-       /* This is just for simplicity. */
-       if (m0->m_pkthdr.len != m0->m_len) {
-               if (m0->m_next) {
-                       m_freem(m0->m_next);
-                       m0->m_next = NULL;
+               /*
+                * compute the maximum size for icmp6 redirect header option.
+                * XXX room for auth header?
+                */
+               len = maxlen - (p - (u_char *)ip6);
+               len &= ~7;
+
+               /* This is just for simplicity. */
+               if (m0->m_pkthdr.len != m0->m_len) {
+                       if (m0->m_next) {
+                               m_freem(m0->m_next);
+                               m0->m_next = NULL;
+                       }
+                       m0->m_pkthdr.len = m0->m_len;
                }
                }
-               m0->m_pkthdr.len = m0->m_len;
-       }
 
 
-       /*
-        * Redirected header option spec (RFC2461 4.6.3) talks nothing
-        * about padding/truncate rule for the original IP packet.
-        * From the discussion on IPv6imp in Feb 1999, the consensus was:
-        * - "attach as much as possible" is the goal
-        * - pad if not aligned (original size can be guessed by original
-        *   ip6 header)
-        * Following code adds the padding if it is simple enough,
-        * and truncates if not.
-        */
-       if (m0->m_next || m0->m_pkthdr.len != m0->m_len)
-               panic("assumption failed in %s:%d\n", __func__, __LINE__);
+               /*
+                * Redirected header option spec (RFC2461 4.6.3) talks nothing
+                * about padding/truncate rule for the original IP packet.
+                * From the discussion on IPv6imp in Feb 1999, the consensus was:
+                * - "attach as much as possible" is the goal
+                * - pad if not aligned (original size can be guessed by original
+                *   ip6 header)
+                * Following code adds the padding if it is simple enough,
+                * and truncates if not.
+                */
+               if (m0->m_next || m0->m_pkthdr.len != m0->m_len) {
+                       panic("assumption failed in %s:%d\n", __func__, __LINE__);
+               }
 
 
-       if (len - sizeof(*nd_opt_rh) < m0->m_pkthdr.len) {
-               /* not enough room, truncate */
-               m0->m_pkthdr.len = m0->m_len = len - sizeof(*nd_opt_rh);
-       } else {
-               /* enough room, pad or truncate */
-               size_t extra;
-
-               extra = m0->m_pkthdr.len % 8;
-               if (extra) {
-                       /* pad if easy enough, truncate if not */
-                       if (8 - extra <= M_TRAILINGSPACE(m0)) {
-                               /* pad */
-                               m0->m_len += (8 - extra);
-                               m0->m_pkthdr.len += (8 - extra);
-                       } else {
-                               /* truncate */
-                               m0->m_pkthdr.len -= extra;
-                               m0->m_len -= extra;
+               if (len - sizeof(*nd_opt_rh) < m0->m_pkthdr.len) {
+                       /* not enough room, truncate */
+                       m0->m_pkthdr.len = m0->m_len = len - sizeof(*nd_opt_rh);
+               } else {
+                       /* enough room, pad or truncate */
+                       size_t extra;
+
+                       extra = m0->m_pkthdr.len % 8;
+                       if (extra) {
+                               /* pad if easy enough, truncate if not */
+                               if (8 - extra <= M_TRAILINGSPACE(m0)) {
+                                       /* pad */
+                                       m0->m_len += (8 - extra);
+                                       m0->m_pkthdr.len += (8 - extra);
+                               } else {
+                                       /* truncate */
+                                       m0->m_pkthdr.len -= extra;
+                                       m0->m_len -= extra;
+                               }
                        }
                        }
+                       len = m0->m_pkthdr.len + sizeof(*nd_opt_rh);
+                       m0->m_pkthdr.len = m0->m_len = len - sizeof(*nd_opt_rh);
                }
                }
-               len = m0->m_pkthdr.len + sizeof(*nd_opt_rh);
-               m0->m_pkthdr.len = m0->m_len = len - sizeof(*nd_opt_rh);
-       }
 
 
-       nd_opt_rh = (struct nd_opt_rd_hdr *)p;
-       bzero(nd_opt_rh, sizeof(*nd_opt_rh));
-       nd_opt_rh->nd_opt_rh_type = ND_OPT_REDIRECTED_HEADER;
-       nd_opt_rh->nd_opt_rh_len = len >> 3;
-       p += sizeof(*nd_opt_rh);
-       m->m_pkthdr.len = m->m_len = p - (u_char *)ip6;
+               nd_opt_rh = (struct nd_opt_rd_hdr *)p;
+               bzero(nd_opt_rh, sizeof(*nd_opt_rh));
+               nd_opt_rh->nd_opt_rh_type = ND_OPT_REDIRECTED_HEADER;
+               nd_opt_rh->nd_opt_rh_len = len >> 3;
+               p += sizeof(*nd_opt_rh);
+               m->m_pkthdr.len = m->m_len = p - (u_char *)ip6;
 
 
-       /* connect m0 to m */
-       m->m_next = m0;
-       m->m_pkthdr.len = m->m_len + m0->m_len;
-    }
+               /* connect m0 to m */
+               m->m_next = m0;
+               m->m_pkthdr.len = m->m_len + m0->m_len;
+       }
 noredhdropt:;
 
        /* XXX: clear embedded link IDs in the inner header */
 noredhdropt:;
 
        /* XXX: clear embedded link IDs in the inner header */
@@ -2836,7 +2972,7 @@ noredhdropt:;
 
        nd_rd->nd_rd_cksum = 0;
        nd_rd->nd_rd_cksum
 
        nd_rd->nd_rd_cksum = 0;
        nd_rd->nd_rd_cksum
-               = in6_cksum(m, IPPROTO_ICMPV6, sizeof(*ip6), ntohs(ip6->ip6_plen));
+               = in6_cksum(m, IPPROTO_ICMPV6, sizeof(*ip6), ntohs(ip6->ip6_plen));
 
        /* send the packet to outside... */
        ip6oa.ip6oa_boundif = ifp->if_index;
 
        /* send the packet to outside... */
        ip6oa.ip6oa_boundif = ifp->if_index;
@@ -2853,12 +2989,15 @@ noredhdropt:;
        return;
 
 fail:
        return;
 
 fail:
-       if (rt != NULL)
+       if (rt != NULL) {
                RT_UNLOCK(rt);
                RT_UNLOCK(rt);
-       if (m)
+       }
+       if (m) {
                m_freem(m);
                m_freem(m);
-       if (m0)
+       }
+       if (m0) {
                m_freem(m0);
                m_freem(m0);
+       }
 }
 
 /*
 }
 
 /*
@@ -2877,8 +3016,9 @@ icmp6_ctloutput(struct socket *so, struct sockopt *sopt)
                op = sopt->sopt_dir;
                optname = sopt->sopt_name;
                optlen = sopt->sopt_valsize;
                op = sopt->sopt_dir;
                optname = sopt->sopt_name;
                optlen = sopt->sopt_valsize;
-       } else
+       } else {
                level = op = optname = optlen = 0;
                level = op = optname = optlen = 0;
+       }
 
        if (level != IPPROTO_ICMPV6) {
                return EINVAL;
 
        if (level != IPPROTO_ICMPV6) {
                return EINVAL;
@@ -2888,7 +3028,7 @@ icmp6_ctloutput(struct socket *so, struct sockopt *sopt)
        case PRCO_SETOPT:
                switch (optname) {
                case ICMP6_FILTER:
        case PRCO_SETOPT:
                switch (optname) {
                case ICMP6_FILTER:
-                   {
+               {
                        struct icmp6_filter *p;
 
                        if (optlen != 0 && optlen != sizeof(*p)) {
                        struct icmp6_filter *p;
 
                        if (optlen != 0 && optlen != sizeof(*p)) {
@@ -2908,10 +3048,10 @@ icmp6_ctloutput(struct socket *so, struct sockopt *sopt)
                                ICMP6_FILTER_SETPASSALL(inp->in6p_icmp6filt);
                        } else {
                                error = sooptcopyin(sopt, inp->in6p_icmp6filt, optlen,
                                ICMP6_FILTER_SETPASSALL(inp->in6p_icmp6filt);
                        } else {
                                error = sooptcopyin(sopt, inp->in6p_icmp6filt, optlen,
-                                       optlen);
+                                   optlen);
                        }
                        break;
                        }
                        break;
-                   }
+               }
 
                default:
                        error = ENOPROTOOPT;
 
                default:
                        error = ENOPROTOOPT;
@@ -2922,15 +3062,15 @@ icmp6_ctloutput(struct socket *so, struct sockopt *sopt)
        case PRCO_GETOPT:
                switch (optname) {
                case ICMP6_FILTER:
        case PRCO_GETOPT:
                switch (optname) {
                case ICMP6_FILTER:
-                   {
+               {
                        if (inp->in6p_icmp6filt == NULL) {
                                error = EINVAL;
                                break;
                        }
                        error = sooptcopyout(sopt, inp->in6p_icmp6filt,
                        if (inp->in6p_icmp6filt == NULL) {
                                error = EINVAL;
                                break;
                        }
                        error = sooptcopyout(sopt, inp->in6p_icmp6filt,
-                                       min(sizeof(struct icmp6_filter), optlen));
+                           min(sizeof(struct icmp6_filter), optlen));
                        break;
                        break;
-                   }
+               }
 
                default:
                        error = ENOPROTOOPT;
 
                default:
                        error = ENOPROTOOPT;
@@ -2939,7 +3079,7 @@ icmp6_ctloutput(struct socket *so, struct sockopt *sopt)
                break;
        }
 
                break;
        }
 
-       return(error);
+       return error;
 }
 
 /*
 }
 
 /*
@@ -2948,56 +3088,58 @@ icmp6_ctloutput(struct socket *so, struct sockopt *sopt)
 int
 icmp6_dgram_ctloutput(struct socket *so, struct sockopt *sopt)
 {
 int
 icmp6_dgram_ctloutput(struct socket *so, struct sockopt *sopt)
 {
-       if (kauth_cred_issuser(so->so_cred))
+       if (kauth_cred_issuser(so->so_cred)) {
                return icmp6_ctloutput(so, sopt);
                return icmp6_ctloutput(so, sopt);
+       }
 
        if (sopt->sopt_level == IPPROTO_ICMPV6) {
                switch (sopt->sopt_name) {
 
        if (sopt->sopt_level == IPPROTO_ICMPV6) {
                switch (sopt->sopt_name) {
-                       case ICMP6_FILTER:
-                               return icmp6_ctloutput(so, sopt);
-                       default:
-                               return EPERM;
+               case ICMP6_FILTER:
+                       return icmp6_ctloutput(so, sopt);
+               default:
+                       return EPERM;
                }
        }
 
                }
        }
 
-       if (sopt->sopt_level != IPPROTO_IPV6)
+       if (sopt->sopt_level != IPPROTO_IPV6) {
                return EINVAL;
                return EINVAL;
+       }
 
        switch (sopt->sopt_name) {
 
        switch (sopt->sopt_name) {
-               case IPV6_UNICAST_HOPS:
-               case IPV6_CHECKSUM:
-               case IPV6_V6ONLY:
-               case IPV6_USE_MIN_MTU:
-               case IPV6_RECVRTHDR:
-               case IPV6_RECVPKTINFO:
-               case IPV6_RECVHOPLIMIT:
-               case IPV6_PATHMTU:
-               case IPV6_PKTINFO:
-               case IPV6_HOPLIMIT:
-               case IPV6_HOPOPTS:
-               case IPV6_DSTOPTS:
-               case IPV6_MULTICAST_IF:
-               case IPV6_MULTICAST_HOPS:
-               case IPV6_MULTICAST_LOOP:
-               case IPV6_JOIN_GROUP:
-               case IPV6_LEAVE_GROUP:
-               case IPV6_PORTRANGE:
-               case IPV6_IPSEC_POLICY:
-               case IPV6_RECVTCLASS:
-               case IPV6_TCLASS:
-               case IPV6_2292PKTOPTIONS:
-               case IPV6_2292PKTINFO:
-               case IPV6_2292HOPLIMIT:
-               case IPV6_2292HOPOPTS:
-               case IPV6_2292DSTOPTS:
-               case IPV6_2292RTHDR:
-               case IPV6_BOUND_IF:
-               case IPV6_NO_IFT_CELLULAR:
-
-                       return ip6_ctloutput(so, sopt);
+       case IPV6_UNICAST_HOPS:
+       case IPV6_CHECKSUM:
+       case IPV6_V6ONLY:
+       case IPV6_USE_MIN_MTU:
+       case IPV6_RECVRTHDR:
+       case IPV6_RECVPKTINFO:
+       case IPV6_RECVHOPLIMIT:
+       case IPV6_PATHMTU:
+       case IPV6_PKTINFO:
+       case IPV6_HOPLIMIT:
+       case IPV6_HOPOPTS:
+       case IPV6_DSTOPTS:
+       case IPV6_MULTICAST_IF:
+       case IPV6_MULTICAST_HOPS:
+       case IPV6_MULTICAST_LOOP:
+       case IPV6_JOIN_GROUP:
+       case IPV6_LEAVE_GROUP:
+       case IPV6_PORTRANGE:
+       case IPV6_IPSEC_POLICY:
+       case IPV6_RECVTCLASS:
+       case IPV6_TCLASS:
+       case IPV6_2292PKTOPTIONS:
+       case IPV6_2292PKTINFO:
+       case IPV6_2292HOPLIMIT:
+       case IPV6_2292HOPOPTS:
+       case IPV6_2292DSTOPTS:
+       case IPV6_2292RTHDR:
+       case IPV6_BOUND_IF:
+       case IPV6_NO_IFT_CELLULAR:
+
+               return ip6_ctloutput(so, sopt);
 
 
-               default:
-                       return EPERM;
+       default:
+               return EPERM;
        }
 }
 
        }
 }
 
@@ -3014,15 +3156,16 @@ icmp6_dgram_send(struct socket *so, int flags, struct mbuf *m,
 
        if (inp == NULL
 #if NECP
 
        if (inp == NULL
 #if NECP
-               || (necp_socket_should_use_flow_divert(inp))
+           || (necp_socket_should_use_flow_divert(inp))
 #endif /* NECP */
 #endif /* NECP */
-               ) {
+           ) {
                error = (inp == NULL ? EINVAL : EPROTOTYPE);
                goto bad;
        }
 
                error = (inp == NULL ? EINVAL : EPROTOTYPE);
                goto bad;
        }
 
-       if (kauth_cred_issuser(so->so_cred))
-               return (rip6_output(m, so, SIN6(nam), control, 0));
+       if (kauth_cred_issuser(so->so_cred)) {
+               return rip6_output(m, so, SIN6(nam), control, 0);
+       }
 
        /* always copy sockaddr to avoid overwrites */
        if (so->so_state & SS_ISCONNECTED) {
 
        /* always copy sockaddr to avoid overwrites */
        if (so->so_state & SS_ISCONNECTED) {
@@ -3035,7 +3178,7 @@ icmp6_dgram_send(struct socket *so, int flags, struct mbuf *m,
                tmp.sin6_family = AF_INET6;
                tmp.sin6_len = sizeof(struct sockaddr_in6);
                bcopy(&inp->in6p_faddr, &tmp.sin6_addr,
                tmp.sin6_family = AF_INET6;
                tmp.sin6_len = sizeof(struct sockaddr_in6);
                bcopy(&inp->in6p_faddr, &tmp.sin6_addr,
-                         sizeof(struct in6_addr));
+                   sizeof(struct in6_addr));
                dst = &tmp;
        } else {
                if (nam == NULL) {
                dst = &tmp;
        } else {
                if (nam == NULL) {
@@ -3051,9 +3194,9 @@ icmp6_dgram_send(struct socket *so, int flags, struct mbuf *m,
         */
        if (SOCK_PROTO(so) == IPPROTO_ICMPV6) {
                if (m->m_len < sizeof(struct icmp6_hdr) &&
         */
        if (SOCK_PROTO(so) == IPPROTO_ICMPV6) {
                if (m->m_len < sizeof(struct icmp6_hdr) &&
-                       (m = m_pullup(m, sizeof(struct icmp6_hdr))) == NULL) {
-                               error = ENOBUFS;
-                               goto bad;
+                   (m = m_pullup(m, sizeof(struct icmp6_hdr))) == NULL) {
+                       error = ENOBUFS;
+                       goto bad;
                }
                icmp6 = mtod(m, struct icmp6_hdr *);
 
                }
                icmp6 = mtod(m, struct icmp6_hdr *);
 
@@ -3080,49 +3223,56 @@ icmp6_dgram_send(struct socket *so, int flags, struct mbuf *m,
        }
 #endif
 
        }
 #endif
 
-       return (rip6_output(m, so, dst, control, 0));
+       return rip6_output(m, so, dst, control, 0);
 bad:
        VERIFY(error != 0);
 
 bad:
        VERIFY(error != 0);
 
-       if (m != NULL)
+       if (m != NULL) {
                m_freem(m);
                m_freem(m);
-       if (control != NULL)
+       }
+       if (control != NULL) {
                m_freem(control);
                m_freem(control);
+       }
 
 
-       return (error);
+       return error;
 }
 
 /* Like rip6_attach but without root privilege enforcement */
 __private_extern__ int
 icmp6_dgram_attach(struct socket *so, int proto, struct proc *p)
 {
 }
 
 /* Like rip6_attach but without root privilege enforcement */
 __private_extern__ int
 icmp6_dgram_attach(struct socket *so, int proto, struct proc *p)
 {
-        struct inpcb *inp;
-        int error;
-
-        inp = sotoinpcb(so);
-        if (inp)
-                panic("icmp6_dgram_attach");
-
-               if (proto != IPPROTO_ICMPV6)
-                       return EINVAL;
-
-        error = soreserve(so, rip_sendspace, rip_recvspace);
-        if (error)
-                return error;
-        error = in_pcballoc(so, &ripcbinfo, p);
-        if (error)
-                return error;
-        inp = (struct inpcb *)so->so_pcb;
-        inp->inp_vflag |= INP_IPV6;
-        inp->in6p_ip6_nxt = IPPROTO_ICMPV6;
-        inp->in6p_hops = -1;    /* use kernel default */
-        inp->in6p_cksum = -1;
-        MALLOC(inp->in6p_icmp6filt, struct icmp6_filter *,
-               sizeof(struct icmp6_filter), M_PCB, M_WAITOK);
-        if (inp->in6p_icmp6filt == NULL)
-                return (ENOMEM);
-        ICMP6_FILTER_SETPASSALL(inp->in6p_icmp6filt);
-        return 0;
+       struct inpcb *inp;
+       int error;
+
+       inp = sotoinpcb(so);
+       if (inp) {
+               panic("icmp6_dgram_attach");
+       }
+
+       if (proto != IPPROTO_ICMPV6) {
+               return EINVAL;
+       }
+
+       error = soreserve(so, rip_sendspace, rip_recvspace);
+       if (error) {
+               return error;
+       }
+       error = in_pcballoc(so, &ripcbinfo, p);
+       if (error) {
+               return error;
+       }
+       inp = (struct inpcb *)so->so_pcb;
+       inp->inp_vflag |= INP_IPV6;
+       inp->in6p_ip6_nxt = IPPROTO_ICMPV6;
+       inp->in6p_hops = -1;    /* use kernel default */
+       inp->in6p_cksum = -1;
+       MALLOC(inp->in6p_icmp6filt, struct icmp6_filter *,
+           sizeof(struct icmp6_filter), M_PCB, M_WAITOK);
+       if (inp->in6p_icmp6filt == NULL) {
+               return ENOMEM;
+       }
+       ICMP6_FILTER_SETPASSALL(inp->in6p_icmp6filt);
+       return 0;
 }
 
 
 }
 
 
@@ -3136,19 +3286,20 @@ icmp6_dgram_attach(struct socket *so, int proto, struct proc *p)
  */
 static int
 icmp6_ratelimit(
  */
 static int
 icmp6_ratelimit(
-       __unused const struct in6_addr *dst,    /* not used at this moment */
+       __unused const struct in6_addr *dst,    /* not used at this moment */
        const int type,
        __unused const int code)
 {
        int ret;
 
        const int type,
        __unused const int code)
 {
        int ret;
 
-       ret = 0;        /* okay to send */
+       ret = 0;        /* okay to send */
 
        /* PPS limit */
        if (type == ND_ROUTER_ADVERT) {
                if (!ppsratecheck(&icmp6rappslim_last, &icmp6rapps_count,
 
        /* PPS limit */
        if (type == ND_ROUTER_ADVERT) {
                if (!ppsratecheck(&icmp6rappslim_last, &icmp6rapps_count,
-                   icmp6rappslim))
+                   icmp6rappslim)) {
                        ret++;
                        ret++;
+               }
        } else if (!ppsratecheck(&icmp6errppslim_last, &icmp6errpps_count,
            icmp6errppslim)) {
                /* The packet is subject to rate limit */
        } else if (!ppsratecheck(&icmp6errppslim_last, &icmp6errpps_count,
            icmp6errppslim)) {
                /* The packet is subject to rate limit */