net: ILA notification mechanism and fixes
Subsystems (4)
v4 cover net: ILA notification mechanism and fixes
This patch set adds support to get netlink notifications for ILA routes when a route is used. This is done to support ILA forwarding cache address resolution as well as ILA router redirect mechanisms.
This patch set contains:
- The ILA route notification mechanism
- Routing messages are used over netlink to indicate resolution requests
- Add net to ila build_state
- Add flush command to ila_xlat
- Fix use of rhashtable for latest fixes
v4:
- Remove front end cache per davem feedback
- Eliminate separate LWT type just use ILA LWT already in place
v3:
- Removed rhashtable changes to their own patch set
- Restructure ILA code to be more amenable to changes
- Remove extra call back functions in resolution interface
Changes from initial RFC:
- Added net argument to LWT build_state
- Made resolve timeout an attribute of the LWT encap route
- Changed ILA notifications to be regular routing messages of event RTM_ADDR_RESOLVE, family RTNL_FAMILY_ILA, and group RTNLGRP_ILA_NOTIFY
Tom Herbert (6):
lwt: Add net to build_state argument
ila: Fix use of rhashtable walk in ila_xlat.c
ila: Call library function alloc_bucket_locks
ila: create main ila source file
ila: Flush netlink command to clear xlat table
ila: Route notify
include/net/lwtunnel.h | 6 +- include/uapi/linux/ila.h | 3 + include/uapi/linux/rtnetlink.h | 8 +- net/core/lwt_bpf.c | 2 +- net/core/lwtunnel.c | 4 +- net/ipv4/fib_semantics.c | 13 +- net/ipv4/ip_tunnel_core.c | 4 +- net/ipv6/ila/Makefile | 2 +- net/ipv6/ila/ila.h | 27 +++- net/ipv6/ila/ila_common.c | 30 ----- net/ipv6/ila/ila_lwt.c | 270 ++++++++++++++++++++++++++------------ net/ipv6/ila/ila_main.c | 121 +++++++++++++++++ net/ipv6/ila/ila_xlat.c | 290 ++++++++++++++++++++--------------------- net/ipv6/route.c | 2 +- net/ipv6/seg6_iptunnel.c | 2 +- net/ipv6/seg6_local.c | 5 +- net/mpls/mpls_iptunnel.c | 2 +- 17 files changed, 508 insertions(+), 283 deletions(-) create mode 100644 net/ipv6/ila/ila_main.c
Signature · 1 line
2.11.0
PATCH v4 1/6 lwt: Add net to build_state argument
Users of LWT need to know net if they want to have per net operations in LWT.
--- include/net/lwtunnel.h | 6 +++--- net/core/lwt_bpf.c | 2 +- net/core/lwtunnel.c | 4 ++-- net/ipv4/fib_semantics.c | 13 ++++++++----- net/ipv4/ip_tunnel_core.c | 4 ++-- net/ipv6/ila/ila_lwt.c | 2 +- net/ipv6/route.c | 2 +- net/ipv6/seg6_iptunnel.c | 2 +- net/ipv6/seg6_local.c | 5 +++-- net/mpls/mpls_iptunnel.c | 2 +- 10 files changed, 23 insertions(+), 19 deletions(-)
include/net/lwtunnel.h +3 -3
@@ -34,7 +34,7 @@ struct lwtunnel_state { };struct lwtunnel_encap_ops { -int (*build_state)(struct nlattr *encap, +int (*build_state)(struct net *net,struct nlattr *encap,unsigned int family,const void *cfg,struct lwtunnel_state **ts,struct netlink_ext_ack *extack);
@@ -113,7 +113,7 @@ int lwtunnel_valid_encap_type(u16 encap_type, struct netlink_ext_ack *extack);int lwtunnel_valid_encap_type_attr (struct nlattr *attr,int len,struct netlink_ext_ack *extack); -int lwtunnel_build_state(u16 encap_type, +int lwtunnel_build_state(struct net *net, u16 encap_type, struct nlattr *encap, unsigned int family, const void *cfg, struct lwtunnel_state **lws,
@@ -192,7 +192,7 @@ static inline int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len,return 0 ; } -static inline int lwtunnel_build_state(u16 encap_type, +static inline int lwtunnel_build_state(struct net *net, u16 encap_type, struct nlattr *encap, unsigned int family, const void *cfg, struct lwtunnel_state **lws,
net/core/lwt_bpf.c +1 -1
@@ -238,7 +238,7 @@ static const struct nla_policy bpf_nl_policy[LWT_BPF_MAX + 1] = { [LWT_BPF_XMIT_HEADROOM] = { .type = NLA_U32 }, }; -static int bpf_build_state (struct nlattr *nla, +static int bpf_build_state (struct net *net,struct nlattr *nla,unsigned int family,const void *cfg,struct lwtunnel_state **ts,struct netlink_ext_ack *extack)
net/core/lwtunnel.c +2 -2
@@ -103,7 +103,7 @@ int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *ops, }EXPORT_SYMBOL_GPL (lwtunnel_encap_del_ops); -int lwtunnel_build_state (u16 encap_type, +int lwtunnel_build_state (struct net *net,u16 encap_type,struct nlattr *encap,unsigned int family,const void *cfg,struct lwtunnel_state **lws,struct netlink_ext_ack *extack)
@@ -124,7 +124,7 @@ int lwtunnel_build_state(u16 encap_type, ops =rcu_dereference (lwtun_encaps[encap_type]);if (likely (ops && ops->build_state &&try_module_get (ops->owner))) { found = true; - ret = ops->build_state (encap, family, cfg, lws, extack); + ret = ops->build_state (net, encap, family, cfg, lws, extack);if (ret)module_put (ops->owner); }
net/ipv4/fib_semantics.c +8 -5
@@ -523,6 +523,7 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,if (nla) {struct lwtunnel_state *lwtstate;struct nlattr *nla_entype; +struct net *net = cfg->fc_nlinfo.nl_net; nla_entype =nla_find (attrs, attrlen,RTA_ENCAP_TYPE );
@@ -533,7 +534,7 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, goto err_inval; } - ret =lwtunnel_build_state (nla_get_u16 ( + ret =lwtunnel_build_state (net,nla_get_u16 ( nla_entype), nla,AF_INET , cfg, &lwtstate, extack);
@@ -607,7 +608,7 @@ static void fib_rebalance(struct fib_info *fi)#endif /* CONFIG_IP_ROUTE_MULTIPATH */ -static int fib_encap_match(u16 encap_type, +static int fib_encap_match(struct net *net, u16 encap_type, struct nlattr *encap, const struct fib_nh *nh, const struct fib_config *cfg,
@@ -619,7 +620,7 @@ static int fib_encap_match(u16 encap_type,if (encap_type ==LWTUNNEL_ENCAP_NONE )return 0 ; - ret =lwtunnel_build_state (encap_type, encap,AF_INET , + ret =lwtunnel_build_state (net, encap_type, encap,AF_INET , cfg, &lwtstate, extack);if (!ret) { result =lwtunnel_cmp_encap (lwtstate, nh->nh_lwtstate);
@@ -632,6 +633,7 @@ static int fib_encap_match(u16 encap_type,int fib_nh_match (struct fib_config *cfg,struct fib_info *fi,struct netlink_ext_ack *extack) { +struct net *net = cfg->fc_nlinfo.nl_net;#ifdef CONFIG_IP_ROUTE_MULTIPATH struct rtnexthop *rtnh;int remaining;
@@ -642,7 +644,8 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,if (cfg->fc_oif || cfg->fc_gw) {if (cfg->fc_encap) { -if (fib_encap_match (cfg->fc_encap_type, cfg->fc_encap, +if (fib_encap_match (net, cfg->fc_encap_type, + cfg->fc_encap, fi->fib_nh, cfg, extack))return 1 ; }
@@ -1180,7 +1183,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg, "LWT encap type not specified"); goto err_inval; } - err =lwtunnel_build_state (cfg->fc_encap_type, + err =lwtunnel_build_state (net, cfg->fc_encap_type, cfg->fc_encap,AF_INET , cfg, &lwtstate, extack);if (err)
net/ipv4/ip_tunnel_core.c +2 -2
@@ -228,7 +228,7 @@ static const struct nla_policy ip_tun_policy[LWTUNNEL_IP_MAX + 1] = { [LWTUNNEL_IP_FLAGS] = { .type = NLA_U16 }, }; -static int ip_tun_build_state (struct nlattr *attr, +static int ip_tun_build_state (struct net *net,struct nlattr *attr,unsigned int family,const void *cfg,struct lwtunnel_state **ts,struct netlink_ext_ack *extack)
@@ -327,7 +327,7 @@ static const struct nla_policy ip6_tun_policy[LWTUNNEL_IP6_MAX + 1] = { [LWTUNNEL_IP6_FLAGS] = { .type = NLA_U16 }, }; -static int ip6_tun_build_state (struct nlattr *attr, +static int ip6_tun_build_state (struct net *net,struct nlattr *attr,unsigned int family,const void *cfg,struct lwtunnel_state **ts,struct netlink_ext_ack *extack)
net/ipv6/ila/ila_lwt.c +1 -1
@@ -125,7 +125,7 @@ static const struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = { [ILA_ATTR_HOOK_TYPE] = { .type = NLA_U8, }, }; -static int ila_build_state (struct nlattr *nla, +static int ila_build_state (struct net *net,struct nlattr *nla,unsigned int family,const void *cfg,struct lwtunnel_state **ts,struct netlink_ext_ack *extack)
net/ipv6/route.c +1 -1
@@ -2565,7 +2565,7 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,if (cfg->fc_encap) {struct lwtunnel_state *lwtstate; - err =lwtunnel_build_state (cfg->fc_encap_type, + err =lwtunnel_build_state (net, cfg->fc_encap_type, cfg->fc_encap,AF_INET6 , cfg, &lwtstate, extack);if (err)
net/ipv6/seg6_iptunnel.c +1 -1
@@ -359,7 +359,7 @@ static int seg6_output(struct net *net, struct sock *sk, struct sk_buff *skb)return err; } -static int seg6_build_state (struct nlattr *nla, +static int seg6_build_state (struct net *net,struct nlattr *nla,unsigned int family,const void *cfg,struct lwtunnel_state **ts,struct netlink_ext_ack *extack)
net/ipv6/seg6_local.c +3 -2
@@ -779,8 +779,9 @@ static int parse_nla_action(struct nlattr **attrs, struct seg6_local_lwt *slwt)return 0 ; } -static int seg6_local_build_state (struct nlattr *nla,unsigned int family, -const void *cfg,struct lwtunnel_state **ts, +static int seg6_local_build_state (struct net *net,struct nlattr *nla, +unsigned int family,const void *cfg, +struct lwtunnel_state **ts,struct netlink_ext_ack *extack) {struct nlattr *tb[SEG6_LOCAL_MAX +1 ];
net/mpls/mpls_iptunnel.c +1 -1
@@ -157,7 +157,7 @@ static int mpls_xmit(struct sk_buff *skb)return -EINVAL ; } -static int mpls_build_state (struct nlattr *nla, +static int mpls_build_state (struct net *net,struct nlattr *nla,unsigned int family,const void *cfg,struct lwtunnel_state **ts,struct netlink_ext_ack *extack)
Signature · 1 line
2.11.0
Re: [PATCH v4 net-next 1/6] lwt: Add net to build_state argument
Quoted 4 lines · Tom Herbert
Users of LWT need to know net if they want to have per net operations in LWT.
Signed-off-by Tom Herbert <[email protected]>
PATCH v4 2/6 ila: Fix use of rhashtable walk in ila_xlat.c
In reply to Tom HerbertPerform better EAGAIN handling, handle case where ila_dump_info fails and we missed objects in the dump, and add a skip index to skip over ila entires in a list on a rhashtable node that have already been visited (by a previous call to ila_nl_dump).
--- net/ipv6/ila/ila_xlat.c | 70 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-)
net/ipv6/ila/ila_xlat.c +54 -16
@@ -474,24 +474,31 @@ static int ila_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info)struct ila_dump_iter {struct rhashtable_iter rhiter; +int skip; };static int ila_nl_dump_start (struct netlink_callback *cb) {struct net *net =sock_net (cb->skb->sk);struct ila_net *ilan =net_generic (net, ila_net_id); -struct ila_dump_iter *iter = (struct ila_dump_iter *)cb->args[0 ]; +struct ila_dump_iter *iter; +int ret; -if (!iter) { - iter =kmalloc (sizeof (*iter),GFP_KERNEL ); -if (!iter) -return -ENOMEM ; + iter =kmalloc (sizeof (*iter),GFP_KERNEL ); +if (!iter) +return -ENOMEM ; - cb->args[0 ] = (long )iter; + ret =rhashtable_walk_init (&ilan->rhash_table, &iter->rhiter, +GFP_KERNEL ); +if (ret) { +kfree (iter); +return ret; } -return rhashtable_walk_init (&ilan->rhash_table, &iter->rhiter, -GFP_KERNEL ); + iter->skip =0 ; + cb->args[0 ] = (long )iter; + +return ret; }static int ila_nl_dump_done (struct netlink_callback *cb)
@@ -509,20 +516,45 @@ static int ila_nl_dump(struct sk_buff *skb, struct netlink_callback *cb) {struct ila_dump_iter *iter = (struct ila_dump_iter *)cb->args[0 ];struct rhashtable_iter *rhiter = &iter->rhiter; +int skip = iter->skip;struct ila_map *ila;int ret;rhashtable_walk_start (rhiter); -for (;;) { - ila =rhashtable_walk_next (rhiter); +/* Get first entry */ + ila =rhashtable_walk_peek (rhiter); + +if (ila && !IS_ERR (ila) && skip) { +/* Skip over visited entries */ + +while (ila && skip) { +/* Skip over any ila entries in this list that we +* have already dumped. +*/ + ila =rcu_access_pointer (ila->next); + skip--; + } + } + skip =0 ; + +for (;;) {if (IS_ERR (ila)) { -if (PTR_ERR (ila) == -EAGAIN ) -continue ; ret =PTR_ERR (ila); - goto done; +if (ret == -EAGAIN ) { +/* Table has changed and iter has reset. Return +* -EAGAIN to the application even if we have +* written data to the skb. The application +* needs to deal with this. +*/ + + goto out_ret; + }else { +break ; + } }else if (!ila) { + ret =0 ;break ; }
@@ -531,15 +563,21 @@ static int ila_nl_dump(struct sk_buff *skb, struct netlink_callback *cb) cb->nlh->nlmsg_seq,NLM_F_MULTI , skb, ILA_CMD_GET);if (ret) - goto done; + goto out; + skip++; ila =rcu_access_pointer (ila->next); } + + skip =0 ; + ila =rhashtable_walk_next (rhiter); } - ret = skb->len; +out: + iter->skip = skip; + ret = (skb->len ? : ret); -done: +out_ret:rhashtable_walk_stop (rhiter);return ret; }
Signature · 1 line
2.11.0
PATCH v4 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 | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-)
net/ipv6/ila/ila_xlat.c +5 -17
@@ -31,26 +31,14 @@ struct ila_net {bool hooks_registered; }; +#define MAX_LOCKS 1024#define LOCKS_PER_CPU 10static 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 ) { - ilan->locks =kvmalloc (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 ; +return alloc_bucket_spinlocks (&ilan->xlat.locks, &ilan->xlat.locks_mask, +MAX_LOCKS ,LOCKS_PER_CPU , +GFP_KERNEL ); }static u32 hashrnd__read_mostly ;
@@ -639,7 +627,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->xlat.locks);if (ilan->hooks_registered) nf_unregister_net_hooks(net, ila_nf_hook_ops,
Signature · 1 line
2.11.0
kbuild test robot
build botRe: [PATCH v4 net-next 3/6] ila: Call library function alloc_bucket_locks
Thank you for the patch! Yet something to improve:
Hi Tom,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Tom-Herbert/net-ILA-notification-mechanism-and-fixes/20171217-041013
config: x86_64-randconfig-x019-201751 (attached as .config)
compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 Note: the linux-review/Tom-Herbert/net-ILA-notification-mechanism-and-fixes/20171217-041013 HEAD bdefe11e33bb3662a60476ea17663189974227a0 builds fine.
It only hurts bisectibility.
All error/warnings (new ones prefixed by >>):
net/ipv6/ila/ila_xlat.c: In function 'alloc_ila_locks':
>> net/ipv6/ila/ila_xlat.c:39:37: error: 'struct ila_net' has no member named 'xlat'
return alloc_bucket_spinlocks(&ilan->xlat.locks, &ilan->xlat.locks_mask,
^~
net/ipv6/ila/ila_xlat.c:39:56: error: 'struct ila_net' has no member named 'xlat'
return alloc_bucket_spinlocks(&ilan->xlat.locks, &ilan->xlat.locks_mask,
^~
net/ipv6/ila/ila_xlat.c: In function 'ila_exit_net':
net/ipv6/ila/ila_xlat.c:630:28: error: 'struct ila_net' has no member named 'xlat'
free_bucket_spinlocks(ilan->xlat.locks);
^~
net/ipv6/ila/ila_xlat.c: In function 'alloc_ila_locks':
>> net/ipv6/ila/ila_xlat.c:42:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^vim +39 net/ipv6/ila/ila_xlat.c
36
37 static int alloc_ila_locks(struct ila_net *ilan)
38 {
> 39 return alloc_bucket_spinlocks(&ilan->xlat.locks, &ilan->xlat.locks_mask,
40 MAX_LOCKS, LOCKS_PER_CPU,
41 GFP_KERNEL);
> 42 }
43 ---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v4 4/6 ila: create main ila source file
In reply to Tom HerbertCreate a main ila file that contains the module initialization functions as well as netlink definitions. Previously these were defined in ila_xlat and ila_common. This approach allows better extensibility.
--- net/ipv6/ila/Makefile | 2 +- net/ipv6/ila/ila.h | 26 ++++++++- net/ipv6/ila/ila_common.c | 30 ---------- net/ipv6/ila/ila_main.c | 115 ++++++++++++++++++++++++++++++++++++++ net/ipv6/ila/ila_xlat.c | 138 +++++++++------------------------------------- 5 files changed, 166 insertions(+), 145 deletions(-) create mode 100644 net/ipv6/ila/ila_main.c
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_main.o ila_common.o ila_lwt.o ila_xlat.o
net/ipv6/ila/ila.h +24 -2
@@ -19,6 +19,7 @@#include <linux/skbuff.h> #include <linux/types.h> #include <net/checksum.h> +#include <net/genetlink.h> #include <net/ip.h> #include <net/protocol.h> #include <uapi/linux/ila.h>
@@ -104,9 +105,30 @@ void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p,void ila_init_saved_csum (struct ila_params *p); +struct ila_net { +struct { +struct rhashtable rhash_table; +spinlock_t *locks;/* Bucket locks for entry manipulation */ +unsigned int locks_mask; +bool hooks_registered; + } xlat; +}; +int ila_lwt_init (void );void ila_lwt_fini (void ); -int ila_xlat_init (void ); -void ila_xlat_fini (void ); + +int ila_xlat_init_net (struct net *net); +void ila_xlat_exit_net (struct net *net); + +int ila_xlat_nl_cmd_add_mapping (struct sk_buff *skb,struct genl_info *info); +int ila_xlat_nl_cmd_del_mapping (struct sk_buff *skb,struct genl_info *info); +int ila_xlat_nl_cmd_get_mapping (struct sk_buff *skb,struct genl_info *info); +int ila_xlat_nl_dump_start (struct netlink_callback *cb); +int ila_xlat_nl_dump_done (struct netlink_callback *cb); +int ila_xlat_nl_dump (struct sk_buff *skb,struct netlink_callback *cb); + +extern unsigned int ila_net_id; + +extern struct genl_family ila_nl_family;#endif /* __ILA_H */
net/ipv6/ila/ila_common.c +0 -30
@@ -154,33 +154,3 @@ void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p, iaddr->loc = p->locator; } -static int __init ila_init (void ) -{ -int ret; - - ret =ila_lwt_init (); - -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 (); -} - -module_init (ila_init); -module_exit (ila_fini); -MODULE_AUTHOR ("Tom Herbert <[email protected]>" ); -MODULE_LICENSE ("GPL" );
net/ipv6/ila/ila_main.c new file +115 -0
115 lines not on this page · raw message
net/ipv6/ila/ila_xlat.c +26 -112
287 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v4 5/6 ila: Flush netlink command to clear xlat table
In reply to Tom HerbertAdd ILA_CMD_FLUSH netlink command to clear the ILA translation table.
--- include/uapi/linux/ila.h | 1 + net/ipv6/ila/ila.h | 1 + net/ipv6/ila/ila_main.c | 6 +++++ net/ipv6/ila/ila_xlat.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 68 insertions(+), 2 deletions(-)
include/uapi/linux/ila.h +1 -0
@@ -30,6 +30,7 @@ enum {ILA_CMD_ADD ,ILA_CMD_DEL ,ILA_CMD_GET , +ILA_CMD_FLUSH , __ILA_CMD_MAX, };
net/ipv6/ila/ila.h +1 -0
@@ -123,6 +123,7 @@ void ila_xlat_exit_net(struct net *net);int ila_xlat_nl_cmd_add_mapping (struct sk_buff *skb,struct genl_info *info);int ila_xlat_nl_cmd_del_mapping (struct sk_buff *skb,struct genl_info *info);int ila_xlat_nl_cmd_get_mapping (struct sk_buff *skb,struct genl_info *info); +int ila_xlat_nl_cmd_flush (struct sk_buff *skb,struct genl_info *info);int ila_xlat_nl_dump_start (struct netlink_callback *cb);int ila_xlat_nl_dump_done (struct netlink_callback *cb);int ila_xlat_nl_dump (struct sk_buff *skb,struct netlink_callback *cb);
net/ipv6/ila/ila_main.c +6 -0
@@ -27,6 +27,12 @@ static const struct genl_ops ila_nl_ops[] = { .flags = GENL_ADMIN_PERM, }, { + .cmd = ILA_CMD_FLUSH, + .doit = ila_xlat_nl_cmd_flush, + .policy = ila_nl_policy, + .flags = GENL_ADMIN_PERM, + }, + { .cmd = ILA_CMD_GET, .doit = ila_xlat_nl_cmd_get_mapping, .start = ila_xlat_nl_dump_start,
net/ipv6/ila/ila_xlat.c +60 -2
81 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v4 6/6 ila: Route notify
In reply to Tom HerbertImplement RTM notifications for ILA routers. This adds support to ILA LWT to send a netlink RTM message when a router is uses.
THe ILA notify mechanism can be used in two contexts:
- On an ILA forwarding cache a route prefix can be configured to do an ILA notification. This method is used when address resolution needs to be done on an address.
- One an ILA router an ILA host route entry may include a noitification. The purpose of this is to get a notification to a userspace daemon to send and ILA redirect
--- include/uapi/linux/ila.h | 2 + include/uapi/linux/rtnetlink.h | 8 +- net/ipv6/ila/ila_lwt.c | 268 ++++++++++++++++++++++++++++------------- 3 files changed, 193 insertions(+), 85 deletions(-)
include/uapi/linux/ila.h +2 -0
@@ -19,6 +19,8 @@ enum {ILA_ATTR_CSUM_MODE ,/* u8 */ ILA_ATTR_IDENT_TYPE ,/* u8 */ ILA_ATTR_HOOK_TYPE ,/* u8 */ +ILA_ATTR_NOTIFY_DST ,/* flag */ +ILA_ATTR_NOTIFY_SRC ,/* flag */ __ILA_ATTR_MAX, };
include/uapi/linux/rtnetlink.h +7 -1
@@ -13,7 +13,8 @@*/ #define RTNL_FAMILY_IPMR 128#define RTNL_FAMILY_IP6MR 129 -#define RTNL_FAMILY_MAX 129 +#define RTNL_FAMILY_ILA 130 +#define RTNL_FAMILY_MAX 130/**** * Routing/neighbour discovery messages.
@@ -150,6 +151,9 @@ enum { RTM_NEWCACHEREPORT = 96,#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT + RTM_ADDR_RESOLVE = 98, +#define RTM_ADDR_RESOLVE RTM_ADDR_RESOLVE + __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
@@ -676,6 +680,8 @@ enum rtnetlink_groups {#define RTNLGRP_IPV4_MROUTE_R RTNLGRP_IPV4_MROUTE_R RTNLGRP_IPV6_MROUTE_R,#define RTNLGRP_IPV6_MROUTE_R RTNLGRP_IPV6_MROUTE_R + RTNLGRP_ILA_NOTIFY, +#define RTNLGRP_ILA_NOTIFY RTNLGRP_ILA_NOTIFY __RTNLGRP_MAX };#define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
net/ipv6/ila/ila_lwt.c +184 -84
377 lines not on this page · raw message
Signature · 1 line
2.11.0
kbuild test robot
build bot[RFC PATCH] ila: ila_notify() can be static
Fixes: bdefe11e33bb ("ila: Route notify")
--- ila_lwt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ila/ila_lwt.c +1 -1
@@ -51,7 +51,7 @@ static size_t ila_rslv_msgsize(void)return len; } -void ila_notify (struct net *net,struct sk_buff *skb,struct ila_lwt *lwt) +static void ila_notify (struct net *net,struct sk_buff *skb,struct ila_lwt *lwt) {struct ipv6hdr *ip6h =ipv6_hdr (skb);int flags =NLM_F_MULTI ;
kbuild test robot
build botRe: [PATCH v4 net-next 6/6] ila: Route notify
In reply to Tom HerbertThank you for the patch! Perhaps something to improve:
Hi Tom,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Tom-Herbert/net-ILA-notification-mechanism-and-fixes/20171217-041013
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__sparse warnings: (new ones prefixed by >>)
Please review and possibly fold the followup patch.
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH v4 net-next 6/6] ila: Route notify
In reply to Tom HerbertQuoted 37 lines · Tom Herbert
Implement RTM notifications for ILA routers. This adds support to ILA LWT to send a netlink RTM message when a router is uses.
THe ILA notify mechanism can be used in two contexts:
- On an ILA forwarding cache a route prefix can be configured to do an ILA notification. This method is used when address resolution needs to be done on an address.
- One an ILA router an ILA host route entry may include a noitification. The purpose of this is to get a notification to a userspace daemon to send and ILA redirectSigned-off-by Tom Herbert <[email protected]>--- include/uapi/linux/ila.h | 2 + include/uapi/linux/rtnetlink.h | 8 +- net/ipv6/ila/ila_lwt.c | 268 ++++++++++++++++++++++++++++------------- 3 files changed, 193 insertions(+), 85 deletions(-)include/uapi/linux/ila.h +2
-0@@ -19,6 +19,8 @@ enum {ILA_ATTR_CSUM_MODE ,/* u8 */ ILA_ATTR_IDENT_TYPE ,/* u8 */ ILA_ATTR_HOOK_TYPE ,/* u8 */ +ILA_ATTR_NOTIFY_DST ,/* flag */ +ILA_ATTR_NOTIFY_SRC ,/* flag */ __ILA_ATTR_MAX, };include/uapi/linux/rtnetlink.h +0
-0
include/uapi/linux/rtnetlink.h line 16
Quoted 5 lines
include/uapi/linux/rtnetlink.h +1
-1@@ -13,7 +13,8 @@*/ #define RTNL_FAMILY_IPMR 128#define RTNL_FAMILY_IP6MR 129 -#define RTNL_FAMILY_MAX 129 +#define RTNL_FAMILY_ILA 130
I don't see this being used, unless I missed it.
include/uapi/linux/rtnetlink.h enum { · line 155
Quoted 10 lines
include/uapi/linux/rtnetlink.h +3
-0+#define RTNL_FAMILY_MAX 130/**** * Routing/neighbour discovery messages. @@ -150,6 +151,9 @@ enum { RTM_NEWCACHEREPORT = 96,#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT + RTM_ADDR_RESOLVE = 98, +#define RTM_ADDR_RESOLVE RTM_ADDR_RESOLVE
Its nice that you are trying to add a generic resolver notify format..., looks good...a few minor comments below for consistency:
your patch adds address resolve notifications with:
- generic notification msg type RTM_ADDR_RESOLVE with route msg format
- On the ILA specific RTNLGRP_ILA_NOTIFY multicast group
Other way to possibly format this for "generic" rtnl netlink resolver is:
- notification msg type RTM_NEWROUTE with route msg format (This is for consistency: route msg format is always used with RTM_*ROUTE msg types)
- route entry msg type RTNL_FAMILY_ILA (ie struct rtmsg-> rtm_family to RTNL_FAMILY_ILA)
- generic address resolution netlink multicast group RTNLGRP_ADDR_RESOLVE_NOTIFY
OR keep everything "specific" to ILA using the ILA genl channel msg
format and family
Besides that, since you are using the route msg format, you could potentially s/ADDR_RESOLVE/ROUTE_RESOLVE/g everywhere above.
Quoted 406 lines
include/uapi/linux/rtnetlink.h +3
-0+ __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };@@ -676,6 +680,8 @@ enum rtnetlink_groups {#define RTNLGRP_IPV4_MROUTE_R RTNLGRP_IPV4_MROUTE_R RTNLGRP_IPV6_MROUTE_R,#define RTNLGRP_IPV6_MROUTE_R RTNLGRP_IPV6_MROUTE_R + RTNLGRP_ILA_NOTIFY, +#define RTNLGRP_ILA_NOTIFY RTNLGRP_ILA_NOTIFY __RTNLGRP_MAX };#define RTNLGRP_MAX (__RTNLGRP_MAX - 1)net/ipv6/ila/ila_lwt.c +184
-85@@ -19,10 +19,15 @@struct ila_lwt {struct ila_params p;struct dst_cache dst_cache; +u8 hook_type;u32 connected :1 ; -u32 lwt_output :1 ; +u32 xlat :1 ; +u32 notify :2 ; }; +#define ILA_NOTIFY_DST 1 +#define ILA_NOTIFY_SRC 2 +static inline struct ila_lwt *ila_lwt_lwtunnel (struct lwtunnel_state *lwt) {@@ -35,6 +40,67 @@ static inline struct ila_params *ila_params_lwtunnel(return &ila_lwt_lwtunnel (lwt)->p; } +static size_t ila_rslv_msgsize (void ) +{ +size_t len = +NLMSG_ALIGN (sizeof (struct rtmsg )) + +nla_total_size (16 )/* RTA_DST */ + +nla_total_size (16 )/* RTA_SRC */ + ; + +return len; +} + +void ila_notify (struct net *net,struct sk_buff *skb,struct ila_lwt *lwt) +{ +struct ipv6hdr *ip6h =ipv6_hdr (skb); +int flags =NLM_F_MULTI ; +struct sk_buff *nlskb; +struct nlmsghdr *nlh; +struct rtmsg *rtm; +int err =0 ; + +/* Send ILA notification to user */ + nlskb =nlmsg_new (ila_rslv_msgsize (),GFP_KERNEL ); +if (!nlskb) +return ; + + nlh =nlmsg_put (nlskb,0 ,0 ,RTM_ADDR_RESOLVE ,sizeof (*rtm), flags); +if (!nlh) { + err = -EMSGSIZE ; + goto errout; + } + + rtm =nlmsg_data (nlh); + rtm->rtm_family =AF_INET6 ; + rtm->rtm_dst_len =128 ; + rtm->rtm_src_len =0 ; + rtm->rtm_tos =0 ; + rtm->rtm_table =RT6_TABLE_UNSPEC ; + rtm->rtm_type =RTN_UNICAST ; + rtm->rtm_scope =RT_SCOPE_UNIVERSE ; + +if (((lwt->notify &ILA_NOTIFY_DST ) && +nla_put_in6_addr (nlskb,RTA_DST , &ip6h->daddr)) || + ((lwt->notify &ILA_NOTIFY_SRC ) && +nla_put_in6_addr (nlskb,RTA_SRC , &ip6h->saddr))) { +nlmsg_cancel (nlskb, nlh); + err = -EMSGSIZE ; + goto errout; + } + +nlmsg_end (nlskb, nlh); + +rtnl_notify (nlskb, net,0 ,RTNLGRP_ILA_NOTIFY ,NULL ,GFP_ATOMIC ); + +return ; + +errout: +kfree_skb (nlskb); +WARN_ON (err == -EMSGSIZE ); +rtnl_set_sk_err (net,RTNLGRP_ILA_NOTIFY , err); +} +static int ila_output (struct net *net,struct sock *sk,struct sk_buff *skb) {struct dst_entry *orig_dst =skb_dst (skb);@@ -46,11 +112,14 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)if (skb->protocol !=htons (ETH_P_IPV6 )) goto drop; -if (ilwt->lwt_output) +if (ilwt->xlat)ila_update_ipv6_locator (skb,ila_params_lwtunnel (orig_dst->lwtstate), true); +if (ilwt->notify) +ila_notify (net, skb, ilwt); +if (rt->rt6i_flags & (RTF_GATEWAY |RTF_CACHE )) {/* Already have a next hop address in route, no need for * dest cache route. @@ -106,11 +175,14 @@ static int ila_input(struct sk_buff *skb)if (skb->protocol !=htons (ETH_P_IPV6 )) goto drop; -if (!ilwt->lwt_output) +if (ilwt->xlat)ila_update_ipv6_locator (skb,ila_params_lwtunnel (dst->lwtstate), false); +if (ilwt->notify) +ila_notify (dev_net (dst->dev), skb, ilwt); +return dst->lwtstate->orig_input (skb); drop:@@ -123,6 +195,8 @@ static const struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = { [ILA_ATTR_CSUM_MODE] = { .type = NLA_U8, }, [ILA_ATTR_IDENT_TYPE] = { .type = NLA_U8, }, [ILA_ATTR_HOOK_TYPE] = { .type = NLA_U8, }, + [ILA_ATTR_NOTIFY_DST] = { .type = NLA_FLAG }, + [ILA_ATTR_NOTIFY_SRC] = { .type = NLA_FLAG }, }; static int ila_build_state(struct net *net, struct nlattr *nla,@@ -130,64 +204,73 @@ static int ila_build_state(struct net *net, struct nlattr *nla,struct lwtunnel_state **ts, struct netlink_ext_ack *extack) { - struct ila_lwt *ilwt; -struct ila_params *p; -struct nlattr *tb[ILA_ATTR_MAX +1 ]; -struct lwtunnel_state *newts; const struct fib6_config *cfg6 = cfg; -struct ila_addr *iaddr; +struct ila_addr *iaddr = (struct ila_addr *)&cfg6->fc_dst;u8 ident_type =ILA_ATYPE_USE_FORMAT ;u8 hook_type =ILA_HOOK_ROUTE_OUTPUT ; +struct nlattr *tb[ILA_ATTR_MAX +1 ];u8 csum_mode =ILA_CSUM_NO_ACTION ; -bool lwt_output = true; +struct lwtunnel_state *newts; +struct ila_lwt *ilwt; +struct ila_params *p;u8 eff_ident_type; -int ret; +int err;if (family !=AF_INET6 )return -EINVAL ; - ret =nla_parse_nested (tb,ILA_ATTR_MAX , nla, ila_nl_policy, extack); -if (ret <0 ) -return ret; + err =nla_parse_nested (tb,ILA_ATTR_MAX , nla, ila_nl_policy, extack); +if (err <0 ) +return err; -if (!tb[ILA_ATTR_LOCATOR ]) -return -EINVAL ; +if (tb[ILA_ATTR_LOCATOR ]) { +/* Doing ILA translation */ - iaddr = (struct ila_addr *)&cfg6->fc_dst; +if (tb[ILA_ATTR_IDENT_TYPE ]) + ident_type =nla_get_u8 (tb[ILA_ATTR_IDENT_TYPE ]); -if (tb[ILA_ATTR_IDENT_TYPE ]) - ident_type =nla_get_u8 (tb[ILA_ATTR_IDENT_TYPE ]); +if (ident_type ==ILA_ATYPE_USE_FORMAT ) { +/* Infer identifier type from type field in formatted +* identifier. +*/ -if (ident_type ==ILA_ATYPE_USE_FORMAT ) { -/* Infer identifier type from type field in formatted -* identifier. -*/ +if (cfg6->fc_dst_len <8 * +sizeof (struct ila_locator ) +3 ) { +/* Need to have full locator and at least type +* field included in destination +*/ +return -EINVAL ; + } + + eff_ident_type = iaddr->ident.type; + }else { + eff_ident_type = ident_type; + } -if (cfg6->fc_dst_len <8 *sizeof (struct ila_locator ) +3 ) { -/* Need to have full locator and at least type field -* included in destination -*/ +switch (eff_ident_type) { +case ILA_ATYPE_IID : +/* Don't allow ILA for IID type */ +return -EINVAL ; +case ILA_ATYPE_LUID : +break ; +case ILA_ATYPE_VIRT_V4 : +case ILA_ATYPE_VIRT_UNI_V6 : +case ILA_ATYPE_VIRT_MULTI_V6 : +case ILA_ATYPE_NONLOCAL_ADDR : +/* These ILA formats are not supported yet. */ +default :return -EINVAL ; } - eff_ident_type = iaddr->ident.type; - }else { - eff_ident_type = ident_type; - } + csum_mode =nla_get_u8 (tb[ILA_ATTR_CSUM_MODE ]); -switch (eff_ident_type) { -case ILA_ATYPE_IID : -/* Don't allow ILA for IID type */ -return -EINVAL ; -case ILA_ATYPE_LUID : -break ; -case ILA_ATYPE_VIRT_V4 : -case ILA_ATYPE_VIRT_UNI_V6 : -case ILA_ATYPE_VIRT_MULTI_V6 : -case ILA_ATYPE_NONLOCAL_ADDR : -/* These ILA formats are not supported yet. */ -default : -return -EINVAL ; +if (csum_mode ==ILA_CSUM_NEUTRAL_MAP && +ila_csum_neutral_set (iaddr->ident)) { +/* Don't allow translation if checksum neutral bit is +* configured and it's set in the SIR address. +*/ +return -EINVAL ; + } }if (tb[ILA_ATTR_HOOK_TYPE ])@@ -195,58 +278,62 @@ static int ila_build_state(struct net *net, struct nlattr *nla,switch (hook_type) {case ILA_HOOK_ROUTE_OUTPUT : - lwt_output = true; -break ;case ILA_HOOK_ROUTE_INPUT : - lwt_output = false;break ;default :return -EINVAL ; } -if (tb[ILA_ATTR_CSUM_MODE ]) - csum_mode =nla_get_u8 (tb[ILA_ATTR_CSUM_MODE ]); - -if (csum_mode ==ILA_CSUM_NEUTRAL_MAP && -ila_csum_neutral_set (iaddr->ident)) { -/* Don't allow translation if checksum neutral bit is -* configured and it's set in the SIR address. -*/ -return -EINVAL ; - } - newts =lwtunnel_state_alloc (sizeof (*ilwt));if (!newts)return -ENOMEM ; ilwt =ila_lwt_lwtunnel (newts); - ret =dst_cache_init (&ilwt->dst_cache,GFP_ATOMIC ); -if (ret) { + + err =dst_cache_init (&ilwt->dst_cache,GFP_ATOMIC ); +if (err) {kfree (newts); -return ret; +return err; } - ilwt->lwt_output = !!lwt_output; + newts->type =LWTUNNEL_ENCAP_ILA ; - p =ila_params_lwtunnel (newts); +switch (hook_type) { +case ILA_HOOK_ROUTE_OUTPUT : + newts->flags |=LWTUNNEL_STATE_OUTPUT_REDIRECT ; +break ; +case ILA_HOOK_ROUTE_INPUT : + newts->flags |=LWTUNNEL_STATE_INPUT_REDIRECT ; +break ; + } - p->csum_mode = csum_mode; - p->ident_type = ident_type; - p->locator.v64 = (__force __be64 )nla_get_u64 (tb[ILA_ATTR_LOCATOR ]); + ilwt->hook_type = hook_type; -/* Precompute checksum difference for translation since we -* know both the old locator and the new one. -*/ - p->locator_match = iaddr->loc; +if (tb[ILA_ATTR_NOTIFY_DST ]) + ilwt->notify |=ILA_NOTIFY_DST ; -ila_init_saved_csum (p); +if (tb[ILA_ATTR_NOTIFY_SRC ]) + ilwt->notify |=ILA_NOTIFY_SRC ; - newts->type =LWTUNNEL_ENCAP_ILA ; - newts->flags |=LWTUNNEL_STATE_OUTPUT_REDIRECT | -LWTUNNEL_STATE_INPUT_REDIRECT ; + p =ila_params_lwtunnel (newts); -if (cfg6->fc_dst_len ==8 *sizeof (struct in6_addr )) - ilwt->connected =1 ; +if (tb[ILA_ATTR_LOCATOR ]) { + ilwt->xlat = true; + p->csum_mode = csum_mode; + p->ident_type = ident_type; + p->locator.v64 = (__force __be64 )nla_get_u64 ( + tb[ILA_ATTR_LOCATOR ]); + +/* Precompute checksum difference for translation since we +* know both the old locator and the new one. +*/ + p->locator_match = iaddr->loc; + +ila_init_saved_csum (p); + +if (cfg6->fc_dst_len ==8 *sizeof (struct in6_addr )) + ilwt->connected =1 ; + } *ts = newts;@@ -264,21 +351,32 @@ static int ila_fill_encap_info(struct sk_buff *skb,struct ila_params *p =ila_params_lwtunnel (lwtstate);struct ila_lwt *ilwt =ila_lwt_lwtunnel (lwtstate); -if (nla_put_u64_64bit (skb,ILA_ATTR_LOCATOR , (__force u64 )p->locator.v64, -ILA_ATTR_PAD )) +if (ilwt->xlat) { +if (nla_put_u64_64bit (skb,ILA_ATTR_LOCATOR , + (__force u64 )p->locator.v64, +ILA_ATTR_PAD )) goto nla_put_failure; -if (nla_put_u8 (skb,ILA_ATTR_CSUM_MODE , (__force u8 )p->csum_mode)) - goto nla_put_failure; +if (nla_put_u8 (skb,ILA_ATTR_CSUM_MODE , + (__force u8 )p->csum_mode)) + goto nla_put_failure; -if (nla_put_u8 (skb,ILA_ATTR_IDENT_TYPE , (__force u8 )p->ident_type)) - goto nla_put_failure; +if (nla_put_u8 (skb,ILA_ATTR_IDENT_TYPE , + (__force u8 )p->ident_type)) + goto nla_put_failure; + } -if (nla_put_u8 (skb,ILA_ATTR_HOOK_TYPE , - ilwt->lwt_output ?ILA_HOOK_ROUTE_OUTPUT : -ILA_HOOK_ROUTE_INPUT )) +if (nla_put_u8 (skb,ILA_ATTR_HOOK_TYPE , ilwt->hook_type)) goto nla_put_failure; +if (ilwt->notify &ILA_NOTIFY_DST ) +if (nla_put_flag (skb,ILA_ATTR_NOTIFY_DST )) + goto nla_put_failure; + +if (ilwt->notify &ILA_NOTIFY_SRC ) +if (nla_put_flag (skb,ILA_ATTR_NOTIFY_SRC )) + goto nla_put_failure; +return 0 ; nla_put_failure:@@ -291,6 +389,8 @@ static int ila_encap_nlsize(struct lwtunnel_state *lwtstate)nla_total_size (sizeof (u8)) +/* ILA_ATTR_CSUM_MODE */ nla_total_size (sizeof (u8)) +/* ILA_ATTR_IDENT_TYPE */ nla_total_size (sizeof (u8)) +/* ILA_ATTR_HOOK_TYPE */ +nla_total_size (0 ) +/* ILA_ATTR_NOTIFY_DST */ +nla_total_size (0 ) +/* ILA_ATTR_NOTIFY_SRC */ 0 ; } --2.11.0