1 // SPDX-License-Identifier: GPL-2.0
2 /* Generic nexthop implementation
4 * Copyright (c) 2017-19 Cumulus Networks
5 * Copyright (c) 2017-19 David Ahern <dsa@cumulusnetworks.com>
8 #include <linux/nexthop.h>
9 #include <linux/rtnetlink.h>
10 #include <linux/slab.h>
12 #include <net/ipv6_stubs.h>
13 #include <net/lwtunnel.h>
14 #include <net/ndisc.h>
15 #include <net/nexthop.h>
16 #include <net/route.h>
19 static void remove_nexthop(struct net *net, struct nexthop *nh,
20 struct nl_info *nlinfo);
22 #define NH_DEV_HASHBITS 8
23 #define NH_DEV_HASHSIZE (1U << NH_DEV_HASHBITS)
25 static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = {
26 [NHA_UNSPEC] = { .strict_start_type = NHA_UNSPEC + 1 },
27 [NHA_ID] = { .type = NLA_U32 },
28 [NHA_GROUP] = { .type = NLA_BINARY },
29 [NHA_GROUP_TYPE] = { .type = NLA_U16 },
30 [NHA_BLACKHOLE] = { .type = NLA_FLAG },
31 [NHA_OIF] = { .type = NLA_U32 },
32 [NHA_GATEWAY] = { .type = NLA_BINARY },
33 [NHA_ENCAP_TYPE] = { .type = NLA_U16 },
34 [NHA_ENCAP] = { .type = NLA_NESTED },
35 [NHA_GROUPS] = { .type = NLA_FLAG },
36 [NHA_MASTER] = { .type = NLA_U32 },
39 static unsigned int nh_dev_hashfn(unsigned int val)
41 unsigned int mask = NH_DEV_HASHSIZE - 1;
44 (val >> NH_DEV_HASHBITS) ^
45 (val >> (NH_DEV_HASHBITS * 2))) & mask;
48 static void nexthop_devhash_add(struct net *net, struct nh_info *nhi)
50 struct net_device *dev = nhi->fib_nhc.nhc_dev;
51 struct hlist_head *head;
56 hash = nh_dev_hashfn(dev->ifindex);
57 head = &net->nexthop.devhash[hash];
58 hlist_add_head(&nhi->dev_hash, head);
61 static void nexthop_free_mpath(struct nexthop *nh)
66 nhg = rcu_dereference_raw(nh->nh_grp);
67 for (i = 0; i < nhg->num_nh; ++i) {
68 struct nh_grp_entry *nhge = &nhg->nh_entries[i];
70 WARN_ON(!list_empty(&nhge->nh_list));
71 nexthop_put(nhge->nh);
74 WARN_ON(nhg->spare == nhg);
80 static void nexthop_free_single(struct nexthop *nh)
84 nhi = rcu_dereference_raw(nh->nh_info);
85 switch (nhi->family) {
87 fib_nh_release(nh->net, &nhi->fib_nh);
90 ipv6_stub->fib6_nh_release(&nhi->fib6_nh);
96 void nexthop_free_rcu(struct rcu_head *head)
98 struct nexthop *nh = container_of(head, struct nexthop, rcu);
101 nexthop_free_mpath(nh);
103 nexthop_free_single(nh);
107 EXPORT_SYMBOL_GPL(nexthop_free_rcu);
109 static struct nexthop *nexthop_alloc(void)
113 nh = kzalloc(sizeof(struct nexthop), GFP_KERNEL);
115 INIT_LIST_HEAD(&nh->fi_list);
116 INIT_LIST_HEAD(&nh->f6i_list);
117 INIT_LIST_HEAD(&nh->grp_list);
122 static struct nh_group *nexthop_grp_alloc(u16 num_nh)
124 size_t sz = offsetof(struct nexthop, nh_grp)
125 + sizeof(struct nh_group)
126 + sizeof(struct nh_grp_entry) * num_nh;
127 struct nh_group *nhg;
129 nhg = kzalloc(sz, GFP_KERNEL);
131 nhg->num_nh = num_nh;
136 static void nh_base_seq_inc(struct net *net)
138 while (++net->nexthop.seq == 0)
142 /* no reference taken; rcu lock or rtnl must be held */
143 struct nexthop *nexthop_find_by_id(struct net *net, u32 id)
145 struct rb_node **pp, *parent = NULL, *next;
147 pp = &net->nexthop.rb_root.rb_node;
151 next = rcu_dereference_raw(*pp);
156 nh = rb_entry(parent, struct nexthop, rb_node);
159 else if (id > nh->id)
160 pp = &next->rb_right;
166 EXPORT_SYMBOL_GPL(nexthop_find_by_id);
168 /* used for auto id allocation; called with rtnl held */
169 static u32 nh_find_unused_id(struct net *net)
171 u32 id_start = net->nexthop.last_id_allocated;
174 net->nexthop.last_id_allocated++;
175 if (net->nexthop.last_id_allocated == id_start)
178 if (!nexthop_find_by_id(net, net->nexthop.last_id_allocated))
179 return net->nexthop.last_id_allocated;
184 static int nla_put_nh_group(struct sk_buff *skb, struct nh_group *nhg)
186 struct nexthop_grp *p;
187 size_t len = nhg->num_nh * sizeof(*p);
193 group_type = NEXTHOP_GRP_TYPE_MPATH;
195 if (nla_put_u16(skb, NHA_GROUP_TYPE, group_type))
196 goto nla_put_failure;
198 nla = nla_reserve(skb, NHA_GROUP, len);
200 goto nla_put_failure;
203 for (i = 0; i < nhg->num_nh; ++i) {
204 p->id = nhg->nh_entries[i].nh->id;
205 p->weight = nhg->nh_entries[i].weight - 1;
215 static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
216 int event, u32 portid, u32 seq, unsigned int nlflags)
218 struct fib6_nh *fib6_nh;
219 struct fib_nh *fib_nh;
220 struct nlmsghdr *nlh;
224 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nhm), nlflags);
228 nhm = nlmsg_data(nlh);
229 nhm->nh_family = AF_UNSPEC;
230 nhm->nh_flags = nh->nh_flags;
231 nhm->nh_protocol = nh->protocol;
235 if (nla_put_u32(skb, NHA_ID, nh->id))
236 goto nla_put_failure;
239 struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
241 if (nla_put_nh_group(skb, nhg))
242 goto nla_put_failure;
246 nhi = rtnl_dereference(nh->nh_info);
247 nhm->nh_family = nhi->family;
248 if (nhi->reject_nh) {
249 if (nla_put_flag(skb, NHA_BLACKHOLE))
250 goto nla_put_failure;
253 const struct net_device *dev;
255 dev = nhi->fib_nhc.nhc_dev;
256 if (dev && nla_put_u32(skb, NHA_OIF, dev->ifindex))
257 goto nla_put_failure;
260 nhm->nh_scope = nhi->fib_nhc.nhc_scope;
261 switch (nhi->family) {
263 fib_nh = &nhi->fib_nh;
264 if (fib_nh->fib_nh_gw_family &&
265 nla_put_u32(skb, NHA_GATEWAY, fib_nh->fib_nh_gw4))
266 goto nla_put_failure;
270 fib6_nh = &nhi->fib6_nh;
271 if (fib6_nh->fib_nh_gw_family &&
272 nla_put_in6_addr(skb, NHA_GATEWAY, &fib6_nh->fib_nh_gw6))
273 goto nla_put_failure;
277 if (nhi->fib_nhc.nhc_lwtstate &&
278 lwtunnel_fill_encap(skb, nhi->fib_nhc.nhc_lwtstate,
279 NHA_ENCAP, NHA_ENCAP_TYPE) < 0)
280 goto nla_put_failure;
287 nlmsg_cancel(skb, nlh);
291 static size_t nh_nlmsg_size_grp(struct nexthop *nh)
293 struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
294 size_t sz = sizeof(struct nexthop_grp) * nhg->num_nh;
296 return nla_total_size(sz) +
297 nla_total_size(2); /* NHA_GROUP_TYPE */
300 static size_t nh_nlmsg_size_single(struct nexthop *nh)
302 struct nh_info *nhi = rtnl_dereference(nh->nh_info);
305 /* covers NHA_BLACKHOLE since NHA_OIF and BLACKHOLE
306 * are mutually exclusive
308 sz = nla_total_size(4); /* NHA_OIF */
310 switch (nhi->family) {
312 if (nhi->fib_nh.fib_nh_gw_family)
313 sz += nla_total_size(4); /* NHA_GATEWAY */
318 if (nhi->fib6_nh.fib_nh_gw_family)
319 sz += nla_total_size(sizeof(const struct in6_addr));
323 if (nhi->fib_nhc.nhc_lwtstate) {
324 sz += lwtunnel_get_encap_size(nhi->fib_nhc.nhc_lwtstate);
325 sz += nla_total_size(2); /* NHA_ENCAP_TYPE */
331 static size_t nh_nlmsg_size(struct nexthop *nh)
333 size_t sz = NLMSG_ALIGN(sizeof(struct nhmsg));
335 sz += nla_total_size(4); /* NHA_ID */
338 sz += nh_nlmsg_size_grp(nh);
340 sz += nh_nlmsg_size_single(nh);
345 static void nexthop_notify(int event, struct nexthop *nh, struct nl_info *info)
347 unsigned int nlflags = info->nlh ? info->nlh->nlmsg_flags : 0;
348 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0;
352 skb = nlmsg_new(nh_nlmsg_size(nh), gfp_any());
356 err = nh_fill_node(skb, nh, event, info->portid, seq, nlflags);
358 /* -EMSGSIZE implies BUG in nh_nlmsg_size() */
359 WARN_ON(err == -EMSGSIZE);
364 rtnl_notify(skb, info->nl_net, info->portid, RTNLGRP_NEXTHOP,
365 info->nlh, gfp_any());
369 rtnl_set_sk_err(info->nl_net, RTNLGRP_NEXTHOP, err);
372 static bool valid_group_nh(struct nexthop *nh, unsigned int npaths,
373 struct netlink_ext_ack *extack)
376 struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
378 /* nested multipath (group within a group) is not
382 NL_SET_ERR_MSG(extack,
383 "Multipath group can not be a nexthop within a group");
387 struct nh_info *nhi = rtnl_dereference(nh->nh_info);
389 if (nhi->reject_nh && npaths > 1) {
390 NL_SET_ERR_MSG(extack,
391 "Blackhole nexthop can not be used in a group with more than 1 path");
399 static int nh_check_attr_group(struct net *net, struct nlattr *tb[],
400 struct netlink_ext_ack *extack)
402 unsigned int len = nla_len(tb[NHA_GROUP]);
403 struct nexthop_grp *nhg;
406 if (!len || len & (sizeof(struct nexthop_grp) - 1)) {
407 NL_SET_ERR_MSG(extack,
408 "Invalid length for nexthop group attribute");
412 /* convert len to number of nexthop ids */
415 nhg = nla_data(tb[NHA_GROUP]);
416 for (i = 0; i < len; ++i) {
417 if (nhg[i].resvd1 || nhg[i].resvd2) {
418 NL_SET_ERR_MSG(extack, "Reserved fields in nexthop_grp must be 0");
421 if (nhg[i].weight > 254) {
422 NL_SET_ERR_MSG(extack, "Invalid value for weight");
425 for (j = i + 1; j < len; ++j) {
426 if (nhg[i].id == nhg[j].id) {
427 NL_SET_ERR_MSG(extack, "Nexthop id can not be used twice in a group");
433 nhg = nla_data(tb[NHA_GROUP]);
434 for (i = 0; i < len; ++i) {
437 nh = nexthop_find_by_id(net, nhg[i].id);
439 NL_SET_ERR_MSG(extack, "Invalid nexthop id");
442 if (!valid_group_nh(nh, len, extack))
445 for (i = NHA_GROUP_TYPE + 1; i < __NHA_MAX; ++i) {
449 NL_SET_ERR_MSG(extack,
450 "No other attributes can be set in nexthop groups");
457 static bool ipv6_good_nh(const struct fib6_nh *nh)
459 int state = NUD_REACHABLE;
464 n = __ipv6_neigh_lookup_noref_stub(nh->fib_nh_dev, &nh->fib_nh_gw6);
466 state = n->nud_state;
468 rcu_read_unlock_bh();
470 return !!(state & NUD_VALID);
473 static bool ipv4_good_nh(const struct fib_nh *nh)
475 int state = NUD_REACHABLE;
480 n = __ipv4_neigh_lookup_noref(nh->fib_nh_dev,
481 (__force u32)nh->fib_nh_gw4);
483 state = n->nud_state;
485 rcu_read_unlock_bh();
487 return !!(state & NUD_VALID);
490 struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
492 struct nexthop *rc = NULL;
493 struct nh_group *nhg;
499 nhg = rcu_dereference(nh->nh_grp);
500 for (i = 0; i < nhg->num_nh; ++i) {
501 struct nh_grp_entry *nhge = &nhg->nh_entries[i];
504 if (hash > atomic_read(&nhge->upper_bound))
507 /* nexthops always check if it is good and does
508 * not rely on a sysctl for this behavior
510 nhi = rcu_dereference(nhge->nh->nh_info);
511 switch (nhi->family) {
513 if (ipv4_good_nh(&nhi->fib_nh))
517 if (ipv6_good_nh(&nhi->fib6_nh))
528 EXPORT_SYMBOL_GPL(nexthop_select_path);
530 int nexthop_for_each_fib6_nh(struct nexthop *nh,
531 int (*cb)(struct fib6_nh *nh, void *arg),
538 struct nh_group *nhg;
541 nhg = rcu_dereference_rtnl(nh->nh_grp);
542 for (i = 0; i < nhg->num_nh; i++) {
543 struct nh_grp_entry *nhge = &nhg->nh_entries[i];
545 nhi = rcu_dereference_rtnl(nhge->nh->nh_info);
546 err = cb(&nhi->fib6_nh, arg);
551 nhi = rcu_dereference_rtnl(nh->nh_info);
552 err = cb(&nhi->fib6_nh, arg);
559 EXPORT_SYMBOL_GPL(nexthop_for_each_fib6_nh);
561 static int check_src_addr(const struct in6_addr *saddr,
562 struct netlink_ext_ack *extack)
564 if (!ipv6_addr_any(saddr)) {
565 NL_SET_ERR_MSG(extack, "IPv6 routes using source address can not use nexthop objects");
571 int fib6_check_nexthop(struct nexthop *nh, struct fib6_config *cfg,
572 struct netlink_ext_ack *extack)
576 /* fib6_src is unique to a fib6_info and limits the ability to cache
577 * routes in fib6_nh within a nexthop that is potentially shared
578 * across multiple fib entries. If the config wants to use source
579 * routing it can not use nexthop objects. mlxsw also does not allow
580 * fib6_src on routes.
582 if (cfg && check_src_addr(&cfg->fc_src, extack) < 0)
586 struct nh_group *nhg;
588 nhg = rtnl_dereference(nh->nh_grp);
592 nhi = rtnl_dereference(nh->nh_info);
593 if (nhi->family == AF_INET)
599 NL_SET_ERR_MSG(extack, "IPv6 routes can not use an IPv4 nexthop");
602 EXPORT_SYMBOL_GPL(fib6_check_nexthop);
604 /* if existing nexthop has ipv6 routes linked to it, need
605 * to verify this new spec works with ipv6
607 static int fib6_check_nh_list(struct nexthop *old, struct nexthop *new,
608 struct netlink_ext_ack *extack)
610 struct fib6_info *f6i;
612 if (list_empty(&old->f6i_list))
615 list_for_each_entry(f6i, &old->f6i_list, nh_list) {
616 if (check_src_addr(&f6i->fib6_src.addr, extack) < 0)
620 return fib6_check_nexthop(new, NULL, extack);
623 static int nexthop_check_scope(struct nexthop *nh, u8 scope,
624 struct netlink_ext_ack *extack)
628 nhi = rtnl_dereference(nh->nh_info);
629 if (scope == RT_SCOPE_HOST && nhi->fib_nhc.nhc_gw_family) {
630 NL_SET_ERR_MSG(extack,
631 "Route with host scope can not have a gateway");
635 if (nhi->fib_nhc.nhc_flags & RTNH_F_ONLINK && scope >= RT_SCOPE_LINK) {
636 NL_SET_ERR_MSG(extack, "Scope mismatch with nexthop");
643 /* Invoked by fib add code to verify nexthop by id is ok with
644 * config for prefix; parts of fib_check_nh not done when nexthop
647 int fib_check_nexthop(struct nexthop *nh, u8 scope,
648 struct netlink_ext_ack *extack)
653 struct nh_group *nhg;
655 if (scope == RT_SCOPE_HOST) {
656 NL_SET_ERR_MSG(extack, "Route with host scope can not have multiple nexthops");
661 nhg = rtnl_dereference(nh->nh_grp);
662 /* all nexthops in a group have the same scope */
663 err = nexthop_check_scope(nhg->nh_entries[0].nh, scope, extack);
665 err = nexthop_check_scope(nh, scope, extack);
671 static int fib_check_nh_list(struct nexthop *old, struct nexthop *new,
672 struct netlink_ext_ack *extack)
676 list_for_each_entry(fi, &old->fi_list, nh_list) {
679 err = fib_check_nexthop(new, fi->fib_scope, extack);
686 static void nh_group_rebalance(struct nh_group *nhg)
692 for (i = 0; i < nhg->num_nh; ++i)
693 total += nhg->nh_entries[i].weight;
695 for (i = 0; i < nhg->num_nh; ++i) {
696 struct nh_grp_entry *nhge = &nhg->nh_entries[i];
700 upper_bound = DIV_ROUND_CLOSEST_ULL((u64)w << 31, total) - 1;
701 atomic_set(&nhge->upper_bound, upper_bound);
705 static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
706 struct nl_info *nlinfo)
708 struct nh_grp_entry *nhges, *new_nhges;
709 struct nexthop *nhp = nhge->nh_parent;
710 struct nexthop *nh = nhge->nh;
711 struct nh_group *nhg, *newg;
716 nhg = rtnl_dereference(nhp->nh_grp);
719 /* last entry, keep it visible and remove the parent */
720 if (nhg->num_nh == 1) {
721 remove_nexthop(net, nhp, nlinfo);
725 newg->has_v4 = nhg->has_v4;
726 newg->mpath = nhg->mpath;
727 newg->num_nh = nhg->num_nh;
729 /* copy old entries to new except the one getting removed */
730 nhges = nhg->nh_entries;
731 new_nhges = newg->nh_entries;
732 for (i = 0, j = 0; i < nhg->num_nh; ++i) {
733 /* current nexthop getting removed */
734 if (nhg->nh_entries[i].nh == nh) {
739 list_del(&nhges[i].nh_list);
740 new_nhges[j].nh_parent = nhges[i].nh_parent;
741 new_nhges[j].nh = nhges[i].nh;
742 new_nhges[j].weight = nhges[i].weight;
743 list_add(&new_nhges[j].nh_list, &new_nhges[j].nh->grp_list);
747 nh_group_rebalance(newg);
748 rcu_assign_pointer(nhp->nh_grp, newg);
750 list_del(&nhge->nh_list);
751 nexthop_put(nhge->nh);
754 nexthop_notify(RTM_NEWNEXTHOP, nhp, nlinfo);
757 static void remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
758 struct nl_info *nlinfo)
760 struct nh_grp_entry *nhge, *tmp;
762 list_for_each_entry_safe(nhge, tmp, &nh->grp_list, nh_list)
763 remove_nh_grp_entry(net, nhge, nlinfo);
765 /* make sure all see the newly published array before releasing rtnl */
769 static void remove_nexthop_group(struct nexthop *nh, struct nl_info *nlinfo)
771 struct nh_group *nhg = rcu_dereference_rtnl(nh->nh_grp);
772 int i, num_nh = nhg->num_nh;
774 for (i = 0; i < num_nh; ++i) {
775 struct nh_grp_entry *nhge = &nhg->nh_entries[i];
777 if (WARN_ON(!nhge->nh))
780 list_del_init(&nhge->nh_list);
784 /* not called for nexthop replace */
785 static void __remove_nexthop_fib(struct net *net, struct nexthop *nh)
787 struct fib6_info *f6i, *tmp;
788 bool do_flush = false;
791 list_for_each_entry(fi, &nh->fi_list, nh_list) {
792 fi->fib_flags |= RTNH_F_DEAD;
798 /* ip6_del_rt removes the entry from this list hence the _safe */
799 list_for_each_entry_safe(f6i, tmp, &nh->f6i_list, nh_list) {
800 /* __ip6_del_rt does a release, so do a hold here */
802 ipv6_stub->ip6_del_rt(net, f6i);
806 static void __remove_nexthop(struct net *net, struct nexthop *nh,
807 struct nl_info *nlinfo)
809 __remove_nexthop_fib(net, nh);
812 remove_nexthop_group(nh, nlinfo);
816 nhi = rtnl_dereference(nh->nh_info);
817 if (nhi->fib_nhc.nhc_dev)
818 hlist_del(&nhi->dev_hash);
820 remove_nexthop_from_groups(net, nh, nlinfo);
824 static void remove_nexthop(struct net *net, struct nexthop *nh,
825 struct nl_info *nlinfo)
827 /* remove from the tree */
828 rb_erase(&nh->rb_node, &net->nexthop.rb_root);
831 nexthop_notify(RTM_DELNEXTHOP, nh, nlinfo);
833 __remove_nexthop(net, nh, nlinfo);
834 nh_base_seq_inc(net);
839 /* if any FIB entries reference this nexthop, any dst entries
840 * need to be regenerated
842 static void nh_rt_cache_flush(struct net *net, struct nexthop *nh,
843 struct nexthop *replaced_nh)
845 struct fib6_info *f6i;
846 struct nh_group *nhg;
849 if (!list_empty(&nh->fi_list))
852 list_for_each_entry(f6i, &nh->f6i_list, nh_list)
853 ipv6_stub->fib6_update_sernum(net, f6i);
855 /* if an IPv6 group was replaced, we have to release all old
856 * dsts to make sure all refcounts are released
858 if (!replaced_nh->is_group)
861 /* new dsts must use only the new nexthop group */
864 nhg = rtnl_dereference(replaced_nh->nh_grp);
865 for (i = 0; i < nhg->num_nh; i++) {
866 struct nh_grp_entry *nhge = &nhg->nh_entries[i];
867 struct nh_info *nhi = rtnl_dereference(nhge->nh->nh_info);
869 if (nhi->family == AF_INET6)
870 ipv6_stub->fib6_nh_release_dsts(&nhi->fib6_nh);
874 static int replace_nexthop_grp(struct net *net, struct nexthop *old,
876 struct netlink_ext_ack *extack)
878 struct nh_group *oldg, *newg;
881 if (!new->is_group) {
882 NL_SET_ERR_MSG(extack, "Can not replace a nexthop group with a nexthop.");
886 oldg = rtnl_dereference(old->nh_grp);
887 newg = rtnl_dereference(new->nh_grp);
889 /* update parents - used by nexthop code for cleanup */
890 for (i = 0; i < newg->num_nh; i++)
891 newg->nh_entries[i].nh_parent = old;
893 rcu_assign_pointer(old->nh_grp, newg);
895 for (i = 0; i < oldg->num_nh; i++)
896 oldg->nh_entries[i].nh_parent = new;
898 rcu_assign_pointer(new->nh_grp, oldg);
903 static int replace_nexthop_single(struct net *net, struct nexthop *old,
905 struct netlink_ext_ack *extack)
907 struct nh_info *oldi, *newi;
910 NL_SET_ERR_MSG(extack, "Can not replace a nexthop with a nexthop group.");
914 oldi = rtnl_dereference(old->nh_info);
915 newi = rtnl_dereference(new->nh_info);
917 newi->nh_parent = old;
918 oldi->nh_parent = new;
920 old->protocol = new->protocol;
921 old->nh_flags = new->nh_flags;
923 rcu_assign_pointer(old->nh_info, newi);
924 rcu_assign_pointer(new->nh_info, oldi);
929 static void __nexthop_replace_notify(struct net *net, struct nexthop *nh,
930 struct nl_info *info)
932 struct fib6_info *f6i;
934 if (!list_empty(&nh->fi_list)) {
937 /* expectation is a few fib_info per nexthop and then
938 * a lot of routes per fib_info. So mark the fib_info
939 * and then walk the fib tables once
941 list_for_each_entry(fi, &nh->fi_list, nh_list)
942 fi->nh_updated = true;
944 fib_info_notify_update(net, info);
946 list_for_each_entry(fi, &nh->fi_list, nh_list)
947 fi->nh_updated = false;
950 list_for_each_entry(f6i, &nh->f6i_list, nh_list)
951 ipv6_stub->fib6_rt_update(net, f6i, info);
954 /* send RTM_NEWROUTE with REPLACE flag set for all FIB entries
955 * linked to this nexthop and for all groups that the nexthop
958 static void nexthop_replace_notify(struct net *net, struct nexthop *nh,
959 struct nl_info *info)
961 struct nh_grp_entry *nhge;
963 __nexthop_replace_notify(net, nh, info);
965 list_for_each_entry(nhge, &nh->grp_list, nh_list)
966 __nexthop_replace_notify(net, nhge->nh_parent, info);
969 static int replace_nexthop(struct net *net, struct nexthop *old,
970 struct nexthop *new, struct netlink_ext_ack *extack)
972 bool new_is_reject = false;
973 struct nh_grp_entry *nhge;
976 /* check that existing FIB entries are ok with the
977 * new nexthop definition
979 err = fib_check_nh_list(old, new, extack);
983 err = fib6_check_nh_list(old, new, extack);
987 if (!new->is_group) {
988 struct nh_info *nhi = rtnl_dereference(new->nh_info);
990 new_is_reject = nhi->reject_nh;
993 list_for_each_entry(nhge, &old->grp_list, nh_list) {
994 /* if new nexthop is a blackhole, any groups using this
995 * nexthop cannot have more than 1 path
998 nexthop_num_path(nhge->nh_parent) > 1) {
999 NL_SET_ERR_MSG(extack, "Blackhole nexthop can not be a member of a group with more than one path");
1003 err = fib_check_nh_list(nhge->nh_parent, new, extack);
1007 err = fib6_check_nh_list(nhge->nh_parent, new, extack);
1013 err = replace_nexthop_grp(net, old, new, extack);
1015 err = replace_nexthop_single(net, old, new, extack);
1018 nh_rt_cache_flush(net, old, new);
1020 __remove_nexthop(net, new, NULL);
1027 /* called with rtnl_lock held */
1028 static int insert_nexthop(struct net *net, struct nexthop *new_nh,
1029 struct nh_config *cfg, struct netlink_ext_ack *extack)
1031 struct rb_node **pp, *parent = NULL, *next;
1032 struct rb_root *root = &net->nexthop.rb_root;
1033 bool replace = !!(cfg->nlflags & NLM_F_REPLACE);
1034 bool create = !!(cfg->nlflags & NLM_F_CREATE);
1035 u32 new_id = new_nh->id;
1036 int replace_notify = 0;
1039 pp = &root->rb_node;
1043 next = rtnl_dereference(*pp);
1049 nh = rb_entry(parent, struct nexthop, rb_node);
1050 if (new_id < nh->id) {
1051 pp = &next->rb_left;
1052 } else if (new_id > nh->id) {
1053 pp = &next->rb_right;
1054 } else if (replace) {
1055 rc = replace_nexthop(net, nh, new_nh, extack);
1057 new_nh = nh; /* send notification with old nh */
1062 /* id already exists and not a replace */
1067 if (replace && !create) {
1068 NL_SET_ERR_MSG(extack, "Replace specified without create and no entry exists");
1073 rb_link_node_rcu(&new_nh->rb_node, parent, pp);
1074 rb_insert_color(&new_nh->rb_node, root);
1078 nh_base_seq_inc(net);
1079 nexthop_notify(RTM_NEWNEXTHOP, new_nh, &cfg->nlinfo);
1081 nexthop_replace_notify(net, new_nh, &cfg->nlinfo);
1088 /* remove all nexthops tied to a device being deleted */
1089 static void nexthop_flush_dev(struct net_device *dev, unsigned long event)
1091 unsigned int hash = nh_dev_hashfn(dev->ifindex);
1092 struct net *net = dev_net(dev);
1093 struct hlist_head *head = &net->nexthop.devhash[hash];
1094 struct hlist_node *n;
1095 struct nh_info *nhi;
1097 hlist_for_each_entry_safe(nhi, n, head, dev_hash) {
1098 if (nhi->fib_nhc.nhc_dev != dev)
1101 if (nhi->reject_nh &&
1102 (event == NETDEV_DOWN || event == NETDEV_CHANGE))
1105 remove_nexthop(net, nhi->nh_parent, NULL);
1109 /* rtnl; called when net namespace is deleted */
1110 static void flush_all_nexthops(struct net *net)
1112 struct rb_root *root = &net->nexthop.rb_root;
1113 struct rb_node *node;
1116 while ((node = rb_first(root))) {
1117 nh = rb_entry(node, struct nexthop, rb_node);
1118 remove_nexthop(net, nh, NULL);
1123 static struct nexthop *nexthop_create_group(struct net *net,
1124 struct nh_config *cfg)
1126 struct nlattr *grps_attr = cfg->nh_grp;
1127 struct nexthop_grp *entry = nla_data(grps_attr);
1128 u16 num_nh = nla_len(grps_attr) / sizeof(*entry);
1129 struct nh_group *nhg;
1133 if (WARN_ON(!num_nh))
1134 return ERR_PTR(-EINVAL);
1136 nh = nexthop_alloc();
1138 return ERR_PTR(-ENOMEM);
1142 nhg = nexthop_grp_alloc(num_nh);
1145 return ERR_PTR(-ENOMEM);
1148 /* spare group used for removals */
1149 nhg->spare = nexthop_grp_alloc(num_nh);
1155 nhg->spare->spare = nhg;
1157 for (i = 0; i < nhg->num_nh; ++i) {
1158 struct nexthop *nhe;
1159 struct nh_info *nhi;
1161 nhe = nexthop_find_by_id(net, entry[i].id);
1162 if (!nexthop_get(nhe))
1165 nhi = rtnl_dereference(nhe->nh_info);
1166 if (nhi->family == AF_INET)
1169 nhg->nh_entries[i].nh = nhe;
1170 nhg->nh_entries[i].weight = entry[i].weight + 1;
1171 list_add(&nhg->nh_entries[i].nh_list, &nhe->grp_list);
1172 nhg->nh_entries[i].nh_parent = nh;
1175 if (cfg->nh_grp_type == NEXTHOP_GRP_TYPE_MPATH) {
1177 nh_group_rebalance(nhg);
1180 rcu_assign_pointer(nh->nh_grp, nhg);
1185 for (i--; i >= 0; --i) {
1186 list_del(&nhg->nh_entries[i].nh_list);
1187 nexthop_put(nhg->nh_entries[i].nh);
1194 return ERR_PTR(-ENOENT);
1197 static int nh_create_ipv4(struct net *net, struct nexthop *nh,
1198 struct nh_info *nhi, struct nh_config *cfg,
1199 struct netlink_ext_ack *extack)
1201 struct fib_nh *fib_nh = &nhi->fib_nh;
1202 struct fib_config fib_cfg = {
1203 .fc_oif = cfg->nh_ifindex,
1204 .fc_gw4 = cfg->gw.ipv4,
1205 .fc_gw_family = cfg->gw.ipv4 ? AF_INET : 0,
1206 .fc_flags = cfg->nh_flags,
1207 .fc_nlinfo = cfg->nlinfo,
1208 .fc_encap = cfg->nh_encap,
1209 .fc_encap_type = cfg->nh_encap_type,
1211 u32 tb_id = l3mdev_fib_table(cfg->dev);
1214 err = fib_nh_init(net, fib_nh, &fib_cfg, 1, extack);
1216 fib_nh_release(net, fib_nh);
1220 /* sets nh_dev if successful */
1221 err = fib_check_nh(net, fib_nh, tb_id, 0, extack);
1223 nh->nh_flags = fib_nh->fib_nh_flags;
1224 fib_info_update_nhc_saddr(net, &fib_nh->nh_common,
1225 !fib_nh->fib_nh_scope ? 0 : fib_nh->fib_nh_scope - 1);
1227 fib_nh_release(net, fib_nh);
1233 static int nh_create_ipv6(struct net *net, struct nexthop *nh,
1234 struct nh_info *nhi, struct nh_config *cfg,
1235 struct netlink_ext_ack *extack)
1237 struct fib6_nh *fib6_nh = &nhi->fib6_nh;
1238 struct fib6_config fib6_cfg = {
1239 .fc_table = l3mdev_fib_table(cfg->dev),
1240 .fc_ifindex = cfg->nh_ifindex,
1241 .fc_gateway = cfg->gw.ipv6,
1242 .fc_flags = cfg->nh_flags,
1243 .fc_nlinfo = cfg->nlinfo,
1244 .fc_encap = cfg->nh_encap,
1245 .fc_encap_type = cfg->nh_encap_type,
1249 if (!ipv6_addr_any(&cfg->gw.ipv6))
1250 fib6_cfg.fc_flags |= RTF_GATEWAY;
1252 /* sets nh_dev if successful */
1253 err = ipv6_stub->fib6_nh_init(net, fib6_nh, &fib6_cfg, GFP_KERNEL,
1256 /* IPv6 is not enabled, don't call fib6_nh_release */
1257 if (err == -EAFNOSUPPORT)
1259 ipv6_stub->fib6_nh_release(fib6_nh);
1261 nh->nh_flags = fib6_nh->fib_nh_flags;
1267 static struct nexthop *nexthop_create(struct net *net, struct nh_config *cfg,
1268 struct netlink_ext_ack *extack)
1270 struct nh_info *nhi;
1274 nh = nexthop_alloc();
1276 return ERR_PTR(-ENOMEM);
1278 nhi = kzalloc(sizeof(*nhi), GFP_KERNEL);
1281 return ERR_PTR(-ENOMEM);
1284 nh->nh_flags = cfg->nh_flags;
1287 nhi->nh_parent = nh;
1288 nhi->family = cfg->nh_family;
1289 nhi->fib_nhc.nhc_scope = RT_SCOPE_LINK;
1291 if (cfg->nh_blackhole) {
1293 cfg->nh_ifindex = net->loopback_dev->ifindex;
1296 switch (cfg->nh_family) {
1298 err = nh_create_ipv4(net, nh, nhi, cfg, extack);
1301 err = nh_create_ipv6(net, nh, nhi, cfg, extack);
1308 return ERR_PTR(err);
1311 /* add the entry to the device based hash */
1312 nexthop_devhash_add(net, nhi);
1314 rcu_assign_pointer(nh->nh_info, nhi);
1319 /* called with rtnl lock held */
1320 static struct nexthop *nexthop_add(struct net *net, struct nh_config *cfg,
1321 struct netlink_ext_ack *extack)
1326 if (cfg->nlflags & NLM_F_REPLACE && !cfg->nh_id) {
1327 NL_SET_ERR_MSG(extack, "Replace requires nexthop id");
1328 return ERR_PTR(-EINVAL);
1332 cfg->nh_id = nh_find_unused_id(net);
1334 NL_SET_ERR_MSG(extack, "No unused id");
1335 return ERR_PTR(-EINVAL);
1340 nh = nexthop_create_group(net, cfg);
1342 nh = nexthop_create(net, cfg, extack);
1347 refcount_set(&nh->refcnt, 1);
1348 nh->id = cfg->nh_id;
1349 nh->protocol = cfg->nh_protocol;
1352 err = insert_nexthop(net, nh, cfg, extack);
1354 __remove_nexthop(net, nh, NULL);
1362 static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
1363 struct nlmsghdr *nlh, struct nh_config *cfg,
1364 struct netlink_ext_ack *extack)
1366 struct nhmsg *nhm = nlmsg_data(nlh);
1367 struct nlattr *tb[NHA_MAX + 1];
1370 err = nlmsg_parse(nlh, sizeof(*nhm), tb, NHA_MAX, rtm_nh_policy,
1376 if (nhm->resvd || nhm->nh_scope) {
1377 NL_SET_ERR_MSG(extack, "Invalid values in ancillary header");
1380 if (nhm->nh_flags & ~NEXTHOP_VALID_USER_FLAGS) {
1381 NL_SET_ERR_MSG(extack, "Invalid nexthop flags in ancillary header");
1385 switch (nhm->nh_family) {
1394 NL_SET_ERR_MSG(extack, "Invalid address family");
1398 if (tb[NHA_GROUPS] || tb[NHA_MASTER]) {
1399 NL_SET_ERR_MSG(extack, "Invalid attributes in request");
1403 memset(cfg, 0, sizeof(*cfg));
1404 cfg->nlflags = nlh->nlmsg_flags;
1405 cfg->nlinfo.portid = NETLINK_CB(skb).portid;
1406 cfg->nlinfo.nlh = nlh;
1407 cfg->nlinfo.nl_net = net;
1409 cfg->nh_family = nhm->nh_family;
1410 cfg->nh_protocol = nhm->nh_protocol;
1411 cfg->nh_flags = nhm->nh_flags;
1414 cfg->nh_id = nla_get_u32(tb[NHA_ID]);
1416 if (tb[NHA_GROUP]) {
1417 if (nhm->nh_family != AF_UNSPEC) {
1418 NL_SET_ERR_MSG(extack, "Invalid family for group");
1421 cfg->nh_grp = tb[NHA_GROUP];
1423 cfg->nh_grp_type = NEXTHOP_GRP_TYPE_MPATH;
1424 if (tb[NHA_GROUP_TYPE])
1425 cfg->nh_grp_type = nla_get_u16(tb[NHA_GROUP_TYPE]);
1427 if (cfg->nh_grp_type > NEXTHOP_GRP_TYPE_MAX) {
1428 NL_SET_ERR_MSG(extack, "Invalid group type");
1431 err = nh_check_attr_group(net, tb, extack);
1433 /* no other attributes should be set */
1437 if (tb[NHA_BLACKHOLE]) {
1438 if (tb[NHA_GATEWAY] || tb[NHA_OIF] ||
1439 tb[NHA_ENCAP] || tb[NHA_ENCAP_TYPE]) {
1440 NL_SET_ERR_MSG(extack, "Blackhole attribute can not be used with gateway or oif");
1444 cfg->nh_blackhole = 1;
1450 NL_SET_ERR_MSG(extack, "Device attribute required for non-blackhole nexthops");
1454 cfg->nh_ifindex = nla_get_u32(tb[NHA_OIF]);
1455 if (cfg->nh_ifindex)
1456 cfg->dev = __dev_get_by_index(net, cfg->nh_ifindex);
1459 NL_SET_ERR_MSG(extack, "Invalid device index");
1461 } else if (!(cfg->dev->flags & IFF_UP)) {
1462 NL_SET_ERR_MSG(extack, "Nexthop device is not up");
1465 } else if (!netif_carrier_ok(cfg->dev)) {
1466 NL_SET_ERR_MSG(extack, "Carrier for nexthop device is down");
1472 if (tb[NHA_GATEWAY]) {
1473 struct nlattr *gwa = tb[NHA_GATEWAY];
1475 switch (cfg->nh_family) {
1477 if (nla_len(gwa) != sizeof(u32)) {
1478 NL_SET_ERR_MSG(extack, "Invalid gateway");
1481 cfg->gw.ipv4 = nla_get_be32(gwa);
1484 if (nla_len(gwa) != sizeof(struct in6_addr)) {
1485 NL_SET_ERR_MSG(extack, "Invalid gateway");
1488 cfg->gw.ipv6 = nla_get_in6_addr(gwa);
1491 NL_SET_ERR_MSG(extack,
1492 "Unknown address family for gateway");
1496 /* device only nexthop (no gateway) */
1497 if (cfg->nh_flags & RTNH_F_ONLINK) {
1498 NL_SET_ERR_MSG(extack,
1499 "ONLINK flag can not be set for nexthop without a gateway");
1504 if (tb[NHA_ENCAP]) {
1505 cfg->nh_encap = tb[NHA_ENCAP];
1507 if (!tb[NHA_ENCAP_TYPE]) {
1508 NL_SET_ERR_MSG(extack, "LWT encapsulation type is missing");
1512 cfg->nh_encap_type = nla_get_u16(tb[NHA_ENCAP_TYPE]);
1513 err = lwtunnel_valid_encap_type(cfg->nh_encap_type, extack);
1517 } else if (tb[NHA_ENCAP_TYPE]) {
1518 NL_SET_ERR_MSG(extack, "LWT encapsulation attribute is missing");
1529 static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
1530 struct netlink_ext_ack *extack)
1532 struct net *net = sock_net(skb->sk);
1533 struct nh_config cfg;
1537 err = rtm_to_nh_config(net, skb, nlh, &cfg, extack);
1539 nh = nexthop_add(net, &cfg, extack);
1547 static int nh_valid_get_del_req(struct nlmsghdr *nlh, u32 *id,
1548 struct netlink_ext_ack *extack)
1550 struct nhmsg *nhm = nlmsg_data(nlh);
1551 struct nlattr *tb[NHA_MAX + 1];
1554 err = nlmsg_parse(nlh, sizeof(*nhm), tb, NHA_MAX, rtm_nh_policy,
1560 for (i = 0; i < __NHA_MAX; ++i) {
1568 NL_SET_ERR_MSG_ATTR(extack, tb[i],
1569 "Unexpected attribute in request");
1573 if (nhm->nh_protocol || nhm->resvd || nhm->nh_scope || nhm->nh_flags) {
1574 NL_SET_ERR_MSG(extack, "Invalid values in header");
1579 NL_SET_ERR_MSG(extack, "Nexthop id is missing");
1583 *id = nla_get_u32(tb[NHA_ID]);
1585 NL_SET_ERR_MSG(extack, "Invalid nexthop id");
1593 static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
1594 struct netlink_ext_ack *extack)
1596 struct net *net = sock_net(skb->sk);
1597 struct nl_info nlinfo = {
1600 .portid = NETLINK_CB(skb).portid,
1606 err = nh_valid_get_del_req(nlh, &id, extack);
1610 nh = nexthop_find_by_id(net, id);
1614 remove_nexthop(net, nh, &nlinfo);
1620 static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh,
1621 struct netlink_ext_ack *extack)
1623 struct net *net = sock_net(in_skb->sk);
1624 struct sk_buff *skb = NULL;
1629 err = nh_valid_get_del_req(nlh, &id, extack);
1634 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1639 nh = nexthop_find_by_id(net, id);
1643 err = nh_fill_node(skb, nh, RTM_NEWNEXTHOP, NETLINK_CB(in_skb).portid,
1646 WARN_ON(err == -EMSGSIZE);
1650 err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid);
1658 static bool nh_dump_filtered(struct nexthop *nh, int dev_idx, int master_idx,
1659 bool group_filter, u8 family)
1661 const struct net_device *dev;
1662 const struct nh_info *nhi;
1664 if (group_filter && !nh->is_group)
1667 if (!dev_idx && !master_idx && !family)
1673 nhi = rtnl_dereference(nh->nh_info);
1674 if (family && nhi->family != family)
1677 dev = nhi->fib_nhc.nhc_dev;
1678 if (dev_idx && (!dev || dev->ifindex != dev_idx))
1682 struct net_device *master;
1687 master = netdev_master_upper_dev_get((struct net_device *)dev);
1688 if (!master || master->ifindex != master_idx)
1695 static int nh_valid_dump_req(const struct nlmsghdr *nlh, int *dev_idx,
1696 int *master_idx, bool *group_filter,
1697 struct netlink_callback *cb)
1699 struct netlink_ext_ack *extack = cb->extack;
1700 struct nlattr *tb[NHA_MAX + 1];
1705 err = nlmsg_parse(nlh, sizeof(*nhm), tb, NHA_MAX, rtm_nh_policy,
1710 for (i = 0; i <= NHA_MAX; ++i) {
1716 idx = nla_get_u32(tb[i]);
1717 if (idx > INT_MAX) {
1718 NL_SET_ERR_MSG(extack, "Invalid device index");
1724 idx = nla_get_u32(tb[i]);
1725 if (idx > INT_MAX) {
1726 NL_SET_ERR_MSG(extack, "Invalid master device index");
1732 *group_filter = true;
1735 NL_SET_ERR_MSG(extack, "Unsupported attribute in dump request");
1740 nhm = nlmsg_data(nlh);
1741 if (nhm->nh_protocol || nhm->resvd || nhm->nh_scope || nhm->nh_flags) {
1742 NL_SET_ERR_MSG(extack, "Invalid values in header for nexthop dump request");
1750 static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb)
1752 struct nhmsg *nhm = nlmsg_data(cb->nlh);
1753 int dev_filter_idx = 0, master_idx = 0;
1754 struct net *net = sock_net(skb->sk);
1755 struct rb_root *root = &net->nexthop.rb_root;
1756 bool group_filter = false;
1757 struct rb_node *node;
1761 err = nh_valid_dump_req(cb->nlh, &dev_filter_idx, &master_idx,
1766 s_idx = cb->args[0];
1767 for (node = rb_first(root); node; node = rb_next(node)) {
1773 nh = rb_entry(node, struct nexthop, rb_node);
1774 if (nh_dump_filtered(nh, dev_filter_idx, master_idx,
1775 group_filter, nhm->nh_family))
1778 err = nh_fill_node(skb, nh, RTM_NEWNEXTHOP,
1779 NETLINK_CB(cb->skb).portid,
1780 cb->nlh->nlmsg_seq, NLM_F_MULTI);
1782 if (likely(skb->len))
1795 cb->seq = net->nexthop.seq;
1796 nl_dump_check_consistent(cb, nlmsg_hdr(skb));
1801 static void nexthop_sync_mtu(struct net_device *dev, u32 orig_mtu)
1803 unsigned int hash = nh_dev_hashfn(dev->ifindex);
1804 struct net *net = dev_net(dev);
1805 struct hlist_head *head = &net->nexthop.devhash[hash];
1806 struct hlist_node *n;
1807 struct nh_info *nhi;
1809 hlist_for_each_entry_safe(nhi, n, head, dev_hash) {
1810 if (nhi->fib_nhc.nhc_dev == dev) {
1811 if (nhi->family == AF_INET)
1812 fib_nhc_update_mtu(&nhi->fib_nhc, dev->mtu,
1819 static int nh_netdev_event(struct notifier_block *this,
1820 unsigned long event, void *ptr)
1822 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1823 struct netdev_notifier_info_ext *info_ext;
1827 case NETDEV_UNREGISTER:
1828 nexthop_flush_dev(dev, event);
1831 if (!(dev_get_flags(dev) & (IFF_RUNNING | IFF_LOWER_UP)))
1832 nexthop_flush_dev(dev, event);
1834 case NETDEV_CHANGEMTU:
1836 nexthop_sync_mtu(dev, info_ext->ext.mtu);
1837 rt_cache_flush(dev_net(dev));
1843 static struct notifier_block nh_netdev_notifier = {
1844 .notifier_call = nh_netdev_event,
1847 static void __net_exit nexthop_net_exit(struct net *net)
1850 flush_all_nexthops(net);
1852 kfree(net->nexthop.devhash);
1855 static int __net_init nexthop_net_init(struct net *net)
1857 size_t sz = sizeof(struct hlist_head) * NH_DEV_HASHSIZE;
1859 net->nexthop.rb_root = RB_ROOT;
1860 net->nexthop.devhash = kzalloc(sz, GFP_KERNEL);
1861 if (!net->nexthop.devhash)
1867 static struct pernet_operations nexthop_net_ops = {
1868 .init = nexthop_net_init,
1869 .exit = nexthop_net_exit,
1872 static int __init nexthop_init(void)
1874 register_pernet_subsys(&nexthop_net_ops);
1876 register_netdevice_notifier(&nh_netdev_notifier);
1878 rtnl_register(PF_UNSPEC, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
1879 rtnl_register(PF_UNSPEC, RTM_DELNEXTHOP, rtm_del_nexthop, NULL, 0);
1880 rtnl_register(PF_UNSPEC, RTM_GETNEXTHOP, rtm_get_nexthop,
1881 rtm_dump_nexthop, 0);
1883 rtnl_register(PF_INET, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
1884 rtnl_register(PF_INET, RTM_GETNEXTHOP, NULL, rtm_dump_nexthop, 0);
1886 rtnl_register(PF_INET6, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
1887 rtnl_register(PF_INET6, RTM_GETNEXTHOP, NULL, rtm_dump_nexthop, 0);
1891 subsys_initcall(nexthop_init);