Skip to contentSkip to conversation

bpf: add BPF_LWT_ENCAP_IP option to bpf_lwt_push_encap

PATCH Applied Peter Oskolkov 4 participants 15 messages Feb 13, 2019 – Feb 14, 2019

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v11 cover bpf: add BPF_LWT_ENCAP_IP option to bpf_lwt_push_encap

This patchset implements BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap BPF helper. It enables BPF programs (specifically, BPF_PROG_TYPE_LWT_IN and BPF_PROG_TYPE_LWT_XMIT prog types) to add IP encapsulation headers to packets (e.g. IP/GRE, GUE, IPIP).

This is useful when thousands of different short-lived flows should be encapped, each with different and dynamically determined destination. Although lwtunnels can be used in some of these scenarios, the ability to dynamically generate encap headers adds more flexibility, e.g. when routing depends on the state of the host (reflected in global bpf maps).

V2 changes: added flowi-based route lookup, IPv6 encapping, and
encapping on ingress.

V3 changes: incorporated David Ahern's suggestions:
- added l3mdev check/oif (patch 2)
- sync bpf.h from include/uapi into tools/include/uapi
- selftest tweaks

V4 changes: moved route lookup/dst change from bpf_push_ip_encap
to when BPF_LWT_REROUTE is handled, as suggested by David Ahern.

V5 changes: added a check in lwt_xmit that skb->protocol stays the
same if the skb is to be passed back to the stack (ret == BPF_OK). Again, suggested by David Ahern.

V6 changes: abandoned.

V7 changes: added handling of GSO packets (patch 3 in the patchset added),
as suggested by BPF maintainers.

V8 changes:
- fixed build errors when LWT or IPV6 are not enabled;
- whitelisted TCP GSO instead of blacklisting SCTP and UDP GSO, as

     suggested by Willem de Bruijn;
   - added validation that pushed length cover needed headers when GRE/UDP
     encap is detected, as suggested by Willem de Bruijn;

- a couple of minor/stylistic tweaks/fixed typos.

V9 changes:
- fixed a kbuild test robot compiler warning;
- added ipv6_route_input to ipv6_stub (patch 4 in the patchset added), and IPv6 routing functions are now invoked via ipv6_stub, as suggested by David Ahern.

V10 changes:
- removed unnecessary IS_ENABLED and pr_warn_once from patch 5.

V11 changes: fixed a potential dst leak in patch 5, as suggested by
David Ahern.

Peter Oskolkov (7):
bpf: add plumbing for BPF_LWT_ENCAP_IP in bpf_lwt_push_encap
bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap
bpf: handle GSO in bpf_lwt_push_encap
ipv6_stub: add ipv6_route_input stub/proxy.
bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c
bpf: sync <kdir>/include/.../bpf.h with tools/include/.../bpf.h
selftests: bpf: add test_lwt_ip_encap selftest

 include/net/addrconf.h                        |   1 +
 include/net/lwtunnel.h                        |   2 +
 include/uapi/linux/bpf.h                      |  26 +-
 net/core/filter.c                             |  49 ++-
 net/core/lwt_bpf.c                            | 254 +++++++++++++-
 net/ipv6/addrconf_core.c                      |   6 +
 net/ipv6/af_inet6.c                           |   7 +
 tools/include/uapi/linux/bpf.h                |  26 +-
 tools/testing/selftests/bpf/Makefile          |   3 +-
 .../selftests/bpf/progs/test_lwt_ip_encap.c   |  85 +++++
 .../selftests/bpf/test_lwt_ip_encap.sh        | 311 ++++++++++++++++++
 11 files changed, 758 insertions(+), 12 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c
 create mode 100755 tools/testing/selftests/bpf/test_lwt_ip_encap.sh
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#1 lore raw

PATCH v11 1/7 bpf: add plumbing for BPF_LWT_ENCAP_IP in bpf_lwt_push_encap

This patch adds all needed plumbing in preparation to allowing bpf programs to do IP encapping via bpf_lwt_push_encap. Actual implementation is added in the next patch in the patchset.

Of note:
- bpf_lwt_push_encap can now be called from BPF_PROG_TYPE_LWT_XMIT prog types in addition to BPF_PROG_TYPE_LWT_IN;
- if the skb being encapped has GSO set, encapsulation is limited to IPIP/IP+GRE/IP+GUE (both IPv4 and IPv6);
- as route lookups are different for ingress vs egress, the single external bpf_lwt_push_encap BPF helper is routed internally to either bpf_lwt_in_push_encap or bpf_lwt_xmit_push_encap BPF_CALLs, depending on prog type.

v8 changes: fixed a typo.

---
 include/uapi/linux/bpf.h | 26 ++++++++++++++++++++--
 net/core/filter.c        | 48 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 67 insertions(+), 7 deletions(-)
include/uapi/linux/bpf.h +24 -2
index 25c8c0e62ecf..bcdd2474eee7 100644
@@ -2016,6 +2016,19 @@ union bpf_attr {
  *			Only works if *skb* contains an IPv6 packet. Insert a
  *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
  *			the IPv6 header.
+ *		**BPF_LWT_ENCAP_IP**
+ *			IP encapsulation (GRE/GUE/IPIP/etc). The outer header
+ *			must be IPv4 or IPv6, followed by zero or more
+ *			additional headers, up to LWT_BPF_MAX_HEADROOM total
+ *			bytes in all prepended headers. Please note that
+ *			if skb_is_gso(skb) is true, no more than two headers
+ *			can be prepended, and the inner header, if present,
+ *			should be either GRE or UDP/GUE.
+ *
+ *		BPF_LWT_ENCAP_SEG6*** types can be called by bpf programs of
+ *		type BPF_PROG_TYPE_LWT_IN; BPF_LWT_ENCAP_IP type can be called
+ *		by bpf programs of types BPF_PROG_TYPE_LWT_IN and
+ *		BPF_PROG_TYPE_LWT_XMIT.
  *
  * 		A call to this helper is susceptible to change the underlaying
  * 		packet buffer. Therefore, at load time, all checks on pointers
@@ -2517,7 +2530,8 @@ enum bpf_hdr_start_off {
 /* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
 enum bpf_lwt_encap_mode {
 	BPF_LWT_ENCAP_SEG6,
-	BPF_LWT_ENCAP_SEG6_INLINE
+	BPF_LWT_ENCAP_SEG6_INLINE,
+	BPF_LWT_ENCAP_IP,
 };
 
 #define __bpf_md_ptr(type, name)	\
@@ -2606,7 +2620,15 @@ enum bpf_ret_code {
 	BPF_DROP = 2,
 	/* 3-6 reserved */
 	BPF_REDIRECT = 7,
-	/* >127 are reserved for prog type specific return codes */
+	/* >127 are reserved for prog type specific return codes.
+	 *
+	 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
+	 *    BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
+	 *    changed and should be routed based on its new L3 header.
+	 *    (This is an L3 redirect, as opposed to L2 redirect
+	 *    represented by BPF_REDIRECT above).
+	 */
+	BPF_LWT_REROUTE = 128,
 };
 
 struct bpf_sock {
net/core/filter.c +43 -5

84 lines not on this page · raw message

Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#2 lore raw

PATCH v11 2/7 bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap

In reply to Peter Oskolkov

Implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap BPF helper. It enables BPF programs (specifically, BPF_PROG_TYPE_LWT_IN and BPF_PROG_TYPE_LWT_XMIT prog types) to add IP encapsulation headers to packets (e.g. IP/GRE, GUE, IPIP).

This is useful when thousands of different short-lived flows should be encapped, each with different and dynamically determined destination. Although lwtunnels can be used in some of these scenarios, the ability to dynamically generate encap headers adds more flexibility, e.g. when routing depends on the state of the host (reflected in global bpf maps).

v7 changes:
- added a call skb_clear_hash();
- removed calls to skb_set_transport_header();
- refuse to encap GSO-enabled packets.

v8 changes:
- fix build errors when LWT is not enabled.

Note: the next patch in the patchset with deal with GSO-enabled packets, which are currently rejected at encapping attempt.

---
 include/net/lwtunnel.h |  2 ++
 net/core/filter.c      |  3 +-
 net/core/lwt_bpf.c     | 65 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)
include/net/lwtunnel.h +2 -0
index 33fd9ba7e0e5..671113bcb2cc 100644
@@ -126,6 +126,8 @@ int lwtunnel_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b);
 int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb);
 int lwtunnel_input(struct sk_buff *skb);
 int lwtunnel_xmit(struct sk_buff *skb);
+int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len,
+			  bool ingress);
 
 static inline void lwtunnel_set_redirect(struct dst_entry *dst)
 {
net/core/filter.c +2 -1
index 12c88c21b6b8..a78deb2656e1 100644
@@ -73,6 +73,7 @@
 #include <linux/seg6_local.h>
 #include <net/seg6.h>
 #include <net/seg6_local.h>
+#include <net/lwtunnel.h>
 
 /**
  *	sk_filter_trim_cap - run a packet through a socket filter
@@ -4819,7 +4820,7 @@ static int bpf_push_seg6_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len
 static int bpf_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len,
 			     bool ingress)
 {
-	return -EINVAL;  /* Implemented in the next patch. */
+	return bpf_lwt_push_ip_encap(skb, hdr, len, ingress);
 }
 #endif
 
net/core/lwt_bpf.c +65 -0

71 lines not on this page · raw message

Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#3 lore raw

PATCH v11 3/7 bpf: handle GSO in bpf_lwt_push_encap

In reply to Peter Oskolkov

This patch adds handling of GSO packets in bpf_lwt_push_ip_encap() (called from bpf_lwt_push_encap):

* IPIP, GRE, and UDP encapsulation types are deduced by looking into iphdr->protocol or ipv6hdr->next_header;
* SCTP GSO packets are not supported (as bpf_skb_proto_4_to_6 and similar do);
* UDP_L4 GSO packets are also not supported (although they are not blocked in bpf_skb_proto_4_to_6 and similar), as skb_decrease_gso_size() will break it;
* SKB_GSO_DODGY bit is set.

Note: it may be possible to support SCTP and UDP_L4 gso packets;
but as these cases seem to be not well handled by other tunneling/encapping code paths, the solution should be generic enough to apply to all tunneling/encapping code.

v8 changes:
- make sure that if GRE or UDP encap is detected, there is

     enough of pushed bytes to cover both IP[v6] + GRE|UDP headers;

- do not reject double-encapped packets;
- whitelist TCP GSO packets rather than block SCTP GSO and UDP GSO.

---
 net/core/lwt_bpf.c | 67 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 65 insertions(+), 2 deletions(-)
net/core/lwt_bpf.c +65 -2
index e5a9850d9f48..079871fc020f 100644
@@ -16,6 +16,7 @@
 #include <linux/types.h>
 #include <linux/bpf.h>
 #include <net/lwtunnel.h>
