Commit b2936b4f authored by Alice Mikityanska's avatar Alice Mikityanska Committed by Jakub Kicinski
Browse files

net/ipv6: Introduce payload_len helpers



The next commits will transition away from using the hop-by-hop
extension header to encode packet length for BIG TCP. Add wrappers
around ip6->payload_len that return the actual value if it's non-zero,
and calculate it from skb->len if payload_len is set to zero (and a
symmetrical setter).

The new helpers are used wherever the surrounding code supports the
hop-by-hop jumbo header for BIG TCP IPv6, or the corresponding IPv4 code
uses skb_ip_totlen (e.g., in include/net/netfilter/nf_tables_ipv6.h).

No behavioral change in this commit.

Signed-off-by: default avatarAlice Mikityanska <alice@isovalent.com>
Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260205133925.526371-2-alice.kernel@fastmail.im


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 5826eec8
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -126,6 +126,28 @@ static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
	       skb_network_header_len(skb);
}

static inline unsigned int
ipv6_payload_len(const struct sk_buff *skb, const struct ipv6hdr *ip6)
{
	u32 len = ntohs(ip6->payload_len);

	return (len || !skb_is_gso(skb) || !skb_is_gso_tcp(skb)) ?
		len :
		skb->len - skb_network_offset(skb) - sizeof(struct ipv6hdr);
}

static inline unsigned int skb_ipv6_payload_len(const struct sk_buff *skb)
{
	return ipv6_payload_len(skb, ipv6_hdr(skb));
}

#define IPV6_MAXPLEN		65535

static inline void ipv6_set_payload_len(struct ipv6hdr *ip6, unsigned int len)
{
	ip6->payload_len = len <= IPV6_MAXPLEN ? htons(len) : 0;
}

/* 
   This structure contains results of exthdrs parsing
   as offsets from skb->nh.
+0 −2
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ struct ip_tunnel_info;

#define SIN6_LEN_RFC2133	24

#define IPV6_MAXPLEN		65535

/*
 *	NextHeader field of IPv6 header
 */
+2 −2
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
	if (ip6h->version != 6)
		return -1;

	pkt_len = ntohs(ip6h->payload_len);
	pkt_len = ipv6_payload_len(pkt->skb, ip6h);
	skb_len = pkt->skb->len - skb_network_offset(pkt->skb);
	if (pkt_len + sizeof(*ip6h) > skb_len)
		return -1;
@@ -86,7 +86,7 @@ static inline int nft_set_pktinfo_ipv6_ingress(struct nft_pktinfo *pkt)
	if (ip6h->version != 6)
		goto inhdr_error;

	pkt_len = ntohs(ip6h->payload_len);
	pkt_len = ipv6_payload_len(pkt->skb, ip6h);
	if (pkt_len + sizeof(*ip6h) > pkt->skb->len) {
		idev = __in6_dev_get(nft_in(pkt));
		__IP6_INC_STATS(nft_net(pkt), idev, IPSTATS_MIB_INTRUNCATEDPKTS);
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ int br_validate_ipv6(struct net *net, struct sk_buff *skb)
	if (hdr->version != 6)
		goto inhdr_error;

	pkt_len = ntohs(hdr->payload_len);
	pkt_len = ipv6_payload_len(skb, hdr);
	if (hdr->nexthdr == NEXTHDR_HOP && nf_ip6_check_hbh_len(skb, &pkt_len))
		goto drop;

+2 −2
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ static int nf_ct_br_ipv6_check(const struct sk_buff *skb)
	if (hdr->version != 6)
		return -1;

	len = ntohs(hdr->payload_len) + sizeof(struct ipv6hdr) + nhoff;
	len = ipv6_payload_len(skb, hdr) + sizeof(struct ipv6hdr) + nhoff;
	if (skb->len < len)
		return -1;

@@ -269,7 +269,7 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb,
		if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
			return NF_ACCEPT;

		len = sizeof(struct ipv6hdr) + ntohs(ipv6_hdr(skb)->payload_len);
		len = sizeof(struct ipv6hdr) + skb_ipv6_payload_len(skb);
		if (pskb_trim_rcsum(skb, len))
			return NF_ACCEPT;

Loading