net: Remove library
Now that we've deprecated the RPCs for a release, we can remove the whole library. Change-Id: I0f1a357fcfb3404efac39aa021928841c2f22ff1 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4305 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
parent
1be049b7d4
commit
e1d06d9954
@ -43,7 +43,7 @@ CFLAGS += -I$(SPDK_ROOT_DIR)/lib
|
||||
|
||||
C_SRCS := iscsi_tgt.c
|
||||
|
||||
SPDK_LIB_LIST = $(ALL_MODULES_LIST) event event_iscsi event_net
|
||||
SPDK_LIB_LIST = $(ALL_MODULES_LIST) event event_iscsi
|
||||
|
||||
ifeq ($(SPDK_ROOT_DIR)/lib/env_dpdk,$(CONFIG_ENV))
|
||||
SPDK_LIB_LIST += env_dpdk_rpc
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "spdk/event.h"
|
||||
#include "iscsi/iscsi.h"
|
||||
#include "spdk/log.h"
|
||||
#include "spdk/net.h"
|
||||
|
||||
static int g_daemon_mode = 0;
|
||||
|
||||
|
@ -405,9 +405,6 @@ Example response:
|
||||
"framework_start_init",
|
||||
"rpc_get_methods",
|
||||
"scsi_get_devices",
|
||||
"net_get_interfaces",
|
||||
"delete_ip_address",
|
||||
"net_interface_add_ip_address",
|
||||
"nbd_get_disks",
|
||||
"nbd_stop_disk",
|
||||
"nbd_start_disk",
|
||||
|
@ -38,6 +38,6 @@ APP = hello_sock
|
||||
C_SRCS := hello_sock.c
|
||||
|
||||
SPDK_LIB_LIST = $(SOCK_MODULES_LIST)
|
||||
SPDK_LIB_LIST += event event_net sock
|
||||
SPDK_LIB_LIST += event sock
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "spdk/string.h"
|
||||
|
||||
#include "spdk/sock.h"
|
||||
#include "spdk/net.h"
|
||||
|
||||
#define ACCEPT_TIMEOUT_US 1000
|
||||
#define CLOSE_TIMEOUT_US 1000000
|
||||
|
@ -1,67 +0,0 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* Net framework abstraction layer
|
||||
*/
|
||||
|
||||
#ifndef SPDK_NET_H
|
||||
#define SPDK_NET_H
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
|
||||
#include "spdk/queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct spdk_sock;
|
||||
|
||||
/**
|
||||
* Initialize the network interfaces by getting information through netlink socket.
|
||||
*
|
||||
* \return 0 on success, 1 on failure.
|
||||
*/
|
||||
int spdk_interface_init(void);
|
||||
|
||||
/**
|
||||
* Destroy the network interfaces.
|
||||
*/
|
||||
void spdk_interface_destroy(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SPDK_NET_H */
|
@ -36,7 +36,7 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.lib_deps.mk
|
||||
|
||||
DIRS-y += bdev blob blobfs conf accel event json jsonrpc \
|
||||
log lvol net rpc sock thread trace util nvme vmd nvmf scsi \
|
||||
log lvol rpc sock thread trace util nvme vmd nvmf scsi \
|
||||
ioat ut_mock iscsi notify init
|
||||
ifeq ($(OS),Linux)
|
||||
DIRS-y += nbd ftl
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "spdk/thread.h"
|
||||
#include "spdk/queue.h"
|
||||
#include "spdk/trace.h"
|
||||
#include "spdk/net.h"
|
||||
#include "spdk/sock.h"
|
||||
#include "spdk/string.h"
|
||||
|
||||
|
@ -43,7 +43,6 @@
|
||||
#include "spdk/sock.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/queue.h"
|
||||
#include "spdk/net.h"
|
||||
|
||||
#include "iscsi/md5.h"
|
||||
#include "iscsi/iscsi.h"
|
||||
|
@ -1,46 +0,0 @@
|
||||
#
|
||||
# BSD LICENSE
|
||||
#
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
SO_VER := 3
|
||||
SO_MINOR := 0
|
||||
|
||||
C_SRCS = interface.c net_rpc.c
|
||||
|
||||
LIBNAME = net
|
||||
|
||||
SPDK_MAP_FILE = $(abspath $(CURDIR)/spdk_net.map)
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
|
@ -1,550 +0,0 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "net_internal.h"
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/string.h"
|
||||
|
||||
#include "spdk/log.h"
|
||||
#include "spdk/net.h"
|
||||
|
||||
#ifdef __linux__ /* Interface management is Linux-specific */
|
||||
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
|
||||
static TAILQ_HEAD(, spdk_interface) g_interface_head = TAILQ_HEAD_INITIALIZER(g_interface_head);
|
||||
|
||||
static pthread_mutex_t interface_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static int get_ifc_ipv4(void)
|
||||
{
|
||||
int ret;
|
||||
int rtattrlen;
|
||||
int netlink_fd;
|
||||
uint32_t ipv4_addr;
|
||||
|
||||
struct {
|
||||
struct nlmsghdr n;
|
||||
struct ifaddrmsg r;
|
||||
struct rtattr rta;
|
||||
} req;
|
||||
char buf[16384];
|
||||
struct nlmsghdr *nlmp;
|
||||
struct ifaddrmsg *rtmp;
|
||||
struct rtattr *rtatp;
|
||||
struct spdk_interface *ifc;
|
||||
|
||||
netlink_fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
|
||||
if (netlink_fd < 0) {
|
||||
SPDK_ERRLOG("socket failed!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare a message structure
|
||||
*/
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
|
||||
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
|
||||
req.n.nlmsg_type = RTM_GETADDR;
|
||||
|
||||
/* IPv4 only */
|
||||
req.r.ifa_family = AF_INET;
|
||||
|
||||
/*
|
||||
* Fill up all the attributes for the rtnetlink header.
|
||||
*/
|
||||
assert(&req.rta == (struct rtattr *)(((char *)&req) + NLMSG_ALIGN(req.n.nlmsg_len)));
|
||||
req.rta.rta_len = RTA_LENGTH(16);
|
||||
|
||||
/* Send and recv the message from kernel */
|
||||
ret = send(netlink_fd, &req, req.n.nlmsg_len, 0);
|
||||
if (ret < 0) {
|
||||
SPDK_ERRLOG("netlink send failed: %s\n", spdk_strerror(errno));
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = recv(netlink_fd, buf, sizeof(buf), 0);
|
||||
if (ret <= 0) {
|
||||
SPDK_ERRLOG("netlink recv failed: %s\n", spdk_strerror(errno));
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (nlmp = (struct nlmsghdr *)buf; ret > (int)sizeof(*nlmp);) {
|
||||
int len = nlmp->nlmsg_len;
|
||||
int req_len = len - sizeof(*nlmp);
|
||||
|
||||
if (req_len < 0 || len > ret) {
|
||||
SPDK_ERRLOG("error\n");
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!NLMSG_OK(nlmp, (uint32_t)ret)) {
|
||||
SPDK_ERRLOG("NLMSG not OK\n");
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
rtmp = (struct ifaddrmsg *)NLMSG_DATA(nlmp);
|
||||
rtatp = (struct rtattr *)IFA_RTA(rtmp);
|
||||
|
||||
rtattrlen = IFA_PAYLOAD(nlmp);
|
||||
|
||||
for (; RTA_OK(rtatp, rtattrlen); rtatp = RTA_NEXT(rtatp, rtattrlen)) {
|
||||
if (rtatp->rta_type == IFA_LOCAL) {
|
||||
memcpy(&ipv4_addr, (struct in_addr *)RTA_DATA(rtatp),
|
||||
sizeof(struct in_addr));
|
||||
TAILQ_FOREACH(ifc, &g_interface_head, tailq) {
|
||||
if (ifc->index == rtmp->ifa_index) {
|
||||
/* add a new IP address to interface */
|
||||
if (ifc->num_ip_addresses >= SPDK_MAX_IP_PER_IFC) {
|
||||
SPDK_ERRLOG("SPDK: number of IP addresses supported for %s excceded. limit=%d\n",
|
||||
ifc->name,
|
||||
SPDK_MAX_IP_PER_IFC);
|
||||
break;
|
||||
}
|
||||
ifc->ip_address[ifc->num_ip_addresses] = ipv4_addr;
|
||||
ifc->num_ip_addresses++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ret -= NLMSG_ALIGN(len);
|
||||
nlmp = (struct nlmsghdr *)((char *)nlmp + NLMSG_ALIGN(len));
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
close(netlink_fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int process_new_interface_msg(struct nlmsghdr *h)
|
||||
{
|
||||
int len;
|
||||
struct spdk_interface *ifc;
|
||||
struct ifinfomsg *iface;
|
||||
struct rtattr *attribute;
|
||||
|
||||
iface = (struct ifinfomsg *)NLMSG_DATA(h);
|
||||
|
||||
ifc = (struct spdk_interface *) malloc(sizeof(*ifc));
|
||||
if (ifc == NULL) {
|
||||
SPDK_ERRLOG("Malloc failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(ifc, 0, sizeof(*ifc));
|
||||
|
||||
/* Set interface index */
|
||||
ifc->index = iface->ifi_index;
|
||||
|
||||
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(*iface));
|
||||
|
||||
/* Loop over all attributes for the NEWLINK message */
|
||||
for (attribute = IFLA_RTA(iface); RTA_OK(attribute, len); attribute = RTA_NEXT(attribute, len)) {
|
||||
switch (attribute->rta_type) {
|
||||
case IFLA_IFNAME:
|
||||
if (if_indextoname(iface->ifi_index, ifc->name) == NULL) {
|
||||
SPDK_ERRLOG("Indextoname failed!\n");
|
||||
free(ifc);
|
||||
return 2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
TAILQ_INSERT_TAIL(&g_interface_head, ifc, tailq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int prepare_ifc_list(void)
|
||||
{
|
||||
int ret = 0;
|
||||
struct nl_req_s {
|
||||
struct nlmsghdr hdr;
|
||||
struct rtgenmsg gen;
|
||||
struct ifinfomsg ifi;
|
||||
};
|
||||
int netlink_fd;
|
||||
struct sockaddr_nl local; /* Our local (user space) side of the communication */
|
||||
struct sockaddr_nl kernel; /* The remote (kernel space) side of the communication */
|
||||
|
||||
struct msghdr rtnl_msg; /* Generic msghdr struct for use with sendmsg */
|
||||
struct iovec io; /* IO vector for sendmsg */
|
||||
|
||||
struct nl_req_s req; /* Structure that describes the rtnetlink packet itself */
|
||||
char reply[16384]; /* a large buffer to receive lots of link information */
|
||||
|
||||
pid_t pid = getpid(); /* Our process ID to build the correct netlink address */
|
||||
int end = 0; /* some flag to end loop parsing */
|
||||
|
||||
/*
|
||||
* Prepare netlink socket for kernel/user space communication
|
||||
*/
|
||||
netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
if (netlink_fd < 0) {
|
||||
SPDK_ERRLOG("socket failed!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&local, 0, sizeof(local)); /* Fill-in local address information */
|
||||
local.nl_family = AF_NETLINK;
|
||||
local.nl_pid = pid;
|
||||
local.nl_groups = 0;
|
||||
|
||||
/* RTNL socket is ready to use, prepare and send L2 request. */
|
||||
memset(&rtnl_msg, 0, sizeof(rtnl_msg));
|
||||
memset(&kernel, 0, sizeof(kernel));
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
kernel.nl_family = AF_NETLINK; /* Fill-in kernel address (destination of our message) */
|
||||
|
||||
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
|
||||
req.hdr.nlmsg_type = RTM_GETLINK;
|
||||
req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
|
||||
req.hdr.nlmsg_seq = 1;
|
||||
req.hdr.nlmsg_pid = pid;
|
||||
|
||||
req.ifi.ifi_family = AF_UNSPEC;
|
||||
req.ifi.ifi_type = 1;
|
||||
|
||||
io.iov_base = &req;
|
||||
io.iov_len = req.hdr.nlmsg_len;
|
||||
rtnl_msg.msg_iov = &io;
|
||||
rtnl_msg.msg_iovlen = 1;
|
||||
rtnl_msg.msg_name = &kernel;
|
||||
rtnl_msg.msg_namelen = sizeof(kernel);
|
||||
|
||||
if (sendmsg(netlink_fd, &rtnl_msg, 0) == -1) {
|
||||
SPDK_ERRLOG("Sendmsg failed!\n");
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Parse reply */
|
||||
while (!end) {
|
||||
int len;
|
||||
struct nlmsghdr *msg_ptr; /* Pointer to current message part */
|
||||
|
||||
struct msghdr rtnl_reply; /* Generic msghdr structure for use with recvmsg */
|
||||
struct iovec io_reply;
|
||||
|
||||
memset(&io_reply, 0, sizeof(io_reply));
|
||||
memset(&rtnl_reply, 0, sizeof(rtnl_reply));
|
||||
|
||||
io.iov_base = reply;
|
||||
io.iov_len = 8192;
|
||||
rtnl_reply.msg_iov = &io;
|
||||
rtnl_reply.msg_iovlen = 1;
|
||||
rtnl_reply.msg_name = &kernel;
|
||||
rtnl_reply.msg_namelen = sizeof(kernel);
|
||||
|
||||
/* Read as much data as fits in the receive buffer */
|
||||
len = recvmsg(netlink_fd, &rtnl_reply, 0);
|
||||
if (len) {
|
||||
for (msg_ptr = (struct nlmsghdr *) reply; NLMSG_OK(msg_ptr, (uint32_t)len);
|
||||
msg_ptr = NLMSG_NEXT(msg_ptr, len)) {
|
||||
switch (msg_ptr->nlmsg_type) {
|
||||
case NLMSG_DONE: /* This is the special meaning NLMSG_DONE message we asked for by using NLM_F_DUMP flag */
|
||||
end++;
|
||||
break;
|
||||
case RTM_NEWLINK: /* This is a RTM_NEWLINK message, which contains lots of information about a link */
|
||||
ret = process_new_interface_msg(msg_ptr);
|
||||
if (ret != 0) {
|
||||
goto exit;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit:
|
||||
close(netlink_fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct spdk_interface *
|
||||
interface_find_by_index(uint32_t ifc_index)
|
||||
{
|
||||
struct spdk_interface *ifc_entry;
|
||||
|
||||
/* Mutex must has benn held by the caller */
|
||||
TAILQ_FOREACH(ifc_entry, &g_interface_head, tailq) {
|
||||
if (ifc_entry->index == ifc_index) {
|
||||
return ifc_entry;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int netlink_addr_msg(uint32_t ifc_idx, uint32_t ip_address, uint32_t create)
|
||||
{
|
||||
int fd;
|
||||
struct sockaddr_nl la;
|
||||
struct sockaddr_nl pa;
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
int ifal;
|
||||
struct {
|
||||
struct nlmsghdr n;
|
||||
struct ifaddrmsg r;
|
||||
char buf[16384];
|
||||
} req;
|
||||
struct rtattr *rta;
|
||||
|
||||
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
if (fd < 0) {
|
||||
SPDK_ERRLOG("socket failed!\n");
|
||||
return errno;
|
||||
}
|
||||
|
||||
/* setup local address & bind using this address. */
|
||||
bzero(&la, sizeof(la));
|
||||
la.nl_family = AF_NETLINK;
|
||||
la.nl_pid = getpid();
|
||||
bind(fd, (struct sockaddr *) &la, sizeof(la));
|
||||
|
||||
/* initialize RTNETLINK request buffer. */
|
||||
bzero(&req, sizeof(req));
|
||||
|
||||
/* compute the initial length of the service request. */
|
||||
ifal = sizeof(struct ifaddrmsg);
|
||||
|
||||
/* add first attrib: set IP addr and RTNETLINK buffer size. */
|
||||
rta = (struct rtattr *) req.buf;
|
||||
rta->rta_type = IFA_ADDRESS;
|
||||
rta->rta_len = sizeof(struct rtattr) + 4;
|
||||
memcpy(((char *)rta) + sizeof(struct rtattr), &ip_address, sizeof(ip_address));
|
||||
ifal += rta->rta_len;
|
||||
|
||||
/* add second attrib. */
|
||||
rta = (struct rtattr *)(((char *)rta) + rta->rta_len);
|
||||
rta->rta_type = IFA_LOCAL;
|
||||
rta->rta_len = sizeof(struct rtattr) + 4;
|
||||
memcpy(((char *)rta) + sizeof(struct rtattr), &ip_address, sizeof(ip_address));
|
||||
ifal += rta->rta_len;
|
||||
|
||||
/* setup the NETLINK header. */
|
||||
req.n.nlmsg_len = NLMSG_LENGTH(ifal);
|
||||
if (create) {
|
||||
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_APPEND;
|
||||
req.n.nlmsg_type = RTM_NEWADDR;
|
||||
} else {
|
||||
req.n.nlmsg_flags = NLM_F_REQUEST;
|
||||
req.n.nlmsg_type = RTM_DELADDR;
|
||||
}
|
||||
|
||||
/* setup the service header (struct rtmsg). */
|
||||
req.r.ifa_family = AF_INET;
|
||||
req.r.ifa_prefixlen = 32; /* hardcoded */
|
||||
req.r.ifa_flags = IFA_F_PERMANENT | IFA_F_SECONDARY;
|
||||
req.r.ifa_index = ifc_idx;
|
||||
req.r.ifa_scope = 0;
|
||||
|
||||
/* create the remote address to communicate. */
|
||||
bzero(&pa, sizeof(pa));
|
||||
pa.nl_family = AF_NETLINK;
|
||||
|
||||
/* initialize & create the struct msghdr supplied to the sendmsg() function. */
|
||||
bzero(&msg, sizeof(msg));
|
||||
msg.msg_name = (void *) &pa;
|
||||
msg.msg_namelen = sizeof(pa);
|
||||
|
||||
/* place the pointer & size of the RTNETLINK message in the struct msghdr. */
|
||||
iov.iov_base = (void *) &req.n;
|
||||
iov.iov_len = req.n.nlmsg_len;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
/* send the RTNETLINK message to kernel. */
|
||||
sendmsg(fd, &msg, 0);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void interface_ip_update(void)
|
||||
{
|
||||
struct spdk_interface *ifc_entry;
|
||||
|
||||
pthread_mutex_lock(&interface_lock);
|
||||
TAILQ_FOREACH(ifc_entry, &g_interface_head, tailq) {
|
||||
ifc_entry->num_ip_addresses = 0;
|
||||
memset(ifc_entry->ip_address, 0, sizeof(ifc_entry->ip_address));
|
||||
}
|
||||
get_ifc_ipv4();
|
||||
pthread_mutex_unlock(&interface_lock);
|
||||
}
|
||||
|
||||
static int
|
||||
interface_is_ip_address_in_use(int ifc_index, uint32_t addr, bool add)
|
||||
{
|
||||
struct spdk_interface *ifc_entry;
|
||||
bool in_use = false;
|
||||
uint32_t idx = 0;
|
||||
|
||||
interface_ip_update();
|
||||
|
||||
pthread_mutex_lock(&interface_lock);
|
||||
ifc_entry = interface_find_by_index(ifc_index);
|
||||
if (ifc_entry == NULL) {
|
||||
pthread_mutex_unlock(&interface_lock);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
for (idx = 0; idx < ifc_entry->num_ip_addresses; idx++) {
|
||||
if (ifc_entry->ip_address[idx] == addr) {
|
||||
in_use = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&interface_lock);
|
||||
|
||||
/* The IP address to add is alerady in use */
|
||||
if (add == true && in_use == true) {
|
||||
return -EADDRINUSE;
|
||||
}
|
||||
|
||||
/* The IP address to delete is not in use */
|
||||
if (add == false && in_use == false) {
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_interface_init(void)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
rc = prepare_ifc_list();
|
||||
if (!rc) {
|
||||
rc = get_ifc_ipv4();
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_interface_destroy(void)
|
||||
{
|
||||
struct spdk_interface *ifc_entry;
|
||||
|
||||
while (!TAILQ_EMPTY(&g_interface_head)) {
|
||||
ifc_entry = TAILQ_FIRST(&g_interface_head);
|
||||
TAILQ_REMOVE(&g_interface_head, ifc_entry, tailq);
|
||||
free(ifc_entry);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
interface_net_interface_add_ip_address(int ifc_index, char *ip_addr)
|
||||
{
|
||||
uint32_t addr;
|
||||
int ret;
|
||||
|
||||
addr = inet_addr(ip_addr);
|
||||
|
||||
ret = interface_is_ip_address_in_use(ifc_index, addr, true);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return netlink_addr_msg(ifc_index, addr, 1);
|
||||
}
|
||||
|
||||
int
|
||||
interface_net_interface_delete_ip_address(int ifc_index, char *ip_addr)
|
||||
{
|
||||
uint32_t addr;
|
||||
int ret;
|
||||
|
||||
addr = inet_addr(ip_addr);
|
||||
|
||||
ret = interface_is_ip_address_in_use(ifc_index, addr, false);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return netlink_addr_msg(ifc_index, addr, 0);
|
||||
}
|
||||
|
||||
void *interface_get_list(void)
|
||||
{
|
||||
interface_ip_update();
|
||||
return &g_interface_head;
|
||||
}
|
||||
|
||||
#else /* Not Linux */
|
||||
|
||||
int
|
||||
spdk_interface_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_interface_destroy(void)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
interface_net_interface_add_ip_address(int ifc_index, char *ip_addr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
interface_net_interface_delete_ip_address(int ifc_index, char *ip_addr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *
|
||||
interface_get_list(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,79 +0,0 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef SPDK_NET_INTERNAL_H
|
||||
#define SPDK_NET_INTERNAL_H
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
|
||||
#include "spdk/queue.h"
|
||||
|
||||
#define SPDK_IFNAMSIZE 32
|
||||
#define SPDK_MAX_IP_PER_IFC 32
|
||||
|
||||
struct spdk_interface {
|
||||
char name[SPDK_IFNAMSIZE];
|
||||
uint32_t index;
|
||||
uint32_t num_ip_addresses; /* number of IP addresses defined */
|
||||
uint32_t ip_address[SPDK_MAX_IP_PER_IFC];
|
||||
TAILQ_ENTRY(spdk_interface) tailq;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an ip address to the network interface.
|
||||
*
|
||||
* \param ifc_index Index of the network interface.
|
||||
* \param ip_addr Ip address to add.
|
||||
*
|
||||
* \return 0 on success, -1 on failure.
|
||||
*/
|
||||
int interface_net_interface_add_ip_address(int ifc_index, char *ip_addr);
|
||||
|
||||
/**
|
||||
* Delete an ip address from the network interface.
|
||||
*
|
||||
* \param ifc_index Index of the network interface.
|
||||
* \param ip_addr Ip address to delete.
|
||||
*
|
||||
* \return 0 on success, -1 on failure.
|
||||
*/
|
||||
int interface_net_interface_delete_ip_address(int ifc_index, char *ip_addr);
|
||||
|
||||
/**
|
||||
* Get the list of all the network interfaces.
|
||||
*
|
||||
* \return a pointer to the head of the linked list of all the network interfaces.
|
||||
*/
|
||||
void *interface_get_list(void);
|
||||
|
||||
#endif /* SPDK_NET_INTERNAL_H */
|
@ -1,199 +0,0 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "net_internal.h"
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
|
||||
#include "spdk/rpc.h"
|
||||
#include "spdk/net.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
#include "spdk/log.h"
|
||||
|
||||
struct rpc_ip_address {
|
||||
int32_t ifc_index;
|
||||
char *ip_address;
|
||||
};
|
||||
|
||||
static void
|
||||
free_rpc_ip_address(struct rpc_ip_address *req)
|
||||
{
|
||||
free(req->ip_address);
|
||||
}
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_ip_address_decoders[] = {
|
||||
{"ifc_index", offsetof(struct rpc_ip_address, ifc_index), spdk_json_decode_int32},
|
||||
{"ip_address", offsetof(struct rpc_ip_address, ip_address), spdk_json_decode_string},
|
||||
};
|
||||
|
||||
static void
|
||||
rpc_net_interface_add_ip_address(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_ip_address req = {};
|
||||
int ret_val = 0;
|
||||
|
||||
SPDK_WARNLOG("net_interface_add_ip_address RPC is deprecated.\n");
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_ip_address_decoders,
|
||||
SPDK_COUNTOF(rpc_ip_address_decoders),
|
||||
&req)) {
|
||||
SPDK_DEBUGLOG(net, "spdk_json_decode_object failed\n");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"spdk_json_decode_object failed");
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
ret_val = interface_net_interface_add_ip_address(req.ifc_index, req.ip_address);
|
||||
if (ret_val) {
|
||||
if (ret_val == -ENODEV) {
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_STATE,
|
||||
"Interface %d not available", req.ifc_index);
|
||||
} else if (ret_val == -EADDRINUSE) {
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"IP address %s is already added to interface %d",
|
||||
req.ip_address, req.ifc_index);
|
||||
} else {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
strerror(ret_val));
|
||||
}
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
free_rpc_ip_address(&req);
|
||||
|
||||
spdk_jsonrpc_send_bool_response(request, true);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_ip_address(&req);
|
||||
}
|
||||
/* private */ SPDK_RPC_REGISTER("net_interface_add_ip_address", rpc_net_interface_add_ip_address,
|
||||
SPDK_RPC_RUNTIME)
|
||||
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(net_interface_add_ip_address, add_ip_address)
|
||||
|
||||
static void
|
||||
rpc_net_interface_delete_ip_address(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_ip_address req = {};
|
||||
int ret_val = 0;
|
||||
|
||||
SPDK_WARNLOG("net_interface_delete_ip_address RPC is deprecated.\n");
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_ip_address_decoders,
|
||||
SPDK_COUNTOF(rpc_ip_address_decoders),
|
||||
&req)) {
|
||||
SPDK_DEBUGLOG(net, "spdk_json_decode_object failed\n");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"spdk_json_decode_object failed");
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
ret_val = interface_net_interface_delete_ip_address(req.ifc_index, req.ip_address);
|
||||
if (ret_val) {
|
||||
if (ret_val == -ENODEV) {
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_STATE,
|
||||
"Interface %d not available", req.ifc_index);
|
||||
} else if (ret_val == -ENXIO) {
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"IP address %s is not found in interface %d",
|
||||
req.ip_address, req.ifc_index);
|
||||
} else {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
strerror(ret_val));
|
||||
}
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
free_rpc_ip_address(&req);
|
||||
|
||||
spdk_jsonrpc_send_bool_response(request, true);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_ip_address(&req);
|
||||
}
|
||||
/* private */ SPDK_RPC_REGISTER("net_interface_delete_ip_address",
|
||||
rpc_net_interface_delete_ip_address,
|
||||
SPDK_RPC_RUNTIME)
|
||||
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(net_interface_delete_ip_address, delete_ip_address)
|
||||
|
||||
static void
|
||||
rpc_net_get_interfaces(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
TAILQ_HEAD(, spdk_interface) *interface_head = interface_get_list();
|
||||
struct spdk_interface *ifc;
|
||||
char *ip_address;
|
||||
struct in_addr inaddr;
|
||||
uint32_t i;
|
||||
|
||||
SPDK_WARNLOG("net_get_interfaces RPC is deprecated.\n");
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"net_get_interfaces requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
TAILQ_FOREACH(ifc, interface_head, tailq) {
|
||||
spdk_json_write_object_begin(w);
|
||||
|
||||
spdk_json_write_named_string(w, "name", ifc->name);
|
||||
|
||||
spdk_json_write_named_int32(w, "ifc_index", ifc->index);
|
||||
|
||||
spdk_json_write_named_array_begin(w, "ip_addr");
|
||||
for (i = 0; i < ifc->num_ip_addresses; i++) {
|
||||
memcpy(&inaddr, &ifc->ip_address[i], sizeof(uint32_t));
|
||||
ip_address = inet_ntoa(inaddr);
|
||||
spdk_json_write_string(w, ip_address);
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_json_write_object_end(w);
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
/* private */ SPDK_RPC_REGISTER("net_get_interfaces", rpc_net_get_interfaces, SPDK_RPC_RUNTIME)
|
||||
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(net_get_interfaces, get_interfaces)
|
||||
|
||||
SPDK_LOG_REGISTER_COMPONENT(net)
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
global:
|
||||
|
||||
# public functions
|
||||
spdk_interface_init;
|
||||
spdk_interface_destroy;
|
||||
|
||||
local: *;
|
||||
};
|
@ -34,13 +34,6 @@
|
||||
spdk_sock_set_default_impl;
|
||||
spdk_sock_write_config_json;
|
||||
|
||||
# public functions in spdk/net.h
|
||||
spdk_net_framework_register;
|
||||
spdk_net_framework_start;
|
||||
spdk_net_framework_fini;
|
||||
spdk_net_framework_init_next;
|
||||
spdk_net_framework_fini_next;
|
||||
|
||||
# internal function in spdk_internal/sock.h
|
||||
spdk_net_impl_register;
|
||||
spdk_sock_map_insert;
|
||||
|
@ -161,7 +161,6 @@ endif
|
||||
# are not related to symbols, but are defined directly in
|
||||
# the SPDK event subsystem code.
|
||||
DEPDIRS-event_accel := init accel
|
||||
DEPDIRS-event_net := init net
|
||||
DEPDIRS-event_vmd := init vmd $(JSON_LIBS) log thread
|
||||
|
||||
DEPDIRS-event_bdev := init bdev event_accel event_vmd event_sock
|
||||
|
@ -34,7 +34,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
DIRS-y += bdev accel iscsi net nvmf scsi vmd sock
|
||||
DIRS-y += bdev accel iscsi nvmf scsi vmd sock
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
DIRS-y += nbd
|
||||
|
@ -1,45 +0,0 @@
|
||||
#
|
||||
# BSD LICENSE
|
||||
#
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
SO_VER := 3
|
||||
SO_MINOR := 0
|
||||
|
||||
C_SRCS = net.c
|
||||
LIBNAME = event_net
|
||||
|
||||
SPDK_MAP_FILE = $(SPDK_ROOT_DIR)/mk/spdk_blank.map
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
|
@ -1,63 +0,0 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
|
||||
#include "spdk/net.h"
|
||||
|
||||
#include "spdk_internal/init.h"
|
||||
|
||||
static void
|
||||
interface_subsystem_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = spdk_interface_init();
|
||||
|
||||
spdk_subsystem_init_next(rc);
|
||||
}
|
||||
|
||||
static void
|
||||
interface_subsystem_destroy(void)
|
||||
{
|
||||
spdk_interface_destroy();
|
||||
spdk_subsystem_fini_next();
|
||||
}
|
||||
|
||||
static struct spdk_subsystem g_spdk_subsystem_interface = {
|
||||
.name = "interface",
|
||||
.init = interface_subsystem_init,
|
||||
.fini = interface_subsystem_destroy,
|
||||
};
|
||||
|
||||
SPDK_SUBSYSTEM_REGISTER(g_spdk_subsystem_interface);
|
@ -1861,32 +1861,6 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
||||
p.add_argument('-n', '--nbd-device', help="Path of the nbd device. Example: /dev/nbd0", required=False)
|
||||
p.set_defaults(func=nbd_get_disks)
|
||||
|
||||
# net
|
||||
def net_interface_add_ip_address(args):
|
||||
rpc.net.net_interface_add_ip_address(args.client, ifc_index=args.ifc_index, ip_addr=args.ip_addr)
|
||||
|
||||
p = subparsers.add_parser('net_interface_add_ip_address', aliases=['add_ip_address'],
|
||||
help='Add IP address')
|
||||
p.add_argument('ifc_index', help='ifc index of the nic device.', type=int)
|
||||
p.add_argument('ip_addr', help='ip address will be added.')
|
||||
p.set_defaults(func=net_interface_add_ip_address)
|
||||
|
||||
def net_interface_delete_ip_address(args):
|
||||
rpc.net.net_interface_delete_ip_address(args.client, ifc_index=args.ifc_index, ip_addr=args.ip_addr)
|
||||
|
||||
p = subparsers.add_parser('net_interface_delete_ip_address', aliases=['delete_ip_address'],
|
||||
help='Delete IP address')
|
||||
p.add_argument('ifc_index', help='ifc index of the nic device.', type=int)
|
||||
p.add_argument('ip_addr', help='ip address will be deleted.')
|
||||
p.set_defaults(func=net_interface_delete_ip_address)
|
||||
|
||||
def net_get_interfaces(args):
|
||||
print_dict(rpc.net.net_get_interfaces(args.client))
|
||||
|
||||
p = subparsers.add_parser(
|
||||
'net_get_interfaces', aliases=['get_interfaces'], help='Display current interface list')
|
||||
p.set_defaults(func=net_get_interfaces)
|
||||
|
||||
# NVMe-oF
|
||||
def nvmf_set_max_subsystems(args):
|
||||
rpc.nvmf.nvmf_set_max_subsystems(args.client,
|
||||
|
@ -14,7 +14,6 @@ from . import iscsi
|
||||
from . import log
|
||||
from . import lvol
|
||||
from . import nbd
|
||||
from . import net
|
||||
from . import notify
|
||||
from . import nvme
|
||||
from . import nvmf
|
||||
|
@ -1,35 +0,0 @@
|
||||
from .helpers import deprecated_alias
|
||||
|
||||
|
||||
@deprecated_alias('add_ip_address')
|
||||
def net_interface_add_ip_address(client, ifc_index, ip_addr):
|
||||
"""Add IP address.
|
||||
|
||||
Args:
|
||||
ifc_index: ifc index of the nic device (int)
|
||||
ip_addr: ip address will be added
|
||||
"""
|
||||
params = {'ifc_index': ifc_index, 'ip_address': ip_addr}
|
||||
return client.call('net_interface_add_ip_address', params)
|
||||
|
||||
|
||||
@deprecated_alias('delete_ip_address')
|
||||
def net_interface_delete_ip_address(client, ifc_index, ip_addr):
|
||||
"""Delete IP address.
|
||||
|
||||
Args:
|
||||
ifc_index: ifc index of the nic device (int)
|
||||
ip_addr: ip address will be deleted
|
||||
"""
|
||||
params = {'ifc_index': ifc_index, 'ip_address': ip_addr}
|
||||
return client.call('net_interface_delete_ip_address', params)
|
||||
|
||||
|
||||
@deprecated_alias('get_interfaces')
|
||||
def net_get_interfaces(client):
|
||||
"""Display current interface list
|
||||
|
||||
Returns:
|
||||
List of current interface
|
||||
"""
|
||||
return client.call('net_get_interfaces')
|
@ -191,10 +191,6 @@ def verify_portal_groups_rpc_methods(rpc_py, rpc_param):
|
||||
"iscsi_get_portal_groups returned {} groups, expected empty".format(jsonvalues))
|
||||
|
||||
lo_ip = (target_ip, other_ip)
|
||||
nics = json.loads(rpc.net_get_interfaces())
|
||||
for x in nics:
|
||||
if x["ifc_index"] == 'lo':
|
||||
rpc.net_interface_add_ip_address(x["ifc_index"], lo_ip[1])
|
||||
for idx, value in enumerate(lo_ip):
|
||||
# The portal group tag must start at 1
|
||||
tag = idx + 1
|
||||
@ -231,10 +227,6 @@ def verify_portal_groups_rpc_methods(rpc_py, rpc_param):
|
||||
verify(jvalue['tag'] != value or jvalue['tag'] == tag_list[idx + jidx + 1], 1,
|
||||
"tag value is {}, expected {} and not {}".format(jvalue['tag'], tag_list[idx + jidx + 1], value))
|
||||
|
||||
for x in nics:
|
||||
if x["ifc_index"] == 'lo':
|
||||
rpc.net_interface_delete_ip_address(x["ifc_index"], lo_ip[1])
|
||||
|
||||
print("verify_portal_groups_rpc_methods passed")
|
||||
|
||||
|
||||
@ -398,17 +390,6 @@ def verify_target_nodes_rpc_methods(rpc_py, rpc_param):
|
||||
print("verify_target_nodes_rpc_methods passed.")
|
||||
|
||||
|
||||
def verify_net_get_interfaces(rpc_py):
|
||||
rpc = spdk_rpc(rpc_py)
|
||||
nics = json.loads(rpc.net_get_interfaces())
|
||||
nics_names = set(x["name"] for x in nics)
|
||||
# parse ip link show to verify the net_get_interfaces result
|
||||
ip_show = ns_cmd + " ip link show"
|
||||
ifcfg_nics = set(re.findall(r'\S+:\s(\S+?)(?:@\S+){0,1}:\s<.*', check_output(ip_show.split()).decode()))
|
||||
verify(nics_names == ifcfg_nics, 1, "net_get_interfaces returned {}".format(nics))
|
||||
print("verify_net_get_interfaces passed.")
|
||||
|
||||
|
||||
def help_get_interface_ip_list(rpc_py, nic_name):
|
||||
rpc = spdk_rpc(rpc_py)
|
||||
nics = json.loads(rpc.net_get_interfaces())
|
||||
@ -418,50 +399,12 @@ def help_get_interface_ip_list(rpc_py, nic_name):
|
||||
return nic[0]["ip_addr"]
|
||||
|
||||
|
||||
def verify_net_interface_add_delete_ip_address(rpc_py):
|
||||
rpc = spdk_rpc(rpc_py)
|
||||
nics = json.loads(rpc.net_get_interfaces())
|
||||
# add ip on up to first 2 nics
|
||||
for x in nics[:2]:
|
||||
faked_ip = "123.123.{}.{}".format(random.randint(1, 254), random.randint(1, 254))
|
||||
ping_cmd = ns_cmd + " ping -c 1 -W 1 " + faked_ip
|
||||
rpc.net_interface_add_ip_address(x["ifc_index"], faked_ip)
|
||||
verify(faked_ip in help_get_interface_ip_list(rpc_py, x["name"]), 1,
|
||||
"add ip {} to nic {} failed.".format(faked_ip, x["name"]))
|
||||
try:
|
||||
check_call(ping_cmd.split())
|
||||
except BaseException:
|
||||
verify(False, 1,
|
||||
"ping ip {} for {} was failed(adding was successful)".format
|
||||
(faked_ip, x["name"]))
|
||||
rpc.net_interface_delete_ip_address(x["ifc_index"], faked_ip)
|
||||
verify(faked_ip not in help_get_interface_ip_list(rpc_py, x["name"]), 1,
|
||||
"delete ip {} from nic {} failed.(adding and ping were successful)".format
|
||||
(faked_ip, x["name"]))
|
||||
# ping should be failed and throw an CalledProcessError exception
|
||||
try:
|
||||
check_call(ping_cmd.split())
|
||||
except CalledProcessError as _:
|
||||
pass
|
||||
except Exception as e:
|
||||
verify(False, 1,
|
||||
"Unexpected exception was caught {}(adding/ping/delete were successful)".format
|
||||
(str(e)))
|
||||
else:
|
||||
verify(False, 1,
|
||||
"ip {} for {} could be pinged after delete ip(adding/ping/delete were successful)".format
|
||||
(faked_ip, x["name"]))
|
||||
print("verify_net_interface_add_delete_ip_address passed.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
rpc_py = sys.argv[1]
|
||||
|
||||
try:
|
||||
verify_log_flag_rpc_methods(rpc_py, rpc_param)
|
||||
verify_net_get_interfaces(rpc_py)
|
||||
verify_net_interface_add_delete_ip_address(rpc_py)
|
||||
create_malloc_bdevs_rpc_methods(rpc_py, rpc_param)
|
||||
verify_portal_groups_rpc_methods(rpc_py, rpc_param)
|
||||
verify_initiator_groups_rpc_methods(rpc_py, rpc_param)
|
||||
|
Loading…
Reference in New Issue
Block a user