Skip to content

Commit e85a9be

Browse files
CCX-Stingraydavem330
authored andcommitted
bnxt_en: do not allow wildcard matches for L2 flows
Before this patch the following commands would succeed as far as the user was concerned: $ tc qdisc add dev p1p1 ingress $ tc filter add dev p1p1 parent ffff: protocol all \ flower skip_sw action drop $ tc filter add dev p1p1 parent ffff: protocol ipv4 \ flower skip_sw src_mac 00:02:00:00:00:01/44 action drop The current flow offload infrastructure used does not support wildcard matching for ethernet headers, so do not allow the second or third commands to succeed. If a user wants to drop traffic on that interface the protocol and MAC addresses need to be specified explicitly: $ tc qdisc add dev p1p1 ingress $ tc filter add dev p1p1 parent ffff: protocol arp \ flower skip_sw action drop $ tc filter add dev p1p1 parent ffff: protocol ipv4 \ flower skip_sw action drop ... $ tc filter add dev p1p1 parent ffff: protocol ipv4 \ flower skip_sw src_mac 00:02:00:00:00:01 action drop $ tc filter add dev p1p1 parent ffff: protocol ipv4 \ flower skip_sw src_mac 00:02:00:00:00:02 action drop ... There are also checks for VLAN parameters in this patch as other callers may wildcard those parameters even if tc does not. Using different flow infrastructure could allow this to work in the future for L2 flows, but for now it does not. Fixes: 2ae7408 ("bnxt_en: bnxt: add TC flower filter offload support") Signed-off-by: Andy Gospodarek <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7991cb9 commit e85a9be

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,30 @@ static bool is_wildcard(void *mask, int len)
377377
return true;
378378
}
379379

380+
static bool is_exactmatch(void *mask, int len)
381+
{
382+
const u8 *p = mask;
383+
int i;
384+
385+
for (i = 0; i < len; i++)
386+
if (p[i] != 0xff)
387+
return false;
388+
389+
return true;
390+
}
391+
392+
static bool bits_set(void *key, int len)
393+
{
394+
const u8 *p = key;
395+
int i;
396+
397+
for (i = 0; i < len; i++)
398+
if (p[i] != 0)
399+
return true;
400+
401+
return false;
402+
}
403+
380404
static int bnxt_hwrm_cfa_flow_alloc(struct bnxt *bp, struct bnxt_tc_flow *flow,
381405
__le16 ref_flow_handle,
382406
__le32 tunnel_handle, __le16 *flow_handle)
@@ -764,6 +788,41 @@ static bool bnxt_tc_can_offload(struct bnxt *bp, struct bnxt_tc_flow *flow)
764788
return false;
765789
}
766790

791+
/* Currently source/dest MAC cannot be partial wildcard */
792+
if (bits_set(&flow->l2_key.smac, sizeof(flow->l2_key.smac)) &&
793+
!is_exactmatch(flow->l2_mask.smac, sizeof(flow->l2_mask.smac))) {
794+
netdev_info(bp->dev, "Wildcard match unsupported for Source MAC\n");
795+
return false;
796+
}
797+
if (bits_set(&flow->l2_key.dmac, sizeof(flow->l2_key.dmac)) &&
798+
!is_exactmatch(&flow->l2_mask.dmac, sizeof(flow->l2_mask.dmac))) {
799+
netdev_info(bp->dev, "Wildcard match unsupported for Dest MAC\n");
800+
return false;
801+
}
802+
803+
/* Currently VLAN fields cannot be partial wildcard */
804+
if (bits_set(&flow->l2_key.inner_vlan_tci,
805+
sizeof(flow->l2_key.inner_vlan_tci)) &&
806+
!is_exactmatch(&flow->l2_mask.inner_vlan_tci,
807+
sizeof(flow->l2_mask.inner_vlan_tci))) {
808+
netdev_info(bp->dev, "Wildcard match unsupported for VLAN TCI\n");
809+
return false;
810+
}
811+
if (bits_set(&flow->l2_key.inner_vlan_tpid,
812+
sizeof(flow->l2_key.inner_vlan_tpid)) &&
813+
!is_exactmatch(&flow->l2_mask.inner_vlan_tpid,
814+
sizeof(flow->l2_mask.inner_vlan_tpid))) {
815+
netdev_info(bp->dev, "Wildcard match unsupported for VLAN TPID\n");
816+
return false;
817+
}
818+
819+
/* Currently Ethertype must be set */
820+
if (!is_exactmatch(&flow->l2_mask.ether_type,
821+
sizeof(flow->l2_mask.ether_type))) {
822+
netdev_info(bp->dev, "Wildcard match unsupported for Ethertype\n");
823+
return false;
824+
}
825+
767826
return true;
768827
}
769828

0 commit comments

Comments
 (0)