FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
application.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #ifndef SRC_VNET_SESSION_APPLICATION_H_
17 #define SRC_VNET_SESSION_APPLICATION_H_
18 
23 
24 #define APP_DEBUG 0
25 
26 #if APP_DEBUG > 0
27 #define APP_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
28 #else
29 #define APP_DBG(_fmt, _args...)
30 #endif
31 
32 typedef struct app_worker_
33 {
34  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
35 
36  /** Worker index in global worker pool*/
38 
39  /** Worker index in app's map pool */
41 
42  /** Index of owning app */
44 
45  /** Application listens for events on this svm queue */
47 
48  /** Segment manager used for outgoing connects issued by the app */
50 
51  /** Lookup tables for listeners. Value is segment manager index */
53 
54  /**
55  * First segment manager has in the the first segment the application's
56  * event fifo. Depending on what the app does, it may be either used for
57  * a listener or for connects.
58  */
61 
62  /** API index for the worker. Needed for multi-process apps */
64 
66 
67  /** Per transport proto hash tables of half-open connection handles */
69 
70  /** Protects detached seg managers */
72 
73  /** Vector of detached listener segment managers */
75 } app_worker_t;
76 
77 typedef struct app_worker_map_
78 {
81 
82 typedef struct app_listener_
83 {
84  clib_bitmap_t *workers; /**< workers accepting connections */
85  u32 accept_rotor; /**< last worker to accept a connection */
86  u32 al_index; /**< app listener index in app pool */
87  u32 app_index; /**< owning app index */
88  u32 local_index; /**< local listening session index */
89  u32 session_index; /**< global listening session index */
90  session_handle_t ls_handle; /**< session handle of the local or global
91  listening session that also identifies
92  the app listener */
94 
95 typedef struct application_
96 {
97  /** App index in app pool */
99 
100  /** Flags */
102 
103  /** Callbacks: shoulder-taps for the server/client */
105 
106  /** Segment manager properties. Shared by all segment managers */
108 
109  /** Pool of mappings that keep track of workers associated to this app */
111 
112  /** Name registered by builtin apps */
114 
115  /** Namespace the application belongs to */
117 
119 
120  /** Pool of listeners for the app */
122 
123  /** Preferred tls engine */
125 
126  /** quic initialization vector */
127  char quic_iv[17];
129 
130 } application_t;
131 
132 typedef struct app_main_
133 {
134  /**
135  * Pool from which we allocate all applications
136  */
138 
139  /**
140  * Hash table of apps by api client index
141  */
143 
144  /**
145  * Hash table of builtin apps by name
146  */
148 
149  /**
150  * Pool from which we allocate certificates (key, cert)
151  */
153 
154  /*
155  * Last registered crypto engine type
156  */
158 } app_main_t;
159 
160 typedef struct app_init_args_
161 {
162 #define _(_type, _name) _type _name;
164 #undef _
166 
167 typedef struct _vnet_app_worker_add_del_args
168 {
169  u32 app_index; /**< App for which a new worker is requested */
170  u32 wrk_map_index; /**< Index to delete or return value if add */
171  u32 api_client_index; /**< Binary API client index */
172  ssvm_private_t *segment; /**< First segment in segment manager */
173  u64 segment_handle; /**< Handle for the segment */
174  svm_msg_q_t *evt_q; /**< Worker message queue */
175  u8 is_add; /**< Flag set if addition */
177 
178 #define APP_INVALID_INDEX ((u32)~0)
179 #define APP_NS_INVALID_INDEX ((u32)~0)
180 #define APP_INVALID_SEGMENT_MANAGER_INDEX ((u32) ~0)
181 
186 void app_listener_cleanup (app_listener_t * app_listener);
189  session_endpoint_cfg_t * sep);
190 
191 /**
192  * Get app listener handle for listening session
193  *
194  * For a given listening session, this can return either the session
195  * handle of the app listener associated to the listening session or,
196  * if no such app listener exists, the session's handle
197  *
198  * @param ls listening session
199  * @return app listener or listening session handle
200  */
202 /**
203  * Get app listener for listener session handle
204  *
205  * Should only be called on handles that have an app listener, i.e.,
206  * were obtained at the end of a @ref vnet_listen call.
207  *
208  * @param handle handle of the app listener. This is the handle of
209  * either the global or local listener
210  * @return pointer to app listener or 0
211  */
216 
228 u32 application_session_table (application_t * app, u8 fib_proto);
230 const u8 *application_name_from_index (u32 app_or_wrk);
235 
237  app_index);
238 
241 
242 /*
243  * App worker
244  */
245 
248  app_worker_t ** wrk);
252 int app_worker_own_session (app_worker_t * app_wrk, session_t * s);
253 void app_worker_free (app_worker_t * app_wrk);
255  u32 api_context);
256 int app_worker_start_listen (app_worker_t * app_wrk, app_listener_t * lstnr);
259 int app_worker_accept_notify (app_worker_t * app_wrk, session_t * s);
262  session_error_t err, u32 opaque);
264  session_handle_t ho_handle,
265  session_handle_t wrk_handle);
267  session_handle_t ho_handle);
269  session_handle_t ho_handle);
270 int app_worker_close_notify (app_worker_t * app_wrk, session_t * s);
272  session_t * s);
273 int app_worker_reset_notify (app_worker_t * app_wrk, session_t * s);
277  session_handle_t new_sh);
278 int app_worker_builtin_rx (app_worker_t * app_wrk, session_t * s);
279 int app_worker_builtin_tx (app_worker_t * app_wrk, session_t * s);
281  svm_fifo_t * f,
284  session_t *);
290  u64 segment_handle);
292  u64 segment_handle);
295  u8 fib_proto, u8 transport_proto);
296 int app_worker_send_event (app_worker_t * app, session_t * s, u8 evt);
298  u8 evt_type);
301 void app_worker_del_detached_sm (app_worker_t * app_wrk, u32 sm_index);
302 u8 *format_app_worker (u8 * s, va_list * args);
303 u8 *format_app_worker_listener (u8 * s, va_list * args);
304 u8 *format_crypto_engine (u8 * s, va_list * args);
305 u8 *format_crypto_context (u8 * s, va_list * args);
306 void app_worker_format_connects (app_worker_t * app_wrk, int verbose);
308 
309 uword unformat_application_proto (unformat_input_t * input, va_list * args);
310 
314 
315 /* Needed while we support both bapi and mq ctrl messages */
316 int mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
317  session_handle_t handle, int rv);
318 int mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
319  session_t * s, session_error_t err);
321  u32 context, int rv);
322 
325 
326 #endif /* SRC_VNET_SESSION_APPLICATION_H_ */
327 
328 /*
329  * fd.io coding-style-patch-verification: ON
330  *
331  * Local Variables:
332  * eval: (c-set-style "gnu")
333  * End:
334  */
u32 flags
Flags.
Definition: application.h:101
int app_worker_lock_and_send_event(app_worker_t *app, session_t *s, u8 evt_type)
Send event to application.
struct _vnet_app_worker_add_del_args vnet_app_worker_add_del_args_t
int app_worker_init_accepted(session_t *s)
session_t * app_worker_proxy_listener(app_worker_t *app, u8 fib_proto, u8 transport_proto)
int app_worker_reset_notify(app_worker_t *app_wrk, session_t *s)
u32 al_index
app listener index in app pool
Definition: application.h:86
int mq_send_session_connected_cb(u32 app_wrk_index, u32 api_context, session_t *s, session_error_t err)
Definition: session_api.c:260
a
Definition: bitmap.h:538
transport_proto
Definition: session.api:22
int app_worker_connect_notify(app_worker_t *app_wrk, session_t *s, session_error_t err, u32 opaque)
app_cert_key_pair_t * app_cert_key_pair_get(u32 index)
Definition: application.c:1694
u32 ns_index
Namespace the application belongs to.
Definition: application.h:116
u32 * detached_seg_managers
Vector of detached listener segment managers.
Definition: application.h:74
application_t * application_lookup_name(const u8 *name)
Definition: application.c:405
application_t * application_get_if_valid(u32 index)
Definition: application.c:434
int app_worker_del_half_open(app_worker_t *app_wrk, transport_proto_t tp, session_handle_t ho_handle)
segment_manager_props_t * application_segment_manager_properties(application_t *app)
Definition: application.c:1312
unsigned long u64
Definition: types.h:89
void application_remove_proxy(application_t *app)
Definition: application.c:1296
segment_manager_t * app_worker_get_or_alloc_connect_segment_manager(app_worker_t *)
int app_worker_connect_session(app_worker_t *app, session_endpoint_t *tep, u32 api_context)
app_listener_t * listeners
Pool of listeners for the app.
Definition: application.h:121
u32 wrk_map_index
Worker index in app&#39;s map pool.
Definition: application.h:40
app_cert_key_pair_t * cert_key_pair_store
Pool from which we allocate certificates (key, cert)
Definition: application.h:152
app_listener_t * app_listener_get_w_session(session_t *ls)
Definition: application.c:67
int app_worker_add_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
Send an API message to the external app, to map new segment.
uword * listeners_table
Lookup tables for listeners.
Definition: application.h:52
application_t * application_lookup(u32 api_client_index)
Definition: application.c:394
struct app_listener_ app_listener_t
u8 app_is_builtin
Definition: application.h:65
u8 * format_crypto_context(u8 *s, va_list *args)
Definition: application.c:1448
u32 connects_seg_manager
Segment manager used for outgoing connects issued by the app.
Definition: application.h:49
segment_manager_t * app_worker_get_listen_segment_manager(app_worker_t *, session_t *)
unsigned char u8
Definition: types.h:56
app_listener_t * app_listener_lookup(application_t *app, session_endpoint_cfg_t *sep)
Definition: application.c:98
u8 app_crypto_engine_n_types(void)
Definition: application.c:1785
uword unformat_application_proto(unformat_input_t *input, va_list *args)
u32 app_index
owning app index
Definition: application.h:87
app_worker_t * application_listener_select_worker(session_t *ls)
Definition: application.c:685
enum session_ft_action_ session_ft_action_t
session_t * app_listener_get_local_session(app_listener_t *al)
Definition: application.c:289
u32 first_segment_manager
First segment manager has in the the first segment the application&#39;s event fifo.
Definition: application.h:59
u32 local_index
local listening session index
Definition: application.h:88
u32 session_index
global listening session index
Definition: application.h:89
unsigned int u32
Definition: types.h:88
u16 proxied_transports
Definition: application.h:118
session_handle_t app_listen_session_handle(session_t *ls)
Get app listener handle for listening session.
Definition: application.c:78
u8 tls_engine
Preferred tls engine.
Definition: application.h:124
struct app_worker_ app_worker_t
struct _session_endpoint_cfg session_endpoint_cfg_t
void app_listener_cleanup(app_listener_t *app_listener)
Definition: application.c:238
int app_worker_accept_notify(app_worker_t *app_wrk, session_t *s)
#define foreach_app_init_args
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
int application_is_builtin(application_t *app)
Definition: application.c:1148
app_cert_key_pair_t * app_cert_key_pair_get_default()
Definition: application.c:1700
int mq_send_session_bound_cb(u32 app_wrk_index, u32 api_context, session_handle_t handle, int rv)
Definition: session_api.c:340
struct _segment_manager_props segment_manager_props_t
segment_manager_t * app_worker_get_connect_segment_manager(app_worker_t *)
app_listener_t * app_listener_get(application_t *app, u32 al_index)
Definition: application.c:46
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
int app_worker_session_fifo_tuning(app_worker_t *app_wrk, session_t *s, svm_fifo_t *f, session_ft_action_t act, u32 len)
app_worker_t * app_worker_alloc(application_t *app)
int application_change_listener_owner(session_t *s, app_worker_t *app_wrk)
Definition: application.c:1108
u8 * format_app_worker_listener(u8 *s, va_list *args)
u8 len
Definition: ip_types.api:92
app_worker_map_t * worker_maps
Pool of mappings that keep track of workers associated to this app.
Definition: application.h:110
app_listener_t * app_listener_get_w_handle(session_handle_t handle)
Get app listener for listener session handle.
Definition: application.c:88
int app_worker_transport_closed_notify(app_worker_t *app_wrk, session_t *s)
uword * app_by_name
Hash table of builtin apps by name.
Definition: application.h:147
session_t * app_worker_first_listener(app_worker_t *app, u8 fib_proto, u8 transport_proto)
segment_manager_props_t sm_properties
Segment manager properties.
Definition: application.h:107
int app_worker_builtin_rx(app_worker_t *app_wrk, session_t *s)
struct app_init_args_ app_init_args_t
u8 * format_crypto_engine(u8 *s, va_list *args)
Definition: application.c:1409
int app_worker_cleanup_notify(app_worker_t *app_wrk, session_t *s, session_cleanup_ntf_t ntf)
clib_bitmap_t * workers
workers accepting connections
Definition: application.h:84
clib_spinlock_t detached_seg_managers_lock
Protects detached seg managers.
Definition: application.h:71
int app_listener_alloc_and_init(application_t *app, session_endpoint_cfg_t *sep, app_listener_t **listener)
Definition: application.c:130
int app_worker_init_connected(app_worker_t *app_wrk, session_t *s)
int vnet_app_worker_add_del(vnet_app_worker_add_del_args_t *a)
Definition: application.c:735
string name[64]
Definition: ip.api:44
const u8 * application_name_from_index(u32 app_or_wrk)
Returns app name for app-index.
Definition: application.c:360
u8 application_has_global_scope(application_t *app)
Definition: application.c:1166
int app_worker_add_half_open(app_worker_t *app_wrk, transport_proto_t tp, session_handle_t ho_handle, session_handle_t wrk_handle)
application_t * application_get(u32 index)
Definition: application.c:426
void app_worker_del_detached_sm(app_worker_t *app_wrk, u32 sm_index)
int application_is_proxy(application_t *app)
Definition: application.c:1142
int app_worker_send_event(app_worker_t *app, session_t *s, u8 evt)
uword * app_by_api_client_index
Hash table of apps by api client index.
Definition: application.h:142
uword ** half_open_table
Per transport proto hash tables of half-open connection handles.
Definition: application.h:68
session_cb_vft_t cb_fns
Callbacks: shoulder-taps for the server/client.
Definition: application.h:104
u32 app_worker_n_listeners(app_worker_t *app)
enum _transport_proto transport_proto_t
u32 application_session_table(application_t *app, u8 fib_proto)
Definition: application.c:332
u32 accept_rotor
last worker to accept a connection
Definition: application.h:85
int app_worker_migrate_notify(app_worker_t *app_wrk, session_t *s, session_handle_t new_sh)
int app_worker_del_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
struct app_main_ app_main_t
u32 app_index
App index in app pool.
Definition: application.h:98
struct app_worker_map_ app_worker_map_t
u32 application_local_session_table(application_t *app)
Definition: application.c:347
u64 app_worker_lookup_half_open(app_worker_t *app_wrk, transport_proto_t tp, session_handle_t ho_handle)
struct application_ application_t
session_handle_t app_listener_handle(app_listener_t *app_listener)
Definition: application.c:61
app_worker_t * app_worker_get(u32 wrk_index)
application_t * app_pool
Pool from which we allocate all applications.
Definition: application.h:137
u64 session_handle_t
int application_alloc_worker_and_init(application_t *app, app_worker_t **wrk)
Definition: application.c:696
u8 * name
Name registered by builtin apps.
Definition: application.h:113
application_t * app_worker_get_app(u32 wrk_index)
u64 uword
Definition: types.h:112
session_handle_t ls_handle
session handle of the local or global listening session that also identifies the app listener ...
Definition: application.h:90
int app_worker_alloc_connects_segment_manager(app_worker_t *app)
u32 index
Definition: flow_types.api:221
struct _segment_manager segment_manager_t
int app_worker_builtin_tx(app_worker_t *app_wrk, session_t *s)
session_t * app_listener_get_session(app_listener_t *al)
Definition: application.c:280
session_cleanup_ntf_t
int app_worker_start_listen(app_worker_t *app_wrk, app_listener_t *lstnr)
u8 application_has_local_scope(application_t *app)
Definition: application.c:1160
u32 app_index
Index of owning app.
Definition: application.h:43
int application_is_builtin_proxy(application_t *app)
Definition: application.c:1154
int app_worker_own_session(app_worker_t *app_wrk, session_t *s)
int app_worker_stop_listen(app_worker_t *app_wrk, app_listener_t *al)
void app_worker_free(app_worker_t *app_wrk)
app_worker_t * application_get_default_worker(application_t *app)
Definition: application.c:673
segment_manager_props_t * application_get_segment_manager_properties(u32 app_index)
Definition: application.c:1318
uword clib_bitmap_t
Definition: bitmap.h:50
enum session_error_ session_error_t
crypto_engine_type_t app_crypto_engine_type_add(void)
Definition: application.c:1779
enum crypto_engine_type_ crypto_engine_type_t
void app_worker_format_connects(app_worker_t *app_wrk, int verbose)
u32 api_client_index
API index for the worker.
Definition: application.h:63
int app_worker_close_notify(app_worker_t *app_wrk, session_t *s)
struct _session_endpoint session_endpoint_t
svm_msg_q_t * event_queue
Application listens for events on this svm queue.
Definition: application.h:46
u8 * format_app_worker(u8 *s, va_list *args)
struct _svm_fifo svm_fifo_t
void application_setup_proxy(application_t *app)
Definition: application.c:1280
CLIB_CACHE_LINE_ALIGN_MARK(cacheline0)
app_cert_key_pair_t * app_cert_key_pair_get_if_valid(u32 index)
Definition: application.c:1686
app_worker_t * application_get_worker(application_t *app, u32 wrk_index)
Definition: application.c:663
crypto_engine_type_t last_crypto_engine
Definition: application.h:157
u8 first_segment_manager_in_use
Definition: application.h:60
void mq_send_unlisten_reply(app_worker_t *app_wrk, session_handle_t sh, u32 context, int rv)
Definition: session_api.c:400