Skip to content

Commit 3aba891

Browse files
Jiri Pirkodavem330
authored andcommitted
bonding: move processing of recv handlers into handle_frame()
Since now when bonding uses rx_handler, all traffic going into bond device goes thru bond_handle_frame. So there's no need to go back into bonding code later via ptype handlers. This patch converts original ptype handlers into "bonding receive probes". These functions are called from bond_handle_frame and they are registered per-mode. Note that vlan packets are also handled because they are always untagged thanks to vlan_untag() Note that this also allows arpmon for eth-bond-bridge-vlan topology. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 22d5969 commit 3aba891

File tree

8 files changed

+43
-189
lines changed

8 files changed

+43
-189
lines changed

drivers/net/bonding/bond_3ad.c

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,35 +2465,16 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
24652465
return NETDEV_TX_OK;
24662466
}
24672467

2468-
int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type* ptype, struct net_device *orig_dev)
2468+
void bond_3ad_lacpdu_recv(struct sk_buff *skb, struct bonding *bond,
2469+
struct slave *slave)
24692470
{
2470-
struct bonding *bond = netdev_priv(dev);
2471-
struct slave *slave = NULL;
2472-
int ret = NET_RX_DROP;
2473-
2474-
if (!(dev->flags & IFF_MASTER))
2475-
goto out;
2476-
2477-
skb = skb_share_check(skb, GFP_ATOMIC);
2478-
if (!skb)
2479-
goto out;
2471+
if (skb->protocol != PKT_TYPE_LACPDU)
2472+
return;
24802473

24812474
if (!pskb_may_pull(skb, sizeof(struct lacpdu)))
2482-
goto out;
2475+
return;
24832476

24842477
read_lock(&bond->lock);
2485-
slave = bond_get_slave_by_dev(netdev_priv(dev), orig_dev);
2486-
if (!slave)
2487-
goto out_unlock;
2488-
24892478
bond_3ad_rx_indication((struct lacpdu *) skb->data, slave, skb->len);
2490-
2491-
ret = NET_RX_SUCCESS;
2492-
2493-
out_unlock:
24942479
read_unlock(&bond->lock);
2495-
out:
2496-
dev_kfree_skb(skb);
2497-
2498-
return ret;
24992480
}

drivers/net/bonding/bond_3ad.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ struct ad_bond_info {
258258
* requested
259259
*/
260260
struct timer_list ad_timer;
261-
struct packet_type ad_pkt_type;
262261
};
263262

264263
struct ad_slave_info {
@@ -280,7 +279,8 @@ void bond_3ad_adapter_duplex_changed(struct slave *slave);
280279
void bond_3ad_handle_link_change(struct slave *slave, char link);
281280
int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info);
282281
int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev);
283-
int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type* ptype, struct net_device *orig_dev);
282+
void bond_3ad_lacpdu_recv(struct sk_buff *skb, struct bonding *bond,
283+
struct slave *slave);
284284
int bond_3ad_set_carrier(struct bonding *bond);
285285
#endif //__BOND_3AD_H__
286286

drivers/net/bonding/bond_alb.c

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -308,49 +308,33 @@ static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
308308
_unlock_rx_hashtbl(bond);
309309
}
310310

