Skip to content

Commit

Permalink
bonding: register slave pointer for rx_handler
Browse files Browse the repository at this point in the history
Register slave pointer as rx_handler data. That would eventually prevent
need to loop over slave devices to find the right slave.

Use synchronize_net to ensure that bond_handle_frame does not get slave
structure freed when working with that.

Signed-off-by: Jiri Pirko <[email protected]>
Reviewed-by: Nicolas de Pesloüan <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jiri Pirko authored and davem330 committed Mar 16, 2011
1 parent c888385 commit f1c1775
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 11 additions & 6 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,21 +1482,22 @@ static bool bond_should_deliver_exact_match(struct sk_buff *skb,

static struct sk_buff *bond_handle_frame(struct sk_buff *skb)
{
struct net_device *slave_dev;
struct slave *slave;
struct net_device *bond_dev;

skb = skb_share_check(skb, GFP_ATOMIC);
if (unlikely(!skb))
return NULL;
slave_dev = skb->dev;
bond_dev = ACCESS_ONCE(slave_dev->master);

slave = bond_slave_get_rcu(skb->dev);
bond_dev = ACCESS_ONCE(slave->dev->master);
if (unlikely(!bond_dev))
return skb;

if (bond_dev->priv_flags & IFF_MASTER_ARPMON)
slave_dev->last_rx = jiffies;
slave->dev->last_rx = jiffies;

if (bond_should_deliver_exact_match(skb, slave_dev, bond_dev)) {
if (bond_should_deliver_exact_match(skb, slave->dev, bond_dev)) {
skb->deliver_no_wcard = 1;
return skb;
}
Expand Down Expand Up @@ -1694,7 +1695,8 @@ 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);
res = netdev_rx_handler_register(slave_dev, bond_handle_frame,
new_slave);
if (res) {
pr_debug("Error %d calling netdev_rx_handler_register\n", res);
goto err_unset_master;
Expand Down Expand Up @@ -1916,6 +1918,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)

err_unreg_rxhandler:
netdev_rx_handler_unregister(slave_dev);
synchronize_net();

err_unset_master:
netdev_set_bond_master(slave_dev, NULL);
Expand Down Expand Up @@ -2099,6 +2102,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
}

netdev_rx_handler_unregister(slave_dev);
synchronize_net();
netdev_set_bond_master(slave_dev, NULL);

slave_disable_netpoll(slave);
Expand Down Expand Up @@ -2213,6 +2217,7 @@ static int bond_release_all(struct net_device *bond_dev)
}

netdev_rx_handler_unregister(slave_dev);
synchronize_net();
netdev_set_bond_master(slave_dev, NULL);

slave_disable_netpoll(slave);
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/bonding/bonding.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ struct bonding {
#endif /* CONFIG_DEBUG_FS */
};

#define bond_slave_get_rcu(dev) \
((struct slave *) rcu_dereference(dev->rx_handler_data))

/**
* Returns NULL if the net_device does not belong to any of the bond's slaves
*
Expand Down

0 comments on commit f1c1775

Please sign in to comment.