net: ILA resolver and generic resolver backend
Subsystems (5)
cover net: ILA resolver and generic resolver backend
This patch sets implements an ILA host side resolver. This uses LWT to implement the hook to a userspace resolver and tracks pending unresolved address using the backend net resolver.
This patch set contains:
- An new library function to allocate an array of spinlocks for use with locking hash buckets.
- Make hash function in rhashtable directly callable.
- A generic resolver backend infrastructure. This primary does two
things: track unsesolved addresses and implement a timeout for resolution not happening. These mechanisms provides rate limiting control over resolution requests (for instance in ILA it use used to rate limit requests to userspace to resolve addresses).
- The ILA resolver. This is implements to path from the kernel ILA implementation to a userspace daemon that an identifier address needs to be resolved.
Tom Herbert (6):
spinlock: Add library function to allocate spinlock buckets array
rhashtable: Call library function alloc_bucket_locks
ila: Call library function alloc_bucket_locks
rhashtable: abstract out function to get hash
net: Generic resolver backend
ila: Resolver mechanism
include/linux/rhashtable.h | 28 +++-- include/linux/spinlock.h | 6 + include/net/resolver.h | 58 +++++++++ include/uapi/linux/lwtunnel.h | 1 + include/uapi/linux/rtnetlink.h | 5 + lib/Makefile | 2 +- lib/bucket_locks.c | 63 ++++++++++ lib/rhashtable.c | 46 +------ net/Kconfig | 4 + net/core/Makefile | 1 + net/core/resolver.c | 267 +++++++++++++++++++++++++++++++++++++++++ net/ipv6/Kconfig | 1 + net/ipv6/ila/Makefile | 2 +- net/ipv6/ila/ila.h | 16 +++ net/ipv6/ila/ila_common.c | 7 ++ net/ipv6/ila/ila_lwt.c | 9 ++ net/ipv6/ila/ila_resolver.c | 192 +++++++++++++++++++++++++++++ net/ipv6/ila/ila_xlat.c | 51 ++------ 18 files changed, 666 insertions(+), 93 deletions(-) create mode 100644 include/net/resolver.h create mode 100644 lib/bucket_locks.c create mode 100644 net/core/resolver.c create mode 100644 net/ipv6/ila/ila_resolver.c
Signature · 1 line
2.8.0.rc2
RFC PATCH 1/6 spinlock: Add library function to allocate spinlock buckets array
Add two new library functions alloc_bucket_spinlocks and free_bucket_spinlocks. These are use to allocate and free an array of spinlocks that are useful as locks for hash buckets. The interface specifies the maximum number of spinlocks in the array as well as a CPU multiplier to derive the number of spinlocks to allocate. The number to allocated is rounded up to a power of two to make the array amenable to hash lookup.
--- include/linux/spinlock.h | 6 +++++ lib/Makefile | 2 +- lib/bucket_locks.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 lib/bucket_locks.c
include/linux/spinlock.h +6 -0
@@ -416,4 +416,10 @@ extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);#define atomic_dec_and_lock (atomic, lock) \ __cond_lock(lock, _atomic_dec_and_lock(atomic, lock)) +int alloc_bucket_spinlocks (spinlock_t **locks,unsigned int *lock_mask, +unsigned int max_size,unsigned int cpu_mult, +gfp_t gfp); + +void free_bucket_spinlocks (spinlock_t *locks); +#endif /* __LINUX_SPINLOCK_H */
lib/Makefile +1 -1
@@ -37,7 +37,7 @@ obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ bsearch.o find_bit.o llist.o memweight.o kfifo.o \ percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o \ - once.o + once.o bucket_locks.o obj-y += string_helpers.o obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o obj-y += hexdump.o
lib/bucket_locks.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.8.0.rc2
Re: [PATCH RFC 1/6] spinlock: Add library function to allocate spinlock buckets array
Quoted 9 lines · Tom Herbert
Add two new library functions
alloc_bucket_spinlocksandfree_bucket_spinlocks. These are use to allocate and free an array of spinlocks that are useful as locks for hash buckets. The interface specifies the maximum number of spinlocks in the array as well as a CPU multiplier to derive the number of spinlocks to allocate. The number to allocated is rounded up to a power of two to make the array amenable to hash lookup.Signed-off-by Tom Herbert <[email protected]>
I like this idea!!
Reviewed by Greg Rose <[email protected]>
Quoted 104 lines
--- include/linux/spinlock.h | 6 +++++ lib/Makefile | 2 +- lib/bucket_locks.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 lib/bucket_locks.cinclude/linux/spinlock.h +6
-0@@ -416,4 +416,10 @@ extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);#define atomic_dec_and_lock (atomic, lock) \ __cond_lock(lock, _atomic_dec_and_lock(atomic, lock)) +int alloc_bucket_spinlocks (spinlock_t **locks,unsigned int *lock_mask, +unsigned int max_size,unsigned int cpu_mult, +gfp_t gfp); + +void free_bucket_spinlocks (spinlock_t *locks); +#endif /* __LINUX_SPINLOCK_H */ lib/Makefile +1
-1@@ -37,7 +37,7 @@ obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ bsearch.o find_bit.o llist.o memweight.o kfifo.o \ percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o \ - once.o + once.o bucket_locks.o obj-y += string_helpers.o obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o obj-y += hexdump.olib/bucket_locks.c new file +63
-0@@ -0,0 +1,63 @@ +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/mm.h> +#include <linux/export.h> + +/* Allocate an array of spinlocks to be accessed by a hash. Two arguments +* indicate the number of elements to allocate in the array. max_size +* gives the maximum number of elements to allocate. cpu_mult gives +* the number of locks per CPU to allocate. The size is rounded up +* to a power of 2 to be suitable as a hash table. +*/ +int alloc_bucket_spinlocks (spinlock_t **locks,unsigned int *locks_mask, +unsigned int max_size,unsigned int cpu_mult, +gfp_t gfp) +{ +unsigned int i, size; +#if defined(CONFIG_PROVE_LOCKING ) +unsigned int nr_pcpus =2 ; +#else +unsigned int nr_pcpus =num_possible_cpus (); +#endif +spinlock_t *tlocks =NULL ; + +if (cpu_mult) { + nr_pcpus = min_t(unsigned int, nr_pcpus, 64UL); + size = min_t(unsigned int, nr_pcpus * cpu_mult, max_size); + }else { + size = max_size; + } + size =roundup_pow_of_two (size); + +if (!size) +return -EINVAL ; + +if (sizeof (spinlock_t) !=0 ) { +#ifdef CONFIG_NUMA +if (size *sizeof (spinlock_t) >PAGE_SIZE && + gfp ==GFP_KERNEL ) + tlocks =vmalloc (size *sizeof (spinlock_t)); +#endif +if (gfp !=GFP_KERNEL ) + gfp |= __GFP_NOWARN | __GFP_NORETRY; + +if (!tlocks) + tlocks =kmalloc_array (size,sizeof (spinlock_t), gfp); +if (!tlocks) +return -ENOMEM ; +for (i =0 ; i < size; i++) +spin_lock_init (&tlocks[i]); + } + *locks = tlocks; + *locks_mask = size -1 ; + +return 0 ; +} +EXPORT_SYMBOL (alloc_bucket_spinlocks); + +void free_bucket_spinlocks (spinlock_t *locks) +{ +kvfree (locks); +} +EXPORT_SYMBOL (free_bucket_spinlocks);
Re: [PATCH RFC 1/6] spinlock: Add library function to allocate spinlock buckets array
In reply to Tom HerbertQuoted 9 lines · Tom Herbert
Add two new library functions
alloc_bucket_spinlocksandfree_bucket_spinlocks. These are use to allocate and free an array of spinlocks that are useful as locks for hash buckets. The interface specifies the maximum number of spinlocks in the array as well as a CPU multiplier to derive the number of spinlocks to allocate. The number to allocated is rounded up to a power of two to make the array amenable to hash lookup.Signed-off-by Tom Herbert <[email protected]>
RFC PATCH 2/6 rhashtable: Call library function alloc_bucket_locks
In reply to Tom HerbertTo allocate the array of bucket locks for the hash table we now call library function alloc_bucket_spinlocks. This function is based on the old alloc_bucket_locks in rhashtable and should produce the same effect.
--- lib/rhashtable.c | 46 ++++------------------------------------------ 1 file changed, 4 insertions(+), 42 deletions(-)
lib/rhashtable.c +4 -42
@@ -59,50 +59,10 @@ EXPORT_SYMBOL_GPL(lockdep_rht_bucket_is_held);#define ASSERT_RHT_MUTEX (HT )#endif - -static int alloc_bucket_locks (struct rhashtable *ht,struct bucket_table *tbl, -gfp_t gfp) -{ -unsigned int i, size; -#if defined(CONFIG_PROVE_LOCKING ) -unsigned int nr_pcpus =2 ; -#else -unsigned int nr_pcpus =num_possible_cpus (); -#endif - - nr_pcpus = min_t(unsigned int, nr_pcpus, 64UL); - size =roundup_pow_of_two (nr_pcpus * ht->p.locks_mul); - -/* Never allocate more than 0.5 locks per bucket */ - size = min_t(unsigned int, size, tbl->size >> 1); - -if (sizeof (spinlock_t) !=0 ) { - tbl->locks =NULL ; -#ifdef CONFIG_NUMA -if (size *sizeof (spinlock_t) >PAGE_SIZE && - gfp ==GFP_KERNEL ) - tbl->locks =vmalloc (size *sizeof (spinlock_t)); -#endif -if (gfp !=GFP_KERNEL ) - gfp |= __GFP_NOWARN | __GFP_NORETRY; - -if (!tbl->locks) - tbl->locks =kmalloc_array (size,sizeof (spinlock_t), - gfp); -if (!tbl->locks) -return -ENOMEM ; -for (i =0 ; i < size; i++) -spin_lock_init (&tbl->locks[i]); - } - tbl->locks_mask = size -1 ; - -return 0 ; -} -static void bucket_table_free (const struct bucket_table *tbl) {if (tbl) -kvfree (tbl->locks); +free_bucket_spinlocks (tbl->locks);kvfree (tbl); }
@@ -131,7 +91,9 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, tbl->size = nbuckets; -if (alloc_bucket_locks (ht, tbl, gfp) <0 ) { +/* Never allocate more than 0.5 locks per bucket */ +if (alloc_bucket_spinlocks (&tbl->locks, &tbl->locks_mask, + tbl->size >>1 , ht->p.locks_mul, gfp)) {bucket_table_free (tbl);return NULL ; }
Signature · 1 line
2.8.0.rc2
Re: [PATCH RFC 2/6] rhashtable: Call library function alloc_bucket_locks
Quoted 6 lines · Tom Herbert
To allocate the array of bucket locks for the hash table we now call library function
alloc_bucket_spinlocks. This function is based on the oldalloc_bucket_locksin rhashtable and should produce the same effect.Signed-off-by Tom Herbert <[email protected]>
Herbert Xu
maintainerRe: [PATCH RFC 2/6] rhashtable: Call library function alloc_bucket_locks
In reply to Tom HerbertQuoted 6 lines · Tom Herbert
To allocate the array of bucket locks for the hash table we now call library function
alloc_bucket_spinlocks. This function is based on the oldalloc_bucket_locksin rhashtable and should produce the same effect.Signed-off-by Tom Herbert <[email protected]>
This conflicts with the work I'm doing to fix the resize ENOMEM issue. I'll be making the hashtable as well as the spinlock table nested, in which case you must not directly dereference it as an array.
If you're just trying to share the spinlocks for another purpose, what we can do is provide a helper function to return the right lock for a given key/object.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
RFC PATCH 3/6 ila: Call library function alloc_bucket_locks
In reply to Tom HerbertTo allocate the array of bucket locks for the hash table we now call library function alloc_bucket_spinlocks.
--- net/ipv6/ila/ila_xlat.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-)
net/ipv6/ila/ila_xlat.c +5 -31
@@ -30,34 +30,6 @@ struct ila_net {bool hooks_registered; }; -#define LOCKS_PER_CPU 10 - -static int alloc_ila_locks (struct ila_net *ilan) -{ -unsigned int i, size; -unsigned int nr_pcpus =num_possible_cpus (); - - nr_pcpus = min_t(unsigned int, nr_pcpus, 32UL); - size =roundup_pow_of_two (nr_pcpus *LOCKS_PER_CPU ); - -if (sizeof (spinlock_t) !=0 ) { -#ifdef CONFIG_NUMA -if (size *sizeof (spinlock_t) >PAGE_SIZE ) - ilan->locks =vmalloc (size *sizeof (spinlock_t)); - else -#endif - ilan->locks =kmalloc_array (size,sizeof (spinlock_t), -GFP_KERNEL ); -if (!ilan->locks) -return -ENOMEM ; -for (i =0 ; i < size; i++) -spin_lock_init (&ilan->locks[i]); - } - ilan->locks_mask = size -1 ; - -return 0 ; -} -static u32 hashrnd__read_mostly ; static __always_inline void __ila_hash_secret_init(void) {
@@ -561,14 +533,16 @@ static const struct genl_ops ila_nl_ops[] = { }, }; -#define ILA_HASH_TABLE_SIZE 1024 +#define LOCKS_PER_CPU 10 +#define MAX_LOCKS 1024static __net_init int ila_init_net (struct net *net) {int err;struct ila_net *ilan =net_generic (net, ila_net_id); - err =alloc_ila_locks (ilan); + err =alloc_bucket_spinlocks (&ilan->locks, &ilan->locks_mask, +MAX_LOCKS ,LOCKS_PER_CPU ,GFP_KERNEL );if (err)return err;
@@ -583,7 +557,7 @@ static __net_exit void ila_exit_net(struct net *net)rhashtable_free_and_destroy (&ilan->rhash_table, ila_free_cb,NULL ); -kvfree (ilan->locks); +free_bucket_spinlocks (ilan->locks);if (ilan->hooks_registered) nf_unregister_net_hooks(net, ila_nf_hook_ops,
Signature · 1 line
2.8.0.rc2
RFC PATCH 4/6 rhashtable: abstract out function to get hash
In reply to Tom HerbertSplit out most of rht_key_hashfn which is calculating the hash into its own function. This way the hash function can be called separately to get the hash value.
--- include/linux/rhashtable.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-)
include/linux/rhashtable.h +18 -10
@@ -208,34 +208,42 @@ static inline unsigned int rht_bucket_index(const struct bucket_table *tbl,return (hash >>RHT_HASH_RESERVED_SPACE ) & (tbl->size -1 ); } -static inline unsigned int rht_key_hashfn ( -struct rhashtable *ht,const struct bucket_table *tbl, -const void *key,const struct rhashtable_params params) +static inline unsigned int rht_key_get_hash (struct rhashtable *ht, +const void *key,const struct rhashtable_params params, +unsigned int hash_rnd) {unsigned int hash;/* params must be equal to ht->p if it isn't constant. */ if (!__builtin_constant_p (params.key_len)) - hash = ht->p.hashfn (key, ht->key_len, tbl->hash_rnd); + hash = ht->p.hashfn (key, ht->key_len, hash_rnd);else if (params.key_len) {unsigned int key_len = params.key_len;if (params.hashfn) - hash = params.hashfn (key, key_len, tbl->hash_rnd); + hash = params.hashfn (key, key_len, hash_rnd);else if (key_len & (sizeof (u32) -1 )) - hash =jhash (key, key_len, tbl->hash_rnd); + hash =jhash (key, key_len, hash_rnd);else - hash =jhash2 (key, key_len /sizeof (u32), - tbl->hash_rnd); + hash =jhash2 (key, key_len /sizeof (u32), hash_rnd); }else {unsigned int key_len = ht->p.key_len;if (params.hashfn) - hash = params.hashfn (key, key_len, tbl->hash_rnd); + hash = params.hashfn (key, key_len, hash_rnd);else - hash =jhash (key, key_len, tbl->hash_rnd); + hash =jhash (key, key_len, hash_rnd); } +return hash; +} + +static inline unsigned int rht_key_hashfn ( +struct rhashtable *ht,const struct bucket_table *tbl, +const void *key,const struct rhashtable_params params) +{ +unsigned int hash =rht_key_get_hash (ht, key, params, tbl->hash_rnd); +return rht_bucket_index (tbl, hash); }
Signature · 1 line
2.8.0.rc2
Re: [PATCH RFC 4/6] rhashtable: abstract out function to get hash
Quoted 5 lines · Tom Herbert
Split out most of
rht_key_hashfnwhich is calculating the hash into its own function. This way the hash function can be called separately to get the hash value.Signed-off-by Tom Herbert <[email protected]>
RFC PATCH 5/6 net: Generic resolver backend
In reply to Tom HerbertThis patch implements the backend of a resolver, specifically it provides a means to track unresolved addresses and to time them out.
The resolver is mostly a frontend to an rhashtable where the key of the table is whatever address type or object is tracked. A resolver instance is created by net_rslv_create. A resolver is destroyed by net_rslv_destroy.
There are two functions that are used to manipulate entries in the
table: net_rslv_lookup_and_create and net_rslv_resolved.
net_rslv_lookup_and_create is called with an unresolved address as the argument. It returns a structure of type net_rslv_ent. When called a lookup is performed to see if an entry for the address is already in the table, if it is the entry is return and the false is returned in the new bool pointer argument to indicate that the entry was preexisting. If an entry is not found, one is create and true is returned on the new pointer argument. It is expected that when an entry is new the address resolution protocol is initiated (for instance a RTM_ADDR_RESOLVE message may be sent to a userspace daemon as we will do in ILA). If net_rslv_lookup_and_create returns NULL then presumably the hash table has reached the limit of number of outstanding unresolved addresses, the caller should take appropriate actions to avoid spamming the resolution protocol.
net_rslv_resolved is called when resolution is completely (e.g. ILA locator mapping was instantiated for a locator. The entry is removed for the hash table.
An argument to net_rslv_create indicates a time for the pending resolution in milliseconds. If the timer fires before resolution then the entry is removed from the table. Subsequently, another attempt to resolve the same address will result in a new entry in the table.
net_rslv_lookup_and_create allocates an net_rslv_ent struct and includes allocating related user data. This is the object[] field in the structure. The key (unresolved address) is always the first field in the the object. Following that the caller may add it's own private field data. The key length and size of the user object (including the key) are specific in net_rslv_create.
There are three callback functions that can be set as arugments in net_rslv_create:
- cmp_fn: Compare function for hash table. Arguments are the key and an object in the table. If this is NULL then the default memcmp of rhashtable is used.
- init_fn: Initial a new net_rslv_ent structure. This allows initialization of the user portion of the structure (the object[]).
- destroy_fn: Called right before a net_rslv_ent is freed. This allows cleanup of user data associated with the entry.
Note that the resolver backend only tracks unresolved addresses, it is up to the caller to perform the mechanism of resolution. This includes the possible of queuing packets awaiting resolution; this can be accomplished for instance by maintaining an skbuff queue in the net_rslv_ent user object[] data.
DOS mitigation is done by limiting the number of entries in the resolver table (the max_size which argument of net_rslv_create) and setting a timeout. IF the timeout is set then the maximum rate of new resolution requests is max_table_size / timeout. For instance, with a maximum size of 1000 entries and a timeout of 100 msecs the maximum rate of resolutions requests is 10000/s.
--- include/net/resolver.h | 58 +++++++++++ net/Kconfig | 4 + net/core/Makefile | 1 + net/core/resolver.c | 267 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 330 insertions(+) create mode 100644 include/net/resolver.h create mode 100644 net/core/resolver.c
include/net/resolver.h new file +58 -0
@@ -0,0 +1,58 @@ +#ifndef __NET_RESOLVER_H +#define __NET_RESOLVER_H + +#include <linux/rhashtable.h> + +struct net_rslv ; +struct net_rslv_ent ; + +typedef int (*net_rslv_cmpfn )(struct net_rslv *nrslv,const void *key, +const void *object); +typedef void (*net_rslv_initfn )(struct net_rslv *nrslv,void *object); +typedef void (*net_rslv_destroyfn )(struct net_rslv_ent *nrent); + +struct net_rslv { +struct rhashtable rhash_table; +struct rhashtable_params params; +net_rslv_cmpfn rslv_cmp; +net_rslv_initfn rslv_init; +net_rslv_destroyfn rslv_destroy; +size_t obj_size; +spinlock_t *locks; +unsigned int locks_mask; +unsigned int hash_rnd; +long timeout; +}; + +struct net_rslv_ent { +struct rcu_head rcu; +union { +/* Fields set when entry is in hash table */ +struct { +struct rhash_head node; +struct delayed_work timeout_work; +struct net_rslv *nrslv; + }; + +/* Fields set when rcu freeing structure */ +struct { +net_rslv_destroyfn destroy; + }; + }; +char object[]; +}; + +struct net_rslv *net_rslv_create (size_t size,size_t key_len, +size_t max_size,long timeout, +net_rslv_cmpfn cmp_fn, +net_rslv_initfn init_fn, +net_rslv_destroyfn destroy_fn); + +struct net_rslv_ent *net_rslv_lookup_and_create (struct net_rslv *nrslv, +void *key,bool *created); + +void net_rslv_resolved (struct net_rslv *nrslv,void *key); + +void net_rslv_destroy (struct net_rslv *nrslv); + +#endif
net/Kconfig +4 -0
@@ -255,6 +255,10 @@ config XPS depends on SMP default y +config NET_EXT_RESOLVER + bool + default n + config HWBM bool
net/core/Makefile +1 -0
@@ -27,3 +27,4 @@ obj-$(CONFIG_LWTUNNEL) += lwtunnel.o obj-$(CONFIG_DST_CACHE) += dst_cache.o obj-$(CONFIG_HWBM) += hwbm.o obj-$(CONFIG_NET_DEVLINK) += devlink.o +obj-$(CONFIG_NET_EXT_RESOLVER) += resolver.o
net/core/resolver.c new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
2.8.0.rc2
Thomas Graf
maintainerRe: [PATCH RFC 5/6] net: Generic resolver backend
Quoted 12 lines · Tom Herbert
net/core/resolver.c new file +6
-0@@ -0,0 +1,267 @@ +#include <linux/errno.h> +#include <linux/ip.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/netlink.h> +#include <linux/skbuff.h>
net/core/resolver.c line 16
Quoted 10 lines
net/core/resolver.c new file +10
-0+#include <linux/socket.h> +#include <linux/types.h> +#include <linux/vmalloc.h> +#include <net/checksum.h> +#include <net/ip.h> +#include <net/ip6_fib.h> +#include <net/lwtunnel.h> +#include <net/protocol.h> +#include <net/resolver.h> +#include <uapi/linux/ila.h>
This include list could be stripped down a bit. ila, lwt, fib, ...
net/core/resolver.c line 110
Quoted 3 lines
net/core/resolver.c new file +3
-0+ +static struct net_rslv_ent *net_rslv_new_ent (struct net_rslv *nrslv, +void *key)
Comment above that net_rslv_get_lock() must be held?
net/core/resolver.c line 115
Quoted 5 lines
net/core/resolver.c new file +5
-0+{ +struct net_rslv_ent *nrent; +int err; + + nrent =kzalloc (sizeof (*nrent) + nrslv->obj_size,GFP_KERNEL );
GFP_ATOMIC since you typically hold net_rslv_get_lock() spinlock?
Quoted 9 lines
net/core/resolver.c new file +9
-0+if (!nrent) +return ERR_PTR (-EAGAIN ); + +/* Key is always at beginning of object data */ +memcpy (nrent->object, key, nrslv->params.key_len); + +/* Initialize user data */ +if (nrslv->rslv_init) + nrslv->rslv_init (nrslv, nrent);
net/core/resolver.c line 134
Quoted 10 lines
net/core/resolver.c new file +10
-0+ +/* Put in hash table */ + err =rhashtable_lookup_insert_fast (&nrslv->rhash_table, + &nrent->node, nrslv->params); +if (err) +return ERR_PTR (err); + +if (nrslv->timeout) { +/* Schedule timeout for resolver */ +INIT_DELAYED_WORK (&nrent->timeout_work, net_rslv_delayed_work);
Should this be done before inserting into rhashtable?
net/core/resolver.c line 138
Quoted 4 lines
net/core/resolver.c new file +4
-0+schedule_delayed_work (&nrent->timeout_work, nrslv->timeout); + } + + nrent->nrslv = nrslv;
Same here. net_rslv_cancel_all_delayed_work() walking the rhashtable could see ->nrslv as NULL.
Re: [PATCH RFC 5/6] net: Generic resolver backend
Quoted 53 lines · Thomas Graf
Quoted 12 lines · Tom Herbert
net/core/resolver.c new file +6
-0@@ -0,0 +1,267 @@ +#include <linux/errno.h> +#include <linux/ip.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/netlink.h> +#include <linux/skbuff.h> net/core/resolver.c line 16
Quoted 10 lines
net/core/resolver.c new file +10
-0+#include <linux/socket.h> +#include <linux/types.h> +#include <linux/vmalloc.h> +#include <net/checksum.h> +#include <net/ip.h> +#include <net/ip6_fib.h> +#include <net/lwtunnel.h> +#include <net/protocol.h> +#include <net/resolver.h> +#include <uapi/linux/ila.h> This include list could be stripped down a bit. ila, lwt, fib, ...
net/core/resolver.c line 110
Quoted 3 lines
net/core/resolver.c new file +3
-0+ +static struct net_rslv_ent *net_rslv_new_ent (struct net_rslv *nrslv, +void *key)Comment above that
net_rslv_get_lock()must be held?net/core/resolver.c line 115
Quoted 5 lines
net/core/resolver.c new file +5
-0+{ +struct net_rslv_ent *nrent; +int err; + + nrent =kzalloc (sizeof (*nrent) + nrslv->obj_size,GFP_KERNEL );
GFP_ATOMICsince you typically holdnet_rslv_get_lock()spinlock?Quoted 13 lines
net/core/resolver.c new file +13
-0+if (!nrent) +return ERR_PTR (-EAGAIN ); + +/* Key is always at beginning of object data */ +memcpy (nrent->object, key, nrslv->params.key_len); + +/* Initialize user data */ +if (nrslv->rslv_init) + nrslv->rslv_init (nrslv, nrent); + +/* Put in hash table */ + err =rhashtable_lookup_insert_fast (&nrslv->rhash_table, + &nrent->node, nrslv->params);
Quoted 9 lines
net/core/resolver.c line 134
Quoted 6 lines
net/core/resolver.c new file +6
-0+if (err) +return ERR_PTR (err); + +if (nrslv->timeout) { +/* Schedule timeout for resolver */ +INIT_DELAYED_WORK (&nrent->timeout_work, net_rslv_delayed_work);Should this be done before inserting into rhashtable?
Adding to the table and setting delayed work are done under a lock so I think it should be okay. I'll add a comment to the function that the lock is held.
Quoted 7 lines
net/core/resolver.c line 138
Quoted 4 lines
net/core/resolver.c new file +4
-0+schedule_delayed_work (&nrent->timeout_work, nrslv->timeout); + } + + nrent->nrslv = nrslv;Same here.
net_rslv_cancel_all_delayed_work()walking the rhashtable could see ->nrslv as NULL.
I'll move it up, but net_rslv_cancel_all_delayed_work is only called when we're destroying the table so it would be a bug in the higher layer if it is both destroying the table and adding entries at the same time.
Thanks,
Tom
Quoted 1 line
RFC PATCH 6/6 ila: Resolver mechanism
In reply to Tom HerbertImplement an ILA resolver. This uses LWT to implement the hook to a userspace resolver and tracks pending unresolved address using the backend net resolver.
The idea is that the kernel sets an ILA resolver route to the SIR prefix, something like:
ip route add 3333::/64 encap ila-resolve \
via 2401:db00:20:911a::27:0 dev eth0When a packet hits the route the address is looked up in a resolver table. If the entry is created (no entry with the address already exists) then an rtnl message is generated with group RTNLGRP_ILA_NOTIFY and type RTM_ADDR_RESOLVE. A userspace daemon can listen for such messages and perform an ILA resolution protocol to determine the ILA mapping. If the mapping is resolved then a /128 ila encap router is set so that host can perform ILA translation and send directly to destination.
--- include/uapi/linux/lwtunnel.h | 1 + include/uapi/linux/rtnetlink.h | 5 ++ net/ipv6/Kconfig | 1 + net/ipv6/ila/Makefile | 2 +- net/ipv6/ila/ila.h | 16 ++++ net/ipv6/ila/ila_common.c | 7 ++ net/ipv6/ila/ila_lwt.c | 9 ++ net/ipv6/ila/ila_resolver.c | 192 +++++++++++++++++++++++++++++++++++++++++ net/ipv6/ila/ila_xlat.c | 15 ++-- 9 files changed, 239 insertions(+), 9 deletions(-) create mode 100644 net/ipv6/ila/ila_resolver.c
include/uapi/linux/lwtunnel.h +1 -0
@@ -9,6 +9,7 @@ enum lwtunnel_encap_types {LWTUNNEL_ENCAP_IP ,LWTUNNEL_ENCAP_ILA ,LWTUNNEL_ENCAP_IP6 , +LWTUNNEL_ENCAP_ILA_NOTIFY , __LWTUNNEL_ENCAP_MAX, };
include/uapi/linux/rtnetlink.h +5 -0
@@ -144,6 +144,9 @@ enum { RTM_GETSTATS = 94,#define RTM_GETSTATS RTM_GETSTATS + RTM_ADDR_RESOLVE = 95, +#define RTM_ADDR_RESOLVE RTM_ADDR_RESOLVE + __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
@@ -656,6 +659,8 @@ enum rtnetlink_groups {#define RTNLGRP_MPLS_ROUTE RTNLGRP_MPLS_ROUTE RTNLGRP_NSID,#define RTNLGRP_NSID RTNLGRP_NSID + RTNLGRP_ILA_NOTIFY, +#define RTNLGRP_ILA_NOTIFY RTNLGRP_ILA_NOTIFY __RTNLGRP_MAX };#define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
net/ipv6/Kconfig +1 -0
@@ -97,6 +97,7 @@ config IPV6_ILA tristate "IPv6: Identifier Locator Addressing (ILA)" depends on NETFILTER select LWTUNNEL + select NET_EXT_RESOLVER ---help--- Support for IPv6 Identifier Locator Addressing (ILA).
net/ipv6/ila/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_IPV6_ILA) += ila.o -ila-objs := ila_common.o ila_lwt.o ila_xlat.o +ila-objs := ila_common.o ila_lwt.o ila_xlat.o ila_resolver.o
net/ipv6/ila/ila.h +16 -0
@@ -15,6 +15,7 @@#include <linux/ip.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/rhashtable.h> #include <linux/socket.h> #include <linux/skbuff.h> #include <linux/types.h>
@@ -23,6 +24,16 @@#include <net/protocol.h> #include <uapi/linux/ila.h> +extern unsigned int ila_net_id; + +struct ila_net { +struct rhashtable rhash_table; +spinlock_t *locks;/* Bucket locks for entry manipulation */ +unsigned int locks_mask; +bool hooks_registered; +struct net_rslv *nrslv; +}; + struct ila_locator { union { __u8 v8[8];
@@ -114,9 +125,14 @@ void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p,void ila_init_saved_csum (struct ila_params *p); +void ila_rslv_resolved (struct ila_net *ilan,struct ila_addr *iaddr);int ila_lwt_init (void );void ila_lwt_fini (void );int ila_xlat_init (void );void ila_xlat_fini (void ); +int ila_rslv_init (void ); +void ila_rslv_fini (void ); +int ila_init_resolver_net (struct ila_net *ilan); +void ila_exit_resolver_net (struct ila_net *ilan);#endif /* __ILA_H */
net/ipv6/ila/ila_common.c +7 -0
@@ -157,7 +157,13 @@ static int __init ila_init(void)if (ret) goto fail_xlat; + ret =ila_rslv_init (); +if (ret) + goto fail_rslv; +return 0 ; +fail_rslv: +ila_xlat_fini (); fail_xlat:ila_lwt_fini (); fail_lwt:
@@ -168,6 +174,7 @@ static void __exit ila_fini(void) {ila_xlat_fini ();ila_lwt_fini (); +ila_rslv_fini (); }module_init (ila_init);
net/ipv6/ila/ila_lwt.c +9 -0
@@ -9,6 +9,7 @@#include <net/ip.h> #include <net/ip6_fib.h> #include <net/lwtunnel.h> +#include <net/netns/generic.h> #include <net/protocol.h> #include <uapi/linux/ila.h> #include "ila.h"
@@ -122,6 +123,14 @@ static int ila_build_state(struct net_device *dev, struct nlattr *nla, *ts = newts; +if (cfg6->fc_dst_len >=sizeof (struct ila_addr )) { +struct net *net =dev_net (dev); +struct ila_net *ilan =net_generic (net, ila_net_id); + +/* Cancel any pending resolution on this address */ +ila_rslv_resolved (ilan, iaddr); + } +return 0 ; }
net/ipv6/ila/ila_resolver.c new file +192 -0
192 lines not on this page · raw message
net/ipv6/ila/ila_xlat.c +7 -8
@@ -21,14 +21,7 @@ struct ila_map {struct rcu_head rcu; }; -static unsigned int ila_net_id; - -struct ila_net { -struct rhashtable rhash_table; -spinlock_t *locks;/* Bucket locks for entry manipulation */ -unsigned int locks_mask; -bool hooks_registered; -}; +unsigned int ila_net_id;static u32 hashrnd__read_mostly ; static __always_inline void __ila_hash_secret_init(void)
@@ -546,6 +539,10 @@ static __net_init int ila_init_net(struct net *net)if (err)return err; +/* Resolver net is create on demand when LWT ILA resolver route +* is made. +*/ +rhashtable_init (&ilan->rhash_table, &rht_params);return 0 ;
@@ -557,6 +554,8 @@ static __net_exit void ila_exit_net(struct net *net)rhashtable_free_and_destroy (&ilan->rhash_table, ila_free_cb,NULL ); +ila_exit_resolver_net (ilan); +free_bucket_spinlocks (ilan->locks);if (ilan->hooks_registered)
Signature · 1 line
2.8.0.rc2