Skip to contentSkip to conversation

ila: Use NF_INET_PRE_ROUTING nfhook

PATCH In review Tom Herbert 3 participants 10 messages Sep 24, 2015 – Sep 29, 2015

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

cover ila: Use NF_INET_PRE_ROUTING nfhook

In the current implementation of ILA, LWT is used to perform translation on both the input and output paths. This is functional, however there is a big performance hit in the receive path. Early demux occurs before the routing lookup (a hit actually obviates the route lookup). Therefore the stack currently performs early demux before translation so that a local connection with ILA addresses is never matched. Note that this issue is not just with ILA, but pretty much any translated or encapsulated packet handled by LWT would miss the opportunity for early demux. Solving the general problem seems non trivial since we would need to move the route lookup before early demx thereby mitigating the value.

This patch set addresses the issue for ILA by adding a fast locator lookup that occurs before early demux. This is done by using a hook at NF_INET_PRE_ROUTING. For the backend we implement an rhashtable that contains identifier to locator to mappings. The table also allows more specific matches that include original locator and interface.

Note that we are not adding functionality to support nfhook for output (e.g. NF_INET_POST_ROUTING). This is because netfilter is done post routing which is prolematic since we need are changing the destination address in ILA. There is an in/out parameter in table entries to allow for the future possibility of performing lookups on the output path.

This patch set:
- Add an rhashtable function to atomically replace and element. This is useful to implement sub-trees from a table entry without needing to use a special anchor structure as the table entry.
- Add a start callback for starting a netlink dump.
- Creates an ila directory under net/ipv6 and moves ila.c to it. ila.c is split into ila_common.c and ila_lwt.c.
- Implement a table to do identifier->locator mapping. This is an rhashtable
- Configuration for the table with netlink
- Set nfhook for IPv6 NF_INET_PRE_ROUTING.do ILA lookup and translation.

Testing:
Running 200 netperf TCP_RR streams

No ILA, baseline
85.36% CPU utilization
1917187 tps
90/157/327 50/90/99% latencies

ILA before fix (LWT on both input and output)
82.86% CPU utilization
1668895 tps (-14% from baseline)
106/180/336 50/90/99% latencies

ILA after fix (NF hook for input)
82.69% CPU utilization
1865113 tps (-2.7% from baseline)
93/162/331 50/90/99% latencies

Tom Herbert (4):
rhashtable: add function to replace an element
netlink: add a start callback for starting a netlink dump
ila: Create net/ipv6/ila directory
ila: Add support for netfilter NF_INET_PRE_ROUTING hook

 include/linux/netlink.h    |   2 +
 include/linux/rhashtable.h |  80 ++++++
 include/net/genetlink.h    |   2 +
 include/uapi/linux/ila.h   |  22 ++
 net/ipv6/Makefile          |   2 +-
 net/ipv6/ila.c             | 229 ----------------
 net/ipv6/ila/Makefile      |   7 +
 net/ipv6/ila/ila.h         |  48 ++++
 net/ipv6/ila/ila_common.c  | 102 +++++++
 net/ipv6/ila/ila_lwt.c     | 149 ++++++++++
 net/ipv6/ila/ila_xlat.c    | 665 +++++++++++++++++++++++++++++++++++++++++++++
 net/netlink/af_netlink.c   |   4 +
 net/netlink/genetlink.c    |  16 ++
 13 files changed, 1098 insertions(+), 230 deletions(-)
 delete mode 100644 net/ipv6/ila.c
 create mode 100644 net/ipv6/ila/Makefile
 create mode 100644 net/ipv6/ila/ila.h
 create mode 100644 net/ipv6/ila/ila_common.c
 create mode 100644 net/ipv6/ila/ila_lwt.c
 create mode 100644 net/ipv6/ila/ila_xlat.c
Signature · 1 line
2.4.6
#2 lore raw

PATCH 2/4 netlink: add a start callback for starting a netlink dump

The start callback allows the caller to set up a context for the dump callbacks. Presumably, the context can then be destroyed in the done callback.

