Skip to contentSkip to conversation

Support for fdb ECMP nexthop groups

RFC PATCH In review Roopa Prabhu 2 participants 12 messages May 4, 2020 – May 5, 2020

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

cover Support for fdb ECMP nexthop groups

From: Roopa Prabhu <[email protected]>

This series introduces ecmp nexthops and nexthop groups for mac fdb entries. In subsequent patches this is used by the vxlan driver fdb entries. The use case is E-VPN multihoming [1,2,3] which requires bridged vxlan traffic to be load balanced to remote switches (vteps) belonging to the same multi-homed ethernet segment (This is analogous to a multi-homed LAG but over vxlan).

Changes include new nexthop flag NHA_FDB for nexthops referenced by fdb entries. These nexthops only have ip. The patches make sure that routes dont reference such nexthops.

example:
$ip nexthop add id 12 via 172.16.1.2 fdb
$ip nexthop add id 13 via 172.16.1.3 fdb
$ip nexthop add id 102 group 12/13 fdb

$bridge fdb add 02:02:00:00:00:13 dev vxlan1000 nhid 101 self

[1] E-VPN https://tools.ietf.org/html/rfc7432
[2] E-VPN VxLAN: https://tools.ietf.org/html/rfc8365
[3] LPC talk with mention of nexthop groups for L2 ecmp
http://vger.kernel.org/lpc_net2018_talks/scaling_bridge_fdb_database_slidesV3.pdf

Roopa Prabhu (5):
nexthop: support for fdb ecmp nexthops
vxlan: ecmp support for mac fdb entries
nexthop: add support for notifiers
vxlan: support for nexthop notifiers
selftests: net: add fdb nexthop tests

 drivers/net/vxlan.c                         | 319 ++++++++++++++++++++++------
 include/net/netns/nexthop.h                 |   1 +
 include/net/nexthop.h                       |  26 +++
 include/uapi/linux/neighbour.h              |   1 +
 include/uapi/linux/nexthop.h                |   1 +
 net/ipv4/nexthop.c                          | 127 +++++++++--
 tools/testing/selftests/net/fib_nexthops.sh |  77 ++++++-
 7 files changed, 464 insertions(+), 88 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

RFC PATCH 1/5 nexthop: support for fdb ecmp nexthops

From: Roopa Prabhu <[email protected]>

This patch introduces ecmp nexthops and nexthop groups for mac fdb entries. In subsequent patches this is used by the vxlan driver fdb entries. The use case is E-VPN multihoming [1,2,3] which requires bridged vxlan traffic to be load balanced to remote switches (vteps) belonging to the same multi-homed ethernet segment (This is analogous to a multi-homed LAG but over vxlan).

Changes include new nexthop flag NHA_FDB for nexthops referenced by fdb entries. These nexthops only have ip. This patch includes appropriate checks to avoid routes referencing such nexthops.

example:
$ip nexthop add id 12 via 172.16.1.2 fdb
$ip nexthop add id 13 via 172.16.1.3 fdb
$ip nexthop add id 102 group 12/13 fdb

$bridge fdb add 02:02:00:00:00:13 dev vxlan1000 nhid 101 self

[1] E-VPN https://tools.ietf.org/html/rfc7432
[2] E-VPN VxLAN: https://tools.ietf.org/html/rfc8365
[3] LPC talk with mention of nexthop groups for L2 ecmp
http://vger.kernel.org/lpc_net2018_talks/scaling_bridge_fdb_database_slidesV3.pdf

---
 include/net/nexthop.h        |  14 ++++++
 include/uapi/linux/nexthop.h |   1 +
 net/ipv4/nexthop.c           | 101 +++++++++++++++++++++++++++++++++----------
 3 files changed, 93 insertions(+), 23 deletions(-)
