2 * net/switchdev/switchdev.c - Switch device API
3 * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
4 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/init.h>
15 #include <linux/mutex.h>
16 #include <linux/notifier.h>
17 #include <linux/netdevice.h>
18 #include <linux/if_bridge.h>
19 #include <net/ip_fib.h>
20 #include <net/switchdev.h>
23 * switchdev_port_attr_get - Get port attribute
26 * @attr: attribute to get
28 int switchdev_port_attr_get(struct net_device
*dev
, struct switchdev_attr
*attr
)
30 const struct switchdev_ops
*ops
= dev
->switchdev_ops
;
31 struct net_device
*lower_dev
;
32 struct list_head
*iter
;
33 struct switchdev_attr first
= {
34 .id
= SWITCHDEV_ATTR_UNDEFINED
36 int err
= -EOPNOTSUPP
;
38 if (ops
&& ops
->switchdev_port_attr_get
)
39 return ops
->switchdev_port_attr_get(dev
, attr
);
41 if (attr
->flags
& SWITCHDEV_F_NO_RECURSE
)
44 /* Switch device port(s) may be stacked under
45 * bond/team/vlan dev, so recurse down to get attr on
46 * each port. Return -ENODATA if attr values don't
47 * compare across ports.
50 netdev_for_each_lower_dev(dev
, lower_dev
, iter
) {
51 err
= switchdev_port_attr_get(lower_dev
, attr
);
54 if (first
.id
== SWITCHDEV_ATTR_UNDEFINED
)
56 else if (memcmp(&first
, attr
, sizeof(*attr
)))
62 EXPORT_SYMBOL_GPL(switchdev_port_attr_get
);
64 static int __switchdev_port_attr_set(struct net_device
*dev
,
65 struct switchdev_attr
*attr
)
67 const struct switchdev_ops
*ops
= dev
->switchdev_ops
;
68 struct net_device
*lower_dev
;
69 struct list_head
*iter
;
70 int err
= -EOPNOTSUPP
;
72 if (ops
&& ops
->switchdev_port_attr_set
)
73 return ops
->switchdev_port_attr_set(dev
, attr
);
75 if (attr
->flags
& SWITCHDEV_F_NO_RECURSE
)
78 /* Switch device port(s) may be stacked under
79 * bond/team/vlan dev, so recurse down to set attr on
83 netdev_for_each_lower_dev(dev
, lower_dev
, iter
) {
84 err
= __switchdev_port_attr_set(lower_dev
, attr
);
92 struct switchdev_attr_set_work
{
93 struct work_struct work
;
94 struct net_device
*dev
;
95 struct switchdev_attr attr
;
98 static void switchdev_port_attr_set_work(struct work_struct
*work
)
100 struct switchdev_attr_set_work
*asw
=
101 container_of(work
, struct switchdev_attr_set_work
, work
);
105 err
= switchdev_port_attr_set(asw
->dev
, &asw
->attr
);
106 if (err
&& err
!= -EOPNOTSUPP
)
107 netdev_err(asw
->dev
, "failed (err=%d) to set attribute (id=%d)\n",
115 static int switchdev_port_attr_set_defer(struct net_device
*dev
,
116 struct switchdev_attr
*attr
)
118 struct switchdev_attr_set_work
*asw
;
120 asw
= kmalloc(sizeof(*asw
), GFP_ATOMIC
);
124 INIT_WORK(&asw
->work
, switchdev_port_attr_set_work
);
128 memcpy(&asw
->attr
, attr
, sizeof(asw
->attr
));
130 schedule_work(&asw
->work
);
136 * switchdev_port_attr_set - Set port attribute
139 * @attr: attribute to set
141 * Use a 2-phase prepare-commit transaction model to ensure
142 * system is not left in a partially updated state due to
143 * failure from driver/device.
145 int switchdev_port_attr_set(struct net_device
*dev
, struct switchdev_attr
*attr
)
149 if (!rtnl_is_locked()) {
150 /* Running prepare-commit transaction across stacked
151 * devices requires nothing moves, so if rtnl_lock is
152 * not held, schedule a worker thread to hold rtnl_lock
153 * while setting attr.
156 return switchdev_port_attr_set_defer(dev
, attr
);
159 /* Phase I: prepare for attr set. Driver/device should fail
160 * here if there are going to be issues in the commit phase,
161 * such as lack of resources or support. The driver/device
162 * should reserve resources needed for the commit phase here,
163 * but should not commit the attr.
166 attr
->trans
= SWITCHDEV_TRANS_PREPARE
;
167 err
= __switchdev_port_attr_set(dev
, attr
);
169 /* Prepare phase failed: abort the transaction. Any
170 * resources reserved in the prepare phase are
174 attr
->trans
= SWITCHDEV_TRANS_ABORT
;
175 __switchdev_port_attr_set(dev
, attr
);
180 /* Phase II: commit attr set. This cannot fail as a fault
181 * of driver/device. If it does, it's a bug in the driver/device
182 * because the driver said everythings was OK in phase I.
185 attr
->trans
= SWITCHDEV_TRANS_COMMIT
;
186 err
= __switchdev_port_attr_set(dev
, attr
);
191 EXPORT_SYMBOL_GPL(switchdev_port_attr_set
);
193 static int __switchdev_port_obj_add(struct net_device
*dev
,
194 struct switchdev_obj
*obj
)
196 const struct switchdev_ops
*ops
= dev
->switchdev_ops
;
197 struct net_device
*lower_dev
;
198 struct list_head
*iter
;
199 int err
= -EOPNOTSUPP
;
201 if (ops
&& ops
->switchdev_port_obj_add
)
202 return ops
->switchdev_port_obj_add(dev
, obj
);
204 /* Switch device port(s) may be stacked under
205 * bond/team/vlan dev, so recurse down to add object on
209 netdev_for_each_lower_dev(dev
, lower_dev
, iter
) {
210 err
= __switchdev_port_obj_add(lower_dev
, obj
);
219 * switchdev_port_obj_add - Add port object
222 * @obj: object to add
224 * Use a 2-phase prepare-commit transaction model to ensure
225 * system is not left in a partially updated state due to
226 * failure from driver/device.
228 * rtnl_lock must be held.
230 int switchdev_port_obj_add(struct net_device
*dev
, struct switchdev_obj
*obj
)
236 /* Phase I: prepare for obj add. Driver/device should fail
237 * here if there are going to be issues in the commit phase,
238 * such as lack of resources or support. The driver/device
239 * should reserve resources needed for the commit phase here,
240 * but should not commit the obj.
243 obj
->trans
= SWITCHDEV_TRANS_PREPARE
;
244 err
= __switchdev_port_obj_add(dev
, obj
);
246 /* Prepare phase failed: abort the transaction. Any
247 * resources reserved in the prepare phase are
251 obj
->trans
= SWITCHDEV_TRANS_ABORT
;
252 __switchdev_port_obj_add(dev
, obj
);
257 /* Phase II: commit obj add. This cannot fail as a fault
258 * of driver/device. If it does, it's a bug in the driver/device
259 * because the driver said everythings was OK in phase I.
262 obj
->trans
= SWITCHDEV_TRANS_COMMIT
;
263 err
= __switchdev_port_obj_add(dev
, obj
);
264 WARN(err
, "%s: Commit of object (id=%d) failed.\n", dev
->name
, obj
->id
);
268 EXPORT_SYMBOL_GPL(switchdev_port_obj_add
);
271 * switchdev_port_obj_del - Delete port object
274 * @obj: object to delete
276 int switchdev_port_obj_del(struct net_device
*dev
, struct switchdev_obj
*obj
)
278 const struct switchdev_ops
*ops
= dev
->switchdev_ops
;
279 struct net_device
*lower_dev
;
280 struct list_head
*iter
;
281 int err
= -EOPNOTSUPP
;
283 if (ops
&& ops
->switchdev_port_obj_del
)
284 return ops
->switchdev_port_obj_del(dev
, obj
);
286 /* Switch device port(s) may be stacked under
287 * bond/team/vlan dev, so recurse down to delete object on
291 netdev_for_each_lower_dev(dev
, lower_dev
, iter
) {
292 err
= switchdev_port_obj_del(lower_dev
, obj
);
299 EXPORT_SYMBOL_GPL(switchdev_port_obj_del
);
302 * switchdev_port_obj_dump - Dump port objects
305 * @obj: object to dump
307 int switchdev_port_obj_dump(struct net_device
*dev
, struct switchdev_obj
*obj
)
309 const struct switchdev_ops
*ops
= dev
->switchdev_ops
;
310 struct net_device
*lower_dev
;
311 struct list_head
*iter
;
312 int err
= -EOPNOTSUPP
;
314 if (ops
&& ops
->switchdev_port_obj_dump
)
315 return ops
->switchdev_port_obj_dump(dev
, obj
);
317 /* Switch device port(s) may be stacked under
318 * bond/team/vlan dev, so recurse down to dump objects on
319 * first port at bottom of stack.
322 netdev_for_each_lower_dev(dev
, lower_dev
, iter
) {
323 err
= switchdev_port_obj_dump(lower_dev
, obj
);
329 EXPORT_SYMBOL_GPL(switchdev_port_obj_dump
);
331 static DEFINE_MUTEX(switchdev_mutex
);
332 static RAW_NOTIFIER_HEAD(switchdev_notif_chain
);
335 * register_switchdev_notifier - Register notifier
336 * @nb: notifier_block
338 * Register switch device notifier. This should be used by code
339 * which needs to monitor events happening in particular device.
340 * Return values are same as for atomic_notifier_chain_register().
342 int register_switchdev_notifier(struct notifier_block
*nb
)
346 mutex_lock(&switchdev_mutex
);
347 err
= raw_notifier_chain_register(&switchdev_notif_chain
, nb
);
348 mutex_unlock(&switchdev_mutex
);
351 EXPORT_SYMBOL_GPL(register_switchdev_notifier
);
354 * unregister_switchdev_notifier - Unregister notifier
355 * @nb: notifier_block
357 * Unregister switch device notifier.
358 * Return values are same as for atomic_notifier_chain_unregister().
360 int unregister_switchdev_notifier(struct notifier_block
*nb
)
364 mutex_lock(&switchdev_mutex
);
365 err
= raw_notifier_chain_unregister(&switchdev_notif_chain
, nb
);
366 mutex_unlock(&switchdev_mutex
);
369 EXPORT_SYMBOL_GPL(unregister_switchdev_notifier
);
372 * call_switchdev_notifiers - Call notifiers
373 * @val: value passed unmodified to notifier function
375 * @info: notifier information data
377 * Call all network notifier blocks. This should be called by driver
378 * when it needs to propagate hardware event.
379 * Return values are same as for atomic_notifier_call_chain().
381 int call_switchdev_notifiers(unsigned long val
, struct net_device
*dev
,
382 struct switchdev_notifier_info
*info
)
387 mutex_lock(&switchdev_mutex
);
388 err
= raw_notifier_call_chain(&switchdev_notif_chain
, val
, info
);
389 mutex_unlock(&switchdev_mutex
);
392 EXPORT_SYMBOL_GPL(call_switchdev_notifiers
);
395 * switchdev_port_bridge_getlink - Get bridge port attributes
399 * Called for SELF on rtnl_bridge_getlink to get bridge port
402 int switchdev_port_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
403 struct net_device
*dev
, u32 filter_mask
,
406 struct switchdev_attr attr
= {
407 .id
= SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS
,
409 u16 mode
= BRIDGE_MODE_UNDEF
;
410 u32 mask
= BR_LEARNING
| BR_LEARNING_SYNC
;
413 err
= switchdev_port_attr_get(dev
, &attr
);
417 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, mode
,
418 attr
.u
.brport_flags
, mask
, nlflags
);
420 EXPORT_SYMBOL_GPL(switchdev_port_bridge_getlink
);
422 static int switchdev_port_br_setflag(struct net_device
*dev
,
423 struct nlattr
*nlattr
,
424 unsigned long brport_flag
)
426 struct switchdev_attr attr
= {
427 .id
= SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS
,
429 u8 flag
= nla_get_u8(nlattr
);
432 err
= switchdev_port_attr_get(dev
, &attr
);
437 attr
.u
.brport_flags
|= brport_flag
;
439 attr
.u
.brport_flags
&= ~brport_flag
;
441 return switchdev_port_attr_set(dev
, &attr
);
444 static const struct nla_policy
445 switchdev_port_bridge_policy
[IFLA_BRPORT_MAX
+ 1] = {
446 [IFLA_BRPORT_STATE
] = { .type
= NLA_U8
},
447 [IFLA_BRPORT_COST
] = { .type
= NLA_U32
},
448 [IFLA_BRPORT_PRIORITY
] = { .type
= NLA_U16
},
449 [IFLA_BRPORT_MODE
] = { .type
= NLA_U8
},
450 [IFLA_BRPORT_GUARD
] = { .type
= NLA_U8
},
451 [IFLA_BRPORT_PROTECT
] = { .type
= NLA_U8
},
452 [IFLA_BRPORT_FAST_LEAVE
] = { .type
= NLA_U8
},
453 [IFLA_BRPORT_LEARNING
] = { .type
= NLA_U8
},
454 [IFLA_BRPORT_LEARNING_SYNC
] = { .type
= NLA_U8
},
455 [IFLA_BRPORT_UNICAST_FLOOD
] = { .type
= NLA_U8
},
458 static int switchdev_port_br_setlink_protinfo(struct net_device
*dev
,
459 struct nlattr
*protinfo
)
465 err
= nla_validate_nested(protinfo
, IFLA_BRPORT_MAX
,
466 switchdev_port_bridge_policy
);
470 nla_for_each_nested(attr
, protinfo
, rem
) {
471 switch (nla_type(attr
)) {
472 case IFLA_BRPORT_LEARNING
:
473 err
= switchdev_port_br_setflag(dev
, attr
,
476 case IFLA_BRPORT_LEARNING_SYNC
:
477 err
= switchdev_port_br_setflag(dev
, attr
,
491 static int switchdev_port_br_afspec(struct net_device
*dev
,
492 struct nlattr
*afspec
,
493 int (*f
)(struct net_device
*dev
,
494 struct switchdev_obj
*obj
))
497 struct bridge_vlan_info
*vinfo
;
498 struct switchdev_obj obj
= {
499 .id
= SWITCHDEV_OBJ_PORT_VLAN
,
501 struct switchdev_obj_vlan
*vlan
= &obj
.u
.vlan
;
505 nla_for_each_nested(attr
, afspec
, rem
) {
506 if (nla_type(attr
) != IFLA_BRIDGE_VLAN_INFO
)
508 if (nla_len(attr
) != sizeof(struct bridge_vlan_info
))
510 vinfo
= nla_data(attr
);
511 vlan
->flags
= vinfo
->flags
;
512 if (vinfo
->flags
& BRIDGE_VLAN_INFO_RANGE_BEGIN
) {
515 vlan
->vid_begin
= vinfo
->vid
;
516 } else if (vinfo
->flags
& BRIDGE_VLAN_INFO_RANGE_END
) {
517 if (!vlan
->vid_begin
)
519 vlan
->vid_end
= vinfo
->vid
;
520 if (vlan
->vid_end
<= vlan
->vid_begin
)
525 memset(vlan
, 0, sizeof(*vlan
));
529 vlan
->vid_begin
= vinfo
->vid
;
530 vlan
->vid_end
= vinfo
->vid
;
534 memset(vlan
, 0, sizeof(*vlan
));
542 * switchdev_port_bridge_setlink - Set bridge port attributes
545 * @nlh: netlink header
546 * @flags: netlink flags
548 * Called for SELF on rtnl_bridge_setlink to set bridge port
551 int switchdev_port_bridge_setlink(struct net_device
*dev
,
552 struct nlmsghdr
*nlh
, u16 flags
)
554 struct nlattr
*protinfo
;
555 struct nlattr
*afspec
;
558 protinfo
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
),
561 err
= switchdev_port_br_setlink_protinfo(dev
, protinfo
);
566 afspec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
),
569 err
= switchdev_port_br_afspec(dev
, afspec
,
570 switchdev_port_obj_add
);
574 EXPORT_SYMBOL_GPL(switchdev_port_bridge_setlink
);
577 * switchdev_port_bridge_dellink - Set bridge port attributes
580 * @nlh: netlink header
581 * @flags: netlink flags
583 * Called for SELF on rtnl_bridge_dellink to set bridge port
586 int switchdev_port_bridge_dellink(struct net_device
*dev
,
587 struct nlmsghdr
*nlh
, u16 flags
)
589 struct nlattr
*afspec
;
591 afspec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
),
594 return switchdev_port_br_afspec(dev
, afspec
,
595 switchdev_port_obj_del
);
599 EXPORT_SYMBOL_GPL(switchdev_port_bridge_dellink
);
602 * switchdev_port_fdb_add - Add FDB (MAC/VLAN) entry to port
604 * @ndmsg: netlink hdr
605 * @nlattr: netlink attributes
607 * @addr: MAC address to add
610 * Add FDB entry to switch device.
612 int switchdev_port_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
613 struct net_device
*dev
, const unsigned char *addr
,
614 u16 vid
, u16 nlm_flags
)
616 struct switchdev_obj obj
= {
617 .id
= SWITCHDEV_OBJ_PORT_FDB
,
624 return switchdev_port_obj_add(dev
, &obj
);
626 EXPORT_SYMBOL_GPL(switchdev_port_fdb_add
);
629 * switchdev_port_fdb_del - Delete FDB (MAC/VLAN) entry from port
631 * @ndmsg: netlink hdr
632 * @nlattr: netlink attributes
634 * @addr: MAC address to delete
635 * @vid: VLAN to delete
637 * Delete FDB entry from switch device.
639 int switchdev_port_fdb_del(struct ndmsg
*ndm
, struct nlattr
*tb
[],
640 struct net_device
*dev
, const unsigned char *addr
,
643 struct switchdev_obj obj
= {
644 .id
= SWITCHDEV_OBJ_PORT_FDB
,
651 return switchdev_port_obj_del(dev
, &obj
);
653 EXPORT_SYMBOL_GPL(switchdev_port_fdb_del
);
655 struct switchdev_fdb_dump
{
656 struct switchdev_obj obj
;
658 struct netlink_callback
*cb
;
662 static int switchdev_port_fdb_dump_cb(struct net_device
*dev
,
663 struct switchdev_obj
*obj
)
665 struct switchdev_fdb_dump
*dump
=
666 container_of(obj
, struct switchdev_fdb_dump
, obj
);
667 u32 portid
= NETLINK_CB(dump
->cb
->skb
).portid
;
668 u32 seq
= dump
->cb
->nlh
->nlmsg_seq
;
669 struct nlmsghdr
*nlh
;
672 if (dump
->idx
< dump
->cb
->args
[0])
675 nlh
= nlmsg_put(dump
->skb
, portid
, seq
, RTM_NEWNEIGH
,
676 sizeof(*ndm
), NLM_F_MULTI
);
680 ndm
= nlmsg_data(nlh
);
681 ndm
->ndm_family
= AF_BRIDGE
;
684 ndm
->ndm_flags
= NTF_SELF
;
686 ndm
->ndm_ifindex
= dev
->ifindex
;
687 ndm
->ndm_state
= NUD_REACHABLE
;
689 if (nla_put(dump
->skb
, NDA_LLADDR
, ETH_ALEN
, obj
->u
.fdb
.addr
))
690 goto nla_put_failure
;
692 if (obj
->u
.fdb
.vid
&& nla_put_u16(dump
->skb
, NDA_VLAN
, obj
->u
.fdb
.vid
))
693 goto nla_put_failure
;
695 nlmsg_end(dump
->skb
, nlh
);
702 nlmsg_cancel(dump
->skb
, nlh
);
707 * switchdev_port_fdb_dump - Dump port FDB (MAC/VLAN) entries
710 * @cb: netlink callback
712 * @filter_dev: filter device
715 * Delete FDB entry from switch device.
717 int switchdev_port_fdb_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
,
718 struct net_device
*dev
,
719 struct net_device
*filter_dev
, int idx
)
721 struct switchdev_fdb_dump dump
= {
723 .id
= SWITCHDEV_OBJ_PORT_FDB
,
724 .cb
= switchdev_port_fdb_dump_cb
,
732 err
= switchdev_port_obj_dump(dev
, &dump
.obj
);
738 EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump
);
740 static struct net_device
*switchdev_get_lowest_dev(struct net_device
*dev
)
742 const struct switchdev_ops
*ops
= dev
->switchdev_ops
;
743 struct net_device
*lower_dev
;
744 struct net_device
*port_dev
;
745 struct list_head
*iter
;
747 /* Recusively search down until we find a sw port dev.
748 * (A sw port dev supports switchdev_port_attr_get).
751 if (ops
&& ops
->switchdev_port_attr_get
)
754 netdev_for_each_lower_dev(dev
, lower_dev
, iter
) {
755 port_dev
= switchdev_get_lowest_dev(lower_dev
);
763 static struct net_device
*switchdev_get_dev_by_nhs(struct fib_info
*fi
)
765 struct switchdev_attr attr
= {
766 .id
= SWITCHDEV_ATTR_PORT_PARENT_ID
,
768 struct switchdev_attr prev_attr
;
769 struct net_device
*dev
= NULL
;
772 /* For this route, all nexthop devs must be on the same switch. */
774 for (nhsel
= 0; nhsel
< fi
->fib_nhs
; nhsel
++) {
775 const struct fib_nh
*nh
= &fi
->fib_nh
[nhsel
];
780 dev
= switchdev_get_lowest_dev(nh
->nh_dev
);
784 if (switchdev_port_attr_get(dev
, &attr
))
788 if (prev_attr
.u
.ppid
.id_len
!= attr
.u
.ppid
.id_len
)
790 if (memcmp(prev_attr
.u
.ppid
.id
, attr
.u
.ppid
.id
,
802 * switchdev_fib_ipv4_add - Add/modify switch IPv4 route entry
804 * @dst: route's IPv4 destination address
805 * @dst_len: destination address length (prefix length)
806 * @fi: route FIB info structure
809 * @nlflags: netlink flags passed in (NLM_F_*)
810 * @tb_id: route table ID
812 * Add/modify switch IPv4 route entry.
814 int switchdev_fib_ipv4_add(u32 dst
, int dst_len
, struct fib_info
*fi
,
815 u8 tos
, u8 type
, u32 nlflags
, u32 tb_id
)
817 struct switchdev_obj fib_obj
= {
818 .id
= SWITCHDEV_OBJ_IPV4_FIB
,
829 struct net_device
*dev
;
832 /* Don't offload route if using custom ip rules or if
833 * IPv4 FIB offloading has been disabled completely.
836 #ifdef CONFIG_IP_MULTIPLE_TABLES
837 if (fi
->fib_net
->ipv4
.fib_has_custom_rules
)
841 if (fi
->fib_net
->ipv4
.fib_offload_disabled
)
844 dev
= switchdev_get_dev_by_nhs(fi
);
848 err
= switchdev_port_obj_add(dev
, &fib_obj
);
850 fi
->fib_flags
|= RTNH_F_OFFLOAD
;
852 return err
== -EOPNOTSUPP
? 0 : err
;
854 EXPORT_SYMBOL_GPL(switchdev_fib_ipv4_add
);
857 * switchdev_fib_ipv4_del - Delete IPv4 route entry from switch
859 * @dst: route's IPv4 destination address
860 * @dst_len: destination address length (prefix length)
861 * @fi: route FIB info structure
864 * @tb_id: route table ID
866 * Delete IPv4 route entry from switch device.
868 int switchdev_fib_ipv4_del(u32 dst
, int dst_len
, struct fib_info
*fi
,
869 u8 tos
, u8 type
, u32 tb_id
)
871 struct switchdev_obj fib_obj
= {
872 .id
= SWITCHDEV_OBJ_IPV4_FIB
,
883 struct net_device
*dev
;
886 if (!(fi
->fib_flags
& RTNH_F_OFFLOAD
))
889 dev
= switchdev_get_dev_by_nhs(fi
);
893 err
= switchdev_port_obj_del(dev
, &fib_obj
);
895 fi
->fib_flags
&= ~RTNH_F_OFFLOAD
;
897 return err
== -EOPNOTSUPP
? 0 : err
;
899 EXPORT_SYMBOL_GPL(switchdev_fib_ipv4_del
);
902 * switchdev_fib_ipv4_abort - Abort an IPv4 FIB operation
904 * @fi: route FIB info structure
906 void switchdev_fib_ipv4_abort(struct fib_info
*fi
)
908 /* There was a problem installing this route to the offload
909 * device. For now, until we come up with more refined
910 * policy handling, abruptly end IPv4 fib offloading for
911 * for entire net by flushing offload device(s) of all
912 * IPv4 routes, and mark IPv4 fib offloading broken from
913 * this point forward.
916 fib_flush_external(fi
->fib_net
);
917 fi
->fib_net
->ipv4
.fib_offload_disabled
= true;
919 EXPORT_SYMBOL_GPL(switchdev_fib_ipv4_abort
);