+#include <net/gre.h>
 
 struct bpf_lwt_prog {
 	struct bpf_prog *prog;
@@ -390,10 +391,72 @@ static const struct lwtunnel_encap_ops bpf_encap_ops = {
 	.owner		= THIS_MODULE,
 };
 
+static int handle_gso_type(struct sk_buff *skb, unsigned int gso_type,
+			   int encap_len)
+{
+	struct skb_shared_info *shinfo = skb_shinfo(skb);
+
+	gso_type |= SKB_GSO_DODGY;
+	shinfo->gso_type |= gso_type;
+	skb_decrease_gso_size(shinfo, encap_len);
+	shinfo->gso_segs = 0;
+	return 0;
+}
+
 static int handle_gso_encap(struct sk_buff *skb, bool ipv4, int encap_len)
 {
-	/* Handling of GSO-enabled packets is added in the next patch. */
-	return -EOPNOTSUPP;
+	int next_hdr_offset;
+	void *next_hdr;
+	__u8 protocol;
+
+	/* SCTP and UDP_L4 gso need more nuanced handling than what
+	 * handle_gso_type() does above: skb_decrease_gso_size() is not enough.
+	 * So at the moment only TCP GSO packets are let through.
+	 */
+	if (!(skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))
+		return -ENOTSUPP;
+
+	if (ipv4) {
+		protocol = ip_hdr(skb)->protocol;
+		next_hdr_offset = sizeof(struct iphdr);
+		next_hdr = skb_network_header(skb) + next_hdr_offset;
+	} else {
+		protocol = ipv6_hdr(skb)->nexthdr;
+		next_hdr_offset = sizeof(struct ipv6hdr);
+		next_hdr = skb_network_header(skb) + next_hdr_offset;
+	}
+
+	switch (protocol) {
+	case IPPROTO_GRE:
+		next_hdr_offset += sizeof(struct gre_base_hdr);
+		if (next_hdr_offset > encap_len)
+			return -EINVAL;
+
+		if (((struct gre_base_hdr *)next_hdr)->flags & GRE_CSUM)
+			return handle_gso_type(skb, SKB_GSO_GRE_CSUM,
+					       encap_len);
+		return handle_gso_type(skb, SKB_GSO_GRE, encap_len);
+
+	case IPPROTO_UDP:
+		next_hdr_offset += sizeof(struct udphdr);
+		if (next_hdr_offset > encap_len)
+			return -EINVAL;
+
+		if (((struct udphdr *)next_hdr)->check)
+			return handle_gso_type(skb, SKB_GSO_UDP_TUNNEL_CSUM,
+					       encap_len);
+		return handle_gso_type(skb, SKB_GSO_UDP_TUNNEL, encap_len);
+
+	case IPPROTO_IP:
+	case IPPROTO_IPV6:
+		if (ipv4)
+			return handle_gso_type(skb, SKB_GSO_IPXIP4, encap_len);
+		else
+			return handle_gso_type(skb, SKB_GSO_IPXIP6, encap_len);
+
+	default:
+		return -EPROTONOSUPPORT;
+	}
 }
 
 int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len, bool ingress)
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#4 lore raw

PATCH v11 4/7 ipv6_stub: add ipv6_route_input stub/proxy.

In reply to Peter Oskolkov

Proxy ip6_route_input via ipv6_stub, for later use by lwt bpf ip encap (see the next patch in the patchset).

---
 include/net/addrconf.h   | 1 +
 net/ipv6/addrconf_core.c | 6 ++++++
 net/ipv6/af_inet6.c      | 7 +++++++
 3 files changed, 14 insertions(+)
include/net/addrconf.h +1 -0
index 20d523ee2fec..269ec27385e9 100644
@@ -248,6 +248,7 @@ struct ipv6_stub {
 				 const struct in6_addr *addr);
 	int (*ipv6_dst_lookup)(struct net *net, struct sock *sk,
 			       struct dst_entry **dst, struct flowi6 *fl6);