include/net/nexthop.h +14 -0
index c440ccc..3ad4e97 100644
@@ -26,6 +26,7 @@ struct nh_config {
 	u8		nh_family;
 	u8		nh_protocol;
 	u8		nh_blackhole;
+	u8		nh_fdb;
 	u32		nh_flags;
 
 	int		nh_ifindex;
@@ -52,6 +53,7 @@ struct nh_info {
 
 	u8			family;
 	bool			reject_nh;
+	bool			fdb_nh;
 
 	union {
 		struct fib_nh_common	fib_nhc;
@@ -80,6 +82,7 @@ struct nexthop {
 	struct rb_node		rb_node;    /* entry on netns rbtree */
 	struct list_head	fi_list;    /* v4 entries using nh */
 	struct list_head	f6i_list;   /* v6 entries using nh */
+	struct list_head        fdb_list;   /* fdb entries using this nh */
 	struct list_head	grp_list;   /* nh group entries using this nh */
 	struct net		*net;
 
@@ -88,6 +91,7 @@ struct nexthop {
 	u8			protocol;   /* app managing this nh */
 	u8			nh_flags;
 	bool			is_group;
+	bool			is_fdb_nh;
 
 	refcount_t		refcnt;
 	struct rcu_head		rcu;
@@ -304,4 +308,14 @@ static inline void nexthop_path_fib6_result(struct fib6_result *res, int hash)
 int nexthop_for_each_fib6_nh(struct nexthop *nh,
 			     int (*cb)(struct fib6_nh *nh, void *arg),
 			     void *arg);
+
+static inline struct nh_info *nexthop_path_fdb(struct nexthop *nh,  u32 hash)
+{
+	struct nh_info *nhi;
+
+	nh = nexthop_select_path(nh, hash);
+	nhi = rcu_dereference(nh->nh_info);
+
+	return nhi;
+}
 #endif
include/uapi/linux/nexthop.h +1 -0
index 7b61867..19a234a 100644
@@ -48,6 +48,7 @@ enum {
 	 */
 	NHA_GROUPS,	/* flag; only return nexthop groups in dump */
 	NHA_MASTER,	/* u32;  only return nexthops with given master dev */
+	NHA_FDB,	/* nexthop belongs to a bridge fdb */
 
 	__NHA_MAX,
 };
net/ipv4/nexthop.c +78 -23

238 lines not on this page · raw message

Signature · 1 line
2.1.4
#2 lore raw

Re: [RFC PATCH net-next 1/5] nexthop: support for fdb ecmp nexthops

Quoted 272 lines · Roopa Prabhu

From: Roopa Prabhu <[email protected]>

This patch introduces ecmp nexthops and nexthop groups for mac fdb entries. In subsequent patches this is used by the vxlan driver fdb entries. The use case is E-VPN multihoming [1,2,3] which requires bridged vxlan traffic to be load balanced to remote switches (vteps) belonging to the same multi-homed ethernet segment (This is analogous to a multi-homed LAG but over vxlan).

Changes include new nexthop flag NHA_FDB for nexthops referenced by fdb entries. These nexthops only have ip. This patch includes appropriate checks to avoid routes referencing such nexthops.

example:
$ip nexthop add id 12 via 172.16.1.2 fdb
$ip nexthop add id 13 via 172.16.1.3 fdb
$ip nexthop add id 102 group 12/13 fdb

$bridge fdb add 02:02:00:00:00:13 dev vxlan1000 nhid 101 self

[1] E-VPN https://tools.ietf.org/html/rfc7432
[2] E-VPN VxLAN: https://tools.ietf.org/html/rfc8365
[3] LPC talk with mention of nexthop groups for L2 ecmp
http://vger.kernel.org/lpc_net2018_talks/scaling_bridge_fdb_database_slidesV3.pdf

---
 include/net/nexthop.h        |  14 ++++++
 include/uapi/linux/nexthop.h |   1 +
 net/ipv4/nexthop.c           | 101 +++++++++++++++++++++++++++++++++----------
 3 files changed, 93 insertions(+), 23 deletions(-)
include/net/nexthop.h +14 -0
index c440ccc..3ad4e97 100644
@@ -26,6 +26,7 @@ struct nh_config {
        u8              nh_family;
        u8              nh_protocol;
        u8              nh_blackhole;
+       u8              nh_fdb;
        u32             nh_flags;
 
        int             nh_ifindex;
@@ -52,6 +53,7 @@ struct nh_info {
 
        u8                      family;
        bool                    reject_nh;
+       bool                    fdb_nh;
 
        union {
                struct fib_nh_common    fib_nhc;
@@ -80,6 +82,7 @@ struct nexthop {
        struct rb_node          rb_node;    /* entry on netns rbtree */
        struct list_head        fi_list;    /* v4 entries using nh */
        struct list_head        f6i_list;   /* v6 entries using nh */
+       struct list_head        fdb_list;   /* fdb entries using this nh */
        struct list_head        grp_list;   /* nh group entries using this nh */
        struct net              *net;
 
@@ -88,6 +91,7 @@ struct nexthop {
        u8                      protocol;   /* app managing this nh */
        u8                      nh_flags;
        bool                    is_group;
+       bool                    is_fdb_nh;
 
        refcount_t              refcnt;
        struct rcu_head         rcu;
@@ -304,4 +308,14 @@ static inline void nexthop_path_fib6_result(struct fib6_result *res, int hash)
 int nexthop_for_each_fib6_nh(struct nexthop *nh,
                             int (*cb)(struct fib6_nh *nh, void *arg),
                             void *arg);
+
+static inline struct nh_info *nexthop_path_fdb(struct nexthop *nh,  u32 hash)
+{
+       struct nh_info *nhi;
+
+       nh = nexthop_select_path(nh, hash);
+       nhi = rcu_dereference(nh->nh_info);
+
+       return nhi;
+}
 #endif
include/uapi/linux/nexthop.h +1 -0
index 7b61867..19a234a 100644
@@ -48,6 +48,7 @@ enum {
         */
        NHA_GROUPS,     /* flag; only return nexthop groups in dump */
        NHA_MASTER,     /* u32;  only return nexthops with given master dev */
+       NHA_FDB,        /* nexthop belongs to a bridge fdb */
 
        __NHA_MAX,
 };
net/ipv4/nexthop.c +44 -6
index 3957364..98f8d2a 100644
@@ -33,6 +33,7 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = {
        [NHA_ENCAP]             = { .type = NLA_NESTED },
        [NHA_GROUPS]            = { .type = NLA_FLAG },
        [NHA_MASTER]            = { .type = NLA_U32 },
+       [NHA_FDB]               = { .type = NLA_FLAG },
 };
 
 static unsigned int nh_dev_hashfn(unsigned int val)
@@ -107,6 +108,7 @@ static struct nexthop *nexthop_alloc(void)
                INIT_LIST_HEAD(&nh->fi_list);
                INIT_LIST_HEAD(&nh->f6i_list);
                INIT_LIST_HEAD(&nh->grp_list);
+               INIT_LIST_HEAD(&nh->fdb_list);
        }
        return nh;
 }
@@ -227,6 +229,9 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
        if (nla_put_u32(skb, NHA_ID, nh->id))
                goto nla_put_failure;
 
+       if (nh->is_fdb_nh && nla_put_flag(skb, NHA_FDB))
+               goto nla_put_failure;
+
        if (nh->is_group) {
                struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
 
@@ -241,7 +246,7 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
                if (nla_put_flag(skb, NHA_BLACKHOLE))
                        goto nla_put_failure;
                goto out;
-       } else {
+       } else if (!nh->is_fdb_nh) {
                const struct net_device *dev;
 
                dev = nhi->fib_nhc.nhc_dev;
@@ -393,6 +398,7 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
        unsigned int len = nla_len(tb[NHA_GROUP]);
        struct nexthop_grp *nhg;
        unsigned int i, j;
+       u8 nhg_fdb = 0;
 
        if (len & (sizeof(struct nexthop_grp) - 1)) {
                NL_SET_ERR_MSG(extack,
@@ -421,6 +427,8 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
                }
        }
 
+       if (tb[NHA_FDB])
+               nhg_fdb = 1;
        nhg = nla_data(tb[NHA_GROUP]);
        for (i = 0; i < len; ++i) {
                struct nexthop *nh;
@@ -432,11 +440,16 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
                }
                if (!valid_group_nh(nh, len, extack))
                        return -EINVAL;
+               if (nhg_fdb && !nh->is_fdb_nh) {
+                       NL_SET_ERR_MSG(extack, "FDB Multipath group can only have fdb nexthops");
+                       return -EINVAL;
+               }
        }
        for (i = NHA_GROUP + 1; i < __NHA_MAX; ++i) {
                if (!tb[i])
                        continue;
-
+               if (tb[NHA_FDB])
+                       continue;
                NL_SET_ERR_MSG(extack,
                               "No other attributes can be set in nexthop groups");
                return -EINVAL;
@@ -495,6 +508,9 @@ struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
                if (hash > atomic_read(&nhge->upper_bound))
                        continue;
 
+               if (nhge->nh->is_fdb_nh)
+                       return nhge->nh;
+
                /* nexthops always check if it is good and does
                 * not rely on a sysctl for this behavior
                 */
@@ -564,6 +580,11 @@ int fib6_check_nexthop(struct nexthop *nh, struct fib6_config *cfg,
 {
        struct nh_info *nhi;
 
+       if (nh->is_fdb_nh) {
+               NL_SET_ERR_MSG(extack, "Route cannot point to a fdb nexthop");
+               return -EINVAL;
+       }
+
        /* fib6_src is unique to a fib6_info and limits the ability to cache
         * routes in fib6_nh within a nexthop that is potentially shared
         * across multiple fib entries. If the config wants to use source
@@ -640,6 +661,12 @@ int fib_check_nexthop(struct nexthop *nh, u8 scope,
 {
        int err = 0;
 
+       if (nh->is_fdb_nh) {
+               NL_SET_ERR_MSG(extack, "Route cannot point to a fdb nexthop");
+               err = -EINVAL;
+               goto out;
+       }
+
        if (nh->is_group) {
                struct nh_group *nhg;
 
@@ -1125,6 +1152,9 @@ static struct nexthop *nexthop_create_group(struct net *net,
                nh_group_rebalance(nhg);
        }
 
+       if (cfg->nh_fdb)
+               nh->is_fdb_nh = 1;
+
        rcu_assign_pointer(nh->nh_grp, nhg);
 
        return nh;
@@ -1152,7 +1182,7 @@ static int nh_create_ipv4(struct net *net, struct nexthop *nh,
                .fc_encap = cfg->nh_encap,
                .fc_encap_type = cfg->nh_encap_type,
        };
-       u32 tb_id = l3mdev_fib_table(cfg->dev);
+       u32 tb_id = (cfg->dev ? l3mdev_fib_table(cfg->dev) : RT_TABLE_MAIN);
        int err;
 
        err = fib_nh_init(net, fib_nh, &fib_cfg, 1, extack);
@@ -1161,6 +1191,9 @@ static int nh_create_ipv4(struct net *net, struct nexthop *nh,
                goto out;
        }
 
+       if (nh->is_fdb_nh)
+               goto out;
+
        /* sets nh_dev if successful */
        err = fib_check_nh(net, fib_nh, tb_id, 0, extack);
        if (!err) {
@@ -1227,6 +1260,9 @@ static struct nexthop *nexthop_create(struct net *net, struct nh_config *cfg,
        nhi->family = cfg->nh_family;
        nhi->fib_nhc.nhc_scope = RT_SCOPE_LINK;
 
+       if (cfg->nh_fdb)
+               nh->is_fdb_nh = 1;
+
        if (cfg->nh_blackhole) {
                nhi->reject_nh = 1;
                cfg->nh_ifindex = net->loopback_dev->ifindex;
@@ -1248,7 +1284,8 @@ static struct nexthop *nexthop_create(struct net *net, struct nh_config *cfg,
        }
 
        /* add the entry to the device based hash */
-       nexthop_devhash_add(net, nhi);
+       if (!nh->is_fdb_nh)
+               nexthop_devhash_add(net, nhi);
 
        rcu_assign_pointer(nh->nh_info, nhi);
 
@@ -1367,6 +1404,9 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
                        NL_SET_ERR_MSG(extack, "Invalid group type");
                        goto out;
                }
+               if (tb[NHA_FDB])
+                       cfg->nh_fdb = nla_get_flag(tb[NHA_FDB]);
+
                err = nh_check_attr_group(net, tb, extack);
 
                /* no other attributes should be set */
@@ -1385,26 +1425,38 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
                goto out;
        }
 
-       if (!tb[NHA_OIF]) {
-               NL_SET_ERR_MSG(extack, "Device attribute required for non-blackhole nexthops");

net/ipv4/nexthop.c static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, · line 1437

Quoted 10 lines
net/ipv4/nexthop.c +10 -0
+       if (tb[NHA_FDB]) {
+               if (tb[NHA_OIF] ||
+                   tb[NHA_ENCAP]   || tb[NHA_ENCAP_TYPE]) {
+                       NL_SET_ERR_MSG(extack, "Fdb attribute can not be used with encap or oif");
+                       goto out;
+               }
+
+               cfg->nh_fdb = nla_get_flag(tb[NHA_FDB]);
+       }
+

all this strict checking still missed the check for blackhole and
reject flags. I will include them in the non-RC version.

Quoted 81 lines
net/ipv4/nexthop.c +24 -18
+       if (!cfg->nh_fdb && !tb[NHA_OIF]) {
+               NL_SET_ERR_MSG(extack, "Device attribute required for non-blackhole and non-fdb nexthops");
                goto out;
        }
 
-       cfg->nh_ifindex = nla_get_u32(tb[NHA_OIF]);
-       if (cfg->nh_ifindex)
-               cfg->dev = __dev_get_by_index(net, cfg->nh_ifindex);
+       if (!cfg->nh_fdb && tb[NHA_OIF]) {
+               cfg->nh_ifindex = nla_get_u32(tb[NHA_OIF]);
+               if (cfg->nh_ifindex)
+                       cfg->dev = __dev_get_by_index(net, cfg->nh_ifindex);
 
-       if (!cfg->dev) {
-               NL_SET_ERR_MSG(extack, "Invalid device index");
-               goto out;
-       } else if (!(cfg->dev->flags & IFF_UP)) {
-               NL_SET_ERR_MSG(extack, "Nexthop device is not up");
-               err = -ENETDOWN;
-               goto out;
-       } else if (!netif_carrier_ok(cfg->dev)) {
-               NL_SET_ERR_MSG(extack, "Carrier for nexthop device is down");
-               err = -ENETDOWN;
-               goto out;
+               if (!cfg->dev) {
+                       NL_SET_ERR_MSG(extack, "Invalid device index");
+                       goto out;
+               } else if (!(cfg->dev->flags & IFF_UP)) {
+                       NL_SET_ERR_MSG(extack, "Nexthop device is not up");
+                       err = -ENETDOWN;
+                       goto out;
+               } else if (!netif_carrier_ok(cfg->dev)) {
+                       NL_SET_ERR_MSG(extack, "Carrier for nexthop device is down");
+                       err = -ENETDOWN;
+                       goto out;
+               }
        }
 
        err = -EINVAL;
@@ -1633,7 +1685,7 @@ static bool nh_dump_filtered(struct nexthop *nh, int dev_idx, int master_idx,
 
 static int nh_valid_dump_req(const struct nlmsghdr *nlh, int *dev_idx,
                             int *master_idx, bool *group_filter,
-                            struct netlink_callback *cb)
+                            bool *fdb_filter, struct netlink_callback *cb)
 {
        struct netlink_ext_ack *extack = cb->extack;
        struct nlattr *tb[NHA_MAX + 1];
@@ -1670,6 +1722,9 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh, int *dev_idx,
                case NHA_GROUPS:
                        *group_filter = true;
                        break;
+               case NHA_FDB:
+                       *fdb_filter = true;
+                       break;
                default:
                        NL_SET_ERR_MSG(extack, "Unsupported attribute in dump request");
                        return -EINVAL;
@@ -1688,17 +1743,17 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh, int *dev_idx,
 /* rtnl */
 static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       bool group_filter = false, fdb_filter = false;
        struct nhmsg *nhm = nlmsg_data(cb->nlh);
        int dev_filter_idx = 0, master_idx = 0;
        struct net *net = sock_net(skb->sk);
        struct rb_root *root = &net->nexthop.rb_root;
-       bool group_filter = false;
        struct rb_node *node;
        int idx = 0, s_idx;
        int err;
 
        err = nh_valid_dump_req(cb->nlh, &dev_filter_idx, &master_idx,
-                               &group_filter, cb);
+                               &group_filter, &fdb_filter, cb);
        if (err < 0)
                return err;
 
--

2.1.4

#3 lore raw

Re: [RFC PATCH net-next 1/5] nexthop: support for fdb ecmp nexthops

In reply to Roopa Prabhu
Quoted 4 lines · Roopa Prabhu
 include/net/nexthop.h        |  14 ++++++
 include/uapi/linux/nexthop.h |   1 +
 net/ipv4/nexthop.c           | 101 +++++++++++++++++++++++++++++++++----------
 3 files changed, 93 insertions(+), 23 deletions(-)

pretty cool that you can extend this from routes to fdb entries with such a small change stat.

Quoted 38 lines
include/net/nexthop.h +4 -0
index c440ccc..3ad4e97 100644
@@ -26,6 +26,7 @@ struct nh_config {
 	u8		nh_family;
 	u8		nh_protocol;
 	u8		nh_blackhole;
+	u8		nh_fdb;
 	u32		nh_flags;
 
 	int		nh_ifindex;
@@ -52,6 +53,7 @@ struct nh_info {
 
 	u8			family;
 	bool			reject_nh;
+	bool			fdb_nh;
 
 	union {
 		struct fib_nh_common	fib_nhc;
@@ -80,6 +82,7 @@ struct nexthop {
 	struct rb_node		rb_node;    /* entry on netns rbtree */
 	struct list_head	fi_list;    /* v4 entries using nh */
 	struct list_head	f6i_list;   /* v6 entries using nh */
+	struct list_head        fdb_list;   /* fdb entries using this nh */
 	struct list_head	grp_list;   /* nh group entries using this nh */
 	struct net		*net;
 
@@ -88,6 +91,7 @@ struct nexthop {
 	u8			protocol;   /* app managing this nh */
 	u8			nh_flags;
 	bool			is_group;
+	bool			is_fdb_nh;
 
 	refcount_t		refcnt;
 	struct rcu_head		rcu;

include/net/nexthop.h static inline void nexthop_path_fib6_result(struct fib6_result *res, int hash) · line 312

Quoted 5 lines
include/net/nexthop.h +2 -0
@@ -304,4 +308,14 @@ static inline void nexthop_path_fib6_result(struct fib6_result *res, int hash)
 int nexthop_for_each_fib6_nh(struct nexthop *nh,
 			     int (*cb)(struct fib6_nh *nh, void *arg),
 			     void *arg);
+
+static inline struct nh_info *nexthop_path_fdb(struct nexthop *nh,  u32 hash)

this is used in the next patch. Any way to not leak the nh_info struct into vxlan code? Right now nh_info is only used in nexthop.{c,h}.

Quoted 14 lines
include/net/nexthop.h +8 -0
+{
+	struct nh_info *nhi;
+
+	nh = nexthop_select_path(nh, hash);
+	nhi = rcu_dereference(nh->nh_info);
+
+	return nhi;
+}
 #endif
include/uapi/linux/nexthop.h +0 -0
index 7b61867..19a234a 100644

include/uapi/linux/nexthop.h enum { · line 51

Quoted 4 lines
include/uapi/linux/nexthop.h +1 -0
@@ -48,6 +48,7 @@ enum {
 	 */
 	NHA_GROUPS,	/* flag; only return nexthop groups in dump */
 	NHA_MASTER,	/* u32;  only return nexthops with given master dev */
+	NHA_FDB,	/* nexthop belongs to a bridge fdb */

please add the 'type' to the comment; I tried to make this uapi file completely self-documenting. ie., no one should have to consult the code to know what kind of attribute NHA_FDB is.

Quoted 60 lines
include/uapi/linux/nexthop.h +0 -0
 	__NHA_MAX,
 };
net/ipv4/nexthop.c +9 -1
index 3957364..98f8d2a 100644
@@ -33,6 +33,7 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = {
 	[NHA_ENCAP]		= { .type = NLA_NESTED },
 	[NHA_GROUPS]		= { .type = NLA_FLAG },
 	[NHA_MASTER]		= { .type = NLA_U32 },
+	[NHA_FDB]		= { .type = NLA_FLAG },
 };
 
 static unsigned int nh_dev_hashfn(unsigned int val)
@@ -107,6 +108,7 @@ static struct nexthop *nexthop_alloc(void)
 		INIT_LIST_HEAD(&nh->fi_list);
 		INIT_LIST_HEAD(&nh->f6i_list);
 		INIT_LIST_HEAD(&nh->grp_list);
+		INIT_LIST_HEAD(&nh->fdb_list);
 	}
 	return nh;
 }
@@ -227,6 +229,9 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
 	if (nla_put_u32(skb, NHA_ID, nh->id))
 		goto nla_put_failure;
 
+	if (nh->is_fdb_nh && nla_put_flag(skb, NHA_FDB))
+		goto nla_put_failure;
+
 	if (nh->is_group) {
 		struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
 
@@ -241,7 +246,7 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
 		if (nla_put_flag(skb, NHA_BLACKHOLE))
 			goto nla_put_failure;
 		goto out;
-	} else {
+	} else if (!nh->is_fdb_nh) {
 		const struct net_device *dev;
 
 		dev = nhi->fib_nhc.nhc_dev;
@@ -393,6 +398,7 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
 	unsigned int len = nla_len(tb[NHA_GROUP]);
 	struct nexthop_grp *nhg;
 	unsigned int i, j;
+	u8 nhg_fdb = 0;
 
 	if (len & (sizeof(struct nexthop_grp) - 1)) {
 		NL_SET_ERR_MSG(extack,
@@ -421,6 +427,8 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
 		}
 	}
 
+	if (tb[NHA_FDB])
+		nhg_fdb = 1;
 	nhg = nla_data(tb[NHA_GROUP]);
 	for (i = 0; i < len; ++i) {
 		struct nexthop *nh;

net/ipv4/nexthop.c static int nh_check_attr_group(struct net *net, struct nlattr *tb[], · line 446

Quoted 7 lines
net/ipv4/nexthop.c +4 -0
@@ -432,11 +440,16 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
 		}
 		if (!valid_group_nh(nh, len, extack))
 			return -EINVAL;
+		if (nhg_fdb && !nh->is_fdb_nh) {
+			NL_SET_ERR_MSG(extack, "FDB Multipath group can only have fdb nexthops");
+			return -EINVAL;
+		}

you should check the reverse as well -- non-nhg_fdb can not use an fdb nh. ie., a group can not be a mix of fdb and route entries.

Make sure the selftests covers the permutations as well.

Quoted 10 lines
net/ipv4/nexthop.c +2 -1
 	}
 	for (i = NHA_GROUP + 1; i < __NHA_MAX; ++i) {
 		if (!tb[i])
 			continue;
-
+		if (tb[NHA_FDB])
+			continue;
 		NL_SET_ERR_MSG(extack,
 			       "No other attributes can be set in nexthop groups");
 		return -EINVAL;
#4 lore raw

Re: [RFC PATCH net-next 1/5] nexthop: support for fdb ecmp nexthops

Quoted 9 lines · David Ahern
Quoted 4 lines · Roopa Prabhu
 include/net/nexthop.h        |  14 ++++++
 include/uapi/linux/nexthop.h |   1 +
 net/ipv4/nexthop.c           | 101 +++++++++++++++++++++++++++++++++----------
 3 files changed, 93 insertions(+), 23 deletions(-)

pretty cool that you can extend this from routes to fdb entries with such a small change stat.

yep, exactly. everything fell into place so neatly.

Quoted 36 lines
Quoted 36 lines
include/net/nexthop.h +4 -0
index c440ccc..3ad4e97 100644
@@ -26,6 +26,7 @@ struct nh_config {
      u8              nh_family;
      u8              nh_protocol;
      u8              nh_blackhole;
+     u8              nh_fdb;
      u32             nh_flags;
 
      int             nh_ifindex;
@@ -52,6 +53,7 @@ struct nh_info {
 
      u8                      family;
      bool                    reject_nh;
+     bool                    fdb_nh;
 
      union {
              struct fib_nh_common    fib_nhc;
@@ -80,6 +82,7 @@ struct nexthop {
      struct rb_node          rb_node;    /* entry on netns rbtree */
      struct list_head        fi_list;    /* v4 entries using nh */
      struct list_head        f6i_list;   /* v6 entries using nh */
+     struct list_head        fdb_list;   /* fdb entries using this nh */
      struct list_head        grp_list;   /* nh group entries using this nh */
      struct net              *net;
 
@@ -88,6 +91,7 @@ struct nexthop {
      u8                      protocol;   /* app managing this nh */
      u8                      nh_flags;
      bool                    is_group;
+     bool                    is_fdb_nh;
 
Quoted 12 lines

include/net/nexthop.h static inline void nexthop_path_fib6_result(struct fib6_result *res, int hash) · line 312

Quoted 8 lines
include/net/nexthop.h +2 -0
      refcount_t              refcnt;
      struct rcu_head         rcu;
@@ -304,4 +308,14 @@ static inline void nexthop_path_fib6_result(struct fib6_result *res, int hash)
 int nexthop_for_each_fib6_nh(struct nexthop *nh,
                           int (*cb)(struct fib6_nh *nh, void *arg),
                           void *arg);
+
+static inline struct nh_info *nexthop_path_fdb(struct nexthop *nh,  u32 hash)

this is used in the next patch. Any way to not leak the nh_info struct into vxlan code? Right now nh_info is only used in nexthop.{c,h}.

yes, sure I think I can do that. I will add an api to get the nh family and use nh everywhere.

Quoted 14 lines
Quoted 14 lines
include/net/nexthop.h +8 -0
+{
+     struct nh_info *nhi;
+
+     nh = nexthop_select_path(nh, hash);
+     nhi = rcu_dereference(nh->nh_info);
+
+     return nhi;
+}
 #endif
include/uapi/linux/nexthop.h +0 -0
index 7b61867..19a234a 100644
@@ -48,6 +48,7 @@ enum {
Quoted 9 lines

include/uapi/linux/nexthop.h enum { · line 51

Quoted 4 lines
include/uapi/linux/nexthop.h +1 -0
       */
      NHA_GROUPS,     /* flag; only return nexthop groups in dump */
      NHA_MASTER,     /* u32;  only return nexthops with given master dev */
+     NHA_FDB,        /* nexthop belongs to a bridge fdb */

please add the 'type' to the comment; I tried to make this uapi file completely self-documenting. ie., no one should have to consult the code to know what kind of attribute NHA_FDB is.

yep, will do. not sure how i missed it,

Quoted 71 lines
Quoted 60 lines
include/uapi/linux/nexthop.h +0 -0
      __NHA_MAX,
 };
net/ipv4/nexthop.c +9 -1
index 3957364..98f8d2a 100644
@@ -33,6 +33,7 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = {
      [NHA_ENCAP]             = { .type = NLA_NESTED },
      [NHA_GROUPS]            = { .type = NLA_FLAG },
      [NHA_MASTER]            = { .type = NLA_U32 },
+     [NHA_FDB]               = { .type = NLA_FLAG },
 };
 
 static unsigned int nh_dev_hashfn(unsigned int val)
@@ -107,6 +108,7 @@ static struct nexthop *nexthop_alloc(void)
              INIT_LIST_HEAD(&nh->fi_list);
              INIT_LIST_HEAD(&nh->f6i_list);
              INIT_LIST_HEAD(&nh->grp_list);
+             INIT_LIST_HEAD(&nh->fdb_list);
      }
      return nh;
 }
@@ -227,6 +229,9 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
      if (nla_put_u32(skb, NHA_ID, nh->id))
              goto nla_put_failure;
 
+     if (nh->is_fdb_nh && nla_put_flag(skb, NHA_FDB))
+             goto nla_put_failure;
+
      if (nh->is_group) {
              struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
 
@@ -241,7 +246,7 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
              if (nla_put_flag(skb, NHA_BLACKHOLE))
                      goto nla_put_failure;
              goto out;
-     } else {
+     } else if (!nh->is_fdb_nh) {
              const struct net_device *dev;
 
              dev = nhi->fib_nhc.nhc_dev;
@@ -393,6 +398,7 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
      unsigned int len = nla_len(tb[NHA_GROUP]);
      struct nexthop_grp *nhg;
      unsigned int i, j;
+     u8 nhg_fdb = 0;
 
      if (len & (sizeof(struct nexthop_grp) - 1)) {
              NL_SET_ERR_MSG(extack,
@@ -421,6 +427,8 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
              }
      }
 
+     if (tb[NHA_FDB])
+             nhg_fdb = 1;
      nhg = nla_data(tb[NHA_GROUP]);
      for (i = 0; i < len; ++i) {
              struct nexthop *nh;

net/ipv4/nexthop.c static int nh_check_attr_group(struct net *net, struct nlattr *tb[], · line 446

Quoted 7 lines
net/ipv4/nexthop.c +4 -0
@@ -432,11 +440,16 @@ static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
              }
              if (!valid_group_nh(nh, len, extack))
                      return -EINVAL;
+             if (nhg_fdb && !nh->is_fdb_nh) {
+                     NL_SET_ERR_MSG(extack, "FDB Multipath group can only have fdb nexthops");
+                     return -EINVAL;
+             }

you should check the reverse as well -- non-nhg_fdb can not use an fdb nh. ie., a group can not be a mix of fdb and route entries.

Quoted 2 lines

Make sure the selftests covers the permutations as well.

yep, will do

Quoted 12 lines
Quoted 10 lines
net/ipv4/nexthop.c +2 -1
      }
      for (i = NHA_GROUP + 1; i < __NHA_MAX; ++i) {
              if (!tb[i])
                      continue;
-
+             if (tb[NHA_FDB])
+                     continue;
              NL_SET_ERR_MSG(extack,
                             "No other attributes can be set in nexthop groups");
              return -EINVAL;
#5 lore raw

RFC PATCH 2/5 vxlan: ecmp support for mac fdb entries

In reply to Roopa Prabhu

From: Roopa Prabhu <[email protected]>

Todays vxlan mac fdb entries can point to multiple remote ips (rdsts) with the sole purpose of replicating broadcast-multicast and unknown unicast packets to those remote ips.

E-VPN multihoming [1,2,3] requires bridged vxlan traffic to be load balanced to remote switches (vteps) belonging to the same multi-homed ethernet segment (E-VPN multihoming is analogous to multi-homed LAG implementations, but with the inter-switch peerlink replaced with a vxlan tunnel). In other words it needs support for mac ecmp. Furthermore, for faster convergence, E-VPN multihoming needs the ability to update fdb ecmp nexthops independent of the fdb entries.

New route nexthop API is perfect for this usecase. This patch extends the vxlan fdb code to take a nexthop id pointing to an ecmp nexthop group.

Changes include:
- New NDA_NH_ID attribute for fdbs
- Use the newly added fdb nexthop groups
- makes vxlan rdsts and nexthop handling code mutually exclusive
- since this is a new use-case and the requirement is for ecmp nexthop groups, the fdb add and update path checks that the nexthop is really an ecmp nexthop group. This check can be relaxed in the future, if we want to introduce replication fdb nexthop groups and allow its use in lieu of current rdst lists.
- fdb update requests with nexthop id's only allowed for existing fdb's that have nexthop id's
- learning will not override an existing fdb entry with nexthop group
- I have wrapped the switchdev offload code around the presence of rdst
- I think there is scope for simplyfing vxlan_xmit_one: Will see what I can do before the non-RFC version

[1] E-VPN RFC https://tools.ietf.org/html/rfc7432
[2] E-VPN with vxlan https://tools.ietf.org/html/rfc8365
[3] http://vger.kernel.org/lpc_net2018_talks/scaling_bridge_fdb_database_slidesV3.pdf

---
 drivers/net/vxlan.c            | 286 ++++++++++++++++++++++++++++++++---------
 include/uapi/linux/neighbour.h |   1 +
 2 files changed, 227 insertions(+), 60 deletions(-)
drivers/net/vxlan.c +226 -60
index a5b415f..176f2b3 100644
@@ -26,6 +26,7 @@
 #include <net/netns/generic.h>
 #include <net/tun_proto.h>
 #include <net/vxlan.h>
+#include <net/nexthop.h>
 
 #if IS_ENABLED(CONFIG_IPV6)
 #include <net/ip6_tunnel.h>
@@ -78,6 +79,8 @@ struct vxlan_fdb {
 	u16		  state;	/* see ndm_state */
 	__be32		  vni;
 	u16		  flags;	/* see ndm_flags and below */
+	struct list_head  nh_list;
+	struct nexthop	  *nh;
 };
 
 #define NTF_VXLAN_ADDED_BY_USER 0x100
@@ -174,11 +177,15 @@ static inline struct hlist_head *vs_head(struct net *net, __be16 port)
  */
 static inline struct vxlan_rdst *first_remote_rcu(struct vxlan_fdb *fdb)
 {
+	if (fdb->nh)
+		return NULL;
 	return list_entry_rcu(fdb->remotes.next, struct vxlan_rdst, list);
 }
 
 static inline struct vxlan_rdst *first_remote_rtnl(struct vxlan_fdb *fdb)
 {
+	if (fdb->nh)
+		return NULL;
 	return list_first_entry(&fdb->remotes, struct vxlan_rdst, list);
 }
 
@@ -265,15 +272,19 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
 	send_eth = send_ip = true;
 
 	if (type == RTM_GETNEIGH) {
-		send_ip = !vxlan_addr_any(&rdst->remote_ip);
+		if (rdst) {
+			send_ip = !vxlan_addr_any(&rdst->remote_ip);
+			ndm->ndm_family = send_ip ? rdst->remote_ip.sa.sa_family : AF_INET;
+		} else if (fdb->nh) {
+			ndm->ndm_family = fdb->nh->nh_info->family;
+		}
 		send_eth = !is_zero_ether_addr(fdb->eth_addr);
-		ndm->ndm_family = send_ip ? rdst->remote_ip.sa.sa_family : AF_INET;
 	} else
 		ndm->ndm_family	= AF_BRIDGE;
 	ndm->ndm_state = fdb->state;
 	ndm->ndm_ifindex = vxlan->dev->ifindex;
 	ndm->ndm_flags = fdb->flags;
-	if (rdst->offloaded)
+	if (rdst && rdst->offloaded)
 		ndm->ndm_flags |= NTF_OFFLOADED;
 	ndm->ndm_type = RTN_UNICAST;
 
@@ -284,23 +295,30 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
 
 	if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr))
 		goto nla_put_failure;
+	if (fdb->nh) {
+		if (nla_put_u32(skb, NDA_NH_ID, fdb->nh->id))
+			goto nla_put_failure;
+	} else if (rdst) {
+		if (send_ip && vxlan_nla_put_addr(skb, NDA_DST,
+						  &rdst->remote_ip))
+			goto nla_put_failure;
+
+		if (rdst->remote_port &&
+		    rdst->remote_port != vxlan->cfg.dst_port &&
+		    nla_put_be16(skb, NDA_PORT, rdst->remote_port))
+			goto nla_put_failure;
+		if (rdst->remote_vni != vxlan->default_dst.remote_vni &&
+		    nla_put_u32(skb, NDA_VNI, be32_to_cpu(rdst->remote_vni)))
+			goto nla_put_failure;
+		if (rdst->remote_ifindex &&
+		    nla_put_u32(skb, NDA_IFINDEX, rdst->remote_ifindex))
+			goto nla_put_failure;
+	}
 
-	if (send_ip && vxlan_nla_put_addr(skb, NDA_DST, &rdst->remote_ip))
-		goto nla_put_failure;
-
-	if (rdst->remote_port && rdst->remote_port != vxlan->cfg.dst_port &&
-	    nla_put_be16(skb, NDA_PORT, rdst->remote_port))
-		goto nla_put_failure;
-	if (rdst->remote_vni != vxlan->default_dst.remote_vni &&
-	    nla_put_u32(skb, NDA_VNI, be32_to_cpu(rdst->remote_vni)))
-		goto nla_put_failure;
 	if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && fdb->vni &&
 	    nla_put_u32(skb, NDA_SRC_VNI,
 			be32_to_cpu(fdb->vni)))
 		goto nla_put_failure;
-	if (rdst->remote_ifindex &&
-	    nla_put_u32(skb, NDA_IFINDEX, rdst->remote_ifindex))
-		goto nla_put_failure;
 
 	ci.ndm_used	 = jiffies_to_clock_t(now - fdb->used);
 	ci.ndm_confirmed = 0;
@@ -401,7 +419,7 @@ static int vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb,
 {
 	int err;
 
-	if (swdev_notify) {
+	if (swdev_notify && rd) {
 		switch (type) {
 		case RTM_NEWNEIGH:
 			err = vxlan_fdb_switchdev_call_notifiers(vxlan, fdb, rd,
@@ -805,6 +823,8 @@ static struct vxlan_fdb *vxlan_fdb_alloc(const u8 *mac, __u16 state,
 	f->flags = ndm_flags;
 	f->updated = f->used = jiffies;
 	f->vni = src_vni;
+	f->nh = NULL;
+	INIT_LIST_HEAD(&f->nh_list);
 	INIT_LIST_HEAD(&f->remotes);
 	memcpy(f->eth_addr, mac, ETH_ALEN);
 
@@ -819,11 +839,59 @@ static void vxlan_fdb_insert(struct vxlan_dev *vxlan, const u8 *mac,
 			   vxlan_fdb_head(vxlan, mac, src_vni));
 }
 
+static int vxlan_fdb_nh_update(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb,
+			       u32 nhid, struct netlink_ext_ack *extack)
+{
+	struct nexthop *nh;
+	int err = -EINVAL;
+
+	if (fdb->nh && (fdb->nh->id == nhid))
+		return 0;
+
+	nh = nexthop_find_by_id(vxlan->net, nhid);
+	if (!nh) {
+		NL_SET_ERR_MSG(extack, "Nexthop id does not exist");
+		goto err_inval;
+	}
+
+	if (nh) {
+		if (!nexthop_get(nh)) {
+			NL_SET_ERR_MSG(extack, "Nexthop has been deleted");
+			nh = NULL;
+			goto err_inval;
+		}
+		if (!nh->is_fdb_nh) {
+			NL_SET_ERR_MSG(extack, "Nexthop is not a fdb nexthop");
+			goto err_inval;
+		}
+
+		if (!nh->is_group || !nh->nh_grp->mpath) {
+			NL_SET_ERR_MSG(extack, "Nexthop is not a multipath group");
+			goto err_inval;
+		}
+	}
+
+	if (fdb->nh) {
+		list_del(&fdb->nh_list);
+		nexthop_put(fdb->nh);
+	}
+
+	fdb->nh = nh;
+	list_add(&fdb->nh_list, &nh->fdb_list);
+	return 0;
+
+err_inval:
+	if (nh)
+		nexthop_put(nh);
+	return err;
+}
+
 static int vxlan_fdb_create(struct vxlan_dev *vxlan,
 			    const u8 *mac, union vxlan_addr *ip,
 			    __u16 state, __be16 port, __be32 src_vni,
 			    __be32 vni, __u32 ifindex, __u16 ndm_flags,
-			    struct vxlan_fdb **fdb)
+			    u32 nhid, struct vxlan_fdb **fdb,
+			    struct netlink_ext_ack *extack)
 {
 	struct vxlan_rdst *rd = NULL;
 	struct vxlan_fdb *f;
@@ -838,15 +906,20 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan,
 	if (!f)
 		return -ENOMEM;
 
-	rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
-	if (rc < 0) {
-		kfree(f);
-		return rc;
-	}
+	if (nhid)
+		rc = vxlan_fdb_nh_update(vxlan, f, nhid, extack);
+	else
+		rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
+	if (rc < 0)
+		goto errout;
 
 	*fdb = f;
 
 	return 0;
+
+errout:
+	kfree(f);
+	return rc;
 }
 
 static void __vxlan_fdb_free(struct vxlan_fdb *f)
@@ -897,7 +970,7 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
 				     __u16 state, __u16 flags,
 				     __be16 port, __be32 vni,
 				     __u32 ifindex, __u16 ndm_flags,
-				     struct vxlan_fdb *f,
+				     struct vxlan_fdb *f, u32 nhid,
 				     bool swdev_notify,
 				     struct netlink_ext_ack *extack)
 {
@@ -908,6 +981,9 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
 	int rc = 0;
 	int err;
 
+	if (nhid && !f->nh)
+		return -EOPNOTSUPP;
+
 	/* Do not allow an externally learned entry to take over an entry added
 	 * by the user.
 	 */
@@ -925,6 +1001,19 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
 		}
 	}
 
+	if (nhid) {
+		if (!f->nh)
+			return -EOPNOTSUPP;
+
+		if (f->nh->id != nhid) {
+			rc = vxlan_fdb_nh_update(vxlan, f, nhid, extack);
+			if (rc < 0)
+				return rc;
+			notify = 1;
+			f->updated = jiffies;
+		}
+	}
+
 	if ((flags & NLM_F_REPLACE)) {
 		/* Only change unicasts */
 		if (!(is_multicast_ether_addr(f->eth_addr) ||
@@ -975,7 +1064,7 @@ static int vxlan_fdb_update_create(struct vxlan_dev *vxlan,
 				   const u8 *mac, union vxlan_addr *ip,
 				   __u16 state, __u16 flags,
 				   __be16 port, __be32 src_vni, __be32 vni,
-				   __u32 ifindex, __u16 ndm_flags,
+				   __u32 ifindex, __u16 ndm_flags, u32 nhid,
 				   bool swdev_notify,
 				   struct netlink_ext_ack *extack)
 {
@@ -990,7 +1079,7 @@ static int vxlan_fdb_update_create(struct vxlan_dev *vxlan,
 
 	netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip);
 	rc = vxlan_fdb_create(vxlan, mac, ip, state, port, src_vni,
-			      vni, ifindex, fdb_flags, &f);
+			      vni, ifindex, fdb_flags, nhid, &f, extack);
 	if (rc < 0)
 		return rc;
 
@@ -1012,7 +1101,7 @@ static int vxlan_fdb_update(struct vxlan_dev *vxlan,
 			    const u8 *mac, union vxlan_addr *ip,
 			    __u16 state, __u16 flags,
 			    __be16 port, __be32 src_vni, __be32 vni,
-			    __u32 ifindex, __u16 ndm_flags,
+			    __u32 ifindex, __u16 ndm_flags, u32 nhid,
 			    bool swdev_notify,
 			    struct netlink_ext_ack *extack)
 {
@@ -1028,14 +1117,15 @@ static int vxlan_fdb_update(struct vxlan_dev *vxlan,
 
 		return vxlan_fdb_update_existing(vxlan, ip, state, flags, port,
 						 vni, ifindex, ndm_flags, f,
-						 swdev_notify, extack);
+						 nhid, swdev_notify, extack);
 	} else {
 		if (!(flags & NLM_F_CREATE))
 			return -ENOENT;
 
 		return vxlan_fdb_update_create(vxlan, mac, ip, state, flags,
 					       port, src_vni, vni, ifindex,
-					       ndm_flags, swdev_notify, extack);
+					       ndm_flags, nhid, swdev_notify,
+					       extack);
 	}
 }
 
@@ -1049,7 +1139,7 @@ static void vxlan_fdb_dst_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
 
 static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan,
 			   union vxlan_addr *ip, __be16 *port, __be32 *src_vni,
-			   __be32 *vni, u32 *ifindex)
+			   __be32 *vni, u32 *ifindex, u32 *nhid)
 {
 	struct net *net = dev_net(vxlan->dev);
 	int err;
@@ -1109,6 +1199,11 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan,
 		*ifindex = 0;
 	}
 
+	if (tb[NDA_NH_ID])
+		*nhid = nla_get_u32(tb[NDA_NH_ID]);
+	else
+		*nhid = 0;
+
 	return 0;
 }
 
@@ -1123,7 +1218,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 	union vxlan_addr ip;
 	__be16 port;
 	__be32 src_vni, vni;
-	u32 ifindex;
+	u32 ifindex, nhid;
 	u32 hash_index;
 	int err;
 
@@ -1133,10 +1228,11 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 		return -EINVAL;
 	}
 
-	if (tb[NDA_DST] == NULL)
+	if (!tb || (!tb[NDA_DST] && !tb[NDA_NH_ID]))
 		return -EINVAL;
 
-	err = vxlan_fdb_parse(tb, vxlan, &ip, &port, &src_vni, &vni, &ifindex);
+	err = vxlan_fdb_parse(tb, vxlan, &ip, &port, &src_vni, &vni, &ifindex,
+			      &nhid);
 	if (err)
 		return err;
 
@@ -1148,7 +1244,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 	err = vxlan_fdb_update(vxlan, addr, &ip, ndm->ndm_state, flags,
 			       port, src_vni, vni, ifindex,
 			       ndm->ndm_flags | NTF_VXLAN_ADDED_BY_USER,
-			       true, extack);
+			       nhid, true, extack);
 	spin_unlock_bh(&vxlan->hash_lock[hash_index]);
 
 	return err;
@@ -1181,6 +1277,12 @@ static int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
 		goto out;
 	}
 
+	if (f->nh) {
+		list_del(&f->nh_list);
+		nexthop_put(f->nh);
+		f->nh = NULL;
+	}
+
 	vxlan_fdb_destroy(vxlan, f, true, swdev_notify);
 
 out:
@@ -1196,11 +1298,12 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
 	union vxlan_addr ip;
 	__be32 src_vni, vni;
 	__be16 port;
-	u32 ifindex;
+	u32 ifindex, nhid;
 	u32 hash_index;
 	int err;
 
-	err = vxlan_fdb_parse(tb, vxlan, &ip, &port, &src_vni, &vni, &ifindex);
+	err = vxlan_fdb_parse(tb, vxlan, &ip, &port, &src_vni, &vni, &ifindex,
+			      &nhid);
 	if (err)
 		return err;
 
@@ -1228,6 +1331,17 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
 		hlist_for_each_entry_rcu(f, &vxlan->fdb_head[h], hlist) {
 			struct vxlan_rdst *rd;
 
+			if (f->nh) {
+				err = vxlan_fdb_info(skb, vxlan, f,
+						     NETLINK_CB(cb->skb).portid,
+						     cb->nlh->nlmsg_seq,
+						     RTM_NEWNEIGH,
+						     NLM_F_MULTI, NULL);
+				if (err < 0)
+					goto out;
+				continue;
+			}
+
 			list_for_each_entry_rcu(rd, &f->remotes, list) {
 				if (*idx < cb->args[2])
 					goto skip;
@@ -1311,6 +1425,10 @@ static bool vxlan_snoop(struct net_device *dev,
 		if (f->state & (NUD_PERMANENT | NUD_NOARP))
 			return true;
 
+		/* Don't override an fdb with nexthop with a learnt entry */
+		if (f->nh)
+			return true;
+
 		if (net_ratelimit())
 			netdev_info(dev,
 				    "%pM migrated from %pIS to %pIS\n",
@@ -1333,7 +1451,7 @@ static bool vxlan_snoop(struct net_device *dev,
 					 vxlan->cfg.dst_port,
 					 vni,
 					 vxlan->default_dst.remote_vni,
-					 ifindex, NTF_SELF, true, NULL);
+					 ifindex, NTF_SELF, 0, true, NULL);
 		spin_unlock(&vxlan->hash_lock[hash_index]);
 	}
 
@@ -2227,6 +2345,8 @@ static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan, struct net_device
 
 	if (tos && !info)
 		use_cache = false;
+	if (!dst_cache)
+		use_cache = false;
 	if (use_cache) {
 		rt = dst_cache_get_ip4(dst_cache, saddr);
 		if (rt)
@@ -2408,11 +2528,26 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev,
 	return 0;
 }
 
+static void nhc_gw2vxlan_addr(struct nh_info *nhi, union vxlan_addr *remote_ip)
+{
+	memset(remote_ip, 0, sizeof(union vxlan_addr));
+	switch (nhi->fib_nh.nh_common.nhc_gw_family) {
+	case AF_INET:
+		remote_ip->sin.sin_addr.s_addr = nhi->fib_nh.nh_common.nhc_gw.ipv4;
+		remote_ip->sa.sa_family = AF_INET;
+		break;
+	case AF_INET6:
+		remote_ip->sin6.sin6_addr = nhi->fib_nh.nh_common.nhc_gw.ipv6;
+		remote_ip->sa.sa_family = AF_INET6;
+		break;
+	}
+}
+
 static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 			   __be32 default_vni, struct vxlan_rdst *rdst,
-			   bool did_rsc)
+			   struct nh_info *nhi, bool did_rsc)
 {
-	struct dst_cache *dst_cache;
+	struct dst_cache *dst_cache = NULL;
 	struct ip_tunnel_info *info;
 	struct vxlan_dev *vxlan = netdev_priv(dev);
 	const struct iphdr *old_iph = ip_hdr(skb);
@@ -2432,8 +2567,13 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 
 	info = skb_tunnel_info(skb);
 
-	if (rdst) {
-		dst = &rdst->remote_ip;
+	if (rdst || nhi) {
+		if (rdst) {
+			dst = &rdst->remote_ip;
+		} else {
+			nhc_gw2vxlan_addr(nhi, &remote_ip);
+			dst = &remote_ip;
+		}
 		if (vxlan_addr_any(dst)) {
 			if (did_rsc) {
 				/* short-circuited back to local bridge */
@@ -2443,11 +2583,17 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 			goto drop;
 		}
 
-		dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port;
-		vni = (rdst->remote_vni) ? : default_vni;
-		ifindex = rdst->remote_ifindex;
+		if (rdst) {
+			dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port;
+			vni = rdst->remote_vni ? : default_vni;
+			ifindex = rdst->remote_ifindex;
+			dst_cache = &rdst->dst_cache;
+		} else {
+			dst_port = vxlan->cfg.dst_port;
+			vni = default_vni;
+			ifindex = nhi->fib_nh.fib_nh_oif;
+		}
 		local_ip = vxlan->cfg.saddr;
-		dst_cache = &rdst->dst_cache;
 		md->gbp = skb->mark;
 		if (flags & VXLAN_F_TTL_INHERIT) {
 			ttl = ip_tunnel_get_ttl(old_iph, skb);
@@ -2616,6 +2762,19 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 	kfree_skb(skb);
 }
 
+static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev,
+			  struct vxlan_fdb *f, __be32 vni, bool did_rsc)
+{
+	struct nexthop *nh = f->nh;
+	struct nh_info *nhi;
+	u32 hash;
+
+	hash = skb_get_hash(skb);
+	nhi = nexthop_path_fdb(nh, hash);
+
+	vxlan_xmit_one(skb, dev, vni, NULL, nhi, did_rsc);
+}
+
 /* Transmit local packets over Vxlan
  *
  * Outer IP header inherits ECN and DF from inner header.
@@ -2642,7 +2801,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
 			vni = tunnel_id_to_key32(info->key.tun_id);
 		} else {
 			if (info && info->mode & IP_TUNNEL_INFO_TX)
-				vxlan_xmit_one(skb, dev, vni, NULL, false);
+				vxlan_xmit_one(skb, dev, vni, NULL, NULL,
+					       false);
 			else
 				kfree_skb(skb);
 			return NETDEV_TX_OK;
@@ -2692,22 +2852,28 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
 		}
 	}
 
-	list_for_each_entry_rcu(rdst, &f->remotes, list) {
-		struct sk_buff *skb1;
+	if (f->nh) {
+		vxlan_xmit_nh(skb, dev, f,
+			      (vni ? : vxlan->default_dst.remote_vni), did_rsc);
+	} else {
+		list_for_each_entry_rcu(rdst, &f->remotes, list) {
+			struct sk_buff *skb1;
 
-		if (!fdst) {
-			fdst = rdst;
-			continue;
+			if (!fdst) {
+				fdst = rdst;
+				continue;
+			}
+			skb1 = skb_clone(skb, GFP_ATOMIC);
+			if (skb1)
+				vxlan_xmit_one(skb1, dev, vni, rdst, NULL,
+					       did_rsc);
 		}
-		skb1 = skb_clone(skb, GFP_ATOMIC);
-		if (skb1)
-			vxlan_xmit_one(skb1, dev, vni, rdst, did_rsc);
+		if (fdst)
+			vxlan_xmit_one(skb, dev, vni, fdst, NULL, did_rsc);
+		else
+			kfree_skb(skb);
 	}
 
-	if (fdst)
-		vxlan_xmit_one(skb, dev, vni, fdst, did_rsc);
-	else
-		kfree_skb(skb);
 	return NETDEV_TX_OK;
 }
 
@@ -3615,7 +3781,7 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
 				       dst->remote_vni,
 				       dst->remote_vni,
 				       dst->remote_ifindex,
-				       NTF_SELF, &f);
+				       NTF_SELF, 0, &f, extack);
 		if (err)
 			return err;
 	}
@@ -4013,7 +4179,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
 					       vxlan->cfg.dst_port,
 					       conf.vni, conf.vni,
 					       conf.remote_ifindex,
-					       NTF_SELF, true, extack);
+					       NTF_SELF, 0, true, extack);
 			if (err) {
 				spin_unlock_bh(&vxlan->hash_lock[hash_index]);
 				netdev_adjacent_change_abort(dst->remote_dev,
@@ -4335,7 +4501,7 @@ vxlan_fdb_external_learn_add(struct net_device *dev,
 			       fdb_info->remote_vni,
 			       fdb_info->remote_ifindex,
 			       NTF_USE | NTF_SELF | NTF_EXT_LEARNED,
-			       false, extack);
+			       0, false, extack);
 	spin_unlock_bh(&vxlan->hash_lock[hash_index]);
 
 	return err;
include/uapi/linux/neighbour.h +1 -0
index cd144e3..eefcda8 100644
@@ -29,6 +29,7 @@ enum {
 	NDA_LINK_NETNSID,
 	NDA_SRC_VNI,
 	NDA_PROTOCOL,  /* Originator of entry */
+	NDA_NH_ID,
 	__NDA_MAX
 };
 
Signature · 1 line
2.1.4
#6 lore raw

Re: [RFC PATCH net-next 2/5] vxlan: ecmp support for mac fdb entries

include/uapi/linux/neighbour.h enum { · line 34

Quoted 11 lines · Roopa Prabhu
include/uapi/linux/neighbour.h +1 -0
index cd144e3..eefcda8 100644
@@ -29,6 +29,7 @@ enum {
 	NDA_LINK_NETNSID,
 	NDA_SRC_VNI,
 	NDA_PROTOCOL,  /* Originator of entry */
+	NDA_NH_ID,
 	__NDA_MAX
 };

those attributes are shared by neighbor and bridge code for example.

nda_policy should reject it, and a new attribute provides a means for starting strict checking (add NDA_UNSPEC with .strict_start_type = NDA_NH_ID).

Similar for the fdb code in rtnetlink.c. Shame AF_BRIDGE parsing does not have a policy attribute.

#7 lore raw

Re: [RFC PATCH net-next 2/5] vxlan: ecmp support for mac fdb entries

Quoted 16 lines · David Ahern

include/uapi/linux/neighbour.h enum { · line 34

Quoted 11 lines · Roopa Prabhu
include/uapi/linux/neighbour.h +1 -0
index cd144e3..eefcda8 100644
@@ -29,6 +29,7 @@ enum {
      NDA_LINK_NETNSID,
      NDA_SRC_VNI,
      NDA_PROTOCOL,  /* Originator of entry */
+     NDA_NH_ID,
      __NDA_MAX
 };

those attributes are shared by neighbor and bridge code for example.

Quoted 6 lines

nda_policy should reject it, and a new attribute provides a means for starting strict checking (add NDA_UNSPEC with .strict_start_type = NDA_NH_ID).

Similar for the fdb code in rtnetlink.c. Shame AF_BRIDGE parsing does not have a policy attribute.

okay, will look

#8 lore raw

RFC PATCH 3/5 nexthop: add support for notifiers

In reply to Roopa Prabhu

From: Roopa Prabhu <[email protected]>

This patch adds nexthop add/del notifiers. To be used by vxlan driver in a later patch. Could possibly be used by switchdev drivers in the future.

---
 include/net/netns/nexthop.h |  1 +
 include/net/nexthop.h       | 12 ++++++++++++
 net/ipv4/nexthop.c          | 27 +++++++++++++++++++++++++++
 3 files changed, 40 insertions(+)
include/net/netns/nexthop.h +1 -0
index c712ee5..1937476 100644
@@ -14,5 +14,6 @@ struct netns_nexthop {
 
 	unsigned int		seq;		/* protected by rtnl_mutex */
 	u32			last_id_allocated;
+	struct atomic_notifier_head notifier_chain;
 };
 #endif
include/net/nexthop.h +12 -0
index 3ad4e97..0301740 100644
@@ -10,6 +10,7 @@
 #define __LINUX_NEXTHOP_H
 
 #include <linux/netdevice.h>
+#include <linux/notifier.h>
 #include <linux/route.h>
 #include <linux/types.h>
 #include <net/ip_fib.h>
@@ -102,6 +103,17 @@ struct nexthop {
 	};
 };
 
+enum nexthop_event_type {
+	NEXTHOP_EVENT_ADD,
+	NEXTHOP_EVENT_DEL
+};
+
+int call_nexthop_notifier(struct notifier_block *nb, struct net *net,
+			  enum nexthop_event_type event_type,
+			  struct nexthop *nh);
+int register_nexthop_notifier(struct notifier_block *nb);
+int unregister_nexthop_notifier(struct notifier_block *nb);
+
 /* caller is holding rcu or rtnl; no reference taken to nexthop */
 struct nexthop *nexthop_find_by_id(struct net *net, u32 id);
 void nexthop_free_rcu(struct rcu_head *head);
net/ipv4/nexthop.c +27 -0
index 98f8d2a..514bb4e 100644
@@ -36,6 +36,17 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = {
 	[NHA_FDB]		= { .type = NLA_FLAG },
 };
 
+static int call_nexthop_notifiers(struct net *net,
+				  enum fib_event_type event_type,
+				  struct nexthop *nh)
+{
+	int err;
+
+	err = atomic_notifier_call_chain(&net->nexthop.notifier_chain,
+					 event_type, nh);
+	return notifier_to_errno(err);
+}
+
 static unsigned int nh_dev_hashfn(unsigned int val)
 {
 	unsigned int mask = NH_DEV_HASHSIZE - 1;
@@ -814,6 +825,8 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh)
 		ipv6_stub->ip6_del_rt(net, f6i,
 				      !net->ipv4.sysctl_nexthop_compat_mode);
 	}
+
+	call_nexthop_notifiers(net, NEXTHOP_EVENT_DEL, nh);
 }
 
 static void __remove_nexthop(struct net *net, struct nexthop *nh,
@@ -1838,6 +1851,20 @@ static struct notifier_block nh_netdev_notifier = {
 	.notifier_call = nh_netdev_event,
 };
 
+static ATOMIC_NOTIFIER_HEAD(nexthop_notif_chain);
+
+int register_nexthop_notifier(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_register(&nexthop_notif_chain, nb);
+}
+EXPORT_SYMBOL(register_nexthop_notifier);
+
+int unregister_nexthop_notifier(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_unregister(&nexthop_notif_chain, nb);
+}
+EXPORT_SYMBOL(unregister_nexthop_notifier);
+
 static void __net_exit nexthop_net_exit(struct net *net)
 {
 	rtnl_lock();
Signature · 1 line
2.1.4
#9 lore raw

RFC PATCH 4/5 vxlan: support for nexthop notifiers

In reply to Roopa Prabhu

From: Roopa Prabhu <[email protected]>

vxlan driver registers for nexthop add/del notifiers to cleanup fdb entries pointing to nexthops.

---
 drivers/net/vxlan.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/net/vxlan.c +33 -3
index 176f2b3..df6c5ff 100644
@@ -81,6 +81,7 @@ struct vxlan_fdb {
 	u16		  flags;	/* see ndm_flags and below */
 	struct list_head  nh_list;
 	struct nexthop	  *nh;
+	struct vxlan_dev  *vdev;
 };
 
 #define NTF_VXLAN_ADDED_BY_USER 0x100
@@ -811,8 +812,9 @@ static int vxlan_gro_complete(struct sock *sk, struct sk_buff *skb, int nhoff)
 	return eth_gro_complete(skb, nhoff + sizeof(struct vxlanhdr));
 }
 
-static struct vxlan_fdb *vxlan_fdb_alloc(const u8 *mac, __u16 state,
-					 __be32 src_vni, __u16 ndm_flags)
+static struct vxlan_fdb *vxlan_fdb_alloc(struct vxlan_dev *vxlan, const u8 *mac,
+					 __u16 state, __be32 src_vni,
+					 __u16 ndm_flags)
 {
 	struct vxlan_fdb *f;
 
@@ -824,6 +826,7 @@ static struct vxlan_fdb *vxlan_fdb_alloc(const u8 *mac, __u16 state,
 	f->updated = f->used = jiffies;
 	f->vni = src_vni;
 	f->nh = NULL;
+	f->vdev = vxlan;
 	INIT_LIST_HEAD(&f->nh_list);
 	INIT_LIST_HEAD(&f->remotes);
 	memcpy(f->eth_addr, mac, ETH_ALEN);
@@ -902,7 +905,7 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan,
 		return -ENOSPC;
 
 	netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip);
-	f = vxlan_fdb_alloc(mac, state, src_vni, ndm_flags);
+	f = vxlan_fdb_alloc(vxlan, mac, state, src_vni, ndm_flags);
 	if (!f)
 		return -ENOMEM;
 
@@ -954,6 +957,7 @@ static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
 					 swdev_notify, NULL);
 
 	hlist_del_rcu(&f->hlist);
+	f->vdev = NULL;
 	call_rcu(&f->rcu, vxlan_fdb_free);
 }
 
@@ -4576,6 +4580,25 @@ static struct notifier_block vxlan_switchdev_notifier_block __read_mostly = {
 	.notifier_call = vxlan_switchdev_event,
 };
 
+static int vxlan_nexthop_event(struct notifier_block *nb,
+			       unsigned long event, void *ptr)
+{
+	struct nexthop *nh = ptr;
+	struct vxlan_fdb *fdb;
+
+	if (!nh || event != NEXTHOP_EVENT_DEL)
+		return NOTIFY_DONE;
+
+	list_for_each_entry(fdb, &nh->fdb_list, nh_list)
+		vxlan_fdb_destroy(fdb->vdev, fdb, true, false);
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block vxlan_nexthop_notifier_block __read_mostly = {
+	.notifier_call = vxlan_nexthop_event,
+};
+
 static __net_init int vxlan_init_net(struct net *net)
 {
 	struct vxlan_net *vn = net_generic(net, vxlan_net_id);
@@ -4655,7 +4678,13 @@ static int __init vxlan_init_module(void)
 	if (rc)
 		goto out4;
 
+	rc = register_nexthop_notifier(&vxlan_nexthop_notifier_block);
+	if (rc)
+		goto out5;
+
 	return 0;
+out5:
+	rtnl_link_unregister(&vxlan_link_ops);
 out4:
 	unregister_switchdev_notifier(&vxlan_switchdev_notifier_block);
 out3:
@@ -4672,6 +4701,7 @@ static void __exit vxlan_cleanup_module(void)
 	rtnl_link_unregister(&vxlan_link_ops);
 	unregister_switchdev_notifier(&vxlan_switchdev_notifier_block);
 	unregister_netdevice_notifier(&vxlan_notifier_block);
+	unregister_nexthop_notifier(&vxlan_nexthop_notifier_block);
 	unregister_pernet_subsys(&vxlan_net_ops);
 	/* rcu_barrier() is called by netns */
 }
Signature · 1 line
2.1.4
#10 lore raw

RFC PATCH 5/5 selftests: net: add fdb nexthop tests

In reply to Roopa Prabhu

From: Roopa Prabhu <[email protected]>

This commit adds ipv4 and ipv6 basic fdb tests to fib_nexthops.sh. Started with a separate test script for fdb nexthops but seems like its better for basic tests to live in fib_nexthops.sh for overall nexthop API coverage.

TODO:
- runtime vxlan fdb tests: Its best to add test similar to the forwarding/vxlan_symmetric.sh test (WIP at the moment. Any suggestions welcome. Plan to include it in the non-RFC version)

---
 tools/testing/selftests/net/fib_nexthops.sh | 77 ++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 2 deletions(-)
tools/testing/selftests/net/fib_nexthops.sh +75 -2
index dd0e5fe..41bce6c 100755
@@ -19,8 +19,8 @@ ret=0
 ksft_skip=4
 
 # all tests in this script. Can be overridden with -t option
-IPV4_TESTS="ipv4_fcnal ipv4_grp_fcnal ipv4_withv6_fcnal ipv4_fcnal_runtime ipv4_compat_mode"
-IPV6_TESTS="ipv6_fcnal ipv6_grp_fcnal ipv6_fcnal_runtime ipv6_compat_mode"
+IPV4_TESTS="ipv4_fcnal ipv4_grp_fcnal ipv4_withv6_fcnal ipv4_fcnal_runtime ipv4_compat_mode ipv4_fdb_grp_fcnal"
+IPV6_TESTS="ipv6_fcnal ipv6_grp_fcnal ipv6_fcnal_runtime ipv6_compat_mode ipv6_fdb_grp_fcnal"
 
 ALL_TESTS="basic ${IPV4_TESTS} ${IPV6_TESTS}"
 TESTS="${ALL_TESTS}"
@@ -146,6 +146,7 @@ setup()
 	create_ns remote
 
 	IP="ip -netns me"
+	BRIDGE="bridge -netns me"
 	set -e
 	$IP li add veth1 type veth peer name veth2
 	$IP li set veth1 up
@@ -280,6 +281,78 @@ stop_ip_monitor()
 	return $rc
 }
 
+check_nexthop_fdb_support()
+{
+	$IP nexthop help 2>&1 | grep -q fdb
+	if [ $? -ne 0 ]; then
+		echo "SKIP: iproute2 too old, missing fdb nexthop support"
+		exit $ksft_skip
+	fi
+}
+
+ipv6_fdb_grp_fcnal()
+{
+	local rc
+
+	echo
+	echo "IPv6 fdb groups functional"
+	echo "--------------------------"
+
+	check_nexthop_fdb_support
+
+	# basic functionality: create a fdb nexthop group, default weight
+	run_cmd "$IP nexthop add id 61 via 2001:db8:91::2 fdb"
+	run_cmd "$IP nexthop add id 62 via 2001:db8:91::3 fdb"
+	run_cmd "$IP nexthop add id 101 group 61/62 fdb"
+	log_test $? 0 "Create nexthop group with single nexthop"
+
+	# get nexthop group
+	run_cmd "$IP nexthop get id 101"
+	log_test $? 0 "Get nexthop group by id"
+	check_nexthop "id 101" "id 101 group 61/62 fdb"
+
+	$IP link add name vx10 type vxlan id 1010 local 10.0.0.1 remote 10.0.0.2 dstport 4789 nolearning noudpcsum tos inherit ttl 100
+	run_cmd "$BRIDGE fdb add 02:02:00:00:00:12 dev vx10 nhid 101 self"
+	log_test $? 0 "Fdb mac add with nexthop"
+
+	run_cmd "$IP nexthop del id 101"
+	log_test $? 0 "Fdb nexthop delete"
+
+	$IP link del dev vx10
+}
+
+ipv4_fdb_grp_fcnal()
+{
+	local rc
+
+	echo
+	echo "IPv4 fdb groups functional"
+	echo "--------------------------"
+
+	check_nexthop_fdb_support
+
+	# create group with multiple nexthops
+	run_cmd "$IP nexthop add id 12 via 172.16.1.2 fdb"
+	run_cmd "$IP nexthop add id 13 via 172.16.1.3 fdb"
+	run_cmd "$IP nexthop add id 102 group 12/13 fdb"
+	log_test $? 0 "Nexthop group with multiple nexthops"
+	check_nexthop "id 102" "id 102 group 12/13"
+
+	# get nexthop group
+	run_cmd "$IP nexthop get id 102"
+	log_test $? 0 "Get nexthop group by id"
+	check_nexthop "id 102" "id 102 group 12/13 fdb"
+
+	run_cmd "$IP link add name vx10 type vxlan id 1010 local 10.0.0.1 remote 10.0.0.2 dstport 4789 nolearning noudpcsum tos inherit ttl 100"
+	run_cmd "$BRIDGE fdb add 02:02:00:00:00:13 dev vx10 nhid 102 self"
+	log_test $? 0 "Fdb mac add with nexthop"
+
+	run_cmd "$IP nexthop del id 102"
+	log_test $? 0 "Fdb nexthop delete"
+
+	$IP link del dev vx10
+}
+
 ################################################################################
 # basic operations (add, delete, replace) on nexthops and nexthop groups
 #
Signature · 1 line
2.1.4
#11 lore raw

Re: [RFC PATCH net-next 5/5] selftests: net: add fdb nexthop tests

Quoted 12 lines · Roopa Prabhu

From: Roopa Prabhu <[email protected]>

This commit adds ipv4 and ipv6 basic fdb tests to fib_nexthops.sh. Started with a separate test script for fdb nexthops but seems like its better for basic tests to live in fib_nexthops.sh for overall nexthop API coverage.

TODO:
- runtime vxlan fdb tests: Its best to add test similar to the forwarding/vxlan_symmetric.sh test (WIP at the moment. Any suggestions welcome. Plan to include it in the non-RFC version)

Quoted 5 lines
---
 tools/testing/selftests/net/fib_nexthops.sh | 77 ++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 2 deletions(-)

make sure the selftests covers negative tests too in the existing functional test sets. e.g., fdb nh can not be used with routes, fdb and blackhole, mixed groups (mpath cannot have a mix of fdb and non-fdb).