---
 include/linux/netlink.h  |  2 ++
 include/net/genetlink.h  |  2 ++
 net/netlink/af_netlink.c |  4 ++++
 net/netlink/genetlink.c  | 16 ++++++++++++++++
 4 files changed, 24 insertions(+)
include/linux/netlink.h +2 -0
index 639e9b8..0b41959 100644
@@ -131,6 +131,7 @@ netlink_skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
 struct netlink_callback {
 	struct sk_buff		*skb;
 	const struct nlmsghdr	*nlh;
+	int			(*start)(struct netlink_callback *);
 	int			(*dump)(struct sk_buff * skb,
 					struct netlink_callback *cb);
 	int			(*done)(struct netlink_callback *cb);
@@ -153,6 +154,7 @@ struct nlmsghdr *
 __nlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, int type, int len, int flags);
 
 struct netlink_dump_control {
+	int (*start)(struct netlink_callback *);
 	int (*dump)(struct sk_buff *skb, struct netlink_callback *);
 	int (*done)(struct netlink_callback *);
 	void *data;
include/net/genetlink.h +2 -0
index a9af1cc..d76f2da 100644
@@ -114,6 +114,7 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)
  * @flags: flags
  * @policy: attribute validation policy
  * @doit: standard command callback
+ * @start: start callback for dumps
  * @dumpit: callback for dumpers
  * @done: completion callback for dumps
  * @ops_list: operations list
@@ -122,6 +123,7 @@ struct genl_ops {
 	const struct nla_policy	*policy;
 	int		       (*doit)(struct sk_buff *skb,
 				       struct genl_info *info);
+	int		       (*start)(struct netlink_callback *cb);
 	int		       (*dumpit)(struct sk_buff *skb,
 					 struct netlink_callback *cb);
 	int		       (*done)(struct netlink_callback *cb);
net/netlink/af_netlink.c +4 -0
index 7f86d3b..25c6633 100644
@@ -2870,6 +2870,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
 
 	cb = &nlk->cb;
 	memset(cb, 0, sizeof(*cb));
+	cb->start = control->start;
 	cb->dump = control->dump;
 	cb->done = control->done;
 	cb->nlh = nlh;
@@ -2882,6 +2883,9 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
 
 	mutex_unlock(nlk->cb_mutex);
 
+	if (cb->start)
+		cb->start(cb);
+
 	ret = netlink_dump(sk);
 	sock_put(sk);
 
net/netlink/genetlink.c +16 -0
index 2ed5f96..3d111b0 100644
@@ -513,6 +513,20 @@ void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
 }
 EXPORT_SYMBOL(genlmsg_put);
 
