Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device
@ 2026-11-26 21:37 Vincent Jardin via B4 Relay
  2026-11-26 21:37 ` [PATCH net-next 1/5] lisp: add LISP (Locator/ID Separation Protocol) Vincent Jardin via B4 Relay
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-26 21:37 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Vincent Jardin, Donald Hunter, Nicolas Dichtel,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Shuah Khan
  Cc: linux-kernel, netdev, linux-doc, linux-kselftest

LISP (Locator/ID Separation Protocol, RFC 9300) carries the packets sent
to an endpoint identifier (EID) over UDP, to a routing locator (RLOC) of
the site of that EID. An EID prefix and its RLOCs are a mapping, which
the LISP control plane (RFC 9301) provides.

This series adds the data plane of a LISP router (xTR): a tunnel device,
link kind "lisp", for IPv4 and IPv6 EIDs over IPv4 and IPv6 RLOCs.

A mapping is a route. The device takes the RLOC of a packet from its
tunnel metadata, which the lwtunnel encapsulation of the route
or of its nexthop provides. A remote site is a nexthop, shared by its
EID prefixes:

  ip link add link wan name lisp101 type lisp id 101 local 192.0.2.1
  ip link set lisp101 master site up
  ip -6 nexthop add id 1 encap ip dst 198.51.100.1 dev lisp101
  ip route add 10.2.0.0/24 vrf site nhid 1
  ip -6 route add 2001:db8:2::/48 vrf site nhid 1

Design:

- The kernel has no map-cache and it does not resolve anything: no
  upcall, no state that the packets of a host create. Its tables are the
  routes and the nexthops, which a control plane in user space writes,
  as it does for any other routing protocol. A packet without RLOC ends
  up dropped.

- A remote site is a nexthop object, not a device: it has been designed
  to scale.

- The common UDP tunnel code is used: its sockets, GRO cells, GSO, the
  dst cache of the encapsulation, and a zero UDP checksum unless the
  encapsulation asks for one.

Note: a LISP driver was posted to netdev back to 2014 and was not
merged. It had a device per remote RLOC and IPv4 RLOCs only, and a
map-cache that traffic fills was not accepted.
lwtunnels is an alternative.

This design shall allow routing daemons like FRRouting to support LISP.

Patches:
- patch 1 adds the driver, drivers/net/lisp.c, and its link attributes
- patch 2 describes them in the rt-link netlink spec
- patch 3 adds Documentation/networking/lisp.rst
- patch 4 adds a selftest, lisp.sh
- patch 5 adds a scale selftest, lisp_scale.sh

The series only adds: no existing code path is changed.

The lisp link type of iproute2 comes as a separate series, for
iproute2-next. Tests are skipped without it. Tell me if you want
iproute2 series too for a simultaneous review.

---
Vincent Jardin (5):
      lisp: add LISP (Locator/ID Separation Protocol)
      netlink: specs: rt-link: add the lisp link type
      docs: net: document the LISP devices
      selftests: net: add a test of the LISP devices
      selftests: net: add a scale test for LISP

 Documentation/netlink/specs/rt-link.yaml  |   35 +
 Documentation/networking/index.rst        |    1 +
 Documentation/networking/lisp.rst         |  142 ++++
 MAINTAINERS                               |    8 +
 drivers/net/Kconfig                       |   20 +
 drivers/net/Makefile                      |    1 +
 drivers/net/lisp.c                        | 1033 ++++++++++++++++++++++++++
 include/uapi/linux/if_link.h              |   12 +
 tools/testing/selftests/net/Makefile      |    2 +
 tools/testing/selftests/net/config        |    4 +
 tools/testing/selftests/net/lisp.sh       | 1120 +++++++++++++++++++++++++++++
 tools/testing/selftests/net/lisp_scale.sh |  532 ++++++++++++++
 12 files changed, 2910 insertions(+)
---
base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
change-id: 20261126-for-upstream-lisp-v1-b47ac698d026

Best regards,
-- 
Vincent Jardin <vjardin@free.fr>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 1/5] lisp: add LISP (Locator/ID Separation Protocol)
  2026-11-26 21:37 [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Vincent Jardin via B4 Relay
@ 2026-11-26 21:37 ` Vincent Jardin via B4 Relay
  2026-11-26 21:37 ` [PATCH net-next 2/5] netlink: specs: rt-link: add the lisp link type Vincent Jardin via B4 Relay
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-26 21:37 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Vincent Jardin, Donald Hunter, Nicolas Dichtel,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Shuah Khan
  Cc: linux-kernel, netdev, linux-doc, linux-kselftest

From: Vincent Jardin <vjardin@free.fr>

LISP (RFC 9300) carries the packets sent to an endpoint identifier
(EID) over UDP, to a routing locator (RLOC) of the site of that EID.
An EID prefix and its RLOCs are a mapping, which the LISP control
plane (RFC 9301) provides.

The data plane of a LISP router (xTR) is a tunnel device. It sends
IPv4 and IPv6 packets with a LISP header over UDP (port 4341).

A mapping is a route. The kernel takes the RLOC of a packet from its
tunnel metadata, which the lightweight tunnel encapsulation of the
route or of its nexthop provides:
  "encap ip" for an IPv4 RLOC
  "encap ip6" for an IPv6 one
whatever the family of the EID prefix.

Example:
  ip link add lisp101 type lisp id 101 local 192.0.2.1
  ip link set lisp101 master site up
  ip -6 nexthop add id 1 encap ip dst 198.51.100.1 dev lisp101
  ip route add 10.2.0.0/24 vrf site nhid 1
  ip -6 route add 2001:db8:2::/48 vrf site nhid 1

The kernel has no map-cache and it does not resolve anything: it holds
no state that the packets of a host create. The routes and the nexthops
come from a control plane, in user space, as those of any other routing
protocol. A packet without RLOC ends up dropped.

A remote site is a nexthop, shared by its EID prefixes.

Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
 MAINTAINERS                  |    6 +
 drivers/net/Kconfig          |   19 +
 drivers/net/Makefile         |    1 +
 drivers/net/lisp.c           | 1033 ++++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/if_link.h |   12 +
 5 files changed, 1071 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 97308edec53dd..6b62bc1f45bae 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15506,6 +15506,12 @@ F:	Documentation/misc-devices/lis3lv02d.rst
 F:	drivers/misc/lis3lv02d/
 F:	drivers/platform/x86/hp/hp_accel.c
 
+LISP DATA PLANE DRIVER
+M:	Vincent Jardin <vjardin@free.fr>
+L:	netdev@vger.kernel.org
+S:	Maintained
+F:	drivers/net/lisp.c
+
 LIST KUNIT TEST
 M:	David Gow <david@davidgow.net>
 L:	linux-kselftest@vger.kernel.org
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index ff79c466712df..aa78fd48e77a9 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -269,6 +269,25 @@ config BAREUDP
 	  To compile this driver as a module, choose M here: the module
 	  will be called bareudp.
 
+config LISP
+	tristate "Locator/ID Separation Protocol (LISP) data plane"
+	depends on INET
+	select NET_UDP_TUNNEL
+	select GRO_CELLS
+	select LWTUNNEL
+	help
+	  This adds the data plane of the Locator/ID Separation Protocol
+	  (LISP, RFC 9300): a tunnel device that carries the IPv4 and IPv6
+	  packets of an instance ID over UDP, to the routing locator (RLOC)
+	  that the route or the nexthop of their destination gives as a
+	  lightweight tunnel encapsulation.
+
+	  The mappings of the destinations to the RLOCs come from user space,
+	  from a LISP control plane or from the configuration.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called lisp.
+
 config GTP
 	tristate "GPRS Tunneling Protocol datapath (GTP-U)"
 	depends on INET
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 88e4c485d6b2f..e7a521ac8b97d 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VXLAN) += vxlan/
 obj-$(CONFIG_GENEVE) += geneve.o
 obj-$(CONFIG_BAREUDP) += bareudp.o
+obj-$(CONFIG_LISP) += lisp.o
 obj-$(CONFIG_GTP) += gtp.o
 obj-$(CONFIG_NLMON) += nlmon.o
 obj-$(CONFIG_PFCP) += pfcp.o
diff --git a/drivers/net/lisp.c b/drivers/net/lisp.c
new file mode 100644
index 0000000000000..8f5a79c88b2c1
--- /dev/null
+++ b/drivers/net/lisp.c
@@ -0,0 +1,1033 @@
+// SPDX-License-Identifier: GPL-2.0
+/* LISP: data plane of the Locator/ID Separation Protocol, RFC 9300.
+ *
+ * Copyright (c) 2026 Vincent Jardin <vjardin@free.fr>, Free Mobile
+ */
+
+#include <linux/hash.h>
+#include <linux/icmp.h>
+#include <linux/icmpv6.h>
+#include <linux/if_arp.h>
+#include <linux/ipv6.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/netdevice.h>
+#include <linux/rculist.h>
+#include <net/dsfield.h>
+#include <net/dst_metadata.h>
+#include <net/gro_cells.h>
+#include <net/gso.h>
+#include <net/icmp.h>
+#include <net/inet_ecn.h>
+#include <net/ip6_route.h>
+#include <net/ip_tunnels.h>
+#include <net/ipv6.h>
+#include <net/l3mdev.h>
+#include <net/netns/generic.h>
+#include <net/rtnetlink.h>
+#include <net/udp_tunnel.h>
+
+/* RFC 9300, section 5.1 */
+#define LISP_UDP_PORT		4341
+
+/* RFC 9300, section 5.3 */
+struct lisphdr {
+	u8	flags;
+	u8	nonce[3];
+	__be32	iid_lsb;
+};
+
+#define LISP_F_I		0x08	/* an instance ID is present */
+#define LISP_F_KK		0x03	/* the payload is encrypted, RFC 8061 */
+#define LISP_IID_SHIFT		8
+#define LISP_IID_MAX		0xffffff
+
+#define LISP_BASE_HLEN		(sizeof(struct udphdr) + sizeof(struct lisphdr))
+#define LISP_IPV4_HLEN		(sizeof(struct iphdr) + LISP_BASE_HLEN)
+#define LISP_IPV6_HLEN		(sizeof(struct ipv6hdr) + LISP_BASE_HLEN)
+
+#define LISP_IID_HASH_BITS	10
+#define LISP_IID_HASH_SIZE	BIT(LISP_IID_HASH_BITS)
+
+static unsigned int lisp_net_id;
+
+struct lisp_net {
+	struct list_head	dev_list;
+	struct list_head	sock_list;
+	/* protects the two lists, and the devices of the sockets */
+	struct mutex		lock;
+};
+
+struct lisp_dev;
+
+/* The UDP sockets of an l3mdev, shared by the devices that use it. */
+struct lisp_sock {
+	struct sock		*sk4;
+	struct sock		*sk6;
+	struct lisp_dev __rcu	*md_dev;
+	struct list_head	list;
+	struct rcu_head		rcu;
+	int			refcnt;
+	struct hlist_head	iid_list[LISP_IID_HASH_SIZE];
+};
+
+struct lisp_dev {
+	struct hlist_node	hlist;
+	struct list_head	next;
+	struct net		*net;	/* netns of the RLOCs */
+	struct net_device	*dev;
+	struct lisp_sock __rcu	*sock;
+	struct gro_cells	gro_cells;
+	struct in6_addr		local6;
+	__be32			local;
+	u32			iid;
+	int			link;
+	bool			collect_md;
+};
+
+static struct hlist_head *lisp_iid_head(struct lisp_sock *ls, u32 iid)
+{
+	return &ls->iid_list[hash_32(iid, LISP_IID_HASH_BITS)];
+}
+
+static struct lisp_dev *lisp_lookup(struct lisp_sock *ls, u32 iid)
+{
+	struct lisp_dev *lisp;
+
+	/* A device that left for another socket may still be walked here. */
+	hlist_for_each_entry_rcu(lisp, lisp_iid_head(ls, iid), hlist)
+		if (lisp->iid == iid && rcu_access_pointer(lisp->sock) == ls)
+			return lisp;
+
+	return rcu_dereference(ls->md_dev);
+}
+
+/* RFC 9300, section 5.3: the inner header gets the congestion indication and
+ * the DSCP of the outer header, and its TTL when that one is lower.
+ */
+static int lisp_decap_fields(struct sk_buff *skb, u8 tos, u8 ttl)
+{
+	u8 dscp = tos & ~INET_ECN_MASK;
+	struct ipv6hdr *ip6h;
+	struct iphdr *iph;
+
+	if (skb->protocol == htons(ETH_P_IP)) {
+		if (skb_ensure_writable(skb, sizeof(*iph)))
+			return -ENOMEM;
+
+		iph = ip_hdr(skb);
+		if (INET_ECN_decapsulate(skb, tos, iph->tos) > 1)
+			return -EINVAL;
+
+		ipv4_change_dsfield(iph, INET_ECN_MASK, dscp);
+		if (ttl < iph->ttl) {
+			csum_replace2(&iph->check, htons(iph->ttl << 8),
+				      htons(ttl << 8));
+			iph->ttl = ttl;
+		}
+		return 0;
+	}
+
+	if (skb_ensure_writable(skb, sizeof(*ip6h)))
+		return -ENOMEM;
+
+	ip6h = ipv6_hdr(skb);
+	if (INET_ECN_decapsulate(skb, tos, ipv6_get_dsfield(ip6h)) > 1)
+		return -EINVAL;
+
+	if (ttl >= ip6h->hop_limit &&
+	    dscp == (ipv6_get_dsfield(ip6h) & ~INET_ECN_MASK))
+		return 0;
+
+	skb_postpull_rcsum(skb, ip6h, sizeof(*ip6h));
+	ipv6_change_dsfield(ip6h, INET_ECN_MASK, dscp);
+	if (ttl < ip6h->hop_limit)
+		ip6h->hop_limit = ttl;
+	skb_postpush_rcsum(skb, ip6h, sizeof(*ip6h));
+
+	return 0;
+}
+
+static int lisp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
+{
+	unsigned short family = AF_INET6;
+	struct metadata_dst *tun_dst;
+	const struct lisphdr *lh;
+	struct lisp_sock *ls;
+	struct lisp_dev *lisp;
+	unsigned int len;
+	__be16 proto;
+	u32 iid = 0;
+	u8 tos, ttl;
+	int err;
+
+	ls = rcu_dereference_sk_user_data(sk);
+	if (!ls)
+		goto drop;
+
+	if (!pskb_may_pull(skb, LISP_BASE_HLEN + 1))
+		goto drop;
+
+	lh = (const struct lisphdr *)(udp_hdr(skb) + 1);
+	if (lh->flags & LISP_F_KK)
+		goto drop;
+
+	if (lh->flags & LISP_F_I)
+		iid = be32_to_cpu(lh->iid_lsb) >> LISP_IID_SHIFT;
+
+	lisp = lisp_lookup(ls, iid);
+	if (!lisp)
+		goto drop;
+
+	switch (*(const u8 *)(lh + 1) >> 4) {
+	case 4:
+		proto = htons(ETH_P_IP);
+		break;
+	case 6:
+		if (!ipv6_mod_enabled())
+			goto rx_dropped;
+		proto = htons(ETH_P_IPV6);
+		break;
+	default:
+		goto rx_frame_error;
+	}
+
+	if (skb->protocol == htons(ETH_P_IP)) {
+		family = AF_INET;
+		tos = ip_hdr(skb)->tos;
+		ttl = ip_hdr(skb)->ttl;
+	} else {
+		tos = ipv6_get_dsfield(ipv6_hdr(skb));
+		ttl = ipv6_hdr(skb)->hop_limit;
+	}
+
+	if (iptunnel_pull_header(skb, LISP_BASE_HLEN, proto,
+				 !net_eq(lisp->net, dev_net(lisp->dev))))
+		goto rx_dropped;
+
+	if (lisp->collect_md) {
+		IP_TUNNEL_DECLARE_FLAGS(flags) = { };
+
+		__set_bit(IP_TUNNEL_KEY_BIT, flags);
+		tun_dst = udp_tun_rx_dst(skb, family, flags,
+					 key32_to_tunnel_id(cpu_to_be32(iid)),
+					 0);
+		if (!tun_dst)
+			goto rx_dropped;
+
+		skb_dst_set(skb, &tun_dst->dst);
+	}
+
+	skb->dev = lisp->dev;
+	skb_reset_mac_header(skb);
+	skb_reset_network_header(skb);
+
+	if (!pskb_inet_may_pull(skb)) {
+		DEV_STATS_INC(lisp->dev, rx_length_errors);
+		DEV_STATS_INC(lisp->dev, rx_errors);
+		goto drop;
+	}
+
+	err = lisp_decap_fields(skb, tos, ttl);
+	if (err == -ENOMEM)
+		goto rx_dropped;
+	if (err)
+		goto rx_frame_error;
+
+	len = skb->len;
+	if (gro_cells_receive(&lisp->gro_cells, skb) == NET_RX_SUCCESS)
+		dev_dstats_rx_add(lisp->dev, len);
+
+	return 0;
+
+rx_frame_error:
+	DEV_STATS_INC(lisp->dev, rx_frame_errors);
+	DEV_STATS_INC(lisp->dev, rx_errors);
+	goto drop;
+rx_dropped:
+	dev_dstats_rx_dropped(lisp->dev);
+drop:
+	kfree_skb(skb);
+	return 0;
+}
+
+static int lisp_udp_encap_err_lookup(struct sock *sk, struct sk_buff *skb)
+{
+	return 0;
+}
+
+static struct sock *lisp_udp_sock(struct net *net, int ifindex,
+				  unsigned short family, struct lisp_sock *ls)
+{
+	struct udp_tunnel_sock_cfg tunnel_cfg = { };
+	struct udp_port_cfg udp_conf = { };
+	struct socket *sock;
+	int err;
+
+	udp_conf.family = family;
+	udp_conf.ipv6_v6only = family == AF_INET6;
+	udp_conf.local_udp_port = htons(LISP_UDP_PORT);
+	udp_conf.bind_ifindex = ifindex;
+
+	err = udp_sock_create(net, &udp_conf, &sock);
+	if (err < 0)
+		return ERR_PTR(err);
+
+	udp_allow_gso(sock->sk);
+
+	tunnel_cfg.sk_user_data = ls;
+	tunnel_cfg.encap_type = 1;
+	tunnel_cfg.encap_rcv = lisp_udp_encap_recv;
+	tunnel_cfg.encap_err_lookup = lisp_udp_encap_err_lookup;
+	setup_udp_tunnel_sock(net, sock->sk, &tunnel_cfg);
+
+	return sock->sk;
+}
+
+static void lisp_sock_release(struct lisp_sock *ls)
+{
+	udp_tunnel_sock_release(ls->sk4);
+	if (ls->sk6)
+		udp_tunnel_sock_release(ls->sk6);
+	kfree_rcu(ls, rcu);
+}
+
+/* A socket per family, as vxlan and geneve have: an IPv6 socket only takes
+ * the IPv4 packets too when net.ipv6.bindv6only allows it.
+ */
+static struct lisp_sock *lisp_sock_create(struct net *net, int ifindex)
+{
+	struct lisp_sock *ls;
+	struct sock *sk;
+
+	ls = kzalloc_obj(*ls);
+	if (!ls)
+		return ERR_PTR(-ENOMEM);
+
+	ls->refcnt = 1;
+
+	sk = lisp_udp_sock(net, ifindex, AF_INET, ls);
+	if (IS_ERR(sk)) {
+		kfree(ls);
+		return ERR_CAST(sk);
+	}
+	ls->sk4 = sk;
+
+	if (!ipv6_mod_enabled())
+		return ls;
+
+	sk = lisp_udp_sock(net, ifindex, AF_INET6, ls);
+	if (IS_ERR(sk)) {
+		lisp_sock_release(ls);
+		return ERR_CAST(sk);
+	}
+	ls->sk6 = sk;
+
+	return ls;
+}
+
+static bool lisp_sock_busy(struct lisp_sock *ls, const struct lisp_dev *lisp)
+{
+	const struct lisp_dev *tmp;
+
+	if (lisp->collect_md)
+		return rcu_access_pointer(ls->md_dev);
+
+	hlist_for_each_entry(tmp, lisp_iid_head(ls, lisp->iid), hlist)
+		if (tmp->iid == lisp->iid)
+			return true;
+
+	return false;
+}
+
+/* The l3mdev of the RLOCs: the link, or the one that the link is in. */
+static int lisp_l3mdev(const struct lisp_dev *lisp)
+{
+	if (!lisp->link)
+		return 0;
+
+	return l3mdev_master_upper_ifindex_by_index(lisp->net, lisp->link);
+}
+
+static int lisp_open(struct net_device *dev)
+{
+	struct lisp_dev *lisp = netdev_priv(dev);
+	struct lisp_sock *ls, *found = NULL;
+	struct lisp_net *ln;
+	int ifindex;
+	int err = 0;
+
+	ifindex = lisp_l3mdev(lisp);
+
+	ln = net_generic(lisp->net, lisp_net_id);
+	mutex_lock(&ln->lock);
+
+	list_for_each_entry(ls, &ln->sock_list, list) {
+		if (ls->sk4->sk_bound_dev_if == ifindex) {
+			found = ls;
+			break;
+		}
+	}
+
+	if (found) {
+		if (lisp_sock_busy(found, lisp)) {
+			err = -EBUSY;
+			goto unlock;
+		}
+		found->refcnt++;
+	} else {
+		found = lisp_sock_create(lisp->net, ifindex);
+		if (IS_ERR(found)) {
+			err = PTR_ERR(found);
+			goto unlock;
+		}
+		list_add(&found->list, &ln->sock_list);
+	}
+
+	rcu_assign_pointer(lisp->sock, found);
+	if (lisp->collect_md)
+		rcu_assign_pointer(found->md_dev, lisp);
+	else
+		hlist_add_head_rcu(&lisp->hlist,
+				   lisp_iid_head(found, lisp->iid));
+
+unlock:
+	mutex_unlock(&ln->lock);
+	return err;
+}
+
+static int lisp_stop(struct net_device *dev)
+{
+	struct lisp_dev *lisp = netdev_priv(dev);
+	struct lisp_sock *ls;
+	struct lisp_net *ln;
+
+	ln = net_generic(lisp->net, lisp_net_id);
+	mutex_lock(&ln->lock);
+
+	ls = rcu_dereference_protected(lisp->sock, lockdep_is_held(&ln->lock));
+	RCU_INIT_POINTER(lisp->sock, NULL);
+	if (lisp->collect_md)
+		RCU_INIT_POINTER(ls->md_dev, NULL);
+	else
+		hlist_del_rcu(&lisp->hlist);
+
+	if (--ls->refcnt) {
+		mutex_unlock(&ln->lock);
+		return 0;
+	}
+
+	list_del(&ls->list);
+	mutex_unlock(&ln->lock);
+
+	lisp_sock_release(ls);
+
+	return 0;
+}
+
+/* RFC 9300, section 7.2: the sender of a packet that does not fit the path to
+ * the RLOC is told what fits, whatever its DF bit. It cannot be told less
+ * than the minimum MTU of its protocol: what is not larger is then sent in
+ * an outer packet that may be fragmented.
+ */
+static int lisp_check_pmtu(struct sk_buff *skb, const struct dst_entry *dst,
+			   unsigned int hlen, bool *frag)
+{
+	int min_mtu = skb->protocol == htons(ETH_P_IPV6) ? IPV6_MIN_MTU :
+							   IPV4_MIN_MTU;
+	int room = dst_mtu(dst) - hlen;
+	u32 mtu = max(room, min_mtu);
+
+	*frag = room < min_mtu;
+
+	if (skb_is_gso(skb) ? skb_gso_validate_network_len(skb, mtu) :
+			      skb->len <= mtu)
+		return 0;
+
+	skb_dst_update_pmtu_no_confirm(skb, mtu);
+
+	if (skb->protocol == htons(ETH_P_IP))
+		icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
+			      htonl(mtu));
+	else
+		icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
+
+	return -EMSGSIZE;
+}
+
+/* RFC 9300, section 5.3: the outer header gets the DSCP and the TTL of the
+ * inner header, unless the tunnel metadata sets them.
+ */
+static u8 lisp_encap_dsfield(const struct sk_buff *skb,
+			     const struct ip_tunnel_key *key)
+{
+	return key->tos ? : ip_tunnel_get_dsfield(ip_hdr(skb), skb);
+}
+
+static void lisp_encap_fields(const struct sk_buff *skb,
+			      const struct ip_tunnel_key *key, u8 dsfield,
+			      u8 *tos, u8 *ttl)
+{
+	const struct iphdr *iph = ip_hdr(skb);
+
+	*tos = ip_tunnel_ecn_encap(dsfield, iph, skb);
+	*ttl = key->ttl ? : ip_tunnel_get_ttl(iph, skb);
+}
+
+/* The route to the RLOC is the one of the DSCP of the outer header. The one
+ * that the encapsulation caches was looked up with its own DSCP.
+ */
+static struct dst_cache *lisp_dst_cache(const struct sk_buff *skb,
+					const struct ip_tunnel_info *info,
+					u8 dsfield)
+{
+	if (((dsfield ^ info->key.tos) & ~INET_ECN_MASK) ||
+	    !ip_tunnel_dst_cache_usable(skb, info))
+		return NULL;
+
+	return (struct dst_cache *)&info->dst_cache;
+}
+
+static int lisp_build_skb(struct sk_buff *skb, const struct dst_entry *dst,
+			  unsigned int hlen, u32 iid, bool udp_sum)
+{
+	struct lisphdr *lh;
+	int err;
+
+	err = skb_cow_head(skb, LL_RESERVED_SPACE(dst_dev(dst)) +
+			   dst->header_len + hlen);
+	if (unlikely(err))
+		return err;
+
+	err = udp_tunnel_handle_offloads(skb, udp_sum);
+	if (err)
+		return err;
+
+	lh = __skb_push(skb, sizeof(*lh));
+	memset(lh, 0, sizeof(*lh));
+	if (iid) {
+		lh->flags = LISP_F_I;
+		lh->iid_lsb = cpu_to_be32(iid << LISP_IID_SHIFT);
+	}
+	skb_set_inner_protocol(skb, skb->protocol);
+
+	return 0;
+}
+
+static int lisp_xmit_skb(struct sk_buff *skb, struct net_device *dev,
+			 struct sock *sk, const struct ip_tunnel_info *info,
+			 u32 iid)
+{
+	bool udp_sum = test_bit(IP_TUNNEL_CSUM_BIT, info->key.tun_flags);
+	const struct lisp_dev *lisp = netdev_priv(dev);
+	bool xnet = !net_eq(lisp->net, dev_net(dev));
+	const struct ip_tunnel_key *key = &info->key;
+	u8 dsfield = lisp_encap_dsfield(skb, key);
+	struct ip_tunnel_key local_key;
+	struct rtable *rt;
+	__be16 sport;
+	__be32 saddr;
+	u8 tos, ttl;
+	bool frag;
+	int err;
+
+	if (!key->u.ipv4.src && lisp->local) {
+		local_key = *key;
+		local_key.u.ipv4.src = lisp->local;
+		key = &local_key;
+	}
+
+	sport = udp_flow_src_port(lisp->net, skb, 0, 0, false);
+	rt = udp_tunnel_dst_lookup(skb, dev, lisp->net, lisp->link, &saddr,
+				   key, sport, htons(LISP_UDP_PORT), dsfield,
+				   lisp_dst_cache(skb, info, dsfield));
+	if (IS_ERR(rt))
+		return PTR_ERR(rt);
+
+	err = lisp_check_pmtu(skb, &rt->dst, LISP_IPV4_HLEN, &frag);
+	if (err)
+		goto free_dst;
+
+	lisp_encap_fields(skb, key, dsfield, &tos, &ttl);
+	skb_scrub_packet(skb, xnet);
+
+	err = lisp_build_skb(skb, &rt->dst, LISP_IPV4_HLEN, iid, udp_sum);
+	if (err)
+		goto free_dst;
+
+	udp_tunnel_xmit_skb(rt, sk, skb, saddr, key->u.ipv4.dst, tos, ttl,
+			    frag ? 0 : htons(IP_DF), sport,
+			    htons(LISP_UDP_PORT), xnet, !udp_sum, 0);
+	return 0;
+
+free_dst:
+	dst_release(&rt->dst);
+	return err;
+}
+
+static int lisp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
+			  struct sock *sk, const struct ip_tunnel_info *info,
+			  u32 iid)
+{
+	bool udp_sum = test_bit(IP_TUNNEL_CSUM_BIT, info->key.tun_flags);
+	const struct lisp_dev *lisp = netdev_priv(dev);
+	bool xnet = !net_eq(lisp->net, dev_net(dev));
+	const struct ip_tunnel_key *key = &info->key;
+	u8 dsfield = lisp_encap_dsfield(skb, key);
+	struct ip_tunnel_key local_key;
+	struct dst_entry *dst;
+	struct in6_addr saddr;
+	__be16 sport;
+	u8 tos, ttl;
+	bool frag;
+	int err;
+
+	if (ipv6_addr_any(&key->u.ipv6.src) && !ipv6_addr_any(&lisp->local6)) {
+		local_key = *key;
+		local_key.u.ipv6.src = lisp->local6;
+		key = &local_key;
+	}
+
+	sport = udp_flow_src_port(lisp->net, skb, 0, 0, false);
+	dst = udp_tunnel6_dst_lookup(skb, dev, lisp->net, sk, lisp->link,
+				     &saddr, key, sport, htons(LISP_UDP_PORT),
+				     dsfield,
+				     lisp_dst_cache(skb, info, dsfield));
+	if (IS_ERR(dst))
+		return PTR_ERR(dst);
+
+	err = lisp_check_pmtu(skb, dst, LISP_IPV6_HLEN, &frag);
+	if (err)
+		goto free_dst;
+
+	lisp_encap_fields(skb, key, dsfield, &tos, &ttl);
+	skb_scrub_packet(skb, xnet);
+
+	err = lisp_build_skb(skb, dst, LISP_IPV6_HLEN, iid, udp_sum);
+	if (err)
+		goto free_dst;
+
+	skb->ignore_df = frag;
+	udp_tunnel6_xmit_skb(dst, sk, skb, dev, &saddr, &key->u.ipv6.dst, tos,
+			     ttl, key->label, sport, htons(LISP_UDP_PORT),
+			     !udp_sum, 0);
+	return 0;
+
+free_dst:
+	dst_release(dst);
+	return err;
+}
+
+static netdev_tx_t lisp_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+	const struct ip_tunnel_info *info = skb_tunnel_info(skb);
+	const struct lisp_dev *lisp = netdev_priv(dev);
+	const struct lisp_sock *ls;
+	u32 iid = lisp->iid;
+	int err = -EINVAL;
+
+	if (skb->protocol != htons(ETH_P_IP) &&
+	    (skb->protocol != htons(ETH_P_IPV6) || !ipv6_mod_enabled()))
+		goto tx_error;
+
+	if (!pskb_inet_may_pull(skb))
+		goto tx_error;
+
+	if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX)))
+		goto tx_error;
+
+	if (lisp->collect_md) {
+		u64 tun_id = be64_to_cpu(info->key.tun_id);
+
+		if (tun_id > LISP_IID_MAX)
+			goto tx_error;
+		iid = tun_id;
+	}
+
+	rcu_read_lock();
+	ls = rcu_dereference(lisp->sock);
+	if (!ls)
+		err = -ESHUTDOWN;
+	else if (ip_tunnel_info_af(info) == AF_INET)
+		err = lisp_xmit_skb(skb, dev, ls->sk4, info, iid);
+	else if (ls->sk6)
+		err = lisp6_xmit_skb(skb, dev, ls->sk6, info, iid);
+	else
+		err = -EAFNOSUPPORT;
+	rcu_read_unlock();
+
+	if (likely(!err))
+		return NETDEV_TX_OK;
+
+tx_error:
+	dev_kfree_skb(skb);
+
+	if (err == -ELOOP)
+		DEV_STATS_INC(dev, collisions);
+	else if (err == -ENETUNREACH)
+		DEV_STATS_INC(dev, tx_carrier_errors);
+
+	DEV_STATS_INC(dev, tx_errors);
+	return NETDEV_TX_OK;
+}
+
+static int lisp_init(struct net_device *dev)
+{
+	struct lisp_dev *lisp = netdev_priv(dev);
+	int err;
+
+	err = gro_cells_init(&lisp->gro_cells, dev);
+	if (err)
+		return err;
+
+	netdev_lockdep_set_classes(dev);
+	return 0;
+}
+
+static void lisp_uninit(struct net_device *dev)
+{
+	struct lisp_dev *lisp = netdev_priv(dev);
+
+	gro_cells_destroy(&lisp->gro_cells);
+}
+
+static int lisp_get_iflink(const struct net_device *dev)
+{
+	const struct lisp_dev *lisp = netdev_priv(dev);
+
+	return lisp->link ? : READ_ONCE(dev->ifindex);
+}
+
+static const struct net_device_ops lisp_netdev_ops = {
+	.ndo_init		= lisp_init,
+	.ndo_uninit		= lisp_uninit,
+	.ndo_open		= lisp_open,
+	.ndo_stop		= lisp_stop,
+	.ndo_start_xmit		= lisp_xmit,
+	.ndo_get_iflink		= lisp_get_iflink,
+};
+
+static const struct device_type lisp_type = {
+	.name = "lisp",
+};
+
+static void lisp_setup(struct net_device *dev)
+{
+	dev->netdev_ops = &lisp_netdev_ops;
+	dev->needs_free_netdev = true;
+	SET_NETDEV_DEVTYPE(dev, &lisp_type);
+
+	dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_FRAGLIST;
+	dev->features |= NETIF_F_RXCSUM;
+	dev->features |= NETIF_F_GSO_SOFTWARE;
+	dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_FRAGLIST;
+	dev->hw_features |= NETIF_F_RXCSUM;
+	dev->hw_features |= NETIF_F_GSO_SOFTWARE;
+
+	dev->type = ARPHRD_NONE;
+	dev->hard_header_len = 0;
+	dev->addr_len = 0;
+	dev->needed_headroom = LL_MAX_HEADER + LISP_IPV6_HLEN;
+	dev->mtu = ETH_DATA_LEN - LISP_IPV6_HLEN;
+	dev->min_mtu = IPV4_MIN_MTU;
+	dev->max_mtu = IP_MAX_MTU - LISP_IPV4_HLEN;
+	dev->flags = IFF_POINTOPOINT | IFF_NOARP;
+	dev->priv_flags |= IFF_NO_QUEUE;
+	dev->lltx = true;
+	dev->pcpu_stat_type = NETDEV_PCPU_STAT_DSTATS;
+
+	netif_keep_dst(dev);
+	netif_set_tso_max_size(dev, GSO_MAX_SIZE);
+}
+
+static const struct netlink_range_validation lisp_iid_range = {
+	.max = LISP_IID_MAX,
+};
+
+static const struct nla_policy lisp_policy[IFLA_LISP_MAX + 1] = {
+	[IFLA_LISP_UNSPEC]		= { .strict_start_type = IFLA_LISP_ID },
+	[IFLA_LISP_ID]			= NLA_POLICY_FULL_RANGE(NLA_U32,
+								&lisp_iid_range),
+	[IFLA_LISP_COLLECT_METADATA]	= { .type = NLA_FLAG },
+	[IFLA_LISP_LOCAL]		= { .type = NLA_BE32 },
+	[IFLA_LISP_LOCAL6]		=
+		NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
+};
+
+static int lisp_validate(struct nlattr *tb[], struct nlattr *data[],
+			 struct netlink_ext_ack *extack)
+{
+	if (!data)
+		return 0;
+
+	if (data[IFLA_LISP_LOCAL]) {
+		__be32 addr = nla_get_in_addr(data[IFLA_LISP_LOCAL]);
+
+		if (ipv4_is_zeronet(addr) || ipv4_is_multicast(addr) ||
+		    ipv4_is_lbcast(addr)) {
+			NL_SET_ERR_MSG_ATTR(extack, data[IFLA_LISP_LOCAL],
+					    "The local RLOC is not a unicast address");
+			return -EINVAL;
+		}
+	}
+
+	if (data[IFLA_LISP_LOCAL6]) {
+		struct in6_addr addr = nla_get_in6_addr(data[IFLA_LISP_LOCAL6]);
+
+		if (ipv6_addr_type(&addr) != IPV6_ADDR_UNICAST) {
+			NL_SET_ERR_MSG_ATTR(extack, data[IFLA_LISP_LOCAL6],
+					    "The local RLOC is not a global unicast address");
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int lisp_newlink(struct net_device *dev,
+			struct rtnl_newlink_params *params,
+			struct netlink_ext_ack *extack)
+{
+	struct net *link_net = rtnl_newlink_link_net(params);
+	struct lisp_net *ln = net_generic(link_net, lisp_net_id);
+	struct lisp_dev *lisp = netdev_priv(dev);
+	struct nlattr **data = params->data;
+	struct nlattr **tb = params->tb;
+	const struct lisp_dev *tmp;
+	int ifindex;
+	int err;
+
+	if (!data ||
+	    !data[IFLA_LISP_ID] == !data[IFLA_LISP_COLLECT_METADATA]) {
+		NL_SET_ERR_MSG(extack,
+			       "Either an instance ID or the collection of metadata is required");
+		return -EINVAL;
+	}
+
+	lisp->net = link_net;
+	lisp->dev = dev;
+	INIT_LIST_HEAD(&lisp->next);
+
+	lisp->collect_md = nla_get_flag(data[IFLA_LISP_COLLECT_METADATA]);
+	lisp->iid = nla_get_u32_default(data[IFLA_LISP_ID], 0);
+	lisp->local = nla_get_in_addr_default(data[IFLA_LISP_LOCAL], 0);
+	if (data[IFLA_LISP_LOCAL6])
+		lisp->local6 = nla_get_in6_addr(data[IFLA_LISP_LOCAL6]);
+
+	if (tb[IFLA_LINK]) {
+		lisp->link = nla_get_u32(tb[IFLA_LINK]);
+		if (!__dev_get_by_index(link_net, lisp->link)) {
+			NL_SET_BAD_ATTR(extack, tb[IFLA_LINK]);
+			return -ENODEV;
+		}
+	}
+
+	ifindex = lisp_l3mdev(lisp);
+	mutex_lock(&ln->lock);
+	list_for_each_entry(tmp, &ln->dev_list, next) {
+		if (lisp_l3mdev(tmp) != ifindex ||
+		    tmp->collect_md != lisp->collect_md)
+			continue;
+
+		if (lisp->collect_md) {
+			mutex_unlock(&ln->lock);
+			NL_SET_ERR_MSG(extack,
+				       "A LISP device already collects the metadata of these RLOCs");
+			return -EEXIST;
+		}
+		if (tmp->iid == lisp->iid) {
+			mutex_unlock(&ln->lock);
+			NL_SET_ERR_MSG(extack,
+				       "A LISP device already has this instance ID for these RLOCs");
+			return -EEXIST;
+		}
+	}
+	mutex_unlock(&ln->lock);
+
+	err = register_netdevice(dev);
+	if (err)
+		return err;
+
+	mutex_lock(&ln->lock);
+	list_add(&lisp->next, &ln->dev_list);
+	mutex_unlock(&ln->lock);
+
+	return 0;
+}
+
+static void lisp_dellink(struct net_device *dev, struct list_head *head)
+{
+	struct lisp_dev *lisp = netdev_priv(dev);
+	struct lisp_net *ln = net_generic(lisp->net, lisp_net_id);
+
+	mutex_lock(&ln->lock);
+	if (!list_empty(&lisp->next)) {
+		list_del_init(&lisp->next);
+		unregister_netdevice_queue_net(dev_net(dev), dev, head);
+	}
+	mutex_unlock(&ln->lock);
+}
+
+static size_t lisp_get_size(const struct net_device *dev)
+{
+	return nla_total_size(sizeof(u32)) +		/* IFLA_LISP_ID */
+	       nla_total_size(0) +	/* IFLA_LISP_COLLECT_METADATA */
+	       nla_total_size(sizeof(struct in_addr)) +	/* IFLA_LISP_LOCAL */
+	       nla_total_size(sizeof(struct in6_addr));	/* IFLA_LISP_LOCAL6 */
+}
+
+static int lisp_fill_info(struct sk_buff *skb, const struct net_device *dev)
+{
+	const struct lisp_dev *lisp = netdev_priv(dev);
+
+	if (lisp->collect_md) {
+		if (nla_put_flag(skb, IFLA_LISP_COLLECT_METADATA))
+			return -EMSGSIZE;
+	} else if (nla_put_u32(skb, IFLA_LISP_ID, lisp->iid)) {
+		return -EMSGSIZE;
+	}
+
+	if (lisp->local &&
+	    nla_put_in_addr(skb, IFLA_LISP_LOCAL, lisp->local))
+		return -EMSGSIZE;
+
+	if (!ipv6_addr_any(&lisp->local6) &&
+	    nla_put_in6_addr(skb, IFLA_LISP_LOCAL6, &lisp->local6))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
+static struct net *lisp_get_link_net(const struct net_device *dev)
+{
+	const struct lisp_dev *lisp = netdev_priv(dev);
+
+	return lisp->net;
+}
+
+static struct rtnl_link_ops lisp_link_ops __read_mostly = {
+	.kind		= "lisp",
+	.maxtype	= IFLA_LISP_MAX,
+	.policy		= lisp_policy,
+	.priv_size	= sizeof(struct lisp_dev),
+	.setup		= lisp_setup,
+	.validate	= lisp_validate,
+	.newlink	= lisp_newlink,
+	.dellink	= lisp_dellink,
+	.get_size	= lisp_get_size,
+	.fill_info	= lisp_fill_info,
+	.get_link_net	= lisp_get_link_net,
+};
+
+static __net_init int lisp_init_net(struct net *net)
+{
+	struct lisp_net *ln = net_generic(net, lisp_net_id);
+
+	INIT_LIST_HEAD(&ln->dev_list);
+	INIT_LIST_HEAD(&ln->sock_list);
+	mutex_init(&ln->lock);
+
+	return 0;
+}
+
+static void __net_exit lisp_exit_rtnl_net(struct net *net,
+					  struct list_head *dev_kill_list)
+{
+	struct lisp_net *ln = net_generic(net, lisp_net_id);
+	struct lisp_dev *lisp, *next;
+
+	mutex_lock(&ln->lock);
+	list_for_each_entry_safe(lisp, next, &ln->dev_list, next) {
+		list_del_init(&lisp->next);
+		unregister_netdevice_queue_net(net, lisp->dev, dev_kill_list);
+	}
+	mutex_unlock(&ln->lock);
+}
+
+static void __net_exit lisp_exit_net(struct net *net)
+{
+	struct lisp_net *ln = net_generic(net, lisp_net_id);
+
+	WARN_ON_ONCE(!list_empty(&ln->dev_list));
+	WARN_ON_ONCE(!list_empty(&ln->sock_list));
+}
+
+static int lisp_netdevice_event(struct notifier_block *nb, unsigned long event,
+				void *ptr)
+{
+	struct net_device *link = netdev_notifier_info_to_dev(ptr);
+	struct net *net = dev_net(link);
+	struct lisp_dev *lisp, *next;
+	struct lisp_net *ln;
+	LIST_HEAD(kill);
+
+	if (event != NETDEV_UNREGISTER)
+		return NOTIFY_DONE;
+
+	ln = net_generic(net, lisp_net_id);
+	mutex_lock(&ln->lock);
+	list_for_each_entry_safe(lisp, next, &ln->dev_list, next) {
+		if (lisp->link != link->ifindex)
+			continue;
+
+		list_del_init(&lisp->next);
+		unregister_netdevice_queue_net(net, lisp->dev, &kill);
+	}
+	mutex_unlock(&ln->lock);
+
+	unregister_netdevice_many(&kill);
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block lisp_notifier_block __read_mostly = {
+	.notifier_call = lisp_netdevice_event,
+};
+
+static struct pernet_operations lisp_net_ops = {
+	.init		= lisp_init_net,
+	.exit_rtnl	= lisp_exit_rtnl_net,
+	.exit		= lisp_exit_net,
+	.id		= &lisp_net_id,
+	.size		= sizeof(struct lisp_net),
+};
+
+static int __init lisp_init_module(void)
+{
+	int err;
+
+	err = register_pernet_subsys(&lisp_net_ops);
+	if (err)
+		return err;
+
+	err = register_netdevice_notifier(&lisp_notifier_block);
+	if (err)
+		goto unregister_pernet;
+
+	err = rtnl_link_register(&lisp_link_ops);
+	if (err)
+		goto unregister_notifier;
+
+	return 0;
+
+unregister_notifier:
+	unregister_netdevice_notifier(&lisp_notifier_block);
+unregister_pernet:
+	unregister_pernet_subsys(&lisp_net_ops);
+	return err;
+}
+late_initcall(lisp_init_module);
+
+static void __exit lisp_cleanup_module(void)
+{
+	rtnl_link_unregister(&lisp_link_ops);
+	unregister_netdevice_notifier(&lisp_notifier_block);
+	unregister_pernet_subsys(&lisp_net_ops);
+}
+module_exit(lisp_cleanup_module);
+
+MODULE_ALIAS_RTNL_LINK("lisp");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Vincent Jardin <vjardin@free.fr>");
+MODULE_DESCRIPTION("Data plane of the Locator/ID Separation Protocol (LISP)");
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 245b362045253..f64399ea9d54f 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -1538,6 +1538,18 @@ enum {
 
 #define IFLA_BAREUDP_MAX (__IFLA_BAREUDP_MAX - 1)
 
+/* LISP section */
+enum {
+	IFLA_LISP_UNSPEC,
+	IFLA_LISP_ID,
+	IFLA_LISP_COLLECT_METADATA,
+	IFLA_LISP_LOCAL,
+	IFLA_LISP_LOCAL6,
+	__IFLA_LISP_MAX
+};
+
+#define IFLA_LISP_MAX (__IFLA_LISP_MAX - 1)
+
 /* PPP section */
 enum {
 	IFLA_PPP_UNSPEC,

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 2/5] netlink: specs: rt-link: add the lisp link type
  2026-11-26 21:37 [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Vincent Jardin via B4 Relay
  2026-11-26 21:37 ` [PATCH net-next 1/5] lisp: add LISP (Locator/ID Separation Protocol) Vincent Jardin via B4 Relay
