Skip to content

Commit 5f143ef

Browse files
danobikuba-moo
authored andcommitted
bnxt_en: ethtool: Support unset l4proto on ip4/ip6 ntuple rules
Previously, trying to insert an ip4/ip6 ntuple rule with an unset l4proto would get rejected with -EOPNOTSUPP. For example, the following would fail: ethtool -N eth0 flow-type ip6 dst-ip $IP6 context 1 The reason was that all the l4proto validation was being run despite the l4proto mask being set to 0x0. Fix by respecting the mask on l4proto and treating a mask of 0x0 as wildcard l4proto. Signed-off-by: Daniel Xu <dxu@dxuuu.xyz> Reviewed-by: Michael Chan <michael.chan@broadcom.com> Link: https://patch.msgid.link/1ac93a2836b25f79e7045f8874d9a17875229ffc.1730778566.git.dxu@dxuuu.xyz Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 050eb2c commit 5f143ef

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,12 @@ static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
11241124
fkeys = &fltr->fkeys;
11251125
fmasks = &fltr->fmasks;
11261126
if (fkeys->basic.n_proto == htons(ETH_P_IP)) {
1127-
if (fkeys->basic.ip_proto == IPPROTO_ICMP) {
1127+
if (fkeys->basic.ip_proto == BNXT_IP_PROTO_WILDCARD) {
1128+
fs->flow_type = IP_USER_FLOW;
1129+
fs->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1130+
fs->h_u.usr_ip4_spec.proto = BNXT_IP_PROTO_WILDCARD;
1131+
fs->m_u.usr_ip4_spec.proto = 0;
1132+
} else if (fkeys->basic.ip_proto == IPPROTO_ICMP) {
11281133
fs->flow_type = IP_USER_FLOW;
11291134
fs->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
11301135
fs->h_u.usr_ip4_spec.proto = IPPROTO_ICMP;
@@ -1149,7 +1154,11 @@ static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
11491154
fs->m_u.tcp_ip4_spec.pdst = fmasks->ports.dst;
11501155
}
11511156
} else {
1152-
if (fkeys->basic.ip_proto == IPPROTO_ICMPV6) {
1157+
if (fkeys->basic.ip_proto == BNXT_IP_PROTO_WILDCARD) {
1158+
fs->flow_type = IPV6_USER_FLOW;
1159+
fs->h_u.usr_ip6_spec.l4_proto = BNXT_IP_PROTO_WILDCARD;
1160+
fs->m_u.usr_ip6_spec.l4_proto = 0;
1161+
} else if (fkeys->basic.ip_proto == IPPROTO_ICMPV6) {
11531162
fs->flow_type = IPV6_USER_FLOW;
11541163
fs->h_u.usr_ip6_spec.l4_proto = IPPROTO_ICMPV6;
11551164
fs->m_u.usr_ip6_spec.l4_proto = BNXT_IP_PROTO_FULL_MASK;
@@ -1274,20 +1283,24 @@ static int bnxt_add_l2_cls_rule(struct bnxt *bp,
12741283
static bool bnxt_verify_ntuple_ip4_flow(struct ethtool_usrip4_spec *ip_spec,
12751284
struct ethtool_usrip4_spec *ip_mask)
12761285
{
1286+
u8 mproto = ip_mask->proto;
1287+
u8 sproto = ip_spec->proto;
1288+
12771289
if (ip_mask->l4_4_bytes || ip_mask->tos ||
12781290
ip_spec->ip_ver != ETH_RX_NFC_IP4 ||
1279-
ip_mask->proto != BNXT_IP_PROTO_FULL_MASK ||
1280-
ip_spec->proto != IPPROTO_ICMP)
1291+
(mproto && (mproto != BNXT_IP_PROTO_FULL_MASK || sproto != IPPROTO_ICMP)))
12811292
return false;
12821293
return true;
12831294
}
12841295

12851296
static bool bnxt_verify_ntuple_ip6_flow(struct ethtool_usrip6_spec *ip_spec,
12861297
struct ethtool_usrip6_spec *ip_mask)
12871298
{
1299+
u8 mproto = ip_mask->l4_proto;
1300+
u8 sproto = ip_spec->l4_proto;
1301+
12881302
if (ip_mask->l4_4_bytes || ip_mask->tclass ||
1289-
ip_mask->l4_proto != BNXT_IP_PROTO_FULL_MASK ||
1290-
ip_spec->l4_proto != IPPROTO_ICMPV6)
1303+
(mproto && (mproto != BNXT_IP_PROTO_FULL_MASK || sproto != IPPROTO_ICMPV6)))
12911304
return false;
12921305
return true;
12931306
}
@@ -1341,7 +1354,8 @@ static int bnxt_add_ntuple_cls_rule(struct bnxt *bp,
13411354
struct ethtool_usrip4_spec *ip_spec = &fs->h_u.usr_ip4_spec;
13421355
struct ethtool_usrip4_spec *ip_mask = &fs->m_u.usr_ip4_spec;
13431356

1344-
fkeys->basic.ip_proto = ip_spec->proto;
1357+
fkeys->basic.ip_proto = ip_mask->proto ? ip_spec->proto
1358+
: BNXT_IP_PROTO_WILDCARD;
13451359
fkeys->basic.n_proto = htons(ETH_P_IP);
13461360
fkeys->addrs.v4addrs.src = ip_spec->ip4src;
13471361
fmasks->addrs.v4addrs.src = ip_mask->ip4src;
@@ -1372,7 +1386,8 @@ static int bnxt_add_ntuple_cls_rule(struct bnxt *bp,
13721386
struct ethtool_usrip6_spec *ip_spec = &fs->h_u.usr_ip6_spec;
13731387
struct ethtool_usrip6_spec *ip_mask = &fs->m_u.usr_ip6_spec;
13741388

1375-
fkeys->basic.ip_proto = ip_spec->l4_proto;
1389+
fkeys->basic.ip_proto = ip_mask->l4_proto ? ip_spec->l4_proto
1390+
: BNXT_IP_PROTO_WILDCARD;
13761391
fkeys->basic.n_proto = htons(ETH_P_IPV6);
13771392
fkeys->addrs.v6addrs.src = *(struct in6_addr *)&ip_spec->ip6src;
13781393
fmasks->addrs.v6addrs.src = *(struct in6_addr *)&ip_mask->ip6src;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct bnxt_led_cfg {
4444
#define BNXT_PXP_REG_LEN 0x3110
4545

4646
#define BNXT_IP_PROTO_FULL_MASK 0xFF
47+
#define BNXT_IP_PROTO_WILDCARD 0x0
4748

4849
extern const struct ethtool_ops bnxt_ethtool_ops;
4950

0 commit comments

Comments
 (0)