summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-09-08 19:52:02 +0200
committerFlorin Coras <florin.coras@gmail.com>2017-09-09 20:11:03 +0000
commit56dd5438b04b869065d8e901c315496bb6777455 (patch)
tree517190c53cfd2725d716eda6dddf9a64ad814084 /src/vnet
parent816122e303efb5012f6897bd53ff8fe28cd8fa1c (diff)
move unix_file_* code to vppinfra
This will allow us to use this code in client libraries without vlib. Change-Id: I8557b752496841ba588aa36b6082cbe2cd1867fe Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/devices/af_packet/af_packet.c12
-rw-r--r--src/vnet/devices/af_packet/af_packet.h2
-rw-r--r--src/vnet/devices/netmap/netmap.c14
-rw-r--r--src/vnet/devices/netmap/netmap.h2
-rw-r--r--src/vnet/devices/virtio/vhost-user.c62
-rw-r--r--src/vnet/devices/virtio/vhost-user.h2
-rw-r--r--src/vnet/ip/punt.c8
-rw-r--r--src/vnet/ip/punt.h2
-rw-r--r--src/vnet/unix/tapcli.c19
-rw-r--r--src/vnet/unix/tuntap.c10
10 files changed, 65 insertions, 68 deletions
diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c
index e7e6921421b..62bb228f04f 100644
--- a/src/vnet/devices/af_packet/af_packet.c
+++ b/src/vnet/devices/af_packet/af_packet.c
@@ -89,7 +89,7 @@ af_packet_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi,
}
static clib_error_t *
-af_packet_fd_read_ready (unix_file_t * uf)
+af_packet_fd_read_ready (clib_file_t * uf)
{
af_packet_main_t *apm = &af_packet_main;
vnet_main_t *vnm = vnet_get_main ();
@@ -281,12 +281,12 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
clib_spinlock_init (&apif->lockp);
{
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
template.read_function = af_packet_fd_read_ready;
template.file_descriptor = fd;
template.private_data = if_index;
template.flags = UNIX_FILE_EVENT_EDGE_TRIGGERED;
- apif->unix_file_index = unix_file_add (&unix_main, &template);
+ apif->clib_file_index = clib_file_add (&file_main, &template);
}
/*use configured or generate random MAC address */
@@ -371,10 +371,10 @@ af_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
vnet_hw_interface_unassign_rx_thread (vnm, apif->hw_if_index, 0);
/* clean up */
- if (apif->unix_file_index != ~0)
+ if (apif->clib_file_index != ~0)
{
- unix_file_del (&unix_main, unix_main.file_pool + apif->unix_file_index);
- apif->unix_file_index = ~0;
+ clib_file_del (&file_main, file_main.file_pool + apif->clib_file_index);
+ apif->clib_file_index = ~0;
}
else
close (apif->fd);
diff --git a/src/vnet/devices/af_packet/af_packet.h b/src/vnet/devices/af_packet/af_packet.h
index 194977f03c1..95c7e7cf5a7 100644
--- a/src/vnet/devices/af_packet/af_packet.h
+++ b/src/vnet/devices/af_packet/af_packet.h
@@ -32,7 +32,7 @@ typedef struct
u8 *tx_ring;
u32 hw_if_index;
u32 sw_if_index;
- u32 unix_file_index;
+ u32 clib_file_index;
u32 next_rx_frame;
u32 next_tx_frame;
diff --git a/src/vnet/devices/netmap/netmap.c b/src/vnet/devices/netmap/netmap.c
index 09afc7640ad..fc49ed629b8 100644
--- a/src/vnet/devices/netmap/netmap.c
+++ b/src/vnet/devices/netmap/netmap.c
@@ -36,7 +36,7 @@ netmap_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi,
}
static clib_error_t *
-netmap_fd_read_ready (unix_file_t * uf)
+netmap_fd_read_ready (clib_file_t * uf)
{
vlib_main_t *vm = vlib_get_main ();
netmap_main_t *nm = &netmap_main;
@@ -54,10 +54,10 @@ netmap_fd_read_ready (unix_file_t * uf)
static void
close_netmap_if (netmap_main_t * nm, netmap_if_t * nif)
{
- if (nif->unix_file_index != ~0)
+ if (nif->clib_file_index != ~0)
{
- unix_file_del (&unix_main, unix_main.file_pool + nif->unix_file_index);
- nif->unix_file_index = ~0;
+ clib_file_del (&file_main, file_main.file_pool + nif->clib_file_index);
+ nif->clib_file_index = ~0;
}
else if (nif->fd > -1)
close (nif->fd);
@@ -137,7 +137,7 @@ netmap_create_if (vlib_main_t * vm, u8 * if_name, u8 * hw_addr_set,
pool_get (nm->interfaces, nif);
nif->if_index = nif - nm->interfaces;
nif->fd = fd;
- nif->unix_file_index = ~0;
+ nif->clib_file_index = ~0;
vec_validate (req, 0);
nif->req = req;
@@ -188,11 +188,11 @@ netmap_create_if (vlib_main_t * vm, u8 * if_name, u8 * hw_addr_set,
clib_spinlock_init (&nif->lockp);
{
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
template.read_function = netmap_fd_read_ready;
template.file_descriptor = nif->fd;
template.private_data = nif->if_index;
- nif->unix_file_index = unix_file_add (&unix_main, &template);
+ nif->clib_file_index = clib_file_add (&file_main, &template);
}
/*use configured or generate random MAC address */
diff --git a/src/vnet/devices/netmap/netmap.h b/src/vnet/devices/netmap/netmap.h
index e04f045d6e2..047318909c9 100644
--- a/src/vnet/devices/netmap/netmap.h
+++ b/src/vnet/devices/netmap/netmap.h
@@ -50,7 +50,7 @@ typedef struct
uword if_index;
u32 hw_if_index;
u32 sw_if_index;
- u32 unix_file_index;
+ u32 clib_file_index;
u32 per_interface_next_index;
u8 is_admin_up;
diff --git a/src/vnet/devices/virtio/vhost-user.c b/src/vnet/devices/virtio/vhost-user.c
index 5fe378cb771..2af96ee7344 100644
--- a/src/vnet/devices/virtio/vhost-user.c
+++ b/src/vnet/devices/virtio/vhost-user.c
@@ -89,7 +89,7 @@
#define UNIX_GET_FD(unixfd_idx) \
(unixfd_idx != ~0) ? \
- pool_elt_at_index (unix_main.file_pool, \
+ pool_elt_at_index (file_main.file_pool, \
unixfd_idx)->file_descriptor : -1;
#define foreach_virtio_trace_flags \
@@ -477,7 +477,7 @@ vhost_user_set_interrupt_pending (vhost_user_intf_t * vui, u32 ifq)
}
static clib_error_t *
-vhost_user_callfd_read_ready (unix_file_t * uf)
+vhost_user_callfd_read_ready (clib_file_t * uf)
{
__attribute__ ((unused)) int n;
u8 buff[8];
@@ -488,7 +488,7 @@ vhost_user_callfd_read_ready (unix_file_t * uf)
}
static clib_error_t *
-vhost_user_kickfd_read_ready (unix_file_t * uf)
+vhost_user_kickfd_read_ready (clib_file_t * uf)
{
__attribute__ ((unused)) int n;
u8 buff[8];
@@ -569,16 +569,16 @@ vhost_user_vring_close (vhost_user_intf_t * vui, u32 qid)
vhost_user_vring_t *vring = &vui->vrings[qid];
if (vring->kickfd_idx != ~0)
{
- unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
+ clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
vring->kickfd_idx);
- unix_file_del (&unix_main, uf);
+ clib_file_del (&file_main, uf);
vring->kickfd_idx = ~0;
}
if (vring->callfd_idx != ~0)
{
- unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
+ clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
vring->callfd_idx);
- unix_file_del (&unix_main, uf);
+ clib_file_del (&file_main, uf);
vring->callfd_idx = ~0;
}
if (vring->errfd != -1)
@@ -597,10 +597,10 @@ vhost_user_if_disconnect (vhost_user_intf_t * vui)
vnet_hw_interface_set_flags (vnm, vui->hw_if_index, 0);
- if (vui->unix_file_index != ~0)
+ if (vui->clib_file_index != ~0)
{
- unix_file_del (&unix_main, unix_main.file_pool + vui->unix_file_index);
- vui->unix_file_index = ~0;
+ clib_file_del (&file_main, file_main.file_pool + vui->clib_file_index);
+ vui->clib_file_index = ~0;
}
vui->is_up = 0;
@@ -654,7 +654,7 @@ vhost_user_log_dirty_pages (vhost_user_intf_t * vui, u64 addr, u64 len)
}
static clib_error_t *
-vhost_user_socket_read (unix_file_t * uf)
+vhost_user_socket_read (clib_file_t * uf)
{
int n, i;
int fd, number_of_fds = 0;
@@ -666,7 +666,7 @@ vhost_user_socket_read (unix_file_t * uf)
vhost_user_intf_t *vui;
struct cmsghdr *cmsg;
u8 q;
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
vnet_main_t *vnm = vnet_get_main ();
vui = pool_elt_at_index (vum->vhost_user_interfaces, uf->private_data);
@@ -927,9 +927,9 @@ vhost_user_socket_read (unix_file_t * uf)
/* if there is old fd, delete and close it */
if (vui->vrings[q].callfd_idx != ~0)
{
- unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
+ clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
vui->vrings[q].callfd_idx);
- unix_file_del (&unix_main, uf);
+ clib_file_del (&file_main, uf);
vui->vrings[q].callfd_idx = ~0;
}
@@ -945,7 +945,7 @@ vhost_user_socket_read (unix_file_t * uf)
template.file_descriptor = fds[0];
template.private_data =
((vui - vhost_user_main.vhost_user_interfaces) << 8) + q;
- vui->vrings[q].callfd_idx = unix_file_add (&unix_main, &template);
+ vui->vrings[q].callfd_idx = clib_file_add (&file_main, &template);
}
else
vui->vrings[q].callfd_idx = ~0;
@@ -959,9 +959,9 @@ vhost_user_socket_read (unix_file_t * uf)
if (vui->vrings[q].kickfd_idx != ~0)
{
- unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
+ clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
vui->vrings[q].kickfd_idx);
- unix_file_del (&unix_main, uf);
+ clib_file_del (&file_main, uf);
vui->vrings[q].kickfd_idx = ~0;
}
@@ -978,7 +978,7 @@ vhost_user_socket_read (unix_file_t * uf)
template.private_data =
(((uword) (vui - vhost_user_main.vhost_user_interfaces)) << 8) +
q;
- vui->vrings[q].kickfd_idx = unix_file_add (&unix_main, &template);
+ vui->vrings[q].kickfd_idx = clib_file_add (&file_main, &template);
}
else
{
@@ -1168,7 +1168,7 @@ close_socket:
}
static clib_error_t *
-vhost_user_socket_error (unix_file_t * uf)
+vhost_user_socket_error (clib_file_t * uf)
{
vlib_main_t *vm = vlib_get_main ();
vhost_user_main_t *vum = &vhost_user_main;
@@ -1184,11 +1184,11 @@ vhost_user_socket_error (unix_file_t * uf)
}
static clib_error_t *
-vhost_user_socksvr_accept_ready (unix_file_t * uf)
+vhost_user_socksvr_accept_ready (clib_file_t * uf)
{
int client_fd, client_len;
struct sockaddr_un client;
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
vhost_user_main_t *vum = &vhost_user_main;
vhost_user_intf_t *vui;
@@ -1207,7 +1207,7 @@ vhost_user_socksvr_accept_ready (unix_file_t * uf)
template.error_function = vhost_user_socket_error;
template.file_descriptor = client_fd;
template.private_data = vui - vhost_user_main.vhost_user_interfaces;
- vui->unix_file_index = unix_file_add (&unix_main, &template);
+ vui->clib_file_index = clib_file_add (&file_main, &template);
return 0;
}
@@ -2475,7 +2475,7 @@ vhost_user_process (vlib_main_t * vm,
vhost_user_intf_t *vui;
struct sockaddr_un sun;
int sockfd;
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
f64 timeout = 3153600000.0 /* 100 years */ ;
uword *event_data = 0;
@@ -2496,7 +2496,7 @@ vhost_user_process (vlib_main_t * vm,
pool_foreach (vui, vum->vhost_user_interfaces, {
if (vui->unix_server_index == ~0) { //Nothing to do for server sockets
- if (vui->unix_file_index == ~0)
+ if (vui->clib_file_index == ~0)
{
if ((sockfd < 0) &&
((sockfd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0))
@@ -2534,7 +2534,7 @@ vhost_user_process (vlib_main_t * vm,
template.file_descriptor = sockfd;
template.private_data =
vui - vhost_user_main.vhost_user_interfaces;
- vui->unix_file_index = unix_file_add (&unix_main, &template);
+ vui->clib_file_index = clib_file_add (&file_main, &template);
/* This sockfd is considered consumed */
sockfd = -1;
@@ -2549,7 +2549,7 @@ vhost_user_process (vlib_main_t * vm,
/* check if socket is alive */
int error = 0;
socklen_t len = sizeof (error);
- int fd = UNIX_GET_FD(vui->unix_file_index);
+ int fd = UNIX_GET_FD(vui->clib_file_index);
int retval =
getsockopt (fd, SOL_SOCKET, SO_ERROR, &error, &len);
@@ -2596,9 +2596,9 @@ vhost_user_term_if (vhost_user_intf_t * vui)
if (vui->unix_server_index != ~0)
{
//Close server socket
- unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
+ clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
vui->unix_server_index);
- unix_file_del (&unix_main, uf);
+ clib_file_del (&file_main, uf);
vui->unix_server_index = ~0;
unlink (vui->sock_filename);
}
@@ -2780,11 +2780,11 @@ vhost_user_vui_init (vnet_main_t * vnm,
sw = vnet_get_hw_sw_interface (vnm, vui->hw_if_index);
if (server_sock_fd != -1)
{
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
template.read_function = vhost_user_socksvr_accept_ready;
template.file_descriptor = server_sock_fd;
template.private_data = vui - vum->vhost_user_interfaces; //hw index
- vui->unix_server_index = unix_file_add (&unix_main, &template);
+ vui->unix_server_index = clib_file_add (&file_main, &template);
}
else
{
@@ -2797,7 +2797,7 @@ vhost_user_vui_init (vnet_main_t * vnm,
vui->sock_errno = 0;
vui->is_up = 0;
vui->feature_mask = feature_mask;
- vui->unix_file_index = ~0;
+ vui->clib_file_index = ~0;
vui->log_base_addr = 0;
vui->if_index = vui - vum->vhost_user_interfaces;
mhash_set_mem (&vum->if_index_by_sock_name, vui->sock_filename,
diff --git a/src/vnet/devices/virtio/vhost-user.h b/src/vnet/devices/virtio/vhost-user.h
index ae3b88e8927..105b92b72ef 100644
--- a/src/vnet/devices/virtio/vhost-user.h
+++ b/src/vnet/devices/virtio/vhost-user.h
@@ -223,7 +223,7 @@ typedef struct
u32 is_up;
u32 admin_up;
u32 unix_server_index;
- u32 unix_file_index;
+ u32 clib_file_index;
char sock_filename[256];
int sock_errno;
uword if_index;
diff --git a/src/vnet/ip/punt.c b/src/vnet/ip/punt.c
index 67c54c3c5c1..1ea32fa0c78 100644
--- a/src/vnet/ip/punt.c
+++ b/src/vnet/ip/punt.c
@@ -550,7 +550,7 @@ VLIB_REGISTER_NODE (punt_socket_rx_node, static) =
format_punt_trace,};
static clib_error_t *
-punt_socket_read_ready (unix_file_t * uf)
+punt_socket_read_ready (clib_file_t * uf)
{
vlib_main_t *vm = vlib_get_main ();
punt_main_t *pm = &punt_main;
@@ -790,11 +790,11 @@ punt_config (vlib_main_t * vm, unformat_input_t * input)
}
/* Register socket */
- unix_main_t *um = &unix_main;
- unix_file_t template = { 0 };
+ clib_file_main_t *fm = &file_main;
+ clib_file_t template = { 0 };
template.read_function = punt_socket_read_ready;
template.file_descriptor = pm->socket_fd;
- pm->unix_file_index = unix_file_add (um, &template);
+ pm->clib_file_index = clib_file_add (fm, &template);
pm->is_configured = true;
diff --git a/src/vnet/ip/punt.h b/src/vnet/ip/punt.h
index 0103249cca0..9defa881782 100644
--- a/src/vnet/ip/punt.h
+++ b/src/vnet/ip/punt.h
@@ -72,7 +72,7 @@ typedef struct
char sun_path[sizeof (struct sockaddr_un)];
punt_client_t *clients_by_dst_port4;
punt_client_t *clients_by_dst_port6;
- u32 unix_file_index;
+ u32 clib_file_index;
bool is_configured;
vlib_node_t *interface_output_node;
u32 *ready_fds;
diff --git a/src/vnet/unix/tapcli.c b/src/vnet/unix/tapcli.c
index 0fc62f6c061..13154b3b034 100644
--- a/src/vnet/unix/tapcli.c
+++ b/src/vnet/unix/tapcli.c
@@ -56,7 +56,7 @@ static void tapcli_nopunt_frame (vlib_main_t * vm,
*/
typedef struct {
u32 unix_fd;
- u32 unix_file_index;
+ u32 clib_file_index;
u32 provision_fd;
/** For counters */
u32 sw_if_index;
@@ -137,8 +137,6 @@ typedef struct {
vlib_main_t * vlib_main;
/** convenience - vnet_main_t */
vnet_main_t * vnet_main;
- /** convenience - unix_main_t */
- unix_main_t * unix_main;
} tapcli_main_t;
static tapcli_main_t tapcli_main;
@@ -453,12 +451,12 @@ VLIB_REGISTER_NODE (tapcli_rx_node, static) = {
/**
* @brief Gets called when file descriptor is ready from epoll.
*
- * @param *uf - unix_file_t
+ * @param *uf - clib_file_t
*
* @return error - clib_error_t
*
*/
-static clib_error_t * tapcli_read_ready (unix_file_t * uf)
+static clib_error_t * tapcli_read_ready (clib_file_t * uf)
{
vlib_main_t * vm = vlib_get_main();
tapcli_main_t * tm = &tapcli_main;
@@ -999,10 +997,10 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
}
{
- unix_file_t template = {0};
+ clib_file_t template = {0};
template.read_function = tapcli_read_ready;
template.file_descriptor = dev_net_tun_fd;
- ti->unix_file_index = unix_file_add (&unix_main, &template);
+ ti->clib_file_index = clib_file_add (&file_main, &template);
ti->unix_fd = dev_net_tun_fd;
ti->provision_fd = dev_tap_fd;
clib_memcpy (&ti->ifr, &ifr, sizeof (ifr));
@@ -1079,9 +1077,9 @@ static int tapcli_tap_disconnect (tapcli_interface_t *ti)
// bring interface down
vnet_sw_interface_set_flags (vnm, sw_if_index, 0);
- if (ti->unix_file_index != ~0) {
- unix_file_del (&unix_main, unix_main.file_pool + ti->unix_file_index);
- ti->unix_file_index = ~0;
+ if (ti->clib_file_index != ~0) {
+ clib_file_del (&file_main, file_main.file_pool + ti->clib_file_index);
+ ti->clib_file_index = ~0;
}
else
close(ti->unix_fd);
@@ -1455,7 +1453,6 @@ tapcli_init (vlib_main_t * vm)
tm->vlib_main = vm;
tm->vnet_main = vnet_get_main();
- tm->unix_main = &unix_main;
tm->mtu_bytes = TAP_MTU_DEFAULT;
tm->tapcli_interface_index_by_sw_if_index = hash_create (0, sizeof(uword));
tm->tapcli_interface_index_by_unix_fd = hash_create (0, sizeof (uword));
diff --git a/src/vnet/unix/tuntap.c b/src/vnet/unix/tuntap.c
index 2c403679349..9616feb2d51 100644
--- a/src/vnet/unix/tuntap.c
+++ b/src/vnet/unix/tuntap.c
@@ -104,7 +104,7 @@ typedef struct {
mhash_t subif_mhash;
/** Unix file index */
- u32 unix_file_index;
+ u32 clib_file_index;
/** For the "normal" interface, if configured */
u32 hw_if_index, sw_if_index;
@@ -388,11 +388,11 @@ VLIB_REGISTER_NODE (tuntap_rx_node,static) = {
/**
* @brief Gets called when file descriptor is ready from epoll.
*
- * @param *uf - unix_file_t
+ * @param *uf - clib_file_t
*
* @return error - clib_error_t
*/
-static clib_error_t * tuntap_read_ready (unix_file_t * uf)
+static clib_error_t * tuntap_read_ready (clib_file_t * uf)
{
vlib_main_t * vm = vlib_get_main();
vlib_node_set_interrupt_pending (vm, tuntap_rx_node.index);
@@ -645,10 +645,10 @@ tuntap_config (vlib_main_t * vm, unformat_input_t * input)
}
{
- unix_file_t template = {0};
+ clib_file_t template = {0};
template.read_function = tuntap_read_ready;
template.file_descriptor = tm->dev_net_tun_fd;
- tm->unix_file_index = unix_file_add (&unix_main, &template);
+ tm->clib_file_index = clib_file_add (&file_main, &template);
}
done: