summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-02-13 02:06:53 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-13 02:06:53 +0000
commita161ee64a89e5dbfa9b52d3b5b088ae196a34072 (patch)
tree4a4382d8894836412aa87fe09032974f8477028a
parent4cd5dc5cb1014a78b610e9811cbc363a6128e38f (diff)
parent78dd1214439188f01a22301e3a80643ca7ff4a3f (diff)
downloadapf-a161ee64a89e5dbfa9b52d3b5b088ae196a34072.tar.gz
Merge "v5: remove unused checksum helper functions" into main am: 78dd121443
Original change: https://android-review.googlesource.com/c/platform/hardware/google/apf/+/2957573 Change-Id: I429af92ed56b52d3590ffce7682bca0f29ee9b47 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--apf_checksum.h74
-rw-r--r--apf_checksum_test.cc30
-rw-r--r--v5/apf_interpreter.c75
-rw-r--r--v5/apf_interpreter_source.c1
4 files changed, 3 insertions, 177 deletions
diff --git a/apf_checksum.h b/apf_checksum.h
index 057f7af..2c5468e 100644
--- a/apf_checksum.h
+++ b/apf_checksum.h
@@ -15,80 +15,6 @@ static u16 fix_udp_csum(u16 csum) {
return csum ? csum : 0xFFFF;
}
-#ifndef DO_NOT_NEED_OLD_CHECKSUM_CODE
-/**
- * Calculate the ipv4 header and tcp/udp layer 4 checksums.
- * (assumes IPv4 checksum field is set to partial sum of ipv4 options [likely 0])
- * (assumes L4 checksum field is set to L4 payload length on input)
- * Warning: TCP/UDP L4 checksum corrupts packet iff ipv4 options are present.
- * Warning: first IPV4_HLEN + TCP_HLEN == 40 bytes of ip4_pkt must be writable!
- * Returns 6-bit DSCP value [0..63], garbage on parse error.
- */
-static int calc_ipv4_csum(u8* const ip4_pkt, const s32 len) {
- store_be16(ip4_pkt + 10, calc_csum(0xFFFF, ip4_pkt, IPV4_HLEN));
-
- u8 proto = ip4_pkt[9];
- u16 csum = calc_csum(proto, ip4_pkt + 12, len - 12);
- switch (proto) {
- case IPPROTO_ICMP:
- /* Note: for this to work, the icmpv4 checksum field must be prefilled
- * with non-zero negative sum of proto (1) and src/dst ips, ie:
- * 5 * 0xFFFF - 1 - (src >> 16) - (src & 0xFFFF) - (dst >> 16) - (dst & 0xFFFF)
- */
- store_be16(ip4_pkt + IPV4_HLEN + 2, csum);
- break;
- case IPPROTO_TCP:
- store_be16(ip4_pkt + IPV4_HLEN + 16, csum);
- break;
- case IPPROTO_UDP:
- store_be16(ip4_pkt + IPV4_HLEN + 6, fix_udp_csum(csum));
- break;
- }
- return ip4_pkt[1] >> 2; /* DSCP */
-}
-
-/**
- * Calculate the ipv6 icmp6/tcp/udp layer 4 checksums.
- * (assumes L4 checksum field is set to L4 payload length on input)
- * Warning: first IPV6_HLEN + TCP_HLEN == 60 bytes of ip6_pkt must be writable!
- * Returns 6-bit DSCP value [0..63], garbage on parse error.
- */
-static int calc_ipv6_csum(u8* const ip6_pkt, const s32 len) {
- u8 proto = ip6_pkt[6];
- u16 csum = calc_csum(proto, ip6_pkt + 8, len - 8);
- switch (proto) {
- case IPPROTO_ICMPV6:
- store_be16(ip6_pkt + IPV6_HLEN + 2, csum);
- break;
- case IPPROTO_TCP:
- store_be16(ip6_pkt + IPV6_HLEN + 16, csum);
- break;
- case IPPROTO_UDP:
- store_be16(ip6_pkt + IPV6_HLEN + 6, fix_udp_csum(csum));
- break;
- }
- return (read_be16(ip6_pkt) >> 6) & 0x3F; /* DSCP */
-}
-
-/**
- * Calculate and store packet checksums and return dscp.
- *
- * @param pkt - pointer to the start of the ethernet header of the packet.
- * WARNING: first ETHER_HLEN + max(IPV{4,6}_HLEN) + TCP_HLEN = 74 bytes
- * of buffer pointed to my 'pkt' pointer *MUST* be writable.
- * @param len - length of the packet.
- *
- * @return 6-bit DSCP value [0..63], garbage on parse error.
- */
-int calculate_checksum_and_return_dscp(u8* const pkt, const s32 len) {
- switch (read_be16(pkt + 12)) { /* ethertype */
- case ETH_P_IP: return calc_ipv4_csum(pkt + ETH_HLEN, len - ETH_HLEN);
- case ETH_P_IPV6: return calc_ipv6_csum(pkt + ETH_HLEN, len - ETH_HLEN);
- default: return 0;
- }
-}
-#endif
-
/**
* Calculate and store packet checksums and return dscp.
*
diff --git a/apf_checksum_test.cc b/apf_checksum_test.cc
index 78c87cb..9fe172d 100644
--- a/apf_checksum_test.cc
+++ b/apf_checksum_test.cc
@@ -50,21 +50,11 @@ TEST(ApfChecksumTest, CalcIPv4UDPChecksum) {
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x62, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00,
0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, 0xc0, 0xa8, 0x01, 0x09,
}};
- // Set the UDP checksum to UDP payload size
- ether_ipv4_udp_pkt.pkt.udphdr.check = htons(sizeof(ether_ipv4_udp_pkt) - IPV4_HLEN - ETH_HLEN);
- uint8_t dscp = calculate_checksum_and_return_dscp((uint8_t *)&ether_ipv4_udp_pkt, sizeof(ether_ipv4_udp_pkt));
- EXPECT_EQ(dscp, 1);
- // Verify IPv4 header checksum
- EXPECT_EQ(read_be16((uint8_t *)&ether_ipv4_udp_pkt.pkt.iphdr.check), 0x9535);
-
- // verify UDP checksum
- EXPECT_EQ(read_be16((uint8_t *)&ether_ipv4_udp_pkt.pkt.udphdr.check), 0xa73d);
-
// Reset IPv4 header checksum to 0
ether_ipv4_udp_pkt.pkt.iphdr.check = 0;
// Set the UDP checksum to UDP payload size
ether_ipv4_udp_pkt.pkt.udphdr.check = htons(sizeof(ether_ipv4_udp_pkt) - IPV4_HLEN - ETH_HLEN);
- dscp = csum_and_return_dscp((uint8_t *)&ether_ipv4_udp_pkt, sizeof(ether_ipv4_udp_pkt),
+ uint8_t dscp = csum_and_return_dscp((uint8_t *)&ether_ipv4_udp_pkt, sizeof(ether_ipv4_udp_pkt),
ETH_HLEN /* ip_ofs */, IPPROTO_UDP /* partial_csum */,
ETH_HLEN + offsetof(iphdr, saddr) /* csum_start */,
ETH_HLEN + IPV4_HLEN + offsetof(udphdr, check) /* csum_ofs */,
@@ -105,14 +95,7 @@ TEST(ApfChecksumTest, CalcIPv6UDPChecksum) {
}};
// Set the UDP checksum to UDP payload size
ether_ipv6_udp_pkt.pkt.udphdr.check = htons(sizeof(ether_ipv6_udp_pkt) - IPV6_HLEN - ETH_HLEN);
- uint8_t dscp = calculate_checksum_and_return_dscp((uint8_t *)&ether_ipv6_udp_pkt, sizeof(ether_ipv6_udp_pkt));
- EXPECT_EQ(dscp, 6);
- // verify UDP checksum
- EXPECT_EQ(read_be16((uint8_t *)&ether_ipv6_udp_pkt.pkt.udphdr.check), 0x1cbd);
-
- // Set the UDP checksum to UDP payload size
- ether_ipv6_udp_pkt.pkt.udphdr.check = htons(sizeof(ether_ipv6_udp_pkt) - IPV6_HLEN - ETH_HLEN);
- dscp = csum_and_return_dscp((uint8_t *)&ether_ipv6_udp_pkt, sizeof(ether_ipv6_udp_pkt),
+ uint8_t dscp = csum_and_return_dscp((uint8_t *)&ether_ipv6_udp_pkt, sizeof(ether_ipv6_udp_pkt),
ETH_HLEN /* ip_ofs */, IPPROTO_UDP /* partial_csum */,
ETH_HLEN + offsetof(ipv6hdr, saddr) /* csum_start */,
ETH_HLEN + IPV6_HLEN + offsetof(udphdr, check) /* csum_ofs */,
@@ -150,14 +133,7 @@ TEST(ApfChecksumTest, CalcICMPv6Checksum) {
}};
// Set the ICMPv6 checksum to ICMPv6 payload size
ether_ipv6_icmp6_pkt.pkt.icmp6hdr.icmp6_cksum = htons(sizeof(ether_ipv6_icmp6_pkt) - IPV6_HLEN - ETH_HLEN);
- uint8_t dscp = calculate_checksum_and_return_dscp((uint8_t *)&ether_ipv6_icmp6_pkt, sizeof(ether_ipv6_icmp6_pkt));
- EXPECT_EQ(dscp, 6);
- // verify layer 4 checksum
- EXPECT_EQ(read_be16((uint8_t *)&ether_ipv6_icmp6_pkt.pkt.icmp6hdr.icmp6_cksum), 0x8a09);
-
- // Set the ICMPv6 checksum to ICMPv6 payload size
- ether_ipv6_icmp6_pkt.pkt.icmp6hdr.icmp6_cksum = htons(sizeof(ether_ipv6_icmp6_pkt) - IPV6_HLEN - ETH_HLEN);
- dscp = csum_and_return_dscp((uint8_t *)&ether_ipv6_icmp6_pkt, sizeof(ether_ipv6_icmp6_pkt),
+ uint8_t dscp = csum_and_return_dscp((uint8_t *)&ether_ipv6_icmp6_pkt, sizeof(ether_ipv6_icmp6_pkt),
ETH_HLEN /* ip_ofs */, IPPROTO_ICMPV6 /* partial_csum */,
ETH_HLEN + offsetof(ipv6hdr, saddr) /* csum_start */,
ETH_HLEN + IPV6_HLEN + offsetof(icmp6hdr, icmp6_cksum) /* csum_ofs */,
diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c
index b297be9..b546f2a 100644
--- a/v5/apf_interpreter.c
+++ b/v5/apf_interpreter.c
@@ -26,7 +26,6 @@
typedef enum { false, true } bool;
-#define DO_NOT_NEED_OLD_CHECKSUM_CODE
/* Begin include of apf_defs.h */
typedef int8_t s8;
typedef int16_t s16;
@@ -496,80 +495,6 @@ static u16 fix_udp_csum(u16 csum) {
return csum ? csum : 0xFFFF;
}
-#ifndef DO_NOT_NEED_OLD_CHECKSUM_CODE
-/**
- * Calculate the ipv4 header and tcp/udp layer 4 checksums.
- * (assumes IPv4 checksum field is set to partial sum of ipv4 options [likely 0])
- * (assumes L4 checksum field is set to L4 payload length on input)
- * Warning: TCP/UDP L4 checksum corrupts packet iff ipv4 options are present.
- * Warning: first IPV4_HLEN + TCP_HLEN == 40 bytes of ip4_pkt must be writable!
- * Returns 6-bit DSCP value [0..63], garbage on parse error.
- */
-static int calc_ipv4_csum(u8* const ip4_pkt, const s32 len) {
- store_be16(ip4_pkt + 10, calc_csum(0xFFFF, ip4_pkt, IPV4_HLEN));
-
- u8 proto = ip4_pkt[9];
- u16 csum = calc_csum(proto, ip4_pkt + 12, len - 12);
- switch (proto) {
- case IPPROTO_ICMP:
- /* Note: for this to work, the icmpv4 checksum field must be prefilled
- * with non-zero negative sum of proto (1) and src/dst ips, ie:
- * 5 * 0xFFFF - 1 - (src >> 16) - (src & 0xFFFF) - (dst >> 16) - (dst & 0xFFFF)
- */
- store_be16(ip4_pkt + IPV4_HLEN + 2, csum);
- break;
- case IPPROTO_TCP:
- store_be16(ip4_pkt + IPV4_HLEN + 16, csum);
- break;
- case IPPROTO_UDP:
- store_be16(ip4_pkt + IPV4_HLEN + 6, fix_udp_csum(csum));
- break;
- }
- return ip4_pkt[1] >> 2; /* DSCP */
-}
-
-/**
- * Calculate the ipv6 icmp6/tcp/udp layer 4 checksums.
- * (assumes L4 checksum field is set to L4 payload length on input)
- * Warning: first IPV6_HLEN + TCP_HLEN == 60 bytes of ip6_pkt must be writable!
- * Returns 6-bit DSCP value [0..63], garbage on parse error.
- */
-static int calc_ipv6_csum(u8* const ip6_pkt, const s32 len) {
- u8 proto = ip6_pkt[6];
- u16 csum = calc_csum(proto, ip6_pkt + 8, len - 8);
- switch (proto) {
- case IPPROTO_ICMPV6:
- store_be16(ip6_pkt + IPV6_HLEN + 2, csum);
- break;
- case IPPROTO_TCP:
- store_be16(ip6_pkt + IPV6_HLEN + 16, csum);
- break;
- case IPPROTO_UDP:
- store_be16(ip6_pkt + IPV6_HLEN + 6, fix_udp_csum(csum));
- break;
- }
- return (read_be16(ip6_pkt) >> 6) & 0x3F; /* DSCP */
-}
-
-/**
- * Calculate and store packet checksums and return dscp.
- *
- * @param pkt - pointer to the start of the ethernet header of the packet.
- * WARNING: first ETHER_HLEN + max(IPV{4,6}_HLEN) + TCP_HLEN = 74 bytes
- * of buffer pointed to my 'pkt' pointer *MUST* be writable.
- * @param len - length of the packet.
- *
- * @return 6-bit DSCP value [0..63], garbage on parse error.
- */
-int calculate_checksum_and_return_dscp(u8* const pkt, const s32 len) {
- switch (read_be16(pkt + 12)) { /* ethertype */
- case ETH_P_IP: return calc_ipv4_csum(pkt + ETH_HLEN, len - ETH_HLEN);
- case ETH_P_IPV6: return calc_ipv6_csum(pkt + ETH_HLEN, len - ETH_HLEN);
- default: return 0;
- }
-}
-#endif
-
/**
* Calculate and store packet checksums and return dscp.
*
diff --git a/v5/apf_interpreter_source.c b/v5/apf_interpreter_source.c
index f120b1f..810e543 100644
--- a/v5/apf_interpreter_source.c
+++ b/v5/apf_interpreter_source.c
@@ -26,7 +26,6 @@
typedef enum { false, true } bool;
-#define DO_NOT_NEED_OLD_CHECKSUM_CODE
#include "apf_defs.h"
#include "apf.h"
#include "apf_utils.h"