Skip to content

Commit 6580714

Browse files
jschwinger233pchaigno
authored andcommitted
bpf: Remove ICMPv6 NS Responder on bpf_host
This commit removes the ICMPv6 NS responder from from-netdev, to-netdev, and from-host. Let me explain why this removal won't break anything. First we need to know NS responder handles packets targeting local router or one of the local endpoints, and here is the responding steps in details: 1. if NS is targeting the local router; 2. or if NS is targeting a local endpoint; 3. transform the packet into an ICMPv6 NA with cilium_host's MAC address as the response; 4. modify the packet L3, set the source IPv6 to the router IPv6; 5. redirect_self; From-netdev is on the native devices handling ingress traffic from other nodes. The ingress traffic should be underlay traffic that doesn't expose overlay addresses, like pod or router addresses. Therefore, NS traffic reaching from-netdev can only target native IPv6, and we don't need the responder to deal with that. To-netdev and from-host are in the same host network namespace, one is attached to native devices, and the other is on cilium_host. Prior to issue cilium#23445, we needed NS responder because no host device had that router IPv6. Since cilium#23445 has been resolved, now curling from host to a local pod or local router doesn't require bpf NS responder anymore. The removal of the responder on from-netdev also fixes a known issue cilium#14509, which is caused by forementioned step 4: NS responder sets responding packet's source IPv6 to router IPv6 even if the NS comes from a native device. Fixes: cilium#14509 Signed-off-by: Zhichuan Liang <gray.liang@isovalent.com>
1 parent 14fcc11 commit 6580714

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

bpf/bpf_host.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ handle_ipv6(struct __ctx_buff *ctx, __u32 secctx __maybe_unused,
150150
struct ct_buffer6 __maybe_unused ct_buffer = {};
151151
void *data, *data_end;
152152
struct ipv6hdr *ip6;
153-
int ret, hdrlen;
153+
int __maybe_unused ret;
154+
int hdrlen;
154155
__u8 nexthdr;
155156
#ifdef ENABLE_HOST_FIREWALL
156157
bool need_hostfw = false;
@@ -164,13 +165,15 @@ handle_ipv6(struct __ctx_buff *ctx, __u32 secctx __maybe_unused,
164165
if (hdrlen < 0)
165166
return hdrlen;
166167

168+
#ifdef ENABLE_HOST_FIREWALL
167169
if (likely(nexthdr == IPPROTO_ICMPV6)) {
168170
ret = icmp6_host_handle(ctx);
169171
if (ret == SKIP_HOST_FIREWALL)
170172
goto skip_host_firewall;
171173
if (IS_ERR(ret))
172174
return ret;
173175
}
176+
#endif /* ENABLE_HOST_FIREWALL */
174177

175178
#ifdef ENABLE_NODEPORT
176179
if (!from_host) {
@@ -214,8 +217,8 @@ handle_ipv6(struct __ctx_buff *ctx, __u32 secctx __maybe_unused,
214217
}
215218
#endif /* ENABLE_HOST_FIREWALL */
216219

217-
skip_host_firewall:
218220
#ifdef ENABLE_HOST_FIREWALL
221+
skip_host_firewall:
219222
ctx_store_meta(ctx, CB_FROM_HOST,
220223
(need_hostfw ? FROM_HOST_FLAG_NEED_HOSTFW : 0));
221224
#endif /* ENABLE_HOST_FIREWALL */
@@ -476,13 +479,15 @@ handle_to_netdev_ipv6(struct __ctx_buff *ctx, struct trace_ctx *trace, __s8 *ext
476479
if (hdrlen < 0)
477480
return hdrlen;
478481

482+
#ifdef ENABLE_HOST_FIREWALL
479483
if (likely(nexthdr == IPPROTO_ICMPV6)) {
480484
ret = icmp6_host_handle(ctx);
481485
if (ret == SKIP_HOST_FIREWALL)
482486
return CTX_ACT_OK;
483487
if (IS_ERR(ret))
484488
return ret;
485489
}
490+
#endif /* ENABLE_HOST_FIREWALL */
486491

487492
if ((ctx->mark & MARK_MAGIC_HOST_MASK) == MARK_MAGIC_HOST)
488493
src_id = HOST_ID;

bpf/lib/icmp6.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,7 @@ icmp6_host_handle(struct __ctx_buff *ctx __maybe_unused)
397397
__u8 type __maybe_unused;
398398

399399
type = icmp6_load_type(ctx, ETH_HLEN);
400-
if (type == ICMP6_NS_MSG_TYPE)
401-
return icmp6_handle_ns(ctx, ETH_HLEN, METRIC_INGRESS);
402400

403-
#ifdef ENABLE_HOST_FIREWALL
404401
/* When the host firewall is enabled, we drop and allow ICMPv6 messages
405402
* according to RFC4890, except for echo request and reply messages which
406403
* are handled by host policies and can be dropped.
@@ -420,7 +417,7 @@ icmp6_host_handle(struct __ctx_buff *ctx __maybe_unused)
420417
* | ICMPv6-mult-list-done | CTX_ACT_OK | 132 |
421418
* | ICMPv6-router-solici | CTX_ACT_OK | 133 |
422419
* | ICMPv6-router-advert | CTX_ACT_OK | 134 |
423-
* | ICMPv6-neighbor-solicit | icmp6_handle_ns | 135 |
420+
* | ICMPv6-neighbor-solicit | CTX_ACT_OK | 135 |
424421
* | ICMPv6-neighbor-advert | CTX_ACT_OK | 136 |
425422
* | ICMPv6-redirect-message | CTX_ACT_DROP | 137 |
426423
* | ICMPv6-router-renumber | CTX_ACT_OK | 138 |
@@ -448,6 +445,9 @@ icmp6_host_handle(struct __ctx_buff *ctx __maybe_unused)
448445
* | ICMPv6-unassigned | CTX_ACT_DROP | |
449446
*/
450447

448+
if (type == ICMP6_NS_MSG_TYPE)
449+
return CTX_ACT_OK;
450+
451451
if (type == ICMP6_ECHO_REQUEST_MSG_TYPE || type == ICMP6_ECHO_REPLY_MSG_TYPE)
452452
/* Decision is deferred to the host policies. */
453453
return CTX_ACT_OK;
@@ -459,9 +459,6 @@ icmp6_host_handle(struct __ctx_buff *ctx __maybe_unused)
459459
(ICMP6_MULT_RA_MSG_TYPE <= type && type <= ICMP6_MULT_RT_MSG_TYPE))
460460
return SKIP_HOST_FIREWALL;
461461
return DROP_FORBIDDEN_ICMP6;
462-
#else
463-
return CTX_ACT_OK;
464-
#endif /* ENABLE_HOST_FIREWALL */
465462
}
466463

467464
#endif

0 commit comments

Comments
 (0)