Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet6/ip6_output.c
| Show First 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | |||||
| static int ip6_setpktopt(int, u_char *, int, struct ip6_pktopts *, | static int ip6_setpktopt(int, u_char *, int, struct ip6_pktopts *, | ||||
| struct ucred *, int, int, int); | struct ucred *, int, int, int); | ||||
| static int ip6_copyexthdr(struct mbuf **, caddr_t, int); | static int ip6_copyexthdr(struct mbuf **, caddr_t, int); | ||||
| static int ip6_insertfraghdr(struct mbuf *, struct mbuf *, int, | static int ip6_insertfraghdr(struct mbuf *, struct mbuf *, int, | ||||
| struct ip6_frag **); | struct ip6_frag **); | ||||
| static int ip6_insert_jumboopt(struct ip6_exthdrs *, u_int32_t); | static int ip6_insert_jumboopt(struct ip6_exthdrs *, u_int32_t); | ||||
| static int ip6_splithdr(struct mbuf *, struct ip6_exthdrs *); | static int ip6_splithdr(struct mbuf *, struct ip6_exthdrs *); | ||||
| static int ip6_getpmtu(struct route_in6 *, int, | static void ip6_getpmtu(struct route_in6 *, int, | ||||
| struct ifnet *, const struct in6_addr *, u_long *, int *, u_int, | struct ifnet *, const struct in6_addr *, u_long *, u_int, u_int); | ||||
| u_int); | static void ip6_calcmtu(struct ifnet *, const struct in6_addr *, u_long, | ||||
| static int ip6_calcmtu(struct ifnet *, const struct in6_addr *, u_long, | u_long *, u_int); | ||||
| u_long *, int *, u_int); | |||||
| static int ip6_getpmtu_ctl(u_int, const struct in6_addr *, u_long *); | static int ip6_getpmtu_ctl(u_int, const struct in6_addr *, u_long *); | ||||
| static int copypktopts(struct ip6_pktopts *, struct ip6_pktopts *, int); | static int copypktopts(struct ip6_pktopts *, struct ip6_pktopts *, int); | ||||
| /* | /* | ||||
| * Make an extension header from option data. hp is the source, | * Make an extension header from option data. hp is the source, | ||||
| * mp is the destination, and _ol is the optlen. | * mp is the destination, and _ol is the optlen. | ||||
| */ | */ | ||||
| #define MAKE_EXTHDR(hp, mp, _ol) \ | #define MAKE_EXTHDR(hp, mp, _ol) \ | ||||
| ▲ Show 20 Lines • Show All 252 Lines • ▼ Show 20 Lines | ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, | ||||
| struct sockaddr_in6 *dst, sin6, src_sa, dst_sa; | struct sockaddr_in6 *dst, sin6, src_sa, dst_sa; | ||||
| struct in6_addr odst; | struct in6_addr odst; | ||||
| u_char *nexthdrp; | u_char *nexthdrp; | ||||
| int tlen, len; | int tlen, len; | ||||
| int error = 0; | int error = 0; | ||||
| int vlan_pcp = -1; | int vlan_pcp = -1; | ||||
| struct in6_ifaddr *ia = NULL; | struct in6_ifaddr *ia = NULL; | ||||
| u_long mtu; | u_long mtu; | ||||
| int alwaysfrag, dontfrag; | int dontfrag; | ||||
| u_int32_t optlen, plen = 0, unfragpartlen; | u_int32_t optlen, plen = 0, unfragpartlen; | ||||
| struct ip6_exthdrs exthdrs; | struct ip6_exthdrs exthdrs; | ||||
| struct in6_addr src0, dst0; | struct in6_addr src0, dst0; | ||||
| u_int32_t zone; | u_int32_t zone; | ||||
| bool hdrsplit; | bool hdrsplit; | ||||
| int sw_csum, tso; | int sw_csum, tso; | ||||
| int needfiblookup; | int needfiblookup; | ||||
| uint32_t fibnum; | uint32_t fibnum; | ||||
| ▲ Show 20 Lines • Show All 504 Lines • ▼ Show 20 Lines | #endif /* IPSEC */ | ||||
| /* | /* | ||||
| * Fill the outgoing inteface to tell the upper layer | * Fill the outgoing inteface to tell the upper layer | ||||
| * to increment per-interface statistics. | * to increment per-interface statistics. | ||||
| */ | */ | ||||
| if (ifpp) | if (ifpp) | ||||
| *ifpp = ifp; | *ifpp = ifp; | ||||
| /* Determine path MTU. */ | /* Determine path MTU. */ | ||||
| if ((error = ip6_getpmtu(ro_pmtu, ro != ro_pmtu, ifp, &ip6->ip6_dst, | ip6_getpmtu(ro_pmtu, ro != ro_pmtu, ifp, &ip6->ip6_dst, &mtu, fibnum, | ||||
| &mtu, &alwaysfrag, fibnum, *nexthdrp)) != 0) | *nexthdrp); | ||||
| goto bad; | KASSERT(mtu > 0, ("%s:%d: mtu %ld, ro_pmtu %p ro %p ifp %p fibnum %u", | ||||
| KASSERT(mtu > 0, ("%s:%d: mtu %ld, ro_pmtu %p ro %p ifp %p " | __func__, __LINE__, mtu, ro_pmtu, ro, ifp, fibnum)); | ||||
| "alwaysfrag %d fibnum %u\n", __func__, __LINE__, mtu, ro_pmtu, ro, | |||||
| ifp, alwaysfrag, fibnum)); | |||||
| /* | /* | ||||
| * The caller of this function may specify to use the minimum MTU | * The caller of this function may specify to use the minimum MTU | ||||
| * in some cases. | * in some cases. | ||||
| * An advanced API option (IPV6_USE_MIN_MTU) can also override MTU | * An advanced API option (IPV6_USE_MIN_MTU) can also override MTU | ||||
| * setting. The logic is a bit complicated; by default, unicast | * setting. The logic is a bit complicated; by default, unicast | ||||
| * packets will follow path MTU while multicast packets will be sent at | * packets will follow path MTU while multicast packets will be sent at | ||||
| * the minimum MTU. If IP6PO_MINMTU_ALL is specified, all packets | * the minimum MTU. If IP6PO_MINMTU_ALL is specified, all packets | ||||
| ▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | if (error != 0) { | ||||
| m = m1; | m = m1; | ||||
| } | } | ||||
| } | } | ||||
| /* | /* | ||||
| * Send the packet to the outgoing interface. | * Send the packet to the outgoing interface. | ||||
| * If necessary, do IPv6 fragmentation before sending. | * If necessary, do IPv6 fragmentation before sending. | ||||
| * | * | ||||
| * The logic here is rather complex: | * 1: normal case (dontfrag == 0) | ||||
| * 1: normal case (dontfrag == 0, alwaysfrag == 0) | |||||
| * 1-a: send as is if tlen <= path mtu | * 1-a: send as is if tlen <= path mtu | ||||
| * 1-b: fragment if tlen > path mtu | * 1-b: fragment if tlen > path mtu | ||||
| * | * | ||||
| * 2: if user asks us not to fragment (dontfrag == 1) | * 2: if user asks us not to fragment (dontfrag == 1) | ||||
| * 2-a: send as is if tlen <= interface mtu | * 2-a: send as is if tlen <= interface mtu | ||||
| * 2-b: error if tlen > interface mtu | * 2-b: error if tlen > interface mtu | ||||
| * | |||||
| * 3: if we always need to attach fragment header (alwaysfrag == 1) | |||||
| * always fragment | |||||
| * | |||||
| * 4: if dontfrag == 1 && alwaysfrag == 1 | |||||
| * error, as we cannot handle this conflicting request. | |||||
| */ | */ | ||||
| sw_csum = m->m_pkthdr.csum_flags; | sw_csum = m->m_pkthdr.csum_flags; | ||||
| if (!hdrsplit) { | if (!hdrsplit) { | ||||
| tso = ((sw_csum & ifp->if_hwassist & | tso = ((sw_csum & ifp->if_hwassist & | ||||
| (CSUM_TSO | CSUM_INNER_TSO)) != 0) ? 1 : 0; | (CSUM_TSO | CSUM_INNER_TSO)) != 0) ? 1 : 0; | ||||
| sw_csum &= ~ifp->if_hwassist; | sw_csum &= ~ifp->if_hwassist; | ||||
| } else | } else | ||||
| tso = 0; | tso = 0; | ||||
| /* | /* | ||||
| * If we added extension headers, we will not do TSO and calculate the | * If we added extension headers, we will not do TSO and calculate the | ||||
| * checksums ourselves for now. | * checksums ourselves for now. | ||||
| * XXX-BZ Need a framework to know when the NIC can handle it, even | * XXX-BZ Need a framework to know when the NIC can handle it, even | ||||
| * with ext. hdrs. | * with ext. hdrs. | ||||
| */ | */ | ||||
| ip6_output_delayed_csum(m, ifp, sw_csum, plen, optlen); | ip6_output_delayed_csum(m, ifp, sw_csum, plen, optlen); | ||||
| /* XXX-BZ m->m_pkthdr.csum_flags &= ~ifp->if_hwassist; */ | /* XXX-BZ m->m_pkthdr.csum_flags &= ~ifp->if_hwassist; */ | ||||
| tlen = m->m_pkthdr.len; | tlen = m->m_pkthdr.len; | ||||
| if ((opt && (opt->ip6po_flags & IP6PO_DONTFRAG)) || tso) | if ((opt && (opt->ip6po_flags & IP6PO_DONTFRAG)) || tso) | ||||
| dontfrag = 1; | dontfrag = 1; | ||||
| else | else | ||||
| dontfrag = 0; | dontfrag = 0; | ||||
| 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 | * If the DONTFRAG option is specified, we cannot send the | ||||
| * packet when the data length is larger than the MTU of the | * packet when the data length is larger than the MTU of the | ||||
| * outgoing interface. | * outgoing interface. | ||||
| * Notify the error by sending IPV6_PATHMTU ancillary data if | * Notify the error by sending IPV6_PATHMTU ancillary data if | ||||
| * application wanted to know the MTU value. Also return an | * application wanted to know the MTU value. Also return an | ||||
| * error code (this is not described in the API spec). | * error code (this is not described in the API spec). | ||||
| */ | */ | ||||
| if (inp != NULL) | if (inp != NULL) | ||||
| ip6_notify_pmtu(inp, &dst_sa, (u_int32_t)mtu); | ip6_notify_pmtu(inp, &dst_sa, (u_int32_t)mtu); | ||||
| error = EMSGSIZE; | error = EMSGSIZE; | ||||
| goto bad; | goto bad; | ||||
| } | } | ||||
| /* Transmit packet without fragmentation. */ | /* Transmit packet without fragmentation. */ | ||||
| if (dontfrag || (!alwaysfrag && tlen <= mtu)) { /* Cases 1-a and 2-a. */ | if (dontfrag || tlen <= mtu) { /* Cases 1-a and 2-a. */ | ||||
| struct in6_ifaddr *ia6; | struct in6_ifaddr *ia6; | ||||
| ip6 = mtod(m, struct ip6_hdr *); | ip6 = mtod(m, struct ip6_hdr *); | ||||
| ia6 = in6_ifawithifp(ifp, &ip6->ip6_src); | ia6 = in6_ifawithifp(ifp, &ip6->ip6_src); | ||||
| if (ia6) { | if (ia6) { | ||||
| /* Record statistics for this interface address. */ | /* Record statistics for this interface address. */ | ||||
| counter_u64_add(ia6->ia_ifa.ifa_opackets, 1); | counter_u64_add(ia6->ia_ifa.ifa_opackets, 1); | ||||
| counter_u64_add(ia6->ia_ifa.ifa_obytes, | counter_u64_add(ia6->ia_ifa.ifa_obytes, | ||||
| m->m_pkthdr.len); | m->m_pkthdr.len); | ||||
| } | } | ||||
| error = ip6_output_send(inp, ifp, origifp, m, dst, ro, | error = ip6_output_send(inp, ifp, origifp, m, dst, ro, | ||||
| (flags & IP_NO_SND_TAG_RL) ? false : true); | (flags & IP_NO_SND_TAG_RL) ? false : true); | ||||
| goto done; | goto done; | ||||
| } | } | ||||
| /* Try to fragment the packet. Cases 1-b and 3. */ | /* Try to fragment the packet. Case 1-b. */ | ||||
| if (mtu < IPV6_MMTU) { | if (mtu < IPV6_MMTU) { | ||||
| /* Path MTU cannot be less than IPV6_MMTU. */ | /* Path MTU cannot be less than IPV6_MMTU. */ | ||||
| error = EMSGSIZE; | error = EMSGSIZE; | ||||
| in6_ifstat_inc(ifp, ifs6_out_fragfail); | in6_ifstat_inc(ifp, ifs6_out_fragfail); | ||||
| goto bad; | goto bad; | ||||
| } else if (ip6->ip6_plen == 0) { | } else if (ip6->ip6_plen == 0) { | ||||
| /* Jumbo payload cannot be fragmented. */ | /* Jumbo payload cannot be fragmented. */ | ||||
| error = EMSGSIZE; | error = EMSGSIZE; | ||||
| ▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | ip6_getpmtu_ctl(u_int fibnum, const struct in6_addr *dst, u_long *mtup) | ||||
| struct in6_addr kdst; | struct in6_addr kdst; | ||||
| uint32_t scopeid; | uint32_t scopeid; | ||||
| int error; | int error; | ||||
| in6_splitscope(dst, &kdst, &scopeid); | in6_splitscope(dst, &kdst, &scopeid); | ||||
| NET_EPOCH_ENTER(et); | NET_EPOCH_ENTER(et); | ||||
| nh = fib6_lookup(fibnum, &kdst, scopeid, NHR_NONE, 0); | nh = fib6_lookup(fibnum, &kdst, scopeid, NHR_NONE, 0); | ||||
| if (nh != NULL) | if (nh != NULL) { | ||||
| error = ip6_calcmtu(nh->nh_ifp, dst, nh->nh_mtu, mtup, NULL, 0); | ip6_calcmtu(nh->nh_ifp, dst, nh->nh_mtu, mtup, 0); | ||||
| else | error = 0; | ||||
| } else | |||||
| error = EHOSTUNREACH; | error = EHOSTUNREACH; | ||||
| NET_EPOCH_EXIT(et); | NET_EPOCH_EXIT(et); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| /* | /* | ||||
| * Calculates IPv6 path MTU for @dst based on transmit @ifp, | * Calculates IPv6 path MTU for @dst based on transmit @ifp, | ||||
| * and cached data in @ro_pmtu. | * and cached data in @ro_pmtu. | ||||
| * MTU from (successful) route lookup is saved (along with dst) | * MTU from (successful) route lookup is saved (along with dst) | ||||
| * inside @ro_pmtu to avoid subsequent route lookups after packet | * inside @ro_pmtu to avoid subsequent route lookups after packet | ||||
| * filter processing. | * filter processing. | ||||
| * | * | ||||
| * Stores mtu and always-frag value into @mtup and @alwaysfragp. | * Stores mtu into @mtup. | ||||
| * Returns 0 on success. | |||||
| */ | */ | ||||
| static int | static void | ||||
| ip6_getpmtu(struct route_in6 *ro_pmtu, int do_lookup, | ip6_getpmtu(struct route_in6 *ro_pmtu, int do_lookup, | ||||
| struct ifnet *ifp, const struct in6_addr *dst, u_long *mtup, | struct ifnet *ifp, const struct in6_addr *dst, u_long *mtup, | ||||
| int *alwaysfragp, u_int fibnum, u_int proto) | u_int fibnum, u_int proto) | ||||
| { | { | ||||
| struct nhop_object *nh; | struct nhop_object *nh; | ||||
| struct in6_addr kdst; | struct in6_addr kdst; | ||||
| uint32_t scopeid; | uint32_t scopeid; | ||||
| struct sockaddr_in6 *sa6_dst, sin6; | struct sockaddr_in6 *sa6_dst, sin6; | ||||
| u_long mtu; | u_long mtu; | ||||
| NET_EPOCH_ASSERT(); | NET_EPOCH_ASSERT(); | ||||
| Show All 27 Lines | if (ro_pmtu == NULL || ro_pmtu->ro_mtu == 0) { | ||||
| } | } | ||||
| } else | } else | ||||
| mtu = ro_pmtu->ro_mtu; | mtu = ro_pmtu->ro_mtu; | ||||
| } | } | ||||
| if (ro_pmtu != NULL && ro_pmtu->ro_nh != NULL) | if (ro_pmtu != NULL && ro_pmtu->ro_nh != NULL) | ||||
| mtu = ro_pmtu->ro_nh->nh_mtu; | mtu = ro_pmtu->ro_nh->nh_mtu; | ||||
| return (ip6_calcmtu(ifp, dst, mtu, mtup, alwaysfragp, proto)); | ip6_calcmtu(ifp, dst, mtu, mtup, proto); | ||||
| } | } | ||||
| /* | /* | ||||
| * Calculate MTU based on transmit @ifp, route mtu @rt_mtu and | * Calculate MTU based on transmit @ifp, route mtu @rt_mtu and | ||||
| * hostcache data for @dst. | * hostcache data for @dst. | ||||
| * Stores mtu and always-frag value into @mtup and @alwaysfragp. | * Stores mtu into @mtup. | ||||
| * | |||||
| * Returns 0 on success. | |||||
| */ | */ | ||||
| static int | static void | ||||
| ip6_calcmtu(struct ifnet *ifp, const struct in6_addr *dst, u_long rt_mtu, | ip6_calcmtu(struct ifnet *ifp, const struct in6_addr *dst, u_long rt_mtu, | ||||
| u_long *mtup, int *alwaysfragp, u_int proto) | u_long *mtup, u_int proto) | ||||
| { | { | ||||
| u_long mtu = 0; | u_long mtu = 0; | ||||
| int alwaysfrag = 0; | |||||
| int error = 0; | |||||
| if (rt_mtu > 0) { | if (rt_mtu > 0) { | ||||
| u_int32_t ifmtu; | /* Skip the hostcache if the protocol handles PMTU changes. */ | ||||
| struct in_conninfo inc; | if (proto != IPPROTO_TCP && proto != IPPROTO_SCTP) { | ||||
| struct in_conninfo inc = { | |||||
| bzero(&inc, sizeof(inc)); | .inc_flags = INC_ISIPV6, | ||||
| inc.inc_flags |= INC_ISIPV6; | .inc6_faddr = *dst, | ||||
| inc.inc6_faddr = *dst; | }; | ||||
| ifmtu = IN6_LINKMTU(ifp); | |||||
| /* TCP is known to react to pmtu changes so skip hc */ | |||||
| if (proto != IPPROTO_TCP) | |||||
| mtu = tcp_hc_getmtu(&inc); | mtu = tcp_hc_getmtu(&inc); | ||||
tuexen: The same is true for SCTP. | |||||
| } | |||||
| if (mtu) | if (mtu) | ||||
| mtu = min(mtu, rt_mtu); | mtu = min(mtu, rt_mtu); | ||||
| else | else | ||||
| mtu = rt_mtu; | mtu = rt_mtu; | ||||
| } | |||||
| if (mtu == 0) | if (mtu == 0) | ||||
| mtu = ifmtu; | |||||
| else if (mtu < IPV6_MMTU) { | |||||
| /* | |||||
| * RFC2460 section 5, last paragraph: | |||||
| * if we record ICMPv6 too big message with | |||||
| * mtu < IPV6_MMTU, transmit packets sized IPV6_MMTU | |||||
| * or smaller, with framgent header attached. | |||||
| * (fragment header is needed regardless from the | |||||
| * packet size, for translators to identify packets) | |||||
| */ | |||||
| alwaysfrag = 1; | |||||
| mtu = IPV6_MMTU; | |||||
| } | |||||
| } else if (ifp) { | |||||
| mtu = IN6_LINKMTU(ifp); | mtu = IN6_LINKMTU(ifp); | ||||
| } else | |||||
| error = EHOSTUNREACH; /* XXX */ | |||||
| *mtup = mtu; | *mtup = mtu; | ||||
| if (alwaysfragp) | |||||
| *alwaysfragp = alwaysfrag; | |||||
| return (error); | |||||
| } | } | ||||
| /* | /* | ||||
| * IP6 socket option processing. | * IP6 socket option processing. | ||||
| */ | */ | ||||
| int | int | ||||
| ip6_ctloutput(struct socket *so, struct sockopt *sopt) | ip6_ctloutput(struct socket *so, struct sockopt *sopt) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 1,767 Lines • Show Last 20 Lines | |||||
The same is true for SCTP.