net: introduce ethernet teaming device
Subsystems (4)
PATCH v6 1/1 net: introduce ethernet teaming device
This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.
Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.
team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.
Python binding of libteam was recently introduced. Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.
v5->v6:
- changed couple of _rcu calls to non _rcu ones in non-readers
v4->v5:
- team_change_mtu() uses team->lock while travesing though port list
- mac address changes are moved completely to jurisdiction of userspace daemon. This way the daemon can do FOM1, FOM2 and possibly other weird things with mac addresses. Only round-robin mode sets up all ports to bond's address then enslaved.
- Extended Kconfig text
v3->v4:
- remove redundant synchronize_rcu from __team_change_mode()
- revert "set and clear of mode_ops happens per pointer, not per byte"
- extend comment of function __team_change_mode()
v2->v3:
- team_change_mtu() uses rcu version of list traversal to unwind
- set and clear of mode_ops happens per pointer, not per byte
- port hashlist changed to be embedded into team structure
- error branch in team_port_enter() does cleanup now
- fixed rtln->rtnl
v1->v2:
- modes are made as modules. Makes team more modular and extendable.
- several commenters' nitpicks found on v1 were fixed
- several other bugs were fixed.
- note I ignored Eric's comment about roundrobin port selector as Eric's way may be easily implemented as another mode (mode "random") in future.
--- Documentation/networking/team.txt | 2 + MAINTAINERS | 7 + drivers/net/Kconfig | 2 + drivers/net/Makefile | 1 + drivers/net/team/Kconfig | 43 + drivers/net/team/Makefile | 7 + drivers/net/team/team.c | 1555 +++++++++++++++++++++++++++++ drivers/net/team/team_mode_activebackup.c | 137 +++ drivers/net/team/team_mode_roundrobin.c | 107 ++ include/linux/Kbuild | 1 + include/linux/if.h | 1 + include/linux/if_team.h | 242 +++++ 12 files changed, 2105 insertions(+), 0 deletions(-) create mode 100644 Documentation/networking/team.txt create mode 100644 drivers/net/team/Kconfig create mode 100644 drivers/net/team/Makefile create mode 100644 drivers/net/team/team.c create mode 100644 drivers/net/team/team_mode_activebackup.c create mode 100644 drivers/net/team/team_mode_roundrobin.c create mode 100644 include/linux/if_team.h
Documentation/networking/team.txt new file +2 -0
@@ -0,0 +1,2 @@ +Team devices are driven from userspace via libteam library which is here: + https://github.com/jpirko/libteam
MAINTAINERS +7 -0
@@ -6484,6 +6484,13 @@ W: http://tcp-lp-mod.sourceforge.net/ S: Maintained F: net/ipv4/tcp_lp.c +TEAM DRIVER +M: Jiri Pirko <[email protected]> +L: [email protected] +S: Supported +F: drivers/net/team/ +F: include/linux/if_team.h + TEGRA SUPPORT M: Colin Cross <[email protected]> M: Olof Johansson <[email protected]>
drivers/net/Kconfig +2 -0
@@ -125,6 +125,8 @@ config IFB 'ifb1' etc. Look at the iproute2 documentation directory for usage etc +source "drivers/net/team/Kconfig" + config MACVLAN tristate "MAC-VLAN support (EXPERIMENTAL)" depends on EXPERIMENTAL
drivers/net/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_NET) += Space.o loopback.o obj-$(CONFIG_NETCONSOLE) += netconsole.o obj-$(CONFIG_PHYLIB) += phy/ obj-$(CONFIG_RIONET) += rionet.o +obj-$(CONFIG_NET_TEAM) += team/ obj-$(CONFIG_TUN) += tun.o obj-$(CONFIG_VETH) += veth.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
drivers/net/team/Kconfig new file +43 -0
43 lines not on this page · raw message
drivers/net/team/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the network team driver +# + +obj-$(CONFIG_NET_TEAM) += team.o +obj-$(CONFIG_NET_TEAM_MODE_ROUNDROBIN) += team_mode_roundrobin.o +obj-$(CONFIG_NET_TEAM_MODE_ACTIVEBACKUP) += team_mode_activebackup.o
drivers/net/team/team.c new file +1555 -0
1,555 lines not on this page · raw message
drivers/net/team/team_mode_activebackup.c new file +137 -0
137 lines not on this page · raw message
drivers/net/team/team_mode_roundrobin.c new file +107 -0
107 lines not on this page · raw message
include/linux/Kbuild +1 -0
@@ -185,6 +185,7 @@ header-y += if_pppol2tp.h header-y += if_pppox.h header-y += if_slip.h header-y += if_strip.h +header-y += if_team.h header-y += if_tr.h header-y += if_tun.h header-y += if_tunnel.h
include/linux/if.h +1 -0
@@ -79,6 +79,7 @@#define IFF_TX_SKB_SHARING 0x10000/* The interface supports sharing * skbs on transmit */ #define IFF_UNICAST_FLT 0x20000/* Supports unicast filtering */ +#define IFF_TEAM_PORT 0x40000/* device used as team port */ #define IF_GET_IFACE 0x0001/* for querying only */ #define IF_GET_PROTO 0x0002
include/linux/if_team.h new file +242 -0
242 lines not on this page · raw message
Signature · 1 line
1.7.6
Quoted 3 lines · Jiri Pirko
This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.
...
Quoted 20 lines
drivers/net/team/team.c new file +20
-0+/* +* note: already called with rcu_read_lock +*/ +static netdev_tx_t team_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct team *team =netdev_priv (dev); +bool tx_success = false; +unsigned int len = skb->len; + +/* +* Ensure transmit function is called only in case there is at least +* one port present. +*/ +if (likely (!list_empty (&team->port_list) && team->mode_ops.transmit)) + tx_success = team->mode_ops.transmit (team, skb); +if (tx_success) { +struct team_pcpu_stats *pcpu_stats; + + pcpu_stats =this_cpu_ptr (team->pcpu_stats); +u64_stats_update_begin (&pcpu_stats->syncp);
drivers/net/team/team.c line 702
Quoted 10 lines
drivers/net/team/team.c new file +10
-0+ pcpu_stats->tx_packets++; + pcpu_stats->tx_bytes += len; +u64_stats_update_end (&pcpu_stats->syncp); + }else { +this_cpu_inc (team->pcpu_stats->tx_dropped); + } + +return NETDEV_TX_OK ; +} +
If skb is not transmitted, its leaked.
Quoted 7 lines · Eric Dumazet
Quoted 3 lines · Jiri Pirko
This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.
...
Quoted 15 lines
Quoted 5 lines
drivers/net/team/team.c new file +5
-0+/* +* note: already called with rcu_read_lock +*/ +static netdev_tx_t team_xmit (struct sk_buff *skb,struct net_device *dev) +{drivers/net/team/team.c line 687
Quoted 10 lines
drivers/net/team/team.c new file +10
-0+struct team *team =netdev_priv (dev); +bool tx_success = false; +unsigned int len = skb->len; + +/* +* Ensure transmit function is called only in case there is at least +* one port present. +*/ +if (likely (!list_empty (&team->port_list) && team->mode_ops.transmit)) + tx_success = team->mode_ops.transmit (team, skb);
Not clear why its so complex here.
When you manipulate team->port_list and make it empty, why dont you set team->mode_ops.transmit to a helper function, freeing the skb and returning false.
Also, instead of setting .transmit to NULL, you also could set it to same helper function.
This way you could just do in fast path :
tx_succcess = team->mode_ops.transmit(team, skb);
Avoiding two tests
Quoted 16 lines
Quoted 15 lines
drivers/net/team/team.c new file +15
-0+if (tx_success) { +struct team_pcpu_stats *pcpu_stats; + + pcpu_stats =this_cpu_ptr (team->pcpu_stats); +u64_stats_update_begin (&pcpu_stats->syncp); + pcpu_stats->tx_packets++; + pcpu_stats->tx_bytes += len; +u64_stats_update_end (&pcpu_stats->syncp); + }else { +this_cpu_inc (team->pcpu_stats->tx_dropped); + } + +return NETDEV_TX_OK ; +} +
Quoted 30 lines · Thu, Nov 10, 2011 at 12:53:09AM CET, [email protected] wrote:
Quoted 7 lines · Eric Dumazet
Quoted 3 lines · Jiri Pirko
This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.
...
Quoted 15 lines
Quoted 5 lines
drivers/net/team/team.c new file +5
-0+/* +* note: already called with rcu_read_lock +*/ +static netdev_tx_t team_xmit (struct sk_buff *skb,struct net_device *dev) +{drivers/net/team/team.c line 687
Quoted 10 lines
drivers/net/team/team.c new file +10
-0+struct team *team =netdev_priv (dev); +bool tx_success = false; +unsigned int len = skb->len; + +/* +* Ensure transmit function is called only in case there is at least +* one port present. +*/ +if (likely (!list_empty (&team->port_list) && team->mode_ops.transmit)) + tx_success = team->mode_ops.transmit (team, skb);Not clear why its so complex here.
When you manipulate
team->port_listand make it empty, why dont you setteam->mode_ops.transmitto a helper function, freeing the skb and returning false.
Quoted 8 lines
Also, instead of setting .transmit to NULL, you also could set it to same helper function.
This way you could just do in fast path :
tx_succcess = team->mode_ops.transmit(team, skb);Avoiding two tests
This approach I was thinking of as well. I was not sure that it would be so nice to change this function from port_add/port_del but I'm going to look at this.
Quoted 20 lines
Quoted 17 lines
Quoted 16 lines
drivers/net/team/team.c new file +15
-0+if (tx_success) { +struct team_pcpu_stats *pcpu_stats; + + pcpu_stats =this_cpu_ptr (team->pcpu_stats); +u64_stats_update_begin (&pcpu_stats->syncp); + pcpu_stats->tx_packets++; + pcpu_stats->tx_bytes += len; +u64_stats_update_end (&pcpu_stats->syncp); + }else { +this_cpu_inc (team->pcpu_stats->tx_dropped); + } + +return NETDEV_TX_OK ; +} +
Quoted 31 lines · Thu, Nov 10, 2011 at 12:12:35AM CET, [email protected] wrote:
Quoted 3 lines · Jiri Pirko
This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.
...
Quoted 24 lines
drivers/net/team/team.c new file +24
-0+/* +* note: already called with rcu_read_lock +*/ +static netdev_tx_t team_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct team *team =netdev_priv (dev); +bool tx_success = false; +unsigned int len = skb->len; + +/* +* Ensure transmit function is called only in case there is at least +* one port present. +*/ +if (likely (!list_empty (&team->port_list) && team->mode_ops.transmit)) + tx_success = team->mode_ops.transmit (team, skb); +if (tx_success) { +struct team_pcpu_stats *pcpu_stats; + + pcpu_stats =this_cpu_ptr (team->pcpu_stats); +u64_stats_update_begin (&pcpu_stats->syncp); + pcpu_stats->tx_packets++; + pcpu_stats->tx_bytes += len; +u64_stats_update_end (&pcpu_stats->syncp); + }else {
Quoted 8 lines
drivers/net/team/team.c line 702
Quoted 6 lines
drivers/net/team/team.c new file +6
-0+this_cpu_inc (team->pcpu_stats->tx_dropped); + } + +return NETDEV_TX_OK ; +} +If skb is not transmitted, its leaked.
dev_kfree_skb is called from module transmit functions to handle free of skb when needed. But I see now that in case when (likely(!list_empty(&team->port_list) && team->mode_ops.transmit)) == false this would leak. I'm going to rewrite this bit somehow.
Quoted 3 lines
Quoted 4 lines · Jiri Pirko
dev_kfree_skbis called from module transmit functions to handle free of skb when needed. But I see now that in case when (likely(!list_empty(&team->port_list) && team->mode_ops.transmit)) == false this would leak. I'm going to rewrite this bit somehow.
This is the leak I mentioned, I thought it was obvious :)
If you return NETDEV_TX_OK, then the skb must have been consumed.
Quoted 10 lines · Eric Dumazet
Quoted 4 lines · Jiri Pirko
dev_kfree_skbis called from module transmit functions to handle free of skb when needed. But I see now that in case when (likely(!list_empty(&team->port_list) && team->mode_ops.transmit)) == false this would leak. I'm going to rewrite this bit somehow.This is the leak I mentioned, I thought it was obvious :)
If you return
NETDEV_TX_OK, then the skb must have been consumed.
I meant : consumed or queued in a device transmit queue...