xref: /dpdk/examples/l3fwd/l3fwd_route.h (revision 7f2a987ca852a45bdb4520edc7ad7e02c4efd269)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2021 Intel Corporation
3  */
4 
5 #include <rte_ip6.h>
6 
7 /* Log file related character defs. */
8 #define COMMENT_LEAD_CHAR	('#')
9 #define ROUTE_LEAD_CHAR		('R')
10 #define ACL_LEAD_CHAR		('@')
11 
12 #define	IPV6_ADDR_LEN	16
13 #define	IPV6_ADDR_U16	(IPV6_ADDR_LEN / sizeof(uint16_t))
14 #define	IPV6_ADDR_U32	(IPV6_ADDR_LEN / sizeof(uint32_t))
15 
16 #define GET_CB_FIELD(in, fd, base, lim, dlm)	do {            \
17 	unsigned long val;                                      \
18 	char *end;                                              \
19 	errno = 0;                                              \
20 	val = strtoul((in), &end, (base));                      \
21 	if (errno != 0 || end[0] != (dlm) || val > (lim))       \
22 		return -EINVAL;                                 \
23 	(fd) = (typeof(fd))val;                                 \
24 	(in) = end + 1;                                         \
25 } while (0)
26 
27 struct ipv4_l3fwd_route {
28 	uint32_t ip;
29 	uint8_t  depth;
30 	uint8_t  if_out;
31 };
32 
33 struct ipv6_l3fwd_route {
34 	struct rte_ipv6_addr ip;
35 	uint8_t depth;
36 	uint8_t if_out;
37 };
38 
39 struct __rte_packed_begin ipv4_5tuple {
40 	uint32_t ip_dst;
41 	uint32_t ip_src;
42 	uint16_t port_dst;
43 	uint16_t port_src;
44 	uint8_t  proto;
45 } __rte_packed_end;
46 
47 struct __rte_packed_begin ipv6_5tuple {
48 	uint8_t  ip_dst[IPV6_ADDR_LEN];
49 	uint8_t  ip_src[IPV6_ADDR_LEN];
50 	uint16_t port_dst;
51 	uint16_t port_src;
52 	uint8_t  proto;
53 } __rte_packed_end;
54 
55 struct lpm_route_rule {
56 	union {
57 		uint32_t ip;
58 		struct rte_ipv6_addr ip6;
59 	};
60 	uint8_t depth;
61 	uint8_t if_out;
62 };
63 
64 struct ipv4_l3fwd_em_route {
65 	struct ipv4_5tuple key;
66 	uint8_t if_out;
67 };
68 
69 struct ipv6_l3fwd_em_route {
70 	struct ipv6_5tuple key;
71 	uint8_t if_out;
72 };
73 
74 struct em_rule {
75 		union {
76 		struct ipv4_5tuple v4_key;
77 		struct ipv6_5tuple v6_key;
78 	};
79 	uint8_t if_out;
80 };
81 
82 extern struct lpm_route_rule *route_base_v4;
83 extern struct lpm_route_rule *route_base_v6;
84 extern int route_num_v4;
85 extern int route_num_v6;
86 
87 extern const struct ipv4_l3fwd_route ipv4_l3fwd_route_array[16];
88 extern const struct ipv6_l3fwd_route ipv6_l3fwd_route_array[16];
89 
90 extern const struct ipv4_l3fwd_em_route ipv4_l3fwd_em_route_array[16];
91 extern const struct ipv6_l3fwd_em_route ipv6_l3fwd_em_route_array[16];
92 
93 void
94 read_config_files_lpm(void);
95 
96 void
97 read_config_files_em(void);
98 
99 void
100 read_config_files_acl(void);
101 
102 void
103 em_free_routes(void);
104 
105 void
106 lpm_free_routes(void);
107 
108 void
109 acl_free_routes(void);
110 
111 void
112 l3fwd_set_alg(const char *optarg);
113 
114 void
115 l3fwd_set_rule_ipv6_name(const char *optarg);
116 
117 void
118 l3fwd_set_rule_ipv4_name(const char *optarg);
119 
120 int
121 is_bypass_line(const char *buff);
122