Added initial support for NDP (IPv6)
[samplevnf.git] / VNFs / DPPD-PROX / handle_swap.c
1 /*
2 // Copyright (c) 2010-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include <rte_mbuf.h>
18 #include <rte_udp.h>
19
20 #include "task_init.h"
21 #include "task_base.h"
22 #include "lconf.h"
23 #include "log.h"
24 #include "prox_port_cfg.h"
25 #include "mpls.h"
26 #include "qinq.h"
27 #include "gre.h"
28 #include "prefetch.h"
29 #include "defines.h"
30 #include "igmp.h"
31 #include "prox_cksum.h"
32 #include "prox_compat.h"
33
34 struct task_swap {
35         struct task_base base;
36         struct rte_mempool *igmp_pool;
37         uint32_t runtime_flags;
38         uint32_t igmp_address;
39         uint8_t src_dst_mac[12];
40         uint32_t local_ipv4;
41         int offload_crc;
42         uint64_t last_echo_req_rcvd_tsc;
43         uint64_t last_echo_rep_rcvd_tsc;
44         uint32_t n_echo_req;
45         uint32_t n_echo_rep;
46 };
47
48 #define NB_IGMP_MBUF            1024
49 #define IGMP_MBUF_SIZE          2048
50 #define NB_CACHE_IGMP_MBUF      256
51
52 static void write_src_and_dst_mac(struct task_swap *task, struct rte_mbuf *mbuf)
53 {
54         prox_rte_ether_hdr *hdr;
55         prox_rte_ether_addr mac;
56
57         if (unlikely((task->runtime_flags & (TASK_ARG_DST_MAC_SET|TASK_ARG_SRC_MAC_SET)) == (TASK_ARG_DST_MAC_SET|TASK_ARG_SRC_MAC_SET))) {
58                 /* Source and Destination mac hardcoded */
59                 hdr = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
60                 rte_memcpy(hdr, task->src_dst_mac, sizeof(task->src_dst_mac));
61         } else {
62                 hdr = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
63                 if (likely((task->runtime_flags & TASK_ARG_SRC_MAC_SET) == 0)) {
64                         /* dst mac will be used as src mac */
65                         prox_rte_ether_addr_copy(&hdr->d_addr, &mac);
66                 }
67
68                 if (unlikely(task->runtime_flags & TASK_ARG_DST_MAC_SET))
69                         prox_rte_ether_addr_copy((prox_rte_ether_addr *)&task->src_dst_mac[0], &hdr->d_addr);
70                 else
71                         prox_rte_ether_addr_copy(&hdr->s_addr, &hdr->d_addr);
72
73                 if (unlikely(task->runtime_flags & TASK_ARG_SRC_MAC_SET)) {
74                         prox_rte_ether_addr_copy((prox_rte_ether_addr *)&task->src_dst_mac[6], &hdr->s_addr);
75                 } else {
76                         prox_rte_ether_addr_copy(&mac, &hdr->s_addr);
77                 }
78         }
79 }
80 static inline void build_mcast_mac(uint32_t ip, prox_rte_ether_addr *dst_mac)
81 {
82         // MAC address is 01:00:5e followed by 23 LSB of IP address
83         uint64_t mac = 0x0000005e0001L | ((ip & 0xFFFF7F00L) << 16);
84         memcpy(dst_mac, &mac, sizeof(prox_rte_ether_addr));
85 }
86
87 static inline void build_icmp_reply_message(struct task_base *tbase, struct rte_mbuf *mbuf)
88 {
89         struct task_swap *task = (struct task_swap *)tbase;
90         prox_rte_ether_hdr *hdr = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
91         prox_rte_ether_addr dst_mac;
92         prox_rte_ether_addr_copy(&hdr->s_addr, &dst_mac);
93         prox_rte_ether_addr_copy(&hdr->d_addr, &hdr->s_addr);
94         prox_rte_ether_addr_copy(&dst_mac, &hdr->d_addr);
95         prox_rte_ipv4_hdr *ip_hdr = (prox_rte_ipv4_hdr *)(hdr + 1);
96         ip_hdr->dst_addr = ip_hdr->src_addr;
97         ip_hdr->src_addr = task->local_ipv4;
98         prox_rte_icmp_hdr *picmp = (prox_rte_icmp_hdr *)(ip_hdr + 1);
99         picmp->icmp_type = PROX_RTE_IP_ICMP_ECHO_REPLY;
100 }
101
102 static inline void build_igmp_message(struct task_base *tbase, struct rte_mbuf *mbuf, uint32_t ip, uint8_t igmp_message)
103 {
104         struct task_swap *task = (struct task_swap *)tbase;
105         prox_rte_ether_hdr *hdr = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
106         prox_rte_ether_addr dst_mac;
107         build_mcast_mac(ip, &dst_mac);
108
109         rte_pktmbuf_pkt_len(mbuf) = 46;
110         rte_pktmbuf_data_len(mbuf) = 46;
111         init_mbuf_seg(mbuf);
112
113         prox_rte_ether_addr_copy(&dst_mac, &hdr->d_addr);
114         prox_rte_ether_addr_copy((prox_rte_ether_addr *)&task->src_dst_mac[6], &hdr->s_addr);
115         hdr->ether_type = ETYPE_IPv4;
116
117         prox_rte_ipv4_hdr *ip_hdr = (prox_rte_ipv4_hdr *)(hdr + 1);
118         ip_hdr->version_ihl = 0x45;             /**< version and header length */
119         ip_hdr->type_of_service = 0;    /**< type of service */
120         ip_hdr->total_length = rte_cpu_to_be_16(32);            /**< length of packet */
121         ip_hdr->packet_id = 0;          /**< packet ID */
122         ip_hdr->fragment_offset = 0;    /**< fragmentation offset */
123         ip_hdr->time_to_live = 1;               /**< time to live */
124         ip_hdr->next_proto_id = IPPROTO_IGMP;           /**< protocol ID */
125         ip_hdr->hdr_checksum = 0;               /**< header checksum */
126         ip_hdr->src_addr = task->local_ipv4;            /**< source address */
127         ip_hdr->dst_addr = ip;  /**< destination address */
128         struct igmpv2_hdr *pigmp = (struct igmpv2_hdr *)(ip_hdr + 1);
129         pigmp->type = igmp_message;
130         pigmp->max_resp_time = 0;
131         pigmp->checksum = 0;
132         pigmp->group_address = ip;
133         prox_ip_udp_cksum(mbuf, ip_hdr, sizeof(prox_rte_ether_hdr), sizeof(prox_rte_ipv4_hdr), task->offload_crc);
134 }
135
136 static void stop_swap(struct task_base *tbase)
137 {
138         struct task_swap *task = (struct task_swap *)tbase;
139         if (task->igmp_pool) {
140                 rte_mempool_free(task->igmp_pool);
141                 task->igmp_pool = NULL;
142         }
143 }
144
145 static void handle_ipv6(struct task_swap *task, struct rte_mbuf *mbufs, prox_rte_ipv6_hdr *ipv6_hdr, uint8_t *out)
146 {
147         __m128i ip =  _mm_loadu_si128((__m128i*)&(ipv6_hdr->src_addr));
148         uint16_t port;
149         uint16_t payload_len;
150         prox_rte_udp_hdr *udp_hdr;
151
152         rte_mov16((uint8_t *)&(ipv6_hdr->src_addr), (uint8_t *)&(ipv6_hdr->dst_addr));  // Copy dst into src
153         rte_mov16((uint8_t *)&(ipv6_hdr->dst_addr), (uint8_t *)&ip);                    // Copy src into dst
154         switch(ipv6_hdr->proto) {
155                 case IPPROTO_TCP:
156                 case IPPROTO_UDP:
157                         payload_len = ipv6_hdr->payload_len;
158                         udp_hdr = (prox_rte_udp_hdr *)(ipv6_hdr + 1);
159                         if (unlikely(udp_hdr->dgram_len < payload_len)) {
160                                 plog_warn("Unexpected L4 len (%u) versus L3 payload len (%u) in IPv6 packet\n", udp_hdr->dgram_len, payload_len);
161                                 *out = OUT_DISCARD;
162                                 break;
163                         }
164                         port = udp_hdr->dst_port;
165                         udp_hdr->dst_port = udp_hdr->src_port;
166                         udp_hdr->src_port = port;
167                         write_src_and_dst_mac(task, mbufs);
168                         *out = 0;
169                         break;
170                 default:
171                         plog_warn("Unsupported next hop %u in IPv6 packet\n", ipv6_hdr->proto);
172                         *out = OUT_DISCARD;
173                         break;
174         }
175 }
176
177 static int handle_swap_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts)
178 {
179         struct task_swap *task = (struct task_swap *)tbase;
180         prox_rte_ether_hdr *hdr;
181         prox_rte_ether_addr mac;
182         prox_rte_ipv4_hdr *ip_hdr;
183         prox_rte_udp_hdr *udp_hdr;
184         prox_rte_ipv6_hdr *ipv6_hdr;
185         struct gre_hdr *pgre;
186         prox_rte_ipv4_hdr *inner_ip_hdr;
187         uint32_t ip;
188         uint16_t port;
189         uint8_t out[64] = {0};
190         struct mpls_hdr *mpls;
191         uint32_t mpls_len = 0;
192         struct qinq_hdr *qinq;
193         prox_rte_vlan_hdr *vlan;
194         uint16_t j;
195         struct igmpv2_hdr *pigmp;
196         prox_rte_icmp_hdr *picmp;
197         uint8_t type;
198
199         for (j = 0; j < n_pkts; ++j) {
200                 PREFETCH0(mbufs[j]);
201         }
202         for (j = 0; j < n_pkts; ++j) {
203                 PREFETCH0(rte_pktmbuf_mtod(mbufs[j], void *));
204         }
205
206         // TODO 1: check packet is long enough for Ethernet + IP + UDP = 42 bytes
207         for (uint16_t j = 0; j < n_pkts; ++j) {
208                 hdr = rte_pktmbuf_mtod(mbufs[j], prox_rte_ether_hdr *);
209                 switch (hdr->ether_type) {
210                 case ETYPE_MPLSU:
211                         mpls = (struct mpls_hdr *)(hdr + 1);
212                         while (!(mpls->bytes & 0x00010000)) {
213                                 // TODO: verify pcket length
214                                 mpls++;
215                                 mpls_len += sizeof(struct mpls_hdr);
216                         }
217                         mpls_len += sizeof(struct mpls_hdr);
218                         ip_hdr = (prox_rte_ipv4_hdr *)(mpls + 1);
219                         if (unlikely((ip_hdr->version_ihl >> 4) == 6)) {
220                                 ipv6_hdr = (prox_rte_ipv6_hdr *)(ip_hdr);
221                                 handle_ipv6(task, mbufs[j], ipv6_hdr, &out[j]);
222                                 continue;
223                         }
224                         break;
225                 case ETYPE_8021ad:
226                         qinq = (struct qinq_hdr *)hdr;
227                         if (qinq->cvlan.eth_proto != ETYPE_VLAN) {
228                                 plog_warn("Unexpected proto in QinQ = %#04x\n", qinq->cvlan.eth_proto);
229                                 out[j] = OUT_DISCARD;
230                                 continue;
231                         }
232                         if (qinq->ether_type == ETYPE_IPv4) {
233                                 ip_hdr = (prox_rte_ipv4_hdr *)(qinq + 1);
234                         } else if (qinq->ether_type == ETYPE_IPv6) {
235                                 ipv6_hdr = (prox_rte_ipv6_hdr *)(qinq + 1);
236                                 handle_ipv6(task, mbufs[j], ipv6_hdr, &out[j]);
237                                 continue;
238                         } else {
239                                 plog_warn("Unsupported packet type\n");
240                                 out[j] = OUT_DISCARD;
241                                 continue;
242                         }
243                         break;
244                 case ETYPE_VLAN:
245                         vlan = (prox_rte_vlan_hdr *)(hdr + 1);
246                         if (vlan->eth_proto == ETYPE_IPv4) {
247                                 ip_hdr = (prox_rte_ipv4_hdr *)(vlan + 1);
248                         } else if (vlan->eth_proto == ETYPE_IPv6) {
249                                 ipv6_hdr = (prox_rte_ipv6_hdr *)(vlan + 1);
250                                 handle_ipv6(task, mbufs[j], ipv6_hdr, &out[j]);
251                                 continue;
252                         } else if (vlan->eth_proto == ETYPE_VLAN) {
253                                 vlan = (prox_rte_vlan_hdr *)(vlan + 1);
254                                 if (vlan->eth_proto == ETYPE_IPv4) {
255                                         ip_hdr = (prox_rte_ipv4_hdr *)(vlan + 1);
256                                 }
257                                 else if (vlan->eth_proto == ETYPE_IPv6) {
258                                         ipv6_hdr = (prox_rte_ipv6_hdr *)(vlan + 1);
259                                         handle_ipv6(task, mbufs[j], ipv6_hdr, &out[j]);
260                                         continue;
261                                 }
262                                 else {
263                                         plog_warn("Unsupported packet type\n");
264                                         out[j] = OUT_DISCARD;
265                                         continue;
266                                 }
267                         } else {
268                                 plog_warn("Unsupported packet type\n");
269                                 out[j] = OUT_DISCARD;
270                                 continue;
271                         }
272                         break;
273                 case ETYPE_IPv4:
274                         ip_hdr = (prox_rte_ipv4_hdr *)(hdr + 1);
275                         break;
276                 case ETYPE_IPv6:
277                         ipv6_hdr = (prox_rte_ipv6_hdr *)(hdr + 1);
278                         handle_ipv6(task, mbufs[j], ipv6_hdr, &out[j]);
279                         continue;
280                 case ETYPE_LLDP:
281                         out[j] = OUT_DISCARD;
282                         continue;
283                 default:
284                         plog_warn("Unsupported ether_type 0x%x\n", hdr->ether_type);
285                         out[j] = OUT_DISCARD;
286                         continue;
287                 }
288                 // TODO 2 : check packet is long enough for Ethernet + IP + UDP + extra header (VLAN, MPLS, ...)
289                 // IPv4 packet
290
291                 ip = ip_hdr->dst_addr;
292                 if (unlikely((ip_hdr->version_ihl >> 4) != 4)) {
293                         out[j] = OUT_DISCARD;
294                         continue;
295                 }
296
297                 switch (ip_hdr->next_proto_id) {
298                 case IPPROTO_GRE:
299                         ip_hdr->dst_addr = ip_hdr->src_addr;
300                         ip_hdr->src_addr = ip;
301
302                         pgre = (struct gre_hdr *)(ip_hdr + 1);
303                         inner_ip_hdr = ((prox_rte_ipv4_hdr *)(pgre + 1));
304                         ip = inner_ip_hdr->dst_addr;
305                         inner_ip_hdr->dst_addr = inner_ip_hdr->src_addr;
306                         inner_ip_hdr->src_addr = ip;
307
308                         udp_hdr = (prox_rte_udp_hdr *)(inner_ip_hdr + 1);
309                         // TODO 3.1 : verify proto is UPD or TCP
310                         port = udp_hdr->dst_port;
311                         udp_hdr->dst_port = udp_hdr->src_port;
312                         udp_hdr->src_port = port;
313                         write_src_and_dst_mac(task, mbufs[j]);
314                         break;
315                 case IPPROTO_UDP:
316                 case IPPROTO_TCP:
317                         if (unlikely(task->igmp_address && PROX_RTE_IS_IPV4_MCAST(rte_be_to_cpu_32(ip)))) {
318                                 out[j] = OUT_DISCARD;
319                                 continue;
320                         }
321                         udp_hdr = (prox_rte_udp_hdr *)(ip_hdr + 1);
322                         ip_hdr->dst_addr = ip_hdr->src_addr;
323                         ip_hdr->src_addr = ip;
324
325                         port = udp_hdr->dst_port;
326                         udp_hdr->dst_port = udp_hdr->src_port;
327                         udp_hdr->src_port = port;
328                         write_src_and_dst_mac(task, mbufs[j]);
329                         break;
330                 case IPPROTO_ICMP:
331                         picmp = (prox_rte_icmp_hdr *)(ip_hdr + 1);
332                         type = picmp->icmp_type;
333                         if (type == PROX_RTE_IP_ICMP_ECHO_REQUEST) {
334                                 if (ip_hdr->dst_addr == task->local_ipv4) {
335                                         task->n_echo_req++;
336                                         if (rte_rdtsc() - task->last_echo_req_rcvd_tsc > rte_get_tsc_hz()) {
337                                                 plog_info("Received %u Echo Request on IP "IPv4_BYTES_FMT" (last received from IP "IPv4_BYTES_FMT")\n", task->n_echo_req, IPv4_BYTES(((uint8_t*)&ip_hdr->dst_addr)), IPv4_BYTES(((uint8_t*)&ip_hdr->src_addr)));
338                                                 task->n_echo_req = 0;
339                                                 task->last_echo_req_rcvd_tsc = rte_rdtsc();
340                                         }
341                                         build_icmp_reply_message(tbase, mbufs[j]);
342                                 } else {
343                                         out[j] = OUT_DISCARD;
344                                         continue;
345                                 }
346                         } else if (type == PROX_RTE_IP_ICMP_ECHO_REPLY) {
347                                 if (ip_hdr->dst_addr == task->local_ipv4) {
348                                         task->n_echo_rep++;
349                                         if (rte_rdtsc() - task->last_echo_rep_rcvd_tsc > rte_get_tsc_hz()) {
350                                                 plog_info("Received %u Echo Reply on IP "IPv4_BYTES_FMT" (last received from IP "IPv4_BYTES_FMT")\n", task->n_echo_rep, IPv4_BYTES(((uint8_t*)&ip_hdr->dst_addr)), IPv4_BYTES(((uint8_t*)&ip_hdr->src_addr)));
351                                                 task->n_echo_rep = 0;
352                                                 task->last_echo_rep_rcvd_tsc = rte_rdtsc();
353                                         }
354                                 } else {
355                                         out[j] = OUT_DISCARD;
356                                         continue;
357                                 }
358                         } else {
359                                 out[j] = OUT_DISCARD;
360                                 continue;
361                         }
362                         break;
363                 case IPPROTO_IGMP:
364                         pigmp = (struct igmpv2_hdr *)(ip_hdr + 1);
365                         // TODO: check packet len
366                         type = pigmp->type;
367                         if (type == IGMP_MEMBERSHIP_QUERY) {
368                                 if (task->igmp_address) {
369                                         // We have an address registered
370                                         if ((task->igmp_address == pigmp->group_address) || (pigmp->group_address == 0)) {
371                                                 // We get a request for the registered address, or to 0.0.0.0
372                                                 build_igmp_message(tbase, mbufs[j], task->igmp_address, IGMP_MEMBERSHIP_REPORT);        // replace Membership query packet with a response
373                                         } else {
374                                                 // Discard as either we are not registered or this is a query for a different group
375                                                 out[j] = OUT_DISCARD;
376                                                 continue;
377                                         }
378                                 } else {
379                                         // Discard as either we are not registered
380                                         out[j] = OUT_DISCARD;
381                                         continue;
382                                 }
383                         } else {
384                                 // Do not forward other IGMP packets back
385                                 out[j] = OUT_DISCARD;
386                                 continue;
387                         }
388                         break;
389                 default:
390                         plog_warn("Unsupported IP protocol 0x%x\n", ip_hdr->next_proto_id);
391                         out[j] = OUT_DISCARD;
392                         continue;
393                 }
394         }
395         return task->base.tx_pkt(&task->base, mbufs, n_pkts, out);
396 }
397
398 void igmp_join_group(struct task_base *tbase, uint32_t igmp_address)
399 {
400         struct task_swap *task = (struct task_swap *)tbase;
401         struct rte_mbuf *igmp_mbuf;
402         uint8_t out[64] = {0};
403         int ret;
404
405         task->igmp_address = igmp_address;
406         ret = rte_mempool_get(task->igmp_pool, (void **)&igmp_mbuf);
407         if (ret != 0) {
408                 plog_err("Unable to allocate igmp mbuf\n");
409                 return;
410         }
411         build_igmp_message(tbase, igmp_mbuf, task->igmp_address, IGMP_MEMBERSHIP_REPORT);
412         task->base.tx_pkt(&task->base, &igmp_mbuf, 1, out);
413 }
414
415 void igmp_leave_group(struct task_base *tbase)
416 {
417         struct task_swap *task = (struct task_swap *)tbase;
418         struct rte_mbuf *igmp_mbuf;
419         uint8_t out[64] = {0};
420         int ret;
421
422         task->igmp_address = 0;
423         ret = rte_mempool_get(task->igmp_pool, (void **)&igmp_mbuf);
424         if (ret != 0) {
425                 plog_err("Unable to allocate igmp mbuf\n");
426                 return;
427         }
428         build_igmp_message(tbase, igmp_mbuf, task->igmp_address, IGMP_LEAVE_GROUP);
429         task->base.tx_pkt(&task->base, &igmp_mbuf, 1, out);
430 }
431
432 static void init_task_swap(struct task_base *tbase, struct task_args *targ)
433 {
434         struct task_swap *task = (struct task_swap *)tbase;
435         prox_rte_ether_addr *src_addr, *dst_addr;
436
437         /*
438          * The destination MAC of the outgoing packet is based on the config file:
439          *    - 'dst mac=xx:xx:xx:xx:xx:xx' => the pre-configured mac will be used as dst mac
440          *    - 'dst mac=packet'            => the src mac of the incoming packet is used as dst mac
441          *    - (default - no 'dst mac')    => the src mac from the incoming packet is used as dst mac
442          *
443          * The source MAC of the outgoing packet is based on the config file:
444          *    - 'src mac=xx:xx:xx:xx:xx:xx' => the pre-configured mac will be used as src mac
445          *    - 'src mac=packet'            => the dst mac of the incoming packet is used as src mac
446          *    - 'src mac=hw'                => the mac address of the tx port is used as src mac
447          *                                     An error is returned if there are no physical tx ports
448          *    - (default - no 'src mac')    => if there is physical tx port, the mac of that port is used as src mac
449          *    - (default - no 'src mac')       if there are no physical tx ports the dst mac of the incoming packet
450          */
451
452         if (targ->flags & TASK_ARG_DST_MAC_SET) {
453                 dst_addr = &targ->edaddr;
454                 memcpy(&task->src_dst_mac[0], dst_addr, sizeof(*src_addr));
455         }
456
457         PROX_PANIC(targ->flags & TASK_ARG_DO_NOT_SET_SRC_MAC, "src mac must be set in swap mode, by definition => src mac=no is not supported\n");
458         PROX_PANIC(targ->flags & TASK_ARG_DO_NOT_SET_DST_MAC, "dst mac must be set in swap mode, by definition => dst mac=no is not supported\n");
459
460         if (targ->flags & TASK_ARG_SRC_MAC_SET) {
461                 src_addr =  &targ->esaddr;
462                 memcpy(&task->src_dst_mac[6], src_addr, sizeof(*dst_addr));
463                 plog_info("\t\tCore %d: src mac set from config file\n", targ->lconf->id);
464         } else {
465                 if (targ->flags & TASK_ARG_HW_SRC_MAC)
466                         PROX_PANIC(targ->nb_txports == 0, "src mac set to hw but no tx port\n");
467                 if (targ->nb_txports) {
468                         src_addr = &prox_port_cfg[task->base.tx_params_hw.tx_port_queue[0].port].eth_addr;
469                         memcpy(&task->src_dst_mac[6], src_addr, sizeof(*dst_addr));
470                         targ->flags |= TASK_ARG_SRC_MAC_SET;
471                         plog_info("\t\tCore %d: src mac set from port\n", targ->lconf->id);
472                 }
473         }
474         task->runtime_flags = targ->flags;
475         task->igmp_address =  rte_cpu_to_be_32(targ->igmp_address);
476         if (task->igmp_pool == NULL) {
477                 static char name[] = "igmp0_pool";
478                 name[4]++;
479                 struct rte_mempool *ret = rte_mempool_create(name, NB_IGMP_MBUF, IGMP_MBUF_SIZE, NB_CACHE_IGMP_MBUF,
480                         sizeof(struct rte_pktmbuf_pool_private), rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, 0,
481                         rte_socket_id(), 0);
482                 PROX_PANIC(ret == NULL, "Failed to allocate IGMP memory pool on socket %u with %u elements\n",
483                         rte_socket_id(), NB_IGMP_MBUF);
484                 plog_info("\t\tMempool %p (%s) size = %u * %u cache %u, socket %d\n", ret, name, NB_IGMP_MBUF,
485                         IGMP_MBUF_SIZE, NB_CACHE_IGMP_MBUF, rte_socket_id());
486                 task->igmp_pool = ret;
487         }
488         task->local_ipv4 = rte_cpu_to_be_32(targ->local_ipv4);
489
490         struct prox_port_cfg *port = find_reachable_port(targ);
491         if (port) {
492                 task->offload_crc = port->requested_tx_offload & (DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM);
493         }
494 }
495
496 static struct task_init task_init_swap = {
497         .mode_str = "swap",
498         .init = init_task_swap,
499         .handle = handle_swap_bulk,
500         .flag_features = 0,
501         .size = sizeof(struct task_swap),
502         .stop_last = stop_swap
503 };
504
505 __attribute__((constructor)) static void reg_task_swap(void)
506 {
507         reg_task(&task_init_swap);
508 }