diff options
Diffstat (limited to 'VNFs/DPPD-PROX/prox_port_cfg.c')
-rw-r--r-- | VNFs/DPPD-PROX/prox_port_cfg.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/VNFs/DPPD-PROX/prox_port_cfg.c b/VNFs/DPPD-PROX/prox_port_cfg.c index 2e19d25d..89824d69 100644 --- a/VNFs/DPPD-PROX/prox_port_cfg.c +++ b/VNFs/DPPD-PROX/prox_port_cfg.c @@ -165,24 +165,39 @@ void prox_pktmbuf_reinit(void *arg, void *start, __attribute__((unused)) void *e plog_info("\t\t%s disabled\n", #flag);\ }\ +static inline uint32_t get_netmask(uint8_t prefix) +{ + if (prefix == 0) + return(~((uint32_t) -1)); + else + return rte_cpu_to_be_32(~((1 << (32 - prefix)) - 1)); +} -static void set_ip_address (char *devname, uint32_t *ip) +static void set_ip_address(char *devname, uint32_t *ip, uint8_t prefix) { struct ifreq ifreq; struct sockaddr_in in_addr; int fd, rc; + uint32_t netmask = get_netmask(prefix); + plog_info("Setting netmask to %x\n", netmask); + + fd = socket(AF_INET, SOCK_DGRAM, 0); memset(&ifreq, 0, sizeof(struct ifreq)); memset(&in_addr, 0, sizeof(struct sockaddr_in)); in_addr.sin_family = AF_INET; in_addr.sin_addr = *(struct in_addr *)ip; - fd = socket(in_addr.sin_family, SOCK_DGRAM, 0); strncpy(ifreq.ifr_name, devname, IFNAMSIZ); ifreq.ifr_addr = *(struct sockaddr *)&in_addr; rc = ioctl(fd, SIOCSIFADDR, &ifreq); - PROX_PANIC(rc < 0, "Failed to set IP address %d on device %s: error = %d\n", *ip, devname, errno); + PROX_PANIC(rc < 0, "Failed to set IP address %x on device %s: error = %d (%s)\n", *ip, devname, errno, strerror(errno)); + + in_addr.sin_addr = *(struct in_addr *)&netmask; + ifreq.ifr_netmask = *(struct sockaddr *)&in_addr; + rc = ioctl(fd, SIOCSIFNETMASK, &ifreq); + PROX_PANIC(rc < 0, "Failed to set netmask %x (prefix %d) on device %s: error = %d (%s)\n", netmask, prefix, devname, errno, strerror(errno)); close(fd); } @@ -212,6 +227,7 @@ void init_rte_dev(int use_dummy_devices) int vdev_port_id = prox_rte_eth_dev_count_avail() - 1; PROX_PANIC(vdev_port_id >= PROX_MAX_PORTS, "Too many port defined %d >= %d\n", vdev_port_id, PROX_MAX_PORTS); plog_info("\tCreating device %s, port %d\n", port_cfg->vdev, vdev_port_id); + prox_port_cfg[vdev_port_id].is_vdev = 1; prox_port_cfg[vdev_port_id].active = 1; prox_port_cfg[vdev_port_id].dpdk_mapping = port_id; prox_port_cfg[vdev_port_id].n_txq = 1; @@ -228,7 +244,7 @@ void init_rte_dev(int use_dummy_devices) prox_port_cfg[port_id].dpdk_mapping = vdev_port_id; prox_port_cfg[vdev_port_id].ip = rte_be_to_cpu_32(prox_port_cfg[port_id].ip); - prox_port_cfg[port_id].ip = 0; // So only vdev has an IP associated + prox_port_cfg[vdev_port_id].prefix = prox_port_cfg[port_id].prefix; prox_port_cfg[vdev_port_id].type = prox_port_cfg[port_id].type; if (prox_port_cfg[vdev_port_id].type == PROX_PORT_MAC_HW) { // If DPDK port MAC set to HW, then make sure the vdev has the same MAC as DPDK port @@ -768,8 +784,8 @@ static void init_port(struct prox_port_cfg *port_cfg) PROX_PANIC(ret < 0, "\n\t\t\trte_eth_dev_start() failed on port %u: error %d\n", port_id, ret); plog_info(" done: "); - if (prox_port_cfg[port_id].ip) { - set_ip_address(prox_port_cfg[port_id].name, &prox_port_cfg[port_id].ip); + if ((prox_port_cfg[port_id].ip) && (prox_port_cfg[port_id].is_vdev)) { + set_ip_address(prox_port_cfg[port_id].name, &prox_port_cfg[port_id].ip, prox_port_cfg[port_id].prefix); } /* Getting link status can be done without waiting if Link State Interrupt is enabled since in that case, if the link |