From owner-svn-src-stable@freebsd.org Mon Mar 2 13:13:43 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3D6D61AE627; Mon, 2 Mar 2020 13:13:43 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48WLF26bPgz4SlD; Mon, 2 Mar 2020 13:13:42 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 97A0F1CE30; Mon, 2 Mar 2020 13:13:42 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 022DDgbY004262; Mon, 2 Mar 2020 13:13:42 GMT (envelope-from bz@FreeBSD.org) Received: (from bz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 022DDgfS004261; Mon, 2 Mar 2020 13:13:42 GMT (envelope-from bz@FreeBSD.org) Message-Id: <202003021313.022DDgfS004261@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bz set sender to bz@FreeBSD.org using -f From: "Bjoern A. Zeeb" Date: Mon, 2 Mar 2020 13:13:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r358539 - stable/11/sys/netinet6 X-SVN-Group: stable-11 X-SVN-Commit-Author: bz X-SVN-Commit-Paths: stable/11/sys/netinet6 X-SVN-Commit-Revision: 358539 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Mar 2020 13:13:43 -0000 Author: bz Date: Mon Mar 2 13:13:42 2020 New Revision: 358539 URL: https://svnweb.freebsd.org/changeset/base/358539 Log: MFC r358071: ip6_output: update comments. Clear up some comments and improve to panic messages. No functional changes. Modified: stable/11/sys/netinet6/ip6_output.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/netinet6/ip6_output.c ============================================================================== --- stable/11/sys/netinet6/ip6_output.c Mon Mar 2 13:12:45 2020 (r358538) +++ stable/11/sys/netinet6/ip6_output.c Mon Mar 2 13:13:42 2020 (r358539) @@ -180,7 +180,9 @@ static int copypktopts(struct ip6_pktopts *, struct ip do {\ if (m) {\ if (!hdrsplit) \ - panic("assumption failed: hdr not split"); \ + panic("%s:%d: assumption failed: "\ + "hdr not split: hdrsplit %d exthdrs %p",\ + __func__, __LINE__, hdrsplit, &exthdrs);\ *mtod((m), u_char *) = *(p);\ *(p) = (i);\ p = mtod((m), u_char *);\ @@ -278,8 +280,9 @@ ip6_fragment(struct ifnet *ifp, struct mbuf *m0, int h } /* - * IP6 output. The packet in mbuf chain m contains a skeletal IP6 - * header (with pri, len, nxt, hlim, src, dst). + * IP6 output. + * The packet in mbuf chain m contains a skeletal IP6 header (with pri, len, + * nxt, hlim, src, dst). * This function may modify ver and hlim only. * The mbuf chain containing the packet will be freed. * The mbuf opt, if present, will not be freed. @@ -287,9 +290,8 @@ ip6_fragment(struct ifnet *ifp, struct mbuf *m0, int h * skipped and ro->ro_rt would be used. If ro is present but ro->ro_rt is NULL, * then result of route lookup is stored in ro->ro_rt. * - * type of "mtu": rt_mtu is u_long, ifnet.ifr_mtu is int, and - * nd_ifinfo.linkmtu is u_int32_t. so we use u_long to hold largest one, - * which is rt_mtu. + * Type of "mtu": rt_mtu is u_long, ifnet.ifr_mtu is int, and nd_ifinfo.linkmtu + * is uint32_t. So we use u_long to hold largest one, which is rt_mtu. * * ifpp - XXX: just for statistics */ @@ -330,7 +332,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, INP_LOCK_ASSERT(inp); M_SETFIB(m, inp->inp_inc.inc_fibnum); if ((flags & IP_NODEFAULTFLOWID) == 0) { - /* unconditionally set flowid */ + /* Unconditionally set flowid. */ m->m_pkthdr.flowid = inp->inp_flowid; M_HASHTYPE_SET(m, inp->inp_flowtype); } @@ -353,12 +355,12 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, bzero(&exthdrs, sizeof(exthdrs)); if (opt) { - /* Hop-by-Hop options header */ + /* Hop-by-Hop options header. */ MAKE_EXTHDR(opt->ip6po_hbh, &exthdrs.ip6e_hbh); - /* Destination options header(1st part) */ + /* Destination options header (1st part). */ if (opt->ip6po_rthdr) { /* - * Destination options header(1st part) + * Destination options header (1st part). * This only makes sense with a routing header. * See Section 9.2 of RFC 3542. * Disabling this part just for MIP6 convenience is @@ -369,9 +371,9 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, */ MAKE_EXTHDR(opt->ip6po_dest1, &exthdrs.ip6e_dest1); } - /* Routing header */ + /* Routing header. */ MAKE_EXTHDR(opt->ip6po_rthdr, &exthdrs.ip6e_rthdr); - /* Destination options header(2nd part) */ + /* Destination options header (2nd part). */ MAKE_EXTHDR(opt->ip6po_dest2, &exthdrs.ip6e_dest2); } @@ -388,7 +390,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, optlen += exthdrs.ip6e_rthdr->m_len; unfragpartlen = optlen + sizeof(struct ip6_hdr); - /* NOTE: we don't add AH/ESP length here (done in ip6_ipsec_output) */ + /* NOTE: we don't add AH/ESP length here (done in ip6_ipsec_output). */ if (exthdrs.ip6e_dest2) optlen += exthdrs.ip6e_dest2->m_len; @@ -407,7 +409,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, ip6 = mtod(m, struct ip6_hdr *); - /* adjust mbuf packet header length */ + /* Adjust mbuf packet header length. */ m->m_pkthdr.len += optlen; plen = m->m_pkthdr.len - sizeof(*ip6); @@ -421,7 +423,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, m = exthdrs.ip6e_ip6; hdrsplit++; } - /* adjust pointer */ + /* Adjust pointer. */ ip6 = mtod(m, struct ip6_hdr *); if ((error = ip6_insert_jumboopt(&exthdrs, plen)) != 0) goto freehdrs; @@ -433,26 +435,29 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, * Concatenate headers and fill in next header fields. * Here we have, on "m" * IPv6 payload - * and we insert headers accordingly. Finally, we should be getting: - * IPv6 hbh dest1 rthdr ah* [esp* dest2 payload] + * and we insert headers accordingly. + * Finally, we should be getting: + * IPv6 hbh dest1 rthdr ah* [esp* dest2 payload]. * - * during the header composing process, "m" points to IPv6 header. - * "mprev" points to an extension header prior to esp. + * During the header composing process "m" points to IPv6 + * header. "mprev" points to an extension header prior to esp. */ u_char *nexthdrp = &ip6->ip6_nxt; mprev = m; /* - * we treat dest2 specially. this makes IPsec processing - * much easier. the goal here is to make mprev point the + * We treat dest2 specially. This makes IPsec processing + * much easier. The goal here is to make mprev point the * mbuf prior to dest2. * - * result: IPv6 dest2 payload + * Result: IPv6 dest2 payload. * m and mprev will point to IPv6 header. */ if (exthdrs.ip6e_dest2) { if (!hdrsplit) - panic("assumption failed: hdr not split"); + panic("%s:%d: assumption failed: " + "hdr not split: hdrsplit %d exthdrs %p", + __func__, __LINE__, hdrsplit, &exthdrs); exthdrs.ip6e_dest2->m_next = m->m_next; m->m_next = exthdrs.ip6e_dest2; *mtod(exthdrs.ip6e_dest2, u_char *) = ip6->ip6_nxt; @@ -460,7 +465,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, } /* - * result: IPv6 hbh dest1 rthdr dest2 payload + * Result: IPv6 hbh dest1 rthdr dest2 payload. * m will point to IPv6 header. mprev will point to the * extension header prior to dest2 (rthdr in the above case). */ @@ -470,15 +475,13 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, MAKE_CHAIN(exthdrs.ip6e_rthdr, mprev, nexthdrp, IPPROTO_ROUTING); - /* - * If there is a routing header, discard the packet. - */ + /* If there is a routing header, discard the packet. */ if (exthdrs.ip6e_rthdr) { error = EINVAL; goto bad; } - /* Source address validation */ + /* Source address validation. */ if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src) && (flags & IPV6_UNSPECSRC) == 0) { error = EOPNOTSUPP; @@ -493,9 +496,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, IP6STAT_INC(ip6s_localout); - /* - * Route packet. - */ + /* Route packet. */ if (ro == NULL) { ro = &ip6route; bzero((caddr_t)ro, sizeof(*ro)); @@ -511,9 +512,9 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, fibnum = (inp != NULL) ? inp->inp_inc.inc_fibnum : M_GETFIB(m); again: /* - * if specified, try to fill in the traffic class field. - * do not override if a non-zero value is already set. - * we check the diffserv field and the ecn field separately. + * If specified, try to fill in the traffic class field. + * Do not override if a non-zero value is already set. + * We check the diffserv field and the ECN field separately. */ if (opt && opt->ip6po_tclass >= 0) { int mask = 0; @@ -526,7 +527,7 @@ again: ip6->ip6_flow |= htonl((opt->ip6po_tclass & mask) << 20); } - /* fill in or override the hop limit field, if necessary. */ + /* Fill in or override the hop limit field, if necessary. */ if (opt && opt->ip6po_hlim != -1) ip6->ip6_hlim = opt->ip6po_hlim & 0xff; else if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { @@ -538,7 +539,7 @@ again: /* * Validate route against routing table additions; * a better/more specific route might have been added. - * Make sure address family is set in route. + * Make sure that the address family is set in route. */ if (inp) { ro->ro_dst.sin6_family = AF_INET6; @@ -569,15 +570,13 @@ again: } if (rt == NULL) { /* - * If in6_selectroute() does not return a route entry, + * If in6_selectroute() does not return a route entry * dst may not have been updated. */ *dst = dst_sa; /* XXX */ } - /* - * then rt (for unicast) and ifp must be non-NULL valid values. - */ + /* Then rt (for unicast) and ifp must be non-NULL valid values. */ if ((flags & IPV6_FORWARDING) == 0) { /* XXX: the FORWARDING flag can be set for mrouting. */ in6_ifstat_inc(ifp, ifs6_out_request); @@ -595,7 +594,7 @@ again: src_sa.sin6_addr = ip6->ip6_src; dst0 = ip6->ip6_dst; - /* re-initialize to be sure */ + /* Re-initialize to be sure. */ bzero(&dst_sa, sizeof(dst_sa)); dst_sa.sin6_family = AF_INET6; dst_sa.sin6_len = sizeof(dst_sa); @@ -612,7 +611,7 @@ again: * * Because the loopback interface cannot receive * packets with a different scope ID than its own, - * there is a trick is to pretend the outgoing packet + * there is a trick to pretend the outgoing packet * was received by the real network interface, by * setting "origifp" different from "ifp". This is * only allowed when "ifp" is a loopback network @@ -650,7 +649,6 @@ again: error = EHOSTUNREACH; /* XXX */ goto bad; } - /* All scope ID checks are successful. */ if (rt && !IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { @@ -667,13 +665,12 @@ again: } if (!IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { - m->m_flags &= ~(M_BCAST | M_MCAST); /* just in case */ + m->m_flags &= ~(M_BCAST | M_MCAST); /* Just in case. */ } else { m->m_flags = (m->m_flags & ~M_BCAST) | M_MCAST; in6_ifstat_inc(ifp, ifs6_out_mcast); - /* - * Confirm that the outgoing interface supports multicast. - */ + + /* Confirm that the outgoing interface supports multicast. */ if (!(ifp->if_flags & IFF_MULTICAST)) { IP6STAT_INC(ip6s_noroute); in6_ifstat_inc(ifp, ifs6_out_discard); @@ -768,8 +765,8 @@ again: } /* - * clear embedded scope identifiers if necessary. - * in6_clearscope will touch the addresses only when necessary. + * Clear embedded scope identifiers if necessary. + * in6_clearscope() will touch the addresses only when necessary. */ in6_clearscope(&ip6->ip6_src); in6_clearscope(&ip6->ip6_dst); @@ -799,7 +796,7 @@ again: if (ip6_process_hopopts(m, (u_int8_t *)(hbh + 1), ((hbh->ip6h_len + 1) << 3) - sizeof(struct ip6_hbh), &dummy, &plen) < 0) { - /* m was already freed at this point */ + /* m was already freed at this point. */ error = EINVAL;/* better error? */ goto done; } @@ -892,7 +889,7 @@ passout: * Send the packet to the outgoing interface. * If necessary, do IPv6 fragmentation before sending. * - * the logic here is rather complex: + * The logic here is rather complex: * 1: normal case (dontfrag == 0, alwaysfrag == 0) * 1-a: send as is if tlen <= path mtu * 1-b: fragment if tlen > path mtu @@ -905,7 +902,7 @@ passout: * always fragment * * 4: if dontfrag == 1 && alwaysfrag == 1 - * error, as we cannot handle this conflicting request + * error, as we cannot handle this conflicting request. */ sw_csum = m->m_pkthdr.csum_flags; if (!hdrsplit) { @@ -936,12 +933,12 @@ passout: dontfrag = 1; else dontfrag = 0; - if (dontfrag && alwaysfrag) { /* case 4 */ - /* conflicting request - can't transmit */ + if (dontfrag && alwaysfrag) { /* Case 4. */ + /* Conflicting request - can't transmit. */ error = EMSGSIZE; goto bad; } - if (dontfrag && tlen > IN6_LINKMTU(ifp) && !tso) { /* case 2-b */ + if (dontfrag && tlen > IN6_LINKMTU(ifp) && !tso) { /* Case 2-b. */ /* * Even if the DONTFRAG option is specified, we cannot send the * packet when the data length is larger than the MTU of the @@ -956,10 +953,8 @@ passout: goto bad; } - /* - * transmit packet without fragmentation - */ - if (dontfrag || (!alwaysfrag && tlen <= mtu)) { /* case 1-a and 2-a */ + /* Transmit packet without fragmentation. */ + if (dontfrag || (!alwaysfrag && tlen <= mtu)) { /* Cases 1-a and 2-a. */ struct in6_ifaddr *ia6; ip6 = mtod(m, struct ip6_hdr *); @@ -976,16 +971,14 @@ passout: goto done; } - /* - * try to fragment the packet. case 1-b and 3 - */ + /* Try to fragment the packet. Cases 1-b and 3. */ if (mtu < IPV6_MMTU) { - /* path MTU cannot be less than IPV6_MMTU */ + /* Path MTU cannot be less than IPV6_MMTU. */ error = EMSGSIZE; in6_ifstat_inc(ifp, ifs6_out_fragfail); goto bad; } else if (ip6->ip6_plen == 0) { - /* jumbo payload cannot be fragmented */ + /* Jumbo payload cannot be fragmented. */ error = EMSGSIZE; in6_ifstat_inc(ifp, ifs6_out_fragfail); goto bad; @@ -1054,9 +1047,7 @@ passout: in6_ifstat_inc(ifp, ifs6_out_fragok); } - /* - * Remove leading garbages. - */ + /* Remove leading garbage. */ sendorfree: m = m0->m_nextpkt; m0->m_nextpkt = 0; @@ -1091,7 +1082,7 @@ done: return (error); freehdrs: - m_freem(exthdrs.ip6e_hbh); /* m_freem will check if mbuf is 0 */ + m_freem(exthdrs.ip6e_hbh); /* m_freem() checks if mbuf is NULL. */ m_freem(exthdrs.ip6e_dest1); m_freem(exthdrs.ip6e_rthdr); m_freem(exthdrs.ip6e_dest2);