Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2018 Intel Corporation
3 : : */
4 : : #include <stdlib.h>
5 : : #include <string.h>
6 : :
7 : : #include <eal_export.h>
8 : : #include <rte_common.h>
9 : : #include <rte_byteorder.h>
10 : : #include <rte_cycles.h>
11 : : #include <rte_malloc.h>
12 : : #include <rte_memcpy.h>
13 : : #include <rte_ether.h>
14 : : #include <rte_ip.h>
15 : : #include <rte_tcp.h>
16 : : #include <rte_udp.h>
17 : : #include <rte_vxlan.h>
18 : : #include <rte_cryptodev.h>
19 : :
20 : : #include "rte_table_action.h"
21 : :
22 : : #define rte_htons rte_cpu_to_be_16
23 : : #define rte_htonl rte_cpu_to_be_32
24 : :
25 : : #define rte_ntohs rte_be_to_cpu_16
26 : : #define rte_ntohl rte_be_to_cpu_32
27 : :
28 : : /**
29 : : * RTE_TABLE_ACTION_FWD
30 : : */
31 : : #define fwd_data rte_pipeline_table_entry
32 : :
33 : : static int
34 : : fwd_apply(struct fwd_data *data,
35 : : struct rte_table_action_fwd_params *p)
36 : : {
37 : 0 : data->action = p->action;
38 : :
39 [ # # ]: 0 : if (p->action == RTE_PIPELINE_ACTION_PORT)
40 : 0 : data->port_id = p->id;
41 : :
42 [ # # ]: 0 : if (p->action == RTE_PIPELINE_ACTION_TABLE)
43 : 0 : data->table_id = p->id;
44 : :
45 : : return 0;
46 : : }
47 : :
48 : : /**
49 : : * RTE_TABLE_ACTION_LB
50 : : */
51 : : static int
52 : : lb_cfg_check(struct rte_table_action_lb_config *cfg)
53 : : {
54 [ # # ]: 0 : if ((cfg == NULL) ||
55 [ # # # # ]: 0 : (cfg->key_size < RTE_TABLE_ACTION_LB_KEY_SIZE_MIN) ||
56 : : (cfg->key_size > RTE_TABLE_ACTION_LB_KEY_SIZE_MAX) ||
57 : 0 : (!rte_is_power_of_2(cfg->key_size)) ||
58 [ # # ]: 0 : (cfg->f_hash == NULL))
59 : : return -1;
60 : :
61 : : return 0;
62 : : }
63 : :
64 : : struct __rte_packed_begin lb_data {
65 : : uint32_t out[RTE_TABLE_ACTION_LB_TABLE_SIZE];
66 : : } __rte_packed_end;
67 : :
68 : : static int
69 : : lb_apply(struct lb_data *data,
70 : : struct rte_table_action_lb_params *p)
71 : : {
72 : 0 : memcpy(data->out, p->out, sizeof(data->out));
73 : :
74 : : return 0;
75 : : }
76 : :
77 : : static __rte_always_inline void
78 : : pkt_work_lb(struct rte_mbuf *mbuf,
79 : : struct lb_data *data,
80 : : struct rte_table_action_lb_config *cfg)
81 : : {
82 : 0 : uint8_t *pkt_key = RTE_MBUF_METADATA_UINT8_PTR(mbuf, cfg->key_offset);
83 : 0 : uint32_t *out = RTE_MBUF_METADATA_UINT32_PTR(mbuf, cfg->out_offset);
84 : : uint64_t digest, pos;
85 : : uint32_t out_val;
86 : :
87 : 0 : digest = cfg->f_hash(pkt_key,
88 : 0 : cfg->key_mask,
89 : : cfg->key_size,
90 : : cfg->seed);
91 : 0 : pos = digest & (RTE_TABLE_ACTION_LB_TABLE_SIZE - 1);
92 : 0 : out_val = data->out[pos];
93 : :
94 : 0 : *out = out_val;
95 : 0 : }
96 : :
97 : : /**
98 : : * RTE_TABLE_ACTION_MTR
99 : : */
100 : : static int
101 : : mtr_cfg_check(struct rte_table_action_mtr_config *mtr)
102 : : {
103 [ # # ]: 0 : if ((mtr->alg == RTE_TABLE_ACTION_METER_SRTCM) ||
104 [ # # ]: 0 : ((mtr->n_tc != 1) && (mtr->n_tc != 4)) ||
105 [ # # ]: 0 : (mtr->n_bytes_enabled != 0))
106 : : return -ENOTSUP;
107 : : return 0;
108 : : }
109 : :
110 : : struct mtr_trtcm_data {
111 : : struct rte_meter_trtcm trtcm;
112 : : uint64_t stats[RTE_COLORS];
113 : : };
114 : :
115 : : #define MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data) \
116 : : (((data)->stats[RTE_COLOR_GREEN] & 0xF8LLU) >> 3)
117 : :
118 : : static void
119 : : mtr_trtcm_data_meter_profile_id_set(struct mtr_trtcm_data *data,
120 : : uint32_t profile_id)
121 : : {
122 : 0 : data->stats[RTE_COLOR_GREEN] &= ~0xF8LLU;
123 : 0 : data->stats[RTE_COLOR_GREEN] |= (profile_id % 32) << 3;
124 : : }
125 : :
126 : : #define MTR_TRTCM_DATA_POLICER_ACTION_DROP_GET(data, color)\
127 : : (((data)->stats[(color)] & 4LLU) >> 2)
128 : :
129 : : #define MTR_TRTCM_DATA_POLICER_ACTION_COLOR_GET(data, color)\
130 : : ((enum rte_color)((data)->stats[(color)] & 3LLU))
131 : :
132 : : static void
133 : : mtr_trtcm_data_policer_action_set(struct mtr_trtcm_data *data,
134 : : enum rte_color color,
135 : : enum rte_table_action_policer action)
136 : : {
137 : 0 : if (action == RTE_TABLE_ACTION_POLICER_DROP) {
138 : 0 : data->stats[color] |= 4LLU;
139 : : } else {
140 : 0 : data->stats[color] &= ~7LLU;
141 : 0 : data->stats[color] |= color & 3LLU;
142 : : }
143 : : }
144 : :
145 : : static uint64_t
146 : : mtr_trtcm_data_stats_get(struct mtr_trtcm_data *data,
147 : : enum rte_color color)
148 : : {
149 : 0 : return data->stats[color] >> 8;
150 : : }
151 : :
152 : : static void
153 : : mtr_trtcm_data_stats_reset(struct mtr_trtcm_data *data,
154 : : enum rte_color color)
155 : : {
156 : 0 : data->stats[color] &= 0xFFLU;
157 : 0 : }
158 : :
159 : : #define MTR_TRTCM_DATA_STATS_INC(data, color) \
160 : : ((data)->stats[(color)] += (1LLU << 8))
161 : :
162 : : static size_t
163 : : mtr_data_size(struct rte_table_action_mtr_config *mtr)
164 : : {
165 : 0 : return mtr->n_tc * sizeof(struct mtr_trtcm_data);
166 : : }
167 : :
168 : : struct dscp_table_entry_data {
169 : : enum rte_color color;
170 : : uint16_t tc;
171 : : uint16_t tc_queue;
172 : : };
173 : :
174 : : struct dscp_table_data {
175 : : struct dscp_table_entry_data entry[64];
176 : : };
177 : :
178 : : struct meter_profile_data {
179 : : struct rte_meter_trtcm_profile profile;
180 : : uint32_t profile_id;
181 : : int valid;
182 : : };
183 : :
184 : : static struct meter_profile_data *
185 : : meter_profile_data_find(struct meter_profile_data *mp,
186 : : uint32_t mp_size,
187 : : uint32_t profile_id)
188 : : {
189 : : uint32_t i;
190 : :
191 [ # # # # : 0 : for (i = 0; i < mp_size; i++) {
# # # # ]
192 : 0 : struct meter_profile_data *mp_data = &mp[i];
193 : :
194 [ # # # # : 0 : if (mp_data->valid && (mp_data->profile_id == profile_id))
# # # # #
# # # # #
# # ]
195 : : return mp_data;
196 : : }
197 : :
198 : : return NULL;
199 : : }
200 : :
201 : : static struct meter_profile_data *
202 : : meter_profile_data_find_unused(struct meter_profile_data *mp,
203 : : uint32_t mp_size)
204 : : {
205 : : uint32_t i;
206 : :
207 [ # # ]: 0 : for (i = 0; i < mp_size; i++) {
208 : 0 : struct meter_profile_data *mp_data = &mp[i];
209 : :
210 [ # # ]: 0 : if (!mp_data->valid)
211 : : return mp_data;
212 : : }
213 : :
214 : : return NULL;
215 : : }
216 : :
217 : : static int
218 : 0 : mtr_apply_check(struct rte_table_action_mtr_params *p,
219 : : struct rte_table_action_mtr_config *cfg,
220 : : struct meter_profile_data *mp,
221 : : uint32_t mp_size)
222 : : {
223 : : uint32_t i;
224 : :
225 [ # # ]: 0 : if (p->tc_mask > RTE_LEN2MASK(cfg->n_tc, uint32_t))
226 : : return -EINVAL;
227 : :
228 [ # # ]: 0 : for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
229 : : struct rte_table_action_mtr_tc_params *p_tc = &p->mtr[i];
230 : : struct meter_profile_data *mp_data;
231 : :
232 [ # # ]: 0 : if ((p->tc_mask & (1LLU << i)) == 0)
233 : 0 : continue;
234 : :
235 : 0 : mp_data = meter_profile_data_find(mp,
236 : : mp_size,
237 : : p_tc->meter_profile_id);
238 [ # # ]: 0 : if (!mp_data)
239 : : return -EINVAL;
240 : : }
241 : :
242 : : return 0;
243 : : }
244 : :
245 : : static int
246 : 0 : mtr_apply(struct mtr_trtcm_data *data,
247 : : struct rte_table_action_mtr_params *p,
248 : : struct rte_table_action_mtr_config *cfg,
249 : : struct meter_profile_data *mp,
250 : : uint32_t mp_size)
251 : : {
252 : : uint32_t i;
253 : : int status;
254 : :
255 : : /* Check input arguments */
256 : 0 : status = mtr_apply_check(p, cfg, mp, mp_size);
257 [ # # ]: 0 : if (status)
258 : : return status;
259 : :
260 : : /* Apply */
261 [ # # ]: 0 : for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
262 : : struct rte_table_action_mtr_tc_params *p_tc = &p->mtr[i];
263 : 0 : struct mtr_trtcm_data *data_tc = &data[i];
264 : : struct meter_profile_data *mp_data;
265 : :
266 [ # # ]: 0 : if ((p->tc_mask & (1LLU << i)) == 0)
267 : 0 : continue;
268 : :
269 : : /* Find profile */
270 : 0 : mp_data = meter_profile_data_find(mp,
271 : : mp_size,
272 : : p_tc->meter_profile_id);
273 [ # # ]: 0 : if (!mp_data)
274 : : return -EINVAL;
275 : :
276 : : memset(data_tc, 0, sizeof(*data_tc));
277 : :
278 : : /* Meter object */
279 : 0 : status = rte_meter_trtcm_config(&data_tc->trtcm,
280 : : &mp_data->profile);
281 [ # # ]: 0 : if (status)
282 : 0 : return status;
283 : :
284 : : /* Meter profile */
285 : 0 : mtr_trtcm_data_meter_profile_id_set(data_tc,
286 : 0 : mp_data - mp);
287 : :
288 : : /* Policer actions */
289 [ # # ]: 0 : mtr_trtcm_data_policer_action_set(data_tc,
290 : : RTE_COLOR_GREEN,
291 : : p_tc->policer[RTE_COLOR_GREEN]);
292 : :
293 [ # # ]: 0 : mtr_trtcm_data_policer_action_set(data_tc,
294 : : RTE_COLOR_YELLOW,
295 : : p_tc->policer[RTE_COLOR_YELLOW]);
296 : :
297 [ # # ]: 0 : mtr_trtcm_data_policer_action_set(data_tc,
298 : : RTE_COLOR_RED,
299 : : p_tc->policer[RTE_COLOR_RED]);
300 : : }
301 : :
302 : : return 0;
303 : : }
304 : :
305 : : static __rte_always_inline uint64_t
306 : : pkt_work_mtr(struct rte_mbuf *mbuf,
307 : : struct mtr_trtcm_data *data,
308 : : struct dscp_table_data *dscp_table,
309 : : struct meter_profile_data *mp,
310 : : uint64_t time,
311 : : uint32_t dscp,
312 : : uint16_t total_length)
313 : : {
314 : : uint64_t drop_mask;
315 : : struct dscp_table_entry_data *dscp_entry = &dscp_table->entry[dscp];
316 : : enum rte_color color_in, color_meter, color_policer;
317 : : uint32_t tc, mp_id;
318 : :
319 : 0 : tc = dscp_entry->tc;
320 : 0 : color_in = dscp_entry->color;
321 : 0 : data += tc;
322 : 0 : mp_id = MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data);
323 : :
324 : : /* Meter */
325 : 0 : color_meter = rte_meter_trtcm_color_aware_check(
326 : : &data->trtcm,
327 : 0 : &mp[mp_id].profile,
328 : : time,
329 : : total_length,
330 : : color_in);
331 : :
332 : : /* Stats */
333 : 0 : MTR_TRTCM_DATA_STATS_INC(data, color_meter);
334 : :
335 : : /* Police */
336 : 0 : drop_mask = MTR_TRTCM_DATA_POLICER_ACTION_DROP_GET(data, color_meter);
337 : 0 : color_policer =
338 : 0 : MTR_TRTCM_DATA_POLICER_ACTION_COLOR_GET(data, color_meter);
339 : 0 : rte_mbuf_sched_color_set(mbuf, (uint8_t)color_policer);
340 : :
341 : : return drop_mask;
342 : : }
343 : :
344 : : /**
345 : : * RTE_TABLE_ACTION_TM
346 : : */
347 : : static int
348 : : tm_cfg_check(struct rte_table_action_tm_config *tm)
349 : : {
350 [ # # ]: 0 : if ((tm->n_subports_per_port == 0) ||
351 [ # # ]: 0 : (rte_is_power_of_2(tm->n_subports_per_port) == 0) ||
352 : 0 : (tm->n_subports_per_port > UINT16_MAX) ||
353 [ # # ]: 0 : (tm->n_pipes_per_subport == 0) ||
354 : : (rte_is_power_of_2(tm->n_pipes_per_subport) == 0))
355 : : return -ENOTSUP;
356 : :
357 : : return 0;
358 : : }
359 : :
360 : : struct __rte_packed_begin tm_data {
361 : : uint32_t queue_id;
362 : : uint32_t reserved;
363 : : } __rte_packed_end;
364 : :
365 : : static int
366 : : tm_apply_check(struct rte_table_action_tm_params *p,
367 : : struct rte_table_action_tm_config *cfg)
368 : : {
369 : 0 : if ((p->subport_id >= cfg->n_subports_per_port) ||
370 [ # # ]: 0 : (p->pipe_id >= cfg->n_pipes_per_subport))
371 : : return -EINVAL;
372 : :
373 : : return 0;
374 : : }
375 : :
376 : : static int
377 : : tm_apply(struct tm_data *data,
378 : : struct rte_table_action_tm_params *p,
379 : : struct rte_table_action_tm_config *cfg)
380 : : {
381 : : int status;
382 : :
383 : : /* Check input arguments */
384 : : status = tm_apply_check(p, cfg);
385 : : if (status)
386 : : return status;
387 : :
388 : : /* Apply */
389 : 0 : data->queue_id = p->subport_id <<
390 : 0 : (rte_ctz32(cfg->n_pipes_per_subport) + 4) |
391 : 0 : p->pipe_id << 4;
392 : :
393 : 0 : return 0;
394 : : }
395 : :
396 : : static __rte_always_inline void
397 : : pkt_work_tm(struct rte_mbuf *mbuf,
398 : : struct tm_data *data,
399 : : struct dscp_table_data *dscp_table,
400 : : uint32_t dscp)
401 : : {
402 : : struct dscp_table_entry_data *dscp_entry = &dscp_table->entry[dscp];
403 : 0 : uint32_t queue_id = data->queue_id |
404 : 0 : dscp_entry->tc_queue;
405 : 0 : rte_mbuf_sched_set(mbuf, queue_id, dscp_entry->tc,
406 : 0 : (uint8_t)dscp_entry->color);
407 : 0 : }
408 : :
409 : : /**
410 : : * RTE_TABLE_ACTION_ENCAP
411 : : */
412 : : static int
413 : : encap_valid(enum rte_table_action_encap_type encap)
414 : : {
415 : 0 : switch (encap) {
416 : : case RTE_TABLE_ACTION_ENCAP_ETHER:
417 : : case RTE_TABLE_ACTION_ENCAP_VLAN:
418 : : case RTE_TABLE_ACTION_ENCAP_QINQ:
419 : : case RTE_TABLE_ACTION_ENCAP_MPLS:
420 : : case RTE_TABLE_ACTION_ENCAP_PPPOE:
421 : : case RTE_TABLE_ACTION_ENCAP_VXLAN:
422 : : case RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
423 : : return 1;
424 : : default:
425 : : return 0;
426 : : }
427 : : }
428 : :
429 : : static int
430 : : encap_cfg_check(struct rte_table_action_encap_config *encap)
431 : : {
432 [ # # # # ]: 0 : if ((encap->encap_mask == 0) ||
433 : : (rte_popcount64(encap->encap_mask) != 1))
434 : : return -ENOTSUP;
435 : :
436 : : return 0;
437 : : }
438 : :
439 : : struct encap_ether_data {
440 : : struct rte_ether_hdr ether;
441 : : };
442 : :
443 : : #define VLAN(pcp, dei, vid) \
444 : : ((uint16_t)((((uint64_t)(pcp)) & 0x7LLU) << 13) | \
445 : : ((((uint64_t)(dei)) & 0x1LLU) << 12) | \
446 : : (((uint64_t)(vid)) & 0xFFFLLU)) \
447 : :
448 : : struct encap_vlan_data {
449 : : struct rte_ether_hdr ether;
450 : : struct rte_vlan_hdr vlan;
451 : : };
452 : :
453 : : struct encap_qinq_data {
454 : : struct rte_ether_hdr ether;
455 : : struct rte_vlan_hdr svlan;
456 : : struct rte_vlan_hdr cvlan;
457 : : };
458 : :
459 : : #define ETHER_TYPE_MPLS_UNICAST 0x8847
460 : :
461 : : #define ETHER_TYPE_MPLS_MULTICAST 0x8848
462 : :
463 : : #define MPLS(label, tc, s, ttl) \
464 : : ((uint32_t)(((((uint64_t)(label)) & 0xFFFFFLLU) << 12) |\
465 : : ((((uint64_t)(tc)) & 0x7LLU) << 9) | \
466 : : ((((uint64_t)(s)) & 0x1LLU) << 8) | \
467 : : (((uint64_t)(ttl)) & 0xFFLLU)))
468 : :
469 : : struct __rte_aligned(2) __rte_packed_begin encap_mpls_data {
470 : : struct rte_ether_hdr ether;
471 : : uint32_t mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
472 : : uint32_t mpls_count;
473 : : } __rte_packed_end;
474 : :
475 : : #define PPP_PROTOCOL_IP 0x0021
476 : :
477 : : struct pppoe_ppp_hdr {
478 : : uint16_t ver_type_code;
479 : : uint16_t session_id;
480 : : uint16_t length;
481 : : uint16_t protocol;
482 : : };
483 : :
484 : : struct encap_pppoe_data {
485 : : struct rte_ether_hdr ether;
486 : : struct pppoe_ppp_hdr pppoe_ppp;
487 : : };
488 : :
489 : : #define IP_PROTO_UDP 17
490 : :
491 : : struct __rte_aligned(2) __rte_packed_begin encap_vxlan_ipv4_data {
492 : : struct rte_ether_hdr ether;
493 : : struct rte_ipv4_hdr ipv4;
494 : : struct rte_udp_hdr udp;
495 : : struct rte_vxlan_hdr vxlan;
496 : : } __rte_packed_end;
497 : :
498 : : struct __rte_aligned(2) __rte_packed_begin encap_vxlan_ipv4_vlan_data {
499 : : struct rte_ether_hdr ether;
500 : : struct rte_vlan_hdr vlan;
501 : : struct rte_ipv4_hdr ipv4;
502 : : struct rte_udp_hdr udp;
503 : : struct rte_vxlan_hdr vxlan;
504 : : } __rte_packed_end;
505 : :
506 : : struct __rte_aligned(2) __rte_packed_begin encap_vxlan_ipv6_data {
507 : : struct rte_ether_hdr ether;
508 : : struct rte_ipv6_hdr ipv6;
509 : : struct rte_udp_hdr udp;
510 : : struct rte_vxlan_hdr vxlan;
511 : : } __rte_packed_end;
512 : :
513 : : struct __rte_aligned(2) __rte_packed_begin encap_vxlan_ipv6_vlan_data {
514 : : struct rte_ether_hdr ether;
515 : : struct rte_vlan_hdr vlan;
516 : : struct rte_ipv6_hdr ipv6;
517 : : struct rte_udp_hdr udp;
518 : : struct rte_vxlan_hdr vxlan;
519 : : } __rte_packed_end;
520 : :
521 : : struct __rte_aligned(2) __rte_packed_begin encap_qinq_pppoe_data {
522 : : struct rte_ether_hdr ether;
523 : : struct rte_vlan_hdr svlan;
524 : : struct rte_vlan_hdr cvlan;
525 : : struct pppoe_ppp_hdr pppoe_ppp;
526 : : } __rte_packed_end;
527 : :
528 : : static size_t
529 : 0 : encap_data_size(struct rte_table_action_encap_config *encap)
530 : : {
531 [ # # # # : 0 : switch (encap->encap_mask) {
# # # # ]
532 : : case 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER:
533 : : return sizeof(struct encap_ether_data);
534 : :
535 : 0 : case 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN:
536 : 0 : return sizeof(struct encap_vlan_data);
537 : :
538 : 0 : case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ:
539 : 0 : return sizeof(struct encap_qinq_data);
540 : :
541 : 0 : case 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS:
542 : 0 : return sizeof(struct encap_mpls_data);
543 : :
544 : 0 : case 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE:
545 : 0 : return sizeof(struct encap_pppoe_data);
546 : :
547 : 0 : case 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN:
548 [ # # ]: 0 : if (encap->vxlan.ip_version)
549 [ # # ]: 0 : if (encap->vxlan.vlan)
550 : : return sizeof(struct encap_vxlan_ipv4_vlan_data);
551 : : else
552 : 0 : return sizeof(struct encap_vxlan_ipv4_data);
553 : : else
554 [ # # ]: 0 : if (encap->vxlan.vlan)
555 : : return sizeof(struct encap_vxlan_ipv6_vlan_data);
556 : : else
557 : 0 : return sizeof(struct encap_vxlan_ipv6_data);
558 : :
559 : 0 : case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
560 : 0 : return sizeof(struct encap_qinq_pppoe_data);
561 : :
562 : 0 : default:
563 : 0 : return 0;
564 : : }
565 : : }
566 : :
567 : : static int
568 : : encap_apply_check(struct rte_table_action_encap_params *p,
569 : : struct rte_table_action_encap_config *cfg)
570 : : {
571 : 0 : if ((encap_valid(p->type) == 0) ||
572 [ # # ]: 0 : ((cfg->encap_mask & (1LLU << p->type)) == 0))
573 : : return -EINVAL;
574 : :
575 [ # # ]: 0 : switch (p->type) {
576 : : case RTE_TABLE_ACTION_ENCAP_ETHER:
577 : : return 0;
578 : :
579 : : case RTE_TABLE_ACTION_ENCAP_VLAN:
580 : : return 0;
581 : :
582 : : case RTE_TABLE_ACTION_ENCAP_QINQ:
583 : : return 0;
584 : :
585 : 0 : case RTE_TABLE_ACTION_ENCAP_MPLS:
586 [ # # ]: 0 : if ((p->mpls.mpls_count == 0) ||
587 : : (p->mpls.mpls_count > RTE_TABLE_ACTION_MPLS_LABELS_MAX))
588 : : return -EINVAL;
589 : :
590 : : return 0;
591 : :
592 : : case RTE_TABLE_ACTION_ENCAP_PPPOE:
593 : : return 0;
594 : :
595 : : case RTE_TABLE_ACTION_ENCAP_VXLAN:
596 : : return 0;
597 : :
598 : : case RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
599 : : return 0;
600 : :
601 : : default:
602 : : return -EINVAL;
603 : : }
604 : : }
605 : :
606 : : static int
607 : : encap_ether_apply(void *data,
608 : : struct rte_table_action_encap_params *p,
609 : : struct rte_table_action_common_config *common_cfg)
610 : : {
611 : : struct encap_ether_data *d = data;
612 [ # # ]: 0 : uint16_t ethertype = (common_cfg->ip_version) ?
613 : : RTE_ETHER_TYPE_IPV4 :
614 : : RTE_ETHER_TYPE_IPV6;
615 : :
616 : : /* Ethernet */
617 : : rte_ether_addr_copy(&p->ether.ether.da, &d->ether.dst_addr);
618 : : rte_ether_addr_copy(&p->ether.ether.sa, &d->ether.src_addr);
619 [ # # ]: 0 : d->ether.ether_type = rte_htons(ethertype);
620 : :
621 : : return 0;
622 : : }
623 : :
624 : : static int
625 : 0 : encap_vlan_apply(void *data,
626 : : struct rte_table_action_encap_params *p,
627 : : struct rte_table_action_common_config *common_cfg)
628 : : {
629 : : struct encap_vlan_data *d = data;
630 [ # # ]: 0 : uint16_t ethertype = (common_cfg->ip_version) ?
631 : : RTE_ETHER_TYPE_IPV4 :
632 : : RTE_ETHER_TYPE_IPV6;
633 : :
634 : : /* Ethernet */
635 : : rte_ether_addr_copy(&p->vlan.ether.da, &d->ether.dst_addr);
636 : : rte_ether_addr_copy(&p->vlan.ether.sa, &d->ether.src_addr);
637 : 0 : d->ether.ether_type = rte_htons(RTE_ETHER_TYPE_VLAN);
638 : :
639 : : /* VLAN */
640 [ # # ]: 0 : d->vlan.vlan_tci = rte_htons(VLAN(p->vlan.vlan.pcp,
641 : : p->vlan.vlan.dei,
642 : : p->vlan.vlan.vid));
643 [ # # ]: 0 : d->vlan.eth_proto = rte_htons(ethertype);
644 : :
645 : 0 : return 0;
646 : : }
647 : :
648 : : static int
649 : 0 : encap_qinq_apply(void *data,
650 : : struct rte_table_action_encap_params *p,
651 : : struct rte_table_action_common_config *common_cfg)
652 : : {
653 : : struct encap_qinq_data *d = data;
654 [ # # ]: 0 : uint16_t ethertype = (common_cfg->ip_version) ?
655 : : RTE_ETHER_TYPE_IPV4 :
656 : : RTE_ETHER_TYPE_IPV6;
657 : :
658 : : /* Ethernet */
659 : : rte_ether_addr_copy(&p->qinq.ether.da, &d->ether.dst_addr);
660 : : rte_ether_addr_copy(&p->qinq.ether.sa, &d->ether.src_addr);
661 : 0 : d->ether.ether_type = rte_htons(RTE_ETHER_TYPE_QINQ);
662 : :
663 : : /* SVLAN */
664 [ # # ]: 0 : d->svlan.vlan_tci = rte_htons(VLAN(p->qinq.svlan.pcp,
665 : : p->qinq.svlan.dei,
666 : : p->qinq.svlan.vid));
667 : 0 : d->svlan.eth_proto = rte_htons(RTE_ETHER_TYPE_VLAN);
668 : :
669 : : /* CVLAN */
670 [ # # ]: 0 : d->cvlan.vlan_tci = rte_htons(VLAN(p->qinq.cvlan.pcp,
671 : : p->qinq.cvlan.dei,
672 : : p->qinq.cvlan.vid));
673 [ # # ]: 0 : d->cvlan.eth_proto = rte_htons(ethertype);
674 : :
675 : 0 : return 0;
676 : : }
677 : :
678 : : static int
679 [ # # ]: 0 : encap_qinq_pppoe_apply(void *data,
680 : : struct rte_table_action_encap_params *p)
681 : : {
682 : : struct encap_qinq_pppoe_data *d = data;
683 : :
684 : : /* Ethernet */
685 : : rte_ether_addr_copy(&p->qinq.ether.da, &d->ether.dst_addr);
686 : : rte_ether_addr_copy(&p->qinq.ether.sa, &d->ether.src_addr);
687 : 0 : d->ether.ether_type = rte_htons(RTE_ETHER_TYPE_VLAN);
688 : :
689 : : /* SVLAN */
690 [ # # ]: 0 : d->svlan.vlan_tci = rte_htons(VLAN(p->qinq.svlan.pcp,
691 : : p->qinq.svlan.dei,
692 : : p->qinq.svlan.vid));
693 : 0 : d->svlan.eth_proto = rte_htons(RTE_ETHER_TYPE_VLAN);
694 : :
695 : : /* CVLAN */
696 [ # # ]: 0 : d->cvlan.vlan_tci = rte_htons(VLAN(p->qinq.cvlan.pcp,
697 : : p->qinq.cvlan.dei,
698 : : p->qinq.cvlan.vid));
699 : 0 : d->cvlan.eth_proto = rte_htons(RTE_ETHER_TYPE_PPPOE_SESSION);
700 : :
701 : : /* PPPoE and PPP*/
702 : 0 : d->pppoe_ppp.ver_type_code = rte_htons(0x1100);
703 [ # # ]: 0 : d->pppoe_ppp.session_id = rte_htons(p->qinq_pppoe.pppoe.session_id);
704 : 0 : d->pppoe_ppp.length = 0; /* not pre-computed */
705 : 0 : d->pppoe_ppp.protocol = rte_htons(PPP_PROTOCOL_IP);
706 : :
707 : 0 : return 0;
708 : : }
709 : :
710 : : static int
711 : 0 : encap_mpls_apply(void *data,
712 : : struct rte_table_action_encap_params *p)
713 : : {
714 : : struct encap_mpls_data *d = data;
715 [ # # ]: 0 : uint16_t ethertype = (p->mpls.unicast) ?
716 : : ETHER_TYPE_MPLS_UNICAST :
717 : : ETHER_TYPE_MPLS_MULTICAST;
718 : : uint32_t i;
719 : :
720 : : /* Ethernet */
721 : : rte_ether_addr_copy(&p->mpls.ether.da, &d->ether.dst_addr);
722 : : rte_ether_addr_copy(&p->mpls.ether.sa, &d->ether.src_addr);
723 [ # # ]: 0 : d->ether.ether_type = rte_htons(ethertype);
724 : :
725 : : /* MPLS */
726 [ # # ]: 0 : for (i = 0; i < p->mpls.mpls_count - 1; i++)
727 [ # # ]: 0 : d->mpls[i] = rte_htonl(MPLS(p->mpls.mpls[i].label,
728 : : p->mpls.mpls[i].tc,
729 : : 0,
730 : : p->mpls.mpls[i].ttl));
731 : :
732 [ # # ]: 0 : d->mpls[i] = rte_htonl(MPLS(p->mpls.mpls[i].label,
733 : : p->mpls.mpls[i].tc,
734 : : 1,
735 : : p->mpls.mpls[i].ttl));
736 : :
737 : 0 : d->mpls_count = p->mpls.mpls_count;
738 : 0 : return 0;
739 : : }
740 : :
741 : : static int
742 : : encap_pppoe_apply(void *data,
743 : : struct rte_table_action_encap_params *p)
744 : : {
745 : : struct encap_pppoe_data *d = data;
746 : :
747 : : /* Ethernet */
748 : : rte_ether_addr_copy(&p->pppoe.ether.da, &d->ether.dst_addr);
749 : : rte_ether_addr_copy(&p->pppoe.ether.sa, &d->ether.src_addr);
750 : 0 : d->ether.ether_type = rte_htons(RTE_ETHER_TYPE_PPPOE_SESSION);
751 : :
752 : : /* PPPoE and PPP*/
753 : 0 : d->pppoe_ppp.ver_type_code = rte_htons(0x1100);
754 [ # # ]: 0 : d->pppoe_ppp.session_id = rte_htons(p->pppoe.pppoe.session_id);
755 : 0 : d->pppoe_ppp.length = 0; /* not pre-computed */
756 : 0 : d->pppoe_ppp.protocol = rte_htons(PPP_PROTOCOL_IP);
757 : :
758 : : return 0;
759 : : }
760 : :
761 : : static int
762 : 0 : encap_vxlan_apply(void *data,
763 : : struct rte_table_action_encap_params *p,
764 : : struct rte_table_action_encap_config *cfg)
765 : : {
766 [ # # ]: 0 : if ((p->vxlan.vxlan.vni > 0xFFFFFF) ||
767 [ # # # # : 0 : (cfg->vxlan.ip_version && (p->vxlan.ipv4.dscp > 0x3F)) ||
# # ]
768 [ # # # # ]: 0 : (!cfg->vxlan.ip_version && (p->vxlan.ipv6.flow_label > 0xFFFFF)) ||
769 [ # # ]: 0 : (!cfg->vxlan.ip_version && (p->vxlan.ipv6.dscp > 0x3F)) ||
770 [ # # # # ]: 0 : (cfg->vxlan.vlan && (p->vxlan.vlan.vid > 0xFFF)))
771 : : return -1;
772 : :
773 [ # # ]: 0 : if (cfg->vxlan.ip_version)
774 [ # # ]: 0 : if (cfg->vxlan.vlan) {
775 : : struct encap_vxlan_ipv4_vlan_data *d = data;
776 : :
777 : : /* Ethernet */
778 : : rte_ether_addr_copy(&p->vxlan.ether.da,
779 : : &d->ether.dst_addr);
780 : : rte_ether_addr_copy(&p->vxlan.ether.sa,
781 : : &d->ether.src_addr);
782 : 0 : d->ether.ether_type = rte_htons(RTE_ETHER_TYPE_VLAN);
783 : :
784 : : /* VLAN */
785 [ # # ]: 0 : d->vlan.vlan_tci = rte_htons(VLAN(p->vxlan.vlan.pcp,
786 : : p->vxlan.vlan.dei,
787 : : p->vxlan.vlan.vid));
788 : 0 : d->vlan.eth_proto = rte_htons(RTE_ETHER_TYPE_IPV4);
789 : :
790 : : /* IPv4*/
791 : 0 : d->ipv4.version_ihl = 0x45;
792 : 0 : d->ipv4.type_of_service = p->vxlan.ipv4.dscp << 2;
793 : 0 : d->ipv4.total_length = 0; /* not pre-computed */
794 : 0 : d->ipv4.packet_id = 0;
795 : 0 : d->ipv4.fragment_offset = 0;
796 : 0 : d->ipv4.time_to_live = p->vxlan.ipv4.ttl;
797 : 0 : d->ipv4.next_proto_id = IP_PROTO_UDP;
798 : 0 : d->ipv4.hdr_checksum = 0;
799 [ # # ]: 0 : d->ipv4.src_addr = rte_htonl(p->vxlan.ipv4.sa);
800 [ # # ]: 0 : d->ipv4.dst_addr = rte_htonl(p->vxlan.ipv4.da);
801 : :
802 [ # # ]: 0 : d->ipv4.hdr_checksum = rte_ipv4_cksum(&d->ipv4);
803 : :
804 : : /* UDP */
805 [ # # ]: 0 : d->udp.src_port = rte_htons(p->vxlan.udp.sp);
806 [ # # ]: 0 : d->udp.dst_port = rte_htons(p->vxlan.udp.dp);
807 : 0 : d->udp.dgram_len = 0; /* not pre-computed */
808 : 0 : d->udp.dgram_cksum = 0;
809 : :
810 : : /* VXLAN */
811 : 0 : d->vxlan.vx_flags = rte_htonl(0x08000000);
812 [ # # ]: 0 : d->vxlan.vx_vni = rte_htonl(p->vxlan.vxlan.vni << 8);
813 : :
814 : 0 : return 0;
815 : : } else {
816 : : struct encap_vxlan_ipv4_data *d = data;
817 : :
818 : : /* Ethernet */
819 : : rte_ether_addr_copy(&p->vxlan.ether.da,
820 : : &d->ether.dst_addr);
821 : : rte_ether_addr_copy(&p->vxlan.ether.sa,
822 : : &d->ether.src_addr);
823 : 0 : d->ether.ether_type = rte_htons(RTE_ETHER_TYPE_IPV4);
824 : :
825 : : /* IPv4*/
826 : 0 : d->ipv4.version_ihl = 0x45;
827 : 0 : d->ipv4.type_of_service = p->vxlan.ipv4.dscp << 2;
828 : 0 : d->ipv4.total_length = 0; /* not pre-computed */
829 : 0 : d->ipv4.packet_id = 0;
830 : 0 : d->ipv4.fragment_offset = 0;
831 : 0 : d->ipv4.time_to_live = p->vxlan.ipv4.ttl;
832 : 0 : d->ipv4.next_proto_id = IP_PROTO_UDP;
833 : 0 : d->ipv4.hdr_checksum = 0;
834 [ # # ]: 0 : d->ipv4.src_addr = rte_htonl(p->vxlan.ipv4.sa);
835 [ # # ]: 0 : d->ipv4.dst_addr = rte_htonl(p->vxlan.ipv4.da);
836 : :
837 [ # # ]: 0 : d->ipv4.hdr_checksum = rte_ipv4_cksum(&d->ipv4);
838 : :
839 : : /* UDP */
840 [ # # ]: 0 : d->udp.src_port = rte_htons(p->vxlan.udp.sp);
841 [ # # ]: 0 : d->udp.dst_port = rte_htons(p->vxlan.udp.dp);
842 : 0 : d->udp.dgram_len = 0; /* not pre-computed */
843 : 0 : d->udp.dgram_cksum = 0;
844 : :
845 : : /* VXLAN */
846 : 0 : d->vxlan.vx_flags = rte_htonl(0x08000000);
847 [ # # ]: 0 : d->vxlan.vx_vni = rte_htonl(p->vxlan.vxlan.vni << 8);
848 : :
849 : 0 : return 0;
850 : : }
851 : : else
852 [ # # ]: 0 : if (cfg->vxlan.vlan) {
853 : : struct encap_vxlan_ipv6_vlan_data *d = data;
854 : :
855 : : /* Ethernet */
856 : : rte_ether_addr_copy(&p->vxlan.ether.da,
857 : : &d->ether.dst_addr);
858 : : rte_ether_addr_copy(&p->vxlan.ether.sa,
859 : : &d->ether.src_addr);
860 : 0 : d->ether.ether_type = rte_htons(RTE_ETHER_TYPE_VLAN);
861 : :
862 : : /* VLAN */
863 [ # # ]: 0 : d->vlan.vlan_tci = rte_htons(VLAN(p->vxlan.vlan.pcp,
864 : : p->vxlan.vlan.dei,
865 : : p->vxlan.vlan.vid));
866 : 0 : d->vlan.eth_proto = rte_htons(RTE_ETHER_TYPE_IPV6);
867 : :
868 : : /* IPv6*/
869 [ # # ]: 0 : d->ipv6.vtc_flow = rte_htonl((6 << 28) |
870 : : (p->vxlan.ipv6.dscp << 22) |
871 : : p->vxlan.ipv6.flow_label);
872 : 0 : d->ipv6.payload_len = 0; /* not pre-computed */
873 : 0 : d->ipv6.proto = IP_PROTO_UDP;
874 : 0 : d->ipv6.hop_limits = p->vxlan.ipv6.hop_limit;
875 : 0 : d->ipv6.src_addr = p->vxlan.ipv6.sa;
876 : 0 : d->ipv6.dst_addr = p->vxlan.ipv6.da;
877 : :
878 : : /* UDP */
879 [ # # ]: 0 : d->udp.src_port = rte_htons(p->vxlan.udp.sp);
880 [ # # ]: 0 : d->udp.dst_port = rte_htons(p->vxlan.udp.dp);
881 : 0 : d->udp.dgram_len = 0; /* not pre-computed */
882 : 0 : d->udp.dgram_cksum = 0;
883 : :
884 : : /* VXLAN */
885 : 0 : d->vxlan.vx_flags = rte_htonl(0x08000000);
886 [ # # ]: 0 : d->vxlan.vx_vni = rte_htonl(p->vxlan.vxlan.vni << 8);
887 : :
888 : 0 : return 0;
889 : : } else {
890 : : struct encap_vxlan_ipv6_data *d = data;
891 : :
892 : : /* Ethernet */
893 : : rte_ether_addr_copy(&p->vxlan.ether.da,
894 : : &d->ether.dst_addr);
895 : : rte_ether_addr_copy(&p->vxlan.ether.sa,
896 : : &d->ether.src_addr);
897 : 0 : d->ether.ether_type = rte_htons(RTE_ETHER_TYPE_IPV6);
898 : :
899 : : /* IPv6*/
900 [ # # ]: 0 : d->ipv6.vtc_flow = rte_htonl((6 << 28) |
901 : : (p->vxlan.ipv6.dscp << 22) |
902 : : p->vxlan.ipv6.flow_label);
903 : 0 : d->ipv6.payload_len = 0; /* not pre-computed */
904 : 0 : d->ipv6.proto = IP_PROTO_UDP;
905 : 0 : d->ipv6.hop_limits = p->vxlan.ipv6.hop_limit;
906 : 0 : d->ipv6.src_addr = p->vxlan.ipv6.sa;
907 : 0 : d->ipv6.dst_addr = p->vxlan.ipv6.da;
908 : :
909 : : /* UDP */
910 [ # # ]: 0 : d->udp.src_port = rte_htons(p->vxlan.udp.sp);
911 [ # # ]: 0 : d->udp.dst_port = rte_htons(p->vxlan.udp.dp);
912 : 0 : d->udp.dgram_len = 0; /* not pre-computed */
913 : 0 : d->udp.dgram_cksum = 0;
914 : :
915 : : /* VXLAN */
916 : 0 : d->vxlan.vx_flags = rte_htonl(0x08000000);
917 [ # # ]: 0 : d->vxlan.vx_vni = rte_htonl(p->vxlan.vxlan.vni << 8);
918 : :
919 : 0 : return 0;
920 : : }
921 : : }
922 : :
923 : : static int
924 [ # # ]: 0 : encap_apply(void *data,
925 : : struct rte_table_action_encap_params *p,
926 : : struct rte_table_action_encap_config *cfg,
927 : : struct rte_table_action_common_config *common_cfg)
928 : : {
929 : : int status;
930 : :
931 : : /* Check input arguments */
932 : : status = encap_apply_check(p, cfg);
933 : : if (status)
934 : : return status;
935 : :
936 [ # # # # : 0 : switch (p->type) {
# # # ]
937 : : case RTE_TABLE_ACTION_ENCAP_ETHER:
938 : 0 : return encap_ether_apply(data, p, common_cfg);
939 : :
940 : 0 : case RTE_TABLE_ACTION_ENCAP_VLAN:
941 : 0 : return encap_vlan_apply(data, p, common_cfg);
942 : :
943 : 0 : case RTE_TABLE_ACTION_ENCAP_QINQ:
944 : 0 : return encap_qinq_apply(data, p, common_cfg);
945 : :
946 : 0 : case RTE_TABLE_ACTION_ENCAP_MPLS:
947 : 0 : return encap_mpls_apply(data, p);
948 : :
949 : : case RTE_TABLE_ACTION_ENCAP_PPPOE:
950 : 0 : return encap_pppoe_apply(data, p);
951 : :
952 : 0 : case RTE_TABLE_ACTION_ENCAP_VXLAN:
953 : 0 : return encap_vxlan_apply(data, p, cfg);
954 : :
955 : 0 : case RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
956 : 0 : return encap_qinq_pppoe_apply(data, p);
957 : :
958 : : default:
959 : : return -EINVAL;
960 : : }
961 : : }
962 : :
963 : : static __rte_always_inline uint16_t
964 : : encap_vxlan_ipv4_checksum_update(uint16_t cksum0,
965 : : uint16_t total_length)
966 : : {
967 : : int32_t cksum1;
968 : :
969 : : cksum1 = cksum0;
970 : 0 : cksum1 = ~cksum1 & 0xFFFF;
971 : :
972 : : /* Add total length (one's complement logic) */
973 : 0 : cksum1 += total_length;
974 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
975 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
976 : :
977 : 0 : return (uint16_t)(~cksum1);
978 : : }
979 : :
980 : : static __rte_always_inline void *
981 : : encap(void *dst, const void *src, size_t n)
982 : : {
983 [ # # # # : 0 : dst = ((uint8_t *) dst) - n;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
984 : : return rte_memcpy(dst, src, n);
985 : : }
986 : :
987 : : static __rte_always_inline void
988 : : pkt_work_encap_vxlan_ipv4(struct rte_mbuf *mbuf,
989 : : struct encap_vxlan_ipv4_data *vxlan_tbl,
990 : : struct rte_table_action_encap_config *cfg)
991 : : {
992 : 0 : uint32_t ether_offset = cfg->vxlan.data_offset;
993 : 0 : void *ether = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ether_offset);
994 : : struct encap_vxlan_ipv4_data *vxlan_pkt;
995 : : uint16_t ether_length, ipv4_total_length, ipv4_hdr_cksum, udp_length;
996 : :
997 : 0 : ether_length = (uint16_t)mbuf->pkt_len;
998 : 0 : ipv4_total_length = ether_length +
999 : : (sizeof(struct rte_vxlan_hdr) +
1000 : : sizeof(struct rte_udp_hdr) +
1001 : : sizeof(struct rte_ipv4_hdr));
1002 : 0 : ipv4_hdr_cksum = encap_vxlan_ipv4_checksum_update(vxlan_tbl->ipv4.hdr_checksum,
1003 [ # # # # : 0 : rte_htons(ipv4_total_length));
# # # # #
# # # ]
1004 [ # # # # : 0 : udp_length = ether_length +
# # # # #
# # # ]
1005 : : (sizeof(struct rte_vxlan_hdr) +
1006 : : sizeof(struct rte_udp_hdr));
1007 : :
1008 : : vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
1009 [ # # # # : 0 : vxlan_pkt->ipv4.total_length = rte_htons(ipv4_total_length);
# # # # #
# # # ]
1010 : 0 : vxlan_pkt->ipv4.hdr_checksum = ipv4_hdr_cksum;
1011 [ # # # # : 0 : vxlan_pkt->udp.dgram_len = rte_htons(udp_length);
# # # # #
# # # ]
1012 : :
1013 : 0 : mbuf->data_off = ether_offset - (sizeof(struct rte_mbuf) + sizeof(*vxlan_pkt));
1014 : 0 : mbuf->pkt_len = mbuf->data_len = ether_length + sizeof(*vxlan_pkt);
1015 : 0 : }
1016 : :
1017 : : static __rte_always_inline void
1018 : : pkt_work_encap_vxlan_ipv4_vlan(struct rte_mbuf *mbuf,
1019 : : struct encap_vxlan_ipv4_vlan_data *vxlan_tbl,
1020 : : struct rte_table_action_encap_config *cfg)
1021 : : {
1022 : 0 : uint32_t ether_offset = cfg->vxlan.data_offset;
1023 : 0 : void *ether = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ether_offset);
1024 : : struct encap_vxlan_ipv4_vlan_data *vxlan_pkt;
1025 : : uint16_t ether_length, ipv4_total_length, ipv4_hdr_cksum, udp_length;
1026 : :
1027 : 0 : ether_length = (uint16_t)mbuf->pkt_len;
1028 : 0 : ipv4_total_length = ether_length +
1029 : : (sizeof(struct rte_vxlan_hdr) +
1030 : : sizeof(struct rte_udp_hdr) +
1031 : : sizeof(struct rte_ipv4_hdr));
1032 : 0 : ipv4_hdr_cksum = encap_vxlan_ipv4_checksum_update(vxlan_tbl->ipv4.hdr_checksum,
1033 [ # # # # : 0 : rte_htons(ipv4_total_length));
# # # # #
# # # ]
1034 [ # # # # : 0 : udp_length = ether_length +
# # # # #
# # # ]
1035 : : (sizeof(struct rte_vxlan_hdr) +
1036 : : sizeof(struct rte_udp_hdr));
1037 : :
1038 : : vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
1039 [ # # # # : 0 : vxlan_pkt->ipv4.total_length = rte_htons(ipv4_total_length);
# # # # #
# # # ]
1040 : 0 : vxlan_pkt->ipv4.hdr_checksum = ipv4_hdr_cksum;
1041 [ # # # # : 0 : vxlan_pkt->udp.dgram_len = rte_htons(udp_length);
# # # # #
# # # ]
1042 : :
1043 : 0 : mbuf->data_off = ether_offset - (sizeof(struct rte_mbuf) + sizeof(*vxlan_pkt));
1044 : 0 : mbuf->pkt_len = mbuf->data_len = ether_length + sizeof(*vxlan_pkt);
1045 : 0 : }
1046 : :
1047 : : static __rte_always_inline void
1048 : : pkt_work_encap_vxlan_ipv6(struct rte_mbuf *mbuf,
1049 : : struct encap_vxlan_ipv6_data *vxlan_tbl,
1050 : : struct rte_table_action_encap_config *cfg)
1051 : : {
1052 : 0 : uint32_t ether_offset = cfg->vxlan.data_offset;
1053 : 0 : void *ether = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ether_offset);
1054 : : struct encap_vxlan_ipv6_data *vxlan_pkt;
1055 : : uint16_t ether_length, ipv6_payload_length, udp_length;
1056 : :
1057 : 0 : ether_length = (uint16_t)mbuf->pkt_len;
1058 [ # # # # : 0 : ipv6_payload_length = ether_length +
# # # # #
# # # ]
1059 : : (sizeof(struct rte_vxlan_hdr) +
1060 : : sizeof(struct rte_udp_hdr));
1061 : : udp_length = ether_length +
1062 : : (sizeof(struct rte_vxlan_hdr) +
1063 : : sizeof(struct rte_udp_hdr));
1064 : :
1065 : : vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
1066 [ # # # # : 0 : vxlan_pkt->ipv6.payload_len = rte_htons(ipv6_payload_length);
# # # # #
# # # ]
1067 [ # # # # : 0 : vxlan_pkt->udp.dgram_len = rte_htons(udp_length);
# # # # #
# # # ]
1068 : :
1069 : 0 : mbuf->data_off = ether_offset - (sizeof(struct rte_mbuf) + sizeof(*vxlan_pkt));
1070 : 0 : mbuf->pkt_len = mbuf->data_len = ether_length + sizeof(*vxlan_pkt);
1071 : 0 : }
1072 : :
1073 : : static __rte_always_inline void
1074 : : pkt_work_encap_vxlan_ipv6_vlan(struct rte_mbuf *mbuf,
1075 : : struct encap_vxlan_ipv6_vlan_data *vxlan_tbl,
1076 : : struct rte_table_action_encap_config *cfg)
1077 : : {
1078 : 0 : uint32_t ether_offset = cfg->vxlan.data_offset;
1079 : 0 : void *ether = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ether_offset);
1080 : : struct encap_vxlan_ipv6_vlan_data *vxlan_pkt;
1081 : : uint16_t ether_length, ipv6_payload_length, udp_length;
1082 : :
1083 : 0 : ether_length = (uint16_t)mbuf->pkt_len;
1084 [ # # # # : 0 : ipv6_payload_length = ether_length +
# # # # #
# # # ]
1085 : : (sizeof(struct rte_vxlan_hdr) +
1086 : : sizeof(struct rte_udp_hdr));
1087 : : udp_length = ether_length +
1088 : : (sizeof(struct rte_vxlan_hdr) +
1089 : : sizeof(struct rte_udp_hdr));
1090 : :
1091 : : vxlan_pkt = encap(ether, vxlan_tbl, sizeof(*vxlan_tbl));
1092 [ # # # # : 0 : vxlan_pkt->ipv6.payload_len = rte_htons(ipv6_payload_length);
# # # # #
# # # ]
1093 [ # # # # : 0 : vxlan_pkt->udp.dgram_len = rte_htons(udp_length);
# # # # #
# # # ]
1094 : :
1095 : 0 : mbuf->data_off = ether_offset - (sizeof(struct rte_mbuf) + sizeof(*vxlan_pkt));
1096 : 0 : mbuf->pkt_len = mbuf->data_len = ether_length + sizeof(*vxlan_pkt);
1097 : 0 : }
1098 : :
1099 : : static __rte_always_inline void
1100 : : pkt_work_encap(struct rte_mbuf *mbuf,
1101 : : void *data,
1102 : : struct rte_table_action_encap_config *cfg,
1103 : : void *ip,
1104 : : uint16_t total_length,
1105 : : uint32_t ip_offset)
1106 : : {
1107 : 0 : switch (cfg->encap_mask) {
1108 : : case 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER:
1109 : : encap(ip, data, sizeof(struct encap_ether_data));
1110 : 0 : mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1111 : : sizeof(struct encap_ether_data));
1112 : 0 : mbuf->pkt_len = mbuf->data_len = total_length +
1113 : : sizeof(struct encap_ether_data);
1114 : 0 : break;
1115 : :
1116 : : case 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN:
1117 : : encap(ip, data, sizeof(struct encap_vlan_data));
1118 : 0 : mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1119 : : sizeof(struct encap_vlan_data));
1120 : 0 : mbuf->pkt_len = mbuf->data_len = total_length +
1121 : : sizeof(struct encap_vlan_data);
1122 : 0 : break;
1123 : :
1124 : : case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ:
1125 : : encap(ip, data, sizeof(struct encap_qinq_data));
1126 : 0 : mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1127 : : sizeof(struct encap_qinq_data));
1128 : 0 : mbuf->pkt_len = mbuf->data_len = total_length +
1129 : : sizeof(struct encap_qinq_data);
1130 : 0 : break;
1131 : :
1132 : 0 : case 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS:
1133 : : {
1134 : : struct encap_mpls_data *mpls = data;
1135 : 0 : size_t size = sizeof(struct rte_ether_hdr) +
1136 [ # # # # : 0 : mpls->mpls_count * 4;
# # # # #
# # # ]
1137 : :
1138 : : encap(ip, data, size);
1139 : 0 : mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) + size);
1140 : 0 : mbuf->pkt_len = mbuf->data_len = total_length + size;
1141 : 0 : break;
1142 : : }
1143 : :
1144 : : case 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE:
1145 : : {
1146 : : struct encap_pppoe_data *pppoe =
1147 : : encap(ip, data, sizeof(struct encap_pppoe_data));
1148 [ # # # # : 0 : pppoe->pppoe_ppp.length = rte_htons(total_length + 2);
# # # # #
# # # ]
1149 : 0 : mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1150 : : sizeof(struct encap_pppoe_data));
1151 : 0 : mbuf->pkt_len = mbuf->data_len = total_length +
1152 : : sizeof(struct encap_pppoe_data);
1153 : 0 : break;
1154 : : }
1155 : :
1156 : : case 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE:
1157 : : {
1158 : : struct encap_qinq_pppoe_data *qinq_pppoe =
1159 : : encap(ip, data, sizeof(struct encap_qinq_pppoe_data));
1160 [ # # # # : 0 : qinq_pppoe->pppoe_ppp.length = rte_htons(total_length + 2);
# # # # #
# # # ]
1161 : 0 : mbuf->data_off = ip_offset - (sizeof(struct rte_mbuf) +
1162 : : sizeof(struct encap_qinq_pppoe_data));
1163 : 0 : mbuf->pkt_len = mbuf->data_len = total_length +
1164 : : sizeof(struct encap_qinq_pppoe_data);
1165 : 0 : break;
1166 : : }
1167 : :
1168 : 0 : case 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN:
1169 : : {
1170 [ # # # # : 0 : if (cfg->vxlan.ip_version)
# # # # #
# # # ]
1171 [ # # # # : 0 : if (cfg->vxlan.vlan)
# # # # #
# # # ]
1172 : : pkt_work_encap_vxlan_ipv4_vlan(mbuf, data, cfg);
1173 : : else
1174 : : pkt_work_encap_vxlan_ipv4(mbuf, data, cfg);
1175 : : else
1176 [ # # # # : 0 : if (cfg->vxlan.vlan)
# # # # #
# # # ]
1177 : : pkt_work_encap_vxlan_ipv6_vlan(mbuf, data, cfg);
1178 : : else
1179 : : pkt_work_encap_vxlan_ipv6(mbuf, data, cfg);
1180 : : }
1181 : :
1182 : : default:
1183 : : break;
1184 : : }
1185 : : }
1186 : :
1187 : : /**
1188 : : * RTE_TABLE_ACTION_NAT
1189 : : */
1190 : : static int
1191 : : nat_cfg_check(struct rte_table_action_nat_config *nat)
1192 : : {
1193 [ # # ]: 0 : if ((nat->proto != 0x06) &&
1194 : : (nat->proto != 0x11))
1195 : : return -ENOTSUP;
1196 : :
1197 : : return 0;
1198 : : }
1199 : :
1200 : : struct __rte_packed_begin nat_ipv4_data {
1201 : : uint32_t addr;
1202 : : uint16_t port;
1203 : : } __rte_packed_end;
1204 : :
1205 : : struct __rte_packed_begin nat_ipv6_data {
1206 : : struct rte_ipv6_addr addr;
1207 : : uint16_t port;
1208 : : } __rte_packed_end;
1209 : :
1210 : : static size_t
1211 : : nat_data_size(struct rte_table_action_nat_config *nat __rte_unused,
1212 : : struct rte_table_action_common_config *common)
1213 : : {
1214 : 0 : int ip_version = common->ip_version;
1215 : :
1216 : : return (ip_version) ?
1217 : 0 : sizeof(struct nat_ipv4_data) :
1218 : : sizeof(struct nat_ipv6_data);
1219 : : }
1220 : :
1221 : : static int
1222 : : nat_apply_check(struct rte_table_action_nat_params *p,
1223 : : struct rte_table_action_common_config *cfg)
1224 : : {
1225 [ # # # # ]: 0 : if ((p->ip_version && (cfg->ip_version == 0)) ||
1226 [ # # ]: 0 : ((p->ip_version == 0) && cfg->ip_version))
1227 : : return -EINVAL;
1228 : :
1229 : : return 0;
1230 : : }
1231 : :
1232 : : static int
1233 [ # # ]: 0 : nat_apply(void *data,
1234 : : struct rte_table_action_nat_params *p,
1235 : : struct rte_table_action_common_config *cfg)
1236 : : {
1237 : : int status;
1238 : :
1239 : : /* Check input arguments */
1240 : : status = nat_apply_check(p, cfg);
1241 : : if (status)
1242 : : return status;
1243 : :
1244 : : /* Apply */
1245 [ # # ]: 0 : if (p->ip_version) {
1246 : : struct nat_ipv4_data *d = data;
1247 : :
1248 [ # # ]: 0 : d->addr = rte_htonl(p->addr.ipv4);
1249 [ # # ]: 0 : d->port = rte_htons(p->port);
1250 : : } else {
1251 : : struct nat_ipv6_data *d = data;
1252 : :
1253 : 0 : d->addr = p->addr.ipv6;
1254 [ # # ]: 0 : d->port = rte_htons(p->port);
1255 : : }
1256 : :
1257 : : return 0;
1258 : : }
1259 : :
1260 : : static __rte_always_inline uint16_t
1261 : : nat_ipv4_checksum_update(uint16_t cksum0,
1262 : : uint32_t ip0,
1263 : : uint32_t ip1)
1264 : : {
1265 : : int32_t cksum1;
1266 : :
1267 : : cksum1 = cksum0;
1268 : : cksum1 = ~cksum1 & 0xFFFF;
1269 : :
1270 : : /* Subtract ip0 (one's complement logic) */
1271 : 0 : cksum1 -= (ip0 >> 16) + (ip0 & 0xFFFF);
1272 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1273 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1274 : :
1275 : : /* Add ip1 (one's complement logic) */
1276 : 0 : cksum1 += (ip1 >> 16) + (ip1 & 0xFFFF);
1277 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1278 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1279 : :
1280 : 0 : return (uint16_t)(~cksum1);
1281 : : }
1282 : :
1283 : : static __rte_always_inline uint16_t
1284 : : nat_ipv4_tcp_udp_checksum_update(uint16_t cksum0,
1285 : : uint32_t ip0,
1286 : : uint32_t ip1,
1287 : : uint16_t port0,
1288 : : uint16_t port1)
1289 : : {
1290 : : int32_t cksum1;
1291 : :
1292 : : cksum1 = cksum0;
1293 : : cksum1 = ~cksum1 & 0xFFFF;
1294 : :
1295 : : /* Subtract ip0 and port 0 (one's complement logic) */
1296 : 0 : cksum1 -= (ip0 >> 16) + (ip0 & 0xFFFF) + port0;
1297 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1298 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1299 : :
1300 : : /* Add ip1 and port1 (one's complement logic) */
1301 : 0 : cksum1 += (ip1 >> 16) + (ip1 & 0xFFFF) + port1;
1302 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1303 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1304 : :
1305 : 0 : return (uint16_t)(~cksum1);
1306 : : }
1307 : :
1308 : : static __rte_always_inline uint16_t
1309 : : nat_ipv6_tcp_udp_checksum_update(uint16_t cksum0,
1310 : : uint16_t *ip0,
1311 : : uint16_t *ip1,
1312 : : uint16_t port0,
1313 : : uint16_t port1)
1314 : : {
1315 : : int32_t cksum1;
1316 : :
1317 : : cksum1 = cksum0;
1318 : 0 : cksum1 = ~cksum1 & 0xFFFF;
1319 : :
1320 : : /* Subtract ip0 and port 0 (one's complement logic) */
1321 : 0 : cksum1 -= ip0[0] + ip0[1] + ip0[2] + ip0[3] +
1322 : 0 : ip0[4] + ip0[5] + ip0[6] + ip0[7] + port0;
1323 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1324 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1325 : :
1326 : : /* Add ip1 and port1 (one's complement logic) */
1327 : 0 : cksum1 += ip1[0] + ip1[1] + ip1[2] + ip1[3] +
1328 : 0 : ip1[4] + ip1[5] + ip1[6] + ip1[7] + port1;
1329 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1330 : 0 : cksum1 = (cksum1 & 0xFFFF) + (cksum1 >> 16);
1331 : :
1332 : 0 : return (uint16_t)(~cksum1);
1333 : : }
1334 : :
1335 : : static __rte_always_inline void
1336 : : pkt_ipv4_work_nat(struct rte_ipv4_hdr *ip,
1337 : : struct nat_ipv4_data *data,
1338 : : struct rte_table_action_nat_config *cfg)
1339 : : {
1340 [ # # # # : 0 : if (cfg->source_nat) {
# # # # #
# # # ]
1341 [ # # # # : 0 : if (cfg->proto == 0x6) {
# # # # #
# # # ]
1342 : : struct rte_tcp_hdr *tcp = (struct rte_tcp_hdr *) &ip[1];
1343 : : uint16_t ip_cksum, tcp_cksum;
1344 : :
1345 : 0 : ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
1346 : : ip->src_addr,
1347 : : data->addr);
1348 : :
1349 : 0 : tcp_cksum = nat_ipv4_tcp_udp_checksum_update(tcp->cksum,
1350 : : ip->src_addr,
1351 : : data->addr,
1352 : 0 : tcp->src_port,
1353 : 0 : data->port);
1354 : :
1355 : 0 : ip->src_addr = data->addr;
1356 : 0 : ip->hdr_checksum = ip_cksum;
1357 : 0 : tcp->src_port = data->port;
1358 : 0 : tcp->cksum = tcp_cksum;
1359 : : } else {
1360 : : struct rte_udp_hdr *udp = (struct rte_udp_hdr *) &ip[1];
1361 : : uint16_t ip_cksum, udp_cksum;
1362 : :
1363 : 0 : ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
1364 : : ip->src_addr,
1365 : : data->addr);
1366 : :
1367 : 0 : udp_cksum = nat_ipv4_tcp_udp_checksum_update(udp->dgram_cksum,
1368 : : ip->src_addr,
1369 : : data->addr,
1370 : 0 : udp->src_port,
1371 : 0 : data->port);
1372 : :
1373 : 0 : ip->src_addr = data->addr;
1374 : 0 : ip->hdr_checksum = ip_cksum;
1375 : 0 : udp->src_port = data->port;
1376 [ # # # # : 0 : if (udp->dgram_cksum)
# # # # #
# # # ]
1377 : 0 : udp->dgram_cksum = udp_cksum;
1378 : : }
1379 : : } else {
1380 [ # # # # : 0 : if (cfg->proto == 0x6) {
# # # # #
# # # ]
1381 : : struct rte_tcp_hdr *tcp = (struct rte_tcp_hdr *) &ip[1];
1382 : : uint16_t ip_cksum, tcp_cksum;
1383 : :
1384 : 0 : ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
1385 : : ip->dst_addr,
1386 : : data->addr);
1387 : :
1388 : 0 : tcp_cksum = nat_ipv4_tcp_udp_checksum_update(tcp->cksum,
1389 : : ip->dst_addr,
1390 : : data->addr,
1391 : 0 : tcp->dst_port,
1392 : 0 : data->port);
1393 : :
1394 : 0 : ip->dst_addr = data->addr;
1395 : 0 : ip->hdr_checksum = ip_cksum;
1396 : 0 : tcp->dst_port = data->port;
1397 : 0 : tcp->cksum = tcp_cksum;
1398 : : } else {
1399 : : struct rte_udp_hdr *udp = (struct rte_udp_hdr *) &ip[1];
1400 : : uint16_t ip_cksum, udp_cksum;
1401 : :
1402 : 0 : ip_cksum = nat_ipv4_checksum_update(ip->hdr_checksum,
1403 : : ip->dst_addr,
1404 : : data->addr);
1405 : :
1406 : 0 : udp_cksum = nat_ipv4_tcp_udp_checksum_update(udp->dgram_cksum,
1407 : : ip->dst_addr,
1408 : : data->addr,
1409 : 0 : udp->dst_port,
1410 : 0 : data->port);
1411 : :
1412 : 0 : ip->dst_addr = data->addr;
1413 : 0 : ip->hdr_checksum = ip_cksum;
1414 : 0 : udp->dst_port = data->port;
1415 [ # # # # : 0 : if (udp->dgram_cksum)
# # # # #
# # # ]
1416 : 0 : udp->dgram_cksum = udp_cksum;
1417 : : }
1418 : : }
1419 : : }
1420 : :
1421 : : static __rte_always_inline void
1422 : : pkt_ipv6_work_nat(struct rte_ipv6_hdr *ip,
1423 : : struct nat_ipv6_data *data,
1424 : : struct rte_table_action_nat_config *cfg)
1425 : : {
1426 [ # # # # : 0 : if (cfg->source_nat) {
# # # # #
# # # ]
1427 [ # # # # : 0 : if (cfg->proto == 0x6) {
# # # # #
# # # ]
1428 : : struct rte_tcp_hdr *tcp = (struct rte_tcp_hdr *) &ip[1];
1429 : : uint16_t tcp_cksum;
1430 : :
1431 : 0 : tcp_cksum = nat_ipv6_tcp_udp_checksum_update(tcp->cksum,
1432 : : (uint16_t *)&ip->src_addr,
1433 : : (uint16_t *)&data->addr,
1434 : 0 : tcp->src_port,
1435 : 0 : data->port);
1436 : :
1437 : 0 : ip->src_addr = data->addr;
1438 : 0 : tcp->src_port = data->port;
1439 : 0 : tcp->cksum = tcp_cksum;
1440 : : } else {
1441 : : struct rte_udp_hdr *udp = (struct rte_udp_hdr *) &ip[1];
1442 : : uint16_t udp_cksum;
1443 : :
1444 : 0 : udp_cksum = nat_ipv6_tcp_udp_checksum_update(udp->dgram_cksum,
1445 : : (uint16_t *)&ip->src_addr,
1446 : : (uint16_t *)&data->addr,
1447 : 0 : udp->src_port,
1448 : 0 : data->port);
1449 : :
1450 : 0 : ip->src_addr = data->addr;
1451 : 0 : udp->src_port = data->port;
1452 : 0 : udp->dgram_cksum = udp_cksum;
1453 : : }
1454 : : } else {
1455 [ # # # # : 0 : if (cfg->proto == 0x6) {
# # # # #
# # # ]
1456 : : struct rte_tcp_hdr *tcp = (struct rte_tcp_hdr *) &ip[1];
1457 : : uint16_t tcp_cksum;
1458 : :
1459 : 0 : tcp_cksum = nat_ipv6_tcp_udp_checksum_update(tcp->cksum,
1460 : : (uint16_t *)&ip->dst_addr,
1461 : : (uint16_t *)&data->addr,
1462 : 0 : tcp->dst_port,
1463 : 0 : data->port);
1464 : :
1465 : 0 : ip->dst_addr = data->addr;
1466 : 0 : tcp->dst_port = data->port;
1467 : 0 : tcp->cksum = tcp_cksum;
1468 : : } else {
1469 : : struct rte_udp_hdr *udp = (struct rte_udp_hdr *) &ip[1];
1470 : : uint16_t udp_cksum;
1471 : :
1472 : 0 : udp_cksum = nat_ipv6_tcp_udp_checksum_update(udp->dgram_cksum,
1473 : : (uint16_t *)&ip->dst_addr,
1474 : : (uint16_t *)&data->addr,
1475 : 0 : udp->dst_port,
1476 : 0 : data->port);
1477 : :
1478 : 0 : ip->dst_addr = data->addr;
1479 : 0 : udp->dst_port = data->port;
1480 : 0 : udp->dgram_cksum = udp_cksum;
1481 : : }
1482 : : }
1483 : : }
1484 : :
1485 : : /**
1486 : : * RTE_TABLE_ACTION_TTL
1487 : : */
1488 : : static int
1489 : : ttl_cfg_check(struct rte_table_action_ttl_config *ttl)
1490 : : {
1491 [ # # ]: 0 : if (ttl->drop == 0)
1492 : : return -ENOTSUP;
1493 : :
1494 : : return 0;
1495 : : }
1496 : :
1497 : : struct __rte_packed_begin ttl_data {
1498 : : uint32_t n_packets;
1499 : : } __rte_packed_end;
1500 : :
1501 : : #define TTL_INIT(data, decrement) \
1502 : : ((data)->n_packets = (decrement) ? 1 : 0)
1503 : :
1504 : : #define TTL_DEC_GET(data) \
1505 : : ((uint8_t)((data)->n_packets & 1))
1506 : :
1507 : : #define TTL_STATS_RESET(data) \
1508 : : ((data)->n_packets = ((data)->n_packets & 1))
1509 : :
1510 : : #define TTL_STATS_READ(data) \
1511 : : ((data)->n_packets >> 1)
1512 : :
1513 : : #define TTL_STATS_ADD(data, value) \
1514 : : ((data)->n_packets = \
1515 : : (((((data)->n_packets >> 1) + (value)) << 1) | \
1516 : : ((data)->n_packets & 1)))
1517 : :
1518 : : static int
1519 : : ttl_apply(void *data,
1520 : : struct rte_table_action_ttl_params *p)
1521 : : {
1522 : : struct ttl_data *d = data;
1523 : :
1524 : 0 : TTL_INIT(d, p->decrement);
1525 : :
1526 : : return 0;
1527 : : }
1528 : :
1529 : : static __rte_always_inline uint64_t
1530 : : pkt_ipv4_work_ttl(struct rte_ipv4_hdr *ip,
1531 : : struct ttl_data *data)
1532 : : {
1533 : : uint32_t drop;
1534 : 0 : uint16_t cksum = ip->hdr_checksum;
1535 : 0 : uint8_t ttl = ip->time_to_live;
1536 : 0 : uint8_t ttl_diff = TTL_DEC_GET(data);
1537 : :
1538 : 0 : cksum += ttl_diff;
1539 : 0 : ttl -= ttl_diff;
1540 : :
1541 : 0 : ip->hdr_checksum = cksum;
1542 : 0 : ip->time_to_live = ttl;
1543 : :
1544 : 0 : drop = (ttl == 0) ? 1 : 0;
1545 : 0 : TTL_STATS_ADD(data, drop);
1546 : :
1547 : 0 : return drop;
1548 : : }
1549 : :
1550 : : static __rte_always_inline uint64_t
1551 : : pkt_ipv6_work_ttl(struct rte_ipv6_hdr *ip,
1552 : : struct ttl_data *data)
1553 : : {
1554 : : uint32_t drop;
1555 : 0 : uint8_t ttl = ip->hop_limits;
1556 : 0 : uint8_t ttl_diff = TTL_DEC_GET(data);
1557 : :
1558 : 0 : ttl -= ttl_diff;
1559 : :
1560 : 0 : ip->hop_limits = ttl;
1561 : :
1562 : 0 : drop = (ttl == 0) ? 1 : 0;
1563 : 0 : TTL_STATS_ADD(data, drop);
1564 : :
1565 : 0 : return drop;
1566 : : }
1567 : :
1568 : : /**
1569 : : * RTE_TABLE_ACTION_STATS
1570 : : */
1571 : : static int
1572 : : stats_cfg_check(struct rte_table_action_stats_config *stats)
1573 : : {
1574 [ # # # # ]: 0 : if ((stats->n_packets_enabled == 0) && (stats->n_bytes_enabled == 0))
1575 : : return -EINVAL;
1576 : :
1577 : : return 0;
1578 : : }
1579 : :
1580 : : struct __rte_packed_begin stats_data {
1581 : : uint64_t n_packets;
1582 : : uint64_t n_bytes;
1583 : : } __rte_packed_end;
1584 : :
1585 : : static int
1586 : : stats_apply(struct stats_data *data,
1587 : : struct rte_table_action_stats_params *p)
1588 : : {
1589 : 0 : data->n_packets = p->n_packets;
1590 : 0 : data->n_bytes = p->n_bytes;
1591 : :
1592 : : return 0;
1593 : : }
1594 : :
1595 : : static __rte_always_inline void
1596 : : pkt_work_stats(struct stats_data *data,
1597 : : uint16_t total_length)
1598 : : {
1599 : 0 : data->n_packets++;
1600 : 0 : data->n_bytes += total_length;
1601 : 0 : }
1602 : :
1603 : : /**
1604 : : * RTE_TABLE_ACTION_TIME
1605 : : */
1606 : : struct __rte_packed_begin time_data {
1607 : : uint64_t time;
1608 : : } __rte_packed_end;
1609 : :
1610 : : static int
1611 : : time_apply(struct time_data *data,
1612 : : struct rte_table_action_time_params *p)
1613 : : {
1614 : 0 : data->time = p->time;
1615 : : return 0;
1616 : : }
1617 : :
1618 : : static __rte_always_inline void
1619 : : pkt_work_time(struct time_data *data,
1620 : : uint64_t time)
1621 : : {
1622 : 0 : data->time = time;
1623 : 0 : }
1624 : :
1625 : :
1626 : : /**
1627 : : * RTE_TABLE_ACTION_CRYPTO
1628 : : */
1629 : :
1630 : : #define CRYPTO_OP_MASK_CIPHER 0x1
1631 : : #define CRYPTO_OP_MASK_AUTH 0x2
1632 : : #define CRYPTO_OP_MASK_AEAD 0x4
1633 : :
1634 : : struct crypto_op_sym_iv_aad {
1635 : : struct rte_crypto_op op;
1636 : : struct rte_crypto_sym_op sym_op;
1637 : : union {
1638 : : struct {
1639 : : uint8_t cipher_iv[
1640 : : RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX];
1641 : : uint8_t auth_iv[
1642 : : RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX];
1643 : : } cipher_auth;
1644 : :
1645 : : struct {
1646 : : uint8_t iv[RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX];
1647 : : uint8_t aad[RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX];
1648 : : } aead_iv_aad;
1649 : :
1650 : : } iv_aad;
1651 : : };
1652 : :
1653 : : struct __rte_packed_begin sym_crypto_data {
1654 : :
1655 : : union {
1656 : : struct {
1657 : :
1658 : : /** Length of cipher iv. */
1659 : : uint16_t cipher_iv_len;
1660 : :
1661 : : /** Offset from start of IP header to the cipher iv. */
1662 : : uint16_t cipher_iv_data_offset;
1663 : :
1664 : : /** Length of cipher iv to be updated in the mbuf. */
1665 : : uint16_t cipher_iv_update_len;
1666 : :
1667 : : /** Offset from start of IP header to the auth iv. */
1668 : : uint16_t auth_iv_data_offset;
1669 : :
1670 : : /** Length of auth iv in the mbuf. */
1671 : : uint16_t auth_iv_len;
1672 : :
1673 : : /** Length of auth iv to be updated in the mbuf. */
1674 : : uint16_t auth_iv_update_len;
1675 : :
1676 : : } cipher_auth;
1677 : : struct {
1678 : :
1679 : : /** Length of iv. */
1680 : : uint16_t iv_len;
1681 : :
1682 : : /** Offset from start of IP header to the aead iv. */
1683 : : uint16_t iv_data_offset;
1684 : :
1685 : : /** Length of iv to be updated in the mbuf. */
1686 : : uint16_t iv_update_len;
1687 : :
1688 : : /** Length of aad */
1689 : : uint16_t aad_len;
1690 : :
1691 : : /** Offset from start of IP header to the aad. */
1692 : : uint16_t aad_data_offset;
1693 : :
1694 : : /** Length of aad to updated in the mbuf. */
1695 : : uint16_t aad_update_len;
1696 : :
1697 : : } aead;
1698 : : };
1699 : :
1700 : : /** Offset from start of IP header to the data. */
1701 : : uint16_t data_offset;
1702 : :
1703 : : /** Digest length. */
1704 : : uint16_t digest_len;
1705 : :
1706 : : /** block size */
1707 : : uint16_t block_size;
1708 : :
1709 : : /** Mask of crypto operation */
1710 : : uint16_t op_mask;
1711 : :
1712 : : /** Session pointer. */
1713 : : struct rte_cryptodev_sym_session *session;
1714 : :
1715 : : /** Direction of crypto, encrypt or decrypt */
1716 : : uint16_t direction;
1717 : :
1718 : : /** Private data size to store cipher iv / aad. */
1719 : : uint8_t iv_aad_data[32];
1720 : :
1721 : : } __rte_packed_end;
1722 : :
1723 : : static int
1724 : 0 : sym_crypto_cfg_check(struct rte_table_action_sym_crypto_config *cfg)
1725 : : {
1726 [ # # ]: 0 : if (!rte_cryptodev_is_valid_dev(cfg->cryptodev_id))
1727 : : return -EINVAL;
1728 [ # # # # ]: 0 : if (cfg->mp_create == NULL || cfg->mp_init == NULL)
1729 : 0 : return -EINVAL;
1730 : :
1731 : : return 0;
1732 : : }
1733 : :
1734 : : static int
1735 : 0 : get_block_size(const struct rte_crypto_sym_xform *xform, uint8_t cdev_id)
1736 : : {
1737 : : struct rte_cryptodev_info dev_info;
1738 : : const struct rte_cryptodev_capabilities *cap;
1739 : : uint32_t i;
1740 : :
1741 : 0 : rte_cryptodev_info_get(cdev_id, &dev_info);
1742 : :
1743 [ # # ]: 0 : for (i = 0; dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
1744 : 0 : i++) {
1745 : : cap = &dev_info.capabilities[i];
1746 : :
1747 [ # # ]: 0 : if (cap->sym.xform_type != xform->type)
1748 : 0 : continue;
1749 : :
1750 [ # # ]: 0 : if ((xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) &&
1751 [ # # ]: 0 : (cap->sym.cipher.algo == xform->cipher.algo))
1752 : 0 : return cap->sym.cipher.block_size;
1753 : :
1754 [ # # ]: 0 : if ((xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) &&
1755 [ # # ]: 0 : (cap->sym.aead.algo == xform->aead.algo))
1756 : 0 : return cap->sym.aead.block_size;
1757 : :
1758 [ # # ]: 0 : if (xform->type == RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED)
1759 : : break;
1760 : : }
1761 : :
1762 : : return -1;
1763 : : }
1764 : :
1765 : : static int
1766 : 0 : sym_crypto_apply(struct sym_crypto_data *data,
1767 : : struct rte_table_action_sym_crypto_config *cfg,
1768 : : struct rte_table_action_sym_crypto_params *p)
1769 : : {
1770 : : const struct rte_crypto_cipher_xform *cipher_xform = NULL;
1771 : : const struct rte_crypto_auth_xform *auth_xform = NULL;
1772 : : const struct rte_crypto_aead_xform *aead_xform = NULL;
1773 : 0 : struct rte_crypto_sym_xform *xform = p->xform;
1774 : : struct rte_cryptodev_sym_session *session;
1775 : : int ret;
1776 : :
1777 : : memset(data, 0, sizeof(*data));
1778 : :
1779 [ # # ]: 0 : while (xform) {
1780 [ # # ]: 0 : if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
1781 : 0 : cipher_xform = &xform->cipher;
1782 : :
1783 [ # # ]: 0 : if (cipher_xform->iv.length >
1784 : : RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX)
1785 : : return -ENOMEM;
1786 [ # # ]: 0 : if (cipher_xform->iv.offset !=
1787 : : RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET)
1788 : : return -EINVAL;
1789 : :
1790 : 0 : ret = get_block_size(xform, cfg->cryptodev_id);
1791 [ # # ]: 0 : if (ret < 0)
1792 : : return -1;
1793 : 0 : data->block_size = (uint16_t)ret;
1794 : 0 : data->op_mask |= CRYPTO_OP_MASK_CIPHER;
1795 : :
1796 : 0 : data->cipher_auth.cipher_iv_len =
1797 : 0 : cipher_xform->iv.length;
1798 : 0 : data->cipher_auth.cipher_iv_data_offset = (uint16_t)
1799 : 0 : p->cipher_auth.cipher_iv_update.offset;
1800 : 0 : data->cipher_auth.cipher_iv_update_len = (uint16_t)
1801 : 0 : p->cipher_auth.cipher_iv_update.length;
1802 : :
1803 : 0 : rte_memcpy(data->iv_aad_data,
1804 : 0 : p->cipher_auth.cipher_iv.val,
1805 [ # # ]: 0 : p->cipher_auth.cipher_iv.length);
1806 : :
1807 : 0 : data->direction = cipher_xform->op;
1808 : :
1809 [ # # ]: 0 : } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
1810 : 0 : auth_xform = &xform->auth;
1811 [ # # ]: 0 : if (auth_xform->iv.length >
1812 : : RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX)
1813 : : return -ENOMEM;
1814 : 0 : data->op_mask |= CRYPTO_OP_MASK_AUTH;
1815 : :
1816 : 0 : data->cipher_auth.auth_iv_len = auth_xform->iv.length;
1817 : 0 : data->cipher_auth.auth_iv_data_offset = (uint16_t)
1818 : 0 : p->cipher_auth.auth_iv_update.offset;
1819 : 0 : data->cipher_auth.auth_iv_update_len = (uint16_t)
1820 : 0 : p->cipher_auth.auth_iv_update.length;
1821 : 0 : data->digest_len = auth_xform->digest_length;
1822 : :
1823 : 0 : data->direction = (auth_xform->op ==
1824 : : RTE_CRYPTO_AUTH_OP_GENERATE) ?
1825 : 0 : RTE_CRYPTO_CIPHER_OP_ENCRYPT :
1826 : : RTE_CRYPTO_CIPHER_OP_DECRYPT;
1827 : :
1828 [ # # ]: 0 : } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
1829 : : aead_xform = &xform->aead;
1830 : :
1831 [ # # ]: 0 : if ((aead_xform->iv.length >
1832 : 0 : RTE_TABLE_ACTION_SYM_CRYPTO_IV_SIZE_MAX) || (
1833 [ # # ]: 0 : aead_xform->aad_length >
1834 : : RTE_TABLE_ACTION_SYM_CRYPTO_AAD_SIZE_MAX))
1835 : : return -EINVAL;
1836 [ # # ]: 0 : if (aead_xform->iv.offset !=
1837 : : RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET)
1838 : : return -EINVAL;
1839 : :
1840 : 0 : ret = get_block_size(xform, cfg->cryptodev_id);
1841 [ # # ]: 0 : if (ret < 0)
1842 : : return -1;
1843 : 0 : data->block_size = (uint16_t)ret;
1844 : 0 : data->op_mask |= CRYPTO_OP_MASK_AEAD;
1845 : :
1846 : 0 : data->digest_len = aead_xform->digest_length;
1847 : 0 : data->aead.iv_len = aead_xform->iv.length;
1848 : 0 : data->aead.aad_len = aead_xform->aad_length;
1849 : :
1850 : 0 : data->aead.iv_data_offset = (uint16_t)
1851 : 0 : p->aead.iv_update.offset;
1852 : 0 : data->aead.iv_update_len = (uint16_t)
1853 : 0 : p->aead.iv_update.length;
1854 : 0 : data->aead.aad_data_offset = (uint16_t)
1855 : 0 : p->aead.aad_update.offset;
1856 : 0 : data->aead.aad_update_len = (uint16_t)
1857 : 0 : p->aead.aad_update.length;
1858 : :
1859 : 0 : rte_memcpy(data->iv_aad_data,
1860 : 0 : p->aead.iv.val,
1861 [ # # ]: 0 : p->aead.iv.length);
1862 : :
1863 : 0 : rte_memcpy(data->iv_aad_data + p->aead.iv.length,
1864 : 0 : p->aead.aad.val,
1865 [ # # ]: 0 : p->aead.aad.length);
1866 : :
1867 : 0 : data->direction = (aead_xform->op ==
1868 : : RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
1869 : 0 : RTE_CRYPTO_CIPHER_OP_ENCRYPT :
1870 : : RTE_CRYPTO_CIPHER_OP_DECRYPT;
1871 : : } else
1872 : : return -EINVAL;
1873 : :
1874 : 0 : xform = xform->next;
1875 : : }
1876 : :
1877 [ # # # # ]: 0 : if (auth_xform && auth_xform->iv.length) {
1878 [ # # ]: 0 : if (cipher_xform) {
1879 : 0 : if (auth_xform->iv.offset !=
1880 : 0 : RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET +
1881 [ # # ]: 0 : cipher_xform->iv.length)
1882 : : return -EINVAL;
1883 : :
1884 : 0 : rte_memcpy(data->iv_aad_data + cipher_xform->iv.length,
1885 : 0 : p->cipher_auth.auth_iv.val,
1886 [ # # ]: 0 : p->cipher_auth.auth_iv.length);
1887 : : } else {
1888 : 0 : rte_memcpy(data->iv_aad_data,
1889 : 0 : p->cipher_auth.auth_iv.val,
1890 [ # # ]: 0 : p->cipher_auth.auth_iv.length);
1891 : : }
1892 : : }
1893 : :
1894 : 0 : session = rte_cryptodev_sym_session_create(cfg->cryptodev_id,
1895 : : p->xform, cfg->mp_create);
1896 [ # # ]: 0 : if (!session)
1897 : : return -ENOMEM;
1898 : :
1899 : 0 : data->data_offset = (uint16_t)p->data_offset;
1900 : 0 : data->session = session;
1901 : :
1902 : 0 : return 0;
1903 : : }
1904 : :
1905 : : static __rte_always_inline uint64_t
1906 : : pkt_work_sym_crypto(struct rte_mbuf *mbuf, struct sym_crypto_data *data,
1907 : : struct rte_table_action_sym_crypto_config *cfg,
1908 : : uint16_t ip_offset)
1909 : : {
1910 : 0 : struct crypto_op_sym_iv_aad *crypto_op = (struct crypto_op_sym_iv_aad *)
1911 : 0 : RTE_MBUF_METADATA_UINT8_PTR(mbuf, cfg->op_offset);
1912 : : struct rte_crypto_op *op = &crypto_op->op;
1913 : : struct rte_crypto_sym_op *sym = op->sym;
1914 : 0 : uint32_t pkt_offset = sizeof(*mbuf) + mbuf->data_off;
1915 : 0 : uint32_t payload_len = pkt_offset + mbuf->data_len - data->data_offset;
1916 : :
1917 : 0 : op->type = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
1918 : 0 : op->sess_type = RTE_CRYPTO_OP_WITH_SESSION;
1919 : 0 : op->phys_addr = rte_mbuf_iova_get(mbuf) + cfg->op_offset - sizeof(*mbuf);
1920 : 0 : op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
1921 : 0 : sym->m_src = mbuf;
1922 : 0 : sym->m_dst = NULL;
1923 : 0 : sym->session = data->session;
1924 : :
1925 : : /** pad the packet */
1926 : 0 : if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
1927 : 0 : uint32_t append_len = RTE_ALIGN_CEIL(payload_len,
1928 : : data->block_size) - payload_len;
1929 : :
1930 [ # # # # : 0 : if (unlikely(rte_pktmbuf_append(mbuf, append_len +
# # # # #
# # # ]
1931 : : data->digest_len) == NULL))
1932 : : return 1;
1933 : :
1934 : : payload_len += append_len;
1935 : : } else
1936 : 0 : payload_len -= data->digest_len;
1937 : :
1938 [ # # # # : 0 : if (data->op_mask & CRYPTO_OP_MASK_CIPHER) {
# # # # #
# # # ]
1939 : : /** prepare cipher op */
1940 : 0 : uint8_t *iv = crypto_op->iv_aad.cipher_auth.cipher_iv;
1941 : :
1942 : 0 : sym->cipher.data.length = payload_len;
1943 : 0 : sym->cipher.data.offset = data->data_offset - pkt_offset;
1944 : :
1945 [ # # # # : 0 : if (data->cipher_auth.cipher_iv_update_len) {
# # # # #
# # # ]
1946 : 0 : uint8_t *pkt_iv = RTE_MBUF_METADATA_UINT8_PTR(mbuf,
1947 : : data->cipher_auth.cipher_iv_data_offset
1948 : : + ip_offset);
1949 : :
1950 : : /** For encryption, update the pkt iv field, otherwise
1951 : : * update the iv_aad_field
1952 : : */
1953 [ # # # # : 0 : if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
# # # # #
# # # ]
1954 [ # # # # : 0 : rte_memcpy(pkt_iv, data->iv_aad_data,
# # # # #
# # # ]
1955 : : data->cipher_auth.cipher_iv_update_len);
1956 : : else
1957 [ # # # # : 0 : rte_memcpy(data->iv_aad_data, pkt_iv,
# # # # #
# # # ]
1958 : : data->cipher_auth.cipher_iv_update_len);
1959 : : }
1960 : :
1961 : : /** write iv */
1962 : 0 : rte_memcpy(iv, data->iv_aad_data,
1963 [ # # # # : 0 : data->cipher_auth.cipher_iv_len);
# # # # #
# # # ]
1964 : : }
1965 : :
1966 [ # # # # : 0 : if (data->op_mask & CRYPTO_OP_MASK_AUTH) {
# # # # #
# # # ]
1967 : : /** authentication always start from IP header. */
1968 : 0 : sym->auth.data.offset = ip_offset - pkt_offset;
1969 : 0 : sym->auth.data.length = mbuf->data_len - sym->auth.data.offset -
1970 : 0 : data->digest_len;
1971 : 0 : sym->auth.digest.data = rte_pktmbuf_mtod_offset(mbuf,
1972 : : uint8_t *, rte_pktmbuf_pkt_len(mbuf) -
1973 : : data->digest_len);
1974 : 0 : sym->auth.digest.phys_addr = rte_pktmbuf_iova_offset(mbuf,
1975 : : rte_pktmbuf_pkt_len(mbuf) - data->digest_len);
1976 : :
1977 [ # # # # : 0 : if (data->cipher_auth.auth_iv_update_len) {
# # # # #
# # # ]
1978 : 0 : uint8_t *pkt_iv = RTE_MBUF_METADATA_UINT8_PTR(mbuf,
1979 : : data->cipher_auth.auth_iv_data_offset
1980 : : + ip_offset);
1981 : 0 : uint8_t *data_iv = data->iv_aad_data +
1982 : 0 : data->cipher_auth.cipher_iv_len;
1983 : :
1984 [ # # # # : 0 : if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
# # # # #
# # # ]
1985 [ # # # # : 0 : rte_memcpy(pkt_iv, data_iv,
# # # # #
# # # ]
1986 : : data->cipher_auth.auth_iv_update_len);
1987 : : else
1988 [ # # # # : 0 : rte_memcpy(data_iv, pkt_iv,
# # # # #
# # # ]
1989 : : data->cipher_auth.auth_iv_update_len);
1990 : : }
1991 : :
1992 [ # # # # : 0 : if (data->cipher_auth.auth_iv_len) {
# # # # #
# # # ]
1993 : : /** prepare cipher op */
1994 : 0 : uint8_t *iv = crypto_op->iv_aad.cipher_auth.auth_iv;
1995 : :
1996 : 0 : rte_memcpy(iv, data->iv_aad_data +
1997 [ # # # # : 0 : data->cipher_auth.cipher_iv_len,
# # # # #
# # # ]
1998 : : data->cipher_auth.auth_iv_len);
1999 : : }
2000 : : }
2001 : :
2002 [ # # # # : 0 : if (data->op_mask & CRYPTO_OP_MASK_AEAD) {
# # # # #
# # # ]
2003 : 0 : uint8_t *iv = crypto_op->iv_aad.aead_iv_aad.iv;
2004 : 0 : uint8_t *aad = crypto_op->iv_aad.aead_iv_aad.aad;
2005 : :
2006 : 0 : sym->aead.aad.data = aad;
2007 : 0 : sym->aead.aad.phys_addr = rte_pktmbuf_iova_offset(mbuf,
2008 : : aad - rte_pktmbuf_mtod(mbuf, uint8_t *));
2009 : 0 : sym->aead.digest.data = rte_pktmbuf_mtod_offset(mbuf,
2010 : : uint8_t *, rte_pktmbuf_pkt_len(mbuf) -
2011 : : data->digest_len);
2012 : 0 : sym->aead.digest.phys_addr = rte_pktmbuf_iova_offset(mbuf,
2013 : : rte_pktmbuf_pkt_len(mbuf) - data->digest_len);
2014 : 0 : sym->aead.data.offset = data->data_offset - pkt_offset;
2015 : 0 : sym->aead.data.length = payload_len;
2016 : :
2017 [ # # # # : 0 : if (data->aead.iv_update_len) {
# # # # #
# # # ]
2018 : 0 : uint8_t *pkt_iv = RTE_MBUF_METADATA_UINT8_PTR(mbuf,
2019 : : data->aead.iv_data_offset + ip_offset);
2020 : 0 : uint8_t *data_iv = data->iv_aad_data;
2021 : :
2022 [ # # # # : 0 : if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
# # # # #
# # # ]
2023 [ # # # # : 0 : rte_memcpy(pkt_iv, data_iv,
# # # # #
# # # ]
2024 : : data->aead.iv_update_len);
2025 : : else
2026 [ # # # # : 0 : rte_memcpy(data_iv, pkt_iv,
# # # # #
# # # ]
2027 : : data->aead.iv_update_len);
2028 : : }
2029 : :
2030 [ # # # # : 0 : rte_memcpy(iv, data->iv_aad_data, data->aead.iv_len);
# # # # #
# # # ]
2031 : :
2032 [ # # # # : 0 : if (data->aead.aad_update_len) {
# # # # #
# # # ]
2033 : 0 : uint8_t *pkt_aad = RTE_MBUF_METADATA_UINT8_PTR(mbuf,
2034 : : data->aead.aad_data_offset + ip_offset);
2035 : 0 : uint8_t *data_aad = data->iv_aad_data +
2036 : 0 : data->aead.iv_len;
2037 : :
2038 [ # # # # : 0 : if (data->direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
# # # # #
# # # ]
2039 : 0 : rte_memcpy(pkt_aad, data_aad,
2040 [ # # # # : 0 : data->aead.iv_update_len);
# # # # #
# # # ]
2041 : : else
2042 : 0 : rte_memcpy(data_aad, pkt_aad,
2043 [ # # # # : 0 : data->aead.iv_update_len);
# # # # #
# # # ]
2044 : : }
2045 : :
2046 : 0 : rte_memcpy(aad, data->iv_aad_data + data->aead.iv_len,
2047 [ # # # # : 0 : data->aead.aad_len);
# # # # #
# # # ]
2048 : : }
2049 : :
2050 : : return 0;
2051 : : }
2052 : :
2053 : : /**
2054 : : * RTE_TABLE_ACTION_TAG
2055 : : */
2056 : : struct __rte_packed_begin tag_data {
2057 : : uint32_t tag;
2058 : : } __rte_packed_end;
2059 : :
2060 : : static int
2061 : : tag_apply(struct tag_data *data,
2062 : : struct rte_table_action_tag_params *p)
2063 : : {
2064 : 0 : data->tag = p->tag;
2065 : : return 0;
2066 : : }
2067 : :
2068 : : static __rte_always_inline void
2069 : : pkt_work_tag(struct rte_mbuf *mbuf,
2070 : : struct tag_data *data)
2071 : : {
2072 : 0 : mbuf->hash.fdir.hi = data->tag;
2073 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2074 : 0 : }
2075 : :
2076 : : static __rte_always_inline void
2077 : : pkt4_work_tag(struct rte_mbuf *mbuf0,
2078 : : struct rte_mbuf *mbuf1,
2079 : : struct rte_mbuf *mbuf2,
2080 : : struct rte_mbuf *mbuf3,
2081 : : struct tag_data *data0,
2082 : : struct tag_data *data1,
2083 : : struct tag_data *data2,
2084 : : struct tag_data *data3)
2085 : : {
2086 : 0 : mbuf0->hash.fdir.hi = data0->tag;
2087 : 0 : mbuf1->hash.fdir.hi = data1->tag;
2088 : 0 : mbuf2->hash.fdir.hi = data2->tag;
2089 : 0 : mbuf3->hash.fdir.hi = data3->tag;
2090 : :
2091 : 0 : mbuf0->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2092 : 0 : mbuf1->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2093 : 0 : mbuf2->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2094 : 0 : mbuf3->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2095 : 0 : }
2096 : :
2097 : : /**
2098 : : * RTE_TABLE_ACTION_DECAP
2099 : : */
2100 : : struct __rte_packed_begin decap_data {
2101 : : uint16_t n;
2102 : : } __rte_packed_end;
2103 : :
2104 : : static int
2105 : : decap_apply(struct decap_data *data,
2106 : : struct rte_table_action_decap_params *p)
2107 : : {
2108 : 0 : data->n = p->n;
2109 : : return 0;
2110 : : }
2111 : :
2112 : : static __rte_always_inline void
2113 : : pkt_work_decap(struct rte_mbuf *mbuf,
2114 : : struct decap_data *data)
2115 : : {
2116 : 0 : uint16_t data_off = mbuf->data_off;
2117 : 0 : uint16_t data_len = mbuf->data_len;
2118 : 0 : uint32_t pkt_len = mbuf->pkt_len;
2119 : 0 : uint16_t n = data->n;
2120 : :
2121 : 0 : mbuf->data_off = data_off + n;
2122 : 0 : mbuf->data_len = data_len - n;
2123 : 0 : mbuf->pkt_len = pkt_len - n;
2124 : 0 : }
2125 : :
2126 : : static __rte_always_inline void
2127 : : pkt4_work_decap(struct rte_mbuf *mbuf0,
2128 : : struct rte_mbuf *mbuf1,
2129 : : struct rte_mbuf *mbuf2,
2130 : : struct rte_mbuf *mbuf3,
2131 : : struct decap_data *data0,
2132 : : struct decap_data *data1,
2133 : : struct decap_data *data2,
2134 : : struct decap_data *data3)
2135 : : {
2136 : 0 : uint16_t data_off0 = mbuf0->data_off;
2137 : 0 : uint16_t data_len0 = mbuf0->data_len;
2138 : 0 : uint32_t pkt_len0 = mbuf0->pkt_len;
2139 : :
2140 : 0 : uint16_t data_off1 = mbuf1->data_off;
2141 : 0 : uint16_t data_len1 = mbuf1->data_len;
2142 : 0 : uint32_t pkt_len1 = mbuf1->pkt_len;
2143 : :
2144 : 0 : uint16_t data_off2 = mbuf2->data_off;
2145 : 0 : uint16_t data_len2 = mbuf2->data_len;
2146 : 0 : uint32_t pkt_len2 = mbuf2->pkt_len;
2147 : :
2148 : 0 : uint16_t data_off3 = mbuf3->data_off;
2149 : 0 : uint16_t data_len3 = mbuf3->data_len;
2150 : 0 : uint32_t pkt_len3 = mbuf3->pkt_len;
2151 : :
2152 : 0 : uint16_t n0 = data0->n;
2153 : 0 : uint16_t n1 = data1->n;
2154 : 0 : uint16_t n2 = data2->n;
2155 : 0 : uint16_t n3 = data3->n;
2156 : :
2157 : 0 : mbuf0->data_off = data_off0 + n0;
2158 : 0 : mbuf0->data_len = data_len0 - n0;
2159 : 0 : mbuf0->pkt_len = pkt_len0 - n0;
2160 : :
2161 : 0 : mbuf1->data_off = data_off1 + n1;
2162 : 0 : mbuf1->data_len = data_len1 - n1;
2163 : 0 : mbuf1->pkt_len = pkt_len1 - n1;
2164 : :
2165 : 0 : mbuf2->data_off = data_off2 + n2;
2166 : 0 : mbuf2->data_len = data_len2 - n2;
2167 : 0 : mbuf2->pkt_len = pkt_len2 - n2;
2168 : :
2169 : 0 : mbuf3->data_off = data_off3 + n3;
2170 : 0 : mbuf3->data_len = data_len3 - n3;
2171 : 0 : mbuf3->pkt_len = pkt_len3 - n3;
2172 : 0 : }
2173 : :
2174 : : /**
2175 : : * Action profile
2176 : : */
2177 : : static int
2178 : : action_valid(enum rte_table_action_type action)
2179 : : {
2180 [ # # # # ]: 0 : switch (action) {
2181 : : case RTE_TABLE_ACTION_FWD:
2182 : : case RTE_TABLE_ACTION_LB:
2183 : : case RTE_TABLE_ACTION_MTR:
2184 : : case RTE_TABLE_ACTION_TM:
2185 : : case RTE_TABLE_ACTION_ENCAP:
2186 : : case RTE_TABLE_ACTION_NAT:
2187 : : case RTE_TABLE_ACTION_TTL:
2188 : : case RTE_TABLE_ACTION_STATS:
2189 : : case RTE_TABLE_ACTION_TIME:
2190 : : case RTE_TABLE_ACTION_SYM_CRYPTO:
2191 : : case RTE_TABLE_ACTION_TAG:
2192 : : case RTE_TABLE_ACTION_DECAP:
2193 : : return 1;
2194 : : default:
2195 : : return 0;
2196 : : }
2197 : : }
2198 : :
2199 : :
2200 : : #define RTE_TABLE_ACTION_MAX 64
2201 : :
2202 : : struct ap_config {
2203 : : uint64_t action_mask;
2204 : : struct rte_table_action_common_config common;
2205 : : struct rte_table_action_lb_config lb;
2206 : : struct rte_table_action_mtr_config mtr;
2207 : : struct rte_table_action_tm_config tm;
2208 : : struct rte_table_action_encap_config encap;
2209 : : struct rte_table_action_nat_config nat;
2210 : : struct rte_table_action_ttl_config ttl;
2211 : : struct rte_table_action_stats_config stats;
2212 : : struct rte_table_action_sym_crypto_config sym_crypto;
2213 : : };
2214 : :
2215 : : static size_t
2216 : : action_cfg_size(enum rte_table_action_type action)
2217 : : {
2218 : : switch (action) {
2219 : : case RTE_TABLE_ACTION_LB:
2220 : : return sizeof(struct rte_table_action_lb_config);
2221 : : case RTE_TABLE_ACTION_MTR:
2222 : : return sizeof(struct rte_table_action_mtr_config);
2223 : : case RTE_TABLE_ACTION_TM:
2224 : : return sizeof(struct rte_table_action_tm_config);
2225 : : case RTE_TABLE_ACTION_ENCAP:
2226 : : return sizeof(struct rte_table_action_encap_config);
2227 : : case RTE_TABLE_ACTION_NAT:
2228 : : return sizeof(struct rte_table_action_nat_config);
2229 : : case RTE_TABLE_ACTION_TTL:
2230 : : return sizeof(struct rte_table_action_ttl_config);
2231 : : case RTE_TABLE_ACTION_STATS:
2232 : : return sizeof(struct rte_table_action_stats_config);
2233 : : case RTE_TABLE_ACTION_SYM_CRYPTO:
2234 : : return sizeof(struct rte_table_action_sym_crypto_config);
2235 : : default:
2236 : : return 0;
2237 : : }
2238 : : }
2239 : :
2240 : : static void*
2241 : : action_cfg_get(struct ap_config *ap_config,
2242 : : enum rte_table_action_type type)
2243 : : {
2244 : 0 : switch (type) {
2245 : 0 : case RTE_TABLE_ACTION_LB:
2246 : 0 : return &ap_config->lb;
2247 : :
2248 : 0 : case RTE_TABLE_ACTION_MTR:
2249 : 0 : return &ap_config->mtr;
2250 : :
2251 : 0 : case RTE_TABLE_ACTION_TM:
2252 : 0 : return &ap_config->tm;
2253 : :
2254 : 0 : case RTE_TABLE_ACTION_ENCAP:
2255 : 0 : return &ap_config->encap;
2256 : :
2257 : 0 : case RTE_TABLE_ACTION_NAT:
2258 : 0 : return &ap_config->nat;
2259 : :
2260 : 0 : case RTE_TABLE_ACTION_TTL:
2261 : 0 : return &ap_config->ttl;
2262 : :
2263 : 0 : case RTE_TABLE_ACTION_STATS:
2264 : 0 : return &ap_config->stats;
2265 : :
2266 : 0 : case RTE_TABLE_ACTION_SYM_CRYPTO:
2267 : 0 : return &ap_config->sym_crypto;
2268 : : default:
2269 : : return NULL;
2270 : : }
2271 : : }
2272 : :
2273 : : static void
2274 [ # # # # : 0 : action_cfg_set(struct ap_config *ap_config,
# # # #
# ]
2275 : : enum rte_table_action_type type,
2276 : : void *action_cfg)
2277 : : {
2278 : : void *dst = action_cfg_get(ap_config, type);
2279 : :
2280 : : if (dst)
2281 : : memcpy(dst, action_cfg, action_cfg_size(type));
2282 : :
2283 : 0 : ap_config->action_mask |= 1LLU << type;
2284 : 0 : }
2285 : :
2286 : : struct ap_data {
2287 : : size_t offset[RTE_TABLE_ACTION_MAX];
2288 : : size_t total_size;
2289 : : };
2290 : :
2291 : : static size_t
2292 : 0 : action_data_size(enum rte_table_action_type action,
2293 : : struct ap_config *ap_config)
2294 : : {
2295 [ # # # # : 0 : switch (action) {
# # # # #
# # ]
2296 : : case RTE_TABLE_ACTION_FWD:
2297 : : return sizeof(struct fwd_data);
2298 : :
2299 : 0 : case RTE_TABLE_ACTION_LB:
2300 : 0 : return sizeof(struct lb_data);
2301 : :
2302 : 0 : case RTE_TABLE_ACTION_MTR:
2303 : 0 : return mtr_data_size(&ap_config->mtr);
2304 : :
2305 : : case RTE_TABLE_ACTION_TM:
2306 : : return sizeof(struct tm_data);
2307 : :
2308 : 0 : case RTE_TABLE_ACTION_ENCAP:
2309 : 0 : return encap_data_size(&ap_config->encap);
2310 : :
2311 [ # # ]: 0 : case RTE_TABLE_ACTION_NAT:
2312 : : return nat_data_size(&ap_config->nat,
2313 : : &ap_config->common);
2314 : :
2315 : 0 : case RTE_TABLE_ACTION_TTL:
2316 : 0 : return sizeof(struct ttl_data);
2317 : :
2318 : 0 : case RTE_TABLE_ACTION_STATS:
2319 : 0 : return sizeof(struct stats_data);
2320 : :
2321 : : case RTE_TABLE_ACTION_TIME:
2322 : : return sizeof(struct time_data);
2323 : :
2324 : 0 : case RTE_TABLE_ACTION_SYM_CRYPTO:
2325 : 0 : return (sizeof(struct sym_crypto_data));
2326 : :
2327 : 0 : case RTE_TABLE_ACTION_TAG:
2328 : 0 : return sizeof(struct tag_data);
2329 : :
2330 : 0 : case RTE_TABLE_ACTION_DECAP:
2331 : 0 : return sizeof(struct decap_data);
2332 : :
2333 : 0 : default:
2334 : 0 : return 0;
2335 : : }
2336 : : }
2337 : :
2338 : :
2339 : : static void
2340 : 0 : action_data_offset_set(struct ap_data *ap_data,
2341 : : struct ap_config *ap_config)
2342 : : {
2343 : 0 : uint64_t action_mask = ap_config->action_mask;
2344 : : size_t offset;
2345 : : uint32_t action;
2346 : :
2347 : 0 : memset(ap_data->offset, 0, sizeof(ap_data->offset));
2348 : :
2349 : : offset = 0;
2350 [ # # ]: 0 : for (action = 0; action < RTE_TABLE_ACTION_MAX; action++)
2351 [ # # ]: 0 : if (action_mask & (1LLU << action)) {
2352 : 0 : ap_data->offset[action] = offset;
2353 : 0 : offset += action_data_size((enum rte_table_action_type)action,
2354 : : ap_config);
2355 : : }
2356 : :
2357 : 0 : ap_data->total_size = offset;
2358 : 0 : }
2359 : :
2360 : : struct rte_table_action_profile {
2361 : : struct ap_config cfg;
2362 : : struct ap_data data;
2363 : : int frozen;
2364 : : };
2365 : :
2366 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_profile_create, 18.05)
2367 : : struct rte_table_action_profile *
2368 : 0 : rte_table_action_profile_create(struct rte_table_action_common_config *common)
2369 : : {
2370 : : struct rte_table_action_profile *ap;
2371 : :
2372 : : /* Check input arguments */
2373 [ # # ]: 0 : if (common == NULL)
2374 : : return NULL;
2375 : :
2376 : : /* Memory allocation */
2377 : 0 : ap = calloc(1, sizeof(struct rte_table_action_profile));
2378 [ # # ]: 0 : if (ap == NULL)
2379 : : return NULL;
2380 : :
2381 : : /* Initialization */
2382 : 0 : memcpy(&ap->cfg.common, common, sizeof(*common));
2383 : :
2384 : 0 : return ap;
2385 : : }
2386 : :
2387 : :
2388 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_profile_action_register, 18.05)
2389 : : int
2390 : 0 : rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
2391 : : enum rte_table_action_type type,
2392 : : void *action_config)
2393 : : {
2394 : : int status;
2395 : :
2396 : : /* Check input arguments */
2397 [ # # ]: 0 : if ((profile == NULL) ||
2398 [ # # ]: 0 : profile->frozen ||
2399 : 0 : (action_valid(type) == 0) ||
2400 [ # # # # ]: 0 : (profile->cfg.action_mask & (1LLU << type)) ||
2401 [ # # # # ]: 0 : ((action_cfg_size(type) == 0) && action_config) ||
2402 [ # # ]: 0 : (action_cfg_size(type) && (action_config == NULL)))
2403 : : return -EINVAL;
2404 : :
2405 [ # # # # : 0 : switch (type) {
# # # #
# ]
2406 : : case RTE_TABLE_ACTION_LB:
2407 : : status = lb_cfg_check(action_config);
2408 : : break;
2409 : :
2410 : : case RTE_TABLE_ACTION_MTR:
2411 : : status = mtr_cfg_check(action_config);
2412 : : break;
2413 : :
2414 : : case RTE_TABLE_ACTION_TM:
2415 : : status = tm_cfg_check(action_config);
2416 : : break;
2417 : :
2418 : : case RTE_TABLE_ACTION_ENCAP:
2419 : : status = encap_cfg_check(action_config);
2420 : : break;
2421 : :
2422 : : case RTE_TABLE_ACTION_NAT:
2423 : : status = nat_cfg_check(action_config);
2424 : : break;
2425 : :
2426 : : case RTE_TABLE_ACTION_TTL:
2427 : : status = ttl_cfg_check(action_config);
2428 : : break;
2429 : :
2430 : : case RTE_TABLE_ACTION_STATS:
2431 : : status = stats_cfg_check(action_config);
2432 : : break;
2433 : :
2434 : 0 : case RTE_TABLE_ACTION_SYM_CRYPTO:
2435 : 0 : status = sym_crypto_cfg_check(action_config);
2436 : : break;
2437 : :
2438 : : default:
2439 : : status = 0;
2440 : : break;
2441 : : }
2442 : :
2443 [ # # ]: 0 : if (status)
2444 : 0 : return status;
2445 : :
2446 : : /* Action enable */
2447 : 0 : action_cfg_set(&profile->cfg, type, action_config);
2448 : :
2449 : 0 : return 0;
2450 : : }
2451 : :
2452 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_profile_freeze, 18.05)
2453 : : int
2454 : 0 : rte_table_action_profile_freeze(struct rte_table_action_profile *profile)
2455 : : {
2456 [ # # ]: 0 : if (profile->frozen)
2457 : : return -EBUSY;
2458 : :
2459 : 0 : profile->cfg.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
2460 : 0 : action_data_offset_set(&profile->data, &profile->cfg);
2461 : 0 : profile->frozen = 1;
2462 : :
2463 : 0 : return 0;
2464 : : }
2465 : :
2466 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_profile_free, 18.05)
2467 : : int
2468 : 0 : rte_table_action_profile_free(struct rte_table_action_profile *profile)
2469 : : {
2470 [ # # ]: 0 : if (profile == NULL)
2471 : : return 0;
2472 : :
2473 : 0 : free(profile);
2474 : 0 : return 0;
2475 : : }
2476 : :
2477 : : /**
2478 : : * Action
2479 : : */
2480 : : #define METER_PROFILES_MAX 32
2481 : :
2482 : : struct rte_table_action {
2483 : : struct ap_config cfg;
2484 : : struct ap_data data;
2485 : : struct dscp_table_data dscp_table;
2486 : : struct meter_profile_data mp[METER_PROFILES_MAX];
2487 : : };
2488 : :
2489 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_create, 18.05)
2490 : : struct rte_table_action *
2491 : 0 : rte_table_action_create(struct rte_table_action_profile *profile,
2492 : : uint32_t socket_id)
2493 : : {
2494 : : struct rte_table_action *action;
2495 : :
2496 : : /* Check input arguments */
2497 [ # # ]: 0 : if ((profile == NULL) ||
2498 [ # # ]: 0 : (profile->frozen == 0))
2499 : : return NULL;
2500 : :
2501 : : /* Memory allocation */
2502 : 0 : action = rte_zmalloc_socket(NULL,
2503 : : sizeof(struct rte_table_action),
2504 : : RTE_CACHE_LINE_SIZE,
2505 : : socket_id);
2506 [ # # ]: 0 : if (action == NULL)
2507 : : return NULL;
2508 : :
2509 : : /* Initialization */
2510 : 0 : memcpy(&action->cfg, &profile->cfg, sizeof(profile->cfg));
2511 : 0 : memcpy(&action->data, &profile->data, sizeof(profile->data));
2512 : :
2513 : 0 : return action;
2514 : : }
2515 : :
2516 : : static __rte_always_inline void *
2517 : : action_data_get(void *data,
2518 : : struct rte_table_action *action,
2519 : : enum rte_table_action_type type)
2520 : : {
2521 : 0 : size_t offset = action->data.offset[type];
2522 : : uint8_t *data_bytes = data;
2523 : :
2524 : 0 : return &data_bytes[offset];
2525 : : }
2526 : :
2527 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_apply, 18.05)
2528 : : int
2529 : 0 : rte_table_action_apply(struct rte_table_action *action,
2530 : : void *data,
2531 : : enum rte_table_action_type type,
2532 : : void *action_params)
2533 : : {
2534 : : void *action_data;
2535 : :
2536 : : /* Check input arguments */
2537 : 0 : if ((action == NULL) ||
2538 [ # # ]: 0 : (data == NULL) ||
2539 : 0 : (action_valid(type) == 0) ||
2540 [ # # # # ]: 0 : ((action->cfg.action_mask & (1LLU << type)) == 0) ||
2541 : : (action_params == NULL))
2542 : : return -EINVAL;
2543 : :
2544 : : /* Data update */
2545 : : action_data = action_data_get(data, action, type);
2546 : :
2547 [ # # # # : 0 : switch (type) {
# # # # #
# # # ]
2548 : : case RTE_TABLE_ACTION_FWD:
2549 : : return fwd_apply(action_data,
2550 : : action_params);
2551 : :
2552 : : case RTE_TABLE_ACTION_LB:
2553 : 0 : return lb_apply(action_data,
2554 : : action_params);
2555 : :
2556 : 0 : case RTE_TABLE_ACTION_MTR:
2557 : 0 : return mtr_apply(action_data,
2558 : : action_params,
2559 : : &action->cfg.mtr,
2560 : 0 : action->mp,
2561 : : RTE_DIM(action->mp));
2562 : :
2563 [ # # ]: 0 : case RTE_TABLE_ACTION_TM:
2564 : : return tm_apply(action_data,
2565 : : action_params,
2566 : : &action->cfg.tm);
2567 : :
2568 : 0 : case RTE_TABLE_ACTION_ENCAP:
2569 : 0 : return encap_apply(action_data,
2570 : : action_params,
2571 : : &action->cfg.encap,
2572 : : &action->cfg.common);
2573 : :
2574 : 0 : case RTE_TABLE_ACTION_NAT:
2575 : 0 : return nat_apply(action_data,
2576 : : action_params,
2577 : : &action->cfg.common);
2578 : :
2579 : : case RTE_TABLE_ACTION_TTL:
2580 : 0 : return ttl_apply(action_data,
2581 : : action_params);
2582 : :
2583 : : case RTE_TABLE_ACTION_STATS:
2584 : 0 : return stats_apply(action_data,
2585 : : action_params);
2586 : :
2587 : : case RTE_TABLE_ACTION_TIME:
2588 : 0 : return time_apply(action_data,
2589 : : action_params);
2590 : :
2591 : 0 : case RTE_TABLE_ACTION_SYM_CRYPTO:
2592 : 0 : return sym_crypto_apply(action_data,
2593 : : &action->cfg.sym_crypto,
2594 : : action_params);
2595 : :
2596 : : case RTE_TABLE_ACTION_TAG:
2597 : 0 : return tag_apply(action_data,
2598 : : action_params);
2599 : :
2600 : : case RTE_TABLE_ACTION_DECAP:
2601 : 0 : return decap_apply(action_data,
2602 : : action_params);
2603 : :
2604 : : default:
2605 : : return -EINVAL;
2606 : : }
2607 : : }
2608 : :
2609 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_dscp_table_update, 18.05)
2610 : : int
2611 : 0 : rte_table_action_dscp_table_update(struct rte_table_action *action,
2612 : : uint64_t dscp_mask,
2613 : : struct rte_table_action_dscp_table *table)
2614 : : {
2615 : : uint32_t i;
2616 : :
2617 : : /* Check input arguments */
2618 [ # # ]: 0 : if ((action == NULL) ||
2619 [ # # ]: 0 : ((action->cfg.action_mask & ((1LLU << RTE_TABLE_ACTION_MTR) |
2620 : : (1LLU << RTE_TABLE_ACTION_TM))) == 0) ||
2621 : 0 : (dscp_mask == 0) ||
2622 [ # # ]: 0 : (table == NULL))
2623 : : return -EINVAL;
2624 : :
2625 [ # # ]: 0 : for (i = 0; i < RTE_DIM(table->entry); i++) {
2626 : : struct dscp_table_entry_data *data =
2627 : : &action->dscp_table.entry[i];
2628 : : struct rte_table_action_dscp_table_entry *entry =
2629 : : &table->entry[i];
2630 : :
2631 [ # # ]: 0 : if ((dscp_mask & (1LLU << i)) == 0)
2632 : 0 : continue;
2633 : :
2634 : 0 : data->color = entry->color;
2635 : 0 : data->tc = entry->tc_id;
2636 : 0 : data->tc_queue = entry->tc_queue_id;
2637 : : }
2638 : :
2639 : : return 0;
2640 : : }
2641 : :
2642 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_meter_profile_add, 18.05)
2643 : : int
2644 : 0 : rte_table_action_meter_profile_add(struct rte_table_action *action,
2645 : : uint32_t meter_profile_id,
2646 : : struct rte_table_action_meter_profile *profile)
2647 : : {
2648 : : struct meter_profile_data *mp_data;
2649 : : uint32_t status;
2650 : :
2651 : : /* Check input arguments */
2652 [ # # ]: 0 : if ((action == NULL) ||
2653 [ # # # # ]: 0 : ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) ||
2654 : : (profile == NULL))
2655 : : return -EINVAL;
2656 : :
2657 [ # # ]: 0 : if (profile->alg != RTE_TABLE_ACTION_METER_TRTCM)
2658 : : return -ENOTSUP;
2659 : :
2660 : 0 : mp_data = meter_profile_data_find(action->mp,
2661 : : RTE_DIM(action->mp),
2662 : : meter_profile_id);
2663 [ # # ]: 0 : if (mp_data)
2664 : : return -EEXIST;
2665 : :
2666 : : mp_data = meter_profile_data_find_unused(action->mp,
2667 : : RTE_DIM(action->mp));
2668 [ # # ]: 0 : if (!mp_data)
2669 : : return -ENOSPC;
2670 : :
2671 : : /* Install new profile */
2672 : 0 : status = rte_meter_trtcm_profile_config(&mp_data->profile,
2673 : : &profile->trtcm);
2674 [ # # ]: 0 : if (status)
2675 : : return status;
2676 : :
2677 : 0 : mp_data->profile_id = meter_profile_id;
2678 : 0 : mp_data->valid = 1;
2679 : :
2680 : 0 : return 0;
2681 : : }
2682 : :
2683 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_meter_profile_delete, 18.05)
2684 : : int
2685 : 0 : rte_table_action_meter_profile_delete(struct rte_table_action *action,
2686 : : uint32_t meter_profile_id)
2687 : : {
2688 : : struct meter_profile_data *mp_data;
2689 : :
2690 : : /* Check input arguments */
2691 [ # # ]: 0 : if ((action == NULL) ||
2692 [ # # ]: 0 : ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0))
2693 : : return -EINVAL;
2694 : :
2695 : 0 : mp_data = meter_profile_data_find(action->mp,
2696 : : RTE_DIM(action->mp),
2697 : : meter_profile_id);
2698 [ # # ]: 0 : if (!mp_data)
2699 : : return 0;
2700 : :
2701 : : /* Uninstall profile */
2702 : 0 : mp_data->valid = 0;
2703 : :
2704 : 0 : return 0;
2705 : : }
2706 : :
2707 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_meter_read, 18.05)
2708 : : int
2709 : 0 : rte_table_action_meter_read(struct rte_table_action *action,
2710 : : void *data,
2711 : : uint32_t tc_mask,
2712 : : struct rte_table_action_mtr_counters *stats,
2713 : : int clear)
2714 : : {
2715 : : struct mtr_trtcm_data *mtr_data;
2716 : : uint32_t i;
2717 : :
2718 : : /* Check input arguments */
2719 [ # # ]: 0 : if ((action == NULL) ||
2720 [ # # # # ]: 0 : ((action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) ||
2721 : 0 : (data == NULL) ||
2722 [ # # ]: 0 : (tc_mask > RTE_LEN2MASK(action->cfg.mtr.n_tc, uint32_t)))
2723 : : return -EINVAL;
2724 : :
2725 : : mtr_data = action_data_get(data, action, RTE_TABLE_ACTION_MTR);
2726 : :
2727 : : /* Read */
2728 [ # # ]: 0 : if (stats) {
2729 [ # # ]: 0 : for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
2730 : : struct rte_table_action_mtr_counters_tc *dst =
2731 : : &stats->stats[i];
2732 : 0 : struct mtr_trtcm_data *src = &mtr_data[i];
2733 : :
2734 [ # # ]: 0 : if ((tc_mask & (1 << i)) == 0)
2735 : 0 : continue;
2736 : :
2737 : 0 : dst->n_packets[RTE_COLOR_GREEN] =
2738 : : mtr_trtcm_data_stats_get(src, RTE_COLOR_GREEN);
2739 : :
2740 : 0 : dst->n_packets[RTE_COLOR_YELLOW] =
2741 : : mtr_trtcm_data_stats_get(src, RTE_COLOR_YELLOW);
2742 : :
2743 : 0 : dst->n_packets[RTE_COLOR_RED] =
2744 : : mtr_trtcm_data_stats_get(src, RTE_COLOR_RED);
2745 : :
2746 : 0 : dst->n_packets_valid = 1;
2747 : 0 : dst->n_bytes_valid = 0;
2748 : : }
2749 : :
2750 : 0 : stats->tc_mask = tc_mask;
2751 : : }
2752 : :
2753 : : /* Clear */
2754 [ # # ]: 0 : if (clear)
2755 [ # # ]: 0 : for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++) {
2756 : 0 : struct mtr_trtcm_data *src = &mtr_data[i];
2757 : :
2758 [ # # ]: 0 : if ((tc_mask & (1 << i)) == 0)
2759 : 0 : continue;
2760 : :
2761 : : mtr_trtcm_data_stats_reset(src, RTE_COLOR_GREEN);
2762 : : mtr_trtcm_data_stats_reset(src, RTE_COLOR_YELLOW);
2763 : : mtr_trtcm_data_stats_reset(src, RTE_COLOR_RED);
2764 : : }
2765 : :
2766 : :
2767 : : return 0;
2768 : : }
2769 : :
2770 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_ttl_read, 18.05)
2771 : : int
2772 : 0 : rte_table_action_ttl_read(struct rte_table_action *action,
2773 : : void *data,
2774 : : struct rte_table_action_ttl_counters *stats,
2775 : : int clear)
2776 : : {
2777 : : struct ttl_data *ttl_data;
2778 : :
2779 : : /* Check input arguments */
2780 [ # # ]: 0 : if ((action == NULL) ||
2781 [ # # ]: 0 : ((action->cfg.action_mask &
2782 [ # # ]: 0 : (1LLU << RTE_TABLE_ACTION_TTL)) == 0) ||
2783 : : (data == NULL))
2784 : : return -EINVAL;
2785 : :
2786 : : ttl_data = action_data_get(data, action, RTE_TABLE_ACTION_TTL);
2787 : :
2788 : : /* Read */
2789 [ # # ]: 0 : if (stats)
2790 : 0 : stats->n_packets = TTL_STATS_READ(ttl_data);
2791 : :
2792 : : /* Clear */
2793 [ # # ]: 0 : if (clear)
2794 : 0 : TTL_STATS_RESET(ttl_data);
2795 : :
2796 : : return 0;
2797 : : }
2798 : :
2799 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_stats_read, 18.05)
2800 : : int
2801 : 0 : rte_table_action_stats_read(struct rte_table_action *action,
2802 : : void *data,
2803 : : struct rte_table_action_stats_counters *stats,
2804 : : int clear)
2805 : : {
2806 : : struct stats_data *stats_data;
2807 : :
2808 : : /* Check input arguments */
2809 [ # # ]: 0 : if ((action == NULL) ||
2810 [ # # ]: 0 : ((action->cfg.action_mask &
2811 [ # # ]: 0 : (1LLU << RTE_TABLE_ACTION_STATS)) == 0) ||
2812 : : (data == NULL))
2813 : : return -EINVAL;
2814 : :
2815 : : stats_data = action_data_get(data, action,
2816 : : RTE_TABLE_ACTION_STATS);
2817 : :
2818 : : /* Read */
2819 [ # # ]: 0 : if (stats) {
2820 : 0 : stats->n_packets = stats_data->n_packets;
2821 : 0 : stats->n_bytes = stats_data->n_bytes;
2822 : 0 : stats->n_packets_valid = 1;
2823 : 0 : stats->n_bytes_valid = 1;
2824 : : }
2825 : :
2826 : : /* Clear */
2827 [ # # ]: 0 : if (clear) {
2828 : 0 : stats_data->n_packets = 0;
2829 : 0 : stats_data->n_bytes = 0;
2830 : : }
2831 : :
2832 : : return 0;
2833 : : }
2834 : :
2835 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_time_read, 18.05)
2836 : : int
2837 : 0 : rte_table_action_time_read(struct rte_table_action *action,
2838 : : void *data,
2839 : : uint64_t *timestamp)
2840 : : {
2841 : : struct time_data *time_data;
2842 : :
2843 : : /* Check input arguments */
2844 [ # # ]: 0 : if ((action == NULL) ||
2845 [ # # ]: 0 : ((action->cfg.action_mask &
2846 : : (1LLU << RTE_TABLE_ACTION_TIME)) == 0) ||
2847 : 0 : (data == NULL) ||
2848 [ # # ]: 0 : (timestamp == NULL))
2849 : : return -EINVAL;
2850 : :
2851 : : time_data = action_data_get(data, action, RTE_TABLE_ACTION_TIME);
2852 : :
2853 : : /* Read */
2854 : 0 : *timestamp = time_data->time;
2855 : :
2856 : 0 : return 0;
2857 : : }
2858 : :
2859 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_crypto_sym_session_get, 18.11)
2860 : : struct rte_cryptodev_sym_session *
2861 : 0 : rte_table_action_crypto_sym_session_get(struct rte_table_action *action,
2862 : : void *data)
2863 : : {
2864 : : struct sym_crypto_data *sym_crypto_data;
2865 : :
2866 : : /* Check input arguments */
2867 [ # # ]: 0 : if ((action == NULL) ||
2868 [ # # ]: 0 : ((action->cfg.action_mask &
2869 [ # # ]: 0 : (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO)) == 0) ||
2870 : : (data == NULL))
2871 : : return NULL;
2872 : :
2873 : : sym_crypto_data = action_data_get(data, action,
2874 : : RTE_TABLE_ACTION_SYM_CRYPTO);
2875 : :
2876 : 0 : return sym_crypto_data->session;
2877 : : }
2878 : :
2879 : : static __rte_always_inline uint64_t
2880 : : pkt_work(struct rte_mbuf *mbuf,
2881 : : struct rte_pipeline_table_entry *table_entry,
2882 : : uint64_t time,
2883 : : struct rte_table_action *action,
2884 : : struct ap_config *cfg)
2885 : : {
2886 : : uint64_t drop_mask = 0;
2887 : :
2888 : 0 : uint32_t ip_offset = action->cfg.common.ip_offset;
2889 : 0 : void *ip = RTE_MBUF_METADATA_UINT32_PTR(mbuf, ip_offset);
2890 : :
2891 : : uint32_t dscp;
2892 : : uint16_t total_length;
2893 : :
2894 : 0 : if (cfg->common.ip_version) {
2895 : : struct rte_ipv4_hdr *hdr = ip;
2896 : :
2897 : 0 : dscp = hdr->type_of_service >> 2;
2898 [ # # # # ]: 0 : total_length = rte_ntohs(hdr->total_length);
2899 : : } else {
2900 : : struct rte_ipv6_hdr *hdr = ip;
2901 : :
2902 [ # # # # ]: 0 : dscp = (rte_ntohl(hdr->vtc_flow) & 0x0F600000) >> 18;
2903 [ # # # # ]: 0 : total_length = rte_ntohs(hdr->payload_len) +
2904 : : sizeof(struct rte_ipv6_hdr);
2905 : : }
2906 : :
2907 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
2908 : : void *data =
2909 : : action_data_get(table_entry, action, RTE_TABLE_ACTION_LB);
2910 : :
2911 : : pkt_work_lb(mbuf,
2912 : : data,
2913 : : &cfg->lb);
2914 : : }
2915 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
2916 : : void *data =
2917 : : action_data_get(table_entry, action, RTE_TABLE_ACTION_MTR);
2918 : :
2919 : : drop_mask |= pkt_work_mtr(mbuf,
2920 : : data,
2921 : : &action->dscp_table,
2922 : 0 : action->mp,
2923 : : time,
2924 : : dscp,
2925 : : total_length);
2926 : : }
2927 : :
2928 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
2929 : : void *data =
2930 : : action_data_get(table_entry, action, RTE_TABLE_ACTION_TM);
2931 : :
2932 : : pkt_work_tm(mbuf,
2933 : : data,
2934 : : &action->dscp_table,
2935 : : dscp);
2936 : : }
2937 : :
2938 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP)) {
2939 : : void *data = action_data_get(table_entry,
2940 : : action,
2941 : : RTE_TABLE_ACTION_DECAP);
2942 : :
2943 : : pkt_work_decap(mbuf, data);
2944 : : }
2945 : :
2946 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
2947 : : void *data =
2948 : : action_data_get(table_entry, action, RTE_TABLE_ACTION_ENCAP);
2949 : :
2950 [ # # # # : 0 : pkt_work_encap(mbuf,
# # # # #
# # # # #
# # ]
2951 : : data,
2952 : : &cfg->encap,
2953 : : ip,
2954 : : total_length,
2955 : : ip_offset);
2956 : : }
2957 : :
2958 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
2959 : : void *data =
2960 : : action_data_get(table_entry, action, RTE_TABLE_ACTION_NAT);
2961 : :
2962 [ # # # # ]: 0 : if (cfg->common.ip_version)
2963 : : pkt_ipv4_work_nat(ip, data, &cfg->nat);
2964 : : else
2965 : : pkt_ipv6_work_nat(ip, data, &cfg->nat);
2966 : : }
2967 : :
2968 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
2969 : : void *data =
2970 : : action_data_get(table_entry, action, RTE_TABLE_ACTION_TTL);
2971 : :
2972 [ # # # # ]: 0 : if (cfg->common.ip_version)
2973 : 0 : drop_mask |= pkt_ipv4_work_ttl(ip, data);
2974 : : else
2975 : 0 : drop_mask |= pkt_ipv6_work_ttl(ip, data);
2976 : : }
2977 : :
2978 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
2979 : : void *data =
2980 : : action_data_get(table_entry, action, RTE_TABLE_ACTION_STATS);
2981 : :
2982 : : pkt_work_stats(data, total_length);
2983 : : }
2984 : :
2985 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
2986 : : void *data =
2987 : : action_data_get(table_entry, action, RTE_TABLE_ACTION_TIME);
2988 : :
2989 : : pkt_work_time(data, time);
2990 : : }
2991 : :
2992 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO)) {
2993 : : void *data = action_data_get(table_entry, action,
2994 : : RTE_TABLE_ACTION_SYM_CRYPTO);
2995 : :
2996 [ # # # # ]: 0 : drop_mask |= pkt_work_sym_crypto(mbuf, data, &cfg->sym_crypto,
2997 : : ip_offset);
2998 : : }
2999 : :
3000 [ # # # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TAG)) {
3001 : : void *data = action_data_get(table_entry,
3002 : : action,
3003 : : RTE_TABLE_ACTION_TAG);
3004 : :
3005 : : pkt_work_tag(mbuf, data);
3006 : : }
3007 : :
3008 : : return drop_mask;
3009 : : }
3010 : :
3011 : : static __rte_always_inline uint64_t
3012 : : pkt4_work(struct rte_mbuf **mbufs,
3013 : : struct rte_pipeline_table_entry **table_entries,
3014 : : uint64_t time,
3015 : : struct rte_table_action *action,
3016 : : struct ap_config *cfg)
3017 : : {
3018 : : uint64_t drop_mask0 = 0;
3019 : : uint64_t drop_mask1 = 0;
3020 : : uint64_t drop_mask2 = 0;
3021 : : uint64_t drop_mask3 = 0;
3022 : :
3023 : 0 : struct rte_mbuf *mbuf0 = mbufs[0];
3024 : 0 : struct rte_mbuf *mbuf1 = mbufs[1];
3025 : 0 : struct rte_mbuf *mbuf2 = mbufs[2];
3026 : 0 : struct rte_mbuf *mbuf3 = mbufs[3];
3027 : :
3028 : 0 : struct rte_pipeline_table_entry *table_entry0 = table_entries[0];
3029 : 0 : struct rte_pipeline_table_entry *table_entry1 = table_entries[1];
3030 : 0 : struct rte_pipeline_table_entry *table_entry2 = table_entries[2];
3031 : 0 : struct rte_pipeline_table_entry *table_entry3 = table_entries[3];
3032 : :
3033 : 0 : uint32_t ip_offset = action->cfg.common.ip_offset;
3034 : 0 : void *ip0 = RTE_MBUF_METADATA_UINT32_PTR(mbuf0, ip_offset);
3035 : 0 : void *ip1 = RTE_MBUF_METADATA_UINT32_PTR(mbuf1, ip_offset);
3036 : 0 : void *ip2 = RTE_MBUF_METADATA_UINT32_PTR(mbuf2, ip_offset);
3037 : 0 : void *ip3 = RTE_MBUF_METADATA_UINT32_PTR(mbuf3, ip_offset);
3038 : :
3039 : : uint32_t dscp0, dscp1, dscp2, dscp3;
3040 : : uint16_t total_length0, total_length1, total_length2, total_length3;
3041 : :
3042 : 0 : if (cfg->common.ip_version) {
3043 : : struct rte_ipv4_hdr *hdr0 = ip0;
3044 : : struct rte_ipv4_hdr *hdr1 = ip1;
3045 : : struct rte_ipv4_hdr *hdr2 = ip2;
3046 : : struct rte_ipv4_hdr *hdr3 = ip3;
3047 : :
3048 : 0 : dscp0 = hdr0->type_of_service >> 2;
3049 : 0 : dscp1 = hdr1->type_of_service >> 2;
3050 : 0 : dscp2 = hdr2->type_of_service >> 2;
3051 : 0 : dscp3 = hdr3->type_of_service >> 2;
3052 : :
3053 [ # # ]: 0 : total_length0 = rte_ntohs(hdr0->total_length);
3054 [ # # ]: 0 : total_length1 = rte_ntohs(hdr1->total_length);
3055 [ # # ]: 0 : total_length2 = rte_ntohs(hdr2->total_length);
3056 [ # # ]: 0 : total_length3 = rte_ntohs(hdr3->total_length);
3057 : : } else {
3058 : : struct rte_ipv6_hdr *hdr0 = ip0;
3059 : : struct rte_ipv6_hdr *hdr1 = ip1;
3060 : : struct rte_ipv6_hdr *hdr2 = ip2;
3061 : : struct rte_ipv6_hdr *hdr3 = ip3;
3062 : :
3063 [ # # ]: 0 : dscp0 = (rte_ntohl(hdr0->vtc_flow) & 0x0F600000) >> 18;
3064 [ # # ]: 0 : dscp1 = (rte_ntohl(hdr1->vtc_flow) & 0x0F600000) >> 18;
3065 [ # # ]: 0 : dscp2 = (rte_ntohl(hdr2->vtc_flow) & 0x0F600000) >> 18;
3066 [ # # ]: 0 : dscp3 = (rte_ntohl(hdr3->vtc_flow) & 0x0F600000) >> 18;
3067 : :
3068 [ # # ]: 0 : total_length0 = rte_ntohs(hdr0->payload_len) +
3069 : : sizeof(struct rte_ipv6_hdr);
3070 [ # # ]: 0 : total_length1 = rte_ntohs(hdr1->payload_len) +
3071 : : sizeof(struct rte_ipv6_hdr);
3072 [ # # ]: 0 : total_length2 = rte_ntohs(hdr2->payload_len) +
3073 : : sizeof(struct rte_ipv6_hdr);
3074 [ # # ]: 0 : total_length3 = rte_ntohs(hdr3->payload_len) +
3075 : : sizeof(struct rte_ipv6_hdr);
3076 : : }
3077 : :
3078 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
3079 : : void *data0 =
3080 : : action_data_get(table_entry0, action, RTE_TABLE_ACTION_LB);
3081 : : void *data1 =
3082 : : action_data_get(table_entry1, action, RTE_TABLE_ACTION_LB);
3083 : : void *data2 =
3084 : : action_data_get(table_entry2, action, RTE_TABLE_ACTION_LB);
3085 : : void *data3 =
3086 : : action_data_get(table_entry3, action, RTE_TABLE_ACTION_LB);
3087 : :
3088 : : pkt_work_lb(mbuf0,
3089 : : data0,
3090 : : &cfg->lb);
3091 : :
3092 : : pkt_work_lb(mbuf1,
3093 : : data1,
3094 : : &cfg->lb);
3095 : :
3096 : : pkt_work_lb(mbuf2,
3097 : : data2,
3098 : : &cfg->lb);
3099 : :
3100 : : pkt_work_lb(mbuf3,
3101 : : data3,
3102 : : &cfg->lb);
3103 : : }
3104 : :
3105 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
3106 : : void *data0 =
3107 : : action_data_get(table_entry0, action, RTE_TABLE_ACTION_MTR);
3108 : : void *data1 =
3109 : : action_data_get(table_entry1, action, RTE_TABLE_ACTION_MTR);
3110 : : void *data2 =
3111 : : action_data_get(table_entry2, action, RTE_TABLE_ACTION_MTR);
3112 : : void *data3 =
3113 : : action_data_get(table_entry3, action, RTE_TABLE_ACTION_MTR);
3114 : :
3115 : : drop_mask0 |= pkt_work_mtr(mbuf0,
3116 : : data0,
3117 : : &action->dscp_table,
3118 : 0 : action->mp,
3119 : : time,
3120 : : dscp0,
3121 : : total_length0);
3122 : :
3123 : : drop_mask1 |= pkt_work_mtr(mbuf1,
3124 : : data1,
3125 : : &action->dscp_table,
3126 : : action->mp,
3127 : : time,
3128 : : dscp1,
3129 : : total_length1);
3130 : :
3131 : : drop_mask2 |= pkt_work_mtr(mbuf2,
3132 : : data2,
3133 : : &action->dscp_table,
3134 : : action->mp,
3135 : : time,
3136 : : dscp2,
3137 : : total_length2);
3138 : :
3139 : : drop_mask3 |= pkt_work_mtr(mbuf3,
3140 : : data3,
3141 : : &action->dscp_table,
3142 : : action->mp,
3143 : : time,
3144 : : dscp3,
3145 : : total_length3);
3146 : : }
3147 : :
3148 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
3149 : : void *data0 =
3150 : : action_data_get(table_entry0, action, RTE_TABLE_ACTION_TM);
3151 : : void *data1 =
3152 : : action_data_get(table_entry1, action, RTE_TABLE_ACTION_TM);
3153 : : void *data2 =
3154 : : action_data_get(table_entry2, action, RTE_TABLE_ACTION_TM);
3155 : : void *data3 =
3156 : : action_data_get(table_entry3, action, RTE_TABLE_ACTION_TM);
3157 : :
3158 : : pkt_work_tm(mbuf0,
3159 : : data0,
3160 : : &action->dscp_table,
3161 : : dscp0);
3162 : :
3163 : : pkt_work_tm(mbuf1,
3164 : : data1,
3165 : : &action->dscp_table,
3166 : : dscp1);
3167 : :
3168 : : pkt_work_tm(mbuf2,
3169 : : data2,
3170 : : &action->dscp_table,
3171 : : dscp2);
3172 : :
3173 : : pkt_work_tm(mbuf3,
3174 : : data3,
3175 : : &action->dscp_table,
3176 : : dscp3);
3177 : : }
3178 : :
3179 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP)) {
3180 : : void *data0 = action_data_get(table_entry0,
3181 : : action,
3182 : : RTE_TABLE_ACTION_DECAP);
3183 : : void *data1 = action_data_get(table_entry1,
3184 : : action,
3185 : : RTE_TABLE_ACTION_DECAP);
3186 : : void *data2 = action_data_get(table_entry2,
3187 : : action,
3188 : : RTE_TABLE_ACTION_DECAP);
3189 : : void *data3 = action_data_get(table_entry3,
3190 : : action,
3191 : : RTE_TABLE_ACTION_DECAP);
3192 : :
3193 : : pkt4_work_decap(mbuf0, mbuf1, mbuf2, mbuf3,
3194 : : data0, data1, data2, data3);
3195 : : }
3196 : :
3197 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
3198 : : void *data0 =
3199 : : action_data_get(table_entry0, action, RTE_TABLE_ACTION_ENCAP);
3200 : : void *data1 =
3201 : : action_data_get(table_entry1, action, RTE_TABLE_ACTION_ENCAP);
3202 : : void *data2 =
3203 : : action_data_get(table_entry2, action, RTE_TABLE_ACTION_ENCAP);
3204 : : void *data3 =
3205 : : action_data_get(table_entry3, action, RTE_TABLE_ACTION_ENCAP);
3206 : :
3207 [ # # # # : 0 : pkt_work_encap(mbuf0,
# # # # ]
3208 : : data0,
3209 : : &cfg->encap,
3210 : : ip0,
3211 : : total_length0,
3212 : : ip_offset);
3213 : :
3214 [ # # # # : 0 : pkt_work_encap(mbuf1,
# # # # ]
3215 : : data1,
3216 : : &cfg->encap,
3217 : : ip1,
3218 : : total_length1,
3219 : : ip_offset);
3220 : :
3221 [ # # # # : 0 : pkt_work_encap(mbuf2,
# # # # ]
3222 : : data2,
3223 : : &cfg->encap,
3224 : : ip2,
3225 : : total_length2,
3226 : : ip_offset);
3227 : :
3228 [ # # # # : 0 : pkt_work_encap(mbuf3,
# # # # ]
3229 : : data3,
3230 : : &cfg->encap,
3231 : : ip3,
3232 : : total_length3,
3233 : : ip_offset);
3234 : : }
3235 : :
3236 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
3237 : : void *data0 =
3238 : : action_data_get(table_entry0, action, RTE_TABLE_ACTION_NAT);
3239 : : void *data1 =
3240 : : action_data_get(table_entry1, action, RTE_TABLE_ACTION_NAT);
3241 : : void *data2 =
3242 : : action_data_get(table_entry2, action, RTE_TABLE_ACTION_NAT);
3243 : : void *data3 =
3244 : : action_data_get(table_entry3, action, RTE_TABLE_ACTION_NAT);
3245 : :
3246 [ # # ]: 0 : if (cfg->common.ip_version) {
3247 : : pkt_ipv4_work_nat(ip0, data0, &cfg->nat);
3248 : : pkt_ipv4_work_nat(ip1, data1, &cfg->nat);
3249 : : pkt_ipv4_work_nat(ip2, data2, &cfg->nat);
3250 : : pkt_ipv4_work_nat(ip3, data3, &cfg->nat);
3251 : : } else {
3252 : : pkt_ipv6_work_nat(ip0, data0, &cfg->nat);
3253 : : pkt_ipv6_work_nat(ip1, data1, &cfg->nat);
3254 : : pkt_ipv6_work_nat(ip2, data2, &cfg->nat);
3255 : : pkt_ipv6_work_nat(ip3, data3, &cfg->nat);
3256 : : }
3257 : : }
3258 : :
3259 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
3260 : : void *data0 =
3261 : : action_data_get(table_entry0, action, RTE_TABLE_ACTION_TTL);
3262 : : void *data1 =
3263 : : action_data_get(table_entry1, action, RTE_TABLE_ACTION_TTL);
3264 : : void *data2 =
3265 : : action_data_get(table_entry2, action, RTE_TABLE_ACTION_TTL);
3266 : : void *data3 =
3267 : : action_data_get(table_entry3, action, RTE_TABLE_ACTION_TTL);
3268 : :
3269 [ # # ]: 0 : if (cfg->common.ip_version) {
3270 : 0 : drop_mask0 |= pkt_ipv4_work_ttl(ip0, data0);
3271 : 0 : drop_mask1 |= pkt_ipv4_work_ttl(ip1, data1);
3272 : 0 : drop_mask2 |= pkt_ipv4_work_ttl(ip2, data2);
3273 : 0 : drop_mask3 |= pkt_ipv4_work_ttl(ip3, data3);
3274 : : } else {
3275 : 0 : drop_mask0 |= pkt_ipv6_work_ttl(ip0, data0);
3276 : 0 : drop_mask1 |= pkt_ipv6_work_ttl(ip1, data1);
3277 : 0 : drop_mask2 |= pkt_ipv6_work_ttl(ip2, data2);
3278 : 0 : drop_mask3 |= pkt_ipv6_work_ttl(ip3, data3);
3279 : : }
3280 : : }
3281 : :
3282 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
3283 : : void *data0 =
3284 : : action_data_get(table_entry0, action, RTE_TABLE_ACTION_STATS);
3285 : : void *data1 =
3286 : : action_data_get(table_entry1, action, RTE_TABLE_ACTION_STATS);
3287 : : void *data2 =
3288 : : action_data_get(table_entry2, action, RTE_TABLE_ACTION_STATS);
3289 : : void *data3 =
3290 : : action_data_get(table_entry3, action, RTE_TABLE_ACTION_STATS);
3291 : :
3292 : : pkt_work_stats(data0, total_length0);
3293 : : pkt_work_stats(data1, total_length1);
3294 : : pkt_work_stats(data2, total_length2);
3295 : : pkt_work_stats(data3, total_length3);
3296 : : }
3297 : :
3298 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
3299 : : void *data0 =
3300 : : action_data_get(table_entry0, action, RTE_TABLE_ACTION_TIME);
3301 : : void *data1 =
3302 : : action_data_get(table_entry1, action, RTE_TABLE_ACTION_TIME);
3303 : : void *data2 =
3304 : : action_data_get(table_entry2, action, RTE_TABLE_ACTION_TIME);
3305 : : void *data3 =
3306 : : action_data_get(table_entry3, action, RTE_TABLE_ACTION_TIME);
3307 : :
3308 : : pkt_work_time(data0, time);
3309 : : pkt_work_time(data1, time);
3310 : : pkt_work_time(data2, time);
3311 : : pkt_work_time(data3, time);
3312 : : }
3313 : :
3314 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO)) {
3315 : : void *data0 = action_data_get(table_entry0, action,
3316 : : RTE_TABLE_ACTION_SYM_CRYPTO);
3317 : : void *data1 = action_data_get(table_entry1, action,
3318 : : RTE_TABLE_ACTION_SYM_CRYPTO);
3319 : : void *data2 = action_data_get(table_entry2, action,
3320 : : RTE_TABLE_ACTION_SYM_CRYPTO);
3321 : : void *data3 = action_data_get(table_entry3, action,
3322 : : RTE_TABLE_ACTION_SYM_CRYPTO);
3323 : :
3324 [ # # # # ]: 0 : drop_mask0 |= pkt_work_sym_crypto(mbuf0, data0, &cfg->sym_crypto,
3325 : : ip_offset);
3326 [ # # ]: 0 : drop_mask1 |= pkt_work_sym_crypto(mbuf1, data1, &cfg->sym_crypto,
3327 : : ip_offset);
3328 [ # # ]: 0 : drop_mask2 |= pkt_work_sym_crypto(mbuf2, data2, &cfg->sym_crypto,
3329 : : ip_offset);
3330 : 0 : drop_mask3 |= pkt_work_sym_crypto(mbuf3, data3, &cfg->sym_crypto,
3331 : : ip_offset);
3332 : : }
3333 : :
3334 [ # # ]: 0 : if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TAG)) {
3335 : : void *data0 = action_data_get(table_entry0,
3336 : : action,
3337 : : RTE_TABLE_ACTION_TAG);
3338 : : void *data1 = action_data_get(table_entry1,
3339 : : action,
3340 : : RTE_TABLE_ACTION_TAG);
3341 : : void *data2 = action_data_get(table_entry2,
3342 : : action,
3343 : : RTE_TABLE_ACTION_TAG);
3344 : : void *data3 = action_data_get(table_entry3,
3345 : : action,
3346 : : RTE_TABLE_ACTION_TAG);
3347 : :
3348 : : pkt4_work_tag(mbuf0, mbuf1, mbuf2, mbuf3,
3349 : : data0, data1, data2, data3);
3350 : : }
3351 : :
3352 : 0 : return drop_mask0 |
3353 : 0 : (drop_mask1 << 1) |
3354 : 0 : (drop_mask2 << 2) |
3355 : 0 : (drop_mask3 << 3);
3356 : : }
3357 : :
3358 : : static __rte_always_inline int
3359 : : ah(struct rte_pipeline *p,
3360 : : struct rte_mbuf **pkts,
3361 : : uint64_t pkts_mask,
3362 : : struct rte_pipeline_table_entry **entries,
3363 : : struct rte_table_action *action,
3364 : : struct ap_config *cfg)
3365 : : {
3366 : : uint64_t pkts_drop_mask = 0;
3367 : : uint64_t time = 0;
3368 : :
3369 : 0 : if (cfg->action_mask & ((1LLU << RTE_TABLE_ACTION_MTR) |
3370 : : (1LLU << RTE_TABLE_ACTION_TIME)))
3371 : 0 : time = rte_rdtsc();
3372 : :
3373 [ # # ]: 0 : if ((pkts_mask & (pkts_mask + 1)) == 0) {
3374 : 0 : uint64_t n_pkts = rte_popcount64(pkts_mask);
3375 : : uint32_t i;
3376 : :
3377 [ # # ]: 0 : for (i = 0; i < (n_pkts & (~0x3LLU)); i += 4) {
3378 : : uint64_t drop_mask;
3379 : :
3380 : 0 : drop_mask = pkt4_work(&pkts[i],
3381 [ # # ]: 0 : &entries[i],
3382 : : time,
3383 : : action,
3384 : : cfg);
3385 : :
3386 : 0 : pkts_drop_mask |= drop_mask << i;
3387 : : }
3388 : :
3389 [ # # ]: 0 : for ( ; i < n_pkts; i++) {
3390 : : uint64_t drop_mask;
3391 : :
3392 : 0 : drop_mask = pkt_work(pkts[i],
3393 [ # # ]: 0 : entries[i],
3394 : : time,
3395 : : action,
3396 : : cfg);
3397 : :
3398 : 0 : pkts_drop_mask |= drop_mask << i;
3399 : : }
3400 : : } else
3401 [ # # ]: 0 : for ( ; pkts_mask; ) {
3402 : 0 : uint32_t pos = rte_ctz64(pkts_mask);
3403 : 0 : uint64_t pkt_mask = 1LLU << pos;
3404 : : uint64_t drop_mask;
3405 : :
3406 : 0 : drop_mask = pkt_work(pkts[pos],
3407 [ # # ]: 0 : entries[pos],
3408 : : time,
3409 : : action,
3410 : : cfg);
3411 : :
3412 : 0 : pkts_mask &= ~pkt_mask;
3413 : 0 : pkts_drop_mask |= drop_mask << pos;
3414 : : }
3415 : :
3416 : 0 : rte_pipeline_ah_packet_drop(p, pkts_drop_mask);
3417 : :
3418 : : return 0;
3419 : : }
3420 : :
3421 : : static int
3422 [ # # ]: 0 : ah_default(struct rte_pipeline *p,
3423 : : struct rte_mbuf **pkts,
3424 : : uint64_t pkts_mask,
3425 : : struct rte_pipeline_table_entry **entries,
3426 : : void *arg)
3427 : : {
3428 : : struct rte_table_action *action = arg;
3429 : :
3430 : 0 : return ah(p,
3431 : : pkts,
3432 : : pkts_mask,
3433 : : entries,
3434 : : action,
3435 : : &action->cfg);
3436 : : }
3437 : :
3438 : : static rte_pipeline_table_action_handler_hit
3439 : : ah_selector(struct rte_table_action *action)
3440 : : {
3441 [ # # ]: 0 : if (action->cfg.action_mask == (1LLU << RTE_TABLE_ACTION_FWD))
3442 : 0 : return NULL;
3443 : :
3444 : : return ah_default;
3445 : : }
3446 : :
3447 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_table_params_get, 18.05)
3448 : : int
3449 : 0 : rte_table_action_table_params_get(struct rte_table_action *action,
3450 : : struct rte_pipeline_table_params *params)
3451 : : {
3452 : : rte_pipeline_table_action_handler_hit f_action_hit;
3453 : : uint32_t total_size;
3454 : :
3455 : : /* Check input arguments */
3456 : 0 : if ((action == NULL) ||
3457 [ # # ]: 0 : (params == NULL))
3458 : : return -EINVAL;
3459 : :
3460 : : f_action_hit = ah_selector(action);
3461 [ # # ]: 0 : total_size = rte_align32pow2(action->data.total_size);
3462 : :
3463 : : /* Fill in params */
3464 : 0 : params->f_action_hit = f_action_hit;
3465 : 0 : params->f_action_miss = NULL;
3466 [ # # ]: 0 : params->arg_ah = (f_action_hit) ? action : NULL;
3467 : 0 : params->action_data_size = total_size -
3468 : : sizeof(struct rte_pipeline_table_entry);
3469 : :
3470 : 0 : return 0;
3471 : : }
3472 : :
3473 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_table_action_free, 18.05)
3474 : : int
3475 : 0 : rte_table_action_free(struct rte_table_action *action)
3476 : : {
3477 [ # # ]: 0 : if (action == NULL)
3478 : : return 0;
3479 : :
3480 : 0 : rte_free(action);
3481 : :
3482 : 0 : return 0;
3483 : : }
|