examples/ipsec-secgw: update eth header during route lookup
[dpdk.git] / examples / ipsec-secgw / ipsec_worker.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2020 Marvell International Ltd.
3  */
4 #ifndef _IPSEC_WORKER_H_
5 #define _IPSEC_WORKER_H_
6
7 #include <rte_acl.h>
8 #include <rte_ethdev.h>
9 #include <rte_lpm.h>
10 #include <rte_lpm6.h>
11
12 #include "ipsec.h"
13
14 /* Configure how many packets ahead to prefetch, when reading packets */
15 #define PREFETCH_OFFSET 3
16 enum pkt_type {
17         PKT_TYPE_PLAIN_IPV4 = 1,
18         PKT_TYPE_IPSEC_IPV4,
19         PKT_TYPE_PLAIN_IPV6,
20         PKT_TYPE_IPSEC_IPV6,
21         PKT_TYPE_INVALID
22 };
23
24 enum {
25         PKT_DROPPED = 0,
26         PKT_FORWARDED,
27         PKT_POSTED      /* for lookaside case */
28 };
29
30 struct route_table {
31         struct rt_ctx *rt4_ctx;
32         struct rt_ctx *rt6_ctx;
33 };
34
35 /*
36  * Conf required by event mode worker with tx internal port
37  */
38 struct lcore_conf_ev_tx_int_port_wrkr {
39         struct ipsec_ctx inbound;
40         struct ipsec_ctx outbound;
41         struct route_table rt;
42 } __rte_cache_aligned;
43
44 void ipsec_poll_mode_worker(void);
45
46 int ipsec_launch_one_lcore(void *args);
47
48 /*
49  * helper routine for inline and cpu(synchronous) processing
50  * this is just to satisfy inbound_sa_check() and get_hop_for_offload_pkt().
51  * Should be removed in future.
52  */
53 static inline void
54 prep_process_group(void *sa, struct rte_mbuf *mb[], uint32_t cnt)
55 {
56         uint32_t j;
57         struct ipsec_mbuf_metadata *priv;
58
59         for (j = 0; j != cnt; j++) {
60                 priv = get_priv(mb[j]);
61                 priv->sa = sa;
62                 /* setup TSO related fields if TSO enabled*/
63                 if (priv->sa->mss) {
64                         uint32_t ptype = mb[j]->packet_type;
65                         /* only TCP is supported */
66                         if ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP) {
67                                 mb[j]->tso_segsz = priv->sa->mss;
68                                 if ((IS_TUNNEL(priv->sa->flags))) {
69                                         mb[j]->outer_l3_len = mb[j]->l3_len;
70                                         mb[j]->outer_l2_len = mb[j]->l2_len;
71                                         mb[j]->ol_flags |=
72                                                 RTE_MBUF_F_TX_TUNNEL_ESP;
73                                         if (RTE_ETH_IS_IPV4_HDR(ptype))
74                                                 mb[j]->ol_flags |=
75                                                 RTE_MBUF_F_TX_OUTER_IP_CKSUM;
76                                 }
77                                 mb[j]->l4_len = sizeof(struct rte_tcp_hdr);
78                                 mb[j]->ol_flags |= (RTE_MBUF_F_TX_TCP_SEG |
79                                                 RTE_MBUF_F_TX_TCP_CKSUM);
80                                 if (RTE_ETH_IS_IPV4_HDR(ptype))
81                                         mb[j]->ol_flags |=
82                                                 RTE_MBUF_F_TX_OUTER_IPV4;
83                                 else
84                                         mb[j]->ol_flags |=
85                                                 RTE_MBUF_F_TX_OUTER_IPV6;
86                         }
87                 }
88         }
89 }
90
91 static __rte_always_inline void
92 adjust_ipv4_pktlen(struct rte_mbuf *m, const struct rte_ipv4_hdr *iph,
93         uint32_t l2_len)
94 {
95         uint32_t plen, trim;
96
97         plen = rte_be_to_cpu_16(iph->total_length) + l2_len;
98         if (plen < m->pkt_len) {
99                 trim = m->pkt_len - plen;
100                 rte_pktmbuf_trim(m, trim);
101         }
102 }
103
104 static __rte_always_inline void
105 adjust_ipv6_pktlen(struct rte_mbuf *m, const struct rte_ipv6_hdr *iph,
106         uint32_t l2_len)
107 {
108         uint32_t plen, trim;
109
110         plen = rte_be_to_cpu_16(iph->payload_len) + sizeof(*iph) + l2_len;
111         if (plen < m->pkt_len) {
112                 trim = m->pkt_len - plen;
113                 rte_pktmbuf_trim(m, trim);
114         }
115 }
116
117 static __rte_always_inline void
118 prepare_one_packet(struct rte_security_ctx *ctx, struct rte_mbuf *pkt,
119                    struct ipsec_traffic *t)
120 {
121         uint32_t ptype = pkt->packet_type;
122         const struct rte_ether_hdr *eth;
123         const struct rte_ipv4_hdr *iph4;
124         const struct rte_ipv6_hdr *iph6;
125         uint32_t tun_type, l3_type;
126         uint64_t tx_offload;
127         uint16_t l3len;
128
129         tun_type = ptype & RTE_PTYPE_TUNNEL_MASK;
130         l3_type = ptype & RTE_PTYPE_L3_MASK;
131
132         eth = rte_pktmbuf_mtod(pkt, const struct rte_ether_hdr *);
133         if (RTE_ETH_IS_IPV4_HDR(l3_type)) {
134                 iph4 = (const struct rte_ipv4_hdr *)rte_pktmbuf_adj(pkt,
135                         RTE_ETHER_HDR_LEN);
136                 adjust_ipv4_pktlen(pkt, iph4, 0);
137
138                 if (tun_type == RTE_PTYPE_TUNNEL_ESP) {
139                         t->ipsec.pkts[(t->ipsec.num)++] = pkt;
140                 } else {
141                         t->ip4.data[t->ip4.num] = &iph4->next_proto_id;
142                         t->ip4.pkts[(t->ip4.num)++] = pkt;
143                 }
144                 tx_offload = sizeof(*iph4) << RTE_MBUF_L2_LEN_BITS;
145         } else if (RTE_ETH_IS_IPV6_HDR(l3_type)) {
146                 int next_proto;
147                 size_t ext_len;
148                 uint8_t *p;
149
150                 /* get protocol type */
151                 iph6 = (const struct rte_ipv6_hdr *)rte_pktmbuf_adj(pkt,
152                         RTE_ETHER_HDR_LEN);
153                 adjust_ipv6_pktlen(pkt, iph6, 0);
154
155                 l3len = sizeof(struct ip6_hdr);
156
157                 if (tun_type == RTE_PTYPE_TUNNEL_ESP) {
158                         t->ipsec.pkts[(t->ipsec.num)++] = pkt;
159                 } else {
160                         t->ip6.data[t->ip6.num] = &iph6->proto;
161                         t->ip6.pkts[(t->ip6.num)++] = pkt;
162                 }
163
164                 /* Determine l3 header size up to ESP extension by walking
165                  * through extension headers.
166                  */
167                 if (l3_type == RTE_PTYPE_L3_IPV6_EXT ||
168                      l3_type == RTE_PTYPE_L3_IPV6_EXT_UNKNOWN) {
169                         p = rte_pktmbuf_mtod(pkt, uint8_t *);
170                         next_proto = iph6->proto;
171                         while (next_proto != IPPROTO_ESP &&
172                                l3len < pkt->data_len &&
173                                (next_proto = rte_ipv6_get_next_ext(p + l3len,
174                                                 next_proto, &ext_len)) >= 0)
175                                 l3len += ext_len;
176
177                         /* Drop pkt when IPv6 header exceeds first seg size */
178                         if (unlikely(l3len > pkt->data_len)) {
179                                 free_pkts(&pkt, 1);
180                                 return;
181                         }
182                 }
183                 tx_offload = l3len << RTE_MBUF_L2_LEN_BITS;
184         } else {
185                 /* Unknown/Unsupported type, drop the packet */
186                 RTE_LOG(ERR, IPSEC, "Unsupported packet type 0x%x\n",
187                         rte_be_to_cpu_16(eth->ether_type));
188                 free_pkts(&pkt, 1);
189                 return;
190         }
191
192         if  ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP)
193                 tx_offload |= (sizeof(struct rte_tcp_hdr) <<
194                                (RTE_MBUF_L2_LEN_BITS + RTE_MBUF_L3_LEN_BITS));
195         else if ((ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP)
196                 tx_offload |= (sizeof(struct rte_udp_hdr) <<
197                                (RTE_MBUF_L2_LEN_BITS + RTE_MBUF_L3_LEN_BITS));
198         pkt->tx_offload = tx_offload;
199
200         /* Check if the packet has been processed inline. For inline protocol
201          * processed packets, the metadata in the mbuf can be used to identify
202          * the security processing done on the packet. The metadata will be
203          * used to retrieve the application registered userdata associated
204          * with the security session.
205          */
206
207         if (ctx && pkt->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD) {
208                 struct ipsec_sa *sa;
209                 struct ipsec_mbuf_metadata *priv;
210
211                 /* Retrieve the userdata registered. Here, the userdata
212                  * registered is the SA pointer.
213                  */
214                 sa = (struct ipsec_sa *)rte_security_get_userdata(ctx,
215                                 *rte_security_dynfield(pkt));
216                 if (sa == NULL) {
217                         /* userdata could not be retrieved */
218                         return;
219                 }
220
221                 /* Save SA as priv member in mbuf. This will be used in the
222                  * IPsec selector(SP-SA) check.
223                  */
224
225                 priv = get_priv(pkt);
226                 priv->sa = sa;
227         }
228 }
229
230 static __rte_always_inline void
231 prepare_traffic(struct rte_security_ctx *ctx, struct rte_mbuf **pkts,
232                 struct ipsec_traffic *t, uint16_t nb_pkts)
233 {
234         int32_t i;
235
236         t->ipsec.num = 0;
237         t->ip4.num = 0;
238         t->ip6.num = 0;
239
240         for (i = 0; i < (nb_pkts - PREFETCH_OFFSET); i++) {
241                 rte_prefetch0(rte_pktmbuf_mtod(pkts[i + PREFETCH_OFFSET],
242                                         void *));
243                 prepare_one_packet(ctx, pkts[i], t);
244         }
245         /* Process left packets */
246         for (; i < nb_pkts; i++)
247                 prepare_one_packet(ctx, pkts[i], t);
248 }
249
250 /* Send burst of packets on an output interface */
251 static __rte_always_inline int32_t
252 send_burst(struct lcore_conf *qconf, uint16_t n, uint16_t port)
253 {
254         struct rte_mbuf **m_table;
255         int32_t ret;
256         uint16_t queueid;
257
258         queueid = qconf->tx_queue_id[port];
259         m_table = (struct rte_mbuf **)qconf->tx_mbufs[port].m_table;
260
261         ret = rte_eth_tx_burst(port, queueid, m_table, n);
262
263         core_stats_update_tx(ret);
264
265         if (unlikely(ret < n)) {
266                 do {
267                         free_pkts(&m_table[ret], 1);
268                 } while (++ret < n);
269         }
270
271         return 0;
272 }
273
274 /*
275  * Helper function to fragment and queue for TX one packet.
276  */
277 static __rte_always_inline uint32_t
278 send_fragment_packet(struct lcore_conf *qconf, struct rte_mbuf *m,
279         uint16_t port, uint8_t proto)
280 {
281         struct rte_ether_hdr *ethhdr;
282         struct rte_ipv4_hdr *ip;
283         struct rte_mbuf *pkt;
284         struct buffer *tbl;
285         uint32_t len, n, i;
286         int32_t rc;
287
288         tbl =  qconf->tx_mbufs + port;
289         len = tbl->len;
290
291         /* free space for new fragments */
292         if (len + RTE_LIBRTE_IP_FRAG_MAX_FRAG >=  RTE_DIM(tbl->m_table)) {
293                 send_burst(qconf, len, port);
294                 len = 0;
295         }
296
297         n = RTE_DIM(tbl->m_table) - len;
298
299         /* Strip the ethernet header that was prepended earlier */
300         rte_pktmbuf_adj(m, RTE_ETHER_HDR_LEN);
301
302         if (proto == IPPROTO_IP)
303                 rc = rte_ipv4_fragment_packet(m, tbl->m_table + len,
304                         n, mtu_size, m->pool, qconf->frag.pool_indir);
305         else
306                 rc = rte_ipv6_fragment_packet(m, tbl->m_table + len,
307                         n, mtu_size, m->pool, qconf->frag.pool_indir);
308
309         if (rc < 0) {
310                 RTE_LOG(ERR, IPSEC,
311                         "%s: failed to fragment packet with size %u, "
312                         "error code: %d\n",
313                         __func__, m->pkt_len, rte_errno);
314                 rc = 0;
315         }
316
317         i = len;
318         len += rc;
319         for (; i < len; i++) {
320                 pkt = tbl->m_table[i];
321
322                 /* Update Ethernet header */
323                 ethhdr = (struct rte_ether_hdr *)
324                         rte_pktmbuf_prepend(pkt, RTE_ETHER_HDR_LEN);
325                 pkt->l2_len = RTE_ETHER_HDR_LEN;
326
327                 if (proto == IPPROTO_IP) {
328                         ethhdr->ether_type =
329                                 rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
330                         /* Update minimum offload data */
331                         pkt->l3_len = sizeof(struct rte_ipv4_hdr);
332                         pkt->ol_flags |= qconf->outbound.ipv4_offloads;
333
334                         ip = (struct rte_ipv4_hdr *)(ethhdr + 1);
335                         ip->hdr_checksum = 0;
336
337                         /* calculate IPv4 cksum in SW */
338                         if ((pkt->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) == 0)
339                                 ip->hdr_checksum = rte_ipv4_cksum(ip);
340                 } else {
341                         ethhdr->ether_type =
342                                 rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
343
344                         /* Update minimum offload data */
345                         pkt->l3_len = sizeof(struct rte_ipv6_hdr);
346                         pkt->ol_flags |= qconf->outbound.ipv6_offloads;
347                 }
348
349                 memcpy(&ethhdr->src_addr, &ethaddr_tbl[port].src,
350                        sizeof(struct rte_ether_addr));
351                 memcpy(&ethhdr->dst_addr, &ethaddr_tbl[port].dst,
352                        sizeof(struct rte_ether_addr));
353         }
354
355         free_pkts(&m, 1);
356         return len;
357 }
358
359 /* Enqueue a single packet, and send burst if queue is filled */
360 static __rte_always_inline int32_t
361 send_single_packet(struct rte_mbuf *m, uint16_t port, uint8_t proto)
362 {
363         uint32_t lcore_id;
364         uint16_t len;
365         struct lcore_conf *qconf;
366
367         lcore_id = rte_lcore_id();
368
369         qconf = &lcore_conf[lcore_id];
370         len = qconf->tx_mbufs[port].len;
371
372         /* L2 header is already part of packet */
373         if (m->pkt_len - RTE_ETHER_HDR_LEN <= mtu_size) {
374                 qconf->tx_mbufs[port].m_table[len] = m;
375                 len++;
376
377         /* need to fragment the packet */
378         } else if (frag_tbl_sz > 0)
379                 len = send_fragment_packet(qconf, m, port, proto);
380         else
381                 free_pkts(&m, 1);
382
383         /* enough pkts to be sent */
384         if (unlikely(len == MAX_PKT_BURST)) {
385                 send_burst(qconf, MAX_PKT_BURST, port);
386                 len = 0;
387         }
388
389         qconf->tx_mbufs[port].len = len;
390         return 0;
391 }
392
393 static __rte_always_inline void
394 inbound_sp_sa(struct sp_ctx *sp, struct sa_ctx *sa, struct traffic_type *ip,
395                 uint16_t lim, struct ipsec_spd_stats *stats)
396 {
397         struct rte_mbuf *m;
398         uint32_t i, j, res, sa_idx;
399
400         if (ip->num == 0 || sp == NULL)
401                 return;
402
403         rte_acl_classify((struct rte_acl_ctx *)sp, ip->data, ip->res,
404                         ip->num, DEFAULT_MAX_CATEGORIES);
405
406         j = 0;
407         for (i = 0; i < ip->num; i++) {
408                 m = ip->pkts[i];
409                 res = ip->res[i];
410                 if (res == BYPASS) {
411                         ip->pkts[j++] = m;
412                         stats->bypass++;
413                         continue;
414                 }
415                 if (res == DISCARD) {
416                         free_pkts(&m, 1);
417                         stats->discard++;
418                         continue;
419                 }
420
421                 /* Only check SPI match for processed IPSec packets */
422                 if (i < lim && ((m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD) == 0)) {
423                         stats->discard++;
424                         free_pkts(&m, 1);
425                         continue;
426                 }
427
428                 sa_idx = res - 1;
429                 if (!inbound_sa_check(sa, m, sa_idx)) {
430                         stats->discard++;
431                         free_pkts(&m, 1);
432                         continue;
433                 }
434                 ip->pkts[j++] = m;
435                 stats->protect++;
436         }
437         ip->num = j;
438 }
439
440 static __rte_always_inline int32_t
441 get_hop_for_offload_pkt(struct rte_mbuf *pkt, int is_ipv6)
442 {
443         struct ipsec_mbuf_metadata *priv;
444         struct ipsec_sa *sa;
445
446         priv = get_priv(pkt);
447
448         sa = priv->sa;
449         if (unlikely(sa == NULL)) {
450                 RTE_LOG(ERR, IPSEC, "SA not saved in private data\n");
451                 goto fail;
452         }
453
454         if (is_ipv6)
455                 return sa->portid;
456
457         /* else */
458         return (sa->portid | RTE_LPM_LOOKUP_SUCCESS);
459
460 fail:
461         if (is_ipv6)
462                 return -1;
463
464         /* else */
465         return 0;
466 }
467
468 static __rte_always_inline void
469 route4_pkts(struct rt_ctx *rt_ctx, struct rte_mbuf *pkts[],
470             uint8_t nb_pkts, uint64_t tx_offloads, bool ip_cksum)
471 {
472         uint32_t hop[MAX_PKT_BURST * 2];
473         uint32_t dst_ip[MAX_PKT_BURST * 2];
474         struct rte_ether_hdr *ethhdr;
475         int32_t pkt_hop = 0;
476         uint16_t i, offset;
477         uint16_t lpm_pkts = 0;
478         unsigned int lcoreid = rte_lcore_id();
479         struct rte_mbuf *pkt;
480         uint16_t port;
481
482         if (nb_pkts == 0)
483                 return;
484
485         /* Need to do an LPM lookup for non-inline packets. Inline packets will
486          * have port ID in the SA
487          */
488
489         for (i = 0; i < nb_pkts; i++) {
490                 pkt = pkts[i];
491                 if (!(pkt->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD)) {
492                         /* Security offload not enabled. So an LPM lookup is
493                          * required to get the hop
494                          */
495                         offset = offsetof(struct ip, ip_dst);
496                         dst_ip[lpm_pkts] = *rte_pktmbuf_mtod_offset(pkt,
497                                         uint32_t *, offset);
498                         dst_ip[lpm_pkts] = rte_be_to_cpu_32(dst_ip[lpm_pkts]);
499                         lpm_pkts++;
500                 }
501         }
502
503         rte_lpm_lookup_bulk((struct rte_lpm *)rt_ctx, dst_ip, hop, lpm_pkts);
504
505         lpm_pkts = 0;
506
507         for (i = 0; i < nb_pkts; i++) {
508                 pkt = pkts[i];
509                 if (pkt->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD) {
510                         /* Read hop from the SA */
511                         pkt_hop = get_hop_for_offload_pkt(pkt, 0);
512                 } else {
513                         /* Need to use hop returned by lookup */
514                         pkt_hop = hop[lpm_pkts++];
515                 }
516
517                 if ((pkt_hop & RTE_LPM_LOOKUP_SUCCESS) == 0) {
518                         core_statistics[lcoreid].lpm4.miss++;
519                         free_pkts(&pkt, 1);
520                         continue;
521                 }
522
523                 port = pkt_hop & 0xff;
524
525                 /* Update minimum offload data */
526                 pkt->l3_len = sizeof(struct rte_ipv4_hdr);
527                 pkt->l2_len = RTE_ETHER_HDR_LEN;
528                 pkt->ol_flags |= RTE_MBUF_F_TX_IPV4;
529
530                 /* Update Ethernet header */
531                 ethhdr = (struct rte_ether_hdr *)
532                         rte_pktmbuf_prepend(pkt, RTE_ETHER_HDR_LEN);
533
534                 if (ip_cksum) {
535                         struct rte_ipv4_hdr *ip;
536
537                         pkt->ol_flags |= tx_offloads;
538
539                         ip = (struct rte_ipv4_hdr *)(ethhdr + 1);
540                         ip->hdr_checksum = 0;
541
542                         /* calculate IPv4 cksum in SW */
543                         if ((pkt->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) == 0)
544                                 ip->hdr_checksum = rte_ipv4_cksum(ip);
545                 }
546
547                 ethhdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
548                 memcpy(&ethhdr->src_addr, &ethaddr_tbl[port].src,
549                        sizeof(struct rte_ether_addr));
550                 memcpy(&ethhdr->dst_addr, &ethaddr_tbl[port].dst,
551                        sizeof(struct rte_ether_addr));
552
553                 send_single_packet(pkt, port, IPPROTO_IP);
554         }
555 }
556
557 static __rte_always_inline void
558 route6_pkts(struct rt_ctx *rt_ctx, struct rte_mbuf *pkts[], uint8_t nb_pkts)
559 {
560         int32_t hop[MAX_PKT_BURST * 2];
561         uint8_t dst_ip[MAX_PKT_BURST * 2][16];
562         struct rte_ether_hdr *ethhdr;
563         uint8_t *ip6_dst;
564         int32_t pkt_hop = 0;
565         uint16_t i, offset;
566         uint16_t lpm_pkts = 0;
567         unsigned int lcoreid = rte_lcore_id();
568         struct rte_mbuf *pkt;
569         uint16_t port;
570
571         if (nb_pkts == 0)
572                 return;
573
574         /* Need to do an LPM lookup for non-inline packets. Inline packets will
575          * have port ID in the SA
576          */
577
578         for (i = 0; i < nb_pkts; i++) {
579                 pkt = pkts[i];
580                 if (!(pkt->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD)) {
581                         /* Security offload not enabled. So an LPM lookup is
582                          * required to get the hop
583                          */
584                         offset = offsetof(struct ip6_hdr, ip6_dst);
585                         ip6_dst = rte_pktmbuf_mtod_offset(pkt, uint8_t *,
586                                         offset);
587                         memcpy(&dst_ip[lpm_pkts][0], ip6_dst, 16);
588                         lpm_pkts++;
589                 }
590         }
591
592         rte_lpm6_lookup_bulk_func((struct rte_lpm6 *)rt_ctx, dst_ip, hop,
593                         lpm_pkts);
594
595         lpm_pkts = 0;
596
597         for (i = 0; i < nb_pkts; i++) {
598                 pkt = pkts[i];
599                 if (pkt->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD) {
600                         /* Read hop from the SA */
601                         pkt_hop = get_hop_for_offload_pkt(pkt, 1);
602                 } else {
603                         /* Need to use hop returned by lookup */
604                         pkt_hop = hop[lpm_pkts++];
605                 }
606
607                 if (pkt_hop == -1) {
608                         core_statistics[lcoreid].lpm6.miss++;
609                         free_pkts(&pkt, 1);
610                         continue;
611                 }
612
613                 port = pkt_hop & 0xff;
614
615                 /* Update minimum offload data */
616                 pkt->ol_flags |= RTE_MBUF_F_TX_IPV6;
617                 pkt->l3_len = sizeof(struct ip6_hdr);
618                 pkt->l2_len = RTE_ETHER_HDR_LEN;
619
620                 /* Update Ethernet header */
621                 ethhdr = (struct rte_ether_hdr *)
622                         rte_pktmbuf_prepend(pkt, RTE_ETHER_HDR_LEN);
623
624                 ethhdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
625                 memcpy(&ethhdr->src_addr, &ethaddr_tbl[port].src,
626                        sizeof(struct rte_ether_addr));
627                 memcpy(&ethhdr->dst_addr, &ethaddr_tbl[port].dst,
628                        sizeof(struct rte_ether_addr));
629
630                 send_single_packet(pkt, port, IPPROTO_IPV6);
631         }
632 }
633
634 static __rte_always_inline void
635 drain_tx_buffers(struct lcore_conf *qconf)
636 {
637         struct buffer *buf;
638         uint32_t portid;
639
640         for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
641                 buf = &qconf->tx_mbufs[portid];
642                 if (buf->len == 0)
643                         continue;
644                 send_burst(qconf, buf->len, portid);
645                 buf->len = 0;
646         }
647 }
648
649 #endif /* _IPSEC_WORKER_H_ */