Fix compilation issues on old DPDK 38/70238/2
authorXavier Simonart <xavier.simonart@intel.com>
Fri, 29 May 2020 21:15:04 +0000 (23:15 +0200)
committerXavier Simonart <xavier.simonart@intel.com>
Fri, 29 May 2020 21:52:44 +0000 (23:52 +0200)
Also fixed minor issues such as
- prevent using vdev on DPDK <= 17.05 as not supported
- potential segmentation fault after panic (if panic thrown early
  in prox initialization)

Change-Id: I49a1962e95a4a44dddadd1fdd906e1b3b232465c
Signed-off-by: Xavier Simonart <xavier.simonart@intel.com>
VNFs/DPPD-PROX/handle_gen.c
VNFs/DPPD-PROX/handle_master.c
VNFs/DPPD-PROX/handle_swap.c
VNFs/DPPD-PROX/packet_utils.h
VNFs/DPPD-PROX/prox_args.c
VNFs/DPPD-PROX/prox_compat.h
VNFs/DPPD-PROX/prox_port_cfg.c
VNFs/DPPD-PROX/task_init.h

index 7a00408..adcabd7 100644 (file)
@@ -614,9 +614,16 @@ static int task_gen_reallocate_templates(struct task_gen *task, uint32_t nb_pkts
        }
 
        size_t mem_size = nb_pkts * sizeof(*task->pkt_template);
+       size_t old_mem_size = task->n_pkts * sizeof(*task->pkt_template);
+       if (old_mem_size > mem_size)
+               old_mem_size = mem_size;
+
        struct pkt_template *ptr;
+
        // re-allocate memory for new pkt_template (this might allocate additional memory or free up some...)
