* Create a flow rule that moves packets with matching src and dest tcp port * to the target queue. * * This function uses general flow rules and doesn't rely on the flow_isolation * that not all the FDIR capable NIC support. * * @param port_id * The selected port. * @param queue * The target queue. * @param dir * The direction of the traffic. * 1 for egress, 2 for ingress and s
| 1249 | * |
| 1250 | */ |
| 1251 | static int |
| 1252 | fdir_add_tcp_flow(uint16_t port_id, uint16_t queue, uint16_t dir, |
| 1253 | uint16_t tcp_sport, uint16_t tcp_dport) |
| 1254 | { |
| 1255 | struct rte_flow_attr attr; |
| 1256 | struct rte_flow_item flow_pattern[4]; |
| 1257 | struct rte_flow_action flow_action[2]; |
| 1258 | struct rte_flow *flow = NULL; |
| 1259 | struct rte_flow_action_queue flow_action_queue = { .index = queue }; |
| 1260 | struct rte_flow_item_tcp tcp_spec; |
| 1261 | struct rte_flow_item_tcp tcp_mask; |
| 1262 | struct rte_flow_error rfe; |
| 1263 | int res; |
| 1264 | |
| 1265 | memset(flow_pattern, 0, sizeof(flow_pattern)); |
| 1266 | memset(flow_action, 0, sizeof(flow_action)); |
| 1267 | |
| 1268 | /* |
| 1269 | * set the rule attribute. |
| 1270 | */ |
| 1271 | memset(&attr, 0, sizeof(struct rte_flow_attr)); |
| 1272 | attr.ingress = ((dir & FF_FLOW_INGRESS) > 0); |
| 1273 | attr.egress = ((dir & FF_FLOW_EGRESS) > 0); |
| 1274 | |
| 1275 | /* |
| 1276 | * create the action sequence. |
| 1277 | * one action only, move packet to queue |
| 1278 | */ |
| 1279 | flow_action[0].type = RTE_FLOW_ACTION_TYPE_QUEUE; |
| 1280 | flow_action[0].conf = &flow_action_queue; |
| 1281 | flow_action[1].type = RTE_FLOW_ACTION_TYPE_END; |
| 1282 | |
| 1283 | flow_pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; |
| 1284 | flow_pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4; |
| 1285 | |
| 1286 | /* |
| 1287 | * set the third level of the pattern (TCP). |
| 1288 | */ |
| 1289 | memset(&tcp_spec, 0, sizeof(struct rte_flow_item_tcp)); |
| 1290 | memset(&tcp_mask, 0, sizeof(struct rte_flow_item_tcp)); |
| 1291 | tcp_spec.hdr.src_port = htons(tcp_sport); |
| 1292 | tcp_mask.hdr.src_port = (tcp_sport == 0 ? 0: 0xffff); |
| 1293 | tcp_spec.hdr.dst_port = htons(tcp_dport); |
| 1294 | tcp_mask.hdr.dst_port = (tcp_dport == 0 ? 0: 0xffff); |
| 1295 | flow_pattern[2].type = RTE_FLOW_ITEM_TYPE_TCP; |
| 1296 | flow_pattern[2].spec = &tcp_spec; |
| 1297 | flow_pattern[2].mask = &tcp_mask; |
| 1298 | |
| 1299 | flow_pattern[3].type = RTE_FLOW_ITEM_TYPE_END; |
| 1300 | |
| 1301 | res = rte_flow_validate(port_id, &attr, flow_pattern, flow_action, &rfe); |
| 1302 | if (res) |
| 1303 | return (1); |
| 1304 | |
| 1305 | flow = rte_flow_create(port_id, &attr, flow_pattern, flow_action, &rfe); |
| 1306 | if (!flow) |
| 1307 | return port_flow_complain(&rfe); |
| 1308 |
no test coverage detected