311-
static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct packet_type *ptype, struct net_device *orig_dev)
311+
static void rlb_arp_recv(struct sk_buff *skb, struct bonding *bond,
312+
struct slave *slave)
312313
{
313-
struct bonding *bond;
314-
struct arp_pkt *arp = (struct arp_pkt *)skb->data;
315-
int res = NET_RX_DROP;
314+
struct arp_pkt *arp;
316315

317-
while (bond_dev->priv_flags & IFF_802_1Q_VLAN)
318-
bond_dev = vlan_dev_real_dev(bond_dev);
319-
320-
if (!(bond_dev->priv_flags & IFF_BONDING) ||
321-
!(bond_dev->flags & IFF_MASTER))
322-
goto out;
316+
if (skb->protocol != cpu_to_be16(ETH_P_ARP))
317+
return;
323318

319+
arp = (struct arp_pkt *) skb->data;
324320
if (!arp) {
325321
pr_debug("Packet has no ARP data\n");
326-
goto out;
322+
return;
327323
}
328324

329-
skb = skb_share_check(skb, GFP_ATOMIC);
330-
if (!skb)
331-
goto out;
332-
333-
if (!pskb_may_pull(skb, arp_hdr_len(bond_dev)))
334-
goto out;
325+
if (!pskb_may_pull(skb, arp_hdr_len(bond->dev)))
326+
return;
335327

336328
if (skb->len < sizeof(struct arp_pkt)) {
337329
pr_debug("Packet is too small to be an ARP\n");
338-
goto out;
330+
return;
339331
}
340332

341333
if (arp->op_code == htons(ARPOP_REPLY)) {
342334
/* update rx hash table for this ARP */
343-
bond = netdev_priv(bond_dev);
344335
rlb_update_entry_from_arp(bond, arp);
345336
pr_debug("Server received an ARP Reply from client\n");
346337
}
347-
348-
res = NET_RX_SUCCESS;
349-
350-
out:
351-
dev_kfree_skb(skb);
352-
353-
return res;
354338
}
355339