+	int (*ipv6_route_input)(struct sk_buff *skb);
 
 	struct fib6_table *(*fib6_get_table)(struct net *net, u32 id);
 	struct fib6_info *(*fib6_lookup)(struct net *net, int oif,
net/ipv6/addrconf_core.c +6 -0
index 5cd0029d930e..6c79af056d9b 100644
@@ -134,6 +134,11 @@ static int eafnosupport_ipv6_dst_lookup(struct net *net, struct sock *u1,
 	return -EAFNOSUPPORT;
 }
 
+static int eafnosupport_ipv6_route_input(struct sk_buff *skb)
+{
+	return -EAFNOSUPPORT;
+}
+
 static struct fib6_table *eafnosupport_fib6_get_table(struct net *net, u32 id)
 {
 	return NULL;
@@ -170,6 +175,7 @@ eafnosupport_ip6_mtu_from_fib6(struct fib6_info *f6i, struct in6_addr *daddr,
 
 const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) {
 	.ipv6_dst_lookup   = eafnosupport_ipv6_dst_lookup,
+	.ipv6_route_input  = eafnosupport_ipv6_route_input,
 	.fib6_get_table    = eafnosupport_fib6_get_table,
 	.fib6_table_lookup = eafnosupport_fib6_table_lookup,
 	.fib6_lookup       = eafnosupport_fib6_lookup,
net/ipv6/af_inet6.c +7 -0
index d99753b5e39b..2f45d2a3e3a3 100644
@@ -900,10 +900,17 @@ static struct pernet_operations inet6_net_ops = {
 	.exit = inet6_net_exit,
 };
 
+static int ipv6_route_input(struct sk_buff *skb)
+{
+	ip6_route_input(skb);
+	return skb_dst(skb)->error;
+}
+
 static const struct ipv6_stub ipv6_stub_impl = {
 	.ipv6_sock_mc_join = ipv6_sock_mc_join,
 	.ipv6_sock_mc_drop = ipv6_sock_mc_drop,
 	.ipv6_dst_lookup   = ip6_dst_lookup,
+	.ipv6_route_input  = ipv6_route_input,
 	.fib6_get_table	   = fib6_get_table,
 	.fib6_table_lookup = fib6_table_lookup,
 	.fib6_lookup       = fib6_lookup,
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#5 lore raw

PATCH v11 5/7 bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c

In reply to Peter Oskolkov

This patch builds on top of the previous patch in the patchset, which added BPF_LWT_ENCAP_IP mode to bpf_lwt_push_encap. As the encapping can result in the skb needing to go via a different interface/route/dst, bpf programs can indicate this by returning BPF_LWT_REROUTE, which triggers a new route lookup for the skb.

v8 changes: fix kbuild errors when LWTUNNEL_BPF is builtin, but
IPV6 is a module: as LWTUNNEL_BPF can only be either Y or N, call IPV6 routing functions only if they are built-in.

v9 changes:
- fixed a kbuild test robot compiler warning;
- call IPV6 routing functions via ipv6_stub.

v10 changes: removed unnecessary IS_ENABLED and pr_warn_once.

v11 changes: fixed a potential dst leak.

---
 net/core/lwt_bpf.c | 126 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 124 insertions(+), 2 deletions(-)
net/core/lwt_bpf.c +124 -2
index 079871fc020f..32251f3fcda0 100644
@@ -17,6 +17,7 @@
 #include <linux/bpf.h>
 #include <net/lwtunnel.h>
 #include <net/gre.h>
+#include <net/ip6_route.h>
 
 struct bpf_lwt_prog {
 	struct bpf_prog *prog;
@@ -56,6 +57,7 @@ static int run_lwt_bpf(struct sk_buff *skb, struct bpf_lwt_prog *lwt,
 
 	switch (ret) {
 	case BPF_OK:
+	case BPF_LWT_REROUTE:
 		break;
 
 	case BPF_REDIRECT:
@@ -88,6 +90,30 @@ static int run_lwt_bpf(struct sk_buff *skb, struct bpf_lwt_prog *lwt,
 	return ret;
 }
 
+static int bpf_lwt_input_reroute(struct sk_buff *skb)
+{
+	int err = -EINVAL;
+
+	if (skb->protocol == htons(ETH_P_IP)) {
+		struct iphdr *iph = ip_hdr(skb);
+
+		err = ip_route_input_noref(skb, iph->daddr, iph->saddr,
+					   iph->tos, skb_dst(skb)->dev);
+	} else if (skb->protocol == htons(ETH_P_IPV6)) {
+		err = ipv6_stub->ipv6_route_input(skb);
+	} else {
+		err = -EAFNOSUPPORT;
+	}
+
+	if (err)
+		goto err;
+	return dst_input(skb);
+
+err:
+	kfree_skb(skb);
+	return err;
+}
+
 static int bpf_input(struct sk_buff *skb)
 {
 	struct dst_entry *dst = skb_dst(skb);
@@ -99,11 +125,11 @@ static int bpf_input(struct sk_buff *skb)
 		ret = run_lwt_bpf(skb, &bpf->in, dst, NO_REDIRECT);
 		if (ret < 0)
 			return ret;
+		if (ret == BPF_LWT_REROUTE)
+			return bpf_lwt_input_reroute(skb);
 	}
 
 	if (unlikely(!dst->lwtstate->orig_input)) {
-		pr_warn_once("orig_input not set on dst for prog %s\n",
-			     bpf->out.name);
 		kfree_skb(skb);
 		return -EINVAL;
 	}
@@ -148,6 +174,91 @@ static int xmit_check_hhlen(struct sk_buff *skb)
 	return 0;
 }
 
+static int bpf_lwt_xmit_reroute(struct sk_buff *skb)
+{
+	struct net_device *l3mdev = l3mdev_master_dev_rcu(skb_dst(skb)->dev);
+	int oif = l3mdev ? l3mdev->ifindex : 0;
+	struct dst_entry *dst = NULL;
+	struct sock *sk;
+	struct net *net;
+	bool ipv4;
+	int err;
+
+	if (skb->protocol == htons(ETH_P_IP))
+		ipv4 = true;
+	else if (skb->protocol == htons(ETH_P_IPV6))
+		ipv4 = false;
+	else
+		return -EAFNOSUPPORT;
+
+	sk = sk_to_full_sk(skb->sk);
+	if (sk) {
+		if (sk->sk_bound_dev_if)
+			oif = sk->sk_bound_dev_if;
+		net = sock_net(sk);
+	} else {
+		net = dev_net(skb_dst(skb)->dev);
+	}
+
+	if (ipv4) {
+		struct iphdr *iph = ip_hdr(skb);
+		struct flowi4 fl4 = {};
+		struct rtable *rt;
+
+		fl4.flowi4_oif = oif;
+		fl4.flowi4_mark = skb->mark;
+		fl4.flowi4_uid = sock_net_uid(net, sk);
+		fl4.flowi4_tos = RT_TOS(iph->tos);
+		fl4.flowi4_flags = FLOWI_FLAG_ANYSRC;
+		fl4.flowi4_proto = iph->protocol;
+		fl4.daddr = iph->daddr;
+		fl4.saddr = iph->saddr;
+
+		rt = ip_route_output_key(net, &fl4);
+		if (IS_ERR(rt))
+			return -EINVAL;
+		dst = &rt->dst;
+	} else {
+		struct ipv6hdr *iph6 = ipv6_hdr(skb);
+		struct flowi6 fl6 = {};
+
+		fl6.flowi6_oif = oif;
+		fl6.flowi6_mark = skb->mark;
+		fl6.flowi6_uid = sock_net_uid(net, sk);
+		fl6.flowlabel = ip6_flowinfo(iph6);
+		fl6.flowi6_proto = iph6->nexthdr;
+		fl6.daddr = iph6->daddr;
+		fl6.saddr = iph6->saddr;
+
+		err = ipv6_stub->ipv6_dst_lookup(net, skb->sk, &dst, &fl6);
+		if (err || IS_ERR(dst))
+			return -EINVAL;
+	}
+	if (unlikely(dst->error)) {
+		dst_release(dst);
+		return -EINVAL;
+	}
+
+	/* Although skb header was reserved in bpf_lwt_push_ip_encap(), it
+	 * was done for the previous dst, so we are doing it here again, in
+	 * case the new dst needs much more space. The call below is a noop
+	 * if there is enough header space in skb.
+	 */
+	err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
+	if (unlikely(err))
+		return err;
+
+	skb_dst_drop(skb);
+	skb_dst_set(skb, dst);
+
+	err = dst_output(dev_net(skb_dst(skb)->dev), skb->sk, skb);
+	if (unlikely(err))
+		return err;
+
+	/* ip[6]_finish_output2 understand LWTUNNEL_XMIT_DONE */
+	return LWTUNNEL_XMIT_DONE;
+}
+
 static int bpf_xmit(struct sk_buff *skb)
 {
 	struct dst_entry *dst = skb_dst(skb);
@@ -155,11 +266,20 @@ static int bpf_xmit(struct sk_buff *skb)
 
 	bpf = bpf_lwt_lwtunnel(dst->lwtstate);
 	if (bpf->xmit.prog) {
+		__be16 proto = skb->protocol;
 		int ret;
 
 		ret = run_lwt_bpf(skb, &bpf->xmit, dst, CAN_REDIRECT);
 		switch (ret) {
 		case BPF_OK:
+			/* If the header changed, e.g. via bpf_lwt_push_encap,
+			 * BPF_LWT_REROUTE below should have been used if the
+			 * protocol was also changed.
+			 */
+			if (skb->protocol != proto) {
+				kfree_skb(skb);
+				return -EINVAL;
+			}
 			/* If the header was expanded, headroom might be too
 			 * small for L2 header to come, expand as needed.
 			 */
@@ -170,6 +290,8 @@ static int bpf_xmit(struct sk_buff *skb)
 			return LWTUNNEL_XMIT_CONTINUE;
 		case BPF_REDIRECT:
 			return LWTUNNEL_XMIT_DONE;
+		case BPF_LWT_REROUTE:
+			return bpf_lwt_xmit_reroute(skb);
 		default:
 			return ret;
 		}
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#6 lore raw

PATCH v11 6/7 bpf: sync <kdir>/include/.../bpf.h with tools/include/.../bpf.h

In reply to Peter Oskolkov

This patch copies changes in bpf.h done by a previous patch in this patchset from the kernel uapi include dir into tools uapi include dir.

---
 tools/include/uapi/linux/bpf.h | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
tools/include/uapi/linux/bpf.h +24 -2
index 25c8c0e62ecf..bcdd2474eee7 100644
@@ -2016,6 +2016,19 @@ union bpf_attr {
  *			Only works if *skb* contains an IPv6 packet. Insert a
  *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
  *			the IPv6 header.
+ *		**BPF_LWT_ENCAP_IP**
+ *			IP encapsulation (GRE/GUE/IPIP/etc). The outer header
+ *			must be IPv4 or IPv6, followed by zero or more
+ *			additional headers, up to LWT_BPF_MAX_HEADROOM total
+ *			bytes in all prepended headers. Please note that
+ *			if skb_is_gso(skb) is true, no more than two headers
+ *			can be prepended, and the inner header, if present,
+ *			should be either GRE or UDP/GUE.
+ *
+ *		BPF_LWT_ENCAP_SEG6*** types can be called by bpf programs of
+ *		type BPF_PROG_TYPE_LWT_IN; BPF_LWT_ENCAP_IP type can be called
+ *		by bpf programs of types BPF_PROG_TYPE_LWT_IN and
+ *		BPF_PROG_TYPE_LWT_XMIT.
  *
  * 		A call to this helper is susceptible to change the underlaying
  * 		packet buffer. Therefore, at load time, all checks on pointers
@@ -2517,7 +2530,8 @@ enum bpf_hdr_start_off {
 /* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
 enum bpf_lwt_encap_mode {
 	BPF_LWT_ENCAP_SEG6,
-	BPF_LWT_ENCAP_SEG6_INLINE
+	BPF_LWT_ENCAP_SEG6_INLINE,
+	BPF_LWT_ENCAP_IP,
 };
 
 #define __bpf_md_ptr(type, name)	\
@@ -2606,7 +2620,15 @@ enum bpf_ret_code {
 	BPF_DROP = 2,
 	/* 3-6 reserved */
 	BPF_REDIRECT = 7,
-	/* >127 are reserved for prog type specific return codes */
+	/* >127 are reserved for prog type specific return codes.
+	 *
+	 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
+	 *    BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
+	 *    changed and should be routed based on its new L3 header.
+	 *    (This is an L3 redirect, as opposed to L2 redirect
+	 *    represented by BPF_REDIRECT above).
+	 */
+	BPF_LWT_REROUTE = 128,
 };
 
 struct bpf_sock {
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#7 lore raw

PATCH v11 7/7 selftests: bpf: add test_lwt_ip_encap selftest

In reply to Peter Oskolkov

This patch adds a bpf self-test to cover BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap.

Covered:
- encapping in LWT_IN and LWT_XMIT
- IPv4 and IPv6

A follow-up patch will add GSO and VRF-enabled tests.

---
 tools/testing/selftests/bpf/Makefile          |   3 +-
 .../selftests/bpf/progs/test_lwt_ip_encap.c   |  85 +++++
 .../selftests/bpf/test_lwt_ip_encap.sh        | 311 ++++++++++++++++++
 3 files changed, 398 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c
 create mode 100755 tools/testing/selftests/bpf/test_lwt_ip_encap.sh
tools/testing/selftests/bpf/Makefile +2 -1
index c3edf47da05d..ccffaa0a0787 100644
@@ -50,7 +50,8 @@ TEST_PROGS := test_kmod.sh \
 	test_lirc_mode2.sh \
 	test_skb_cgroup_id.sh \
 	test_flow_dissector.sh \
-	test_xdp_vlan.sh
+	test_xdp_vlan.sh \
+	test_lwt_ip_encap.sh
 
 TEST_PROGS_EXTENDED := with_addr.sh \
 	with_tunnels.sh \
tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c new file +85 -0

85 lines not on this page · raw message

tools/testing/selftests/bpf/test_lwt_ip_encap.sh new file +311 -0

311 lines not on this page · raw message

Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Reviewed-by on the v11 series
#9 lore raw
In reply to Peter Oskolkov
Quoted 5 lines · Peter Oskolkov

This patchset implements BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap BPF helper. It enables BPF programs (specifically, BPF_PROG_TYPE_LWT_IN and BPF_PROG_TYPE_LWT_XMIT prog types) to add IP encapsulation headers to packets (e.g. IP/GRE, GUE, IPIP).

Quoted 7 lines

This is useful when thousands of different short-lived flows should be encapped, each with different and dynamically determined destination. Although lwtunnels can be used in some of these scenarios, the ability to dynamically generate encap headers adds more flexibility, e.g. when routing depends on the state of the host (reflected in global bpf maps).

For the set:

#10 lore raw
Quoted 15 lines · David Ahern
Quoted 5 lines · Peter Oskolkov

This patchset implements BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap BPF helper. It enables BPF programs (specifically, BPF_PROG_TYPE_LWT_IN and BPF_PROG_TYPE_LWT_XMIT prog types) to add IP encapsulation headers to packets (e.g. IP/GRE, GUE, IPIP).

Quoted 7 lines

This is useful when thousands of different short-lived flows should be encapped, each with different and dynamically determined destination. Although lwtunnels can be used in some of these scenarios, the ability to dynamically generate encap headers adds more flexibility, e.g. when routing depends on the state of the host (reflected in global bpf maps).

Quoted 2 lines

For the set:

Applied. Thanks everyone!

#11 lore raw
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · David Ahern
Quoted 12 lines · Peter Oskolkov

This patchset implements BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap BPF helper. It enables BPF programs (specifically, BPF_PROG_TYPE_LWT_IN and BPF_PROG_TYPE_LWT_XMIT prog types) to add IP encapsulation headers to packets (e.g. IP/GRE, GUE, IPIP).

This is useful when thousands of different short-lived flows should be encapped, each with different and dynamically determined destination. Although lwtunnels can be used in some of these scenarios, the ability to dynamically generate encap headers adds more flexibility, e.g. when routing depends on the state of the host (reflected in global bpf maps).

Quoted 5 lines
Quoted 2 lines

For the set:

Applied. Thanks everyone!

Looks like a cleanup round is needed.

I changed the routes to fail with unreachable:

@@ -179,16 +175,16 @@
ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local
${IPv4_GRE} ttl 255
ip -netns ${NS3} link set gre_dev up
ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev
- ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6}
- ip -netns ${NS2} route add ${IPv4_GRE}/32 dev veth7 via ${IPv4_8}
+ ip -netns ${NS1} route add unreachable ${IPv4_GRE}/32
+ ip -netns ${NS2} route add unreachable ${IPv4_GRE}/32

 	# configure IPv6 GRE device in NS3, and a route to it via the "bottom"
route
 	ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote
${IPv6_1} local ${IPv6_GRE} ttl 255
 	ip -netns ${NS3} link set gre6_dev up
 	ip -netns ${NS3} -6 addr add ${IPv6_GRE} nodad dev gre6_dev
-	ip -netns ${NS1} -6 route add ${IPv6_GRE}/128 dev veth5 via ${IPv6_6}
-	ip -netns ${NS2} -6 route add ${IPv6_GRE}/128 dev veth7 via ${IPv6_8}
+	ip -netns ${NS1} -6 route add unreachable ${IPv6_GRE}/128
+	ip -netns ${NS2} -6 route add unreachable ${IPv6_GRE}/128
 	# rp_filter gets confused by what these tests are doing, so disable it
 	ip netns exec ${NS1} sysctl -wq net.ipv4.conf.all.rp_filter=0
@@ -220,7 +216,6 @@

and then removed all of the set -e and exit 1's in the script (really should let all of the tests run versus bailing on the first failure).

With kmemleak enabled I see a lot of suspected memory leaks - some may not be related to this change but it is triggering the suspected leak:

unreferenced object 0xffff88813407a9c0 (size 160):
comm "ping", pid 1040, jiffies 4294800240 (age 130.536s) hex dump (first 32 bytes):

    00 60 23 28 81 88 ff ff 80 d7 23 82 ff ff ff ff  .`#(......#.....
    c1 7f c8 81 ff ff ff ff 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<00000000dec307f3>] dst_alloc+0x89/0xc1
    [<0000000037c7c09a>] rt_dst_alloc+0x57/0xd4
    [<00000000850d146d>] ip_route_output_key_hash_rcu+0x57a/0x64d
    [<0000000059f3e271>] ip_route_output_key_hash+0x6e/0x98
    [<0000000093465e72>] ip_route_output_flow+0x1e/0x47
    [<000000007eee78d9>] raw_sendmsg+0x551/0xbd8
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff
unreferenced object 0xffff8881280bdf00 (size 224):
  comm "ping", pid 1040, jiffies 4294800240 (age 130.536s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 80 96 27 81 88 ff ff 40 da a2 27 81 88 ff ff  ...'....@..'....
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<0000000043c55b9b>] __alloc_skb+0x66/0x1b9
    [<00000000e92d2e81>] __ip_append_data+0x44f/0xa88
    [<00000000c0fa4285>] ip_append_data.part.19+0xa4/0xb7
    [<000000008437d83b>] ip_append_data+0x22/0x28
    [<0000000010065ae2>] raw_sendmsg+0xaff/0xbd8
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff

unreferenced object 0xffff888127ad6c00 (size 1024):
comm "ping", pid 1040, jiffies 4294800240 (age 130.545s) hex dump (first 32 bytes):
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
backtrace:

    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<00000000ebec8a26>] __kmalloc_reserve.isra.17+0x2d/0x6d
    [<00000000827ebff0>] pskb_expand_head+0xcc/0x2d1
    [<0000000034bfc15f>] skb_cow_head+0xae/0xb7
    [<000000008f8c30fc>] bpf_lwt_push_ip_encap+0xb1/0x34c
    [<000000007add911b>] bpf_lwt_xmit_push_encap+0x1d/0x29
    [<00000000eecbf798>] ___bpf_prog_run+0xbc3/0x1757
    [<000000002d199add>] __bpf_prog_run32+0x42/0x58
    [<00000000d0c1f29b>] run_lwt_bpf.constprop.4+0xff/0x2e6
    [<00000000b9ad5b04>] bpf_xmit+0x3d/0xef
    [<000000003ba220bf>] lwtunnel_xmit+0xc7/0xeb
    [<00000000abfa977f>] ip_finish_output2+0x5b6/0x5e7
    [<000000005a652edf>] ip_finish_output+0x17f/0x191
    [<00000000cded5fe2>] ip_output+0x58/0x88
unreferenced object 0xffff888131020f00 (size 224):
  comm "ping", pid 1040, jiffies 4294800240 (age 130.545s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 80 96 27 81 88 ff ff 40 da a2 27 81 88 ff ff  ...'....@..'....
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<0000000043c55b9b>] __alloc_skb+0x66/0x1b9
    [<00000000e92d2e81>] __ip_append_data+0x44f/0xa88
    [<00000000c0fa4285>] ip_append_data.part.19+0xa4/0xb7
    [<000000008437d83b>] ip_append_data+0x22/0x28
    [<0000000010065ae2>] raw_sendmsg+0xaff/0xbd8
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff

unreferenced object 0xffff88812779cc00 (size 1024):
comm "ping", pid 1040, jiffies 4294800240 (age 130.545s) hex dump (first 32 bytes):
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
backtrace:

    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<00000000ebec8a26>] __kmalloc_reserve.isra.17+0x2d/0x6d
    [<00000000827ebff0>] pskb_expand_head+0xcc/0x2d1
    [<0000000034bfc15f>] skb_cow_head+0xae/0xb7
    [<000000008f8c30fc>] bpf_lwt_push_ip_encap+0xb1/0x34c
    [<000000007add911b>] bpf_lwt_xmit_push_encap+0x1d/0x29
    [<00000000eecbf798>] ___bpf_prog_run+0xbc3/0x1757
    [<000000002d199add>] __bpf_prog_run32+0x42/0x58
    [<00000000d0c1f29b>] run_lwt_bpf.constprop.4+0xff/0x2e6
    [<00000000b9ad5b04>] bpf_xmit+0x3d/0xef
    [<000000003ba220bf>] lwtunnel_xmit+0xc7/0xeb
    [<00000000abfa977f>] ip_finish_output2+0x5b6/0x5e7
    [<000000005a652edf>] ip_finish_output+0x17f/0x191
    [<00000000cded5fe2>] ip_output+0x58/0x88
unreferenced object 0xffff888131abf980 (size 1632):
  comm "ping6", pid 1041, jiffies 4294801264 (age 129.529s)
  hex dump (first 32 bytes):
    00 00 00 00 7f 00 00 06 00 00 00 00 00 00 3a 00  ..............:.
    0a 00 07 41 00 00 00 00 00 00 00 00 00 00 00 00  ...A............
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<000000006287ee1f>] sk_prot_alloc.isra.27+0x30/0xb4
    [<00000000f5b12125>] sk_alloc+0x2e/0x1aa
    [<00000000c2b12d1b>] inet6_create+0x1ae/0x3a7
    [<000000000a3125dc>] __sock_create+0x1c1/0x22a
    [<00000000039d3cb8>] sock_create+0x30/0x32
    [<000000000556b08a>] __sys_socket+0x3d/0xb3
    [<000000007e47d085>] __x64_sys_socket+0x1a/0x1e
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff
unreferenced object 0xffff888127683f00 (size 224):
  comm "softirq", pid 0, jiffies 4294801264 (age 129.529s)
  hex dump (first 32 bytes):
    00 60 23 28 81 88 ff ff 00 2f 30 35 81 88 ff ff  .`#(...../05....
    c1 7f c8 81 ff ff ff ff 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<00000000dec307f3>] dst_alloc+0x89/0xc1
    [<000000002651f911>] ip6_dst_alloc+0x25/0x63
    [<000000008608d224>] ip6_pol_route+0x201/0x2ae
    [<000000000084a9eb>] ip6_pol_route_output+0x19/0x1b
    [<000000005d385680>] fib6_rule_lookup+0xe7/0x12c
    [<000000001a93c416>] ip6_route_output_flags+0xc5/0xd1
    [<0000000023cbe9f3>] ip6_dst_lookup_tail+0x1a3/0x364
    [<000000003afeb57e>] ip6_dst_lookup_flow+0x47/0x9b
    [<00000000938dbf6b>] rawv6_sendmsg+0x45f/0xdfc
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
unreferenced object 0xffff88812fb34f00 (size 224):
  comm "ping6", pid 1041, jiffies 4294801264 (age 129.530s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 80 96 27 81 88 ff ff 80 f9 ab 31 81 88 ff ff  ...'.......1....
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<0000000043c55b9b>] __alloc_skb+0x66/0x1b9
    [<0000000014f706bf>] __ip6_append_data+0x57c/0xc62
    [<0000000016ddc7e9>] ip6_append_data+0x135/0x148
    [<00000000210a1bd5>] rawv6_sendmsg+0xb19/0xdfc
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff

unreferenced object 0xffff8881276bdc00 (size 1024):
comm "ping6", pid 1041, jiffies 4294801264 (age 129.537s) hex dump (first 32 bytes):
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
backtrace:

    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<00000000ebec8a26>] __kmalloc_reserve.isra.17+0x2d/0x6d
    [<00000000827ebff0>] pskb_expand_head+0xcc/0x2d1
    [<0000000034bfc15f>] skb_cow_head+0xae/0xb7
    [<000000008f8c30fc>] bpf_lwt_push_ip_encap+0xb1/0x34c
    [<000000007add911b>] bpf_lwt_xmit_push_encap+0x1d/0x29
    [<00000000eecbf798>] ___bpf_prog_run+0xbc3/0x1757
    [<000000002d199add>] __bpf_prog_run32+0x42/0x58
    [<00000000d0c1f29b>] run_lwt_bpf.constprop.4+0xff/0x2e6
    [<00000000b9ad5b04>] bpf_xmit+0x3d/0xef
    [<000000003ba220bf>] lwtunnel_xmit+0xc7/0xeb
    [<000000004c67bd98>] ip6_finish_output2+0x477/0x494
    [<00000000bf642298>] ip6_finish_output+0x106/0x110
    [<00000000365d3055>] ip6_output+0x87/0xbf
unreferenced object 0xffff8881278cbf00 (size 224):
  comm "ping6", pid 1041, jiffies 4294801264 (age 129.537s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 80 96 27 81 88 ff ff 80 f9 ab 31 81 88 ff ff  ...'.......1....
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<0000000043c55b9b>] __alloc_skb+0x66/0x1b9
    [<0000000014f706bf>] __ip6_append_data+0x57c/0xc62
    [<0000000016ddc7e9>] ip6_append_data+0x135/0x148
    [<00000000210a1bd5>] rawv6_sendmsg+0xb19/0xdfc
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff

unreferenced object 0xffff8881268fdc00 (size 1024):
comm "ping6", pid 1041, jiffies 4294801264 (age 129.537s) hex dump (first 32 bytes):
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
backtrace:

    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<00000000ebec8a26>] __kmalloc_reserve.isra.17+0x2d/0x6d
    [<00000000827ebff0>] pskb_expand_head+0xcc/0x2d1
    [<0000000034bfc15f>] skb_cow_head+0xae/0xb7
    [<000000008f8c30fc>] bpf_lwt_push_ip_encap+0xb1/0x34c
    [<000000007add911b>] bpf_lwt_xmit_push_encap+0x1d/0x29
    [<00000000eecbf798>] ___bpf_prog_run+0xbc3/0x1757
    [<000000002d199add>] __bpf_prog_run32+0x42/0x58
    [<00000000d0c1f29b>] run_lwt_bpf.constprop.4+0xff/0x2e6
    [<00000000b9ad5b04>] bpf_xmit+0x3d/0xef
    [<000000003ba220bf>] lwtunnel_xmit+0xc7/0xeb
    [<000000004c67bd98>] ip6_finish_output2+0x477/0x494
    [<00000000bf642298>] ip6_finish_output+0x106/0x110
    [<00000000365d3055>] ip6_output+0x87/0xbf
unreferenced object 0xffff888127157e80 (size 128):
  comm "ip", pid 1157, jiffies 4294810718 (age 120.100s)
  hex dump (first 32 bytes):
    06 00 04 00 00 00 00 00 02 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<00000000bd21c202>] __kmalloc+0x102/0x143
    [<00000000ac289f37>] lwtunnel_state_alloc+0x1a/0x1c
    [<000000002acf5ea0>] bpf_build_state+0x8c/0x16a
    [<00000000e1c85c0f>] lwtunnel_build_state+0x10a/0x148
    [<00000000187eb239>] ip6_route_info_create+0x2ae/0x823
    [<0000000017a89b3a>] ip6_route_add+0x1a/0x4e
    [<00000000de590240>] inet6_rtm_newroute+0x62/0x80
    [<000000009356b68b>] rtnetlink_rcv_msg+0x22d/0x273
    [<000000003da74356>] netlink_rcv_skb+0x8b/0xd9
    [<000000005349126a>] rtnetlink_rcv+0x15/0x17
    [<00000000d24a54ac>] netlink_unicast+0x118/0x1b1
    [<0000000096e0cc4e>] netlink_sendmsg+0x328/0x34d
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<000000003872075e>] ___sys_sendmsg+0x1ad/0x238
unreferenced object 0xffff8881271d1180 (size 64):
  comm "ip", pid 1157, jiffies 4294810718 (age 120.100s)
  hex dump (first 32 bytes):
    74 65 73 74 5f 6c 77 74 5f 69 70 5f 65 6e 63 61  test_lwt_ip_enca
    70 2e 6f 3a 5b 65 6e 63 61 70 5f 67 72 65 36 5d  p.o:[encap_gre6]
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<000000004a28667f>] kmemdup+0x20/0x35
    [<00000000f0fe083f>] bpf_parse_prog+0x77/0xc3
    [<000000005e53fa11>] bpf_build_state+0x108/0x16a
    [<00000000e1c85c0f>] lwtunnel_build_state+0x10a/0x148
    [<00000000187eb239>] ip6_route_info_create+0x2ae/0x823
    [<0000000017a89b3a>] ip6_route_add+0x1a/0x4e
    [<00000000de590240>] inet6_rtm_newroute+0x62/0x80
    [<000000009356b68b>] rtnetlink_rcv_msg+0x22d/0x273
    [<000000003da74356>] netlink_rcv_skb+0x8b/0xd9
    [<000000005349126a>] rtnetlink_rcv+0x15/0x17
    [<00000000d24a54ac>] netlink_unicast+0x118/0x1b1
    [<0000000096e0cc4e>] netlink_sendmsg+0x328/0x34d
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
unreferenced object 0xffff88813189ea40 (size 1432):
  comm "ping", pid 1159, jiffies 4294810742 (age 120.076s)
  hex dump (first 32 bytes):
    00 00 00 00 ac 10 01 64 00 00 00 00 00 00 01 00  .......d........
    02 00 07 41 00 00 00 00 00 00 00 00 00 00 00 00  ...A............
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<000000006287ee1f>] sk_prot_alloc.isra.27+0x30/0xb4
    [<00000000f5b12125>] sk_alloc+0x2e/0x1aa
    [<0000000048f46e3a>] inet_create+0x1ab/0x32e
    [<000000000a3125dc>] __sock_create+0x1c1/0x22a
    [<00000000039d3cb8>] sock_create+0x30/0x32
    [<000000000556b08a>] __sys_socket+0x3d/0xb3
    [<000000007e47d085>] __x64_sys_socket+0x1a/0x1e
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff
unreferenced object 0xffff8881270f2f00 (size 224):
  comm "ping", pid 1159, jiffies 4294810743 (age 120.084s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 30 af 26 81 88 ff ff 40 ea 89 31 81 88 ff ff  .0.&[email protected]....
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<0000000043c55b9b>] __alloc_skb+0x66/0x1b9
    [<00000000e92d2e81>] __ip_append_data+0x44f/0xa88
    [<00000000c0fa4285>] ip_append_data.part.19+0xa4/0xb7
    [<000000008437d83b>] ip_append_data+0x22/0x28
    [<0000000010065ae2>] raw_sendmsg+0xaff/0xbd8
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff

unreferenced object 0xffff8881336dac00 (size 1024):
comm "ping", pid 1159, jiffies 4294810743 (age 120.084s) hex dump (first 32 bytes):
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
backtrace:

    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<00000000ebec8a26>] __kmalloc_reserve.isra.17+0x2d/0x6d
    [<00000000827ebff0>] pskb_expand_head+0xcc/0x2d1
    [<0000000034bfc15f>] skb_cow_head+0xae/0xb7
    [<000000008f8c30fc>] bpf_lwt_push_ip_encap+0xb1/0x34c
    [<000000007add911b>] bpf_lwt_xmit_push_encap+0x1d/0x29
    [<00000000eecbf798>] ___bpf_prog_run+0xbc3/0x1757
    [<0000000055e881cc>] __bpf_prog_run64+0x42/0x58
    [<00000000d0c1f29b>] run_lwt_bpf.constprop.4+0xff/0x2e6
    [<00000000b9ad5b04>] bpf_xmit+0x3d/0xef
    [<000000003ba220bf>] lwtunnel_xmit+0xc7/0xeb
    [<00000000abfa977f>] ip_finish_output2+0x5b6/0x5e7
    [<000000005a652edf>] ip_finish_output+0x17f/0x191
    [<00000000cded5fe2>] ip_output+0x58/0x88
unreferenced object 0xffff8881283d0f00 (size 224):
  comm "ping", pid 1159, jiffies 4294810743 (age 120.084s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 30 af 26 81 88 ff ff 40 ea 89 31 81 88 ff ff  .0.&[email protected]....
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<0000000043c55b9b>] __alloc_skb+0x66/0x1b9
    [<00000000e92d2e81>] __ip_append_data+0x44f/0xa88
    [<00000000c0fa4285>] ip_append_data.part.19+0xa4/0xb7
    [<000000008437d83b>] ip_append_data+0x22/0x28
    [<0000000010065ae2>] raw_sendmsg+0xaff/0xbd8
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff

unreferenced object 0xffff8881272edc00 (size 1024):
comm "ping", pid 1159, jiffies 4294810743 (age 120.093s) hex dump (first 32 bytes):
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
backtrace:

    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<00000000ebec8a26>] __kmalloc_reserve.isra.17+0x2d/0x6d
    [<00000000827ebff0>] pskb_expand_head+0xcc/0x2d1
    [<0000000034bfc15f>] skb_cow_head+0xae/0xb7
    [<000000008f8c30fc>] bpf_lwt_push_ip_encap+0xb1/0x34c
    [<000000007add911b>] bpf_lwt_xmit_push_encap+0x1d/0x29
    [<00000000eecbf798>] ___bpf_prog_run+0xbc3/0x1757
    [<0000000055e881cc>] __bpf_prog_run64+0x42/0x58
    [<00000000d0c1f29b>] run_lwt_bpf.constprop.4+0xff/0x2e6
    [<00000000b9ad5b04>] bpf_xmit+0x3d/0xef
    [<000000003ba220bf>] lwtunnel_xmit+0xc7/0xeb
    [<00000000abfa977f>] ip_finish_output2+0x5b6/0x5e7
    [<000000005a652edf>] ip_finish_output+0x17f/0x191
    [<00000000cded5fe2>] ip_output+0x58/0x88