-       if ((ptr = rte_realloc_socket(task->pkt_template, mem_size, RTE_CACHE_LINE_SIZE, task->socket_id)) != NULL) {
+       if ((ptr = rte_malloc_socket(NULL, mem_size, RTE_CACHE_LINE_SIZE, task->socket_id)) != NULL) {
+               memcpy(ptr, task->pkt_template, old_mem_size);
+               rte_free(task->pkt_template);
                task->pkt_template = ptr;
        } else {
                plog_err_or_panic(do_panic, "Failed to allocate %lu bytes (in huge pages) for packet template for IMIX\n", mem_size);
index 8e03526..1026a17 100644 (file)
@@ -24,6 +24,7 @@
 #include <rte_hash.h>
 #include <rte_hash_crc.h>
 #include <rte_ether.h>
+#include <rte_icmp.h>
 
 #include "prox_cfg.h"
 #include "prox_globals.h"
index a5abd89..e097bc0 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <rte_mbuf.h>
 #include <rte_udp.h>
+#include <rte_icmp.h>
 
 #include "task_init.h"
 #include "task_base.h"
index 381a768..e1b262d 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef _PACKET_UTILS_H_
 #define _PACKET_UTILS_H_
 
+#include <rte_cycles.h>
+
 #include "prox_compat.h"
 #include "arp.h"
 #include "quit.h"
index 43f9d5f..d89481a 100644 (file)
@@ -2287,7 +2287,7 @@ int prox_setup_rte(const char *prog_name)
        }
        uint16_t port_id;
        for (int i = 0; i < n_deferred_ports; i++) {
-               if (rte_eth_dev_get_port_by_name(deferred_port[i].name, &port_id) != 0) {
+               if (prox_rte_eth_dev_get_port_by_name(deferred_port[i].name, &port_id) != 0) {
                        plog_err("Did not find port name %s used while reading %s\n", deferred_port[i].name, deferred_port[i].is_rx_port ? "rx port" : "tx_port");
                        return -1;
                }
index 091c2cc..404ce9e 100644 (file)
 #define _PROX_COMPAT_H_
 #include <rte_common.h>
 #include <rte_table_hash.h>
+#include <rte_ethdev.h>
 #include <rte_hash_crc.h>
 #include <rte_cryptodev.h>
+
 #include "hash_utils.h"
+#include "log.h"
 
 /* This is a copy of the rte_table_hash_params from DPDK 17.11  *
  * So if DPDK decides to change the structure the modifications *
@@ -36,12 +39,19 @@ struct prox_rte_table_params {
        uint64_t seed;
 };
 
-#if RTE_VERSION < RTE_VERSION_NUM(16,4,0,1)
+#if RTE_VERSION < RTE_VERSION_NUM(16,4,0,0)
 typedef uint8_t prox_next_hop_index_type;
 #else
 typedef uint32_t prox_next_hop_index_type;
 #endif
 
+#if RTE_VERSION < RTE_VERSION_NUM(16,7,0,0)
+static void rte_mempool_free(struct rte_mempool *mp)
+{
+       plog_warn("rte_mempool_free not supported in this DPDK - upgrade DPDK to avoid memory leaks\n");
+}
+#endif
+
 #if RTE_VERSION < RTE_VERSION_NUM(17,11,0,0)
 
 static void *prox_rte_table_create(struct prox_rte_table_params *params, int socket_id, uint32_t entry_size)
@@ -70,6 +80,16 @@ static void *prox_rte_table_create(struct prox_rte_table_params *params, int soc
        }
 };
 
+static inline int prox_rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
+{
+#if RTE_VERSION < RTE_VERSION_NUM(16,7,0,0)
+       plog_err("Not supported in DPDK version <= 16.04 by lack of rte_eth_dev_get_port_by_name support\n");
+       return -1;
+#else
+       return rte_eth_dev_get_port_by_name(name, (uint8_t *)port_id);
+#endif
+}
+
 #define prox_rte_table_free        rte_table_hash_ext_dosig_ops.f_free
 #define prox_rte_table_add         rte_table_hash_ext_dosig_ops.f_add
 #define prox_rte_table_delete      rte_table_hash_ext_dosig_ops.f_delete
@@ -109,6 +129,8 @@ static void *prox_rte_table_create(struct prox_rte_table_params *params, int soc
        }
 }
 
+#define prox_rte_eth_dev_get_port_by_name rte_eth_dev_get_port_by_name
+
 #define prox_rte_table_free        rte_table_hash_ext_ops.f_free
 #define prox_rte_table_add         rte_table_hash_ext_ops.f_add
 #define prox_rte_table_delete      rte_table_hash_ext_ops.f_delete
index 89824d6..b8b80a1 100644 (file)
@@ -215,13 +215,13 @@ void init_rte_dev(int use_dummy_devices)
                }
                struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id];
                if (port_cfg->vdev[0]) {
-#if (RTE_VERSION > RTE_VERSION_NUM(17,5,0,1))
                        char name[MAX_NAME_SIZE], tap[MAX_NAME_SIZE];
                        snprintf(tap, MAX_NAME_SIZE, "net_tap%d", port_id);
+#if (RTE_VERSION > RTE_VERSION_NUM(17,5,0,1))
                        snprintf(name, MAX_NAME_SIZE, "iface=%s", port_cfg->vdev);
                        rc = rte_vdev_init(tap, name);
 #else
-                       rc = eth_dev_null_create(tap, name, PROX_RTE_ETHER_MIN_LEN, 0);
+                       PROX_PANIC(1, "vdev not supported in DPDK < 17.05\n");
 #endif
                        PROX_PANIC(rc != 0, "Unable to create device %s %s\n", "net tap", port_cfg->vdev);
                        int vdev_port_id = prox_rte_eth_dev_count_avail() - 1;
@@ -289,6 +289,8 @@ void init_rte_dev(int use_dummy_devices)
 
                nb_ports = PROX_MAX_PORTS;
        }
+
+#if (RTE_VERSION >= RTE_VERSION_NUM(17,5,0,0))
        port_id_max = -1;
        uint16_t id;
        RTE_ETH_FOREACH_DEV(id) {
@@ -304,18 +306,28 @@ void init_rte_dev(int use_dummy_devices)
                                port_id_max = id;
                }
        }
+#else
+       port_id_max = nb_ports - 1;
+#endif
+
        port_id_last = prox_last_port_active();
        PROX_PANIC(port_id_last > port_id_max,
                   "\tError: invalid port(s) specified, last port index active: %d (max index is %d)\n",
                   port_id_last, port_id_max);
 
        /* Assign ports to PROX interfaces & Read max RX/TX queues per port */
+#if (RTE_VERSION >= RTE_VERSION_NUM(17,5,0,0))
        for (uint8_t port_id = 0; port_id <= port_id_last; ++port_id) {
+#else
+       for (uint8_t port_id = 0; port_id <= nb_ports; ++port_id) {
+#endif
                /* skip ports that are not enabled */
                if (!prox_port_cfg[port_id].active) {
                        continue;
+#if (RTE_VERSION >= RTE_VERSION_NUM(17,5,0,0))
                } else if (prox_port_cfg[port_id].available == 0) {
                        PROX_PANIC(1, "port %u enabled but not available\n", port_id);
+#endif
                }
                plog_info("\tGetting info for rte dev %u\n", port_id);
                rte_eth_dev_info_get(port_id, &dev_info);
@@ -875,6 +887,9 @@ void close_ports_atexit(void)
                rte_eth_dev_close(portid);
        }
 
+       if (lcore_cfg == NULL)
+               return;
+
        struct lcore_cfg *lconf = NULL;
        struct task_args *targ;
        while (core_targ_next(&lconf, &targ, 0) == 0) {
index 30a1515..33b912e 100644 (file)
@@ -137,6 +137,7 @@ struct task_args {
        uint32_t               arp_ndp_retransmit_timeout;
        struct ipv6_addr       local_ipv6;    /* For IPv6 Tunnel, it's the local tunnel endpoint address */
        struct ipv6_addr       global_ipv6;
+       struct ipv6_addr       gateway_ipv6;
        struct ipv6_addr       router_prefix;
        struct rte_ring        *rx_rings[MAX_RINGS_PER_TASK];
        struct rte_ring        *tx_rings[MAX_RINGS_PER_TASK];