356340
/* Caller must hold bond lock for read */
@@ -759,7 +743,6 @@ static void rlb_init_table_entry(struct rlb_client_info *entry)
759743
static int rlb_initialize(struct bonding *bond)
760744
{
761745
struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
762-
struct packet_type *pk_type = &(BOND_ALB_INFO(bond).rlb_pkt_type);
763746
struct rlb_client_info *new_hashtbl;
764747
int size = RLB_HASH_TABLE_SIZE * sizeof(struct rlb_client_info);
765748
int i;
@@ -784,13 +767,8 @@ static int rlb_initialize(struct bonding *bond)
784767

785768
_unlock_rx_hashtbl(bond);
786769

787-
/*initialize packet type*/
788-
pk_type->type = cpu_to_be16(ETH_P_ARP);
789-
pk_type->dev = bond->dev;
790-
pk_type->func = rlb_arp_recv;
791-
792770
/* register to receive ARPs */
793-
dev_add_pack(pk_type);
771+
bond->recv_probe = rlb_arp_recv;
794772

795773
return 0;
796774
}
@@ -799,8 +777,6 @@ static void rlb_deinitialize(struct bonding *bond)
799777
{
800778
struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
801779

802-
dev_remove_pack(&(bond_info->rlb_pkt_type));
803-
804780
_lock_rx_hashtbl(bond);
805781

806782
kfree(bond_info->rx_hashtbl);

drivers/net/bonding/bond_alb.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ struct alb_bond_info {
129129
int lp_counter;
130130
/* -------- rlb parameters -------- */
131131
int rlb_enabled;
132-
struct packet_type rlb_pkt_type;
133132
struct rlb_client_info *rx_hashtbl; /* Receive hash table */
134133
spinlock_t rx_hashtbl_lock;
135134
u32 rx_hashtbl_head;

drivers/net/bonding/bond_main.c

Lines changed: 23 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,27 +1439,17 @@ static void bond_setup_by_slave(struct net_device *bond_dev,
14391439
}
14401440

14411441
/* On bonding slaves other than the currently active slave, suppress
1442-
* duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and
1443-
* ARP on active-backup slaves with arp_validate enabled.
1442+
* duplicates except for alb non-mcast/bcast.
14441443
*/
14451444
static bool bond_should_deliver_exact_match(struct sk_buff *skb,
14461445
struct slave *slave,
14471446
struct bonding *bond)
14481447
{
14491448
if (bond_is_slave_inactive(slave)) {
1450-
if (slave_do_arp_validate(bond, slave) &&
1451-
skb->protocol == __cpu_to_be16(ETH_P_ARP))
1452-
return false;
1453-
14541449
if (bond->params.mode == BOND_MODE_ALB &&
14551450
skb->pkt_type != PACKET_BROADCAST &&
14561451
skb->pkt_type != PACKET_MULTICAST)
1457-
return false;
1458-
1459-
if (bond->params.mode == BOND_MODE_8023AD &&
1460-
skb->protocol == __cpu_to_be16(ETH_P_SLOW))
14611452
return false;
1462-
14631453
return true;
14641454
}
14651455
return false;
@@ -1483,6 +1473,15 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
14831473
if (bond->params.arp_interval)
14841474
slave->dev->last_rx = jiffies;
14851475

1476+
if (bond->recv_probe) {
1477+
struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
1478+
1479+
if (likely(nskb)) {
1480+
bond->recv_probe(nskb, bond, slave);
1481+
dev_kfree_skb(nskb);
1482+
}
1483+
}
1484+
14861485
if (bond_should_deliver_exact_match(skb, slave, bond)) {
14871486
return RX_HANDLER_EXACT;
14881487
}
@@ -2743,48 +2742,26 @@ static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32
27432742
}
27442743
}
27452744

2746-
static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
2745+
static void bond_arp_rcv(struct sk_buff *skb, struct bonding *bond,
2746+
struct slave *slave)
27472747
{
27482748
struct arphdr *arp;
2749-
struct slave *slave;
2750-
struct bonding *bond;
27512749
unsigned char *arp_ptr;
27522750
__be32 sip, tip;
27532751

2754-
if (dev->priv_flags & IFF_802_1Q_VLAN) {
2755-
/*
2756-
* When using VLANS and bonding, dev and oriv_dev may be
2757-
* incorrect if the physical interface supports VLAN
2758-
* acceleration. With this change ARP validation now
2759-
* works for hosts only reachable on the VLAN interface.
2760-
*/
2761-
dev = vlan_dev_real_dev(dev);
2762-
orig_dev = dev_get_by_index_rcu(dev_net(skb->dev),skb->skb_iif);
2763-
}
2764-
2765-
if (!(dev->priv_flags & IFF_BONDING) || !(dev->flags & IFF_MASTER))
2766-
goto out;
2752+
if (skb->protocol != __cpu_to_be16(ETH_P_ARP))
2753+
return;
27672754

2768-
bond = netdev_priv(dev);
27692755
read_lock(&bond->lock);
27702756

2771-
pr_debug("bond_arp_rcv: bond %s skb->dev %s orig_dev %s\n",
2772-
bond->dev->name, skb->dev ? skb->dev->name : "NULL",
2773-
orig_dev ? orig_dev->name : "NULL");
2757+
pr_debug("bond_arp_rcv: bond %s skb->dev %s\n",
2758+
bond->dev->name, skb->dev->name);
27742759

2775-
slave = bond_get_slave_by_dev(bond, orig_dev);
2776-
if (!slave || !slave_do_arp_validate(bond, slave))
2777-
goto out_unlock;
2778-
2779-
skb = skb_share_check(skb, GFP_ATOMIC);
2780-
if (!skb)
2781-
goto out_unlock;
2782-
2783-
if (!pskb_may_pull(skb, arp_hdr_len(dev)))
2760+
if (!pskb_may_pull(skb, arp_hdr_len(bond->dev)))
27842761
goto out_unlock;
27852762

27862763
arp = arp_hdr(skb);
2787-
if (arp->ar_hln != dev->addr_len ||
2764+
if (arp->ar_hln != bond->dev->addr_len ||
27882765
skb->pkt_type == PACKET_OTHERHOST ||
27892766
skb->pkt_type == PACKET_LOOPBACK ||
27902767
arp->ar_hrd != htons(ARPHRD_ETHER) ||
@@ -2793,9 +2770,9 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
27932770
goto out_unlock;
27942771

27952772
arp_ptr = (unsigned char *)(arp + 1);
2796-
arp_ptr += dev->addr_len;
2773+
arp_ptr += bond->dev->addr_len;
27972774
memcpy(&sip, arp_ptr, 4);
2798-
arp_ptr += 4 + dev->addr_len;
2775+
arp_ptr += 4 + bond->dev->addr_len;
27992776
memcpy(&tip, arp_ptr, 4);
28002777

28012778
pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n",
@@ -2818,9 +2795,6 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
28182795

28192796
out_unlock:
28202797
read_unlock(&bond->lock);
2821-
out:
2822-
dev_kfree_skb(skb);
2823-
return NET_RX_SUCCESS;
28242798
}
28252799

28262800
/*
@@ -3407,48 +3381,6 @@ static struct notifier_block bond_inetaddr_notifier = {
34073381
.notifier_call = bond_inetaddr_event,
34083382
};
34093383

3410-
/*-------------------------- Packet type handling ---------------------------*/
3411-
3412-
/* register to receive lacpdus on a bond */
3413-
static void bond_register_lacpdu(struct bonding *bond)
3414-
{
3415-
struct packet_type *pk_type = &(BOND_AD_INFO(bond).ad_pkt_type);
3416-
3417-
/* initialize packet type */
3418-
pk_type->type = PKT_TYPE_LACPDU;
3419-
pk_type->dev = bond->dev;
3420-
pk_type->func = bond_3ad_lacpdu_recv;
3421-
3422-
dev_add_pack(pk_type);
3423-
}
3424-
3425-
/* unregister to receive lacpdus on a bond */
3426-
static void bond_unregister_lacpdu(struct bonding *bond)
3427-
{
3428-
dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type));
3429-
}
3430-
3431-
void bond_register_arp(struct bonding *bond)
3432-
{
3433-
struct packet_type *pt = &bond->arp_mon_pt;
3434-
3435-
if (pt->type)
3436-
return;
3437-
3438-
pt->type = htons(ETH_P_ARP);
3439-
pt->dev = bond->dev;
3440-
pt->func = bond_arp_rcv;
3441-
dev_add_pack(pt);
3442-
}
3443-
3444-
void bond_unregister_arp(struct bonding *bond)
3445-
{
3446-
struct packet_type *pt = &bond->arp_mon_pt;
3447-
3448-
dev_remove_pack(pt);
3449-
pt->type = 0;
3450-
}
3451-
34523384
/*---------------------------- Hashing Policies -----------------------------*/
34533385

34543386
/*
@@ -3542,14 +3474,14 @@ static int bond_open(struct net_device *bond_dev)
35423474

35433475
queue_delayed_work(bond->wq, &bond->arp_work, 0);
35443476
if (bond->params.arp_validate)
3545-
bond_register_arp(bond);
3477+
bond->recv_probe = bond_arp_rcv;
35463478
}
35473479

35483480
if (bond->params.mode == BOND_MODE_8023AD) {
35493481
INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
35503482
queue_delayed_work(bond->wq, &bond->ad_work, 0);
35513483
/* register to receive LACPDUs */
3552-
bond_register_lacpdu(bond);
3484+
bond->recv_probe = bond_3ad_lacpdu_recv;
35533485
bond_3ad_initiate_agg_selection(bond, 1);
35543486
}
35553487

@@ -3560,14 +3492,6 @@ static int bond_close(struct net_device *bond_dev)
35603492
{
35613493
struct bonding *bond = netdev_priv(bond_dev);
35623494

3563-
if (bond->params.mode == BOND_MODE_8023AD) {
3564-
/* Unregister the receive of LACPDUs */
3565-
bond_unregister_lacpdu(bond);
3566-
}
3567-
3568-
if (bond->params.arp_validate)
3569-
bond_unregister_arp(bond);
3570-
35713495
write_lock_bh(&bond->lock);
35723496

35733497
/* signal timers not to re-arm */
@@ -3604,6 +3528,7 @@ static int bond_close(struct net_device *bond_dev)
36043528
*/
36053529
bond_alb_deinitialize(bond);
36063530
}
3531+
bond->recv_probe = NULL;
36073532

36083533
return 0;
36093534
}

drivers/net/bonding/bond_sysfs.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,6 @@ static ssize_t bonding_store_arp_validate(struct device *d,
422422
bond->dev->name, arp_validate_tbl[new_value].modename,
423423
new_value);
424424

425-
if (!bond->params.arp_validate && new_value)
426-
bond_register_arp(bond);
427-
else if (bond->params.arp_validate && !new_value)
428-
bond_unregister_arp(bond);
429-
430425
bond->params.arp_validate = new_value;
431426

432427
return count;
@@ -923,7 +918,6 @@ static ssize_t bonding_store_miimon(struct device *d,
923918
bond->dev->name);
924919
bond->params.arp_interval = 0;
925920
if (bond->params.arp_validate) {
926-
bond_unregister_arp(bond);
927921
bond->params.arp_validate =
928922
BOND_ARP_VALIDATE_NONE;
929923
}

0 commit comments

Comments
 (0)