unreferenced object 0xffff88813355d980 (size 1632):
  comm "ping6", pid 1160, jiffies 4294811768 (age 119.068s)
  hex dump (first 32 bytes):
    00 00 00 00 7f 00 00 06 00 00 00 00 00 00 3a 00  ..............:.
    0a 00 07 41 00 00 00 00 00 00 00 00 00 00 00 00  ...A............
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<000000006287ee1f>] sk_prot_alloc.isra.27+0x30/0xb4
    [<00000000f5b12125>] sk_alloc+0x2e/0x1aa
    [<00000000c2b12d1b>] inet6_create+0x1ae/0x3a7
    [<000000000a3125dc>] __sock_create+0x1c1/0x22a
    [<00000000039d3cb8>] sock_create+0x30/0x32
    [<000000000556b08a>] __sys_socket+0x3d/0xb3
    [<000000007e47d085>] __x64_sys_socket+0x1a/0x1e
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff
unreferenced object 0xffff8881282b1f00 (size 224):
  comm "softirq", pid 0, jiffies 4294811768 (age 119.068s)
  hex dump (first 32 bytes):
    00 10 1c 28 81 88 ff ff 40 ee 25 28 81 88 ff ff  ...(....@.%(....
    c1 7f c8 81 ff ff ff ff 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<00000000dec307f3>] dst_alloc+0x89/0xc1
    [<000000002651f911>] ip6_dst_alloc+0x25/0x63
    [<000000008608d224>] ip6_pol_route+0x201/0x2ae
    [<000000000084a9eb>] ip6_pol_route_output+0x19/0x1b
    [<000000005d385680>] fib6_rule_lookup+0xe7/0x12c
    [<000000001a93c416>] ip6_route_output_flags+0xc5/0xd1
    [<0000000023cbe9f3>] ip6_dst_lookup_tail+0x1a3/0x364
    [<000000003afeb57e>] ip6_dst_lookup_flow+0x47/0x9b
    [<00000000938dbf6b>] rawv6_sendmsg+0x45f/0xdfc
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
unreferenced object 0xffff88812744bf00 (size 224):
  comm "ping6", pid 1160, jiffies 4294811768 (age 119.076s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 30 af 26 81 88 ff ff 80 d9 55 33 81 88 ff ff  .0.&......U3....
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<0000000043c55b9b>] __alloc_skb+0x66/0x1b9
    [<0000000014f706bf>] __ip6_append_data+0x57c/0xc62
    [<0000000016ddc7e9>] ip6_append_data+0x135/0x148
    [<00000000210a1bd5>] rawv6_sendmsg+0xb19/0xdfc
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff

unreferenced object 0xffff888127371c00 (size 1024):
comm "ping6", pid 1160, jiffies 4294811769 (age 119.075s) hex dump (first 32 bytes):
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
backtrace:

    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<00000000ebec8a26>] __kmalloc_reserve.isra.17+0x2d/0x6d
    [<00000000827ebff0>] pskb_expand_head+0xcc/0x2d1
    [<0000000034bfc15f>] skb_cow_head+0xae/0xb7
    [<000000008f8c30fc>] bpf_lwt_push_ip_encap+0xb1/0x34c
    [<000000007add911b>] bpf_lwt_xmit_push_encap+0x1d/0x29
    [<00000000eecbf798>] ___bpf_prog_run+0xbc3/0x1757
    [<0000000055e881cc>] __bpf_prog_run64+0x42/0x58
    [<00000000d0c1f29b>] run_lwt_bpf.constprop.4+0xff/0x2e6
    [<00000000b9ad5b04>] bpf_xmit+0x3d/0xef
    [<000000003ba220bf>] lwtunnel_xmit+0xc7/0xeb
    [<000000004c67bd98>] ip6_finish_output2+0x477/0x494
    [<00000000bf642298>] ip6_finish_output+0x106/0x110
    [<00000000365d3055>] ip6_output+0x87/0xbf
