srtp: basic implementation based on libsrtp2
[vpp.git] / src / plugins / srtp / srtp.h
1 /*
2  * Copyright (c) 2021 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 #include <vnet/plugin/plugin.h>
17 #include <vpp/app/version.h>
18
19 #include <vnet/session/application_interface.h>
20 #include <vnet/session/application.h>
21
22 #include <srtp2/srtp.h>
23
24 #ifndef SRC_PLUGINS_SRTP_SRTP_H_
25 #define SRC_PLUGINS_SRTP_SRTP_H_
26
27 #define SRTP_DEBUG 0
28
29 #if SRTP_DEBUG
30 #define SRTP_DBG(_lvl, _fmt, _args...)                                        \
31   if (_lvl <= SRTP_DEBUG)                                                     \
32   clib_warning (_fmt, ##_args)
33 #else
34 #define SRTP_DBG(_lvl, _fmt, _args...)
35 #endif
36
37 typedef struct srtp_cxt_id_
38 {
39   union
40   {
41     session_handle_t app_session_handle;
42     u32 parent_app_api_ctx;
43   };
44   session_handle_t srtp_session_handle;
45   u32 parent_app_wrk_index;
46   u32 srtp_ctx;
47   u32 listener_ctx_index;
48   u8 udp_is_ip4;
49 } srtp_ctx_id_t;
50
51 STATIC_ASSERT (sizeof (srtp_ctx_id_t) <= TRANSPORT_CONN_ID_LEN,
52                "ctx id must be less than TRANSPORT_CONN_ID_LEN");
53
54 #define SRTP_MAX_KEYLEN 46 /**< libsrtp AES 256 key len with salt */
55
56 typedef struct transport_endpt_cfg_srtp_policy
57 {
58   u32 ssrc_type;
59   u32 ssrc_value;
60   u32 window_size;
61   u8 allow_repeat_tx;
62   u8 key_len;
63   u8 key[SRTP_MAX_KEYLEN];
64 } transport_endpt_cfg_srtp_policy_t;
65
66 typedef struct transport_endpt_cfg_srtp
67 {
68   transport_endpt_cfg_srtp_policy_t policies[2];
69 } transport_endpt_cfg_srtp_t;
70
71 typedef struct srtp_ctx_
72 {
73   union
74   {
75     transport_connection_t connection;
76     srtp_ctx_id_t c_srtp_ctx_id;
77   };
78 #define parent_app_wrk_index c_srtp_ctx_id.parent_app_wrk_index
79 #define app_session_handle   c_srtp_ctx_id.app_session_handle
80 #define srtp_session_handle  c_srtp_ctx_id.srtp_session_handle
81 #define listener_ctx_index   c_srtp_ctx_id.listener_ctx_index
82 #define udp_is_ip4           c_srtp_ctx_id.udp_is_ip4
83 #define srtp_ctx_engine      c_srtp_ctx_id.srtp_engine_id
84 #define srtp_ssl_ctx         c_srtp_ctx_id.ssl_ctx
85 #define srtp_ctx_handle      c_c_index
86   /* Temporary storage for session open opaque. Overwritten once
87    * underlying tcp connection is established */
88 #define parent_app_api_context c_srtp_ctx_id.parent_app_api_ctx
89
90   u8 is_passive_close;
91   u8 resume;
92   u8 app_closed;
93   u8 no_app_session;
94   u8 is_migrated;
95   srtp_t srtp_ctx;
96   srtp_policy_t srtp_policy[2];
97 } srtp_tc_t;
98
99 typedef struct srtp_main_
100 {
101   srtp_tc_t **ctx_pool;
102   srtp_tc_t *listener_ctx_pool;
103   u32 app_index;
104   clib_rwlock_t half_open_rwlock;
105   /*
106    * Config
107    */
108   u64 first_seg_size;
109   u32 fifo_size;
110 } srtp_main_t;
111
112 #endif /* SRC_PLUGINS_SRTP_SRTP_H_ */
113
114 /*
115  * fd.io coding-style-patch-verification: ON
116  *
117  * Local Variables:
118  * eval: (c-set-style "gnu")
119  * End:
120  */