Added support for VLAN in IPv6
[samplevnf.git] / VNFs / DPPD-PROX / lconf.c
index 399c8a7..be2486e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-// Copyright (c) 2010-2017 Intel Corporation
+// Copyright (c) 2010-2020 Intel Corporation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -127,6 +127,10 @@ static void msg_stop(struct lcore_cfg *lconf)
                                idx++;
                        }
                }
+               // Check that task id is valid and running
+               if (idx == -1)
+                       return;
+
                lconf->task_is_running[lconf->msg.task_id] = 0;
 
                t = lconf->tasks_all[lconf->msg.task_id];
@@ -155,8 +159,14 @@ static void msg_start(struct lcore_cfg *lconf)
                                t->aux->start(t);
                }
                lconf->n_tasks_run = lconf->n_tasks_all;
+               return;
        }
-       else if (lconf->n_tasks_run == 0) {
+
+       // Check that task id is valid
+       if (lconf->msg.task_id >= lconf->n_tasks_all)
+               return;
+
+       if (lconf->n_tasks_run == 0) {
                t = lconf->tasks_run[0] = lconf->tasks_all[lconf->msg.task_id];
                lconf->n_tasks_run = 1;
                lconf->task_is_running[lconf->msg.task_id] = 1;
@@ -167,9 +177,13 @@ static void msg_start(struct lcore_cfg *lconf)
                        t->aux->start(t);
        }
        else {
+               if (lconf->task_is_running[lconf->msg.task_id])
+                       return;
                for (int i = lconf->n_tasks_run - 1; i >= 0; --i) {
                        idx = lconf_get_task_id(lconf, lconf->tasks_run[i]);
                        if (idx == lconf->msg.task_id) {
+                               // We should not come here as checking earlier if task id is running...
+                               plog_warn("Unexpectedly get request to start task %d already running\n", idx);
                                break;
                        }
                        else if (idx > lconf->msg.task_id) {
@@ -198,6 +212,15 @@ int lconf_do_flags(struct lcore_cfg *lconf)
        struct task_base *t;
        int ret = 0;
 
+       if ((lconf->msg.type == LCONF_MSG_TRACE) && (lconf->tasks_all[lconf->msg.task_id]->tx_pkt == tx_pkt_drop_all)) {
+               /* We are asked to dump packets through command dump.
+                * This usually means map RX and TX packets before printing them.
+                * However we do not transmit the packets in this case => use the DUMP_RX function.
+                * This will prevent seeing the received packets also printed as TX[255] (= dropped)
+                */
+               lconf->msg.type = LCONF_MSG_DUMP_RX;
+       }
+
        switch (lconf->msg.type) {
        case LCONF_MSG_STOP:
                msg_stop(lconf);
@@ -223,7 +246,7 @@ int lconf_do_flags(struct lcore_cfg *lconf)
                        if (lconf->msg.type == LCONF_MSG_DUMP ||
                            lconf->msg.type == LCONF_MSG_DUMP_TX) {
                                t->aux->task_rt_dump.n_print_tx = lconf->msg.val;
-                               if (t->tx_pkt == tx_pkt_l3) {
+                               if ((t->tx_pkt == tx_pkt_l3) || (t->tx_pkt == tx_pkt_ndp)) {
                                        if (t->aux->tx_pkt_orig)
                                                t->aux->tx_pkt_l2 = t->aux->tx_pkt_orig;
                                        t->aux->tx_pkt_orig = t->aux->tx_pkt_l2;
@@ -241,11 +264,10 @@ int lconf_do_flags(struct lcore_cfg *lconf)
                t = lconf->tasks_all[lconf->msg.task_id];
 
                if (lconf->msg.val) {
-                       t->aux->task_rt_dump.n_trace = lconf->msg.val;
-
                        if (task_base_get_original_rx_pkt_function(t) != rx_pkt_dummy) {
+                               t->aux->task_rt_dump.n_trace = lconf->msg.val;
                                task_base_add_rx_pkt_function(t, rx_pkt_trace);
-                               if (t->tx_pkt == tx_pkt_l3) {
+                               if ((t->tx_pkt == tx_pkt_l3) || (t->tx_pkt == tx_pkt_ndp)) {
                                        if (t->aux->tx_pkt_orig)
                                                t->aux->tx_pkt_l2 = t->aux->tx_pkt_orig;
                                        t->aux->tx_pkt_orig = t->aux->tx_pkt_l2;
@@ -258,7 +280,7 @@ int lconf_do_flags(struct lcore_cfg *lconf)
                                }
                        } else {
                                t->aux->task_rt_dump.n_print_tx = lconf->msg.val;
-                               if (t->tx_pkt == tx_pkt_l3) {
+                               if ((t->tx_pkt == tx_pkt_l3) || (t->tx_pkt == tx_pkt_ndp)) {
                                        if (t->aux->tx_pkt_orig)
                                                t->aux->tx_pkt_l2 = t->aux->tx_pkt_orig;
                                        t->aux->tx_pkt_orig = t->aux->tx_pkt_l2;
@@ -284,7 +306,7 @@ int lconf_do_flags(struct lcore_cfg *lconf)
                for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
                        t = lconf->tasks_all[task_id];
 
-                       if (t->tx_pkt == tx_pkt_l3) {
+                       if ((t->tx_pkt == tx_pkt_l3) || (t->tx_pkt == tx_pkt_ndp)) {
                                t->aux->tx_pkt_orig = t->aux->tx_pkt_l2;
                                t->aux->tx_pkt_l2 = tx_pkt_distr;
                        } else {
@@ -306,11 +328,11 @@ int lconf_do_flags(struct lcore_cfg *lconf)
                for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
                        t = lconf->tasks_all[task_id];
                        if (t->aux->tx_pkt_orig) {
-                               if (t->tx_pkt == tx_pkt_l3) {
-                                       t->tx_pkt = t->aux->tx_pkt_orig;
+                               if ((t->tx_pkt == tx_pkt_l3) || (t->tx_pkt == tx_pkt_ndp)) {
+                                       t->aux->tx_pkt_l2 = t->aux->tx_pkt_orig;
                                        t->aux->tx_pkt_orig = NULL;
                                } else {
-                                       t->aux->tx_pkt_l2 = t->aux->tx_pkt_orig;
+                                       t->tx_pkt = t->aux->tx_pkt_orig;
                                        t->aux->tx_pkt_orig = NULL;
                                }
                                lconf->flags &= ~LCONF_FLAG_TX_DISTR_ACTIVE;
@@ -349,7 +371,7 @@ int lconf_do_flags(struct lcore_cfg *lconf)
                for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
                        t = lconf->tasks_all[task_id];
 
-                       if (t->tx_pkt == tx_pkt_l3) {
+                       if ((t->tx_pkt == tx_pkt_l3) || (t->tx_pkt == tx_pkt_ndp)) {
                                t->aux->tx_pkt_orig = t->aux->tx_pkt_l2;
                                t->aux->tx_pkt_l2 = tx_pkt_bw;
                        } else {
@@ -363,7 +385,7 @@ int lconf_do_flags(struct lcore_cfg *lconf)
                for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
                        t = lconf->tasks_all[task_id];
                        if (t->aux->tx_pkt_orig) {
-                               if (t->tx_pkt == tx_pkt_l3) {
+                               if ((t->tx_pkt == tx_pkt_l3) || (t->tx_pkt == tx_pkt_ndp)) {
                                        t->aux->tx_pkt_l2 = t->aux->tx_pkt_orig;
                                        t->aux->tx_pkt_orig = NULL;
                                } else {