+static int genl_lock_start(struct netlink_callback *cb)
+{
+	/* our ops are always const - netlink API doesn't propagate that */
+	const struct genl_ops *ops = cb->data;
+	int rc = 0;
+
+	if (ops->start) {
+		genl_lock();
+		rc = ops->start(cb);
+		genl_unlock();
+	}
+	return rc;
+}
+
 static int genl_lock_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 {
 	/* our ops are always const - netlink API doesn't propagate that */
@@ -577,6 +591,7 @@ static int genl_family_rcv_msg(struct genl_family *family,
 				.module = family->module,
 				/* we have const, but the netlink API doesn't */
 				.data = (void *)ops,
+				.start = genl_lock_start,
 				.dump = genl_lock_dumpit,
 				.done = genl_lock_done,
 			};
@@ -588,6 +603,7 @@ static int genl_family_rcv_msg(struct genl_family *family,
 		} else {
 			struct netlink_dump_control c = {
 				.module = family->module,
+				.start = ops->start,
 				.dump = ops->dumpit,
 				.done = ops->done,
 			};
Signature · 1 line
2.4.6
#1 lore raw

PATCH 1/4 rhashtable: add function to replace an element

In reply to Tom Herbert

Add the rhashtable_replace_fast function. This replaces one object in the table with another atomically. The hashes of the new and old objects must be equal.

---
 include/linux/rhashtable.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
include/linux/rhashtable.h +80 -0
index 843ceca..c7c86cb 100644
@@ -819,4 +819,84 @@ out:
 	return err;
 }
 
+/* Internal function, please use rhashtable_replace_fast() instead */
+static inline int __rhashtable_replace_fast(
+	struct rhashtable *ht, struct bucket_table *tbl,
+	struct rhash_head *obj_old, struct rhash_head *obj_new,
+	const struct rhashtable_params params)
+{
+	struct rhash_head __rcu **pprev;
+	struct rhash_head *he;
+	spinlock_t *lock;
+	unsigned int hash;
+	int err = -ENOENT;
+
+	/* Minimally, the old and new objects must have same hash */
+	hash = rht_head_hashfn(ht, tbl, obj_old, params);
+	if (hash != rht_head_hashfn(ht, tbl, obj_new, params))
+		return -EINVAL;
+
+	lock = rht_bucket_lock(tbl, hash);
+
+	spin_lock_bh(lock);
+
+	pprev = &tbl->buckets[hash];
+	rht_for_each(he, tbl, hash) {
+		if (he != obj_old) {
+			pprev = &he->next;
+			continue;
+		}
+
+		rcu_assign_pointer(obj_new->next, obj_old->next);
+		rcu_assign_pointer(*pprev, obj_new);
+		err = 0;
+		break;
+	}
+
+	spin_unlock_bh(lock);
+
+	return err;
+}
+
+/**
+ * rhashtable_replace_fast - replace an object in hash table
+ * @ht:		hash table
+ * @obj_old:	pointer to hash head inside object being replaced
+ * @obj_new:	pointer to hash head inside object which is new
+ * @params:	hash table parameters
+ *
+ * Replacing an object doesn't affect the number of elements in the hash table
+ * or bucket, so we don't need to worry about shrinking or expanding the
+ * table here.
+ *
+ * Returns zero on success, -ENOENT if the entry could not be found,
+ * -EINVAL if hash is not the same for the old and new objects.
+ */
+static inline int rhashtable_replace_fast(
+	struct rhashtable *ht, struct rhash_head *obj_old,
+	struct rhash_head *obj_new,
+	const struct rhashtable_params params)
+{
+	struct bucket_table *tbl;
+	int err;
+
+	rcu_read_lock();
+
+	tbl = rht_dereference_rcu(ht->tbl, ht);
+
+	/* Because we have already taken (and released) the bucket
+	 * lock in old_tbl, if we find that future_tbl is not yet
+	 * visible then that guarantees the entry to still be in
+	 * the old tbl if it exists.
+	 */
+	while ((err = __rhashtable_replace_fast(ht, tbl, obj_old,
+						obj_new, params)) &&
+	       (tbl = rht_dereference_rcu(tbl->future_tbl, ht)))
+		;
+
+	rcu_read_unlock();
+
+	return err;
+}
+
 #endif /* _LINUX_RHASHTABLE_H */
Signature · 1 line
2.4.6
#3 lore raw

PATCH 3/4 ila: Create net/ipv6/ila directory

In reply to Tom Herbert

Create ila directory in preparation for supporting other hooks in the kernel than LWT for doing ILA. This includes:
- Moving ila.c to ila/ila_lwt.c
- Splitting out some common functions into ila_common.c

---
 net/ipv6/Makefile         |   2 +-
 net/ipv6/ila.c            | 229 ----------------------------------------------
 net/ipv6/ila/Makefile     |   7 ++
 net/ipv6/ila/ila.h        |  46 ++++++++++
 net/ipv6/ila/ila_common.c |  94 +++++++++++++++++++
 net/ipv6/ila/ila_lwt.c    | 149 ++++++++++++++++++++++++++++++
 6 files changed, 297 insertions(+), 230 deletions(-)
 delete mode 100644 net/ipv6/ila.c
 create mode 100644 net/ipv6/ila/Makefile
 create mode 100644 net/ipv6/ila/ila.h
 create mode 100644 net/ipv6/ila/ila_common.c
 create mode 100644 net/ipv6/ila/ila_lwt.c
net/ipv6/Makefile +1 -1
index 2c900c7..2fbd90b 100644
@@ -34,7 +34,7 @@ obj-$(CONFIG_INET6_XFRM_MODE_TUNNEL) += xfrm6_mode_tunnel.o
 obj-$(CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION) += xfrm6_mode_ro.o
 obj-$(CONFIG_INET6_XFRM_MODE_BEET) += xfrm6_mode_beet.o
 obj-$(CONFIG_IPV6_MIP6) += mip6.o
-obj-$(CONFIG_IPV6_ILA) += ila.o
+obj-$(CONFIG_IPV6_ILA) += ila/
 obj-$(CONFIG_NETFILTER)	+= netfilter/
 
 obj-$(CONFIG_IPV6_VTI) += ip6_vti.o
net/ipv6/ila.c deleted +0 -229

229 lines not on this page · raw message

net/ipv6/ila/Makefile new file +7 -0
new file mode 100644
index 0000000..31d136b
@@ -0,0 +1,7 @@
+#
+# Makefile for ILA module
+#
+
+obj-$(CONFIG_IPV6_ILA) += ila.o
+
+ila-objs := ila_common.o ila_lwt.o
net/ipv6/ila/ila.h new file +46 -0

46 lines not on this page · raw message

net/ipv6/ila/ila_common.c new file +94 -0

94 lines not on this page · raw message

net/ipv6/ila/ila_lwt.c new file +149 -0

149 lines not on this page · raw message

Signature · 1 line
2.4.6
#4 lore raw

PATCH 4/4 ila: Add support for netfilter NF_INET_PRE_ROUTING hook

In reply to Tom Herbert

This patch sets up a hook at NF_INET_PRE_ROUTING to perform ILA translation. This is done to have a way to perform translation before early demux which can be a significant performance advantage over LWT which would occur after.

The implementation uses an rhashtable which is used to do the locator lookup. The entries in the rhashtable is configured via new netlink commands.

---
 include/uapi/linux/ila.h  |  22 ++
 net/ipv6/ila/Makefile     |   2 +-
 net/ipv6/ila/ila.h        |   2 +
 net/ipv6/ila/ila_common.c |   8 +
 net/ipv6/ila/ila_xlat.c   | 665 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 698 insertions(+), 1 deletion(-)
 create mode 100644 net/ipv6/ila/ila_xlat.c
include/uapi/linux/ila.h +22 -0
index 7ed9e67..abde7bb 100644
@@ -3,13 +3,35 @@
 #ifndef _UAPI_LINUX_ILA_H
 #define _UAPI_LINUX_ILA_H
 
+/* NETLINK_GENERIC related info */
+#define ILA_GENL_NAME		"ila"
+#define ILA_GENL_VERSION	0x1
+
 enum {
 	ILA_ATTR_UNSPEC,
 	ILA_ATTR_LOCATOR,			/* u64 */
+	ILA_ATTR_IDENTIFIER,			/* u64 */
+	ILA_ATTR_LOCATOR_MATCH,			/* u64 */
+	ILA_ATTR_IFINDEX,			/* s32 */
+	ILA_ATTR_DIR,				/* u32 */
 
 	__ILA_ATTR_MAX,
 };
 
 #define ILA_ATTR_MAX		(__ILA_ATTR_MAX - 1)
 
+enum {
+	ILA_CMD_UNSPEC,
+	ILA_CMD_ADD,
+	ILA_CMD_DEL,
+	ILA_CMD_GET,
+
+	__ILA_CMD_MAX,
+};
+
+#define ILA_CMD_MAX	(__ILA_CMD_MAX - 1)
+
+#define ILA_DIR_IN	(1 << 0)
+#define ILA_DIR_OUT	(1 << 1)
+
 #endif /* _UAPI_LINUX_ILA_H */
net/ipv6/ila/Makefile +1 -1
index 31d136b..4b32e59 100644
@@ -4,4 +4,4 @@
 
 obj-$(CONFIG_IPV6_ILA) += ila.o
 
-ila-objs := ila_common.o ila_lwt.o
+ila-objs := ila_common.o ila_lwt.o ila_xlat.o
net/ipv6/ila/ila.h +2 -0
index b94081f..28542cb 100644
@@ -42,5 +42,7 @@ void update_ipv6_locator(struct sk_buff *skb, struct ila_params *p);
 
 int ila_lwt_init(void);
 void ila_lwt_fini(void);
+int ila_xlat_init(void);
+void ila_xlat_fini(void);
 
 #endif /* __ILA_H */
net/ipv6/ila/ila_common.c +8 -0
index 7cfd54d..5f97559 100644
@@ -79,12 +79,20 @@ static int __init ila_init(void)
 	if (ret)
 		goto fail_lwt;
 
+	ret = ila_xlat_init();
+	if (ret)
+		goto fail_xlat;
+
+	return 0;
+fail_xlat:
+	ila_lwt_fini();
 fail_lwt:
 	return ret;
 }
 
 static void __exit ila_fini(void)
 {
+	ila_xlat_fini();
 	ila_lwt_fini();
 }
 
