From 824fb294ee6767626f7f670d844a02f86cc75b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Mon, 11 Apr 2022 23:29:46 -0700 Subject: [PATCH] rename try_make_readable() to try_make_writable() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In practice this function makes things readable and writable, so use a less confusing name. Test: TreeHugger, 'git grep try_make_readable' comes up empty Signed-off-by: Maciej Żenczykowski Change-Id: I32faad148cc5714cf0ec7246620376ed4dd3d6d2 --- bpf_progs/bpf_net_helpers.h | 5 +++-- bpf_progs/clatd.c | 4 ++-- bpf_progs/offload.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bpf_progs/bpf_net_helpers.h b/bpf_progs/bpf_net_helpers.h index c7985806fe..e382713693 100644 --- a/bpf_progs/bpf_net_helpers.h +++ b/bpf_progs/bpf_net_helpers.h @@ -65,8 +65,9 @@ static inline __always_inline __unused bool is_received_skb(struct __sk_buff* sk skb->pkt_type == PACKET_MULTICAST; } -// try to make the first 'len' header bytes readable via direct packet access -static inline __always_inline void try_make_readable(struct __sk_buff* skb, int len) { +// try to make the first 'len' header bytes readable/writable via direct packet access +// (note: AFAIK there is no way to ask for only direct packet read without also getting write) +static inline __always_inline void try_make_writable(struct __sk_buff* skb, int len) { if (len > skb->len) len = skb->len; if (skb->data_end - skb->data < len) bpf_skb_pull_data(skb, len); } diff --git a/bpf_progs/clatd.c b/bpf_progs/clatd.c index 8971f6b538..9a9d3373dc 100644 --- a/bpf_progs/clatd.c +++ b/bpf_progs/clatd.c @@ -57,7 +57,7 @@ static inline __always_inline int nat64(struct __sk_buff* skb, bool is_ethernet) // Not clear if this is actually necessary considering we use DPA (Direct Packet Access), // but we need to make sure we can read the IPv6 header reliably so that we can set // skb->mark = 0xDeadC1a7 for packets we fail to offload. - try_make_readable(skb, l2_header_size + sizeof(struct ipv6hdr)); + try_make_writable(skb, l2_header_size + sizeof(struct ipv6hdr)); void* data = (void*)(long)skb->data; const void* data_end = (void*)(long)skb->data_end; @@ -224,7 +224,7 @@ DEFINE_BPF_PROG("schedcls/egress4/clat_rawip", AID_ROOT, AID_SYSTEM, sched_cls_e if (skb->protocol != htons(ETH_P_IP)) return TC_ACT_PIPE; // Possibly not needed, but for consistency with nat64 up above - try_make_readable(skb, sizeof(struct iphdr)); + try_make_writable(skb, sizeof(struct iphdr)); void* data = (void*)(long)skb->data; const void* data_end = (void*)(long)skb->data_end; diff --git a/bpf_progs/offload.c b/bpf_progs/offload.c index 977e918d67..92a774cefe 100644 --- a/bpf_progs/offload.c +++ b/bpf_progs/offload.c @@ -122,7 +122,7 @@ static inline __always_inline int do_forward6(struct __sk_buff* skb, const bool // not trigger and thus we need to manually make sure we can read packet headers via DPA. // Note: this is a blind best effort pull, which may fail or pull less - this doesn't matter. // It has to be done early cause it will invalidate any skb->data/data_end derived pointers. - try_make_readable(skb, l2_header_size + IP6_HLEN + TCP_HLEN); + try_make_writable(skb, l2_header_size + IP6_HLEN + TCP_HLEN); void* data = (void*)(long)skb->data; const void* data_end = (void*)(long)skb->data_end; @@ -369,7 +369,7 @@ static inline __always_inline int do_forward4(struct __sk_buff* skb, const bool // not trigger and thus we need to manually make sure we can read packet headers via DPA. // Note: this is a blind best effort pull, which may fail or pull less - this doesn't matter. // It has to be done early cause it will invalidate any skb->data/data_end derived pointers. - try_make_readable(skb, l2_header_size + IP4_HLEN + TCP_HLEN); + try_make_writable(skb, l2_header_size + IP4_HLEN + TCP_HLEN); void* data = (void*)(long)skb->data; const void* data_end = (void*)(long)skb->data_end;