net: add rte prefix to ether defines
[dpdk.git] / lib / librte_kni / rte_kni.c
index b8edd40..e6507b0 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright(c) 2010-2014 Intel Corporation
  */
 
-#ifndef RTE_EXEC_ENV_LINUXAPP
+#ifndef RTE_EXEC_ENV_LINUX
 #error "KNI is not supported"
 #endif
 
@@ -21,7 +21,7 @@
 #include <rte_tailq.h>
 #include <rte_rwlock.h>
 #include <rte_eal_memconfig.h>
-#include <exec-env/rte_kni_common.h>
+#include <rte_kni_common.h>
 #include "rte_kni_fifo.h"
 
 #define MAX_MBUF_BURST_NUM            32
@@ -234,7 +234,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
                goto kni_fail;
        }
 
-       snprintf(kni->name, RTE_KNI_NAMESIZE, "%s", conf->name);
+       strlcpy(kni->name, conf->name, RTE_KNI_NAMESIZE);
 
        if (ops)
                memcpy(&kni->ops, ops, sizeof(struct rte_kni_ops));
@@ -253,9 +253,9 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
        dev_info.mbuf_size = conf->mbuf_size;
        dev_info.mtu = conf->mtu;
 
-       memcpy(dev_info.mac_addr, conf->mac_addr, ETHER_ADDR_LEN);
+       memcpy(dev_info.mac_addr, conf->mac_addr, RTE_ETHER_ADDR_LEN);
 
-       snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", conf->name);
+       strlcpy(dev_info.name, conf->name, RTE_KNI_NAMESIZE);
 
        RTE_LOG(INFO, KNI, "pci: %02x:%02x:%02x \t %02x:%02x\n",
                dev_info.bus, dev_info.devid, dev_info.function,
@@ -400,7 +400,7 @@ rte_kni_release(struct rte_kni *kni)
        if (te == NULL)
                goto unlock;
 
-       snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
+       strlcpy(dev_info.name, kni->name, sizeof(dev_info.name));
        if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) {
                RTE_LOG(ERR, KNI, "Fail to release kni device\n");
                goto unlock;
@@ -451,7 +451,7 @@ kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[])
        RTE_LOG(INFO, KNI, "Configure mac address of %d", port_id);
 
        ret = rte_eth_dev_default_mac_addr_set(port_id,
-                                              (struct ether_addr *)mac_addr);
+                                       (struct rte_ether_addr *)mac_addr);
        if (ret < 0)
                RTE_LOG(ERR, KNI, "Failed to config mac_addr for port %d\n",
                        port_id);
@@ -483,7 +483,7 @@ int
 rte_kni_handle_request(struct rte_kni *kni)
 {
        unsigned ret;
-       struct rte_kni_request *req;
+       struct rte_kni_request *req = NULL;
 
        if (kni == NULL)
                return -1;
@@ -717,6 +717,47 @@ rte_kni_unregister_handlers(struct rte_kni *kni)
 
        return 0;
 }
+
+int __rte_experimental
+rte_kni_update_link(struct rte_kni *kni, unsigned int linkup)
+{
+       char path[64];
+       char old_carrier[2];
+       const char *new_carrier;
+       int old_linkup;
+       int fd, ret;
+
+       if (kni == NULL)
+               return -1;
+
+       snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier",
+               kni->name);
+
+       fd = open(path, O_RDWR);
+       if (fd == -1) {
+               RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path);
+               return -1;
+       }
+
+       ret = read(fd, old_carrier, 2);
+       if (ret < 1) {
+               close(fd);
+               return -1;
+       }
+       old_linkup = (old_carrier[0] == '1');
+
+       new_carrier = linkup ? "1" : "0";
+       ret = write(fd, new_carrier, 1);
+       if (ret < 1) {
+               RTE_LOG(ERR, KNI, "Failed to write file: %s.\n", path);
+               close(fd);
+               return -1;
+       }
+
+       close(fd);
+       return old_linkup;
+}
+
 void
 rte_kni_close(void)
 {