net/ipv6/ila/ila_xlat.c new file +665 -0

665 lines not on this page · raw message

Signature · 1 line
2.4.6
maintainer
#5 lore raw
In reply to Tom Herbert

From: Tom Herbert <[email protected]>
Date: Thu, 24 Sep 2015 09:30:20 -0700

Quoted 6 lines

This patch set addresses the issue for ILA by adding a fast locator lookup that occurs before early demux. This is done by using a hook at NF_INET_PRE_ROUTING. For the backend we implement an rhashtable that contains identifier to locator to mappings. The table also allows more specific matches that include original locator and interface.

I really don't think we should use netfilter hooks to perform operations setup outside of netfilter's normal configuration mechanisms.

It is not a set of arbitray hooks to take advantage of in another subsystem or facility.

If ILA were instead configured inside of netfilter's normal mechanisms then there would be full transparency about whether ILA transformations are performed before or after the user's other netfilter rules. And the user would have full control over this. As implemented here, they don't.

So sorry, I'm not too keen on this and I bet if netfilter developers reviewed this patch series they'd have similar objections.

#6 lore raw
Quoted 10 lines · David Miller
Quoted 6 lines

This patch set addresses the issue for ILA by adding a fast locator lookup that occurs before early demux. This is done by using a hook at NF_INET_PRE_ROUTING. For the backend we implement an rhashtable that contains identifier to locator to mappings. The table also allows more specific matches that include original locator and interface.

