2 * Copyright (c) 2016-2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #include <vnet/session/application_interface.h>
16 #include <vnet/session/application.h>
17 #include <vnet/session/session.h>
20 VPP's application/session API bind/unbind/connect/disconnect calls
26 * transport-proto://[hostname]ip46-addr:port
27 * eg. tcp://ip46-addr:port
28 * tls://[testtsl.fd.io]ip46-addr:port
30 * u8 ip46_address[16];
31 * u16 port_in_host_byte_order;
32 * stream_session_type_t sst;
35 * if (unformat (input, "%U", unformat_vnet_uri, &ip46_address,
36 * &sst, &port, &fifo_name))
41 unformat_vnet_uri (unformat_input_t * input, va_list * args)
43 session_endpoint_cfg_t *sep = va_arg (*args, session_endpoint_cfg_t *);
44 u32 transport_proto = 0, port;
46 if (unformat (input, "%U://%U/%d", unformat_transport_proto,
47 &transport_proto, unformat_ip4_address, &sep->ip.ip4, &port))
49 sep->transport_proto = transport_proto;
50 sep->port = clib_host_to_net_u16 (port);
54 else if (unformat (input, "%U://[%s]%U/%d", unformat_transport_proto,
55 &transport_proto, &sep->hostname, unformat_ip4_address,
58 sep->transport_proto = transport_proto;
59 sep->port = clib_host_to_net_u16 (port);
63 else if (unformat (input, "%U://%U/%d", unformat_transport_proto,
64 &transport_proto, unformat_ip6_address, &sep->ip.ip6,
67 sep->transport_proto = transport_proto;
68 sep->port = clib_host_to_net_u16 (port);
72 else if (unformat (input, "%U://[%s]%U/%d", unformat_transport_proto,
73 &transport_proto, &sep->hostname, unformat_ip6_address,
76 sep->transport_proto = transport_proto;
77 sep->port = clib_host_to_net_u16 (port);
81 else if (unformat (input, "%U://session/%lu", unformat_transport_proto,
82 &transport_proto, &sep->transport_opts))
84 sep->transport_proto = transport_proto;
86 sep->ip.ip4.as_u32 = 1; /* ip need to be non zero in vnet */
93 static session_endpoint_cfg_t *cache_sep;
96 parse_uri (char *uri, session_endpoint_cfg_t * sep)
98 unformat_input_t _input, *input = &_input;
100 if (cache_uri && !strncmp (uri, (char *) cache_uri, vec_len (cache_uri)))
107 uri = (char *) format (0, "%s%c", uri, 0);
110 unformat_init_string (input, uri, strlen (uri));
111 if (!unformat (input, "%U", unformat_vnet_uri, sep))
113 unformat_free (input);
114 return VNET_API_ERROR_INVALID_VALUE;
116 unformat_free (input);
118 vec_free (cache_uri);
119 cache_uri = (u8 *) uri;
121 clib_mem_free (cache_sep);
122 cache_sep = clib_mem_alloc (sizeof (*sep));
129 vnet_bind_uri (vnet_listen_args_t * a)
131 session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL;
134 rv = parse_uri (a->uri, &sep);
137 sep.app_wrk_index = 0;
138 clib_memcpy (&a->sep_ext, &sep, sizeof (sep));
139 return vnet_listen (a);
143 vnet_unbind_uri (vnet_unlisten_args_t * a)
145 session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL;
150 if ((rv = parse_uri (a->uri, &sep)))
153 /* NOTE: only default fib tables supported for uri apis */
154 table_index = session_lookup_get_index_for_fib (fib_ip_proto (!sep.is_ip4),
156 listener = session_lookup_listener (table_index,
157 (session_endpoint_t *) & sep);
159 return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
160 a->handle = listen_session_get_handle (listener);
161 return vnet_unlisten (a);
165 vnet_connect_uri (vnet_connect_args_t * a)
167 session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL;
170 if ((rv = parse_uri (a->uri, &sep)))
173 clib_memcpy (&a->sep_ext, &sep, sizeof (sep));
174 if ((rv = vnet_connect (a)))
180 * fd.io coding-style-patch-verification: ON
183 * eval: (c-set-style "gnu")