u32 vrf;
vppcom_ip46_t lcl_addr;
vppcom_ip46_t peer_addr;
- u16 port;
+ u16 lcl_port; // network order
+ u16 peer_port; // network order
u8 proto;
u64 client_queue_address;
u64 options[16];
u32 tx_fifo_size;
u32 event_queue_size;
u32 listen_queue_size;
+ u8 session_scope_local;
+ u8 session_scope_global;
+ u8 *namespace_id;
+ u64 namespace_secret;
f64 app_timeout;
f64 session_timeout;
f64 accept_timeout;
{
vppcom_main_t *vcm = &vppcom_main;
vl_api_application_attach_t *bmp;
+ u8 nsid_len = vec_len (vcm->cfg.namespace_id);
+
bmp = vl_msg_api_alloc (sizeof (*bmp));
memset (bmp, 0, sizeof (*bmp));
bmp->context = htonl (0xfeedface);
bmp->options[APP_OPTIONS_FLAGS] =
APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT |
- APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE | APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
+ (vcm->cfg.session_scope_local ? APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE : 0) |
+ (vcm->cfg.session_scope_global ? APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE : 0);
bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
+ if (nsid_len)
+ {
+ bmp->namespace_id_len = nsid_len;
+ clib_memcpy (bmp->namespace_id, vcm->cfg.namespace_id, nsid_len);
+ bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = vcm->cfg.namespace_secret;
+ }
vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
}
cmp->vrf = session->vrf;
cmp->is_ip4 = session->peer_addr.is_ip4;
clib_memcpy (cmp->ip, &session->peer_addr.ip46, sizeof (cmp->ip));
- cmp->port = session->port;
+ cmp->port = session->peer_port;
cmp->proto = session->proto;
clib_memcpy (cmp->options, session->options, sizeof (cmp->options));
vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & cmp);
session->state = STATE_ACCEPT;
session->is_cut_thru = 0;
session->is_server = 1;
- session->port = mp->port;
+ session->peer_port = mp->port;
session->peer_addr.is_ip4 = mp->is_ip4;
clib_memcpy (&session->peer_addr.ip46, mp->ip,
sizeof (session->peer_addr.ip46));
session->client_queue_address = mp->client_queue_address;
session->is_cut_thru = 1;
session->is_server = 1;
- session->port = mp->port;
+ session->peer_port = mp->port;
session->peer_addr.is_ip4 = mp->is_ip4;
clib_memcpy (&session->peer_addr.ip46, mp->ip,
sizeof (session->peer_addr.ip46));
bmp->vrf = session->vrf;
bmp->is_ip4 = session->lcl_addr.is_ip4;
clib_memcpy (bmp->ip, &session->lcl_addr.ip46, sizeof (bmp->ip));
- bmp->port = session->port;
+ bmp->port = session->lcl_port;
bmp->proto = session->proto;
clib_memcpy (bmp->options, session->options, sizeof (bmp->options));
vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
(void) unformat_user (input, unformat_line_input, line_input);
unformat_skip_white_space (line_input);
- if (unformat (line_input, "vppcom {"))
+ if (unformat (line_input, "vcl {"))
{
vc_cfg_input = 1;
continue;
if (VPPCOM_DEBUG > 0)
clib_warning ("[%d] configured gid %d", vcm->my_pid, gid);
}
- else if (unformat (line_input, "segment-baseva 0x%llx",
+ else if (unformat (line_input, "segment-baseva 0x%lx",
&vcl_cfg->segment_baseva))
{
if (VPPCOM_DEBUG > 0)
- clib_warning ("[%d] configured segment_baseva 0x%llx",
+ clib_warning ("[%d] configured segment_baseva 0x%lx",
vcm->my_pid, vcl_cfg->segment_baseva);
}
else if (unformat (line_input, "segment-size 0x%lx",
clib_warning ("[%d] configured accept_timeout %f",
vcm->my_pid, vcl_cfg->accept_timeout);
}
+ else if (unformat (line_input, "session-scope-local"))
+ {
+ vcl_cfg->session_scope_local = 1;
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] configured session_scope_local (%d)",
+ vcm->my_pid, vcl_cfg->session_scope_local);
+ }
+ else if (unformat (line_input, "session-scope-global"))
+ {
+ vcl_cfg->session_scope_global = 1;
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] configured session_scope_global (%d)",
+ vcm->my_pid, vcl_cfg->session_scope_global);
+ }
+ else if (unformat (line_input, "namespace-secret 0x%lx",
+ &vcl_cfg->namespace_secret))
+ {
+ if (VPPCOM_DEBUG > 0)
+ clib_warning
+ ("[%d] configured namespace_secret 0x%lx (%lu)",
+ vcm->my_pid, vcl_cfg->namespace_secret,
+ vcl_cfg->namespace_secret);
+ }
+ else if (unformat (line_input, "namespace-secret %lu",
+ &vcl_cfg->namespace_secret))
+ {
+ if (VPPCOM_DEBUG > 0)
+ clib_warning
+ ("[%d] configured namespace_secret %lu (0x%lx)",
+ vcm->my_pid, vcl_cfg->namespace_secret,
+ vcl_cfg->namespace_secret);
+ }
+ else if (unformat (line_input, "namespace-id %v",
+ &vcl_cfg->namespace_id))
+ {
+ vl_api_application_attach_t *mp;
+ u32 max_nsid_vec_len = sizeof (mp->namespace_id) - 1;
+ u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id);
+ if (nsid_vec_len > max_nsid_vec_len)
+ {
+ _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len;
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] configured namespace_id is too long,"
+ " truncated to %d characters!", vcm->my_pid,
+ max_nsid_vec_len);
+ }
+
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] configured namespace_id %v",
+ vcm->my_pid, vcl_cfg->namespace_id);
+ }
else if (unformat (line_input, "}"))
{
vc_cfg_input = 0;
if (!vcm->init)
{
char *conf_fname;
+ char *env_var_str;
vcm->init = 1;
vcm->my_pid = getpid ();
clib_fifo_validate (vcm->client_session_index_fifo,
vcm->cfg.listen_queue_size);
vppcom_cfg_init (vcl_cfg);
- conf_fname = getenv (VPPCOM_CONF_ENV);
+ conf_fname = getenv (VPPCOM_ENV_CONF);
if (!conf_fname)
{
conf_fname = VPPCOM_CONF_DEFAULT;
if (VPPCOM_DEBUG > 0)
clib_warning ("[%d] getenv '%s' failed!", vcm->my_pid,
- VPPCOM_CONF_ENV);
+ VPPCOM_ENV_CONF);
}
vppcom_cfg_heapsize (conf_fname);
vppcom_cfg_read (conf_fname);
+ env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_ID);
+ if (env_var_str)
+ {
+ u32 ns_id_vec_len = strlen (env_var_str);
+
+ vec_reset_length (vcm->cfg.namespace_id);
+ vec_validate (vcm->cfg.namespace_id, ns_id_vec_len - 1);
+ clib_memcpy (vcm->cfg.namespace_id, env_var_str, ns_id_vec_len);
+
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] configured namespace_id (%v) from "
+ VPPCOM_ENV_APP_NAMESPACE_ID "!", vcm->my_pid,
+ vcm->cfg.namespace_id);
+ }
+ env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_SECRET);
+ if (env_var_str)
+ {
+ u64 tmp;
+ if (sscanf (env_var_str, "%lu", &tmp) != 1)
+ clib_warning ("[%d] Invalid namespace secret specified in "
+ "the environment variable "
+ VPPCOM_ENV_APP_NAMESPACE_SECRET
+ " (%s)!\n", vcm->my_pid, env_var_str);
+ else
+ {
+ vcm->cfg.namespace_secret = tmp;
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] configured namespace secret (%lu) from "
+ VPPCOM_ENV_APP_NAMESPACE_ID "!", vcm->my_pid,
+ vcm->cfg.namespace_secret);
+ }
+ }
+ if (getenv (VPPCOM_ENV_SESSION_SCOPE_LOCAL))
+ {
+ vcm->cfg.session_scope_local = 1;
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] configured session_scope_local (%u) from "
+ VPPCOM_ENV_SESSION_SCOPE_LOCAL "!", vcm->my_pid,
+ vcm->cfg.session_scope_local);
+ }
+ if (getenv (VPPCOM_ENV_SESSION_SCOPE_GLOBAL))
+ {
+ vcm->cfg.session_scope_global = 1;
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] configured session_scope_global (%u) from "
+ VPPCOM_ENV_SESSION_SCOPE_GLOBAL "!", vcm->my_pid,
+ vcm->cfg.session_scope_global);
+ }
+
vcm->bind_session_index = ~0;
vcm->main_cpu = os_get_thread_index ();
heap = clib_mem_get_per_cpu_heap ();
return VPPCOM_EBADFD;
}
- if (VPPCOM_DEBUG > 0)
- clib_warning ("[%d] sid %d", vcm->my_pid, session_index);
-
session->vrf = ep->vrf;
session->lcl_addr.is_ip4 = ep->is_ip4;
session->lcl_addr.ip46 = to_ip46 (!ep->is_ip4, ep->ip);
- session->port = ep->port;
+ session->lcl_port = ep->port;
+
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] sid %d, bound to lcl address %U lcl port %u",
+ vcm->my_pid, session_index, format_ip46_address,
+ &session->lcl_addr.ip46, session->lcl_addr.is_ip4,
+ clib_net_to_host_u16 (session->lcl_port));
clib_spinlock_unlock (&vcm->sessions_lockp);
return VPPCOM_OK;
clib_warning ("[%d] Got a request: client sid %d", vcm->my_pid,
client_session_index);
+ // Copy the lcl information from the listening session to the client session
+ // client_session->lcl_port = listen_session->lcl_port;
+ // client_session->lcl_addr = listen_session->lcl_addr;
+
ep->vrf = client_session->vrf;
ep->is_cut_thru = client_session->is_cut_thru;
ep->is_ip4 = client_session->peer_addr.is_ip4;
- ep->port = client_session->port;
+ ep->port = client_session->peer_port;
if (client_session->peer_addr.is_ip4)
clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip4,
sizeof (ip4_address_t));
else
clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip6,
sizeof (ip6_address_t));
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] sid %d, accepted peer address %U peer port %u",
+ vcm->my_pid, client_session_index, format_ip46_address,
+ &client_session->peer_addr.ip46,
+ client_session->peer_addr.is_ip4,
+ clib_net_to_host_u16 (client_session->peer_port));
clib_spinlock_unlock (&vcm->sessions_lockp);
return (int) client_session_index;
}
session->vrf = server_ep->vrf;
session->peer_addr.is_ip4 = server_ep->is_ip4;
session->peer_addr.ip46 = to_ip46 (!server_ep->is_ip4, server_ep->ip);
- session->port = server_ep->port;
+ session->peer_port = server_ep->port;
if (VPPCOM_DEBUG > 0)
{
session->peer_addr.is_ip4);
clib_warning ("[%d] connect sid %d to %s server port %d proto %s",
vcm->my_pid, session_index, ip_str,
- clib_net_to_host_u16 (session->port),
+ clib_net_to_host_u16 (session->peer_port),
session->proto ? "UDP" : "TCP");
vec_free (ip_str);
}
return VPPCOM_OK;
}
-int
-vppcom_session_read (uint32_t session_index, void *buf, int n)
+static inline int
+vppcom_session_read_internal (uint32_t session_index, void *buf, int n,
+ u8 peek)
{
vppcom_main_t *vcm = &vppcom_main;
session_t *session = 0;
do
{
- n_read = svm_fifo_dequeue_nowait (rx_fifo, n, buf);
+ if (peek)
+ n_read = svm_fifo_peek (rx_fifo, 0, n, buf);
+ else
+ n_read = svm_fifo_dequeue_nowait (rx_fifo, n, buf);
}
while (!session->is_nonblocking && (n_read <= 0));
return (n_read <= 0) ? VPPCOM_EAGAIN : n_read;
}
+int
+vppcom_session_read (uint32_t session_index, void *buf, int n)
+{
+ return (vppcom_session_read_internal (session_index, buf, n, 0));
+}
+
+static int
+vppcom_session_peek (uint32_t session_index, void *buf, int n)
+{
+ return (vppcom_session_read_internal (session_index, buf, n, 1));
+}
+
static inline int
vppcom_session_read_ready (session_t * session, u32 session_index)
{
{
case VPPCOM_ATTR_GET_NREAD:
rv = vppcom_session_read_ready (session, session_index);
- if (VPPCOM_DEBUG > 0)
+ if (VPPCOM_DEBUG > 1)
clib_warning ("VPPCOM_ATTR_GET_NREAD: nread = %d", rv);
break;
{
*flags = O_RDWR | ((session->is_nonblocking) ? O_NONBLOCK : 0);
*buflen = sizeof (*flags);
- if (VPPCOM_DEBUG > 0)
+ if (VPPCOM_DEBUG > 1)
clib_warning ("VPPCOM_ATTR_GET_FLAGS: flags = 0x%08x, "
"is_nonblocking = %u", *flags,
session->is_nonblocking);
if (buffer && buflen && (*buflen >= sizeof (*flags)))
{
session->is_nonblocking = (*flags & O_NONBLOCK) ? 1 : 0;
- if (VPPCOM_DEBUG > 0)
+ if (VPPCOM_DEBUG > 1)
clib_warning ("VPPCOM_ATTR_SET_FLAGS: flags = 0x%08x, "
"is_nonblocking = %u", *flags,
session->is_nonblocking);
{
ep->vrf = session->vrf;
ep->is_ip4 = session->peer_addr.is_ip4;
- ep->port = session->port;
+ ep->port = session->peer_port;
if (session->peer_addr.is_ip4)
clib_memcpy (ep->ip, &session->peer_addr.ip46.ip4,
sizeof (ip4_address_t));
clib_memcpy (ep->ip, &session->peer_addr.ip46.ip6,
sizeof (ip6_address_t));
*buflen = sizeof (*ep);
- if (VPPCOM_DEBUG > 0)
- clib_warning ("VPPCOM_ATTR_GET_PEER_ADDR: is_ip4 = %u, "
- "addr = %U", ep->is_ip4, format_ip46_address,
- &session->peer_addr.ip46, ep->is_ip4);
+ if (VPPCOM_DEBUG > 1)
+ clib_warning ("VPPCOM_ATTR_GET_PEER_ADDR: sid %u is_ip4 = %u, "
+ "addr = %U, port %u", session_index,
+ ep->is_ip4, format_ip46_address,
+ &session->peer_addr.ip46, ep->is_ip4,
+ clib_net_to_host_u16 (ep->port));
}
else
rv = VPPCOM_EINVAL;
{
ep->vrf = session->vrf;
ep->is_ip4 = session->lcl_addr.is_ip4;
- ep->port = session->port;
+ ep->port = session->lcl_port;
if (session->lcl_addr.is_ip4)
clib_memcpy (ep->ip, &session->lcl_addr.ip46.ip4,
sizeof (ip4_address_t));
clib_memcpy (ep->ip, &session->lcl_addr.ip46.ip6,
sizeof (ip6_address_t));
*buflen = sizeof (*ep);
- if (VPPCOM_DEBUG > 0)
- if (VPPCOM_DEBUG > 0)
- clib_warning ("VPPCOM_ATTR_GET_LCL_ADDR: is_ip4 = %u, "
- "addr = %U", ep->is_ip4, format_ip46_address,
- &session->lcl_addr.ip46, ep->is_ip4);
+ if (VPPCOM_DEBUG > 1)
+ clib_warning ("VPPCOM_ATTR_GET_LCL_ADDR: sid %u is_ip4 = %u, "
+ "addr = %U port %d", session_index,
+ ep->is_ip4, format_ip46_address,
+ &session->lcl_addr.ip46, ep->is_ip4,
+ clib_net_to_host_u16 (ep->port));
}
else
rv = VPPCOM_EINVAL;
return rv;
}
+int
+vppcom_session_recvfrom (uint32_t session_index, void *buffer,
+ uint32_t buflen, int flags, vppcom_endpt_t * ep)
+{
+ vppcom_main_t *vcm = &vppcom_main;
+ int rv = VPPCOM_OK;
+ session_t *session = 0;
+
+ if (ep)
+ {
+ clib_spinlock_lock (&vcm->sessions_lockp);
+ rv = vppcom_session_at_index (session_index, &session);
+ if (PREDICT_FALSE (rv))
+ {
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] invalid session, sid (%u) has been closed!",
+ vcm->my_pid, session_index);
+ rv = VPPCOM_EBADFD;
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ goto done;
+ }
+ ep->vrf = session->vrf;
+ ep->is_ip4 = session->peer_addr.is_ip4;
+ ep->port = session->peer_port;
+ if (session->peer_addr.is_ip4)
+ clib_memcpy (ep->ip, &session->peer_addr.ip46.ip4,
+ sizeof (ip4_address_t));
+ else
+ clib_memcpy (ep->ip, &session->peer_addr.ip46.ip6,
+ sizeof (ip6_address_t));
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ }
+
+ if (flags == 0)
+ rv = vppcom_session_read (session_index, buffer, buflen);
+ else if (flags & MSG_PEEK)
+ rv = vppcom_session_peek (session_index, buffer, buflen);
+ else
+ {
+ clib_warning ("Unsupport flags for recvfrom %d", flags);
+ rv = VPPCOM_EAFNOSUPPORT;
+ }
+
+done:
+ return rv;
+}
+
+int
+vppcom_session_sendto (uint32_t session_index, void *buffer,
+ uint32_t buflen, int flags, vppcom_endpt_t * ep)
+{
+ vppcom_main_t *vcm = &vppcom_main;
+
+ if (!buffer)
+ return VPPCOM_EINVAL;
+
+ if (ep)
+ {
+ // TBD
+ return VPPCOM_EINVAL;
+ }
+
+ if (flags)
+ {
+ // TBD check the flags and do the right thing
+ if (VPPCOM_DEBUG > 2)
+ clib_warning ("[%d] handling flags 0x%u (%d) not implemented yet.",
+ vcm->my_pid, flags, flags);
+ }
+
+ return (vppcom_session_write (session_index, buffer, buflen));
+}
+
/*
* fd.io coding-style-patch-verification: ON
*