I really don't think we should use netfilter hooks to perform operations setup outside of netfilter's normal configuration mechanisms.

Thanks, thats my thinking as well.

Quoted 8 lines

If ILA were instead configured inside of netfilter's normal mechanisms then there would be full transparency about whether ILA transformations are performed before or after the user's other netfilter rules. And the user would have full control over this. As implemented here, they don't.

So sorry, I'm not too keen on this and I bet if netfilter developers reviewed this patch series they'd have similar objections.

Seems this should/could be implemented similar to RFC6296 network prefix translations (see net/ipv6/netfilter/ip6t_NPT.c).

#7 lore raw
Quoted 20 lines · Florian Westphal
Quoted 10 lines · David Miller
Quoted 6 lines

This patch set addresses the issue for ILA by adding a fast locator lookup that occurs before early demux. This is done by using a hook at NF_INET_PRE_ROUTING. For the backend we implement an rhashtable that contains identifier to locator to mappings. The table also allows more specific matches that include original locator and interface.

I really don't think we should use netfilter hooks to perform operations setup outside of netfilter's normal configuration mechanisms.

Thanks, thats my thinking as well.

Quoted 6 lines

If ILA were instead configured inside of netfilter's normal mechanisms then there would be full transparency about whether ILA transformations are performed before or after the user's other netfilter rules. And the user would have full control over this. As implemented here, they don't.

Quoted 5 lines
Quoted 2 lines

So sorry, I'm not too keen on this and I bet if netfilter developers reviewed this patch series they'd have similar objections.

Seems this should/could be implemented similar to RFC6296 network prefix translations (see net/ipv6/netfilter/ip6t_NPT.c).