@ 2026-11-26 21:37 ` Vincent Jardin via B4 Relay
  2026-11-26 21:37 ` [PATCH net-next 3/5] docs: net: document the LISP devices Vincent Jardin via B4 Relay
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-26 21:37 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Vincent Jardin, Donald Hunter, Nicolas Dichtel,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Shuah Khan
  Cc: linux-kernel, netdev, linux-doc, linux-kselftest

From: Vincent Jardin <vjardin@free.fr>

Describe the attributes of the LISP devices.

Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
 Documentation/netlink/specs/rt-link.yaml | 35 ++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml
index 81b58633911d6..30a8e36c212f4 100644
--- a/Documentation/netlink/specs/rt-link.yaml
+++ b/Documentation/netlink/specs/rt-link.yaml
@@ -2368,6 +2368,38 @@ attribute-sets:
         name: mode
         type: u8
         enum: ovpn-mode
+  -
+    name: linkinfo-lisp-attrs
+    name-prefix: ifla-lisp-
+    attributes:
+      -
+        name: id
+        type: u32
+        doc: |
+          Instance ID of the packets that the device sends and receives,
+          24 bits.
+      -
+        name: collect-metadata
+        type: flag
+        doc: |
+          The device serves the instance IDs that have no device: it takes
+          the instance ID of a packet from its tunnel metadata, and
+          provides it when it receives.
+      -
+        name: local
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+        doc: |
+          Source address of the packets sent to an IPv4 RLOC, when the
+          tunnel metadata do not give it.
+      -
+        name: local6
+        type: binary
+        display-hint: ipv6
+        doc: |
+          Source address of the packets sent to an IPv6 RLOC, when the
+          tunnel metadata do not give it.
 
 sub-messages:
   -
