Skip to content

Commit 475a194

Browse files
bpf: host: optimize from-host's ICMPv6 path
The ICMPv6 handling in handle_ipv6() is only required for the HostFW or by from-netdev. Exclude it otherwise. This is a minor optimization for dc9dfd7 ("bpf: Re-introduce ICMPv6 NS responder on from-netdev"). Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
1 parent 2fda72e commit 475a194

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

bpf/bpf_host.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,26 @@ handle_ipv6(struct __ctx_buff *ctx, __u32 secctx __maybe_unused,
148148
#endif /* ENABLE_HOST_FIREWALL */
149149
void *data, *data_end;
150150
struct ipv6hdr *ip6;
151-
int ret, hdrlen;
152-
__u8 nexthdr;
151+
int ret;
153152

154153
if (!revalidate_data(ctx, &data, &data_end, &ip6))
155154
return DROP_INVALID;
156155

157-
nexthdr = ip6->nexthdr;
158-
hdrlen = ipv6_hdrlen(ctx, &nexthdr);
159-
if (hdrlen < 0)
160-
return hdrlen;
156+
if (is_defined(ENABLE_HOST_FIREWALL) || !from_host) {
157+
__u8 nexthdr = ip6->nexthdr;
158+
int hdrlen;
161159

162-
if (likely(nexthdr == IPPROTO_ICMPV6)) {
163-
ret = icmp6_host_handle(ctx, ETH_HLEN + hdrlen, ext_err, !from_host);
164-
if (ret == SKIP_HOST_FIREWALL)
165-
goto skip_host_firewall;
166-
if (IS_ERR(ret))
167-
return ret;
160+
hdrlen = ipv6_hdrlen(ctx, &nexthdr);
161+
if (hdrlen < 0)
162+
return hdrlen;
163+
164+
if (likely(nexthdr == IPPROTO_ICMPV6)) {
165+
ret = icmp6_host_handle(ctx, ETH_HLEN + hdrlen, ext_err, !from_host);
166+
if (ret == SKIP_HOST_FIREWALL)
167+
goto skip_host_firewall;
168+
if (IS_ERR(ret))
169+
return ret;
170+
}
168171
}
169172

170173
#ifdef ENABLE_NODEPORT

0 commit comments

Comments
 (0)