Lines Matching refs:nexthop
2 /* Generic nexthop implementation
8 #include <linux/nexthop.h>
15 #include <net/nexthop.h>
19 static void remove_nexthop(struct net *net, struct nexthop *nh,
41 struct nexthop *nh)
45 err = blocking_notifier_call_chain(&net->nexthop.notifier_chain,
68 head = &net->nexthop.devhash[hash];
72 static void nexthop_free_mpath(struct nexthop *nh)
91 static void nexthop_free_single(struct nexthop *nh)
109 struct nexthop *nh = container_of(head, struct nexthop, rcu);
120 static struct nexthop *nexthop_alloc(void)
122 struct nexthop *nh;
124 nh = kzalloc(sizeof(struct nexthop), GFP_KERNEL);
147 while (++net->nexthop.seq == 0)
152 struct nexthop *nexthop_find_by_id(struct net *net, u32 id)
156 pp = &net->nexthop.rb_root.rb_node;
158 struct nexthop *nh;
165 nh = rb_entry(parent, struct nexthop, rb_node);
180 u32 id_start = net->nexthop.last_id_allocated;
183 net->nexthop.last_id_allocated++;
184 if (net->nexthop.last_id_allocated == id_start)
187 if (!nexthop_find_by_id(net, net->nexthop.last_id_allocated))
188 return net->nexthop.last_id_allocated;
225 static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
306 static size_t nh_nlmsg_size_grp(struct nexthop *nh)
315 static size_t nh_nlmsg_size_single(struct nexthop *nh)
346 static size_t nh_nlmsg_size(struct nexthop *nh)
360 static void nexthop_notify(int event, struct nexthop *nh, struct nl_info *info)
387 static bool valid_group_nh(struct nexthop *nh, unsigned int npaths,
398 "Multipath group can not be a nexthop within a group");
407 "Blackhole nexthop can not be used in a group with more than 1 path");
416 static int nh_check_attr_fdb_group(struct nexthop *nh, u8 *nh_family,
424 NL_SET_ERR_MSG(extack, "FDB nexthop group can only have fdb nexthops");
431 NL_SET_ERR_MSG(extack, "FDB nexthop group cannot have mixed family nexthops");
449 "Invalid length for nexthop group attribute");
453 /* convert len to number of nexthop ids */
478 struct nexthop *nh;
483 NL_SET_ERR_MSG(extack, "Invalid nexthop id");
493 NL_SET_ERR_MSG(extack, "Non FDB nexthop group cannot have fdb nexthops");
503 "No other attributes can be set in nexthop groups");
543 struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
545 struct nexthop *rc = NULL;
586 int nexthop_for_each_fib6_nh(struct nexthop *nh,
621 NL_SET_ERR_MSG(extack, "IPv6 routes using source address can not use nexthop objects");
627 int fib6_check_nexthop(struct nexthop *nh, struct fib6_config *cfg,
634 * routes in fib6_nh within a nexthop that is potentially shared
636 * routing it can not use nexthop objects. mlxsw also does not allow
657 NL_SET_ERR_MSG(extack, "Route cannot point to a fdb nexthop");
663 NL_SET_ERR_MSG(extack, "IPv6 routes can not use an IPv4 nexthop");
668 /* if existing nexthop has ipv6 routes linked to it, need
671 static int fib6_check_nh_list(struct nexthop *old, struct nexthop *new,
697 NL_SET_ERR_MSG(extack, "Scope mismatch with nexthop");
704 /* Invoked by fib add code to verify nexthop by id is ok with
705 * config for prefix; parts of fib_check_nh not done when nexthop
708 int fib_check_nexthop(struct nexthop *nh, u8 scope,
719 NL_SET_ERR_MSG(extack, "Route cannot point to a fdb nexthop");
736 NL_SET_ERR_MSG(extack, "Route cannot point to a fdb nexthop");
747 static int fib_check_nh_list(struct nexthop *old, struct nexthop *new,
785 struct nexthop *nhp = nhge->nh_parent;
786 struct nexthop *nh = nhge->nh;
812 /* current nexthop getting removed */
840 static void remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
852 static void remove_nexthop_group(struct nexthop *nh, struct nl_info *nlinfo)
867 /* not called for nexthop replace */
868 static void __remove_nexthop_fib(struct net *net, struct nexthop *nh)
890 static void __remove_nexthop(struct net *net, struct nexthop *nh,
908 static void remove_nexthop(struct net *net, struct nexthop *nh,
914 rb_erase(&nh->rb_node, &net->nexthop.rb_root);
925 /* if any FIB entries reference this nexthop, any dst entries
928 static void nh_rt_cache_flush(struct net *net, struct nexthop *nh,
929 struct nexthop *replaced_nh)
947 /* new dsts must use only the new nexthop group */
960 static int replace_nexthop_grp(struct net *net, struct nexthop *old,
961 struct nexthop *new,
968 NL_SET_ERR_MSG(extack, "Can not replace a nexthop group with a nexthop.");
975 /* update parents - used by nexthop code for cleanup */
1006 static int replace_nexthop_single(struct net *net, struct nexthop *old,
1007 struct nexthop *new,
1013 NL_SET_ERR_MSG(extack, "Can not replace a nexthop with a nexthop group.");
1029 /* When replacing an IPv4 nexthop with an IPv6 nexthop, potentially
1030 * update IPv4 indication in all the groups using the nexthop.
1036 struct nexthop *nhp = nhge->nh_parent;
1047 static void __nexthop_replace_notify(struct net *net, struct nexthop *nh,
1055 /* expectation is a few fib_info per nexthop and then
1073 * linked to this nexthop and for all groups that the nexthop
1076 static void nexthop_replace_notify(struct net *net, struct nexthop *nh,
1087 static int replace_nexthop(struct net *net, struct nexthop *old,
1088 struct nexthop *new, struct netlink_ext_ack *extack)
1095 * new nexthop definition
1112 /* if new nexthop is a blackhole, any groups using this
1113 * nexthop cannot have more than 1 path
1117 NL_SET_ERR_MSG(extack, "Blackhole nexthop can not be a member of a group with more than one path");
1146 static int insert_nexthop(struct net *net, struct nexthop *new_nh,
1150 struct rb_root *root = &net->nexthop.rb_root;
1159 struct nexthop *nh;
1167 nh = rb_entry(parent, struct nexthop, rb_node);
1212 struct hlist_head *head = &net->nexthop.devhash[hash];
1231 struct rb_root *root = &net->nexthop.rb_root;
1233 struct nexthop *nh;
1236 nh = rb_entry(node, struct nexthop, rb_node);
1242 static struct nexthop *nexthop_create_group(struct net *net,
1249 struct nexthop *nh;
1277 struct nexthop *nhe;
1319 static int nh_create_ipv4(struct net *net, struct nexthop *nh,
1358 static int nh_create_ipv6(struct net *net, struct nexthop *nh,
1393 static struct nexthop *nexthop_create(struct net *net, struct nh_config *cfg,
1397 struct nexthop *nh;
1450 static struct nexthop *nexthop_add(struct net *net, struct nh_config *cfg,
1453 struct nexthop *nh;
1457 NL_SET_ERR_MSG(extack, "Replace requires nexthop id");
1511 NL_SET_ERR_MSG(extack, "Invalid nexthop flags in ancillary header");
1553 NL_SET_ERR_MSG(extack, "Unsupported nexthop flags in ancillary header");
1610 NL_SET_ERR_MSG(extack, "Carrier for nexthop device is down");
1641 /* device only nexthop (no gateway) */
1644 "ONLINK flag can not be set for nexthop without a gateway");
1679 struct nexthop *nh;
1730 NL_SET_ERR_MSG(extack, "Invalid nexthop id");
1747 struct nexthop *nh;
1770 struct nexthop *nh;
1803 static bool nh_dump_filtered(struct nexthop *nh, int dev_idx, int master_idx,
1890 NL_SET_ERR_MSG(extack, "Invalid values in header for nexthop dump request");
1904 struct rb_root *root = &net->nexthop.rb_root;
1916 struct nexthop *nh;
1921 nh = rb_entry(node, struct nexthop, rb_node);
1943 cb->seq = net->nexthop.seq;
1953 struct hlist_head *head = &net->nexthop.devhash[hash];
1997 return blocking_notifier_chain_register(&net->nexthop.notifier_chain,
2004 return blocking_notifier_chain_unregister(&net->nexthop.notifier_chain,
2014 kfree(net->nexthop.devhash);
2021 net->nexthop.rb_root = RB_ROOT;
2022 net->nexthop.devhash = kzalloc(sz, GFP_KERNEL);
2023 if (!net->nexthop.devhash)
2025 BLOCKING_INIT_NOTIFIER_HEAD(&net->nexthop.notifier_chain);