Skip to content

Commit c672e37

Browse files
sumang-mrvldavem330
authored andcommitted
octeontx2-pf: Add support to filter packet based on IP fragment
1. Added support to filter packets based on IP fragment. For IPv4 packets check for ip_flag == 0x20 (more fragment bit set). For IPv6 packets check for next_header == 0x2c (next_header set to 'fragment header for IPv6') 2. Added configuration support from both "ethtool ntuple" and "tc flower". Signed-off-by: Suman Ghosh <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a66d79e commit c672e37

File tree

7 files changed

+71
-4
lines changed

7 files changed

+71
-4
lines changed

drivers/net/ethernet/marvell/octeontx2/af/mbox.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,10 @@ struct flow_msg {
14401440
u8 tc;
14411441
__be16 sport;
14421442
__be16 dport;
1443+
union {
1444+
u8 ip_flag;
1445+
u8 next_header;
1446+
};
14431447
};
14441448

14451449
struct npc_install_flow_req {

drivers/net/ethernet/marvell/octeontx2/af/npc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,10 @@ enum key_fields {
185185
NPC_VLAN_ETYPE_STAG, /* 0x88A8 */
186186
NPC_OUTER_VID,
187187
NPC_TOS,
188+
NPC_IPFRAG_IPV4,
188189
NPC_SIP_IPV4,
189190
NPC_DIP_IPV4,
191+
NPC_IPFRAG_IPV6,
190192
NPC_SIP_IPV6,
191193
NPC_DIP_IPV6,
192194
NPC_IPPROTO_TCP,

drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,14 @@ static void rvu_dbg_npc_mcam_show_flows(struct seq_file *s,
27992799
seq_printf(s, "%pI6 ", rule->packet.ip6dst);
28002800
seq_printf(s, "mask %pI6\n", rule->mask.ip6dst);
28012801
break;
2802+
case NPC_IPFRAG_IPV6:
2803+
seq_printf(s, "0x%x ", rule->packet.next_header);
2804+
seq_printf(s, "mask 0x%x\n", rule->mask.next_header);
2805+
break;
2806+
case NPC_IPFRAG_IPV4:
2807+
seq_printf(s, "0x%x ", rule->packet.ip_flag);
2808+
seq_printf(s, "mask 0x%x\n", rule->mask.ip_flag);
2809+
break;
28022810
case NPC_SPORT_TCP:
28032811
case NPC_SPORT_UDP:
28042812
case NPC_SPORT_SCTP:

drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ static const char * const npc_flow_names[] = {
2626
[NPC_VLAN_ETYPE_STAG] = "vlan ether type stag",
2727
[NPC_OUTER_VID] = "outer vlan id",
2828
[NPC_TOS] = "tos",
29+
[NPC_IPFRAG_IPV4] = "fragmented IPv4 header ",
2930
[NPC_SIP_IPV4] = "ipv4 source ip",
3031
[NPC_DIP_IPV4] = "ipv4 destination ip",
32+
[NPC_IPFRAG_IPV6] = "fragmented IPv6 header ",
3133
[NPC_SIP_IPV6] = "ipv6 source ip",
3234
[NPC_DIP_IPV6] = "ipv6 destination ip",
3335
[NPC_IPPROTO_TCP] = "ip proto tcp",
@@ -484,8 +486,10 @@ do { \
484486
* Example: Source IP is 4 bytes and starts at 12th byte of IP header
485487
*/
486488
NPC_SCAN_HDR(NPC_TOS, NPC_LID_LC, NPC_LT_LC_IP, 1, 1);
489+
NPC_SCAN_HDR(NPC_IPFRAG_IPV4, NPC_LID_LC, NPC_LT_LC_IP, 6, 1);
487490
NPC_SCAN_HDR(NPC_SIP_IPV4, NPC_LID_LC, NPC_LT_LC_IP, 12, 4);
488491
NPC_SCAN_HDR(NPC_DIP_IPV4, NPC_LID_LC, NPC_LT_LC_IP, 16, 4);
492+
NPC_SCAN_HDR(NPC_IPFRAG_IPV6, NPC_LID_LC, NPC_LT_LC_IP6_EXT, 6, 1);
489493
NPC_SCAN_HDR(NPC_SIP_IPV6, NPC_LID_LC, NPC_LT_LC_IP6, 8, 16);
490494
NPC_SCAN_HDR(NPC_DIP_IPV6, NPC_LID_LC, NPC_LT_LC_IP6, 24, 16);
491495
NPC_SCAN_HDR(NPC_SPORT_UDP, NPC_LID_LD, NPC_LT_LD_UDP, 0, 2);
@@ -899,6 +903,8 @@ do { \
899903
NPC_WRITE_FLOW(NPC_ETYPE, etype, ntohs(pkt->etype), 0,
900904
ntohs(mask->etype), 0);
901905
NPC_WRITE_FLOW(NPC_TOS, tos, pkt->tos, 0, mask->tos, 0);
906+
NPC_WRITE_FLOW(NPC_IPFRAG_IPV4, ip_flag, pkt->ip_flag, 0,
907+
mask->ip_flag, 0);
902908
NPC_WRITE_FLOW(NPC_SIP_IPV4, ip4src, ntohl(pkt->ip4src), 0,
903909
ntohl(mask->ip4src), 0);
904910
NPC_WRITE_FLOW(NPC_DIP_IPV4, ip4dst, ntohl(pkt->ip4dst), 0,
@@ -919,6 +925,8 @@ do { \
919925
NPC_WRITE_FLOW(NPC_OUTER_VID, vlan_tci, ntohs(pkt->vlan_tci), 0,
920926
ntohs(mask->vlan_tci), 0);
921927

928+
NPC_WRITE_FLOW(NPC_IPFRAG_IPV6, next_header, pkt->next_header, 0,
929+
mask->next_header, 0);
922930
npc_update_ipv6_flow(rvu, entry, features, pkt, mask, output, intf);
923931
npc_update_vlan_features(rvu, entry, features, intf);
924932

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include "otx2_devlink.h"
2929
#include <rvu_trace.h>
3030

31+
/* IPv4 flag more fragment bit */
32+
#define IPV4_FLAG_MORE 0x20
33+
3134
/* PCI device IDs */
3235
#define PCI_DEVID_OCTEONTX2_RVU_PF 0xA063
3336
#define PCI_DEVID_OCTEONTX2_RVU_VF 0xA064

drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,11 @@ static int otx2_prepare_ipv6_flow(struct ethtool_rx_flow_spec *fsp,
711711
sizeof(pmask->ip6dst));
712712
req->features |= BIT_ULL(NPC_DIP_IPV6);
713713
}
714+
if (ipv6_usr_hdr->l4_proto == IPPROTO_FRAGMENT) {
715+
pkt->next_header = ipv6_usr_hdr->l4_proto;
716+
pmask->next_header = ipv6_usr_mask->l4_proto;
717+
req->features |= BIT_ULL(NPC_IPFRAG_IPV6);
718+
}
714719
pkt->etype = cpu_to_be16(ETH_P_IPV6);
715720
pmask->etype = cpu_to_be16(0xFFFF);
716721
req->features |= BIT_ULL(NPC_ETYPE);
@@ -891,10 +896,22 @@ static int otx2_prepare_flow_request(struct ethtool_rx_flow_spec *fsp,
891896
req->features |= BIT_ULL(NPC_OUTER_VID);
892897
}
893898

894-
/* Not Drop/Direct to queue but use action in default entry */
895-
if (fsp->m_ext.data[1] &&
896-
fsp->h_ext.data[1] == cpu_to_be32(OTX2_DEFAULT_ACTION))
897-
req->op = NIX_RX_ACTION_DEFAULT;
899+
if (fsp->m_ext.data[1]) {
900+
if (flow_type == IP_USER_FLOW) {
901+
if (be32_to_cpu(fsp->h_ext.data[1]) != IPV4_FLAG_MORE)
902+
return -EINVAL;
903+
904+
pkt->ip_flag = be32_to_cpu(fsp->h_ext.data[1]);
905+
pmask->ip_flag = be32_to_cpu(fsp->m_ext.data[1]);
906+
req->features |= BIT_ULL(NPC_IPFRAG_IPV4);
907+
} else if (fsp->h_ext.data[1] ==
908+
cpu_to_be32(OTX2_DEFAULT_ACTION)) {
909+
/* Not Drop/Direct to queue but use action
910+
* in default entry
911+
*/
912+
req->op = NIX_RX_ACTION_DEFAULT;
913+
}
914+
}
898915
}
899916

900917
if (fsp->flow_type & FLOW_MAC_EXT &&

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,31 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node,
532532
req->features |= BIT_ULL(NPC_IPPROTO_ICMP6);
533533
}
534534

535+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
536+
struct flow_match_control match;
537+
538+
flow_rule_match_control(rule, &match);
539+
if (match.mask->flags & FLOW_DIS_FIRST_FRAG) {
540+
NL_SET_ERR_MSG_MOD(extack, "HW doesn't support frag first/later");
541+
return -EOPNOTSUPP;
542+
}
543+
544+
if (match.mask->flags & FLOW_DIS_IS_FRAGMENT) {
545+
if (ntohs(flow_spec->etype) == ETH_P_IP) {
546+
flow_spec->ip_flag = IPV4_FLAG_MORE;
547+
flow_mask->ip_flag = 0xff;
548+
req->features |= BIT_ULL(NPC_IPFRAG_IPV4);
549+
} else if (ntohs(flow_spec->etype) == ETH_P_IPV6) {
550+
flow_spec->next_header = IPPROTO_FRAGMENT;
551+
flow_mask->next_header = 0xff;
552+
req->features |= BIT_ULL(NPC_IPFRAG_IPV6);
553+
} else {
554+
NL_SET_ERR_MSG_MOD(extack, "flow-type should be either IPv4 and IPv6");
555+
return -EOPNOTSUPP;
556+
}
557+
}
558+
}
559+
535560
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
536561
struct flow_match_eth_addrs match;
537562

0 commit comments

Comments
 (0)