File: ip4_local.c

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (87 lines) | stat: -rw-r--r-- 2,071 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(C) 2023 Marvell International Ltd.
 */

#include <arpa/inet.h>
#include <sys/socket.h>

#include <rte_ethdev.h>
#include <rte_ether.h>
#include <rte_graph.h>
#include <rte_graph_worker.h>
#include <rte_ip.h>
#include <rte_lpm.h>
#include <rte_hash.h>
#include <rte_fbk_hash.h>
#include <rte_jhash.h>
#include <rte_hash_crc.h>

#include "rte_node_ip4_api.h"

#include "node_private.h"

static uint16_t
ip4_local_node_process_scalar(struct rte_graph *graph, struct rte_node *node,
			      void **objs, uint16_t nb_objs)
{
	void **to_next, **from;
	uint16_t last_spec = 0;
	rte_edge_t next_index;
	struct rte_mbuf *mbuf;
	uint16_t held = 0;
	uint32_t l4;
	int i;

	/* Speculative next */
	next_index = RTE_NODE_IP4_LOCAL_NEXT_UDP4_INPUT;

	from = objs;
	to_next = rte_node_next_stream_get(graph, node, next_index, nb_objs);
	for (i = 0; i < nb_objs; i++) {
		uint16_t next;

		mbuf = (struct rte_mbuf *)objs[i];
		l4 = mbuf->packet_type & RTE_PTYPE_L4_MASK;

		next = (l4 == RTE_PTYPE_L4_UDP)
				? next_index
				: RTE_NODE_IP4_LOCAL_NEXT_PKT_DROP;

		if (unlikely(next_index != next)) {
			/* Copy things successfully speculated till now */
			rte_memcpy(to_next, from, last_spec * sizeof(from[0]));
			from += last_spec;
			to_next += last_spec;
			held += last_spec;
			last_spec = 0;

			rte_node_enqueue_x1(graph, node, next, from[0]);
			from += 1;
		} else {
			last_spec += 1;
		}
	}
	/* !!! Home run !!! */
	if (likely(last_spec == nb_objs)) {
		rte_node_next_stream_move(graph, node, next_index);
		return nb_objs;
	}
	held += last_spec;
	rte_memcpy(to_next, from, last_spec * sizeof(from[0]));
	rte_node_next_stream_put(graph, node, next_index, held);

	return nb_objs;
}

static struct rte_node_register ip4_local_node = {
	.process = ip4_local_node_process_scalar,
	.name = "ip4_local",

	.nb_edges = RTE_NODE_IP4_LOCAL_NEXT_PKT_DROP + 1,
	.next_nodes = {
		[RTE_NODE_IP4_LOCAL_NEXT_UDP4_INPUT] = "udp4_input",
		[RTE_NODE_IP4_LOCAL_NEXT_PKT_DROP] = "pkt_drop",
	},
};

RTE_NODE_REGISTER(ip4_local_node);