Merge "offload.c - adjust bytes for l2 header" am: 58d800c94d am: ed21dcf98a
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2370730 Change-Id: I8ea6feddcda1fca40435e9c87ed4927bbdd1d2f3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -80,8 +80,8 @@ public class MtsEthernetTetheringTest extends EthernetTetheringTestBase {
|
|||||||
// Per RX UDP packet size: iphdr (20) + udphdr (8) + payload (2) = 30 bytes.
|
// Per RX UDP packet size: iphdr (20) + udphdr (8) + payload (2) = 30 bytes.
|
||||||
private static final int RX_UDP_PACKET_SIZE = 30;
|
private static final int RX_UDP_PACKET_SIZE = 30;
|
||||||
private static final int RX_UDP_PACKET_COUNT = 456;
|
private static final int RX_UDP_PACKET_COUNT = 456;
|
||||||
// Per TX UDP packet size: ethhdr (14) + iphdr (20) + udphdr (8) + payload (2) = 44 bytes.
|
// Per TX UDP packet size: iphdr (20) + udphdr (8) + payload (2) = 30 bytes.
|
||||||
private static final int TX_UDP_PACKET_SIZE = 44;
|
private static final int TX_UDP_PACKET_SIZE = 30;
|
||||||
private static final int TX_UDP_PACKET_COUNT = 123;
|
private static final int TX_UDP_PACKET_COUNT = 123;
|
||||||
|
|
||||||
private static final String DUMPSYS_TETHERING_RAWMAP_ARG = "bpfRawMap";
|
private static final String DUMPSYS_TETHERING_RAWMAP_ARG = "bpfRawMap";
|
||||||
|
|||||||
@@ -232,13 +232,13 @@ static inline __always_inline int do_forward6(struct __sk_buff* skb, const bool
|
|||||||
// This would require a much newer kernel with newer ebpf accessors.
|
// This would require a much newer kernel with newer ebpf accessors.
|
||||||
// (This is also blindly assuming 12 bytes of tcp timestamp option in tcp header)
|
// (This is also blindly assuming 12 bytes of tcp timestamp option in tcp header)
|
||||||
uint64_t packets = 1;
|
uint64_t packets = 1;
|
||||||
uint64_t bytes = skb->len;
|
uint64_t L3_bytes = skb->len - l2_header_size;
|
||||||
if (bytes > v->pmtu) {
|
if (L3_bytes > v->pmtu) {
|
||||||
const int tcp_overhead = sizeof(struct ipv6hdr) + sizeof(struct tcphdr) + 12;
|
const int tcp6_overhead = sizeof(struct ipv6hdr) + sizeof(struct tcphdr) + 12;
|
||||||
const int mss = v->pmtu - tcp_overhead;
|
const int mss = v->pmtu - tcp6_overhead;
|
||||||
const uint64_t payload = bytes - tcp_overhead;
|
const uint64_t payload = L3_bytes - tcp6_overhead;
|
||||||
packets = (payload + mss - 1) / mss;
|
packets = (payload + mss - 1) / mss;
|
||||||
bytes = tcp_overhead * packets + payload;
|
L3_bytes = tcp6_overhead * packets + payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we past the limit? If so, then abort...
|
// Are we past the limit? If so, then abort...
|
||||||
@@ -247,7 +247,7 @@ static inline __always_inline int do_forward6(struct __sk_buff* skb, const bool
|
|||||||
// a packet we let the core stack deal with things.
|
// a packet we let the core stack deal with things.
|
||||||
// (The core stack needs to handle limits correctly anyway,
|
// (The core stack needs to handle limits correctly anyway,
|
||||||
// since we don't offload all traffic in both directions)
|
// since we don't offload all traffic in both directions)
|
||||||
if (stat_v->rxBytes + stat_v->txBytes + bytes > *limit_v) TC_PUNT(LIMIT_REACHED);
|
if (stat_v->rxBytes + stat_v->txBytes + L3_bytes > *limit_v) TC_PUNT(LIMIT_REACHED);
|
||||||
|
|
||||||
if (!is_ethernet) {
|
if (!is_ethernet) {
|
||||||
// Try to inject an ethernet header, and simply return if we fail.
|
// Try to inject an ethernet header, and simply return if we fail.
|
||||||
@@ -287,7 +287,7 @@ static inline __always_inline int do_forward6(struct __sk_buff* skb, const bool
|
|||||||
bpf_csum_update(skb, 0xFFFF - ntohs(old_hl) + ntohs(new_hl));
|
bpf_csum_update(skb, 0xFFFF - ntohs(old_hl) + ntohs(new_hl));
|
||||||
|
|
||||||
__sync_fetch_and_add(downstream ? &stat_v->rxPackets : &stat_v->txPackets, packets);
|
__sync_fetch_and_add(downstream ? &stat_v->rxPackets : &stat_v->txPackets, packets);
|
||||||
__sync_fetch_and_add(downstream ? &stat_v->rxBytes : &stat_v->txBytes, bytes);
|
__sync_fetch_and_add(downstream ? &stat_v->rxBytes : &stat_v->txBytes, L3_bytes);
|
||||||
|
|
||||||
// Overwrite any mac header with the new one
|
// Overwrite any mac header with the new one
|
||||||
// For a rawip tx interface it will simply be a bunch of zeroes and later stripped.
|
// For a rawip tx interface it will simply be a bunch of zeroes and later stripped.
|
||||||
@@ -449,13 +449,13 @@ static inline __always_inline int do_forward4_bottom(struct __sk_buff* skb,
|
|||||||
// This would require a much newer kernel with newer ebpf accessors.
|
// This would require a much newer kernel with newer ebpf accessors.
|
||||||
// (This is also blindly assuming 12 bytes of tcp timestamp option in tcp header)
|
// (This is also blindly assuming 12 bytes of tcp timestamp option in tcp header)
|
||||||
uint64_t packets = 1;
|
uint64_t packets = 1;
|
||||||
uint64_t bytes = skb->len;
|
uint64_t L3_bytes = skb->len - l2_header_size;
|
||||||
if (bytes > v->pmtu) {
|
if (L3_bytes > v->pmtu) {
|
||||||
const int tcp_overhead = sizeof(struct iphdr) + sizeof(struct tcphdr) + 12;
|
const int tcp4_overhead = sizeof(struct iphdr) + sizeof(struct tcphdr) + 12;
|
||||||
const int mss = v->pmtu - tcp_overhead;
|
const int mss = v->pmtu - tcp4_overhead;
|
||||||
const uint64_t payload = bytes - tcp_overhead;
|
const uint64_t payload = L3_bytes - tcp4_overhead;
|
||||||
packets = (payload + mss - 1) / mss;
|
packets = (payload + mss - 1) / mss;
|
||||||
bytes = tcp_overhead * packets + payload;
|
L3_bytes = tcp4_overhead * packets + payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we past the limit? If so, then abort...
|
// Are we past the limit? If so, then abort...
|
||||||
@@ -464,7 +464,7 @@ static inline __always_inline int do_forward4_bottom(struct __sk_buff* skb,
|
|||||||
// a packet we let the core stack deal with things.
|
// a packet we let the core stack deal with things.
|
||||||
// (The core stack needs to handle limits correctly anyway,
|
// (The core stack needs to handle limits correctly anyway,
|
||||||
// since we don't offload all traffic in both directions)
|
// since we don't offload all traffic in both directions)
|
||||||
if (stat_v->rxBytes + stat_v->txBytes + bytes > *limit_v) TC_PUNT(LIMIT_REACHED);
|
if (stat_v->rxBytes + stat_v->txBytes + L3_bytes > *limit_v) TC_PUNT(LIMIT_REACHED);
|
||||||
|
|
||||||
if (!is_ethernet) {
|
if (!is_ethernet) {
|
||||||
// Try to inject an ethernet header, and simply return if we fail.
|
// Try to inject an ethernet header, and simply return if we fail.
|
||||||
@@ -540,7 +540,7 @@ static inline __always_inline int do_forward4_bottom(struct __sk_buff* skb,
|
|||||||
if (updatetime) v->last_used = bpf_ktime_get_boot_ns();
|
if (updatetime) v->last_used = bpf_ktime_get_boot_ns();
|
||||||
|
|
||||||
__sync_fetch_and_add(downstream ? &stat_v->rxPackets : &stat_v->txPackets, packets);
|
__sync_fetch_and_add(downstream ? &stat_v->rxPackets : &stat_v->txPackets, packets);
|
||||||
__sync_fetch_and_add(downstream ? &stat_v->rxBytes : &stat_v->txBytes, bytes);
|
__sync_fetch_and_add(downstream ? &stat_v->rxBytes : &stat_v->txBytes, L3_bytes);
|
||||||
|
|
||||||
// Redirect to forwarded interface.
|
// Redirect to forwarded interface.
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user