unreferenced object 0xffff88812723cf00 (size 224):
  comm "softirq", pid 0, jiffies 4294811770 (age 119.074s)
  hex dump (first 32 bytes):
    00 10 1c 28 81 88 ff ff 40 ee 25 28 81 88 ff ff  ...(....@.%(....
    c1 7f c8 81 ff ff ff ff 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<00000000dec307f3>] dst_alloc+0x89/0xc1
    [<000000002651f911>] ip6_dst_alloc+0x25/0x63
    [<000000008608d224>] ip6_pol_route+0x201/0x2ae
    [<000000000084a9eb>] ip6_pol_route_output+0x19/0x1b
    [<000000005d385680>] fib6_rule_lookup+0xe7/0x12c
    [<000000001a93c416>] ip6_route_output_flags+0xc5/0xd1
    [<0000000023cbe9f3>] ip6_dst_lookup_tail+0x1a3/0x364
    [<000000003afeb57e>] ip6_dst_lookup_flow+0x47/0x9b
    [<00000000938dbf6b>] rawv6_sendmsg+0x45f/0xdfc
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
unreferenced object 0xffff8881273d3f00 (size 224):
  comm "ping6", pid 1160, jiffies 4294811770 (age 119.084s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 30 af 26 81 88 ff ff 80 d9 55 33 81 88 ff ff  .0.&......U3....
  backtrace:
    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<0000000025231f88>] kmem_cache_alloc+0xd8/0x1fa
    [<0000000043c55b9b>] __alloc_skb+0x66/0x1b9
    [<0000000014f706bf>] __ip6_append_data+0x57c/0xc62
    [<0000000016ddc7e9>] ip6_append_data+0x135/0x148
    [<00000000210a1bd5>] rawv6_sendmsg+0xb19/0xdfc
    [<00000000f564ad0b>] inet_sendmsg+0x3f/0x82
    [<00000000a0a71539>] sock_sendmsg_nosec+0x18/0x2f
    [<0000000025dbe598>] __sys_sendto+0x102/0x143
    [<000000000f989e54>] __x64_sys_sendto+0x28/0x2c
    [<00000000520e974d>] do_syscall_64+0x5c/0x6e
    [<00000000413f2b33>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
    [<000000005a49f8d9>] 0xffffffffffffffff

unreferenced object 0xffff88812825bc00 (size 1024):
comm "ping6", pid 1160, jiffies 4294811771 (age 119.083s) hex dump (first 32 bytes):
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZZZZZZZZZ
backtrace:

    [<00000000c4c19340>] kmemleak_alloc+0x70/0x94
    [<000000003251fc6a>] slab_post_alloc_hook+0x47/0x5c
    [<000000006cd7857e>] __kmalloc_track_caller+0xfe/0x13f
    [<00000000ebec8a26>] __kmalloc_reserve.isra.17+0x2d/0x6d
    [<00000000827ebff0>] pskb_expand_head+0xcc/0x2d1
    [<0000000034bfc15f>] skb_cow_head+0xae/0xb7
    [<000000008f8c30fc>] bpf_lwt_push_ip_encap+0xb1/0x34c
    [<000000007add911b>] bpf_lwt_xmit_push_encap+0x1d/0x29
    [<00000000eecbf798>] ___bpf_prog_run+0xbc3/0x1757
    [<0000000055e881cc>] __bpf_prog_run64+0x42/0x58
    [<00000000d0c1f29b>] run_lwt_bpf.constprop.4+0xff/0x2e6
    [<00000000b9ad5b04>] bpf_xmit+0x3d/0xef
    [<000000003ba220bf>] lwtunnel_xmit+0xc7/0xeb
    [<000000004c67bd98>] ip6_finish_output2+0x477/0x494
    [<00000000bf642298>] ip6_finish_output+0x106/0x110
    [<00000000365d3055>] ip6_output+0x87/0xbf
#12 lore raw
Quoted 57 lines · David Ahern
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · David Ahern
Quoted 12 lines · Peter Oskolkov

This patchset implements BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap BPF helper. It enables BPF programs (specifically, BPF_PROG_TYPE_LWT_IN and BPF_PROG_TYPE_LWT_XMIT prog types) to add IP encapsulation headers to packets (e.g. IP/GRE, GUE, IPIP).

This is useful when thousands of different short-lived flows should be encapped, each with different and dynamically determined destination. Although lwtunnels can be used in some of these scenarios, the ability to dynamically generate encap headers adds more flexibility, e.g. when routing depends on the state of the host (reflected in global bpf maps).

Quoted 5 lines
Quoted 2 lines

For the set:

Applied. Thanks everyone!

Looks like a cleanup round is needed.

I changed the routes to fail with unreachable:

(quoted diff) +0 -0
@@ -179,16 +175,16 @@
 	ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local

${IPv4_GRE} ttl 255

(quoted diff) +2 -2
 	ip -netns ${NS3} link set gre_dev up
 	ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev
-	ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6}
-	ip -netns ${NS2} route add ${IPv4_GRE}/32 dev veth7 via ${IPv4_8}
+	ip -netns ${NS1} route add unreachable ${IPv4_GRE}/32
+	ip -netns ${NS2} route add unreachable ${IPv4_GRE}/32
 
 
 	# configure IPv6 GRE device in NS3, and a route to it via the "bottom"

route
ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote
${IPv6_1} local ${IPv6_GRE} ttl 255

(quoted diff) +2 -2
 	ip -netns ${NS3} link set gre6_dev up
 	ip -netns ${NS3} -6 addr add ${IPv6_GRE} nodad dev gre6_dev
-	ip -netns ${NS1} -6 route add ${IPv6_GRE}/128 dev veth5 via ${IPv6_6}
-	ip -netns ${NS2} -6 route add ${IPv6_GRE}/128 dev veth7 via ${IPv6_8}
+	ip -netns ${NS1} -6 route add unreachable ${IPv6_GRE}/128
+	ip -netns ${NS2} -6 route add unreachable ${IPv6_GRE}/128
 
 	# rp_filter gets confused by what these tests are doing, so disable it
 	ip netns exec ${NS1} sysctl -wq net.ipv4.conf.all.rp_filter=0
@@ -220,7 +216,6 @@
 
 

and then removed all of the set -e and exit 1's in the script (really should let all of the tests run versus bailing on the first failure).

Quoted 2 lines

With kmemleak enabled I see a lot of suspected memory leaks - some may not be related to this change but it is triggering the suspected leak:

argh. Thanks a lot for catching it.
Let's figure out the fix quickly.
If it's too intrusive we can revert and reapply.
I'm not going to send a pull-req to Dave with a known issue like this.

#13 lore raw
Quoted 56 lines · Alexei Starovoitov
Quoted 54 lines · David Ahern
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · David Ahern
Quoted 12 lines · Peter Oskolkov

This patchset implements BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap BPF helper. It enables BPF programs (specifically, BPF_PROG_TYPE_LWT_IN and BPF_PROG_TYPE_LWT_XMIT prog types) to add IP encapsulation headers to packets (e.g. IP/GRE, GUE, IPIP).

This is useful when thousands of different short-lived flows should be encapped, each with different and dynamically determined destination. Although lwtunnels can be used in some of these scenarios, the ability to dynamically generate encap headers adds more flexibility, e.g. when routing depends on the state of the host (reflected in global bpf maps).

Quoted 5 lines
Quoted 2 lines

For the set:

Applied. Thanks everyone!

Looks like a cleanup round is needed.

I changed the routes to fail with unreachable:

(quoted diff) +0 -0
@@ -179,16 +175,16 @@
      ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local

${IPv4_GRE} ttl 255

      ip -netns ${NS3} link set gre_dev up
      ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev
(quoted diff) +2 -2
-     ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6}
-     ip -netns ${NS2} route add ${IPv4_GRE}/32 dev veth7 via ${IPv4_8}
+     ip -netns ${NS1} route add unreachable ${IPv4_GRE}/32
+     ip -netns ${NS2} route add unreachable ${IPv4_GRE}/32
 
 
      # configure IPv6 GRE device in NS3, and a route to it via the "bottom"

route

      ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote
${IPv6_1} local ${IPv6_GRE} ttl 255
      ip -netns ${NS3} link set gre6_dev up
      ip -netns ${NS3} -6 addr add ${IPv6_GRE} nodad dev gre6_dev
(quoted diff) +2 -2
-     ip -netns ${NS1} -6 route add ${IPv6_GRE}/128 dev veth5 via ${IPv6_6}
-     ip -netns ${NS2} -6 route add ${IPv6_GRE}/128 dev veth7 via ${IPv6_8}
+     ip -netns ${NS1} -6 route add unreachable ${IPv6_GRE}/128
+     ip -netns ${NS2} -6 route add unreachable ${IPv6_GRE}/128
 
      # rp_filter gets confused by what these tests are doing, so disable it
      ip netns exec ${NS1} sysctl -wq net.ipv4.conf.all.rp_filter=0
@@ -220,7 +216,6 @@
 
 
Quoted 8 lines
Quoted 5 lines

and then removed all of the set -e and exit 1's in the script (really should let all of the tests run versus bailing on the first failure).

With kmemleak enabled I see a lot of suspected memory leaks - some may not be related to this change but it is triggering the suspected leak:

argh. Thanks a lot for catching it.
Let's figure out the fix quickly.

Reproduced. Looking.

Quoted 3 lines

If it's too intrusive we can revert and reapply.
I'm not going to send a pull-req to Dave with a known issue like this.

#8 lore raw

Re: [PATCH bpf-next v11 7/7] selftests: bpf: add test_lwt_ip_encap selftest

In reply to Peter Oskolkov
Quoted 67 lines · Peter Oskolkov

This patch adds a bpf self-test to cover BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap.

Covered:
- encapping in LWT_IN and LWT_XMIT
- IPv4 and IPv6

A follow-up patch will add GSO and VRF-enabled tests.

---
 tools/testing/selftests/bpf/Makefile          |   3 +-
 .../selftests/bpf/progs/test_lwt_ip_encap.c   |  85 +++++
 .../selftests/bpf/test_lwt_ip_encap.sh        | 311 ++++++++++++++++++
 3 files changed, 398 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c
 create mode 100755 tools/testing/selftests/bpf/test_lwt_ip_encap.sh
tools/testing/selftests/bpf/Makefile +2 -1
index c3edf47da05d..ccffaa0a0787 100644
@@ -50,7 +50,8 @@ TEST_PROGS := test_kmod.sh \
 	test_lirc_mode2.sh \
 	test_skb_cgroup_id.sh \
 	test_flow_dissector.sh \
-	test_xdp_vlan.sh
+	test_xdp_vlan.sh \
+	test_lwt_ip_encap.sh
 
 TEST_PROGS_EXTENDED := with_addr.sh \
 	with_tunnels.sh \
tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c new file +29 -0
new file mode 100644
index 000000000000..c957d6dfe6d7
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stddef.h>
+#include <string.h>
+#include <linux/bpf.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include "bpf_helpers.h"
+#include "bpf_endian.h"
+
+struct grehdr {
+	__be16 flags;
+	__be16 protocol;
+};
+
+SEC("encap_gre")
+int bpf_lwt_encap_gre(struct __sk_buff *skb)
+{
+	struct encap_hdr {
+		struct iphdr iph;
+		struct grehdr greh;
+	} hdr;
+	int err;
+
+	memset(&hdr, 0, sizeof(struct encap_hdr));
+
+	hdr.iph.ihl = 5;
+	hdr.iph.version = 4;
+	hdr.iph.ttl = 0x40;
+	hdr.iph.protocol = 47;  /* IPPROTO_GRE */

[...]

tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c line 38

Quoted 9 lines
tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c new file +9 -0
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+	hdr.iph.saddr = 0x640110ac;  /* 172.16.1.100 */
+	hdr.iph.daddr = 0x641010ac;  /* 172.16.16.100 */
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+	hdr.iph.saddr = 0xac100164;  /* 172.16.1.100 */
+	hdr.iph.daddr = 0xac101064;  /* 172.16.16.100 */
+#else
+#error "Fix your compiler's __BYTE_ORDER__?!"
+#endif

Nit, why not just:

	hdr.iph.saddr = bpf_htonl(0xac100164);  /* 172.16.1.100 */
	hdr.iph.daddr = bpf_htonl(0xac101064);  /* 172.16.16.100 */

?

Quoted 367 lines
tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c new file +47 -0
+	hdr.iph.tot_len = bpf_htons(skb->len + sizeof(struct encap_hdr));
+
+	hdr.greh.protocol = skb->protocol;
+
+	err = bpf_lwt_push_encap(skb, BPF_LWT_ENCAP_IP, &hdr,
+				 sizeof(struct encap_hdr));
+	if (err)
+		return BPF_DROP;
+
+	return BPF_LWT_REROUTE;
+}
+
+SEC("encap_gre6")
+int bpf_lwt_encap_gre6(struct __sk_buff *skb)
+{
+	struct encap_hdr {
+		struct ipv6hdr ip6hdr;
+		struct grehdr greh;
+	} hdr;
+	int err;
+
+	memset(&hdr, 0, sizeof(struct encap_hdr));
+
+	hdr.ip6hdr.version = 6;
+	hdr.ip6hdr.payload_len = bpf_htons(skb->len + sizeof(struct grehdr));
+	hdr.ip6hdr.nexthdr = 47;  /* IPPROTO_GRE */
+	hdr.ip6hdr.hop_limit = 0x40;
+	/* fb01::1 */
+	hdr.ip6hdr.saddr.s6_addr[0] = 0xfb;
+	hdr.ip6hdr.saddr.s6_addr[1] = 1;
+	hdr.ip6hdr.saddr.s6_addr[15] = 1;
+	/* fb10::1 */
+	hdr.ip6hdr.daddr.s6_addr[0] = 0xfb;
+	hdr.ip6hdr.daddr.s6_addr[1] = 0x10;
+	hdr.ip6hdr.daddr.s6_addr[15] = 1;
+
+	hdr.greh.protocol = skb->protocol;
+
+	err = bpf_lwt_push_encap(skb, BPF_LWT_ENCAP_IP, &hdr,
+				 sizeof(struct encap_hdr));
+	if (err)
+		return BPF_DROP;
+
+	return BPF_LWT_REROUTE;
+}
+
+char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/test_lwt_ip_encap.sh new file +311 -0
new file mode 100755
index 000000000000..4ca714e23ab0
@@ -0,0 +1,311 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Setup/topology:
+#
+#    NS1             NS2             NS3
+#   veth1 <---> veth2   veth3 <---> veth4 (the top route)
+#   veth5 <---> veth6   veth7 <---> veth8 (the bottom route)
+#
+#   each vethN gets IPv[4|6]_N address
+#
+#   IPv*_SRC = IPv*_1
+#   IPv*_DST = IPv*_4
+#
+#   all tests test pings from IPv*_SRC to IPv*_DST
+#
+#   by default, routes are configured to allow packets to go
+#   IP*_1 <=> IP*_2 <=> IP*_3 <=> IP*_4 (the top route)
+#
+#   a GRE device is installed in NS3 with IPv*_GRE, and
+#   NS1/NS2 are configured to route packets to IPv*_GRE via IP*_8
+#   (the bottom route)
+#
+# Tests:
+#
+#   1. routes NS2->IPv*_DST are brought down, so the only way a ping
+#      from IP*_SRC to IP*_DST can work is via IPv*_GRE
+#
+#   2a. in an egress test, a bpf LWT_XMIT program is installed on veth1
+#       that encaps the packets with an IP/GRE header to route to IPv*_GRE
+#
+#       ping: SRC->[encap at veth1:egress]->GRE:decap->DST
+#       ping replies go DST->SRC directly
+#
+#   2b. in an ingress test, a bpf LWT_IN program is installed on veth2
+#       that encaps the packets with an IP/GRE header to route to IPv*_GRE
+#
+#       ping: SRC->[encap at veth2:ingress]->GRE:decap->DST
+#       ping replies go DST->SRC directly
+
+set -e  # exit on error
+
+if [[ $EUID -ne 0 ]]; then
+	echo "This script must be run as root"
+	echo "FAIL"
+	exit 1
+fi
+
+readonly NS1="ns1-$(mktemp -u XXXXXX)"
+readonly NS2="ns2-$(mktemp -u XXXXXX)"
+readonly NS3="ns3-$(mktemp -u XXXXXX)"
+
+readonly IPv4_1="172.16.1.100"
+readonly IPv4_2="172.16.2.100"
+readonly IPv4_3="172.16.3.100"
+readonly IPv4_4="172.16.4.100"
+readonly IPv4_5="172.16.5.100"
+readonly IPv4_6="172.16.6.100"
+readonly IPv4_7="172.16.7.100"
+readonly IPv4_8="172.16.8.100"
+readonly IPv4_GRE="172.16.16.100"
+
+readonly IPv4_SRC=$IPv4_1
+readonly IPv4_DST=$IPv4_4
+
+readonly IPv6_1="fb01::1"
+readonly IPv6_2="fb02::1"
+readonly IPv6_3="fb03::1"
+readonly IPv6_4="fb04::1"
+readonly IPv6_5="fb05::1"
+readonly IPv6_6="fb06::1"
+readonly IPv6_7="fb07::1"
+readonly IPv6_8="fb08::1"
+readonly IPv6_GRE="fb10::1"
+
+readonly IPv6_SRC=$IPv6_1
+readonly IPv6_DST=$IPv6_4
+
+setup() {
+set -e  # exit on error
+	# create devices and namespaces
+	ip netns add "${NS1}"
+	ip netns add "${NS2}"
+	ip netns add "${NS3}"
+
+	ip link add veth1 type veth peer name veth2
+	ip link add veth3 type veth peer name veth4
+	ip link add veth5 type veth peer name veth6
+	ip link add veth7 type veth peer name veth8
+
+	ip netns exec ${NS2} sysctl -wq net.ipv4.ip_forward=1
+	ip netns exec ${NS2} sysctl -wq net.ipv6.conf.all.forwarding=1
+
+	ip link set veth1 netns ${NS1}
+	ip link set veth2 netns ${NS2}
+	ip link set veth3 netns ${NS2}
+	ip link set veth4 netns ${NS3}
+	ip link set veth5 netns ${NS1}
+	ip link set veth6 netns ${NS2}
+	ip link set veth7 netns ${NS2}
+	ip link set veth8 netns ${NS3}
+
+	# configure addesses: the top route (1-2-3-4)
+	ip -netns ${NS1}    addr add ${IPv4_1}/24  dev veth1
+	ip -netns ${NS2}    addr add ${IPv4_2}/24  dev veth2
+	ip -netns ${NS2}    addr add ${IPv4_3}/24  dev veth3
+	ip -netns ${NS3}    addr add ${IPv4_4}/24  dev veth4
+	ip -netns ${NS1} -6 addr add ${IPv6_1}/128 nodad dev veth1
+	ip -netns ${NS2} -6 addr add ${IPv6_2}/128 nodad dev veth2
+	ip -netns ${NS2} -6 addr add ${IPv6_3}/128 nodad dev veth3
+	ip -netns ${NS3} -6 addr add ${IPv6_4}/128 nodad dev veth4
+
+	# configure addresses: the bottom route (5-6-7-8)
+	ip -netns ${NS1}    addr add ${IPv4_5}/24  dev veth5
+	ip -netns ${NS2}    addr add ${IPv4_6}/24  dev veth6
+	ip -netns ${NS2}    addr add ${IPv4_7}/24  dev veth7
+	ip -netns ${NS3}    addr add ${IPv4_8}/24  dev veth8
+	ip -netns ${NS1} -6 addr add ${IPv6_5}/128 nodad dev veth5
+	ip -netns ${NS2} -6 addr add ${IPv6_6}/128 nodad dev veth6
+	ip -netns ${NS2} -6 addr add ${IPv6_7}/128 nodad dev veth7
+	ip -netns ${NS3} -6 addr add ${IPv6_8}/128 nodad dev veth8
+
+
+	ip -netns ${NS1} link set dev veth1 up
+	ip -netns ${NS2} link set dev veth2 up
+	ip -netns ${NS2} link set dev veth3 up
+	ip -netns ${NS3} link set dev veth4 up
+	ip -netns ${NS1} link set dev veth5 up
+	ip -netns ${NS2} link set dev veth6 up
+	ip -netns ${NS2} link set dev veth7 up
+	ip -netns ${NS3} link set dev veth8 up
+
+	# configure routes: IP*_SRC -> veth1/IP*_2 (= top route) default;
+	# the bottom route to specific bottom addresses
+
+	# NS1
+	# top route
+	ip -netns ${NS1}    route add ${IPv4_2}/32  dev veth1
+	ip -netns ${NS1}    route add default dev veth1 via ${IPv4_2}  # go top by default
+	ip -netns ${NS1} -6 route add ${IPv6_2}/128 dev veth1
+	ip -netns ${NS1} -6 route add default dev veth1 via ${IPv6_2}  # go top by default
+	# bottom route
+	ip -netns ${NS1}    route add ${IPv4_6}/32  dev veth5
+	ip -netns ${NS1}    route add ${IPv4_7}/32  dev veth5 via ${IPv4_6}
+	ip -netns ${NS1}    route add ${IPv4_8}/32  dev veth5 via ${IPv4_6}
+	ip -netns ${NS1} -6 route add ${IPv6_6}/128 dev veth5
+	ip -netns ${NS1} -6 route add ${IPv6_7}/128 dev veth5 via ${IPv6_6}
+	ip -netns ${NS1} -6 route add ${IPv6_8}/128 dev veth5 via ${IPv6_6}
+
+	# NS2
+	# top route
+	ip -netns ${NS2}    route add ${IPv4_1}/32  dev veth2
+	ip -netns ${NS2}    route add ${IPv4_4}/32  dev veth3
+	ip -netns ${NS2} -6 route add ${IPv6_1}/128 dev veth2
+	ip -netns ${NS2} -6 route add ${IPv6_4}/128 dev veth3
+	# bottom route
+	ip -netns ${NS2}    route add ${IPv4_5}/32  dev veth6
+	ip -netns ${NS2}    route add ${IPv4_8}/32  dev veth7
+	ip -netns ${NS2} -6 route add ${IPv6_5}/128 dev veth6
+	ip -netns ${NS2} -6 route add ${IPv6_8}/128 dev veth7
+
+	# NS3
+	# top route
+	ip -netns ${NS3}    route add ${IPv4_3}/32  dev veth4
+	ip -netns ${NS3}    route add ${IPv4_1}/32  dev veth4 via ${IPv4_3}
+	ip -netns ${NS3}    route add ${IPv4_2}/32  dev veth4 via ${IPv4_3}
+	ip -netns ${NS3} -6 route add ${IPv6_3}/128 dev veth4
+	ip -netns ${NS3} -6 route add ${IPv6_1}/128 dev veth4 via ${IPv6_3}
+	ip -netns ${NS3} -6 route add ${IPv6_2}/128 dev veth4 via ${IPv6_3}
+	# bottom route
+	ip -netns ${NS3}    route add ${IPv4_7}/32  dev veth8
+	ip -netns ${NS3}    route add ${IPv4_5}/32  dev veth8 via ${IPv4_7}
+	ip -netns ${NS3}    route add ${IPv4_6}/32  dev veth8 via ${IPv4_7}
+	ip -netns ${NS3} -6 route add ${IPv6_7}/128 dev veth8
+	ip -netns ${NS3} -6 route add ${IPv6_5}/128 dev veth8 via ${IPv6_7}
+	ip -netns ${NS3} -6 route add ${IPv6_6}/128 dev veth8 via ${IPv6_7}
+
+	# configure IPv4 GRE device in NS3, and a route to it via the "bottom" route
+	ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local ${IPv4_GRE} ttl 255
+	ip -netns ${NS3} link set gre_dev up
+	ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev
+	ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6}
+	ip -netns ${NS2} route add ${IPv4_GRE}/32 dev veth7 via ${IPv4_8}
+
+
+	# configure IPv6 GRE device in NS3, and a route to it via the "bottom" route
+	ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote ${IPv6_1} local ${IPv6_GRE} ttl 255
+	ip -netns ${NS3} link set gre6_dev up
+	ip -netns ${NS3} -6 addr add ${IPv6_GRE} nodad dev gre6_dev
+	ip -netns ${NS1} -6 route add ${IPv6_GRE}/128 dev veth5 via ${IPv6_6}
+	ip -netns ${NS2} -6 route add ${IPv6_GRE}/128 dev veth7 via ${IPv6_8}
+
+	# rp_filter gets confused by what these tests are doing, so disable it
+	ip netns exec ${NS1} sysctl -wq net.ipv4.conf.all.rp_filter=0
+	ip netns exec ${NS2} sysctl -wq net.ipv4.conf.all.rp_filter=0
+	ip netns exec ${NS3} sysctl -wq net.ipv4.conf.all.rp_filter=0
+}
+
+cleanup() {
+	ip netns del ${NS1} 2> /dev/null
+	ip netns del ${NS2} 2> /dev/null
+	ip netns del ${NS3} 2> /dev/null
+}
+
+trap cleanup EXIT
+
+test_ping() {
+	local readonly PROTO=$1
+	local readonly EXPECTED=$2
+	local RET=0
+
+	set +e
+	if [ "${PROTO}" == "IPv4" ] ; then
+		ip netns exec ${NS1} ping  -c 1 -W 1 -I ${IPv4_SRC} ${IPv4_DST} 2>&1 > /dev/null
+		RET=$?
+	elif [ "${PROTO}" == "IPv6" ] ; then
+		ip netns exec ${NS1} ping6 -c 1 -W 6 -I ${IPv6_SRC} ${IPv6_DST} 2>&1 > /dev/null
+		RET=$?
+	else
+		echo "test_ping: unknown PROTO: ${PROTO}"
+		exit 1
+	fi
+	set -e
+
+	if [ "0" != "${RET}" ]; then
+		RET=1
+	fi
+
+	if [ "${EXPECTED}" != "${RET}" ] ; then
+		echo "FAIL: test_ping: ${RET}"
+		exit 1
+	fi
+}
+
+test_egress() {
+	local readonly ENCAP=$1
+	echo "starting egress ${ENCAP} encap test"
+	setup
+
+	# need to wait a bit for IPv6 to autoconf, otherwise
+	# ping6 sometimes fails with "unable to bind to address"
+
+	# by default, pings work
+	test_ping IPv4 0
+	test_ping IPv6 0
+
+	# remove NS2->DST routes, ping fails
+	ip -netns ${NS2}    route del ${IPv4_DST}/32  dev veth3
+	ip -netns ${NS2} -6 route del ${IPv6_DST}/128 dev veth3
+	test_ping IPv4 1
+	test_ping IPv6 1
+
+	# install replacement routes (LWT/eBPF), pings succeed
+	if [ "${ENCAP}" == "IPv4" ] ; then
+		ip -netns ${NS1} route add ${IPv4_DST} encap bpf xmit obj test_lwt_ip_encap.o sec encap_gre dev veth1
+		ip -netns ${NS1} -6 route add ${IPv6_DST} encap bpf xmit obj test_lwt_ip_encap.o sec encap_gre dev veth1
+	elif [ "${ENCAP}" == "IPv6" ] ; then
+		ip -netns ${NS1} route add ${IPv4_DST} encap bpf xmit obj test_lwt_ip_encap.o sec encap_gre6 dev veth1
+		ip -netns ${NS1} -6 route add ${IPv6_DST} encap bpf xmit obj test_lwt_ip_encap.o sec encap_gre6 dev veth1
+	else
+		echo "FAIL: unknown encap ${ENCAP}"
+	fi
+	test_ping IPv4 0
+	test_ping IPv6 0
+
+	cleanup
+	echo "PASS"
+}
+
+test_ingress() {
+	local readonly ENCAP=$1
+	echo "starting ingress ${ENCAP} encap test"
+	setup
+
+	# need to wait a bit for IPv6 to autoconf, otherwise
+	# ping6 sometimes fails with "unable to bind to address"
+
+	# by default, pings work
+	test_ping IPv4 0
+	test_ping IPv6 0
+
+	# remove NS2->DST routes, pings fail
+	ip -netns ${NS2}    route del ${IPv4_DST}/32  dev veth3
+	ip -netns ${NS2} -6 route del ${IPv6_DST}/128 dev veth3
+	test_ping IPv4 1
+	test_ping IPv6 1
+
+	# install replacement routes (LWT/eBPF), pings succeed
+	if [ "${ENCAP}" == "IPv4" ] ; then
+		ip -netns ${NS2} route add ${IPv4_DST} encap bpf in obj test_lwt_ip_encap.o sec encap_gre dev veth2
+		ip -netns ${NS2} -6 route add ${IPv6_DST} encap bpf in obj test_lwt_ip_encap.o sec encap_gre dev veth2
+	elif [ "${ENCAP}" == "IPv6" ] ; then
+		ip -netns ${NS2} route add ${IPv4_DST} encap bpf in obj test_lwt_ip_encap.o sec encap_gre6 dev veth2
+		ip -netns ${NS2} -6 route add ${IPv6_DST} encap bpf in obj test_lwt_ip_encap.o sec encap_gre6 dev veth2
+	else
+		echo "FAIL: unknown encap ${ENCAP}"
+	fi
+	test_ping IPv4 0
+	test_ping IPv6 0
+
+	cleanup
+	echo "PASS"
+}
+
+test_egress IPv4
+test_egress IPv6
+
+test_ingress IPv4
+test_ingress IPv6
+
+echo "all tests passed"
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#14 lore raw
In reply to Alexei Starovoitov
Quoted 56 lines · Alexei Starovoitov
Quoted 54 lines · David Ahern
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · David Ahern
Quoted 12 lines · Peter Oskolkov

