xref: /dpdk/lib/node/ip4_local.c (revision 58fbbcca1b1ef25df902c136c4ebf2752fdfa269)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2023 Marvell International Ltd.
3  */
4 
5 #include <arpa/inet.h>
6 #include <sys/socket.h>
7 
8 #include <rte_ethdev.h>
9 #include <rte_ether.h>
10 #include <rte_graph.h>
11 #include <rte_graph_worker.h>
12 #include <rte_ip.h>
13 #include <rte_lpm.h>
14 #include <rte_hash.h>
15 #include <rte_fbk_hash.h>
16 #include <rte_jhash.h>
17 #include <rte_hash_crc.h>
18 
19 #include "rte_node_ip4_api.h"
20 
21 #include "node_private.h"
22 
23 static uint16_t
ip4_local_node_process_scalar(struct rte_graph * graph,struct rte_node * node,void ** objs,uint16_t nb_objs)24 ip4_local_node_process_scalar(struct rte_graph *graph, struct rte_node *node,
25 			      void **objs, uint16_t nb_objs)
26 {
27 	void **to_next, **from;
28 	uint16_t last_spec = 0;
29 	rte_edge_t next_index;
30 	struct rte_mbuf *mbuf;
31 	uint16_t held = 0;
32 	uint32_t l4;
33 	int i;
34 
35 	/* Speculative next */
36 	next_index = RTE_NODE_IP4_LOCAL_NEXT_UDP4_INPUT;
37 
38 	from = objs;
39 	to_next = rte_node_next_stream_get(graph, node, next_index, nb_objs);
40 	for (i = 0; i < nb_objs; i++) {
41 		uint16_t next;
42 
43 		mbuf = (struct rte_mbuf *)objs[i];
44 		l4 = mbuf->packet_type & RTE_PTYPE_L4_MASK;
45 
46 		next = (l4 == RTE_PTYPE_L4_UDP)
47 				? next_index
48 				: RTE_NODE_IP4_LOCAL_NEXT_PKT_DROP;
49 
50 		if (unlikely(next_index != next)) {
51 			/* Copy things successfully speculated till now */
52 			rte_memcpy(to_next, from, last_spec * sizeof(from[0]));
53 			from += last_spec;
54 			to_next += last_spec;
55 			held += last_spec;
56 			last_spec = 0;
57 
58 			rte_node_enqueue_x1(graph, node, next, from[0]);
59 			from += 1;
60 		} else {
61 			last_spec += 1;
62 		}
63 	}
64 	/* !!! Home run !!! */
65 	if (likely(last_spec == nb_objs)) {
66 		rte_node_next_stream_move(graph, node, next_index);
67 		return nb_objs;
68 	}
69 	held += last_spec;
70 	rte_memcpy(to_next, from, last_spec * sizeof(from[0]));
71 	rte_node_next_stream_put(graph, node, next_index, held);
72 
73 	return nb_objs;
74 }
75 
76 static struct rte_node_register ip4_local_node = {
77 	.process = ip4_local_node_process_scalar,
78 	.name = "ip4_local",
79 
80 	.nb_edges = RTE_NODE_IP4_LOCAL_NEXT_PKT_DROP + 1,
81 	.next_nodes = {
82 		[RTE_NODE_IP4_LOCAL_NEXT_UDP4_INPUT] = "udp4_input",
83 		[RTE_NODE_IP4_LOCAL_NEXT_PKT_DROP] = "pkt_drop",
84 	},
85 };
86 
87 RTE_NODE_REGISTER(ip4_local_node);
88