aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--src/plugins/memif/memif.c36
-rw-r--r--src/plugins/memif/private.h38
-rw-r--r--src/plugins/memif/socket.c56
-rw-r--r--src/vlib/linux/pci.c13
-rw-r--r--src/vlib/unix/cli.c85
-rw-r--r--src/vlib/unix/input.c13
-rw-r--r--src/vlib/unix/main.c1
-rw-r--r--src/vlib/unix/mc_socket.c69
-rw-r--r--src/vlib/unix/mc_socket.h2
-rw-r--r--src/vlib/unix/unix.h76
-rw-r--r--src/vlibapi/api_common.h2
-rw-r--r--src/vlibsocket/api.h12
-rw-r--r--src/vlibsocket/sockclnt_vlib.c12
-rw-r--r--src/vlibsocket/socksvr_vlib.c92
-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
-rw-r--r--src/vppinfra.am1
-rw-r--r--src/vppinfra/file.h134
26 files changed, 423 insertions, 352 deletions
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index 4c387b92f81..8fec409a16d 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -52,10 +52,10 @@ memif_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
static void
memif_queue_intfd_close (memif_queue_t * mq)
{
- if (mq->int_unix_file_index != ~0)
+ if (mq->int_clib_file_index != ~0)
{
- memif_file_del_by_index (mq->int_unix_file_index);
- mq->int_unix_file_index = ~0;
+ memif_file_del_by_index (mq->int_clib_file_index);
+ mq->int_clib_file_index = ~0;
mq->int_fd = -1;
}
else if (mq->int_fd > -1)
@@ -94,13 +94,13 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err)
vnet_hw_interface_set_flags (vnm, mif->hw_if_index, 0);
/* close connection socket */
- if (mif->conn_unix_file_index != ~0)
+ if (mif->conn_clib_file_index != ~0)
{
memif_socket_file_t *msf = vec_elt_at_index (mm->socket_files,
mif->socket_file_index);
hash_unset (msf->dev_instance_by_fd, mif->conn_fd);
- memif_file_del_by_index (mif->conn_unix_file_index);
- mif->conn_unix_file_index = ~0;
+ memif_file_del_by_index (mif->conn_clib_file_index);
+ mif->conn_clib_file_index = ~0;
}
else if (mif->conn_fd > -1)
close (mif->conn_fd);
@@ -145,7 +145,7 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err)
}
static clib_error_t *
-memif_int_fd_read_ready (unix_file_t * uf)
+memif_int_fd_read_ready (clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
vnet_main_t *vnm = vnet_get_main ();
@@ -173,7 +173,7 @@ clib_error_t *
memif_connect (memif_if_t * mif)
{
vnet_main_t *vnm = vnet_get_main ();
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
memif_region_t *mr;
int i;
@@ -219,7 +219,7 @@ memif_connect (memif_if_t * mif)
{
template.file_descriptor = mq->int_fd;
template.private_data = (mif->dev_instance << 16) | (i & 0xFFFF);
- memif_file_add (&mq->int_unix_file_index, &template);
+ memif_file_add (&mq->int_clib_file_index, &template);
}
vnet_hw_interface_assign_rx_thread (vnm, mif->hw_if_index, i, ~0);
rv = vnet_hw_interface_set_rx_mode (vnm, mif->hw_if_index, i,
@@ -330,7 +330,7 @@ memif_init_regions_and_queues (memif_if_t * mif)
memif_queue_t *mq = vec_elt_at_index (mif->tx_queues, i);
if ((mq->int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
return clib_error_return_unix (0, "eventfd[tx queue %u]", i);
- mq->int_unix_file_index = ~0;
+ mq->int_clib_file_index = ~0;
mq->ring = memif_get_ring (mif, MEMIF_RING_S2M, i);
mq->log2_ring_size = mif->cfg.log2_ring_size;
mq->region = 0;
@@ -346,7 +346,7 @@ memif_init_regions_and_queues (memif_if_t * mif)
memif_queue_t *mq = vec_elt_at_index (mif->rx_queues, i);
if ((mq->int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
return clib_error_return_unix (0, "eventfd[rx queue %u]", i);
- mq->int_unix_file_index = ~0;
+ mq->int_clib_file_index = ~0;
mq->ring = memif_get_ring (mif, MEMIF_RING_M2S, i);
mq->log2_ring_size = mif->cfg.log2_ring_size;
mq->region = 0;
@@ -432,7 +432,7 @@ memif_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
(sockfd, (struct sockaddr *) &sun,
sizeof (struct sockaddr_un)) == 0)
{
- unix_file_t t = { 0 };
+ clib_file_t t = { 0 };
mif->conn_fd = sockfd;
t.read_function = memif_slave_conn_fd_read_ready;
@@ -440,7 +440,7 @@ memif_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
t.error_function = memif_slave_conn_fd_error;
t.file_descriptor = mif->conn_fd;
t.private_data = mif->dev_instance;
- memif_file_add (&mif->conn_unix_file_index, &t);
+ memif_file_add (&mif->conn_clib_file_index, &t);
hash_set (msf->dev_instance_by_fd, mif->conn_fd, mif->dev_instance);
mif->flags |= MEMIF_IF_FLAG_CONNECTING;
@@ -507,7 +507,7 @@ memif_delete_if (vlib_main_t * vm, memif_if_t * mif)
if (msf->is_listener)
{
uword *x;
- memif_file_del_by_index (msf->unix_file_index);
+ memif_file_del_by_index (msf->clib_file_index);
vec_foreach (x, msf->pending_file_indices)
{
memif_file_del_by_index (*x);
@@ -639,7 +639,7 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
mif->socket_file_index = msf - mm->socket_files;
mif->id = args->id;
mif->sw_if_index = mif->hw_if_index = mif->per_interface_next_index = ~0;
- mif->conn_unix_file_index = ~0;
+ mif->conn_clib_file_index = ~0;
mif->conn_fd = -1;
mif->mode = args->mode;
if (args->secret)
@@ -737,12 +737,12 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
goto error;
}
- msf->unix_file_index = ~0;
- unix_file_t template = { 0 };
+ msf->clib_file_index = ~0;
+ clib_file_t template = { 0 };
template.read_function = memif_conn_fd_accept_ready;
template.file_descriptor = msf->fd;
template.private_data = mif->socket_file_index;
- memif_file_add (&msf->unix_file_index, &template);
+ memif_file_add (&msf->clib_file_index, &template);
}
msf->ref_cnt++;
diff --git a/src/plugins/memif/private.h b/src/plugins/memif/private.h
index b5f2f8ff55f..912ec59abd2 100644
--- a/src/plugins/memif/private.h
+++ b/src/plugins/memif/private.h
@@ -41,34 +41,34 @@
#if MEMIF_DEBUG == 1
#define memif_file_add(a, b) do { \
ASSERT (*a == ~0); \
- *a = unix_file_add (&unix_main, b); \
- clib_warning ("unix_file_add fd %d private_data %u idx %u", \
+ *a = clib_file_add (&file_main, b); \
+ clib_warning ("clib_file_add fd %d private_data %u idx %u", \
(b)->file_descriptor, (b)->private_data, *a); \
} while (0)
#define memif_file_del(a) do { \
- clib_warning ("unix_file_del idx %u",a - unix_main.file_pool); \
- unix_file_del (&unix_main, a); \
+ clib_warning ("clib_file_del idx %u",a - file_main.file_pool); \
+ clib_file_del (&file_main, a); \
} while (0)
#define memif_file_del_by_index(a) do { \
- clib_warning ("unix_file_del idx %u", a); \
- unix_file_del_by_index (&unix_main, a); \
+ clib_warning ("clib_file_del idx %u", a); \
+ clib_file_del_by_index (&file_main, a); \
} while (0)
#else
#define memif_file_add(a, b) do { \
ASSERT (*a == ~0); \
- *a = unix_file_add (&unix_main, b); \
+ *a = clib_file_add (&file_main, b); \
} while (0)
-#define memif_file_del(a) unix_file_del(&unix_main, a)
-#define memif_file_del_by_index(a) unix_file_del_by_index(&unix_main, a)
+#define memif_file_del(a) clib_file_del(&file_main, a)
+#define memif_file_del_by_index(a) clib_file_del_by_index(&file_main, a)
#endif
typedef struct
{
u8 *filename;
int fd;
- uword unix_file_index;
+ uword clib_file_index;
uword *pending_file_indices;
int ref_cnt;
int is_listener;
@@ -106,7 +106,7 @@ typedef struct
/* interrupts */
int int_fd;
- uword int_unix_file_index;
+ uword int_clib_file_index;
u64 int_count;
} memif_queue_t;
@@ -140,7 +140,7 @@ typedef struct
/* socket connection */
uword socket_file_index;
int conn_fd;
- uword conn_unix_file_index;
+ uword conn_clib_file_index;
memif_msg_fifo_elt_t *msg_queue;
u8 *secret;
@@ -241,13 +241,13 @@ clib_error_t *memif_connect (memif_if_t * mif);
void memif_disconnect (memif_if_t * mif, clib_error_t * err);
/* socket.c */
-clib_error_t *memif_conn_fd_accept_ready (unix_file_t * uf);
-clib_error_t *memif_master_conn_fd_read_ready (unix_file_t * uf);
-clib_error_t *memif_slave_conn_fd_read_ready (unix_file_t * uf);
-clib_error_t *memif_master_conn_fd_write_ready (unix_file_t * uf);
-clib_error_t *memif_slave_conn_fd_write_ready (unix_file_t * uf);
-clib_error_t *memif_master_conn_fd_error (unix_file_t * uf);
-clib_error_t *memif_slave_conn_fd_error (unix_file_t * uf);
+clib_error_t *memif_conn_fd_accept_ready (clib_file_t * uf);
+clib_error_t *memif_master_conn_fd_read_ready (clib_file_t * uf);
+clib_error_t *memif_slave_conn_fd_read_ready (clib_file_t * uf);
+clib_error_t *memif_master_conn_fd_write_ready (clib_file_t * uf);
+clib_error_t *memif_slave_conn_fd_write_ready (clib_file_t * uf);
+clib_error_t *memif_master_conn_fd_error (clib_file_t * uf);
+clib_error_t *memif_slave_conn_fd_error (clib_file_t * uf);
clib_error_t *memif_msg_send_disconnect (memif_if_t * mif,
clib_error_t * err);
u8 *format_memif_device_name (u8 * s, va_list * args);
diff --git a/src/plugins/memif/socket.c b/src/plugins/memif/socket.c
index 79ae07bef15..1abc0f119aa 100644
--- a/src/plugins/memif/socket.c
+++ b/src/plugins/memif/socket.c
@@ -246,7 +246,7 @@ memif_msg_receive_hello (memif_if_t * mif, memif_msg_t * msg)
static clib_error_t *
memif_msg_receive_init (memif_if_t ** mifp, memif_msg_t * msg,
- unix_file_t * uf)
+ clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
memif_socket_file_t *msf =
@@ -258,7 +258,7 @@ memif_msg_receive_init (memif_if_t ** mifp, memif_msg_t * msg,
if (i->version != MEMIF_VERSION)
{
- memif_file_del_by_index (uf - unix_main.file_pool);
+ memif_file_del_by_index (uf - file_main.file_pool);
return clib_error_return (0, "unsupported version");
}
@@ -291,7 +291,7 @@ memif_msg_receive_init (memif_if_t ** mifp, memif_msg_t * msg,
}
mif->conn_fd = uf->file_descriptor;
- mif->conn_unix_file_index = uf - unix_main.file_pool;
+ mif->conn_clib_file_index = uf - file_main.file_pool;
hash_set (msf->dev_instance_by_fd, mif->conn_fd, mif->dev_instance);
mif->remote_name = memif_str2vec (i->name, sizeof (i->name));
*mifp = mif;
@@ -316,7 +316,7 @@ memif_msg_receive_init (memif_if_t ** mifp, memif_msg_t * msg,
error:
tmp.conn_fd = uf->file_descriptor;
memif_msg_send_disconnect (&tmp, err);
- memif_file_del_by_index (uf - unix_main.file_pool);
+ memif_file_del_by_index (uf - file_main.file_pool);
return err;
}
@@ -377,7 +377,7 @@ memif_msg_receive_add_ring (memif_if_t * mif, memif_msg_t * msg, int fd)
}
mq->int_fd = fd;
- mq->int_unix_file_index = ~0;
+ mq->int_clib_file_index = ~0;
mq->log2_ring_size = ar->log2_ring_size;
mq->region = ar->region;
mq->offset = ar->offset;
@@ -422,7 +422,7 @@ memif_msg_receive_disconnect (memif_if_t * mif, memif_msg_t * msg)
}
static clib_error_t *
-memif_msg_receive (memif_if_t ** mifp, unix_file_t * uf)
+memif_msg_receive (memif_if_t ** mifp, clib_file_t * uf)
{
char ctl[CMSG_SPACE (sizeof (int)) +
CMSG_SPACE (sizeof (struct ucred))] = { 0 };
@@ -544,20 +544,21 @@ memif_msg_receive (memif_if_t ** mifp, unix_file_t * uf)
return err;
}
- if (clib_fifo_elts (mif->msg_queue) && mif->conn_unix_file_index != ~0)
- unix_file_set_data_available_to_write (mif->conn_unix_file_index, 1);
+ if (clib_fifo_elts (mif->msg_queue) && mif->conn_clib_file_index != ~0)
+ clib_file_set_data_available_to_write (&file_main,
+ mif->conn_clib_file_index, 1);
return 0;
}
clib_error_t *
-memif_master_conn_fd_read_ready (unix_file_t * uf)
+memif_master_conn_fd_read_ready (clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
memif_socket_file_t *msf =
pool_elt_at_index (mm->socket_files, uf->private_data);
uword *p;
memif_if_t *mif = 0;
- uword conn_unix_file_index = ~0;
+ uword conn_clib_file_index = ~0;
clib_error_t *err = 0;
p = hash_get (msf->dev_instance_by_fd, uf->file_descriptor);
@@ -570,13 +571,13 @@ memif_master_conn_fd_read_ready (unix_file_t * uf)
/* This is new connection, remove index from pending vector */
int i;
vec_foreach_index (i, msf->pending_file_indices)
- if (msf->pending_file_indices[i] == uf - unix_main.file_pool)
+ if (msf->pending_file_indices[i] == uf - file_main.file_pool)
{
- conn_unix_file_index = msf->pending_file_indices[i];
+ conn_clib_file_index = msf->pending_file_indices[i];
vec_del1 (msf->pending_file_indices, i);
break;
}
- ASSERT (conn_unix_file_index != ~0);
+ ASSERT (conn_clib_file_index != ~0);
}
err = memif_msg_receive (&mif, uf);
if (err)
@@ -588,7 +589,7 @@ memif_master_conn_fd_read_ready (unix_file_t * uf)
}
clib_error_t *
-memif_slave_conn_fd_read_ready (unix_file_t * uf)
+memif_slave_conn_fd_read_ready (clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
clib_error_t *err;
@@ -603,17 +604,18 @@ memif_slave_conn_fd_read_ready (unix_file_t * uf)
}
static clib_error_t *
-memif_conn_fd_write_ready (unix_file_t * uf, memif_if_t * mif)
+memif_conn_fd_write_ready (clib_file_t * uf, memif_if_t * mif)
{
memif_msg_fifo_elt_t *e;
clib_fifo_sub2 (mif->msg_queue, e);
- unix_file_set_data_available_to_write (mif->conn_unix_file_index, 0);
+ clib_file_set_data_available_to_write (&file_main,
+ mif->conn_clib_file_index, 0);
memif_msg_send (mif->conn_fd, &e->msg, e->fd);
return 0;
}
clib_error_t *
-memif_master_conn_fd_write_ready (unix_file_t * uf)
+memif_master_conn_fd_write_ready (clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
memif_socket_file_t *msf =
@@ -630,7 +632,7 @@ memif_master_conn_fd_write_ready (unix_file_t * uf)
}
clib_error_t *
-memif_slave_conn_fd_write_ready (unix_file_t * uf)
+memif_slave_conn_fd_write_ready (clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
memif_if_t *mif = vec_elt_at_index (mm->interfaces, uf->private_data);
@@ -638,7 +640,7 @@ memif_slave_conn_fd_write_ready (unix_file_t * uf)
}
clib_error_t *
-memif_slave_conn_fd_error (unix_file_t * uf)
+memif_slave_conn_fd_error (clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
memif_if_t *mif = vec_elt_at_index (mm->interfaces, uf->private_data);
@@ -652,7 +654,7 @@ memif_slave_conn_fd_error (unix_file_t * uf)
}
clib_error_t *
-memif_master_conn_fd_error (unix_file_t * uf)
+memif_master_conn_fd_error (clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
memif_socket_file_t *msf =
@@ -674,7 +676,7 @@ memif_master_conn_fd_error (unix_file_t * uf)
{
int i;
vec_foreach_index (i, msf->pending_file_indices)
- if (msf->pending_file_indices[i] == uf - unix_main.file_pool)
+ if (msf->pending_file_indices[i] == uf - file_main.file_pool)
{
vec_del1 (msf->pending_file_indices, i);
memif_file_del (uf);
@@ -689,7 +691,7 @@ memif_master_conn_fd_error (unix_file_t * uf)
clib_error_t *
-memif_conn_fd_accept_ready (unix_file_t * uf)
+memif_conn_fd_accept_ready (clib_file_t * uf)
{
memif_main_t *mm = &memif_main;
memif_socket_file_t *msf =
@@ -697,8 +699,8 @@ memif_conn_fd_accept_ready (unix_file_t * uf)
int addr_len;
struct sockaddr_un client;
int conn_fd;
- unix_file_t template = { 0 };
- uword unix_file_index = ~0;
+ clib_file_t template = { 0 };
+ uword clib_file_index = ~0;
clib_error_t *err;
@@ -715,16 +717,16 @@ memif_conn_fd_accept_ready (unix_file_t * uf)
template.file_descriptor = conn_fd;
template.private_data = uf->private_data;
- memif_file_add (&unix_file_index, &template);
+ memif_file_add (&clib_file_index, &template);
err = memif_msg_enq_hello (conn_fd);
if (err)
{
clib_error_report (err);
- memif_file_del_by_index (unix_file_index);
+ memif_file_del_by_index (clib_file_index);
}
else
- vec_add1 (msf->pending_file_indices, unix_file_index);
+ vec_add1 (msf->pending_file_indices, clib_file_index);
return 0;
}
diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c
index cd2affdc903..4ce19190531 100644
--- a/src/vlib/linux/pci.c
+++ b/src/vlib/linux/pci.c
@@ -68,8 +68,8 @@ typedef struct
/* Minor device for uio device. */
u32 uio_minor;
- /* Index given by unix_file_add. */
- u32 unix_file_index;
+ /* Index given by clib_file_add. */
+ u32 clib_file_index;
} linux_pci_device_t;
@@ -237,7 +237,7 @@ scan_uio_dir (void *arg, u8 * path_name, u8 * file_name)
}
static clib_error_t *
-linux_pci_uio_read_ready (unix_file_t * uf)
+linux_pci_uio_read_ready (clib_file_t * uf)
{
vlib_pci_main_t *pm = &pci_main;
vlib_pci_device_t *d;
@@ -257,7 +257,7 @@ linux_pci_uio_read_ready (unix_file_t * uf)
}
static clib_error_t *
-linux_pci_uio_error_ready (unix_file_t * uf)
+linux_pci_uio_error_ready (clib_file_t * uf)
{
u32 error_index = (u32) uf->private_data;
@@ -294,15 +294,14 @@ add_device (vlib_pci_device_t * dev, linux_pci_device_t * pdev)
}
{
- unix_file_t template = { 0 };
- unix_main_t *um = &unix_main;
+ clib_file_t template = { 0 };
template.read_function = linux_pci_uio_read_ready;
template.file_descriptor = l->uio_fd;
template.error_function = linux_pci_uio_error_ready;
template.private_data = dev - pm->pci_devs;
- l->unix_file_index = unix_file_add (um, &template);
+ l->clib_file_index = clib_file_add (&file_main, &template);
}
}
diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c
index 068a4e169dc..39368823b34 100644
--- a/src/vlib/unix/cli.c
+++ b/src/vlib/unix/cli.c
@@ -141,7 +141,7 @@ typedef struct
typedef struct
{
/** The file index held by unix.c */
- u32 unix_file_index;
+ u32 clib_file_index;
/** Vector of output pending write to file descriptor. */
u8 *output_vector;
@@ -502,11 +502,11 @@ unix_cli_match_action (unix_cli_parse_actions_t * a,
* are available to be sent.
*/
static void
-unix_cli_add_pending_output (unix_file_t * uf,
+unix_cli_add_pending_output (clib_file_t * uf,
unix_cli_file_t * cf,
u8 * buffer, uword buffer_bytes)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
vec_add (cf->output_vector, buffer, buffer_bytes);
if (vec_len (cf->output_vector) > 0)
@@ -514,7 +514,7 @@ unix_cli_add_pending_output (unix_file_t * uf,
int skip_update = 0 != (uf->flags & UNIX_FILE_DATA_AVAILABLE_TO_WRITE);
uf->flags |= UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
if (!skip_update)
- um->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
+ fm->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
}
}
@@ -522,10 +522,10 @@ unix_cli_add_pending_output (unix_file_t * uf,
* that no more bytes are available to be sent.
*/
static void
-unix_cli_del_pending_output (unix_file_t * uf,
+unix_cli_del_pending_output (clib_file_t * uf,
unix_cli_file_t * cf, uword n_bytes)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
vec_delete (cf->output_vector, n_bytes, 0);
if (vec_len (cf->output_vector) <= 0)
@@ -533,7 +533,7 @@ unix_cli_del_pending_output (unix_file_t * uf,
int skip_update = 0 == (uf->flags & UNIX_FILE_DATA_AVAILABLE_TO_WRITE);
uf->flags &= ~UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
if (!skip_update)
- um->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
+ fm->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
}
}
@@ -580,7 +580,7 @@ unix_vlib_findchr (u8 chr, u8 * str, word len)
*/
static void
unix_vlib_cli_output_raw (unix_cli_file_t * cf,
- unix_file_t * uf, u8 * buffer, uword buffer_bytes)
+ clib_file_t * uf, u8 * buffer, uword buffer_bytes)
{
int n = 0;
@@ -610,7 +610,7 @@ unix_vlib_cli_output_raw (unix_cli_file_t * cf,
*/
static void
unix_vlib_cli_output_cooked (unix_cli_file_t * cf,
- unix_file_t * uf,
+ clib_file_t * uf,
u8 * buffer, uword buffer_bytes)
{
word end = 0, start = 0;
@@ -646,7 +646,7 @@ unix_vlib_cli_output_cooked (unix_cli_file_t * cf,
/** @brief Output the CLI prompt */
static void
-unix_cli_cli_prompt (unix_cli_file_t * cf, unix_file_t * uf)
+unix_cli_cli_prompt (unix_cli_file_t * cf, clib_file_t * uf)
{
unix_cli_main_t *cm = &unix_cli_main;
@@ -655,7 +655,7 @@ unix_cli_cli_prompt (unix_cli_file_t * cf, unix_file_t * uf)
/** @brief Output a pager prompt and show number of buffered lines */
static void
-unix_cli_pager_prompt (unix_cli_file_t * cf, unix_file_t * uf)
+unix_cli_pager_prompt (unix_cli_file_t * cf, clib_file_t * uf)
{
u8 *prompt;
u32 h;
@@ -678,7 +678,7 @@ unix_cli_pager_prompt (unix_cli_file_t * cf, unix_file_t * uf)
/** @brief Output a pager "skipping" message */
static void
-unix_cli_pager_message (unix_cli_file_t * cf, unix_file_t * uf,
+unix_cli_pager_message (unix_cli_file_t * cf, clib_file_t * uf,
char *message, char *postfix)
{
u8 *prompt;
@@ -694,7 +694,7 @@ unix_cli_pager_message (unix_cli_file_t * cf, unix_file_t * uf,
/** @brief Erase the printed pager prompt */
static void
-unix_cli_pager_prompt_erase (unix_cli_file_t * cf, unix_file_t * uf)
+unix_cli_pager_prompt_erase (unix_cli_file_t * cf, clib_file_t * uf)
{
if (cf->ansi_capable)
{
@@ -716,7 +716,7 @@ unix_cli_pager_prompt_erase (unix_cli_file_t * cf, unix_file_t * uf)
/** @brief Uses an ANSI escape sequence to move the cursor */
static void
-unix_cli_ansi_cursor (unix_cli_file_t * cf, unix_file_t * uf, u16 x, u16 y)
+unix_cli_ansi_cursor (unix_cli_file_t * cf, clib_file_t * uf, u16 x, u16 y)
{
u8 *str;
@@ -732,7 +732,7 @@ unix_cli_ansi_cursor (unix_cli_file_t * cf, unix_file_t * uf, u16 x, u16 y)
* @param uf Unix file of the CLI session.
*/
static void
-unix_cli_pager_redraw (unix_cli_file_t * cf, unix_file_t * uf)
+unix_cli_pager_redraw (unix_cli_file_t * cf, clib_file_t * uf)
{
unix_cli_pager_index_t *pi = NULL;
u8 *line = NULL;
@@ -930,12 +930,13 @@ static void
unix_vlib_cli_output (uword cli_file_index, u8 * buffer, uword buffer_bytes)
{
unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
unix_cli_main_t *cm = &unix_cli_main;
unix_cli_file_t *cf;
- unix_file_t *uf;
+ clib_file_t *uf;
cf = pool_elt_at_index (cm->cli_file_pool, cli_file_index);
- uf = pool_elt_at_index (um->file_pool, cf->unix_file_index);
+ uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
if (cf->no_pager || um->cli_pager_buffer_limit == 0 || cf->height == 0)
{
@@ -1037,7 +1038,8 @@ static void
unix_cli_file_welcome (unix_cli_main_t * cm, unix_cli_file_t * cf)
{
unix_main_t *um = &unix_main;
- unix_file_t *uf = pool_elt_at_index (um->file_pool, cf->unix_file_index);
+ clib_file_main_t *fm = &file_main;
+ clib_file_t *uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
unix_cli_banner_t *banner;
int i, len;
@@ -1104,7 +1106,7 @@ unix_cli_file_welcome_timer (any arg, f64 delay)
static i32
unix_cli_process_telnet (unix_main_t * um,
unix_cli_file_t * cf,
- unix_file_t * uf, u8 * input_vector, uword len)
+ clib_file_t * uf, u8 * input_vector, uword len)
{
/* Input_vector starts at IAC byte.
* See if we have a complete message; if not, return -1 so we wait for more.
@@ -1229,7 +1231,7 @@ static int
unix_cli_line_process_one (unix_cli_main_t * cm,
unix_main_t * um,
unix_cli_file_t * cf,
- unix_file_t * uf,
+ clib_file_t * uf,
u8 input, unix_cli_parse_action_t action)
{
u8 *prev;
@@ -2059,10 +2061,10 @@ unix_cli_line_process_one (unix_cli_main_t * cm,
/** @brief Process input bytes on a stream to provide line editing and
* command history in the CLI. */
static int
-unix_cli_line_edit (unix_cli_main_t * cm,
- unix_main_t * um, unix_cli_file_t * cf)
+unix_cli_line_edit (unix_cli_main_t * cm, unix_main_t * um,
+ clib_file_main_t * fm, unix_cli_file_t * cf)
{
- unix_file_t *uf = pool_elt_at_index (um->file_pool, cf->unix_file_index);
+ clib_file_t *uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
int i;
for (i = 0; i < vec_len (cf->input_vector); i++)
@@ -2139,7 +2141,8 @@ static void
unix_cli_process_input (unix_cli_main_t * cm, uword cli_file_index)
{
unix_main_t *um = &unix_main;
- unix_file_t *uf;
+ clib_file_main_t *fm = &file_main;
+ clib_file_t *uf;
unix_cli_file_t *cf = pool_elt_at_index (cm->cli_file_pool, cli_file_index);
unformat_input_t input;
int vlib_parse_eval (u8 *);
@@ -2157,7 +2160,7 @@ more:
else
{
/* Line edit, echo, etc. */
- if (unix_cli_line_edit (cm, um, cf))
+ if (unix_cli_line_edit (cm, um, fm, cf))
/* want more input */
return;
}
@@ -2196,7 +2199,7 @@ more:
/* Re-fetch pointer since pool may have moved. */
cf = pool_elt_at_index (cm->cli_file_pool, cli_file_index);
- uf = pool_elt_at_index (um->file_pool, cf->unix_file_index);
+ uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
done:
/* reset vector; we'll re-use it later */
@@ -2240,12 +2243,13 @@ static void
unix_cli_kill (unix_cli_main_t * cm, uword cli_file_index)
{
unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
unix_cli_file_t *cf;
- unix_file_t *uf;
+ clib_file_t *uf;
int i;
cf = pool_elt_at_index (cm->cli_file_pool, cli_file_index);
- uf = pool_elt_at_index (um->file_pool, cf->unix_file_index);
+ uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
/* Quit/EOF on stdin means quit program. */
if (uf->file_descriptor == UNIX_CLI_STDIN_FD)
@@ -2259,7 +2263,7 @@ unix_cli_kill (unix_cli_main_t * cm, uword cli_file_index)
vec_free (cf->command_history);
- unix_file_del (um, uf);
+ clib_file_del (fm, uf);
unix_cli_file_free (cf);
pool_put (cm->cli_file_pool, cf);
@@ -2311,7 +2315,7 @@ done:
/** Called when a CLI session file descriptor can be written to without
* blocking. */
static clib_error_t *
-unix_cli_write_ready (unix_file_t * uf)
+unix_cli_write_ready (clib_file_t * uf)
{
unix_cli_main_t *cm = &unix_cli_main;
unix_cli_file_t *cf;
@@ -2334,7 +2338,7 @@ unix_cli_write_ready (unix_file_t * uf)
/** Called when a CLI session file descriptor has data to be read. */
static clib_error_t *
-unix_cli_read_ready (unix_file_t * uf)
+unix_cli_read_ready (clib_file_t * uf)
{
unix_main_t *um = &unix_main;
unix_cli_main_t *cm = &unix_cli_main;
@@ -2380,8 +2384,9 @@ static u32
unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd)
{
unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
unix_cli_file_t *cf;
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
vlib_main_t *vm = um->vlib_main;
vlib_node_t *n;
@@ -2424,7 +2429,7 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd)
template.private_data = cf - cm->cli_file_pool;
cf->process_node_index = n->index;
- cf->unix_file_index = unix_file_add (um, &template);
+ cf->clib_file_index = clib_file_add (fm, &template);
cf->output_vector = 0;
cf->input_vector = 0;
@@ -2439,9 +2444,10 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd)
/** Telnet listening socket has a new connection. */
static clib_error_t *
-unix_cli_listen_read_ready (unix_file_t * uf)
+unix_cli_listen_read_ready (clib_file_t * uf)
{
unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
unix_cli_main_t *cm = &unix_cli_main;
clib_socket_t *s = &um->cli_listen_socket;
clib_socket_t client;
@@ -2497,7 +2503,7 @@ unix_cli_listen_read_ready (unix_file_t * uf)
/* Setup the pager */
cf->no_pager = um->cli_no_pager;
- uf = pool_elt_at_index (um->file_pool, cf->unix_file_index);
+ uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
/* Send the telnet options */
unix_vlib_cli_output_raw (cf, uf, charmode_option,
@@ -2517,11 +2523,11 @@ unix_cli_listen_read_ready (unix_file_t * uf)
static void
unix_cli_resize_interrupt (int signum)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
unix_cli_main_t *cm = &unix_cli_main;
unix_cli_file_t *cf = pool_elt_at_index (cm->cli_file_pool,
cm->stdin_cli_file_index);
- unix_file_t *uf = pool_elt_at_index (um->file_pool, cf->unix_file_index);
+ clib_file_t *uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
struct winsize ws;
(void) signum;
@@ -2548,6 +2554,7 @@ static clib_error_t *
unix_cli_config (vlib_main_t * vm, unformat_input_t * input)
{
unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
unix_cli_main_t *cm = &unix_cli_main;
int flags;
clib_error_t *error = 0;
@@ -2640,7 +2647,7 @@ unix_cli_config (vlib_main_t * vm, unformat_input_t * input)
if (s->config && s->config[0] != 0)
{
/* CLI listen. */
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
/* mkdir of file socketu, only under /run */
if (strncmp (s->config, "/run", 4) == 0)
@@ -2667,7 +2674,7 @@ unix_cli_config (vlib_main_t * vm, unformat_input_t * input)
template.read_function = unix_cli_listen_read_ready;
template.file_descriptor = s->fd;
- unix_file_add (um, &template);
+ clib_file_add (fm, &template);
}
/* Set CLI prompt. */
diff --git a/src/vlib/unix/input.c b/src/vlib/unix/input.c
index 515dae94811..ecd317913e9 100644
--- a/src/vlib/unix/input.c
+++ b/src/vlib/unix/input.c
@@ -62,9 +62,9 @@ typedef struct
static linux_epoll_main_t linux_epoll_main;
static void
-linux_epoll_file_update (unix_file_t * f, unix_file_update_type_t update_type)
+linux_epoll_file_update (clib_file_t * f, unix_file_update_type_t update_type)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
linux_epoll_main_t *em = &linux_epoll_main;
struct epoll_event e;
int op;
@@ -76,7 +76,7 @@ linux_epoll_file_update (unix_file_t * f, unix_file_update_type_t update_type)
e.events |= EPOLLOUT;
if (f->flags & UNIX_FILE_EVENT_EDGE_TRIGGERED)
e.events |= EPOLLET;
- e.data.u32 = f - um->file_pool;
+ e.data.u32 = f - fm->file_pool;
op = -1;
@@ -108,6 +108,7 @@ linux_epoll_input (vlib_main_t * vm,
vlib_node_runtime_t * node, vlib_frame_t * frame)
{
unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
linux_epoll_main_t *em = &linux_epoll_main;
struct epoll_event *e;
int n_fds_ready;
@@ -186,7 +187,7 @@ linux_epoll_input (vlib_main_t * vm,
for (e = em->epoll_events; e < em->epoll_events + n_fds_ready; e++)
{
u32 i = e->data.u32;
- unix_file_t *f = pool_elt_at_index (um->file_pool, i);
+ clib_file_t *f = pool_elt_at_index (fm->file_pool, i);
clib_error_t *errors[4];
int n_errors = 0;
@@ -236,7 +237,7 @@ clib_error_t *
linux_epoll_input_init (vlib_main_t * vm)
{
linux_epoll_main_t *em = &linux_epoll_main;
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
/* Allocate some events. */
vec_resize (em->epoll_events, VLIB_FRAME_SIZE);
@@ -245,7 +246,7 @@ linux_epoll_input_init (vlib_main_t * vm)
if (em->epoll_fd < 0)
return clib_error_return_unix (0, "epoll_create");
- um->file_update = linux_epoll_file_update;
+ fm->file_update = linux_epoll_file_update;
return 0;
}
diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c
index 3a92b2e3d12..ed0631ec871 100644
--- a/src/vlib/unix/main.c
+++ b/src/vlib/unix/main.c
@@ -60,6 +60,7 @@ char *vlib_default_runtime_dir __attribute__ ((weak));
char *vlib_default_runtime_dir = "vlib";
unix_main_t unix_main;
+clib_file_main_t file_main;
static clib_error_t *
unix_main_init (vlib_main_t * vm)
diff --git a/src/vlib/unix/mc_socket.c b/src/vlib/unix/mc_socket.c
index 9c12ad3b559..3f1cd99d382 100644
--- a/src/vlib/unix/mc_socket.c
+++ b/src/vlib/unix/mc_socket.c
@@ -243,7 +243,7 @@ recvmsg_helper (mc_socket_main_t * msm,
}
static clib_error_t *
-mastership_socket_read_ready (unix_file_t * uf)
+mastership_socket_read_ready (clib_file_t * uf)
{
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
mc_main_t *mcm = &msm->mc_main;
@@ -263,7 +263,7 @@ mastership_socket_read_ready (unix_file_t * uf)
}
static clib_error_t *
-to_relay_socket_read_ready (unix_file_t * uf)
+to_relay_socket_read_ready (clib_file_t * uf)
{
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
mc_main_t *mcm = &msm->mc_main;
@@ -297,7 +297,7 @@ to_relay_socket_read_ready (unix_file_t * uf)
}
static clib_error_t *
-from_relay_socket_read_ready (unix_file_t * uf)
+from_relay_socket_read_ready (clib_file_t * uf)
{
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
mc_main_t *mcm = &msm->mc_main;
@@ -317,7 +317,7 @@ from_relay_socket_read_ready (unix_file_t * uf)
}
static clib_error_t *
-join_socket_read_ready (unix_file_t * uf)
+join_socket_read_ready (clib_file_t * uf)
{
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
mc_main_t *mcm = &msm->mc_main;
@@ -354,7 +354,7 @@ join_socket_read_ready (unix_file_t * uf)
}
static clib_error_t *
-ack_socket_read_ready (unix_file_t * uf)
+ack_socket_read_ready (clib_file_t * uf)
{
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
mc_main_t *mcm = &msm->mc_main;
@@ -371,10 +371,11 @@ ack_socket_read_ready (unix_file_t * uf)
static void
catchup_cleanup (mc_socket_main_t * msm,
- mc_socket_catchup_t * c, unix_main_t * um, unix_file_t * uf)
+ mc_socket_catchup_t * c, clib_file_main_t * um,
+ clib_file_t * uf)
{
hash_unset (msm->catchup_index_by_file_descriptor, uf->file_descriptor);
- unix_file_del (um, uf);
+ clib_file_del (um, uf);
vec_free (c->input_vector);
vec_free (c->output_vector);
pool_put (msm->catchups, c);
@@ -390,9 +391,9 @@ find_catchup_from_file_descriptor (mc_socket_main_t * msm,
}
static clib_error_t *
-catchup_socket_read_ready (unix_file_t * uf, int is_server)
+catchup_socket_read_ready (clib_file_t * uf, int is_server)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *um = &file_main;
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
mc_main_t *mcm = &msm->mc_main;
mc_socket_catchup_t *c =
@@ -440,13 +441,13 @@ catchup_socket_read_ready (unix_file_t * uf, int is_server)
}
static clib_error_t *
-catchup_server_read_ready (unix_file_t * uf)
+catchup_server_read_ready (clib_file_t * uf)
{
return catchup_socket_read_ready (uf, /* is_server */ 1);
}
static clib_error_t *
-catchup_client_read_ready (unix_file_t * uf)
+catchup_client_read_ready (clib_file_t * uf)
{
if (MC_EVENT_LOGGING)
{
@@ -460,9 +461,9 @@ catchup_client_read_ready (unix_file_t * uf)
}
static clib_error_t *
-catchup_socket_write_ready (unix_file_t * uf, int is_server)
+catchup_socket_write_ready (clib_file_t * uf, int is_server)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *um = &file_main;
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
mc_socket_catchup_t *c =
find_catchup_from_file_descriptor (msm, uf->file_descriptor);
@@ -522,7 +523,7 @@ catchup_socket_write_ready (unix_file_t * uf, int is_server)
if (!is_server)
{
uf->flags &= ~UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
- unix_main.file_update (uf, UNIX_FILE_UPDATE_MODIFY);
+ file_main.file_update (uf, UNIX_FILE_UPDATE_MODIFY);
/* Send EOF to other side. */
shutdown (uf->file_descriptor, SHUT_WR);
return error;
@@ -537,21 +538,21 @@ catchup_socket_write_ready (unix_file_t * uf, int is_server)
}
static clib_error_t *
-catchup_server_write_ready (unix_file_t * uf)
+catchup_server_write_ready (clib_file_t * uf)
{
return catchup_socket_write_ready (uf, /* is_server */ 1);
}
static clib_error_t *
-catchup_client_write_ready (unix_file_t * uf)
+catchup_client_write_ready (clib_file_t * uf)
{
return catchup_socket_write_ready (uf, /* is_server */ 0);
}
static clib_error_t *
-catchup_socket_error_ready (unix_file_t * uf)
+catchup_socket_error_ready (clib_file_t * uf)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *um = &file_main;
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
mc_socket_catchup_t *c =
find_catchup_from_file_descriptor (msm, uf->file_descriptor);
@@ -560,13 +561,13 @@ catchup_socket_error_ready (unix_file_t * uf)
}
static clib_error_t *
-catchup_listen_read_ready (unix_file_t * uf)
+catchup_listen_read_ready (clib_file_t * uf)
{
mc_socket_main_t *msm = (mc_socket_main_t *) uf->private_data;
struct sockaddr_in client_addr;
int client_len;
mc_socket_catchup_t *c;
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
pool_get (msm->catchups, c);
memset (c, 0, sizeof (c[0]));
@@ -616,7 +617,7 @@ catchup_listen_read_ready (unix_file_t * uf)
template.error_function = catchup_socket_error_ready;
template.file_descriptor = c->socket;
template.private_data = pointer_to_uword (msm);
- c->unix_file_index = unix_file_add (&unix_main, &template);
+ c->clib_file_index = clib_file_add (&file_main, &template);
hash_set (msm->catchup_index_by_file_descriptor, c->socket,
c - msm->catchups);
@@ -772,45 +773,45 @@ socket_setup (mc_socket_main_t * msm)
/* epoll setup for multicast mastership socket */
{
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
template.read_function = mastership_socket_read_ready;
template.file_descriptor =
msm->multicast_sockets[MC_TRANSPORT_MASTERSHIP].socket;
template.private_data = (uword) msm;
- unix_file_add (&unix_main, &template);
+ clib_file_add (&file_main, &template);
/* epoll setup for multicast to_relay socket */
template.read_function = to_relay_socket_read_ready;
template.file_descriptor =
msm->multicast_sockets[MC_TRANSPORT_USER_REQUEST_TO_RELAY].socket;
template.private_data = (uword) msm;
- unix_file_add (&unix_main, &template);
+ clib_file_add (&file_main, &template);
/* epoll setup for multicast from_relay socket */
template.read_function = from_relay_socket_read_ready;
template.file_descriptor =
msm->multicast_sockets[MC_TRANSPORT_USER_REQUEST_FROM_RELAY].socket;
template.private_data = (uword) msm;
- unix_file_add (&unix_main, &template);
+ clib_file_add (&file_main, &template);
template.read_function = join_socket_read_ready;
template.file_descriptor =
msm->multicast_sockets[MC_TRANSPORT_JOIN].socket;
template.private_data = (uword) msm;
- unix_file_add (&unix_main, &template);
+ clib_file_add (&file_main, &template);
/* epoll setup for ack rx socket */
template.read_function = ack_socket_read_ready;
template.file_descriptor = msm->ack_socket;
template.private_data = (uword) msm;
- unix_file_add (&unix_main, &template);
+ clib_file_add (&file_main, &template);
/* epoll setup for TCP catchup server */
template.read_function = catchup_listen_read_ready;
template.file_descriptor = msm->catchup_server_socket;
template.private_data = (uword) msm;
- unix_file_add (&unix_main, &template);
+ clib_file_add (&file_main, &template);
}
return 0;
@@ -820,8 +821,8 @@ static void *
catchup_add_pending_output (mc_socket_catchup_t * c, uword n_bytes,
u8 * set_output_vector)
{
- unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
- c->unix_file_index);
+ clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
+ c->clib_file_index);
u8 *result = 0;
if (set_output_vector)
@@ -833,7 +834,7 @@ catchup_add_pending_output (mc_socket_catchup_t * c, uword n_bytes,
int skip_update = 0 != (uf->flags & UNIX_FILE_DATA_AVAILABLE_TO_WRITE);
uf->flags |= UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
if (!skip_update)
- unix_main.file_update (uf, UNIX_FILE_UPDATE_MODIFY);
+ file_main.file_update (uf, UNIX_FILE_UPDATE_MODIFY);
}
return result;
}
@@ -847,7 +848,7 @@ catchup_request_fun (void *transport_main,
vlib_main_t *vm = mcm->vlib_main;
mc_socket_catchup_t *c;
struct sockaddr_in addr;
- unix_main_t *um = &unix_main;
+ clib_file_main_t *um = &file_main;
int one = 1;
pool_get (msm->catchups, c);
@@ -895,14 +896,14 @@ catchup_request_fun (void *transport_main,
}
{
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
template.read_function = catchup_client_read_ready;
template.write_function = catchup_client_write_ready;
template.error_function = catchup_socket_error_ready;
template.file_descriptor = c->socket;
template.private_data = (uword) msm;
- c->unix_file_index = unix_file_add (um, &template);
+ c->clib_file_index = clib_file_add (um, &template);
hash_set (msm->catchup_index_by_file_descriptor, c->socket,
c - msm->catchups);
diff --git a/src/vlib/unix/mc_socket.h b/src/vlib/unix/mc_socket.h
index 273c9ad430b..3686c824a2d 100644
--- a/src/vlib/unix/mc_socket.h
+++ b/src/vlib/unix/mc_socket.h
@@ -31,7 +31,7 @@ typedef struct
typedef struct
{
int socket;
- u32 unix_file_index;
+ u32 clib_file_index;
u8 *input_vector;
u8 *output_vector;
diff --git a/src/vlib/unix/unix.h b/src/vlib/unix/unix.h
index 1b0d8b9d384..4c8566b7ee8 100644
--- a/src/vlib/unix/unix.h
+++ b/src/vlib/unix/unix.h
@@ -40,42 +40,16 @@
#ifndef included_unix_unix_h
#define included_unix_unix_h
+#include <vppinfra/file.h>
#include <vppinfra/socket.h>
#include <termios.h>
-
-struct unix_file;
-typedef clib_error_t *(unix_file_function_t) (struct unix_file * f);
-
-typedef struct unix_file
-{
- /* Unix file descriptor from open/socket. */
- u32 file_descriptor;
-
- u32 flags;
-#define UNIX_FILE_DATA_AVAILABLE_TO_WRITE (1 << 0)
-#define UNIX_FILE_EVENT_EDGE_TRIGGERED (1 << 1)
-
- /* Data available for function's use. */
- uword private_data;
-
- /* Functions to be called when read/write data becomes ready. */
- unix_file_function_t *read_function, *write_function, *error_function;
-} unix_file_t;
-
typedef struct
{
f64 time;
clib_error_t *error;
} unix_error_history_t;
-typedef enum
-{
- UNIX_FILE_UPDATE_ADD,
- UNIX_FILE_UPDATE_MODIFY,
- UNIX_FILE_UPDATE_DELETE,
-} unix_file_update_type_t;
-
typedef struct
{
/* Back pointer to main structure. */
@@ -86,15 +60,9 @@ typedef struct
#define UNIX_FLAG_INTERACTIVE (1 << 0)
#define UNIX_FLAG_NODAEMON (1 << 1)
- /* Pool of files to poll for input/output. */
- unix_file_t *file_pool;
-
/* CLI listen socket. */
clib_socket_t cli_listen_socket;
- void (*file_update) (unix_file_t * file,
- unix_file_update_type_t update_type);
-
/* Circular buffer of last unix errors. */
unix_error_history_t error_history[128];
u32 error_history_index;
@@ -138,47 +106,7 @@ typedef struct
/* Global main structure. */
extern unix_main_t unix_main;
-
-always_inline uword
-unix_file_add (unix_main_t * um, unix_file_t * template)
-{
- unix_file_t *f;
- pool_get (um->file_pool, f);
- f[0] = template[0];
- um->file_update (f, UNIX_FILE_UPDATE_ADD);
- return f - um->file_pool;
-}
-
-always_inline void
-unix_file_del (unix_main_t * um, unix_file_t * f)
-{
- um->file_update (f, UNIX_FILE_UPDATE_DELETE);
- close (f->file_descriptor);
- f->file_descriptor = ~0;
- pool_put (um->file_pool, f);
-}
-
-always_inline void
-unix_file_del_by_index (unix_main_t * um, uword index)
-{
- unix_file_t *uf;
- uf = pool_elt_at_index (um->file_pool, index);
- unix_file_del (um, uf);
-}
-
-always_inline uword
-unix_file_set_data_available_to_write (u32 unix_file_index,
- uword is_available)
-{
- unix_file_t *uf = pool_elt_at_index (unix_main.file_pool, unix_file_index);
- uword was_available = (uf->flags & UNIX_FILE_DATA_AVAILABLE_TO_WRITE);
- if ((was_available != 0) != (is_available != 0))
- {
- uf->flags ^= UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
- unix_main.file_update (uf, UNIX_FILE_UPDATE_MODIFY);
- }
- return was_available != 0;
-}
+extern clib_file_main_t file_main;
always_inline void
unix_save_error (unix_main_t * um, clib_error_t * error)
diff --git a/src/vlibapi/api_common.h b/src/vlibapi/api_common.h
index b84d269e80c..651566aea29 100644
--- a/src/vlibapi/api_common.h
+++ b/src/vlibapi/api_common.h
@@ -51,7 +51,7 @@ typedef struct vl_api_registration_
unix_shared_memory_queue_t *vl_input_queue;
/* socket server and client */
- u32 unix_file_index;
+ u32 clib_file_index;
i8 *unprocessed_input;
u32 unprocessed_msg_length;
u8 *output_vector;
diff --git a/src/vlibsocket/api.h b/src/vlibsocket/api.h
index 79c0d08a682..d7b7055d596 100644
--- a/src/vlibsocket/api.h
+++ b/src/vlibsocket/api.h
@@ -41,27 +41,27 @@ typedef struct
* or to a shared-memory connection.
*/
vl_api_registration_t *current_rp;
- unix_file_t *current_uf;
+ clib_file_t *current_uf;
/* One input buffer, shared across all sockets */
i8 *input_buffer;
} socket_main_t;
extern socket_main_t socket_main;
-void socksvr_add_pending_output (struct unix_file *uf,
+void socksvr_add_pending_output (clib_file_t * uf,
struct vl_api_registration_ *cf,
u8 * buffer, uword buffer_bytes);
#define SOCKSVR_DEFAULT_PORT 32741 /* whatever */
void vl_free_socket_registration_index (u32 pool_index);
-void vl_socket_process_msg (struct unix_file *uf,
+void vl_socket_process_msg (clib_file_t * uf,
struct vl_api_registration_ *rp, i8 * input_v);
-clib_error_t *vl_socket_read_ready (struct unix_file *uf);
-void vl_socket_add_pending_output (struct unix_file *uf,
+clib_error_t *vl_socket_read_ready (clib_file_t * uf);
+void vl_socket_add_pending_output (clib_file_t * uf,
struct vl_api_registration_ *rp,
u8 * buffer, uword buffer_bytes);
-clib_error_t *vl_socket_write_ready (struct unix_file *uf);
+clib_error_t *vl_socket_write_ready (clib_file_t * uf);
void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem);
void vl_socket_api_send_with_data (vl_api_registration_t * rp,
u8 * elem, u8 * data_vector);
diff --git a/src/vlibsocket/sockclnt_vlib.c b/src/vlibsocket/sockclnt_vlib.c
index e16adfeb503..760ad9445ca 100644
--- a/src/vlibsocket/sockclnt_vlib.c
+++ b/src/vlibsocket/sockclnt_vlib.c
@@ -60,11 +60,11 @@ vl_api_sockclnt_create_reply_t_handler (vl_api_sockclnt_create_reply_t * mp)
static void
vl_api_sockclnt_delete_reply_t_handler (vl_api_sockclnt_delete_reply_t * mp)
{
- unix_main_t *um = &unix_main;
- unix_file_t *uf = socket_main.current_uf;
+ clib_file_main_t *fm = &file_main;
+ clib_file_t *uf = socket_main.current_uf;
vl_api_registration_t *rp = socket_main.current_rp;
- unix_file_del (um, uf);
+ clib_file_del (fm, uf);
vl_free_socket_registration_index (rp->vl_api_registration_pool_index);
}
@@ -72,8 +72,8 @@ u32
sockclnt_open_index (char *client_name, char *hostname, int port)
{
vl_api_registration_t *rp;
- unix_main_t *um = &unix_main;
- unix_file_t template = { 0 };
+ clib_file_main_t *fm = &file_main;
+ clib_file_t template = { 0 };
int sockfd;
int one = 1;
int rv;
@@ -129,7 +129,7 @@ sockclnt_open_index (char *client_name, char *hostname, int port)
template.file_descriptor = sockfd;
template.private_data = rp - socket_main.registration_pool;
- rp->unix_file_index = unix_file_add (um, &template);
+ rp->clib_file_index = clib_file_add (fm, &template);
rp->name = format (0, "%s:%d", hostname, port);
mp = vl_msg_api_alloc (sizeof (*mp));
diff --git a/src/vlibsocket/socksvr_vlib.c b/src/vlibsocket/socksvr_vlib.c
index dc8c63ebbaf..31b33df5393 100644
--- a/src/vlibsocket/socksvr_vlib.c
+++ b/src/vlibsocket/socksvr_vlib.c
@@ -53,8 +53,8 @@ dump_socket_clients (vlib_main_t * vm, api_main_t * am)
{
vl_api_registration_t *reg;
socket_main_t *sm = &socket_main;
- unix_main_t *um = &unix_main;
- unix_file_t *f;
+ clib_file_main_t *fm = &file_main;
+ clib_file_t *f;
/*
* Must have at least one active client, not counting the
@@ -69,7 +69,7 @@ dump_socket_clients (vlib_main_t * vm, api_main_t * am)
pool_foreach (reg, sm->registration_pool,
({
if (reg->registration_type == REGISTRATION_TYPE_SOCKET_SERVER) {
- f = pool_elt_at_index (um->file_pool, reg->unix_file_index);
+ f = pool_elt_at_index (fm->file_pool, reg->clib_file_index);
vlib_cli_output (vm, "%16s %8d",
reg->name, f->file_descriptor);
}
@@ -99,13 +99,13 @@ vl_socket_api_send (vl_api_registration_t * rp, u8 * elem)
nbytes += msg_length;
tmp = clib_host_to_net_u32 (nbytes);
- vl_socket_add_pending_output (rp->unix_file_index
- + unix_main.file_pool,
+ vl_socket_add_pending_output (rp->clib_file_index
+ + file_main.file_pool,
rp->vl_api_registration_pool_index
+ socket_main.registration_pool,
(u8 *) & tmp, sizeof (tmp));
- vl_socket_add_pending_output (rp->unix_file_index
- + unix_main.file_pool,
+ vl_socket_add_pending_output (rp->clib_file_index
+ + file_main.file_pool,
rp->vl_api_registration_pool_index
+ socket_main.registration_pool,
elem, msg_length);
@@ -139,18 +139,18 @@ vl_socket_api_send_with_data (vl_api_registration_t * rp,
/* Length in network byte order */
tmp = clib_host_to_net_u32 (nbytes);
- vl_socket_add_pending_output (rp->unix_file_index
- + unix_main.file_pool,
+ vl_socket_add_pending_output (rp->clib_file_index
+ + file_main.file_pool,
rp->vl_api_registration_pool_index
+ socket_main.registration_pool,
(u8 *) & tmp, sizeof (tmp));
- vl_socket_add_pending_output (rp->unix_file_index
- + unix_main.file_pool,
+ vl_socket_add_pending_output (rp->clib_file_index
+ + file_main.file_pool,
rp->vl_api_registration_pool_index
+ socket_main.registration_pool,
elem, msg_length);
- vl_socket_add_pending_output (rp->unix_file_index
- + unix_main.file_pool,
+ vl_socket_add_pending_output (rp->clib_file_index
+ + file_main.file_pool,
rp->vl_api_registration_pool_index
+ socket_main.registration_pool,
data_vector, vec_len (data_vector));
@@ -181,13 +181,13 @@ vl_socket_api_send_with_length_internal (vl_api_registration_t * rp,
/* Length in network byte order */
tmp = clib_host_to_net_u32 (nbytes);
- vl_socket_add_pending_output (rp->unix_file_index
- + unix_main.file_pool,
+ vl_socket_add_pending_output (rp->clib_file_index
+ + file_main.file_pool,
rp->vl_api_registration_pool_index
+ socket_main.registration_pool,
(u8 *) & tmp, sizeof (tmp));
- vl_socket_add_pending_output (rp->unix_file_index
- + unix_main.file_pool,
+ vl_socket_add_pending_output (rp->clib_file_index
+ + file_main.file_pool,
rp->vl_api_registration_pool_index
+ socket_main.registration_pool,
elem, msg_length);
@@ -231,7 +231,7 @@ vl_free_socket_registration_index (u32 pool_index)
}
static inline void
-socket_process_msg (unix_file_t * uf, vl_api_registration_t * rp,
+socket_process_msg (clib_file_t * uf, vl_api_registration_t * rp,
i8 * input_v)
{
u8 *the_msg = (u8 *) (input_v + sizeof (u32));
@@ -243,9 +243,9 @@ socket_process_msg (unix_file_t * uf, vl_api_registration_t * rp,
}
clib_error_t *
-vl_socket_read_ready (unix_file_t * uf)
+vl_socket_read_ready (clib_file_t * uf)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
vl_api_registration_t *rp;
int n;
i8 *msg_buffer = 0;
@@ -259,7 +259,7 @@ vl_socket_read_ready (unix_file_t * uf)
if (n <= 0 && errno != EAGAIN)
{
- unix_file_del (um, uf);
+ clib_file_del (fm, uf);
if (!pool_is_free (socket_main.registration_pool, rp))
{
@@ -352,11 +352,11 @@ turf_it:
}
void
-vl_socket_add_pending_output (unix_file_t * uf,
+vl_socket_add_pending_output (clib_file_t * uf,
vl_api_registration_t * rp,
u8 * buffer, uword buffer_bytes)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
vec_add (rp->output_vector, buffer, buffer_bytes);
if (vec_len (rp->output_vector) > 0)
@@ -364,15 +364,15 @@ vl_socket_add_pending_output (unix_file_t * uf,
int skip_update = 0 != (uf->flags & UNIX_FILE_DATA_AVAILABLE_TO_WRITE);
uf->flags |= UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
if (!skip_update)
- um->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
+ fm->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
}
}
static void
-socket_del_pending_output (unix_file_t * uf,
+socket_del_pending_output (clib_file_t * uf,
vl_api_registration_t * rp, uword n_bytes)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
vec_delete (rp->output_vector, n_bytes, 0);
if (vec_len (rp->output_vector) <= 0)
@@ -380,14 +380,14 @@ socket_del_pending_output (unix_file_t * uf,
int skip_update = 0 == (uf->flags & UNIX_FILE_DATA_AVAILABLE_TO_WRITE);
uf->flags &= ~UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
if (!skip_update)
- um->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
+ fm->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
}
}
clib_error_t *
-vl_socket_write_ready (unix_file_t * uf)
+vl_socket_write_ready (clib_file_t * uf)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
vl_api_registration_t *rp;
int n;
@@ -402,7 +402,7 @@ vl_socket_write_ready (unix_file_t * uf)
#if DEBUG > 2
clib_warning ("write error, close the file...\n");
#endif
- unix_file_del (um, uf);
+ clib_file_del (fm, uf);
vl_free_socket_registration_index (rp - socket_main.registration_pool);
return 0;
@@ -415,23 +415,23 @@ vl_socket_write_ready (unix_file_t * uf)
}
clib_error_t *
-vl_socket_error_ready (unix_file_t * uf)
+vl_socket_error_ready (clib_file_t * uf)
{
vl_api_registration_t *rp;
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
rp = pool_elt_at_index (socket_main.registration_pool, uf->private_data);
- unix_file_del (um, uf);
+ clib_file_del (fm, uf);
vl_free_socket_registration_index (rp - socket_main.registration_pool);
return 0;
}
void
-socksvr_file_add (unix_main_t * um, int fd)
+socksvr_file_add (clib_file_main_t * fm, int fd)
{
vl_api_registration_t *rp;
- unix_file_t template = { 0 };
+ clib_file_t template = { 0 };
pool_get (socket_main.registration_pool, rp);
memset (rp, 0, sizeof (*rp));
@@ -444,13 +444,13 @@ socksvr_file_add (unix_main_t * um, int fd)
rp->registration_type = REGISTRATION_TYPE_SOCKET_SERVER;
rp->vl_api_registration_pool_index = rp - socket_main.registration_pool;
- rp->unix_file_index = unix_file_add (um, &template);
+ rp->clib_file_index = clib_file_add (fm, &template);
}
static clib_error_t *
-socksvr_accept_ready (unix_file_t * uf)
+socksvr_accept_ready (clib_file_t * uf)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
struct sockaddr_in client_addr;
int client_fd;
int client_len;
@@ -468,12 +468,12 @@ socksvr_accept_ready (unix_file_t * uf)
if (client_fd < 0)
return clib_error_return_unix (0, "socksvr_accept_ready: accept");
- socksvr_file_add (um, client_fd);
+ socksvr_file_add (fm, client_fd);
return 0;
}
static clib_error_t *
-socksvr_bogus_write (unix_file_t * uf)
+socksvr_bogus_write (clib_file_t * uf)
{
clib_warning ("why am I here?");
return 0;
@@ -525,7 +525,7 @@ vl_api_sockclnt_delete_t_handler (vl_api_sockclnt_delete_t * mp)
vl_msg_api_send (regp, (u8 *) rp);
- unix_file_del (&unix_main, unix_main.file_pool + regp->unix_file_index);
+ clib_file_del (&file_main, file_main.file_pool + regp->clib_file_index);
vl_free_socket_registration_index (mp->index);
}
@@ -542,8 +542,8 @@ _(SOCKCLNT_DELETE, sockclnt_delete)
static clib_error_t *
socksvr_api_init (vlib_main_t * vm)
{
- unix_main_t *um = &unix_main;
- unix_file_t template = { 0 };
+ clib_file_main_t *fm = &file_main;
+ clib_file_t template = { 0 };
int sockfd;
int one = 1;
int rv;
@@ -625,14 +625,14 @@ socksvr_api_init (vlib_main_t * vm)
template.file_descriptor = sockfd;
template.private_data = rp - socket_main.registration_pool;
- rp->unix_file_index = unix_file_add (um, &template);
+ rp->clib_file_index = clib_file_add (fm, &template);
return 0;
}
static clib_error_t *
socket_exit (vlib_main_t * vm)
{
- unix_main_t *um = &unix_main;
+ clib_file_main_t *fm = &file_main;
vl_api_registration_t *rp;
/* Defensive driving in case something wipes out early */
@@ -641,7 +641,7 @@ socket_exit (vlib_main_t * vm)
u32 index;
/* *INDENT-OFF* */
pool_foreach (rp, socket_main.registration_pool, ({
- unix_file_del (um, um->file_pool + rp->unix_file_index);
+ clib_file_del (fm, fm->file_pool + rp->clib_file_index);
index = rp->vl_api_registration_pool_index;
vl_free_socket_registration_index (index);
}));
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:
diff --git a/src/vppinfra.am b/src/vppinfra.am
index 8f01114c12a..a5769a0de08 100644
--- a/src/vppinfra.am
+++ b/src/vppinfra.am
@@ -183,6 +183,7 @@ nobase_include_HEADERS = \
vppinfra/error.h \
vppinfra/error_bootstrap.h \
vppinfra/fifo.h \
+ vppinfra/file.h \
vppinfra/format.h \
vppinfra/graph.h \
vppinfra/hash.h \
diff --git a/src/vppinfra/file.h b/src/vppinfra/file.h
new file mode 100644
index 00000000000..69facea9993
--- /dev/null
+++ b/src/vppinfra/file.h
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * file.h: unix file handling
+ *
+ * Copyright (c) 2008 Eliot Dresselhaus
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef included_clib_file_h
+#define included_clib_file_h
+
+#include <vppinfra/socket.h>
+#include <termios.h>
+
+
+struct clib_file;
+typedef clib_error_t *(clib_file_function_t) (struct clib_file * f);
+
+typedef struct clib_file
+{
+ /* Unix file descriptor from open/socket. */
+ u32 file_descriptor;
+
+ u32 flags;
+#define UNIX_FILE_DATA_AVAILABLE_TO_WRITE (1 << 0)
+#define UNIX_FILE_EVENT_EDGE_TRIGGERED (1 << 1)
+
+ /* Data available for function's use. */
+ uword private_data;
+
+ /* Functions to be called when read/write data becomes ready. */
+ clib_file_function_t *read_function, *write_function, *error_function;
+} clib_file_t;
+
+typedef enum
+{
+ UNIX_FILE_UPDATE_ADD,
+ UNIX_FILE_UPDATE_MODIFY,
+ UNIX_FILE_UPDATE_DELETE,
+} unix_file_update_type_t;
+
+typedef struct
+{
+ /* Pool of files to poll for input/output. */
+ clib_file_t *file_pool;
+
+ void (*file_update) (clib_file_t * file,
+ unix_file_update_type_t update_type);
+
+} clib_file_main_t;
+
+always_inline uword
+clib_file_add (clib_file_main_t * um, clib_file_t * template)
+{
+ clib_file_t *f;
+ pool_get (um->file_pool, f);
+ f[0] = template[0];
+ um->file_update (f, UNIX_FILE_UPDATE_ADD);
+ return f - um->file_pool;
+}
+
+always_inline void
+clib_file_del (clib_file_main_t * um, clib_file_t * f)
+{
+ um->file_update (f, UNIX_FILE_UPDATE_DELETE);
+ close (f->file_descriptor);
+ f->file_descriptor = ~0;
+ pool_put (um->file_pool, f);
+}
+
+always_inline void
+clib_file_del_by_index (clib_file_main_t * um, uword index)
+{
+ clib_file_t *uf;
+ uf = pool_elt_at_index (um->file_pool, index);
+ clib_file_del (um, uf);
+}
+
+always_inline uword
+clib_file_set_data_available_to_write (clib_file_main_t * um,
+ u32 clib_file_index,
+ uword is_available)
+{
+ clib_file_t *uf = pool_elt_at_index (um->file_pool, clib_file_index);
+ uword was_available = (uf->flags & UNIX_FILE_DATA_AVAILABLE_TO_WRITE);
+ if ((was_available != 0) != (is_available != 0))
+ {
+ uf->flags ^= UNIX_FILE_DATA_AVAILABLE_TO_WRITE;
+ um->file_update (uf, UNIX_FILE_UPDATE_MODIFY);
+ }
+ return was_available != 0;
+}
+
+
+#endif /* included_clib_file_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */