Skip to content

Commit a54c4d7

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Improve ntuple filters by checking destination MAC address.
Include the destination MAC address in the ntuple filter structure. The current code assumes that the destination MAC address is always the MAC address of the NIC. This may not be true if there are macvlans, for example. Add destination MAC address checking and configure the filter correctly using the correct index for the destination MAC address. Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 59d3f1c commit a54c4d7

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,7 +3240,7 @@ static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
32403240
struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
32413241

32423242
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
3243-
req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[0];
3243+
req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
32443244

32453245
req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
32463246

@@ -6299,7 +6299,8 @@ static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
62996299
keys1->ports.ports == keys2->ports.ports &&
63006300
keys1->basic.ip_proto == keys2->basic.ip_proto &&
63016301
keys1->basic.n_proto == keys2->basic.n_proto &&
6302-
ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr))
6302+
ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
6303+
ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
63036304
return true;
63046305

63056306
return false;
@@ -6312,12 +6313,28 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
63126313
struct bnxt_ntuple_filter *fltr, *new_fltr;
63136314
struct flow_keys *fkeys;
63146315
struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
6315-
int rc = 0, idx, bit_id;
6316+
int rc = 0, idx, bit_id, l2_idx = 0;
63166317
struct hlist_head *head;
63176318

63186319
if (skb->encapsulation)
63196320
return -EPROTONOSUPPORT;
63206321

6322+
if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
6323+
struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6324+
int off = 0, j;
6325+
6326+
netif_addr_lock_bh(dev);
6327+
for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
6328+
if (ether_addr_equal(eth->h_dest,
6329+
vnic->uc_list + off)) {
6330+
l2_idx = j + 1;
6331+
break;
6332+
}
6333+
}
6334+
netif_addr_unlock_bh(dev);
6335+
if (!l2_idx)
6336+
return -EINVAL;
6337+
}
63216338
new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
63226339
if (!new_fltr)
63236340
return -ENOMEM;
@@ -6335,6 +6352,7 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
63356352
goto err_free;
63366353
}
63376354

6355+
memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
63386356
memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
63396357

63406358
idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
@@ -6360,6 +6378,7 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
63606378

63616379
new_fltr->sw_id = (u16)bit_id;
63626380
new_fltr->flow_id = flow_id;
6381+
new_fltr->l2_fltr_idx = l2_idx;
63636382
new_fltr->rxq = rxq_index;
63646383
hlist_add_head_rcu(&new_fltr->hash, head);
63656384
bp->ntp_fltr_count++;

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,12 @@ struct bnxt_pf_info {
785785

786786
struct bnxt_ntuple_filter {
787787
struct hlist_node hash;
788+
u8 dst_mac_addr[ETH_ALEN];
788789
u8 src_mac_addr[ETH_ALEN];
789790
struct flow_keys fkeys;
790791
__le64 filter_id;
791792
u16 sw_id;
793+
u8 l2_fltr_idx;
792794
u16 rxq;
793795
u32 flow_id;
794796
unsigned long state;

0 commit comments

Comments
 (0)