This patchset implements BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap BPF helper. It enables BPF programs (specifically, BPF_PROG_TYPE_LWT_IN and BPF_PROG_TYPE_LWT_XMIT prog types) to add IP encapsulation headers to packets (e.g. IP/GRE, GUE, IPIP).

This is useful when thousands of different short-lived flows should be encapped, each with different and dynamically determined destination. Although lwtunnels can be used in some of these scenarios, the ability to dynamically generate encap headers adds more flexibility, e.g. when routing depends on the state of the host (reflected in global bpf maps).

Quoted 5 lines
Quoted 2 lines

For the set:

Applied. Thanks everyone!

Looks like a cleanup round is needed.

I changed the routes to fail with unreachable:

(quoted diff) +0 -0
@@ -179,16 +175,16 @@
      ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local

${IPv4_GRE} ttl 255

      ip -netns ${NS3} link set gre_dev up
      ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev
(quoted diff) +2 -2
-     ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6}
-     ip -netns ${NS2} route add ${IPv4_GRE}/32 dev veth7 via ${IPv4_8}
+     ip -netns ${NS1} route add unreachable ${IPv4_GRE}/32
+     ip -netns ${NS2} route add unreachable ${IPv4_GRE}/32
 
 
      # configure IPv6 GRE device in NS3, and a route to it via the "bottom"

route

      ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote
${IPv6_1} local ${IPv6_GRE} ttl 255
      ip -netns ${NS3} link set gre6_dev up
      ip -netns ${NS3} -6 addr add ${IPv6_GRE} nodad dev gre6_dev
(quoted diff) +2 -2
-     ip -netns ${NS1} -6 route add ${IPv6_GRE}/128 dev veth5 via ${IPv6_6}
-     ip -netns ${NS2} -6 route add ${IPv6_GRE}/128 dev veth7 via ${IPv6_8}
+     ip -netns ${NS1} -6 route add unreachable ${IPv6_GRE}/128
+     ip -netns ${NS2} -6 route add unreachable ${IPv6_GRE}/128
 
      # rp_filter gets confused by what these tests are doing, so disable it
      ip netns exec ${NS1} sysctl -wq net.ipv4.conf.all.rp_filter=0
@@ -220,7 +216,6 @@
 
 
Quoted 8 lines
Quoted 5 lines

and then removed all of the set -e and exit 1's in the script (really should let all of the tests run versus bailing on the first failure).

With kmemleak enabled I see a lot of suspected memory leaks - some may not be related to this change but it is triggering the suspected leak:

argh. Thanks a lot for catching it.
Let's figure out the fix quickly.

Sent a fix: https://patchwork.ozlabs.org/patch/1041836/
Sorry about that.

Quoted 3 lines

If it's too intrusive we can revert and reapply.
I'm not going to send a pull-req to Dave with a known issue like this.