Merge "Rest API: Fix all the bugs in the HWLB, mask issue, etc"
[samplevnf.git] / common / vnf_common / vnf_common.c
index a40d4d8..ff0039b 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include "vnf_common.h"
+#include "gateway.h"
 #include "pipeline_arpicmp_be.h"
 #ifndef VNF_ACL
 #include "lib_arp.h"
@@ -47,13 +48,12 @@ uint8_t is_port_index_privte(uint16_t phy_port)
 uint32_t get_prv_to_pub_port(uint32_t *ip_addr, uint8_t type)
 {
        uint32_t dest_if = 0xff;
-       struct ether_addr addr;
 
        switch (type) {
        case 4:
        {
                uint32_t nhip;
-               nhip = get_nh(ip_addr[0], &dest_if, &addr);
+               gw_get_nh_port_ipv4(*ip_addr, &dest_if, &nhip);
 
                if (nhip)
                        return dest_if;
@@ -63,7 +63,8 @@ uint32_t get_prv_to_pub_port(uint32_t *ip_addr, uint8_t type)
        case 6:
        {
                uint8_t nhipv6[16];
-               get_nh_ipv6((uint8_t *)ip_addr, &dest_if, &nhipv6[0]);
+               gw_get_nh_port_ipv6((uint8_t *)ip_addr, &dest_if, nhipv6);
+
                if (dest_if != 0xff)
                        return dest_if;
                return 0xff;
@@ -76,13 +77,13 @@ uint32_t get_prv_to_pub_port(uint32_t *ip_addr, uint8_t type)
 uint32_t get_pub_to_prv_port(uint32_t *ip_addr, uint8_t type)
 {
        uint32_t dest_if = 0xff;
-       struct ether_addr addr;
 
        switch (type) {
        case 4:
        {
                uint32_t nhip;
-               nhip = get_nh(ip_addr[0], &dest_if, &addr);
+
+               gw_get_nh_port_ipv4(*ip_addr, &dest_if, &nhip);
 
                if (nhip)
                        return dest_if;
@@ -92,7 +93,8 @@ uint32_t get_pub_to_prv_port(uint32_t *ip_addr, uint8_t type)
        case 6:
        {
                uint8_t nhipv6[16];
-               get_nh_ipv6((uint8_t *)ip_addr, &dest_if, &nhipv6[0]);
+
+               gw_get_nh_port_ipv6((uint8_t *)ip_addr, &dest_if, nhipv6);
                if (dest_if != 0xff)
                        return dest_if;
                return 0xff;
@@ -139,10 +141,11 @@ void trim(char *input)
        char result[len + 1];
 
        memset(result, 0, sizeof(result));
-       for (i = 0; input[i] != '\0'; i++) {
+       for (i = 0; (input[i] != '\0') && (i < PIPELINE_MAX_ARGS); i++) {
                if (!isspace(input[i]))
                        result[j++] = input[i];
        }
+       result[j] = '\0';
 
-       strncpy(input, result, len);
+       strncpy(input, result, strlen(result));
 }