[RFC PATCHv2 13/13] xdp: early drop ipv6 packet.


William Tu
 

If not using ipv6, drop it in XDP.

Signed-off-by: William Tu <u9012063@...>
---
bpf/xdp.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/bpf/xdp.h b/bpf/xdp.h
index 2d2102a6ba28..e71b268370c6 100644
--- a/bpf/xdp.h
+++ b/bpf/xdp.h
@@ -23,8 +23,26 @@ __section("xdp")
static int xdp_ingress(struct xdp_md *ctx OVS_UNUSED)
{
/* TODO: see p4c-xdp project */
+#ifdef BPF_ENABLE_IPV6
printt("return XDP_PASS\n");
return XDP_PASS;
+#else
+ /* Early drop ipv6 */
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ struct ethhdr *eth = data;
+ __u16 h_proto;
+
+ if ((char *)eth + 14 > (char *)data_end)
+ return XDP_DROP;
+
+ h_proto = eth->h_proto;
+
+ if (h_proto == bpf_htons(ETH_P_IPV6)) {
+ printt("drop ipv6\n");
+ return XDP_DROP;
+ }
+#endif
}

__section("af_xdp")
--
2.7.4

Join iovisor-dev@lists.iovisor.org to automatically receive all group messages.