11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/module.h>
15 #include <linux/slab.h>
17 #include <linux/errno.h>
18 #include <linux/ctype.h>
20 #include <linux/netdevice.h>
22 #include <linux/if_vlan.h>
23 #include <linux/if_arp.h>
24 #include <linux/socket.h>
26 #include <linux/rtnetlink.h>
31 #include <linux/if_team.h>
33 #define DRV_NAME "team"
40 #define team_port_exists(dev) (dev->priv_flags & IFF_TEAM_PORT)
70 static int team_port_set_orig_dev_addr(
struct team_port *
port)
72 return __set_port_dev_addr(port->
dev, port->
orig.dev_addr);
77 return __set_port_dev_addr(port->
dev, port->
team->dev->dev_addr);
102 const char *opt_name)
119 static void __team_option_inst_del_option(
struct team *
team,
125 if (opt_inst->
option == option)
126 __team_option_inst_del(opt_inst);
130 static int __team_option_inst_add(
struct team *team,
struct team_option *option,
134 unsigned int array_size;
142 for (i = 0; i < array_size; i++) {
148 opt_inst->
info.array_index =
i;
153 err = option->
init(team, &opt_inst->
info);
162 static int __team_option_inst_add_option(
struct team *team,
169 err = __team_option_inst_add(team, option,
NULL);
171 goto inst_del_option;
175 err = __team_option_inst_add(team, option, port);
177 goto inst_del_option;
182 __team_option_inst_del_option(team, option);
186 static void __team_option_inst_mark_removed_option(
struct team *team,
192 if (opt_inst->
option == option) {
199 static void __team_option_inst_del_port(
struct team *team,
205 if (opt_inst->
option->per_port &&
206 opt_inst->
info.port == port)
207 __team_option_inst_del(opt_inst);
211 static int __team_option_inst_add_port(
struct team *team,
220 err = __team_option_inst_add(team, option, port);
227 __team_option_inst_del_port(team, port);
231 static void __team_option_inst_mark_removed_port(
struct team *team,
237 if (opt_inst->
info.port == port) {
244 static int __team_options_register(
struct team *team,
252 dst_opts = kzalloc(
sizeof(
struct team_option *) * option_count,
256 for (i = 0; i < option_count; i++, option++) {
257 if (__team_find_option(team, option->
name)) {
268 for (i = 0; i < option_count; i++) {
269 err = __team_option_inst_add_option(team, dst_opts[i]);
279 for (i--; i >= 0; i--)
280 __team_option_inst_del_option(team, dst_opts[i]);
282 i = option_count - 1;
284 for (i--; i >= 0; i--)
291 static void __team_options_mark_removed(
struct team *team,
297 for (i = 0; i < option_count; i++, option++) {
300 del_opt = __team_find_option(team, option->
name);
302 __team_option_inst_mark_removed_option(team, del_opt);
306 static void __team_options_unregister(
struct team *team,
312 for (i = 0; i < option_count; i++, option++) {
315 del_opt = __team_find_option(team, option->
name);
317 __team_option_inst_del_option(team, del_opt);
324 static void __team_options_change_check(
struct team *team);
332 err = __team_options_register(team, option, option_count);
335 __team_options_change_check(team);
344 __team_options_mark_removed(team, option, option_count);
345 __team_options_change_check(team);
346 __team_options_unregister(team, option, option_count);
350 static int team_option_get(
struct team *team,
354 if (!opt_inst->
option->getter)
356 return opt_inst->
option->getter(team, ctx);
359 static int team_option_set(
struct team *team,
363 if (!opt_inst->
option->setter)
365 return opt_inst->
option->setter(team, ctx);
379 __team_options_change_check(team);
407 static bool is_good_mode_name(
const char *
name)
409 while (*name !=
'\0') {
422 if (!is_good_mode_name(mode->
kind) ||
430 spin_lock(&mode_list_lock);
431 if (__find_mode(mode->
kind)) {
439 spin_unlock(&mode_list_lock);
448 spin_lock(&mode_list_lock);
449 mitem = __find_mode(mode->
kind);
451 list_del_init(&mitem->
list);
454 spin_unlock(&mode_list_lock);
458 static const struct team_mode *team_mode_get(
const char *
kind)
463 spin_lock(&mode_list_lock);
464 mitem = __find_mode(kind);
466 spin_unlock(&mode_list_lock);
467 request_module(
"team-mode-%s", kind);
468 spin_lock(&mode_list_lock);
469 mitem = __find_mode(kind);
473 if (!try_module_get(mode->
owner))
477 spin_unlock(&mode_list_lock);
481 static void team_mode_put(
const struct team_mode *mode)
483 module_put(mode->
owner);
486 static bool team_dummy_transmit(
struct team *team,
struct sk_buff *
skb)
499 static const struct team_mode __team_no_mode = {
503 static bool team_is_mode_set(
struct team *team)
505 return team->
mode != &__team_no_mode;
508 static void team_set_no_mode(
struct team *team)
510 team->
mode = &__team_no_mode;
513 static void __team_adjust_ops(
struct team *team,
int en_port_count)
520 if (!en_port_count || !team_is_mode_set(team) ||
521 !team->
mode->ops->transmit)
522 team->
ops.transmit = team_dummy_transmit;
524 team->
ops.transmit = team->
mode->ops->transmit;
526 if (!en_port_count || !team_is_mode_set(team) ||
527 !team->
mode->ops->receive)
530 team->
ops.receive = team->
mode->ops->receive;
533 static void team_adjust_ops(
struct team *team)
543 static int __team_change_mode(
struct team *team,
547 if (team_is_mode_set(team)) {
548 void (*exit_op)(
struct team *team) = team->
ops.exit;
552 team_adjust_ops(team);
556 team_mode_put(team->
mode);
557 team_set_no_mode(team);
566 if (new_mode->
ops->init) {
569 err = new_mode->
ops->init(team);
574 team->
mode = new_mode;
576 team_adjust_ops(team);
581 static int team_change_mode(
struct team *team,
const char *kind)
588 netdev_err(dev,
"No ports can be present during mode change\n");
592 if (team_is_mode_set(team) &&
strcmp(team->
mode->kind, kind) == 0) {
593 netdev_err(dev,
"Unable to change to the same mode the team is in\n");
597 new_mode = team_mode_get(kind);
599 netdev_err(dev,
"Mode \"%s\" not found\n", kind);
603 err = __team_change_mode(team, new_mode);
605 netdev_err(dev,
"Failed to change to mode \"%s\"\n", kind);
606 team_mode_put(new_mode);
610 netdev_info(dev,
"Mode changed to \"%s\"\n", kind);
633 port = team_port_get_rcu(skb->
dev);
635 if (!team_port_enabled(port)) {
639 res = team->
ops.receive(team, port, skb);
645 u64_stats_update_begin(&pcpu_stats->
syncp);
650 u64_stats_update_end(&pcpu_stats->
syncp);
665 static int team_queue_override_init(
struct team *team)
668 unsigned int queue_cnt = team->
dev->num_tx_queues - 1;
677 for (i = 0; i < queue_cnt; i++)
678 INIT_LIST_HEAD(listarr++);
682 static void team_queue_override_fini(
struct team *team)
687 static struct list_head *__team_get_qom_list(
struct team *team,
u16 queue_id)
695 static bool team_queue_override_transmit(
struct team *team,
struct sk_buff *skb)
703 list_for_each_entry_rcu(port, qom_list, qom_list) {
704 if (!team_dev_queue_xmit(team, port, skb))
710 static void __team_queue_override_port_del(
struct team *team,
718 static bool team_queue_override_port_has_gt_prio_than(
struct team_port *port,
730 static void __team_queue_override_port_add(
struct team *team,
737 if (!port->
queue_id || !team_port_enabled(port))
740 qom_list = __team_get_qom_list(team, port->
queue_id);
743 if (team_queue_override_port_has_gt_prio_than(port, cur))
747 list_add_tail_rcu(&port->
qom_list, node);
750 static void __team_queue_override_enabled_check(
struct team *team)
764 enabled ?
"Enabling" :
"Disabling");
768 static void team_queue_override_port_refresh(
struct team *team,
771 __team_queue_override_port_del(team, port);
772 __team_queue_override_port_add(team, port);
773 __team_queue_override_enabled_check(team);
781 static bool team_port_find(
const struct team *team,
798 static
void team_port_enable(
struct team *team,
801 if (team_port_enabled(port))
803 port->index = team->en_port_count++;
804 hlist_add_head_rcu(&port->hlist,
805 team_port_index_hash(team, port->index));
806 team_adjust_ops(team);
807 team_queue_override_port_refresh(team, port);
808 if (team->ops.port_enabled)
809 team->ops.port_enabled(team, port);
812 static void __reconstruct_port_hlist(
struct team *team,
int rm_index)
818 port = team_get_port_by_index(team, i);
819 hlist_del_rcu(&port->
hlist);
821 hlist_add_head_rcu(&port->
hlist,
822 team_port_index_hash(team, port->
index));
826 static void team_port_disable(
struct team *team,
829 if (!team_port_enabled(port))
831 if (team->
ops.port_disabled)
832 team->
ops.port_disabled(team, port);
833 hlist_del_rcu(&port->
hlist);
834 __reconstruct_port_hlist(team, port->
index);
836 team_queue_override_port_refresh(team, port);
846 #define TEAM_VLAN_FEATURES (NETIF_F_ALL_CSUM | NETIF_F_SG | \
847 NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \
848 NETIF_F_HIGHDMA | NETIF_F_LRO)
850 static void __team_compute_features(
struct team *team)
854 unsigned short max_hard_header_len =
ETH_HLEN;
859 port->
dev->vlan_features,
862 dst_release_flag &= port->
dev->priv_flags;
863 if (port->
dev->hard_header_len > max_hard_header_len)
864 max_hard_header_len = port->
dev->hard_header_len;
867 team->
dev->vlan_features = vlan_features;
868 team->
dev->hard_header_len = max_hard_header_len;
871 team->
dev->priv_flags = flags | dst_release_flag;
876 static void team_compute_features(
struct team *team)
879 __team_compute_features(team);
883 static int team_port_enter(
struct team *team,
struct team_port *port)
889 if (team->
ops.port_enter) {
890 err = team->
ops.port_enter(team, port);
892 netdev_err(team->
dev,
"Device %s failed to enter team mode\n",
907 static void team_port_leave(
struct team *team,
struct team_port *port)
909 if (team->
ops.port_leave)
910 team->
ops.port_leave(team, port);
915 #ifdef CONFIG_NET_POLL_CONTROLLER
916 static int team_port_enable_netpoll(
struct team *team,
struct team_port *port,
922 np = kzalloc(
sizeof(*np), gfp);
935 static void team_port_disable_netpoll(
struct team_port *port)
949 static struct netpoll_info *team_netpoll_info(
struct team *team)
951 return team->
dev->npinfo;
955 static int team_port_enable_netpoll(
struct team *team,
struct team_port *port,
960 static void team_port_disable_netpoll(
struct team_port *port)
963 static struct netpoll_info *team_netpoll_info(
struct team *team)
969 static void __team_port_change_port_added(
struct team_port *port,
bool linkup);
970 static int team_dev_type_check_change(
struct net_device *dev,
977 char *portname = port_dev->
name;
981 netdev_err(dev,
"Device %s is loopback device. Loopback devices can't be added as a team port\n",
987 netdev_err(dev,
"Device %s is already a port "
988 "of a team device\n", portname);
994 netdev_err(dev,
"Device %s is VLAN challenged and team device has VLAN set up\n",
999 err = team_dev_type_check_change(dev, port_dev);
1004 netdev_err(dev,
"Device %s is up. Set it down before adding it as a team port\n",
1009 port = kzalloc(
sizeof(
struct team_port) + team->
mode->port_priv_size,
1014 port->
dev = port_dev;
1018 port->
orig.mtu = port_dev->
mtu;
1021 netdev_dbg(dev,
"Error %d calling dev_set_mtu\n", err);
1027 err = team_port_enter(team, port);
1029 netdev_err(dev,
"Device %s failed to enter team mode\n",
1031 goto err_port_enter;
1036 netdev_dbg(dev,
"Device %s opening failed\n",
1043 netdev_err(dev,
"Failed to add vlan ids to device %s\n",
1048 if (team_netpoll_info(team)) {
1049 err = team_port_enable_netpoll(team, port,
GFP_KERNEL);
1051 netdev_err(dev,
"Failed to enable netpoll on device %s\n",
1053 goto err_enable_netpoll;
1059 netdev_err(dev,
"Device %s failed to set master\n", portname);
1060 goto err_set_master;
1066 netdev_err(dev,
"Device %s failed to register rx_handler\n",
1068 goto err_handler_register;
1071 err = __team_option_inst_add_port(team, port);
1073 netdev_err(dev,
"Device %s failed to add per-port options\n",
1075 goto err_option_port_add;
1079 team_port_enable(team, port);
1081 __team_compute_features(team);
1082 __team_port_change_port_added(port, !!netif_carrier_ok(port_dev));
1083 __team_options_change_check(team);
1085 netdev_info(dev,
"Port device %s added\n", portname);
1089 err_option_port_add:
1092 err_handler_register:
1096 team_port_disable_netpoll(port);
1105 team_port_leave(team, port);
1106 team_port_set_orig_dev_addr(port);
1117 static void __team_port_change_port_removed(
struct team_port *port);
1119 static int team_port_del(
struct team *team,
struct net_device *port_dev)
1123 char *portname = port_dev->
name;
1125 port = team_port_get_rtnl(port_dev);
1126 if (!port || !team_port_find(team, port)) {
1127 netdev_err(dev,
"Device %s does not act as a port of this team\n",
1132 __team_option_inst_mark_removed_port(team, port);
1133 __team_options_change_check(team);
1134 __team_option_inst_del_port(team, port);
1135 __team_port_change_port_removed(port);
1136 team_port_disable(team, port);
1137 list_del_rcu(&port->
list);
1140 team_port_disable_netpoll(port);
1143 team_port_leave(team, port);
1144 team_port_set_orig_dev_addr(port);
1148 netdev_info(dev,
"Port device %s removed\n", portname);
1149 __team_compute_features(team);
1159 static int team_mode_option_get(
struct team *team,
struct team_gsetter_ctx *ctx)
1165 static int team_mode_option_set(
struct team *team,
struct team_gsetter_ctx *ctx)
1170 static int team_port_en_option_get(
struct team *team,
1179 static int team_port_en_option_set(
struct team *team,
1185 team_port_enable(team, port);
1187 team_port_disable(team, port);
1191 static int team_user_linkup_option_get(
struct team *team,
1200 static int team_user_linkup_option_set(
struct team *team,
1206 team_refresh_port_linkup(port);
1210 static int team_user_linkup_en_option_get(
struct team *team,
1219 static int team_user_linkup_en_option_set(
struct team *team,
1225 team_refresh_port_linkup(port);
1229 static int team_priority_option_get(
struct team *team,
1238 static int team_priority_option_set(
struct team *team,
1244 team_queue_override_port_refresh(team, port);
1248 static int team_queue_id_option_get(
struct team *team,
1257 static int team_queue_id_option_set(
struct team *team,
1267 team_queue_override_port_refresh(team, port);
1272 static const struct team_option team_options[] = {
1276 .getter = team_mode_option_get,
1277 .setter = team_mode_option_set,
1283 .getter = team_port_en_option_get,
1284 .setter = team_port_en_option_set,
1287 .name =
"user_linkup",
1290 .getter = team_user_linkup_option_get,
1291 .setter = team_user_linkup_option_set,
1294 .name =
"user_linkup_enabled",
1297 .getter = team_user_linkup_en_option_get,
1298 .setter = team_user_linkup_en_option_set,
1304 .getter = team_priority_option_get,
1305 .setter = team_priority_option_set,
1311 .getter = team_queue_id_option_get,
1312 .setter = team_queue_id_option_set,
1320 static void team_set_lockdep_class_one(
struct net_device *dev,
1327 static void team_set_lockdep_class(
struct net_device *dev)
1330 netdev_for_each_tx_queue(dev, team_set_lockdep_class_one,
NULL);
1336 struct team *team = netdev_priv(dev);
1342 team_set_no_mode(team);
1351 err = team_queue_override_init(team);
1353 goto err_team_queue_override_init;
1355 team_adjust_ops(team);
1361 goto err_options_register;
1364 team_set_lockdep_class(dev);
1368 err_options_register:
1369 team_queue_override_fini(team);
1370 err_team_queue_override_init:
1376 static void team_uninit(
struct net_device *dev)
1378 struct team *team = netdev_priv(dev);
1384 team_port_del(team, port->dev);
1386 __team_change_mode(team,
NULL);
1387 __team_options_unregister(team, team_options,
ARRAY_SIZE(team_options));
1388 team_queue_override_fini(team);
1394 struct team *team = netdev_priv(dev);
1406 static int team_close(
struct net_device *dev)
1417 struct team *team = netdev_priv(dev);
1419 unsigned int len = skb->
len;
1421 tx_success = team_queue_override_transmit(team, skb);
1423 tx_success = team->
ops.transmit(team, skb);
1428 u64_stats_update_begin(&pcpu_stats->
syncp);
1431 u64_stats_update_end(&pcpu_stats->
syncp);
1447 u16 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : 0;
1462 static void team_change_rx_flags(
struct net_device *dev,
int change)
1464 struct team *team = netdev_priv(dev);
1471 inc = dev->
flags & IFF_PROMISC ? 1 : -1;
1475 inc = dev->
flags & IFF_ALLMULTI ? 1 : -1;
1482 static void team_set_rx_mode(
struct net_device *dev)
1484 struct team *team = netdev_priv(dev);
1495 static int team_set_mac_address(
struct net_device *dev,
void *
p)
1498 struct team *team = netdev_priv(dev);
1507 if (team->ops.port_change_dev_addr)
1508 team->ops.port_change_dev_addr(team, port);
1515 struct team *team = netdev_priv(dev);
1527 netdev_err(dev,
"Device %s failed to change mtu",
1549 struct team *team = netdev_priv(dev);
1559 start = u64_stats_fetch_begin_bh(&p->
syncp);
1565 }
while (u64_stats_fetch_retry_bh(&p->
syncp, start));
1586 struct team *team = netdev_priv(dev);
1614 struct team *team = netdev_priv(dev);
1625 #ifdef CONFIG_NET_POLL_CONTROLLER
1626 static void team_poll_controller(
struct net_device *dev)
1630 static void __team_netpoll_cleanup(
struct team *team)
1635 team_port_disable_netpoll(port);
1640 struct team *team = netdev_priv(dev);
1643 __team_netpoll_cleanup(team);
1647 static int team_netpoll_setup(
struct net_device *dev,
1650 struct team *team = netdev_priv(dev);
1656 err = team_port_enable_netpoll(team, port, gfp);
1658 __team_netpoll_cleanup(team);
1669 struct team *team = netdev_priv(dev);
1673 err = team_port_add(team, port_dev);
1680 struct team *team = netdev_priv(dev);
1684 err = team_port_del(team, port_dev);
1693 struct team *team = netdev_priv(dev);
1703 port->
dev->features,
1711 .ndo_init = team_init,
1712 .ndo_uninit = team_uninit,
1713 .ndo_open = team_open,
1714 .ndo_stop = team_close,
1715 .ndo_start_xmit = team_xmit,
1716 .ndo_select_queue = team_select_queue,
1717 .ndo_change_rx_flags = team_change_rx_flags,
1718 .ndo_set_rx_mode = team_set_rx_mode,
1719 .ndo_set_mac_address = team_set_mac_address,
1720 .ndo_change_mtu = team_change_mtu,
1721 .ndo_get_stats64 = team_get_stats64,
1722 .ndo_vlan_rx_add_vid = team_vlan_rx_add_vid,
1723 .ndo_vlan_rx_kill_vid = team_vlan_rx_kill_vid,
1724 #ifdef CONFIG_NET_POLL_CONTROLLER
1725 .ndo_poll_controller = team_poll_controller,
1726 .ndo_netpoll_setup = team_netpoll_setup,
1727 .ndo_netpoll_cleanup = team_netpoll_cleanup,
1729 .ndo_add_slave = team_add_slave,
1730 .ndo_del_slave = team_del_slave,
1731 .ndo_fix_features = team_fix_features,
1739 static void team_setup_by_port(
struct net_device *dev,
1746 dev->
mtu = port_dev->
mtu;
1752 static int team_dev_type_check_change(
struct net_device *dev,
1755 struct team *team = netdev_priv(dev);
1756 char *portname = port_dev->
name;
1762 netdev_err(dev,
"Device %s is of different type\n", portname);
1766 err = notifier_to_errno(err);
1768 netdev_err(dev,
"Refused to change device type\n");
1773 team_setup_by_port(dev, port_dev);
1778 static void team_setup(
struct net_device *dev)
1806 static int team_newlink(
struct net *src_net,
struct net_device *dev,
1812 eth_hw_addr_random(dev);
1821 static int team_validate(
struct nlattr *tb[],
struct nlattr *data[])
1824 if (nla_len(tb[IFLA_ADDRESS]) !=
ETH_ALEN)
1826 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
1832 static unsigned int team_get_num_tx_queues(
void)
1837 static unsigned int team_get_num_rx_queues(
void)
1844 .priv_size =
sizeof(
struct team),
1845 .
setup = team_setup,
1846 .newlink = team_newlink,
1847 .validate = team_validate,
1848 .get_num_tx_queues = team_get_num_tx_queues,
1849 .get_num_rx_queues = team_get_num_rx_queues,
1901 genlmsg_end(msg, hdr);
1903 return genlmsg_unicast(genl_info_net(info), msg, info->
snd_portid);
1915 static struct team *team_nl_team_get(
struct genl_info *info)
1917 struct net *
net = genl_info_net(info);
1927 if (!dev || dev->
netdev_ops != &team_netdev_ops) {
1933 team = netdev_priv(dev);
1938 static void team_nl_team_put(
struct team *team)
1944 static int team_nl_send_generic(
struct genl_info *info,
struct team *team,
1945 int (*fill_func)(
struct sk_buff *skb,
1947 int flags,
struct team *team))
1956 err = fill_func(skb, info,
NLM_F_ACK, team);
1960 err = genlmsg_unicast(genl_info_net(info), skb, info->
snd_portid);
1969 struct team *team,
u32 portid);
1971 static int team_nl_send_unicast(
struct sk_buff *skb,
struct team *team,
u32 portid)
1973 return genlmsg_unicast(dev_net(team->
dev), skb, portid);
1976 static int team_nl_fill_one_option_get(
struct sk_buff *skb,
struct team *team,
1979 struct nlattr *option_item;
1985 ctx.
info = opt_inst_info;
1986 err = team_option_get(team, opt_inst, &ctx);
1996 if (opt_inst_info->
port &&
1998 opt_inst_info->
port->dev->ifindex))
2000 if (opt_inst->
option->array_size &&
2005 switch (option->
type) {
2049 nla_nest_end(skb, option_item);
2053 nla_nest_cancel(skb, option_item);
2057 static int __send_and_alloc_skb(
struct sk_buff **pskb,
2058 struct team *team,
u32 portid,
2064 err = send_func(*pskb, team, portid);
2074 static int team_nl_send_options_get(
struct team *team,
u32 portid,
u32 seq,
2078 struct nlattr *option_list;
2091 err = __send_and_alloc_skb(&skb, team, portid, send_func);
2101 goto nla_put_failure;
2104 goto nla_put_failure;
2109 err = team_nl_fill_one_option_get(skb, team, opt_inst);
2122 nla_nest_end(skb, option_list);
2123 genlmsg_end(skb, hdr);
2130 err = __send_and_alloc_skb(&skb, team, portid, send_func);
2136 return send_func(skb, team, portid);
2141 genlmsg_cancel(skb, hdr);
2146 static int team_nl_cmd_options_get(
struct sk_buff *skb,
struct genl_info *info)
2153 team = team_nl_team_get(info);
2159 err = team_nl_send_options_get(team, info->snd_portid, info->snd_seq,
2161 &sel_opt_inst_list);
2163 team_nl_team_put(team);
2168 static
int team_nl_send_event_options_get(
struct team *team,
2176 struct nlattr *nl_option;
2179 team = team_nl_team_get(info);
2192 struct nlattr *attr_data;
2194 int opt_port_ifindex = 0;
2195 u32 opt_array_index = 0;
2196 bool opt_is_array =
false;
2199 bool opt_found =
false;
2206 nl_option, team_nl_option_policy);
2214 switch (nla_get_u8(opt_attrs[TEAM_ATTR_OPTION_TYPE])) {
2243 opt_port_ifindex = nla_get_u32(attr);
2247 opt_is_array =
true;
2248 opt_array_index = nla_get_u32(attr);
2257 opt_inst_info = &opt_inst->
info;
2258 tmp_ifindex = opt_inst_info->
port ?
2259 opt_inst_info->
port->dev->ifindex : 0;
2260 if (option->
type != opt_type ||
2262 tmp_ifindex != opt_port_ifindex ||
2267 ctx.
info = opt_inst_info;
2292 err = team_option_set(team, opt_inst, &ctx);
2296 list_add(&opt_inst->
tmp_list, &opt_inst_list);
2304 err = team_nl_send_event_options_get(team, &opt_inst_list);
2307 team_nl_team_put(team);
2312 static int team_nl_fill_port_list_get(
struct sk_buff *skb,
2313 u32 portid,
u32 seq,
int flags,
2321 hdr =
genlmsg_put(skb, portid, seq, &team_nl_family, flags,
2327 goto nla_put_failure;
2330 goto nla_put_failure;
2333 struct nlattr *port_item;
2336 if (!fillall && !port->
changed)
2340 goto nla_put_failure;
2342 goto nla_put_failure;
2345 goto nla_put_failure;
2350 (port->
state.linkup &&
2354 goto nla_put_failure;
2355 nla_nest_end(skb, port_item);
2358 nla_nest_end(skb, port_list);
2359 return genlmsg_end(skb, hdr);
2362 genlmsg_cancel(skb, hdr);
2366 static int team_nl_fill_port_list_get_all(
struct sk_buff *skb,
2370 return team_nl_fill_port_list_get(skb, info->
snd_portid,
2375 static int team_nl_cmd_port_list_get(
struct sk_buff *skb,
2381 team = team_nl_team_get(info);
2385 err = team_nl_send_generic(info, team, team_nl_fill_port_list_get_all);
2387 team_nl_team_put(team);
2392 static struct genl_ops team_nl_ops[] = {
2395 .doit = team_nl_cmd_noop,
2396 .policy = team_nl_policy,
2400 .doit = team_nl_cmd_options_set,
2401 .policy = team_nl_policy,
2406 .doit = team_nl_cmd_options_get,
2407 .policy = team_nl_policy,
2412 .doit = team_nl_cmd_port_list_get,
2413 .policy = team_nl_policy,
2422 static int team_nl_send_multicast(
struct sk_buff *skb,
2423 struct team *team,
u32 portid)
2425 return genlmsg_multicast_netns(dev_net(team->
dev), skb, 0,
2429 static int team_nl_send_event_options_get(
struct team *team,
2432 return team_nl_send_options_get(team, 0, 0, 0, team_nl_send_multicast,
2436 static int team_nl_send_event_port_list_get(
struct team *team)
2440 struct net *net = dev_net(team->
dev);
2446 err = team_nl_fill_port_list_get(skb, 0, 0, 0, team,
false);
2450 err = genlmsg_multicast_netns(net, skb, 0, team_change_event_mcgrp.
id,
2459 static int team_nl_init(
void)
2470 goto err_change_event_grp_reg;
2474 err_change_event_grp_reg:
2480 static void team_nl_fini(
void)
2490 static void __team_options_change_check(
struct team *team)
2500 err = team_nl_send_event_options_get(team, &sel_opt_inst_list);
2501 if (err && err != -
ESRCH)
2502 netdev_warn(team->
dev,
"Failed to send options change via netlink (err %d)\n",
2508 static void __team_port_change_send(
struct team_port *port,
bool linkup)
2513 port->
state.linkup = linkup;
2514 team_refresh_port_linkup(port);
2520 port->
state.speed = ethtool_cmd_speed(&ecmd);
2521 port->
state.duplex = ecmd.duplex;
2525 port->
state.speed = 0;
2526 port->
state.duplex = 0;
2529 err = team_nl_send_event_port_list_get(port->
team);
2530 if (err && err != -
ESRCH)
2531 netdev_warn(port->
team->dev,
"Failed to send port change of device %s via netlink (err %d)\n",
2532 port->
dev->name, err);
2536 static void __team_port_change_check(
struct team_port *port,
bool linkup)
2538 if (port->
state.linkup != linkup)
2539 __team_port_change_send(port, linkup);
2542 static void __team_port_change_port_added(
struct team_port *port,
bool linkup)
2544 __team_port_change_send(port, linkup);
2547 static void __team_port_change_port_removed(
struct team_port *port)
2550 __team_port_change_send(port,
false);
2553 static void team_port_change_check(
struct team_port *port,
bool linkup)
2555 struct team *team = port->
team;
2558 __team_port_change_check(port, linkup);
2573 port = team_port_get_rtnl(dev);
2579 if (netif_carrier_ok(dev))
2580 team_port_change_check(port,
true);
2582 team_port_change_check(port,
false);
2584 if (netif_running(port->
dev))
2585 team_port_change_check(port,
2586 !!netif_carrier_ok(port->
dev));
2589 team_del_slave(port->
team->dev, dev);
2592 team_compute_features(port->
team);
2604 static struct notifier_block team_notifier_block __read_mostly = {
2605 .notifier_call = team_device_event,
2613 static int __init team_module_init(
void)
2623 err = team_nl_init();
2638 static void __exit team_module_exit(
void)