]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: document pseudo-header checksum helpers
authorAlexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
Wed, 20 Nov 2024 07:43:20 +0000 (08:43 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 2 Dec 2024 16:41:16 +0000 (08:41 -0800)
network_helpers.h provides helpers to compute checksum for pseudo
headers but no helpers to compute the global checksums.

Before adding those, clarify csum_tcpudp_magic and csum_ipv6_magic
purpose by adding some documentation.

Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://lore.kernel.org/r/20241120-flow_dissector-v3-10-45b46494f937@bootlin.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/network_helpers.h

index 0b2ed90c763fa5a30af348c6faf3d5b6f504aafb..00d6e7d52545cae1cda92920f7e8c70e04de2401 100644 (file)
@@ -129,6 +129,21 @@ static inline __sum16 build_ip_csum(struct iphdr *iph)
        return csum_fold(sum);
 }
 
+/**
+ * csum_tcpudp_magic - compute IP pseudo-header checksum
+ *
+ * Compute the IPv4 pseudo header checksum. The helper can take a
+ * accumulated sum from the transport layer to accumulate it and directly
+ * return the transport layer
+ *
+ * @saddr: IP source address
+ * @daddr: IP dest address
+ * @len: IP data size
+ * @proto: transport layer protocol
+ * @csum: The accumulated partial sum to add to the computation
+ *
+ * Returns the folded sum
+ */
 static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
                                        __u32 len, __u8 proto,
                                        __wsum csum)
@@ -144,6 +159,21 @@ static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
        return csum_fold((__u32)s);
 }
 
+/**
+ * csum_ipv6_magic - compute IPv6 pseudo-header checksum
+ *
+ * Compute the ipv6 pseudo header checksum. The helper can take a
+ * accumulated sum from the transport layer to accumulate it and directly
+ * return the transport layer
+ *
+ * @saddr: IPv6 source address
+ * @daddr: IPv6 dest address
+ * @len: IPv6 data size
+ * @proto: transport layer protocol
+ * @csum: The accumulated partial sum to add to the computation
+ *
+ * Returns the folded sum
+ */
 static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
                                      const struct in6_addr *daddr,
                                        __u32 len, __u8 proto,