@@ -2427,6 +2459,9 @@ sub-messages:
       -
         value: ovpn
         attribute-set: linkinfo-ovpn-attrs
+      -
+        value: lisp
+        attribute-set: linkinfo-lisp-attrs
   -
     name: linkinfo-member-data-msg
     formats:

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 3/5] docs: net: document the LISP devices
  2026-11-26 21:37 [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Vincent Jardin via B4 Relay
  2026-11-26 21:37 ` [PATCH net-next 1/5] lisp: add LISP (Locator/ID Separation Protocol) Vincent Jardin via B4 Relay
  2026-11-26 21:37 ` [PATCH net-next 2/5] netlink: specs: rt-link: add the lisp link type Vincent Jardin via B4 Relay
@ 2026-11-26 21:37 ` Vincent Jardin via B4 Relay
  2026-11-26 21:37 ` [PATCH net-next 4/5] selftests: net: add a test of " Vincent Jardin via B4 Relay
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-26 21:37 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Vincent Jardin, Donald Hunter, Nicolas Dichtel,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Shuah Khan
  Cc: linux-kernel, netdev, linux-doc, linux-kselftest

From: Vincent Jardin <vjardin@free.fr>

Describe the LISP devices, how the routes and the nexthops
give the RLOCs and what checks the sources of the packets that a
device decapsulates.

Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
 Documentation/networking/index.rst |   1 +
 Documentation/networking/lisp.rst  | 142 +++++++++++++++++++++++++++++++++++++
 MAINTAINERS                        |   1 +
 drivers/net/Kconfig                |   3 +-
 4 files changed, 146 insertions(+), 1 deletion(-)

diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst
index 44a422ad3b055..f2bc062f80d80 100644
--- a/Documentation/networking/index.rst
+++ b/Documentation/networking/index.rst
@@ -69,6 +69,7 @@ Contents:
    kcm
    l2tp
    lapb-module
+   lisp
    mac80211-injection
    mctp
    mpls-sysctl
diff --git a/Documentation/networking/lisp.rst b/Documentation/networking/lisp.rst
new file mode 100644
index 0000000000000..70ad8bb29700b
--- /dev/null
+++ b/Documentation/networking/lisp.rst
@@ -0,0 +1,142 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. Copyright (c) 2026 Vincent Jardin <vjardin@free.fr>, Free Mobile
+
+=============================================
+Locator/ID Separation Protocol (LISP) devices
+=============================================
+
+LISP separates the addresses of the hosts, the endpoint identifiers (EIDs),
+from the addresses of the routers that the hosts are reachable through, the
+routing locators (RLOCs). A LISP router, an xTR, carries the packets that are
+sent to a remote EID over UDP to an RLOC of the site of that EID (:rfc:`9300`).
+
+A LISP device is the data plane of an xTR. It encapsulates IPv4 and IPv6
+packets in a LISP header, UDP port 4341, and an IPv4 or IPv6 header, and it
+decapsulates what it receives. The family of the RLOCs is independent from the
+family of the EIDs.
+
+The kernel has no LISP control plane and no map-cache: the association of an
+EID prefix with its RLOCs, a mapping, is a route. Its nexthop gives the RLOC as
+a lightweight tunnel encapsulation, ``encap ip`` for an IPv4 RLOC and ``encap
+ip6`` for an IPv6 one, and has the LISP device as output device. The routes are
+configured, or installed by a LISP control plane in user space (:rfc:`9301`)
+as any routing daemon does. A packet whose destination has no route with an
+RLOC is not resolved by the kernel.
+
+Devices
+=======
+
+There are two kinds of LISP devices.
+
+A device (1) with an instance ID sends and receives the packets of that instance::
+
+  ip link add site type vrf table 10
+  ip link set site up
+  ip link add lisp101 type lisp id 101
+  ip link set lisp101 master site up
+
+It is meant to be in the VRF of the EIDs of the instance: what it receives is
+routed in that VRF, and the routes of that VRF send to it. A site has one
+device per instance, whatever the number of remote sites.
+
+A device (2) that collects metadata serves all the instance IDs that have no device
+of their own::
+
+  ip link add lisp0 type lisp external
+
+The instance ID then comes with the RLOC, as the ``id`` of the encapsulation
+of the nexthop. The packets that the device receives have it in their tunnel
+metadata, where a routing rule (``ip rule add tun_id``), a traffic control
+filter or a BPF program finds it.
+
+Both kinds take the RLOC from the tunnel metadata of the packet. A packet
+without metadata, sent by a route that has no encapsulation, is dropped and
+counted as a transmit error.
+
+``id IID``
+  The instance ID, from 0 to 16777215. The header of the packets of the
+  instance 0 has no instance ID, and a packet without instance ID is received
+  by the instance 0.
+
+``external``
+  The device collects metadata.
+
+``local ADDR``
+  The source address of the packets that are sent to an RLOC of the same
+  family, a local RLOC. It can be given once per family. A source address in
+  the encapsulation of the nexthop is used instead. Without either, the route
+  to the RLOC gives the source address.
+
+``link DEVICE``
+  A generic option of ``ip link add``, before ``type lisp``. The packets are
+  sent to the RLOCs through ``DEVICE``: by the routes of a VRF when it is a
+  VRF device, by its own routes otherwise. The LISP device receives what
+  comes from the VRF that ``DEVICE`` is, or is in. Without link, or with a
+  link that is in no VRF, the RLOCs are in the main table. The LISP device is
+  removed with ``DEVICE``::
+
+    ip link add link wan name lisp101 type lisp id 101 local 192.0.2.1
+
+The devices that have the same VRF of RLOCs share their UDP sockets, one per
+address family. The sockets are in the network namespace of ``DEVICE``: the
+one that the LISP device is created from, unless ``link-netns`` names another
+one, which the LISP device is then removed with. An instance ID is used once
+per VRF of RLOCs, and one device collects its metadata. The sockets of a VRF
+and those of the main table cannot coexist: the RLOCs of a network namespace
+are either in VRFs or in the main table.
+
+Mappings
+========
+
+The RLOC of an EID prefix is a nexthop, shared by the prefixes of the same
+site, or a group of nexthops for the RLOCs that share the traffic::
+
+  ip -6 nexthop add id 1 encap ip dst 192.0.2.1 dev lisp101
+  ip -6 nexthop add id 2 encap ip6 dst 2001:db8::1 dev lisp101
+  ip nexthop add id 3 group 1,3/2,1
+
+  ip route add 10.1.0.0/16 vrf site nhid 1
+  ip -6 route add 2001:db8:1::/48 vrf site nhid 3
+
+An IPv6 nexthop is used by IPv4 and IPv6 routes. With the device that
+collects metadata, the nexthop gives the instance ID too::
+
+  ip -6 nexthop add id 4 encap ip id 102 dst 192.0.2.1 dev lisp0
+
+A route can carry the encapsulation itself, without nexthop object. This does
+not scale with the number of RLOCs: the routes that only differ by their
+encapsulation are compared with each other when one is added.
+
+A group counts the packets that it forwards to each of its nexthops
+(``ip -s nexthop``).
+
+A nexthop is removed with its routes when the device goes down.
+
+Checking the IP sources
+=======================
+
+The device decapsulates what comes for its instance ID, from any RLOC: it
+does not check the source of a packet. What the kernel has for any device
+applies to it.
+
+The reverse path filter of IPv4 checks the source EID. With ``rp_filter`` set
+to 1 for the LISP device, a packet is dropped unless the route to its source
+sends to that device, that is, unless its source has a mapping in that
+instance. The packets that it drops are counted as ``IPReversePathFilter``::
+
+  sysctl -w net.ipv4.conf.lisp101.rp_filter=1
+
+It does not look at the RLOC that a packet comes from. With mappings that user
+space installs when packets need them, it drops what a site sends until the
+mapping of that site is there.
+
+The packets that a device that collects metadata receives have the RLOC that
+they come from and their instance ID in their tunnel metadata, which a traffic
+control filter matches with the source EID. These filters accept an EID
+prefix from the RLOC of its site and drop what else the device receives,
+which the last one counts::
+
+  tc qdisc add dev lisp0 clsact
+  tc filter add dev lisp0 ingress protocol ip pref 10 flower \
+      enc_key_id 102 enc_src_ip 192.0.2.1 src_ip 10.1.0.0/16 action pass
+  tc filter add dev lisp0 ingress pref 100 matchall action drop
diff --git a/MAINTAINERS b/MAINTAINERS
index 6b62bc1f45bae..addedadf43446 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15510,6 +15510,7 @@ LISP DATA PLANE DRIVER
 M:	Vincent Jardin <vjardin@free.fr>
 L:	netdev@vger.kernel.org
 S:	Maintained
+F:	Documentation/networking/lisp.rst
 F:	drivers/net/lisp.c
 
 LIST KUNIT TEST
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index aa78fd48e77a9..6201f5046422b 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -280,7 +280,8 @@ config LISP
 	  (LISP, RFC 9300): a tunnel device that carries the IPv4 and IPv6
 	  packets of an instance ID over UDP, to the routing locator (RLOC)
 	  that the route or the nexthop of their destination gives as a
-	  lightweight tunnel encapsulation.
+	  lightweight tunnel encapsulation. See
+	  Documentation/networking/lisp.rst.
 
 	  The mappings of the destinations to the RLOCs come from user space,
 	  from a LISP control plane or from the configuration.

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 4/5] selftests: net: add a test of the LISP devices
  2026-11-26 21:37 [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Vincent Jardin via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-26 21:37 ` [PATCH net-next 3/5] docs: net: document the LISP devices Vincent Jardin via B4 Relay
@ 2026-11-26 21:37 ` Vincent Jardin via B4 Relay
  2026-11-26 21:37 ` [PATCH net-next 5/5] selftests: net: add a scale test for LISP Vincent Jardin via B4 Relay
  2026-11-27 10:24 ` [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Matthieu Baerts
  5 siblings, 0 replies; 7+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-26 21:37 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Vincent Jardin, Donald Hunter, Nicolas Dichtel,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Shuah Khan
  Cc: linux-kernel, netdev, linux-doc, linux-kselftest

From: Vincent Jardin <vjardin@free.fr>

Scenario: 2 xTRs carry the packets of 2 hosts through a core router.
The EIDs of the first one are in a VRF and its RLOCs in another one,
the second one uses its main table.

Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
 MAINTAINERS                          |    1 +
 tools/testing/selftests/net/Makefile |    1 +
 tools/testing/selftests/net/config   |    4 +
 tools/testing/selftests/net/lisp.sh  | 1120 ++++++++++++++++++++++++++++++++++
 4 files changed, 1126 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index addedadf43446..0d3a537d87023 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15512,6 +15512,7 @@ L:	netdev@vger.kernel.org
 S:	Maintained
 F:	Documentation/networking/lisp.rst
 F:	drivers/net/lisp.c
+F:	tools/testing/selftests/net/lisp*.sh
 
 LIST KUNIT TEST
 M:	David Gow <david@davidgow.net>
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index fb0a64662053f..7263049ab7c44 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -63,6 +63,7 @@ TEST_PROGS := \
 	l2_tos_ttl_inherit.sh \
 	l2tp.sh \
 	link_netns.py \
+	lisp.sh \
 	lwt_dst_cache_ref_loop.sh \
 	macvlan_mcast_shared_mac.sh \
 	msg_zerocopy.sh \
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index dab62cdfa27ba..767c0fdb79353 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -31,8 +31,10 @@ CONFIG_IP6_NF_MATCH_SRH=m
 CONFIG_IP6_NF_NAT=m
 CONFIG_IP6_NF_RAW=m
 CONFIG_IP6_NF_TARGET_REJECT=m
+CONFIG_IP_ADVANCED_ROUTER=y
 CONFIG_IP_MROUTE=y
 CONFIG_IP_MULTICAST=y
+CONFIG_IP_MULTIPLE_TABLES=y
 CONFIG_IP_NF_FILTER=m
 CONFIG_IP_NF_IPTABLES=m
 CONFIG_IP_NF_IPTABLES_LEGACY=m
@@ -42,6 +44,7 @@ CONFIG_IP_NF_NAT=m
 CONFIG_IP_NF_RAW=m
 CONFIG_IP_NF_TARGET_REJECT=m
 CONFIG_IP_NF_TARGET_TTL=m
+CONFIG_IP_ROUTE_MULTIPATH=y
 CONFIG_IP_SCTP=m
 CONFIG_IPV6=y
 CONFIG_IPV6_FOU=m
@@ -64,6 +67,7 @@ CONFIG_L2TP=m
 CONFIG_L2TP_ETH=m
 CONFIG_L2TP_IP=m
 CONFIG_L2TP_V3=y
+CONFIG_LISP=m
 CONFIG_MACSEC=m
 CONFIG_MACVLAN=y
 CONFIG_MACVTAP=y
diff --git a/tools/testing/selftests/net/lisp.sh b/tools/testing/selftests/net/lisp.sh
new file mode 100755
index 0000000000000..780053db366bc
--- /dev/null
+++ b/tools/testing/selftests/net/lisp.sh
@@ -0,0 +1,1120 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Vincent Jardin <vjardin@free.fr>, Free Mobile
+#
+# Test the LISP data plane of drivers/net/lisp.c between two xTRs.
+#
+# The EIDs of x1 are in the VRF "site" and its RLOCs in the VRF "wan". x2 keeps
+# everything in its main table. The instance 101 has one LISP device on each
+# xTR. The instance 102 has a device on x1, in the VRF "site2", and uses a device
+# that collects metadata on x2.
+#
+#  h1          x1                         core               x2            h2
+#  10.1.0.2    10.1.0.1 (site)                               10.2.0.1      10.2.0.2
+#  fd00:1::2   fd00:1::1                                     fd00:2::1     fd00:2::2
+#        veth       lisp101 (site)                    lisp101      veth
+#                   lisp102 (site2)                   lispmd
+#                   192.0.2.1 (wan)      192.0.2.2
+#                   2001:db8:1::1  veth  2001:db8:1::2
+#                                        198.51.100.2        198.51.100.1
+#                                        2001:db8:2::2  veth 2001:db8:2::1
+
+source lib.sh
+
+# shellcheck disable=SC2155 # prefer RO variable over return value from cmd
+readonly CLI="$(dirname "$(readlink -f "$0")")/../../../net/ynl/pyynl/cli.py"
+
+ALL_TESTS="
+	netlink_test
+	ping_test
+	fields_test
+	mtu_test
+	pmtu_test
+	multipath_test
+	instance_test
+	receive_test
+	rpfilter_test
+	updown_test
+	tcp_test
+	cross_vrf_test
+	cross_netns_test
+	netns_test
+"
+
+LISP_PORT=4341
+IID=101
+
+X1_RLOC4=192.0.2.1
+X1_RLOC6=2001:db8:1::1
+X2_RLOC4=198.51.100.1
+X2_RLOC6=2001:db8:2::1
+
+# ID of the nexthop that reaches the other xTR at its RLOC of a family
+NH4=14
+NH6=16
+# IDs of the nexthops that a test makes for itself
+NH_FIELDS=24
+NH_GROUP=30
+NH_INSTANCE=40
+NH_OTHER=99
+
+# An RLOC that is not the one of an xTR
+OTHER_RLOC4=203.0.113.9
+
+TCP_PORT=5000
+TCP_TIMEOUT=60
+TCP_FILE=
+
+################################################################################
+# Helpers
+
+h1_ping()
+{
+	ip netns exec "$h1" ping -q -c 1 -W 2 "$@" > /dev/null 2>&1
+}
+
+h2_ping()
+{
+	ip netns exec "$h2" ping -q -c 1 -W 1 "$@" > /dev/null 2>&1
+}
+
+tc_packets()
+{
+	local ns=$1; shift
+	local dev=$1; shift
+	local pref=$1; shift
+
+	tc -n "$ns" -j -s filter show dev "$dev" ingress pref "$pref" |
+		jq '[.[] | select(.options.actions) |
+		     .options.actions[0].stats.packets] | add'
+}
+
+# On the core, coming from x1.
+core_packets()
+{
+	tc_packets "$core" c1 "$1"
+}
+
+h2_packets()
+{
+	tc_packets "$h2" eth0 "$1"
+}
+
+link_stat()
+{
+	local ns=$1; shift
+	local dev=$1; shift
+	local stat=$1; shift
+
+	ip -n "$ns" -j -s -s link show dev "$dev" | jq ".[0].stats64$stat"
+}
+
+# What the kernel answers to the creation of a device with these attributes,
+# which ip refuses to send.
+ynl_add()
+{
+	local data=$1; shift
+
+	ip netns exec "$x2" "$CLI" --family rt-link --create --excl \
+		--do newlink --json "{\"ifname\": \"t0\",
+			\"linkinfo\": {\"kind\": \"lisp\", \"data\": $data}}" 2>&1
+}
+
+# The EID prefixes of the instance 101 use the RLOCs of a family.
+use_rlocs()
+{
+	local family=$1; shift
+	local nh=NH$family
+
+	ip -n "$x1" route replace 10.2.0.0/24 vrf site nhid "${!nh}"
+	ip -n "$x1" -6 route replace fd00:2::/64 vrf site nhid "${!nh}"
+	ip -n "$x2" route replace 10.1.0.0/24 nhid "${!nh}"
+	ip -n "$x2" -6 route replace fd00:1::/64 nhid "${!nh}"
+}
+
+core_send()
+{
+	local bytes=$1; shift
+
+	ip netns exec "$core" bash -c \
+		"printf '$bytes' > /dev/udp/$X1_RLOC4/$LISP_PORT"
+}
+
+################################################################################
+# Setup
+
+host_setup()
+{
+	local ns=$1; shift
+	local id=$1; shift
+
+	ip -n "$ns" link set eth0 up
+	ip -n "$ns" addr add "10.$id.0.2/24" dev eth0
+	ip -n "$ns" addr add "fd00:$id::2/64" dev eth0 nodad
+	ip -n "$ns" route add default via "10.$id.0.1"
+	ip -n "$ns" -6 route add default via "fd00:$id::1"
+	tc -n "$ns" qdisc add dev eth0 clsact
+}
+
+setup()
+{
+	local ns
+
+	setup_ns h1 x1 core x2 h2 || return
+
+	for ns in "$h1" "$x1" "$core" "$x2" "$h2"; do
+		ip netns exec "$ns" sysctl -wq net.ipv6.conf.all.accept_dad=0
+		ip netns exec "$ns" sysctl -wq net.ipv6.conf.default.accept_dad=0
+	done
+	ip netns exec "$x2" sysctl -wq net.ipv6.bindv6only=1
+
+	ip link add eth0 netns "$h1" type veth peer name eth0 netns "$x1"
+	ip link add eth1 netns "$x1" type veth peer name c1 netns "$core"
+	ip link add eth1 netns "$x2" type veth peer name c2 netns "$core"
+	ip link add eth0 netns "$h2" type veth peer name eth0 netns "$x2"
+
+	for ns in "$x1" "$core" "$x2"; do
+		ip netns exec "$ns" sysctl -wq net.ipv4.ip_forward=1
+		ip netns exec "$ns" sysctl -wq net.ipv6.conf.all.forwarding=1
+	done
+
+	host_setup "$h1" 1
+	host_setup "$h2" 2
+
+	ip -n "$core" link set c1 up
+	ip -n "$core" link set c2 up
+	ip -n "$core" addr add 192.0.2.2/30 dev c1
+	ip -n "$core" addr add 2001:db8:1::2/64 dev c1 nodad
+	ip -n "$core" addr add 198.51.100.2/30 dev c2
+	ip -n "$core" addr add 2001:db8:2::2/64 dev c2 nodad
+	tc -n "$core" qdisc add dev c1 clsact
+	tc -n "$core" qdisc add dev c2 clsact
+
+	# The packets of the instance 101, by family of RLOC: the I flag and
+	# the instance ID after the UDP header, and DF in the IPv4 header.
+	tc -n "$core" filter add dev c1 ingress protocol ip pref 4 u32 \
+		match ip protocol 17 0xff match ip dport $LISP_PORT 0xffff \
+		match u16 0x4000 0xffff at 6 match u8 0x08 0xff at 28 \
+		match u32 $((IID << 8)) 0xffffffff at 32 action continue
+	tc -n "$core" filter add dev c1 ingress protocol ipv6 pref 6 u32 \
+		match ip6 protocol 17 0xff match ip6 dport $LISP_PORT 0xffff \
+		match u8 0x08 0xff at 48 \
+		match u32 $((IID << 8)) 0xffffffff at 52 action continue
+
+	ip -n "$x1" link add site type vrf table 10
+	ip -n "$x1" link add wan type vrf table 20
+	ip -n "$x1" link add site2 type vrf table 30
+	ip -n "$x1" link set site up
+	ip -n "$x1" link set wan up
+	ip -n "$x1" link set site2 up
+	ip -n "$x1" link set eth0 master site up
+	ip -n "$x1" link set eth1 master wan up
+	ip -n "$x1" addr add 10.1.0.1/24 dev eth0
+	ip -n "$x1" addr add fd00:1::1/64 dev eth0 nodad
+	ip -n "$x1" addr add $X1_RLOC4/30 dev eth1
+	ip -n "$x1" addr add $X1_RLOC6/64 dev eth1 nodad
+	ip -n "$x1" route add default vrf wan via 192.0.2.2
+	ip -n "$x1" -6 route add default vrf wan via 2001:db8:1::2
+
+	ip -n "$x1" link add link wan name lisp101 type lisp id $IID \
+		local $X1_RLOC4 local $X1_RLOC6 || return
+	ip -n "$x1" link set lisp101 master site up
+	ip -n "$x1" -6 nexthop add id $NH4 encap ip dst $X2_RLOC4 dev lisp101
+	ip -n "$x1" -6 nexthop add id $NH6 encap ip6 dst $X2_RLOC6 dev lisp101
+
+	ip -n "$x2" link set eth0 up
+	ip -n "$x2" link set eth1 up
+	ip -n "$x2" addr add 10.2.0.1/24 dev eth0
+	ip -n "$x2" addr add fd00:2::1/64 dev eth0 nodad
+	ip -n "$x2" addr add $X2_RLOC4/30 dev eth1
+	ip -n "$x2" addr add $X2_RLOC6/64 dev eth1 nodad
+	ip -n "$x2" route add default via 198.51.100.2
+	ip -n "$x2" -6 route add default via 2001:db8:2::2
+
+	ip -n "$x2" link add lisp101 type lisp id $IID
+	ip -n "$x2" link set lisp101 up
+	ip -n "$x2" -6 nexthop add id $NH4 encap ip dst $X1_RLOC4 dev lisp101
+	ip -n "$x2" -6 nexthop add id $NH6 encap ip6 dst $X1_RLOC6 dev lisp101
+
+	use_rlocs 4
+}
+
+cleanup()
+{
+	[[ -n $TCP_FILE ]] && rm -f "$TCP_FILE" "$TCP_FILE.out"
+	cleanup_all_ns
+}
+
+################################################################################
+# Tests
+
+netlink_test()
+{
+	local out
+
+	RET=0
+
+	out=$(ip -n "$x2" link add t0 type lisp id $IID 2>&1)
+	check_fail $? "an instance ID is used twice"
+	[[ $out == *"already has this instance ID"* ]]
+	check_err $? "unexpected error for a used instance ID: $out"
+
+	ip -n "$x2" link add t1 type lisp external
+	check_err $? "no device that collects metadata"
+	out=$(ip -n "$x2" link add t0 type lisp external 2>&1)
+	check_fail $? "two devices collect metadata"
+	[[ $out == *"already collects the metadata"* ]]
+	check_err $? "unexpected error for a second device with metadata: $out"
+	out=$(ip -n "$x2" -d -j link show dev t1 |
+	      jq -c '.[0].linkinfo.info_data')
+	[[ $out == '{"external":true}' ]]
+	check_err $? "unexpected attributes with metadata: $out"
+	ip -n "$x2" link del t1
+
+	out=$(ip -n "$x2" link add t0 type lisp id 7 local 224.0.0.1 2>&1)
+	check_fail $? "a multicast local RLOC is accepted"
+	[[ $out == *"not a unicast address"* ]]
+	check_err $? "unexpected error for a multicast RLOC: $out"
+
+	out=$(ip -n "$x2" link add t0 type lisp id 7 local fe80::1 2>&1)
+	check_fail $? "a link-local local RLOC is accepted"
+	[[ $out == *"not a global unicast address"* ]]
+	check_err $? "unexpected error for a link-local RLOC: $out"
+
+	out=$(ip -n "$x2" link set lisp101 type lisp id 7 2>&1)
+	check_fail $? "the instance ID of a device can be changed"
+	[[ $out == *"Operation not supported"* ]]
+	check_err $? "unexpected error for a change: $out"
+	ip -n "$x1" link set lisp101 type lisp local 192.0.2.99 2> /dev/null
+	check_fail $? "a local RLOC of a device can be changed"
+
+	ip -n "$x2" link add t0 type lisp id 16777215 local 192.0.2.9 \
+		local 2001:db8::9
+	check_err $? "the highest instance ID is refused"
+	out=$(ip -n "$x2" -d -j link show dev t0 | jq -c \
+		'.[0] | [.mtu, .linkinfo.info_data.id,
+			 .linkinfo.info_data.local, .linkinfo.info_data.local6]')
+	[[ $out == '[1444,16777215,"192.0.2.9","2001:db8::9"]' ]]
+	check_err $? "unexpected attributes: $out"
+	ip -n "$x2" link del t0
+
+	[[ $(ip -n "$x1" -j link show dev lisp101 | jq -r '.[0].link') == wan ]]
+	check_err $? "the link of the RLOCs is not reported"
+
+	# The same instance ID can be used with RLOCs of another l3mdev, but
+	# not twice with the same one.
+	ip -n "$x1" link add link site2 name t0 type lisp id $IID
+	check_err $? "an instance ID cannot be used with two l3mdevs"
+	ip -n "$x1" link set t0 up
+	check_err $? "an instance ID cannot be up with two l3mdevs"
+	ip -n "$x1" link del t0
+
+	out=$(ip -n "$x1" link add link eth1 name t0 type lisp id $IID 2>&1)
+	check_fail $? "an instance ID is used twice with the links of an l3mdev"
+	[[ $out == *"already has this instance ID"* ]]
+	check_err $? "unexpected error for a used l3mdev: $out"
+
+	# A link that joins the l3mdev later: the device cannot be up.
+	ip -n "$x1" link add port9 type dummy
+	ip -n "$x1" link add link port9 name t0 type lisp id $IID
+	check_err $? "an instance ID cannot be used with a link of the main table"
+	ip -n "$x1" link set port9 master wan
+	out=$(ip -n "$x1" link set t0 up 2>&1)
+	check_fail $? "an instance ID is up twice with the same l3mdev"
+	[[ $out == *"Device or resource busy"* ]]
+	check_err $? "unexpected error for a used l3mdev: $out"
+
+	# A device goes with its link.
+	ip -n "$x1" link del port9
+	busywait "$BUSYWAIT_TIMEOUT" bash -c \
+		"! ip -n $x1 link show dev t0 > /dev/null 2>&1"
+	check_err $? "a device outlives its link"
+
+	log_test "Device attributes"
+
+	if ! "$CLI" --family rt-link --list-ops > /dev/null 2>&1; then
+		log_test_skip "Device attributes that ip does not send" \
+			"YNL CLI not usable"
+		return
+	fi
+
+	RET=0
+
+	out=$(ynl_add '{"id": 16777216}')
+	[[ $out == *"Numerical result out of range"* ]]
+	check_err $? "unexpected answer to an instance ID of 25 bits: $out"
+	out=$(ynl_add '{"local": "192.0.2.9"}')
+	[[ $out == *"Invalid argument"* ]]
+	check_err $? "unexpected answer without instance ID: $out"
+	out=$(ynl_add '{"id": 7, "collect-metadata": true}')
+	[[ $out == *"Invalid argument"* ]]
+	check_err $? "unexpected answer with an instance ID and metadata: $out"
+	out=$(ynl_add '{"id": 7, "local": "192.0.2.9"}')
+	check_err $? "unexpected answer to valid attributes: $out"
+	ip -n "$x2" link del t0
+
+	log_test "Device attributes that ip does not send"
+}
+
+rloc_family_test()
+{
+	local family=$1; shift
+	local other=$1; shift
+	local before_other
+	local before
+
+	RET=0
+
+	use_rlocs "$family"
+	before=$(core_packets "$family")
+	before_other=$(core_packets "$other")
+
+	h1_ping 10.2.0.2
+	check_err $? "no answer from the IPv4 EID"
+	h1_ping fd00:2::2
+	check_err $? "no answer from the IPv6 EID"
+
+	(( $(core_packets "$family") - before == 2 ))
+	check_err $? "unexpected LISP header with IPv$family RLOCs"
+	(( $(core_packets "$other") == before_other ))
+	check_err $? "packets sent to IPv$other RLOCs"
+
+	log_test "IPv4 and IPv6 EIDs with IPv$family RLOCs"
+}
+
+ping_test()
+{
+	rloc_family_test 4 6
+	rloc_family_test 6 4
+	use_rlocs 4
+}
+
+# The TTL and the DSCP of a packet go to the outer header, then come back with
+# what the core did to them. The host sends 20, x1 forwards 19, which the core
+# gets in the outer header and forwards as 18. x2 forwards 17.
+fields_test()
+{
+	RET=0
+
+	tc -n "$core" filter add dev c1 ingress protocol ip pref 10 u32 \
+		match ip dport $LISP_PORT 0xffff match ip tos 0x28 0xff \
+		match u8 19 0xff at 8 action pass
+	tc -n "$h2" filter add dev eth0 ingress protocol ip pref 10 u32 \
+		match ip protocol 1 0xff match ip tos 0x28 0xff \
+		match u8 17 0xff at 8 action pass
+	tc -n "$h2" filter add dev eth0 ingress protocol ipv6 pref 11 u32 \
+		match ip6 protocol 58 0xff match ip6 priority 0x28 0xff \
+		match u8 17 0xff at 7 action pass
+
+	h1_ping -t 20 -Q 0x28 10.2.0.2
+	check_err $? "no answer from the IPv4 EID"
+	h1_ping -t 20 -Q 0x28 fd00:2::2
+	check_err $? "no answer from the IPv6 EID"
+
+	(( $(core_packets 10) == 2 ))
+	check_err $? "the outer header did not inherit the TTL and the DSCP"
+	(( $(h2_packets 10) == 1 ))
+	check_err $? "the IPv4 packet did not get the outer TTL and DSCP"
+	(( $(h2_packets 11) == 1 ))
+	check_err $? "the IPv6 packet did not get the outer TTL and DSCP"
+
+	tc -n "$core" filter del dev c1 ingress pref 10
+	tc -n "$h2" filter del dev eth0 ingress pref 10
+	tc -n "$h2" filter del dev eth0 ingress pref 11
+	log_test "TTL and DSCP inherited"
+
+	RET=0
+
+	ip -n "$x1" -6 nexthop add id $NH_FIELDS encap ip dst $X2_RLOC4 ttl 5 \
+		tos 0x40 dev lisp101
+	ip -n "$x1" route replace 10.2.0.0/24 vrf site nhid $NH_FIELDS
+	ip -n "$x1" -6 route replace fd00:2::/64 vrf site nhid $NH_FIELDS
+
+	tc -n "$core" filter add dev c1 ingress protocol ip pref 10 u32 \
+		match ip dport $LISP_PORT 0xffff match ip tos 0x42 0xff \
+		match u8 5 0xff at 8 action pass
+	tc -n "$core" filter add dev c2 egress protocol ip pref 10 u32 \
+		match ip dport $LISP_PORT 0xffff match ip tos 0x02 0x03 \
+		action pedit ex munge ip tos set 0x03 retain 0x03 \
+		pipe action csum ip4h
+	tc -n "$h2" filter add dev eth0 ingress protocol ip pref 10 u32 \
+		match ip protocol 1 0xff match ip tos 0x43 0xff \
+		match u8 3 0xff at 8 action pass
+	tc -n "$h2" filter add dev eth0 ingress protocol ipv6 pref 11 u32 \
+		match ip6 protocol 58 0xff match ip6 priority 0x43 0xff \
+		match u8 3 0xff at 7 action pass
+
+	h1_ping -Q 0x2a 10.2.0.2
+	check_err $? "no answer from the IPv4 EID"
+	h1_ping -Q 0x2a fd00:2::2
+	check_err $? "no answer from the IPv6 EID"
+
+	(( $(core_packets 10) == 2 ))
+	check_err $? "the outer header did not get the TTL and DSCP of the nexthop"
+	(( $(h2_packets 10) == 1 ))
+	check_err $? "the IPv4 packet did not get the outer TTL, DSCP and ECN"
+	(( $(h2_packets 11) == 1 ))
+	check_err $? "the IPv6 packet did not get the outer TTL, DSCP and ECN"
+
+	tc -n "$core" filter del dev c1 ingress pref 10
+	tc -n "$core" filter del dev c2 egress pref 10
+	tc -n "$h2" filter del dev eth0 ingress pref 10
+	tc -n "$h2" filter del dev eth0 ingress pref 11
+	use_rlocs 4
+	ip -n "$x1" nexthop del id $NH_FIELDS
+	log_test "TTL and DSCP of the nexthop, congestion marked by the core"
+}
+
+mtu_test()
+{
+	local family
+
+	for family in 4 6; do
+		RET=0
+		use_rlocs "$family"
+
+		h1_ping -M do -s 1416 10.2.0.2
+		check_err $? "an IPv4 packet of 1444 bytes is lost"
+		h1_ping -M do -s 1417 10.2.0.2
+		check_fail $? "an IPv4 packet of 1445 bytes goes through"
+		h1_ping -s 1396 fd00:2::2
+		check_err $? "an IPv6 packet of 1444 bytes is lost"
+		h1_ping -s 1397 fd00:2::2
+		check_fail $? "an IPv6 packet of 1445 bytes goes through"
+		h1_ping -s 3000 10.2.0.2
+		check_err $? "IPv4 fragments are lost"
+
+		log_test "Device MTU with IPv$family RLOCs"
+	done
+
+	ip -n "$h1" route flush cache
+	ip -n "$h1" -6 route flush cache
+	use_rlocs 4
+}
+
+pmtu_family_test()
+{
+	local family=$1; shift
+	local hlen=$1; shift
+	local mtu=$((1400 - hlen))
+
+	RET=0
+	use_rlocs "$family"
+
+	h1_ping -M do -s 1372 10.2.0.2
+	check_fail $? "a packet goes through a path that is too small"
+	h1_ping -M do -s 1372 10.2.0.2
+	check_fail $? "a packet goes through a path that is known as too small"
+	ip -n "$h1" route get 10.2.0.2 | grep -qw "mtu $mtu"
+	check_err $? "no IPv4 path MTU of $mtu on the host"
+	h1_ping -M do -s $((mtu - 28)) 10.2.0.2
+	check_err $? "an IPv4 packet of the path MTU is lost"
+
+	h1_ping -s 1352 fd00:2::2
+	check_fail $? "an IPv6 packet goes through a path that is too small"
+	ip -n "$h1" -6 route get fd00:2::2 | grep -qw "mtu $mtu"
+	check_err $? "no IPv6 path MTU of $mtu on the host"
+	h1_ping -s $((mtu - 48)) fd00:2::2
+	check_err $? "an IPv6 packet of the path MTU is lost"
+
+	log_test "Path MTU with IPv$family RLOCs"
+
+	ip -n "$h1" route flush cache
+	ip -n "$h1" -6 route flush cache
+	ip -n "$x1" route flush cache
+	ip -n "$x1" -6 route flush cache
+}
+
+frag_family_test()
+{
+	local family=$1; shift
+
+	RET=0
+	use_rlocs "$family"
+
+	# x1 learns the path MTU to the RLOC with a first packet.
+	h1_ping -s 1232 fd00:2::2
+	h1_ping -s 1232 fd00:2::2
+	check_err $? "an IPv6 packet of 1280 bytes is lost"
+	h1_ping -s 1233 fd00:2::2
+	check_fail $? "an IPv6 packet of 1281 bytes goes through"
+	ip -n "$h1" -6 route get fd00:2::2 | grep -qw "mtu 1280"
+	check_err $? "no IPv6 path MTU of 1280 on the host"
+
+	log_test "Path that leaves less than 1280 bytes, IPv$family RLOCs"
+
+	ip -n "$h1" -6 route flush cache
+	ip -n "$x1" route flush cache
+	ip -n "$x1" -6 route flush cache
+}
+
+pmtu_test()
+{
+	ip -n "$core" link set c2 mtu 1400
+	ip -n "$x2" link set eth1 mtu 1400
+
+	pmtu_family_test 4 36
+	pmtu_family_test 6 56
+
+	ip -n "$core" link set c2 mtu 1300
+	ip -n "$x2" link set eth1 mtu 1300
+
+	frag_family_test 4
+	frag_family_test 6
+
+	ip -n "$core" link set c2 mtu 1500
+	ip -n "$x2" link set eth1 mtu 1500
+	use_rlocs 4
+}
+
+multipath_test()
+{
+	local before4
+	local before6
+	local i
+
+	RET=0
+
+	for i in $(seq 16 47); do
+		ip -n "$h2" addr add "10.2.0.$i/24" dev eth0
+	done
+	ip -n "$x1" nexthop add id $NH_GROUP group $NH4/$NH6
+	ip -n "$x1" route replace 10.2.0.0/24 vrf site nhid $NH_GROUP
+
+	before4=$(core_packets 4)
+	before6=$(core_packets 6)
+	for i in $(seq 16 47); do
+		h1_ping "10.2.0.$i"
+		check_err $? "no answer from 10.2.0.$i"
+	done
+
+	(( $(core_packets 4) > before4 ))
+	check_err $? "nothing was sent to the IPv4 RLOC of the group"
+	(( $(core_packets 6) > before6 ))
+	check_err $? "nothing was sent to the IPv6 RLOC of the group"
+	(( $(core_packets 4) + $(core_packets 6) - before4 - before6 == 32 ))
+	check_err $? "packets were not sent once"
+
+	# The group counts what it sends to each RLOC.
+	(( $(ip -n "$x1" -j -s nexthop show id $NH_GROUP | jq --argjson id $NH4 \
+	     '.[0].group_stats[] | select(.id == $id) | .packets') ==
+	   $(core_packets 4) - before4 ))
+	check_err $? "unexpected count of the packets sent to the IPv4 RLOC"
+	(( $(ip -n "$x1" -j -s nexthop show id $NH_GROUP | jq --argjson id $NH6 \
+	     '.[0].group_stats[] | select(.id == $id) | .packets') ==
+	   $(core_packets 6) - before6 ))
+	check_err $? "unexpected count of the packets sent to the IPv6 RLOC"
+
+	use_rlocs 4
+	ip -n "$x1" nexthop del id $NH_GROUP
+	for i in $(seq 16 47); do
+		ip -n "$h2" addr del "10.2.0.$i/24" dev eth0
+	done
+	log_test "Group of nexthops"
+}
+
+# Another instance uses the same sockets: a device in another VRF of x1, and
+# the device that collects metadata on x2, where the routes give the instance
+# ID.
+instance_test()
+{
+	local rx_before
+	local tx_errors
+	local family
+	local addr
+
+	RET=0
+
+	ip -n "$x1" link add link wan name lisp102 type lisp id 102
+	ip -n "$x1" link set lisp102 master site2 up
+	ip -n "$x1" addr add 10.9.1.1/32 dev lisp102
+	ip -n "$x1" addr add fd00:91::1/128 dev lisp102 nodad
+
+	ip -n "$x2" link add lispmd type lisp external
+	ip -n "$x2" link set lispmd up
+	ip -n "$x2" link add dummy0 type dummy
+	ip -n "$x2" link set dummy0 up
+	ip -n "$x2" addr add 10.9.2.1/24 dev dummy0
+	ip -n "$x2" addr add fd00:92::1/64 dev dummy0 nodad
+	tc -n "$x2" qdisc add dev lispmd clsact
+
+	for family in 4 6; do
+		if [[ $family == 4 ]]; then
+			ip -n "$x1" -6 nexthop add id $NH_INSTANCE encap ip \
+				dst $X2_RLOC4 dev lisp102
+			ip -n "$x2" -6 nexthop add id $NH_INSTANCE encap ip \
+				id 102 dst $X1_RLOC4 dev lispmd
+			tc -n "$x2" filter add dev lispmd ingress pref 1 \
+				flower enc_key_id 102 enc_src_ip $X1_RLOC4 \
+				action pass
+		else
+			ip -n "$x1" -6 nexthop replace id $NH_INSTANCE encap ip6 \
+				dst $X2_RLOC6 dev lisp102
+			ip -n "$x2" -6 nexthop replace id $NH_INSTANCE encap ip6 \
+				id 102 dst $X1_RLOC6 dev lispmd
+			tc -n "$x2" filter add dev lispmd ingress pref 1 \
+				flower enc_key_id 102 enc_src_ip $X1_RLOC6 \
+				action pass
+		fi
+		ip -n "$x1" route replace 10.9.2.0/24 vrf site2 nhid $NH_INSTANCE
+		ip -n "$x1" -6 route replace fd00:92::/64 vrf site2 \
+			nhid $NH_INSTANCE
+		ip -n "$x2" route replace 10.9.1.0/24 nhid $NH_INSTANCE
+		ip -n "$x2" -6 route replace fd00:91::/64 nhid $NH_INSTANCE
+
+		rx_before=$(link_stat "$x1" lisp101 .rx.packets)
+		for addr in 10.9.2.1 fd00:92::1; do
+			ip netns exec "$x1" ping -q -c 1 -W 2 -I site2 "$addr" \
+				> /dev/null 2>&1
+			check_err $? "no answer from $addr with IPv$family RLOCs"
+		done
+
+		(( $(tc_packets "$x2" lispmd 1) == 2 ))
+		check_err $? "no metadata with IPv$family RLOCs"
+		(( $(link_stat "$x1" lisp101 .rx.packets) == rx_before ))
+		check_err $? "packets received by another instance"
+
+		tc -n "$x2" filter del dev lispmd ingress pref 1
+	done
+
+	h1_ping 10.2.0.2
+	check_err $? "the first instance is lost"
+
+	# An instance ID that does not fit the header: the device refuses it.
+	ip -n "$x2" -6 route del fd00:91::/64
+	ip -n "$x2" -6 nexthop replace id $NH_INSTANCE encap ip id 16777216 \
+		dst $X1_RLOC4 dev lispmd
+	tx_errors=$(link_stat "$x2" lispmd .tx.errors)
+	ip netns exec "$x2" ping -q -c 1 -W 1 10.9.1.1 > /dev/null 2>&1
+	check_fail $? "an instance ID of 25 bits is sent"
+	(( $(link_stat "$x2" lispmd .tx.errors) == tx_errors + 1 ))
+	check_err $? "an instance ID of 25 bits is not refused by the device"
+
+	ip -n "$x2" route del 10.9.1.0/24
+	ip -n "$x2" nexthop del id $NH_INSTANCE
+	ip -n "$x2" link del dummy0
+	ip -n "$x2" link del lispmd
+	ip -n "$x1" link del lisp102
+	log_test "Instances with a device each and with metadata"
+}
+
+receive_test()
+{
+	local frame_errors
+	local length_errors
+	local rx
+
+	RET=0
+
+	rx=$(link_stat "$x1" lisp101 .rx.packets)
+	frame_errors=$(link_stat "$x1" lisp101 .rx.frame_errors)
+	length_errors=$(link_stat "$x1" lisp101 .rx.length_errors)
+
+	# Neither IPv4 nor IPv6 after the header.
+	core_send '\x08\x00\x00\x00\x00\x00\x65\x00\x00\x00\x00\x00'
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is \
+		"== $((frame_errors + 1))" \
+		link_stat "$x1" lisp101 .rx.frame_errors > /dev/null
+	check_err $? "a payload of an unknown version is not counted"
+
+	# An IPv4 header that is cut.
+	core_send '\x08\x00\x00\x00\x00\x00\x65\x00\x45\x00\x00\x00'
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is \
+		"== $((length_errors + 1))" \
+		link_stat "$x1" lisp101 .rx.length_errors > /dev/null
+	check_err $? "a short payload is not counted"
+
+	# An encrypted payload, an unknown instance, and no instance.
+	core_send '\x09\x00\x00\x00\x00\x00\x65\x00\x00\x00\x00\x00'
+	core_send '\x08\x00\x00\x00\x00\x00\x66\x00\x00\x00\x00\x00'
+	core_send '\x00\x00\x00\x00\x00\x00\x65\x00\x00\x00\x00\x00'
+	core_send '\x08\x00\x00\x00\x00\x00\x65\x00\x00\x00\x00\x00'
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is \
+		"== $((frame_errors + 2))" \
+		link_stat "$x1" lisp101 .rx.frame_errors > /dev/null
+	check_err $? "packets of other instances are counted"
+
+	# Without the I flag, the instance is 0.
+	ip -n "$x1" link add link wan name lisp0 type lisp id 0
+	ip -n "$x1" link set lisp0 up
+	core_send '\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00'
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== 1" \
+		link_stat "$x1" lisp0 .rx.frame_errors > /dev/null
+	check_err $? "a packet without instance ID is not for the instance 0"
+	ip -n "$x1" link del lisp0
+
+	(( $(link_stat "$x1" lisp101 .rx.packets) == rx ))
+	check_err $? "packets were received"
+
+	# A route without RLOC.
+	ip -n "$x1" route add 10.3.0.0/24 vrf site dev lisp101
+	rx=$(link_stat "$x1" lisp101 .tx.errors)
+	h1_ping -W 1 10.3.0.1
+	(( $(link_stat "$x1" lisp101 .tx.errors) == rx + 1 ))
+	check_err $? "a packet without RLOC is not counted"
+	ip -n "$x1" route del 10.3.0.0/24 vrf site
+
+	log_test "Packets that are dropped"
+}
+
+# the reverse path filter of IPv4 dropped on x1
+x1_filtered()
+{
+	ip netns exec "$x1" nstat -asz TcpExtIPReversePathFilter |
+		awk '$1 == "TcpExtIPReversePathFilter" { print $2 }'
+}
+
+h1_echos()
+{
+	ip netns exec "$h1" nstat -asz IcmpInEchos |
+		awk '$1 == "IcmpInEchos" { print $2 }'
+}
+
+rpfilter_test()
+{
+	local filtered
+	local echos
+	local all
+
+	RET=0
+
+	use_rlocs 4
+	all=$(ip netns exec "$x1" sysctl -n net.ipv4.conf.all.rp_filter)
+	ip netns exec "$x1" sysctl -qw net.ipv4.conf.all.rp_filter=0
+	ip netns exec "$x1" sysctl -qw net.ipv4.conf.lisp101.rp_filter=1
+
+	h2_ping 10.1.0.2
+	check_err $? "a source is dropped, whose route sends to the device"
+
+	# The route of the source has another RLOC than the one of x2.
+	ip -n "$x1" -6 nexthop add id $NH_OTHER encap ip dst $OTHER_RLOC4 \
+		dev lisp101
+	ip -n "$x1" route replace 10.2.0.0/24 vrf site nhid $NH_OTHER
+	echos=$(h1_echos)
+	h2_ping 10.1.0.2
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== $((echos + 1))" \
+		h1_echos > /dev/null
+	check_err $? "a source is dropped for the RLOC that it comes from"
+
+	ip -n "$x1" link add nomap type dummy
+	ip -n "$x1" link set nomap master site up
+	ip -n "$x1" route replace 10.2.0.0/24 vrf site dev nomap
+	filtered=$(x1_filtered)
+	h2_ping 10.1.0.2
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== $((filtered + 1))" \
+		x1_filtered > /dev/null
+	check_err $? "a source without mapping is not dropped by the filter"
+
+	ip netns exec "$x1" sysctl -qw net.ipv4.conf.lisp101.rp_filter=0
+	echos=$(h1_echos)
+	h2_ping 10.1.0.2
+	busywait "$BUSYWAIT_TIMEOUT" until_counter_is "== $((echos + 1))" \
+		h1_echos > /dev/null
+	check_err $? "a source without mapping is dropped without the filter"
+
+	ip netns exec "$x1" sysctl -qw net.ipv4.conf.all.rp_filter="$all"
+	ip -n "$x1" link del nomap
+	ip -n "$x1" nexthop del id $NH_OTHER
+	use_rlocs 4
+	h2_ping 10.1.0.2
+	check_err $? "no connectivity after the test"
+
+	log_test "Reverse path filter on a device"
+}
+
+updown_test()
+{
+	RET=0
+
+	ip -n "$x1" link add link wan name lisp102 type lisp id 102
+	ip -n "$x1" link set lisp102 up
+	ip -n "$x1" link set lisp101 down
+	h1_ping -W 1 10.2.0.2
+	check_fail $? "an answer through a device that is down"
+
+	ip -n "$x1" nexthop show id $NH4 > /dev/null 2>&1
+	check_fail $? "a nexthop outlives its device"
+	ip -n "$x1" link set lisp101 up
+	ip -n "$x1" -6 nexthop add id $NH4 encap ip dst $X2_RLOC4 dev lisp101
+	ip -n "$x1" -6 nexthop add id $NH6 encap ip6 dst $X2_RLOC6 dev lisp101
+	use_rlocs 4
+	ip -n "$x1" link del lisp102
+	h1_ping 10.2.0.2
+	check_err $? "no answer once the device is up again"
+
+	ip -n "$x1" link set lisp101 down
+	ip -n "$x1" link set lisp101 up
+	ip -n "$x1" -6 nexthop add id $NH4 encap ip dst $X2_RLOC4 dev lisp101
+	ip -n "$x1" -6 nexthop add id $NH6 encap ip6 dst $X2_RLOC6 dev lisp101
+	use_rlocs 4
+	h1_ping fd00:2::2
+	check_err $? "no answer with a new socket"
+
+	log_test "Devices going down and up"
+}
+
+tcp_family_test()
+{
+	local family=$1; shift
+	local addr=$1; shift
+	local pid
+
+	ip netns exec "$h2" timeout $TCP_TIMEOUT socat -u \
+		"TCP$family-LISTEN:$TCP_PORT,reuseaddr" \
+		"OPEN:$TCP_FILE.out,creat,trunc" &
+	pid=$!
+	wait_local_port_listen "$h2" $TCP_PORT tcp
+	if ip netns exec "$h1" timeout $TCP_TIMEOUT socat -u "OPEN:$TCP_FILE" \
+			"TCP$family:$addr:$TCP_PORT"; then
+		wait $pid
+		check_err $? "the listener of $addr did not end"
+	else
+		check_err 1 "no TCP connection to $addr"
+		kill_process $pid
+	fi
+
+	cmp -s "$TCP_FILE" "$TCP_FILE.out"
+	check_err $? "the data sent to $addr is not what was received"
+}
+
+tcp_test()
+{
+	local family
+
+	if ! command -v socat > /dev/null; then
+		log_test_skip "TCP" "socat not installed"
+		return
+	fi
+
+	TCP_FILE=$(mktemp)
+	head -c 16M /dev/urandom > "$TCP_FILE"
+
+	for family in 4 6; do
+		RET=0
+		use_rlocs "$family"
+		tcp_family_test 4 10.2.0.2
+		tcp_family_test 6 "[fd00:2::2]"
+		log_test "TCP with IPv$family RLOCs"
+	done
+	use_rlocs 4
+}
+
+# Two xTRs whose EIDs and RLOCs are in two routing domains with the same
+# addresses: the EID of an xTR is the RLOC of the other one. A packet and its
+# outer header have then the same addresses, the other way around, and they
+# only reach their destinations when each one is routed in its own domain.
+CROSS_A4=192.0.2.9
+CROSS_A6=2001:db8:3::1
+CROSS_B4=192.0.2.10
+CROSS_B6=2001:db8:3::2
+
+cross_nexthops()
+{
+	local ns=$1; shift
+	local rloc4=$1; shift
+	local rloc6=$1; shift
+
+	ip -n "$ns" -6 nexthop add id $NH4 encap ip dst "$rloc4" dev lisp0
+	ip -n "$ns" -6 nexthop add id $NH6 encap ip6 dst "$rloc6" dev lisp0
+}
+
+cross_routes()
+{
+	local ns=$1; shift
+	local nh=$1; shift
+	local eid4=$1; shift
+	local eid6=$1; shift
+
+	ip -n "$ns" route replace "$eid4/32" "$@" nhid "$nh"
+	ip -n "$ns" -6 route replace "$eid6/128" "$@" nhid "$nh"
+}
+
+cross_ping()
+{
+	local ns=$1; shift
+	local eid4=$1; shift
+	local eid6=$1; shift
+	local before
+
+	before=$(link_stat "$ns" lisp0 .rx.packets)
+	ip netns exec "$ns" ping -q -c 1 -W 2 "$@" "$eid4" > /dev/null 2>&1
+	check_err $? "no answer from the EID $eid4"
+	ip netns exec "$ns" ping -q -c 1 -W 2 "$@" "$eid6" > /dev/null 2>&1
+	check_err $? "no answer from the EID $eid6"
+	(( $(link_stat "$ns" lisp0 .rx.packets) == before + 2 ))
+	check_err $? "the answers did not come through the LISP device"
+}
+
+# The first xTR has its EIDs in a VRF and its RLOCs in the main table, the
+# second one has its RLOCs in a VRF and its EIDs in the main table.
+#
+#   y1                                           y2
+#   VRF "eid", lisp0: B4, B6 ................... lisp0: A4, A6
+#   eth0: A4, A6 ------------------------------- VRF "rloc", eth0: B4, B6
+cross_vrf_test()
+{
+	local family
+	local before
+	local ns
+	local nh
+
+	setup_ns y1 y2
+	ip link add eth0 netns "$y1" type veth peer name eth0 netns "$y2"
+
+	for ns in "$y1" "$y2"; do
+		ip -n "$ns" rule add pref 32765 table local
+		ip -n "$ns" rule del pref 0
+		ip -n "$ns" -6 rule add pref 32765 table local
+		ip -n "$ns" -6 rule del pref 0
+	done
+
+	ip -n "$y1" link set eth0 up
+	ip -n "$y1" addr add $CROSS_A4/30 dev eth0
+	ip -n "$y1" addr add $CROSS_A6/64 dev eth0 nodad
+	ip -n "$y1" link add eid type vrf table 10
+	ip -n "$y1" link set eid up
+	ip -n "$y1" link add lisp0 type lisp id 7
+	ip -n "$y1" link set lisp0 master eid up
+	ip -n "$y1" addr add $CROSS_B4/32 dev lisp0
+	ip -n "$y1" addr add $CROSS_B6/128 dev lisp0 nodad
+	cross_nexthops "$y1" $CROSS_B4 $CROSS_B6
+
+	ip -n "$y2" link add rloc type vrf table 10
+	ip -n "$y2" link set rloc up
+	ip -n "$y2" link set eth0 master rloc up
+	ip -n "$y2" addr add $CROSS_B4/30 dev eth0
+	ip -n "$y2" addr add $CROSS_B6/64 dev eth0 nodad
+	ip -n "$y2" link add link rloc name lisp0 type lisp id 7
+	ip -n "$y2" link set lisp0 up
+	ip -n "$y2" addr add $CROSS_A4/32 dev lisp0
+	ip -n "$y2" addr add $CROSS_A6/128 dev lisp0 nodad
+	cross_nexthops "$y2" $CROSS_A4 $CROSS_A6
+
+	for family in 4 6; do
+		RET=0
+		nh=NH$family
+		cross_routes "$y1" "${!nh}" $CROSS_A4 $CROSS_A6 vrf eid
+		cross_routes "$y2" "${!nh}" $CROSS_B4 $CROSS_B6
+
+		cross_ping "$y1" $CROSS_A4 $CROSS_A6 -I eid
+		cross_ping "$y2" $CROSS_B4 $CROSS_B6
+
+		# In the main table of y1, the same addresses are the RLOCs
+		# of y2, which answer without LISP.
+		before=$(link_stat "$y1" lisp0 .tx.packets)
+		ip netns exec "$y1" ping -q -c 1 -W 2 $CROSS_B4 > /dev/null 2>&1
+		check_err $? "no answer from the RLOC $CROSS_B4"
+		ip netns exec "$y1" ping -q -c 1 -W 2 $CROSS_B6 > /dev/null 2>&1
+		check_err $? "no answer from the RLOC $CROSS_B6"
+		(( $(link_stat "$y1" lisp0 .tx.packets) == before ))
+		check_err $? "packets for an RLOC were sent to the LISP device"
+
+		log_test "EIDs and RLOCs in a VRF and the main table, IPv$family RLOCs"
+	done
+
+	cleanup_ns "$y1" "$y2"
+}
+
+# Both xTRs have their EIDs in a netns and their RLOCs in another one. The
+# netns of the EIDs has no other device than the LISP one.
+#
+#   ain                                          bin
+#   lisp0: B4, B6 .............................. lisp0: A4, A6
+#   aout                                         bout
+#   eth0: A4, A6 ------------------------------- eth0: B4, B6
+cross_netns_test()
+{
+	local family
+	local nh
+
+	setup_ns ain aout bin bout
+	ip link add eth0 netns "$aout" type veth peer name eth0 netns "$bout"
+
+	ip -n "$aout" link set eth0 up
+	ip -n "$aout" addr add $CROSS_A4/30 dev eth0
+	ip -n "$aout" addr add $CROSS_A6/64 dev eth0 nodad
+	ip -n "$ain" link add lisp0 link-netns "$aout" type lisp id 8
+	ip -n "$ain" link set lisp0 up
+	ip -n "$ain" addr add $CROSS_B4/32 dev lisp0
+	ip -n "$ain" addr add $CROSS_B6/128 dev lisp0 nodad
+	cross_nexthops "$ain" $CROSS_B4 $CROSS_B6
+
+	ip -n "$bout" link set eth0 up
+	ip -n "$bout" addr add $CROSS_B4/30 dev eth0
+	ip -n "$bout" addr add $CROSS_B6/64 dev eth0 nodad
+	ip -n "$bin" link add lisp0 link-netns "$bout" type lisp id 8
+	ip -n "$bin" link set lisp0 up
+	ip -n "$bin" addr add $CROSS_A4/32 dev lisp0
+	ip -n "$bin" addr add $CROSS_A6/128 dev lisp0 nodad
+	cross_nexthops "$bin" $CROSS_A4 $CROSS_A6
+
+	for family in 4 6; do
+		RET=0
+		nh=NH$family
+		cross_routes "$ain" "${!nh}" $CROSS_A4 $CROSS_A6
+		cross_routes "$bin" "${!nh}" $CROSS_B4 $CROSS_B6
+
+		cross_ping "$ain" $CROSS_A4 $CROSS_A6
+		cross_ping "$bin" $CROSS_B4 $CROSS_B6
+
+		log_test "EIDs and RLOCs in two netns, IPv$family RLOCs"
+	done
+
+	cleanup_ns "$ain" "$aout" "$bin" "$bout"
+}
+
+netns_test()
+{
+	local port
+
+	RET=0
+	port=$(printf ':%04X' $LISP_PORT)
+
+	setup_ns eid rloc
+	ip -n "$eid" link add lisp0 link-netns "$rloc" type lisp id 5
+	check_err $? "no device with a link netns"
+	ip -n "$eid" link set lisp0 up
+	ip -n "$eid" -d link show dev lisp0 | grep -q link-netns
+	check_err $? "the link netns is not reported"
+	ip netns exec "$rloc" grep -q "$port " /proc/net/udp /proc/net/udp6
+	check_err $? "no socket in the link netns"
+	ip netns exec "$eid" grep -q "$port " /proc/net/udp /proc/net/udp6
+	check_fail $? "a socket in the netns of the device"
+
+	cleanup_ns "$rloc"
+	busywait "$BUSYWAIT_TIMEOUT" bash -c \
+		"! ip -n $eid link show dev lisp0 > /dev/null 2>&1"
+	check_err $? "the device outlives the netns of its RLOCs"
+	cleanup_ns "$eid"
+
+	log_test "RLOCs in another netns"
+}
+
+################################################################################
+# Main
+
+require_command jq
+
+if ! ip link help lisp 2>&1 | grep -q "^Usage: ... lisp"; then
+	echo "SKIP: iproute2 does not know the lisp devices"
+	exit "$ksft_skip"
+fi
+
+trap cleanup EXIT
+
+setup_ns probe
+out=$(ip -n "$probe" link add lisp0 type lisp id 1 2>&1)
+if [[ $out == *"Unknown device type"* ]]; then
+	echo "SKIP: the kernel does not have the lisp devices (CONFIG_LISP)"
+	exit "$ksft_skip"
+fi
+cleanup_ns "$probe"
+
+if ! setup; then
+	echo "FAIL: the setup of the test failed"
+	exit "$ksft_fail"
+fi
+
+tests_run
+
+exit "$EXIT_STATUS"

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 5/5] selftests: net: add a scale test for LISP
  2026-11-26 21:37 [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Vincent Jardin via B4 Relay
                   ` (3 preceding siblings ...)
  2026-11-26 21:37 ` [PATCH net-next 4/5] selftests: net: add a test of " Vincent Jardin via B4 Relay
@ 2026-11-26 21:37 ` Vincent Jardin via B4 Relay
  2026-11-27 10:24 ` [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Matthieu Baerts
  5 siblings, 0 replies; 7+ messages in thread
From: Vincent Jardin via B4 Relay @ 2026-11-26 21:37 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Vincent Jardin, Donald Hunter, Nicolas Dichtel,
	Simon Horman, Jonathan Corbet, Shuah Khan, Randy Dunlap,
	Shuah Khan
  Cc: linux-kernel, netdev, linux-doc, linux-kselftest

From: Vincent Jardin <vjardin@free.fr>

Scenario: an xTR with the mappings of many remote sites on one LISP
device.
1 nexthop per site, half of them with an IPv4 RLOC and half with an
IPv6 one, and 4 routes per site, 2 IPv4 and 2 IPv6 EID prefixes.

Another xTR stands for all the sites.

Signed-off-by: Vincent Jardin <vjardin@free.fr>
---
 tools/testing/selftests/net/Makefile      |   1 +
 tools/testing/selftests/net/lisp_scale.sh | 532 ++++++++++++++++++++++++++++++
 2 files changed, 533 insertions(+)

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 7263049ab7c44..27a1e9e6b4ed3 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -64,6 +64,7 @@ TEST_PROGS := \
 	l2tp.sh \
 	link_netns.py \
 	lisp.sh \
+	lisp_scale.sh \
 	lwt_dst_cache_ref_loop.sh \
 	macvlan_mcast_shared_mac.sh \
 	msg_zerocopy.sh \
diff --git a/tools/testing/selftests/net/lisp_scale.sh b/tools/testing/selftests/net/lisp_scale.sh
new file mode 100755
index 0000000000000..badba6491a42c
--- /dev/null
+++ b/tools/testing/selftests/net/lisp_scale.sh
@@ -0,0 +1,532 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Vincent Jardin <vjardin@free.fr>, Free Mobile
+#
+# Scale of the LISP data plane of drivers/net/lisp.c: the mappings of many
+# remote sites on one device of an xTR. A site is an RLOC, which is a nexthop,
+# and EID prefixes, which are routes to it. The sites with an even number have
+# an IPv4 RLOC, the others an IPv6 one. Each site has two IPv4 and two IPv6 EID
+# prefixes.
+#
+# x2 stands for all the remote sites: their RLOCs and their EIDs are local to
+# it, and it answers to the EIDs of x1.
+#
+#   x1 (VRF "site")                                    x2
+#   172.16.0.1, fd01::1    lisp101 ...... lisp101      10.0.0.0/8, fd00::/16
+#   192.0.2.1, 2001:db8:1::1  veth        veth         198.18.0.0/15,
+#                                                      2001:db8:ffff::/48
+#
+# LISP_SITES is the number of sites: 40000 by default, 8000 on a slow machine,
+# which is also the least: the tests change sites of their own, below 8000.
+
+source lib.sh
+
+if [[ $KSFT_MACHINE_SLOW == yes ]]; then
+	: "${LISP_SITES:=8000}"
+else
+	: "${LISP_SITES:=40000}"
+fi
+
+ALL_TESTS="
+	install_test
+	stats_test
+	move_test
+	replace_test
+	withdraw_test
+	churn_test
+	down_test
+"
+
+X1_RLOC4=192.0.2.1
+X1_RLOC6=2001:db8:1::1
+
+# The nexthop of a site has its number plus 1 as ID. Those of the sites that
+# move are above the others, and the groups above them.
+NH_MOVED=1000000
+NH_GROUP=2000000
+
+################################################################################
+# Helpers
+
+site_addr()
+{
+	local site=$1; shift
+	local format=$1; shift
+
+	awk -v i="$site" "BEGIN { printf \"$format\", $* }"
+}
+
+site_rloc()
+{
+	local site=$1; shift
+
+	if (( site % 2 )); then
+		site_addr "$site" "2001:db8:ffff:%x::1" i
+	else
+		site_addr "$site" "198.18.%d.%d" "int(i / 256), i % 256"
+	fi
+}
+
+# The IPv4 RLOC that a site gets when a test moves it.
+site_moved_rloc()
+{
+	site_addr "$1" "198.19.%d.%d" "int(i / 256), i % 256"
+}
+
+site_eid4()
+{
+	site_addr "$1" "10.%d.%d.129" "int(i / 256), i % 256"
+}
+
+site_eid6()
+{
+	site_addr "$1" "fd00:%x:1::1" i
+}
+
+sites_batch()
+{
+	local family=$1; shift
+	local first=$1; shift
+	local last=$1; shift
+	local program=$1; shift
+
+	awk -v first="$first" -v last="$last" -v moved="$NH_MOVED" \
+	    -v group="$NH_GROUP" "
+	BEGIN {
+		for (i = first; i < last; i++) {
+			nh = i + 1
+			hi = int(i / 256)
+			lo = i % 256
+			if (i % 2) {
+				encap = \"ip6\"
+				rloc = sprintf(\"2001:db8:ffff:%x::1\", i)
+			} else {
+				encap = \"ip\"
+				rloc = sprintf(\"198.18.%d.%d\", hi, lo)
+			}
+			$program
+		}
+	}" | ip -n "$x1" ${family:+-$family} -batch -
+}
+
+SITE_ROUTES='
+	printf "route %s 10.%d.%d.0/25 vrf site nhid %d\n", cmd, hi, lo, to
+	printf "route %s 10.%d.%d.128/25 vrf site nhid %d\n", cmd, hi, lo, to
+	printf "route %s fd00:%x:0::/64 vrf site nhid %d\n", cmd, i, to
+	printf "route %s fd00:%x:1::/64 vrf site nhid %d\n", cmd, i, to
+'
+
+sites_add()
+{
+	local first=$1; shift
+	local last=$1; shift
+
+	sites_batch 6 "$first" "$last" '
+		printf "nexthop add id %d encap %s dst %s dev lisp101\n", \
+			nh, encap, rloc
+	' && sites_batch "" "$first" "$last" \
+		"cmd = \"add\"; to = nh; $SITE_ROUTES"
+}
+
+count_nexthops()
+{
+	ip -n "$x1" nexthop show dev lisp101 | wc -l
+}
+
+count_routes()
+{
+	local family=$1; shift
+
+	ip -n "$x1" "-$family" route show vrf site | grep -c " nhid "
+}
+
+site_ping()
+{
+	local site=$1; shift
+
+	ip netns exec "$x1" ping -q -c 1 -W 2 -I site "$(site_eid4 "$site")" \
+		> /dev/null 2>&1 &&
+	ip netns exec "$x1" ping -q -c 1 -W 2 -I site "$(site_eid6 "$site")" \
+		> /dev/null 2>&1
+}
+
+rloc_filter()
+{
+	local rloc=$1; shift
+	local protocol=ip
+
+	[[ $rloc == *:* ]] && protocol=ipv6
+	tc -n "$x2" filter add dev eth0 ingress protocol $protocol pref 1 \
+		flower dst_ip "$rloc" action pass
+}
+
+rloc_packets()
+{
+	tc -n "$x2" -j -s filter show dev eth0 ingress pref 1 |
+		jq '[.[] | select(.options.actions) |
+		     .options.actions[0].stats.packets] | add'
+	tc -n "$x2" filter del dev eth0 ingress pref 1
+}
+
+site_check()
+{
+	local site=$1; shift
+	local rloc=$1; shift
+
+	rloc_filter "$rloc"
+	site_ping "$site"
+	check_err $? "no answer from the site $site"
+	(( $(rloc_packets) == 2 ))
+	check_err $? "the site $site is not reached through $rloc"
+}
+
+elapsed()
+{
+	local start=$1; shift
+
+	echo "$(( $(timestamp_ms) - start )) ms"
+}
+
+################################################################################
+# Setup
+
+setup()
+{
+	local ns
+
+	setup_ns x1 x2 || return
+
+	ip link add eth0 netns "$x1" type veth peer name eth0 netns "$x2"
+	for ns in "$x1" "$x2"; do
+		ip netns exec "$ns" sysctl -wq net.ipv4.ip_forward=1
+		ip netns exec "$ns" sysctl -wq net.ipv6.conf.all.forwarding=1
+		ip -n "$ns" link set eth0 up
+	done
+
+	ip -n "$x1" addr add $X1_RLOC4/30 dev eth0
+	ip -n "$x1" addr add $X1_RLOC6/64 dev eth0 nodad
+	ip -n "$x1" route add 198.18.0.0/15 via 192.0.2.2
+	ip -n "$x1" -6 route add 2001:db8:ffff::/48 via 2001:db8:1::2
+	ip -n "$x1" link add site type vrf table 10
+	ip -n "$x1" link set site up
+	ip -n "$x1" link add lisp101 type lisp id 101 \
+		local $X1_RLOC4 local $X1_RLOC6 || return
+	ip -n "$x1" link set lisp101 master site up
+	ip -n "$x1" addr add 172.16.0.1/32 dev lisp101
+	ip -n "$x1" addr add fd01::1/128 dev lisp101 nodad
+
+	ip -n "$x2" addr add 192.0.2.2/30 dev eth0
+	ip -n "$x2" addr add 2001:db8:1::2/64 dev eth0 nodad
+	ip -n "$x2" route add local 198.18.0.0/15 dev lo
+	ip -n "$x2" -6 route add local 2001:db8:ffff::/48 dev lo
+	ip -n "$x2" route add local 10.0.0.0/8 dev lo
+	ip -n "$x2" -6 route add local fd00::/16 dev lo
+	ip -n "$x2" link add lisp101 type lisp id 101
+	ip -n "$x2" link set lisp101 up
+	ip -n "$x2" route add 172.16.0.1/32 encap ip dst $X1_RLOC4 dev lisp101
+	ip -n "$x2" -6 route add fd01::1/128 encap ip6 dst $X1_RLOC6 \
+		dev lisp101
+	tc -n "$x2" qdisc add dev eth0 clsact
+}
+
+cleanup()
+{
+	cleanup_all_ns
+}
+
+################################################################################
+# Tests
+
+install_test()
+{
+	local start
+	local site
+
+	RET=0
+
+	start=$(timestamp_ms)
+	sites_add 0 "$LISP_SITES"
+	check_err $? "the sites are not installed"
+	log_info "$LISP_SITES sites installed in $(elapsed "$start")"
+
+	(( $(count_nexthops) == LISP_SITES ))
+	check_err $? "unexpected count of nexthops"
+	(( $(count_routes 4) == 2 * LISP_SITES ))
+	check_err $? "unexpected count of IPv4 routes"
+	(( $(count_routes 6) == 2 * LISP_SITES ))
+	check_err $? "unexpected count of IPv6 routes"
+
+	for site in 0 1 $((LISP_SITES / 2)) $((LISP_SITES / 2 + 1)) \
+		    $((LISP_SITES - 2)) $((LISP_SITES - 1)); do
+		site_check "$site" "$(site_rloc "$site")"
+	done
+
+	log_test "$LISP_SITES sites: $LISP_SITES nexthops, $((4 * LISP_SITES)) routes"
+}
+
+stats_test()
+{
+	local rx_before
+	local tx_before
+	local packets
+	local i
+
+	RET=0
+
+	ip -n "$x1" nexthop add id $NH_GROUP group 6001/6002
+	sites_batch "" 6000 6064 "cmd = \"replace\"; to = group; $SITE_ROUTES"
+
+	tx_before=$(ip -n "$x1" -j -s link show dev lisp101 |
+		    jq '.[0].stats64.tx.packets')
+	rx_before=$(ip -n "$x1" -j -s link show dev lisp101 |
+		    jq '.[0].stats64.rx.packets')
+	for i in $(seq 6000 6063); do
+		site_ping "$i"
+		check_err $? "no answer from the site $i"
+	done
+
+	(( $(ip -n "$x1" -j -s link show dev lisp101 |
+	     jq '.[0].stats64.tx.packets') == tx_before + 128 ))
+	check_err $? "unexpected count of sent packets"
+	(( $(ip -n "$x1" -j -s link show dev lisp101 |
+	     jq '.[0].stats64.rx.packets') == rx_before + 128 ))
+	check_err $? "unexpected count of received packets"
+
+	packets=$(ip -n "$x1" -j -s nexthop show id $NH_GROUP |
+		  jq -c '[.[0].group_stats[].packets]')
+	(( $(jq 'add' <<< "$packets") >= 128 ))
+	check_err $? "unexpected count of the packets of the group: $packets"
+	[[ $(jq 'min' <<< "$packets") != 0 ]]
+	check_err $? "an RLOC of the group is not used: $packets"
+
+	sites_batch "" 6000 6064 "cmd = \"replace\"; to = nh; $SITE_ROUTES"
+	ip -n "$x1" nexthop del id $NH_GROUP
+	log_test "Counters of the device and of a group"
+}
+
+move_test()
+{
+	local start
+
+	RET=0
+
+	start=$(timestamp_ms)
+	sites_batch 6 1000 2000 '
+		printf "nexthop add id %d encap ip dst 198.19.%d.%d dev lisp101\n", \
+			moved + i, hi, lo
+	' && sites_batch "" 1000 2000 \
+		"cmd = \"replace\"; to = moved + i; $SITE_ROUTES" &&
+	sites_batch "" 1000 2000 'printf "nexthop del id %d\n", nh'
+	check_err $? "the sites are not moved"
+	log_info "1000 sites moved to new nexthops in $(elapsed "$start")"
+
+	(( $(count_nexthops) == LISP_SITES ))
+	check_err $? "unexpected count of nexthops"
+	site_check 1000 "$(site_moved_rloc 1000)"
+	site_check 1999 "$(site_moved_rloc 1999)"
+	site_check 2000 "$(site_rloc 2000)"
+
+	log_test "RLOC changed with new nexthops"
+}
+
+replace_test()
+{
+	local start
+
+	RET=0
+
+	start=$(timestamp_ms)
+	sites_batch 6 2000 2100 '
+		printf "nexthop replace id %d encap ip dst 198.19.%d.%d dev lisp101\n", \
+			nh, hi, lo
+	'
+	check_err $? "the nexthops are not replaced"
+	log_info "100 nexthops replaced in $(elapsed "$start")"
+
+	site_check 2000 "$(site_moved_rloc 2000)"
+	site_check 2099 "$(site_moved_rloc 2099)"
+	site_check 2100 "$(site_rloc 2100)"
+
+	log_test "RLOC changed in place"
+}
+
+withdraw_test()
+{
+	local start
+
+	RET=0
+
+	start=$(timestamp_ms)
+	sites_batch "" 3000 4000 '
+		printf "route del 10.%d.%d.0/25 vrf site\n", hi, lo
+		printf "route del 10.%d.%d.128/25 vrf site\n", hi, lo
+		printf "route del fd00:%x:0::/64 vrf site\n", i
+		printf "route del fd00:%x:1::/64 vrf site\n", i
+	' && sites_batch "" 3000 4000 'printf "nexthop del id %d\n", nh'
+	check_err $? "the sites are not withdrawn"
+	log_info "1000 sites withdrawn in $(elapsed "$start")"
+
+	start=$(timestamp_ms)
+	sites_batch "" 4000 4100 'printf "nexthop del id %d\n", nh'
+	check_err $? "the nexthops are not removed"
+	log_info "100 nexthops removed with their routes in $(elapsed "$start")"
+
+	(( $(count_nexthops) == LISP_SITES - 1100 ))
+	check_err $? "unexpected count of nexthops"
+	(( $(count_routes 4) == 2 * (LISP_SITES - 1100) ))
+	check_err $? "unexpected count of IPv4 routes"
+	(( $(count_routes 6) == 2 * (LISP_SITES - 1100) ))
+	check_err $? "unexpected count of IPv6 routes"
+
+	site_ping 3500
+	check_fail $? "an answer from a site that left"
+	site_ping 4050
+	check_fail $? "an answer from a site whose nexthop was removed"
+	site_check 4100 "$(site_rloc 4100)"
+
+	log_test "Sites withdrawn"
+}
+
+churn_test()
+{
+	local loops=()
+	local pids=()
+	local rounds=0
+	local site
+	local out
+	local pid
+
+	RET=0
+
+	out=$(mktemp -d)
+	for site in 5500 5501; do
+		ip netns exec "$x1" ping -q -f -w 10 -I site \
+			"$(site_eid4 "$site")" > "$out/$site.4" 2>&1 &
+		pids+=($!)
+		ip netns exec "$x1" ping -q -f -w 10 -I site \
+			"$(site_eid6 "$site")" > "$out/$site.6" 2>&1 &
+		pids+=($!)
+	done
+
+	for site in 5000 5001; do
+		while :; do
+			ip netns exec "$x1" ping -q -f -w 1 -I site \
+				"$(site_eid4 "$site")"
+			ip netns exec "$x1" ping -q -f -w 1 -I site \
+				"$(site_eid6 "$site")"
+		done > /dev/null 2>&1 &
+		loops+=($!)
+	done
+
+	while kill -0 "${pids[0]}" 2> /dev/null; do
+		sites_batch "" 5000 5200 'printf "nexthop del id %d\n", nh'
+		sites_add 5000 5200
+		check_err $? "the sites are not installed again"
+		sites_batch 6 5000 5016 '
+			printf "nexthop replace id %d encap ip dst 198.19.%d.%d dev lisp101\n", \
+				nh, hi, lo
+		'
+		sites_batch 6 5000 5016 '
+			printf "nexthop replace id %d encap %s dst %s dev lisp101\n", \
+				nh, encap, rloc
+		'
+		rounds=$((rounds + 1))
+	done
+	log_info "$rounds rounds of changes under traffic"
+
+	for pid in "${loops[@]}"; do
+		kill_process "$pid"
+	done
+	for pid in "${pids[@]}"; do
+		wait "$pid"
+		check_err $? "no answer from a site that did not change"
+	done
+	# The ping that a loop was running goes on for a second without it.
+	ip netns pids "$x1" | xargs -r kill 2> /dev/null
+
+	# The changes of the other sites cost them less than half their packets.
+	for site in 5500 5501; do
+		awk '/packets transmitted/ { n++; if ($4 * 2 < $1) lost = 1 }
+		     END { exit lost || n != 2 }' "$out/$site.4" "$out/$site.6"
+		check_err $? "most packets of a site that did not change are lost"
+	done
+	rm -rf "$out"
+
+	(( $(count_nexthops) == LISP_SITES - 1100 ))
+	check_err $? "unexpected count of nexthops"
+	site_check 5002 "$(site_rloc 5002)"
+	site_check 5199 "$(site_rloc 5199)"
+	site_check 5500 "$(site_rloc 5500)"
+
+	log_test "Mappings changed under traffic"
+}
+
+down_test()
+{
+	local start
+	local pid
+
+	RET=0
+
+	ip netns exec "$x1" ping -q -f -w 4 -I site "$(site_eid4 7500)" \
+		> /dev/null 2>&1 &
+	pid=$!
+
+	start=$(timestamp_ms)
+	ip -n "$x1" link set lisp101 down
+	log_info "device down with its nexthops and routes in $(elapsed "$start")"
+	(( $(count_nexthops) == 0 ))
+	check_err $? "nexthops outlive the device"
+	(( $(count_routes 4) == 0 && $(count_routes 6) == 0 ))
+	check_err $? "routes outlive the device"
+
+	ip -n "$x1" link set lisp101 up
+	ip -n "$x1" addr add fd01::1/128 dev lisp101 nodad
+	sites_add 7000 7100
+	check_err $? "no site can be installed again"
+	site_check 7000 "$(site_rloc 7000)"
+	site_check 7099 "$(site_rloc 7099)"
+
+	start=$(timestamp_ms)
+	ip -n "$x1" link del lisp101
+	log_info "device deleted in $(elapsed "$start")"
+	(( $(ip -n "$x1" nexthop | wc -l) == 0 ))
+	check_err $? "nexthops outlive the device"
+	wait $pid
+
+	log_test "Device down and deleted"
+}
+
+################################################################################
+# Main
+
+require_command jq
+
+if ! ip link help lisp 2>&1 | grep -q "^Usage: ... lisp"; then
+	echo "SKIP: iproute2 does not know the lisp devices"
+	exit "$ksft_skip"
+fi
+
+if (( LISP_SITES < 8000 || LISP_SITES > 65536 )); then
+	echo "SKIP: LISP_SITES must be between 8000 and 65536"
+	exit "$ksft_skip"
+fi
+
+trap cleanup EXIT
+
+setup_ns probe
+out=$(ip -n "$probe" link add lisp0 type lisp id 1 2>&1)
+if [[ $out == *"Unknown device type"* ]]; then
+	echo "SKIP: the kernel does not have the lisp devices (CONFIG_LISP)"
+	exit "$ksft_skip"
+fi
+cleanup_ns "$probe"
+
+if ! setup; then
+	echo "FAIL: the setup of the test failed"
+	exit "$ksft_fail"
+fi
+
+tests_run
+
+exit "$EXIT_STATUS"

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device
  2026-11-26 21:37 [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Vincent Jardin via B4 Relay
                   ` (4 preceding siblings ...)
  2026-11-26 21:37 ` [PATCH net-next 5/5] selftests: net: add a scale test for LISP Vincent Jardin via B4 Relay
@ 2026-11-27 10:24 ` Matthieu Baerts
  5 siblings, 0 replies; 7+ messages in thread
From: Matthieu Baerts @ 2026-11-27 10:24 UTC (permalink / raw)
  To: Vincent Jardin
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Donald Hunter, Nicolas Dichtel, Simon Horman,
	Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan,
	linux-kernel, netdev, linux-doc, linux-kselftest

Hi Vincent,

Thank you for working on that.

On 26/11/2026 22:37, Vincent Jardin wrote:

(...)

> The lisp link type of iproute2 comes as a separate series, for
> iproute2-next. Tests are skipped without it. Tell me if you want
> iproute2 series too for a simultaneous review.

Do you mind sharing a branch on top of iproute2-next with these patches,
please? (or the patches)

With that, we can build an iproute2 version supporting lisp, and the CI
can validate this series next time, instead of always marking this
series as "Changes Requested" because some tests are marked as 'skip'.

Cheers,
Matt

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-27 10:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 21:37 [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Vincent Jardin via B4 Relay
2026-11-26 21:37 ` [PATCH net-next 1/5] lisp: add LISP (Locator/ID Separation Protocol) Vincent Jardin via B4 Relay
2026-11-26 21:37 ` [PATCH net-next 2/5] netlink: specs: rt-link: add the lisp link type Vincent Jardin via B4 Relay
2026-11-26 21:37 ` [PATCH net-next 3/5] docs: net: document the LISP devices Vincent Jardin via B4 Relay
2026-11-26 21:37 ` [PATCH net-next 4/5] selftests: net: add a test of " Vincent Jardin via B4 Relay
2026-11-26 21:37 ` [PATCH net-next 5/5] selftests: net: add a scale test for LISP Vincent Jardin via B4 Relay
2026-11-27 10:24 ` [PATCH net-next 0/5] lisp: add a LISP (RFC 9300) tunnel device Matthieu Baerts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox