Skip to content

Commit

Permalink
bpf: clean up ctx_adjust_hroom_flags() variants
Browse files Browse the repository at this point in the history
We have two implementations (for DSR and SRv6) that do the same thing.
Consolidate them.

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
  • Loading branch information
julianwiedmann committed Mar 7, 2023
1 parent 001cbea commit 3ee7d75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
9 changes: 9 additions & 0 deletions bpf/lib/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,15 @@ static __always_inline int redirect_ep(struct __ctx_buff *ctx __maybe_unused,
}
}

static __always_inline __u64 ctx_adjust_hroom_flags(void)
{
#ifdef HAVE_CSUM_LEVEL
return BPF_F_ADJ_ROOM_NO_CSUM_RESET;
#else
return 0;
#endif
}

struct lpm_v4_key {
struct bpf_lpm_trie_key lpm;
__u8 addr[4];
Expand Down
9 changes: 0 additions & 9 deletions bpf/lib/egress_policies.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,6 @@ is_srv6_packet(const struct ipv6hdr *ip6)
}

# ifndef SKIP_SRV6_HANDLING
static __always_inline __u64 ctx_adjust_hroom_flags(void)
{
#ifdef HAVE_CSUM_LEVEL
return BPF_F_ADJ_ROOM_NO_CSUM_RESET;
#else
return 0;
#endif
}

static __always_inline int
srv6_encapsulation(struct __ctx_buff *ctx, int growth, __u16 new_payload_len,
__u8 nexthdr, union v6addr *saddr, struct in6_addr *sid)
Expand Down
21 changes: 6 additions & 15 deletions bpf/lib/nodeport.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,6 @@ bpf_skip_recirculation(const struct __ctx_buff *ctx __maybe_unused)
#endif
}

static __always_inline __u64 ctx_adjust_hroom_dsr_flags(void)
{
#ifdef HAVE_CSUM_LEVEL
return BPF_F_ADJ_ROOM_NO_CSUM_RESET;
#else
return 0;
#endif
}

static __always_inline bool dsr_fail_needs_reply(int code __maybe_unused)
{
#ifdef ENABLE_DSR_ICMP_ERRORS
Expand Down Expand Up @@ -181,7 +172,7 @@ static __always_inline int dsr_set_ipip6(struct __ctx_buff *ctx,
rss_gen_src6(&saddr, (union v6addr *)&ip6->saddr, l4_hint);

if (ctx_adjust_hroom(ctx, sizeof(*ip6), BPF_ADJ_ROOM_NET,
ctx_adjust_hroom_dsr_flags()))
ctx_adjust_hroom_flags()))
return DROP_INVALID;
if (ctx_store_bytes(ctx, l3_off + offsetof(struct ipv6hdr, payload_len),
&tp_new.payload_len, 4, 0) < 0)
Expand Down Expand Up @@ -240,7 +231,7 @@ static __always_inline int dsr_set_ext6(struct __ctx_buff *ctx,
opt.port = svc_port;

if (ctx_adjust_hroom(ctx, sizeof(opt), BPF_ADJ_ROOM_NET,
ctx_adjust_hroom_dsr_flags()))
ctx_adjust_hroom_flags()))
return DROP_INVALID;
if (ctx_store_bytes(ctx, ETH_HLEN + sizeof(*ip6), &opt,
sizeof(opt), 0) < 0)
Expand Down Expand Up @@ -435,7 +426,7 @@ static __always_inline int dsr_reply_icmp6(struct __ctx_buff *ctx,
goto drop_err;
if (ctx_adjust_hroom(ctx, sizeof(ip) + sizeof(icmp),
BPF_ADJ_ROOM_NET,
ctx_adjust_hroom_dsr_flags()) < 0)
ctx_adjust_hroom_flags()) < 0)
goto drop_err;

if (eth_store_daddr(ctx, smac.addr, 0) < 0)
Expand Down Expand Up @@ -1338,7 +1329,7 @@ static __always_inline int dsr_set_ipip4(struct __ctx_buff *ctx,
}

if (ctx_adjust_hroom(ctx, sizeof(*ip4), BPF_ADJ_ROOM_NET,
ctx_adjust_hroom_dsr_flags()))
ctx_adjust_hroom_flags()))
return DROP_INVALID;
sum = csum_diff(&tp_old, 16, &tp_new, 16, 0);
if (ctx_store_bytes(ctx, l3_off + offsetof(struct iphdr, tot_len),
Expand Down Expand Up @@ -1401,7 +1392,7 @@ static __always_inline int dsr_set_opt4(struct __ctx_buff *ctx,
sum = csum_diff(NULL, 0, &opt, sizeof(opt), sum);

if (ctx_adjust_hroom(ctx, sizeof(opt), BPF_ADJ_ROOM_NET,
ctx_adjust_hroom_dsr_flags()))
ctx_adjust_hroom_flags()))
return DROP_INVALID;

if (ctx_store_bytes(ctx, ETH_HLEN + sizeof(*ip4),
Expand Down Expand Up @@ -1581,7 +1572,7 @@ static __always_inline int dsr_reply_icmp4(struct __ctx_buff *ctx,
goto drop_err;
if (ctx_adjust_hroom(ctx, sizeof(ip) + sizeof(icmp),
BPF_ADJ_ROOM_NET,
ctx_adjust_hroom_dsr_flags()) < 0)
ctx_adjust_hroom_flags()) < 0)
goto drop_err;

if (eth_store_daddr(ctx, smac.addr, 0) < 0)
Expand Down

0 comments on commit 3ee7d75

Please sign in to comment.