net: convert bonding to use rx_handler
Subsystems (3)
RFC PATCH 1/1 net: convert bonding to use rx_handler
Hello.
This is an attempt to convert bonding to use rx_handler. Result should be cleaner __netif_receive_skb() with much less exceptions needed. I think I covered all aspects, not sure though. I gave this quick smoke test on my testing env. Please comment, test.
Thanks!
--- drivers/net/bonding/bond_main.c | 75 ++++++++++++++++++++- include/linux/skbuff.h | 1 + net/core/dev.c | 144 +++++++++++--------------------------- 3 files changed, 117 insertions(+), 103 deletions(-)
drivers/net/bonding/bond_main.c +74 -1
@@ -1423,6 +1423,68 @@ static void bond_setup_by_slave(struct net_device *bond_dev, bond->setup_by_slave =1 ; } +/* On bonding slaves other than the currently active slave, suppress +* duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and +* ARP on active-backup slaves with arp_validate enabled. +*/ +static bool bond_should_deliver_exact_match (struct sk_buff *skb, +struct net_device *slave_dev, +struct net_device *bond_dev) +{ +if (slave_dev->priv_flags &IFF_SLAVE_INACTIVE ) { +if (slave_dev->priv_flags &IFF_SLAVE_NEEDARP && + skb->protocol ==__cpu_to_be16 (ETH_P_ARP )) +return false; + +if (bond_dev->priv_flags &IFF_MASTER_ALB && + skb->pkt_type !=PACKET_BROADCAST && + skb->pkt_type !=PACKET_MULTICAST ) +return false; + +if (bond_dev->priv_flags &IFF_MASTER_8023AD && + skb->protocol ==__cpu_to_be16 (ETH_P_SLOW )) +return false; + +return true; + } +return false; +} + +static struct sk_buff *bond_handle_frame (struct sk_buff *skb) +{ +struct net_device *slave_dev; +struct net_device *bond_dev; + + skb =skb_share_check (skb,GFP_ATOMIC ); +if (unlikely (!skb)) +return NULL ; + slave_dev = skb->dev; + bond_dev = slave_dev->master; +if (unlikely (!bond_dev)) +return skb; + +if (bond_dev->priv_flags &IFF_MASTER_ARPMON ) + slave_dev->last_rx = jiffies; + +if (bond_should_deliver_exact_match (skb, slave_dev, bond_dev)) { + skb->deliver_no_wcard =1 ; +return skb; + } + + skb->dev = bond_dev; + +if (bond_dev->priv_flags &IFF_MASTER_ALB && + bond_dev->priv_flags &IFF_BRIDGE_PORT && + skb->pkt_type ==PACKET_HOST ) { +u16 *dest = (u16 *)eth_hdr (skb)->h_dest; + +memcpy (dest, bond_dev->dev_addr,ETH_ALEN ); + } + +netif_rx (skb); +return NULL ; +} +/* enslave device <slave> to bond device <master> */ int bond_enslave (struct net_device *bond_dev,struct net_device *slave_dev) {
@@ -1599,11 +1661,17 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)pr_debug ("Error %d calling netdev_set_bond_master\n" , res); goto err_restore_mac; } + res =netdev_rx_handler_register (slave_dev, bond_handle_frame,NULL ); +if (res) { +pr_debug ("Error %d calling netdev_rx_handler_register\n" , res); + goto err_unset_master; + } +/* open the slave since the application closed it */ res =dev_open (slave_dev);if (res) {pr_debug ("Opening slave %s failed\n" , slave_dev->name); - goto err_unset_master; + goto err_unreg_rxhandler; } new_slave->dev = slave_dev;
@@ -1811,6 +1879,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) err_close:dev_close (slave_dev); +err_unreg_rxhandler: +netdev_rx_handler_unregister (slave_dev); + err_unset_master:netdev_set_bond_master (slave_dev,NULL );
@@ -1992,6 +2063,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)netif_addr_unlock_bh (bond_dev); } +netdev_rx_handler_unregister (slave_dev);netdev_set_bond_master (slave_dev,NULL );#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -2114,6 +2186,7 @@ static int bond_release_all(struct net_device *bond_dev)netif_addr_unlock_bh (bond_dev); } +netdev_rx_handler_unregister (slave_dev);netdev_set_bond_master (slave_dev,NULL );/* close slave before restoring its mac address */
include/linux/skbuff.h +1 -0
@@ -325,6 +325,7 @@ struct sk_buff {struct sock *sk;struct net_device *dev; +struct net_device *orig_dev;/* * This is the control buffer. It is free to use for every
net/core/dev.c +42 -102
240 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Quoted 20 lines · Jiri Pirko
Hello.
This is an attempt to convert bonding to use
rx_handler. Result should be cleaner__netif_receive_skb()with much less exceptions needed. I think I covered all aspects, not sure though. I gave this quick smoke test on my testing env. Please comment, test.Thanks!
Signed-off-by Jiri Pirko <[email protected]>--- drivers/net/bonding/bond_main.c | 75 ++++++++++++++++++++- include/linux/skbuff.h | 1 + net/core/dev.c | 144 +++++++++++--------------------------- 3 files changed, 117 insertions(+), 103 deletions(-)drivers/net/bonding/bond_main.c +1
-0+
drivers/net/bonding/bond_main.c static void bond_setup_by_slave(struct net_device *bond_dev, · line 1462
Quoted 10 lines
drivers/net/bonding/bond_main.c +10
-0+static struct sk_buff *bond_handle_frame (struct sk_buff *skb) +{ +struct net_device *slave_dev; +struct net_device *bond_dev; + + skb =skb_share_check (skb,GFP_ATOMIC ); +if (unlikely (!skb)) +return NULL ; + slave_dev = skb->dev; + bond_dev = slave_dev->master;
I suggest being 10%% safe here :
bond_dev = ACCESS_ONCE(slave_dev->master);
Quoted 32 lines
drivers/net/bonding/bond_main.c +25
-0+if (unlikely (!bond_dev)) +return skb; + +if (bond_dev->priv_flags &IFF_MASTER_ARPMON ) + slave_dev->last_rx = jiffies; + +if (bond_should_deliver_exact_match (skb, slave_dev, bond_dev)) { + skb->deliver_no_wcard =1 ; +return skb; + } + + skb->dev = bond_dev; + +if (bond_dev->priv_flags &IFF_MASTER_ALB && + bond_dev->priv_flags &IFF_BRIDGE_PORT && + skb->pkt_type ==PACKET_HOST ) { +u16 *dest = (u16 *)eth_hdr (skb)->h_dest; + +memcpy (dest, bond_dev->dev_addr,ETH_ALEN ); + } + +netif_rx (skb); +return NULL ; +} +include/linux/skbuff.h +0
-0
include/linux/skbuff.h struct sk_buff { · line 331
Quoted 7 lines
include/linux/skbuff.h +1
-0@@ -325,6 +325,7 @@ struct sk_buff {struct sock *sk;struct net_device *dev; +struct net_device *orig_dev;/* * This is the control buffer. It is free to use for every
Thats a problem. lifetime of this field is so small, I wonder if you cant find a solution to handle this differently. Maybe a percpu variable, or in cb[] ?
Quoted 34 lines · Thu, Feb 17, 2011 at 02:20:35PM CET, [email protected] wrote:
Quoted 20 lines · Jiri Pirko
Hello.
This is an attempt to convert bonding to use
rx_handler. Result should be cleaner__netif_receive_skb()with much less exceptions needed. I think I covered all aspects, not sure though. I gave this quick smoke test on my testing env. Please comment, test.Thanks!
Signed-off-by Jiri Pirko <[email protected]>--- drivers/net/bonding/bond_main.c | 75 ++++++++++++++++++++- include/linux/skbuff.h | 1 + net/core/dev.c | 144 +++++++++++--------------------------- 3 files changed, 117 insertions(+), 103 deletions(-)drivers/net/bonding/bond_main.c +1
-0+drivers/net/bonding/bond_main.c static void bond_setup_by_slave(struct net_device *bond_dev, · line 1462
Quoted 10 lines
drivers/net/bonding/bond_main.c +10
-0+static struct sk_buff *bond_handle_frame (struct sk_buff *skb) +{ +struct net_device *slave_dev; +struct net_device *bond_dev; + + skb =skb_share_check (skb,GFP_ATOMIC ); +if (unlikely (!skb)) +return NULL ; + slave_dev = skb->dev; + bond_dev = slave_dev->master;I suggest being 10%% safe here :
Quoted 1 line
bond_dev = ACCESS_ONCE(slave_dev->master);
Right, will change this.
Quoted 38 lines
Quoted 38 lines
drivers/net/bonding/bond_main.c +25
-0+if (unlikely (!bond_dev)) +return skb; + +if (bond_dev->priv_flags &IFF_MASTER_ARPMON ) + slave_dev->last_rx = jiffies; + +if (bond_should_deliver_exact_match (skb, slave_dev, bond_dev)) { + skb->deliver_no_wcard =1 ; +return skb; + } + + skb->dev = bond_dev; + +if (bond_dev->priv_flags &IFF_MASTER_ALB && + bond_dev->priv_flags &IFF_BRIDGE_PORT && + skb->pkt_type ==PACKET_HOST ) { +u16 *dest = (u16 *)eth_hdr (skb)->h_dest; + +memcpy (dest, bond_dev->dev_addr,ETH_ALEN ); + } + +netif_rx (skb); +return NULL ; +} +include/linux/skbuff.h +1
-0@@ -325,6 +325,7 @@ struct sk_buff {struct sock *sk;struct net_device *dev; +struct net_device *orig_dev;
Quoted 6 lines
include/linux/skbuff.h struct sk_buff { · line 331
Quoted 2 lines
include/linux/skbuff.h +0
-0/* * This is the control buffer. It is free to use for every Thats a problem. lifetime of this field is so small, I wonder if you cant find a solution to handle this differently. Maybe a percpu variable, or in cb[] ?
Yes, I was not feeling absolutely comfortable puting this here. You mean global percpu variable living in net/core/dev.c? I must say I would probably like skb->orig_dev more than that.
As for cb - I do not like that much. Also I think there might be collision e.g. with bridge code.