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