Hi Florian,

RFC6296 doesn't work because it allows an invalid checksum to be sent on wire relative to the addresses used on the wire. That means we would lose CHECKSUM_UNNECESSARY for ILA which is way too big of a performance hit. This might actually be worse for some devices that are doing NETIF_F_IP_CSUM if they are calculating the checksum based on the addresses in packet instead of the ultimate destination address which seems to be what RFC6296 wants (could result checksum errors). Unfortunately we're going to be seeing this problem more and more as there are more method that rewrite addresses without updating the transport checksum before leaving the host (e.g. segment routing).

For devices doing CHECKSUM_COMPLETE I suspect there are also some issues. In ip6t_npt_map_pfx it seems like if the addresses are being rewritten in the receive path, the skb->csum should be updated accordingly. GRO might consistently fail on bad checksums also...

In any case, I did at one point create some netfilter targets for ILA to do the translation correctly updating the checksum. While this provided the required functionality, I couldn't get sufficient performance. A specialized fixed length lookup table gets most of the performance needed for ILA.

Thanks,
Tom

#8 lore raw
Quoted 4 lines · Tom Herbert

RFC6296 doesn't work because it allows an invalid checksum to be sent on wire relative to the addresses used on the wire. That means we would lose CHECKSUM_UNNECESSARY for ILA which is way too big of a performance hit.

Not following. I did not say you should use NPT instead of ILA.

[..]

Quoted 5 lines

In any case, I did at one point create some netfilter targets for ILA to do the translation correctly updating the checksum. While this provided the required functionality, I couldn't get sufficient performance. A specialized fixed length lookup table gets most of the performance needed for ILA.

I'm not following at all.

Could you explain why you can't just 'relocate' your proposed implementation to netfilter/ipv6?

F.e. I see no reason why you could not use a lookup table in a netfilter target (or nft expression, for that matter) ... ?

Thanks,
Florian

#9 lore raw
Quoted 15 lines · Florian Westphal
Quoted 4 lines · Tom Herbert

RFC6296 doesn't work because it allows an invalid checksum to be sent on wire relative to the addresses used on the wire. That means we would lose CHECKSUM_UNNECESSARY for ILA which is way too big of a performance hit.

Not following. I did not say you should use NPT instead of ILA.

[..]

Quoted 5 lines

In any case, I did at one point create some netfilter targets for ILA to do the translation correctly updating the checksum. While this provided the required functionality, I couldn't get sufficient performance. A specialized fixed length lookup table gets most of the performance needed for ILA.

Quoted 5 lines

I'm not following at all.

Could you explain why you can't just 'relocate' your proposed implementation to netfilter/ipv6?

Florian

I modified DNPT to perform ILA. Performance results are below. What I see is that DNPT offers only a slight improvement over just doing translation at LWT and not getting a hit in early demux. Top function in perf is:

2.49% [kernel] [k] ip6t_do_table

so I think this performance result is mostly the overhead of netfilter and not ILA translation. But in any case, doing a direct specialized lookup like what we do in this patch gets us close to same performance without ILA enabled-- low performance overhead is critical for our ILA use cases.

Tom

No ILA, baseline
85.72% CPU utilization
1861945 tps
93/163/330 50/90/99% latencies

ILA before fix (LWT on both input and output)
83.47 CPU utilization
16583186 tps (-11% from baseline)
107/183/338 50/90/99% latencies

ILA after fix (hook for input)
84.97% CPU utilization
1833948 tps (-1.5% from baseline)
95/164/331 50/90/99% latencies

Modify DNPT to do ILA (ip6tables -t mangle -I PREROUTING -d 2001:0:0:3::/64 -j DNPT --src-pfx 2001:0:0:3::/64 --dst-pfx 3333:0:0:1::/64)
80.94% CPU utilization
1683315 tps (-10% from baseline)
104/179/350 50/90/99% latencies

Quoted 5 lines

F.e. I see no reason why you could not use a lookup table in a netfilter target (or nft expression, for that matter) ... ?

Thanks,
Florian