Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2019 Cisco and/or its affiliates. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 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/vnet.h> |
| 17 | #include <vlibmemory/api.h> |
| 18 | #include <vnet/session/application.h> |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 19 | #include <vnet/session/application_interface.h> |
Florin Coras | ba7d8f5 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 20 | #include <vnet/session/application_local.h> |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 21 | #include <vnet/session/session_rules_table.h> |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 22 | #include <vnet/session/session_table.h> |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 23 | #include <vnet/session/session.h> |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 24 | #include <vnet/ip/ip_types_api.h> |
| 25 | |
Filip Tehlar | 0046e97 | 2021-06-26 22:12:08 +0000 | [diff] [blame] | 26 | #include <vnet/format_fns.h> |
| 27 | #include <vnet/session/session.api_enum.h> |
| 28 | #include <vnet/session/session.api_types.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 29 | |
Filip Tehlar | 0046e97 | 2021-06-26 22:12:08 +0000 | [diff] [blame] | 30 | #define REPLY_MSG_ID_BASE session_main.msg_id_base |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 31 | #include <vlibapi/api_helper_macros.h> |
| 32 | |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 33 | static transport_proto_t |
| 34 | api_session_transport_proto_decode (const vl_api_transport_proto_t * api_tp) |
| 35 | { |
| 36 | switch (*api_tp) |
| 37 | { |
| 38 | case TRANSPORT_PROTO_API_TCP: |
| 39 | return TRANSPORT_PROTO_TCP; |
| 40 | case TRANSPORT_PROTO_API_UDP: |
| 41 | return TRANSPORT_PROTO_UDP; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 42 | case TRANSPORT_PROTO_API_TLS: |
| 43 | return TRANSPORT_PROTO_TLS; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 44 | case TRANSPORT_PROTO_API_QUIC: |
| 45 | return TRANSPORT_PROTO_QUIC; |
| 46 | default: |
| 47 | return TRANSPORT_PROTO_NONE; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | static vl_api_transport_proto_t |
| 52 | api_session_transport_proto_encode (const transport_proto_t tp) |
| 53 | { |
| 54 | switch (tp) |
| 55 | { |
| 56 | case TRANSPORT_PROTO_TCP: |
| 57 | return TRANSPORT_PROTO_API_TCP; |
| 58 | case TRANSPORT_PROTO_UDP: |
| 59 | return TRANSPORT_PROTO_API_UDP; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 60 | case TRANSPORT_PROTO_TLS: |
| 61 | return TRANSPORT_PROTO_API_TLS; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 62 | case TRANSPORT_PROTO_QUIC: |
| 63 | return TRANSPORT_PROTO_API_QUIC; |
| 64 | default: |
| 65 | return TRANSPORT_PROTO_API_NONE; |
| 66 | } |
| 67 | } |
| 68 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 69 | static int |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 70 | session_send_fds (vl_api_registration_t * reg, int fds[], int n_fds) |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 71 | { |
| 72 | clib_error_t *error; |
| 73 | if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 74 | return SESSION_E_BAPI_NO_FD; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 75 | error = vl_api_send_fd_msg (reg, fds, n_fds); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 76 | if (error) |
| 77 | { |
| 78 | clib_error_report (error); |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 79 | return SESSION_E_BAPI_SEND_FD; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 80 | } |
| 81 | return 0; |
| 82 | } |
| 83 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 84 | static int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 85 | mq_send_session_accepted_cb (session_t * s) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 86 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 87 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 88 | session_accepted_msg_t m = { 0 }; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 89 | fifo_segment_t *eq_seg; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 90 | session_t *listener; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 91 | application_t *app; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 92 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 93 | app = application_get (app_wrk->app_index); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 94 | |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 95 | m.context = app->app_index; |
| 96 | m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); |
| 97 | m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); |
| 98 | m.segment_handle = session_segment_handle (s); |
| 99 | m.flags = s->flags; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 100 | |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 101 | eq_seg = application_get_rx_mqs_segment (app); |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 102 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 103 | if (session_has_transport (s)) |
| 104 | { |
Nathan Skrzypczak | 2f0f96b | 2019-06-13 10:14:28 +0200 | [diff] [blame] | 105 | listener = listen_session_get_from_handle (s->listener_handle); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 106 | m.listener_handle = app_listen_session_handle (listener); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 107 | if (application_is_proxy (app)) |
| 108 | { |
| 109 | listener = |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 110 | app_worker_first_listener (app_wrk, session_get_fib_proto (s), |
| 111 | session_get_transport_proto (s)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 112 | if (listener) |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 113 | m.listener_handle = listen_session_get_handle (listener); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 114 | } |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 115 | m.vpp_event_queue_address = |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 116 | fifo_segment_msg_q_offset (eq_seg, s->thread_index); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 117 | m.mq_index = s->thread_index; |
| 118 | m.handle = session_handle (s); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 119 | |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 120 | session_get_endpoint (s, &m.rmt, 0 /* is_lcl */); |
Florin Coras | 67c90a3 | 2021-03-09 18:36:06 -0800 | [diff] [blame] | 121 | session_get_endpoint (s, &m.lcl, 1 /* is_lcl */); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 122 | } |
| 123 | else |
| 124 | { |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 125 | ct_connection_t *ct; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 126 | |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 127 | ct = (ct_connection_t *) session_get_transport (s); |
Nathan Skrzypczak | 2f0f96b | 2019-06-13 10:14:28 +0200 | [diff] [blame] | 128 | listener = listen_session_get_from_handle (s->listener_handle); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 129 | m.listener_handle = app_listen_session_handle (listener); |
| 130 | m.rmt.is_ip4 = session_type_is_ip4 (listener->session_type); |
| 131 | m.rmt.port = ct->c_rmt_port; |
Florin Coras | 67c90a3 | 2021-03-09 18:36:06 -0800 | [diff] [blame] | 132 | m.lcl.port = ct->c_lcl_port; |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 133 | m.handle = session_handle (s); |
| 134 | m.vpp_event_queue_address = |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 135 | fifo_segment_msg_q_offset (eq_seg, s->thread_index); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 136 | m.mq_index = s->thread_index; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 137 | } |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 138 | |
qinyang | af9b715 | 2023-06-27 01:11:53 -0700 | [diff] [blame] | 139 | if (application_original_dst_is_enabled (app)) |
| 140 | { |
| 141 | session_get_original_dst (&m.lcl, &m.rmt, |
| 142 | session_get_transport_proto (s), |
| 143 | &m.original_dst_ip4, &m.original_dst_port); |
| 144 | } |
| 145 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 146 | app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_ACCEPTED, &m, sizeof (m)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 151 | static inline void |
| 152 | mq_send_session_close_evt (app_worker_t * app_wrk, session_handle_t sh, |
| 153 | session_evt_type_t evt_type) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 154 | { |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 155 | session_disconnected_msg_t m = { 0 }; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 156 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 157 | m.handle = sh; |
| 158 | m.context = app_wrk->api_client_index; |
| 159 | |
| 160 | app_wrk_send_ctrl_evt (app_wrk, evt_type, &m, sizeof (m)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 163 | static inline void |
| 164 | mq_notify_close_subscribers (u32 app_index, session_handle_t sh, |
| 165 | svm_fifo_t * f, session_evt_type_t evt_type) |
| 166 | { |
| 167 | app_worker_t *app_wrk; |
| 168 | application_t *app; |
| 169 | int i; |
| 170 | |
| 171 | app = application_get (app_index); |
| 172 | if (!app) |
| 173 | return; |
| 174 | |
Florin Coras | c547e91 | 2020-12-08 17:50:45 -0800 | [diff] [blame] | 175 | for (i = 0; i < f->shr->n_subscribers; i++) |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 176 | { |
Florin Coras | c547e91 | 2020-12-08 17:50:45 -0800 | [diff] [blame] | 177 | if (!(app_wrk = application_get_worker (app, f->shr->subscribers[i]))) |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 178 | continue; |
| 179 | mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_DISCONNECTED); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 184 | mq_send_session_disconnected_cb (session_t * s) |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 185 | { |
| 186 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
| 187 | session_handle_t sh = session_handle (s); |
| 188 | |
| 189 | mq_send_session_close_evt (app_wrk, session_handle (s), |
| 190 | SESSION_CTRL_EVT_DISCONNECTED); |
| 191 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 192 | if (svm_fifo_n_subscribers (s->rx_fifo)) |
| 193 | mq_notify_close_subscribers (app_wrk->app_index, sh, s->rx_fifo, |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 194 | SESSION_CTRL_EVT_DISCONNECTED); |
| 195 | } |
| 196 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 197 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 198 | mq_send_session_reset_cb (session_t * s) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 199 | { |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 200 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
| 201 | session_handle_t sh = session_handle (s); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 202 | |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 203 | mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_RESET); |
| 204 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 205 | if (svm_fifo_n_subscribers (s->rx_fifo)) |
| 206 | mq_notify_close_subscribers (app_wrk->app_index, sh, s->rx_fifo, |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 207 | SESSION_CTRL_EVT_RESET); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 210 | int |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 211 | mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context, |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 212 | session_t * s, session_error_t err) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 213 | { |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 214 | session_connected_msg_t m = { 0 }; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 215 | fifo_segment_t *eq_seg; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 216 | app_worker_t *app_wrk; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 217 | application_t *app; |
| 218 | |
| 219 | app_wrk = app_worker_get (app_wrk_index); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 220 | |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 221 | m.context = api_context; |
| 222 | m.retval = err; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 223 | |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 224 | if (err) |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 225 | goto snd_msg; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 226 | |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 227 | app = application_get (app_wrk->app_index); |
| 228 | eq_seg = application_get_rx_mqs_segment (app); |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 229 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 230 | if (session_has_transport (s)) |
| 231 | { |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 232 | m.handle = session_handle (s); |
| 233 | m.vpp_event_queue_address = |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 234 | fifo_segment_msg_q_offset (eq_seg, s->thread_index); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 235 | |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 236 | session_get_endpoint (s, &m.lcl, 1 /* is_lcl */); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 237 | |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 238 | m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); |
| 239 | m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); |
| 240 | m.segment_handle = session_segment_handle (s); |
Florin Coras | f6e284b | 2021-07-21 18:17:20 -0700 | [diff] [blame] | 241 | m.mq_index = s->thread_index; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 242 | } |
| 243 | else |
| 244 | { |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 245 | ct_connection_t *cct; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 246 | |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 247 | cct = (ct_connection_t *) session_get_transport (s); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 248 | m.handle = session_handle (s); |
| 249 | m.lcl.port = cct->c_lcl_port; |
| 250 | m.lcl.is_ip4 = cct->c_is_ip4; |
| 251 | m.vpp_event_queue_address = |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 252 | fifo_segment_msg_q_offset (eq_seg, s->thread_index); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 253 | m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo); |
| 254 | m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo); |
| 255 | m.segment_handle = session_segment_handle (s); |
Florin Coras | f6e284b | 2021-07-21 18:17:20 -0700 | [diff] [blame] | 256 | m.mq_index = s->thread_index; |
Florin Coras | 9375266 | 2023-11-20 14:46:10 -0800 | [diff] [blame] | 257 | m.ct_rx_fifo = fifo_segment_fifo_offset (cct->client_rx_fifo); |
| 258 | m.ct_tx_fifo = fifo_segment_fifo_offset (cct->client_tx_fifo); |
| 259 | m.ct_segment_handle = cct->segment_handle; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Florin Coras | 893bc97 | 2021-04-23 08:58:57 -0700 | [diff] [blame] | 262 | /* Setup client session index in advance, in case data arrives |
| 263 | * before the app processes message and updates it */ |
| 264 | s->rx_fifo->shr->client_session_index = api_context; |
| 265 | s->tx_fifo->shr->client_session_index = api_context; |
| 266 | |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 267 | snd_msg: |
| 268 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 269 | app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_CONNECTED, &m, sizeof (m)); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 270 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
Florin Coras | 4f3da9c | 2024-02-29 18:19:30 -0800 | [diff] [blame] | 274 | static int |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 275 | mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context, |
| 276 | session_handle_t handle, int rv) |
| 277 | { |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 278 | session_bound_msg_t m = { 0 }; |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 279 | transport_connection_t *ltc; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 280 | fifo_segment_t *eq_seg; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 281 | app_worker_t *app_wrk; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 282 | application_t *app; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 283 | app_listener_t *al; |
| 284 | session_t *ls = 0; |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 285 | |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 286 | app_wrk = app_worker_get (app_wrk_index); |
| 287 | |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 288 | m.context = api_context; |
| 289 | m.retval = rv; |
| 290 | |
| 291 | if (rv) |
| 292 | goto snd_msg; |
| 293 | |
| 294 | m.handle = handle; |
| 295 | al = app_listener_get_w_handle (handle); |
| 296 | if (al->session_index != SESSION_INVALID_INDEX) |
| 297 | ls = app_listener_get_session (al); |
| 298 | else |
| 299 | ls = app_listener_get_local_session (al); |
| 300 | |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 301 | ltc = session_get_transport (ls); |
| 302 | m.lcl_port = ltc->lcl_port; |
| 303 | m.lcl_is_ip4 = ltc->is_ip4; |
| 304 | clib_memcpy_fast (m.lcl_ip, <c->lcl_ip, sizeof (m.lcl_ip)); |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 305 | app = application_get (app_wrk->app_index); |
| 306 | eq_seg = application_get_rx_mqs_segment (app); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 307 | m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, ls->thread_index); |
Florin Coras | f6e284b | 2021-07-21 18:17:20 -0700 | [diff] [blame] | 308 | m.mq_index = ls->thread_index; |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 309 | |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 310 | if (transport_connection_is_cless (ltc)) |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 311 | { |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 312 | session_t *wrk_ls; |
Florin Coras | aeb7c1c | 2023-03-10 10:22:21 -0800 | [diff] [blame] | 313 | m.mq_index = transport_cl_thread (); |
| 314 | m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, m.mq_index); |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 315 | wrk_ls = app_listener_get_wrk_cl_session (al, app_wrk->wrk_map_index); |
| 316 | m.rx_fifo = fifo_segment_fifo_offset (wrk_ls->rx_fifo); |
| 317 | m.tx_fifo = fifo_segment_fifo_offset (wrk_ls->tx_fifo); |
| 318 | m.segment_handle = session_segment_handle (wrk_ls); |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | snd_msg: |
| 322 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 323 | app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_BOUND, &m, sizeof (m)); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 324 | |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
Florin Coras | 4f3da9c | 2024-02-29 18:19:30 -0800 | [diff] [blame] | 328 | static void |
| 329 | mq_send_unlisten_cb (u32 app_wrk_index, session_handle_t sh, u32 context, |
| 330 | int rv) |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 331 | { |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 332 | session_unlisten_reply_msg_t m = { 0 }; |
Florin Coras | 4f3da9c | 2024-02-29 18:19:30 -0800 | [diff] [blame] | 333 | app_worker_t *app_wrk; |
| 334 | |
| 335 | app_wrk = app_worker_get (app_wrk_index); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 336 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 337 | m.context = context; |
| 338 | m.handle = sh; |
| 339 | m.retval = rv; |
| 340 | app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_UNLISTEN_REPLY, &m, |
| 341 | sizeof (m)); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Florin Coras | 49568af | 2019-07-31 16:46:24 -0700 | [diff] [blame] | 344 | static void |
| 345 | mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh) |
| 346 | { |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 347 | session_migrated_msg_t m = { 0 }; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 348 | fifo_segment_t *eq_seg; |
Florin Coras | 68b7e58 | 2020-01-21 18:33:23 -0800 | [diff] [blame] | 349 | app_worker_t *app_wrk; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 350 | application_t *app; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 351 | u32 thread_index; |
| 352 | |
| 353 | thread_index = session_thread_from_handle (new_sh); |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 354 | app_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 355 | app = application_get (app_wrk->app_index); |
| 356 | eq_seg = application_get_rx_mqs_segment (app); |
Florin Coras | 68b7e58 | 2020-01-21 18:33:23 -0800 | [diff] [blame] | 357 | |
Florin Coras | 09bf91a | 2021-02-23 08:44:13 -0800 | [diff] [blame] | 358 | m.handle = session_handle (s); |
| 359 | m.new_handle = new_sh; |
| 360 | m.vpp_thread_index = thread_index; |
| 361 | m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, thread_index); |
| 362 | m.segment_handle = SESSION_INVALID_HANDLE; |
| 363 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 364 | app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_MIGRATED, &m, sizeof (m)); |
Florin Coras | 49568af | 2019-07-31 16:46:24 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 367 | static int |
| 368 | mq_send_add_segment_cb (u32 app_wrk_index, u64 segment_handle) |
| 369 | { |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 370 | session_app_add_segment_msg_t m = { 0 }; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 371 | vl_api_registration_t *reg; |
| 372 | app_worker_t *app_wrk; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 373 | fifo_segment_t *fs; |
| 374 | ssvm_private_t *sp; |
| 375 | u8 fd_flags = 0; |
| 376 | |
| 377 | app_wrk = app_worker_get (app_wrk_index); |
| 378 | |
| 379 | reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index); |
| 380 | if (!reg) |
| 381 | { |
| 382 | clib_warning ("no api registration for client: %u", |
| 383 | app_wrk->api_client_index); |
| 384 | return -1; |
| 385 | } |
| 386 | |
| 387 | fs = segment_manager_get_segment_w_handle (segment_handle); |
| 388 | sp = &fs->ssvm; |
| 389 | if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD) |
| 390 | { |
| 391 | if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
| 392 | { |
| 393 | clib_warning ("can't send memfd fd"); |
| 394 | return -1; |
| 395 | } |
| 396 | |
| 397 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 400 | m.segment_size = sp->ssvm_size; |
| 401 | m.fd_flags = fd_flags; |
| 402 | m.segment_handle = segment_handle; |
| 403 | strncpy ((char *) m.segment_name, (char *) sp->name, |
| 404 | sizeof (m.segment_name) - 1); |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 405 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 406 | app_wrk_send_ctrl_evt_fd (app_wrk, SESSION_CTRL_EVT_APP_ADD_SEGMENT, &m, |
| 407 | sizeof (m), sp->fd); |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static int |
| 413 | mq_send_del_segment_cb (u32 app_wrk_index, u64 segment_handle) |
| 414 | { |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 415 | session_app_del_segment_msg_t m = { 0 }; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 416 | vl_api_registration_t *reg; |
| 417 | app_worker_t *app_wrk; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 418 | |
| 419 | app_wrk = app_worker_get (app_wrk_index); |
| 420 | reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index); |
| 421 | if (!reg) |
| 422 | { |
| 423 | clib_warning ("no registration: %u", app_wrk->api_client_index); |
| 424 | return -1; |
| 425 | } |
| 426 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 427 | m.segment_handle = segment_handle; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 428 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 429 | app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_APP_DEL_SEGMENT, &m, |
| 430 | sizeof (m)); |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 431 | |
| 432 | return 0; |
| 433 | } |
| 434 | |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 435 | static void |
| 436 | mq_send_session_cleanup_cb (session_t * s, session_cleanup_ntf_t ntf) |
| 437 | { |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 438 | session_cleanup_msg_t m = { 0 }; |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 439 | app_worker_t *app_wrk; |
| 440 | |
Florin Coras | 36d4939 | 2020-04-24 23:00:11 +0000 | [diff] [blame] | 441 | /* Propagate transport cleanup notifications only if app didn't close */ |
| 442 | if (ntf == SESSION_CLEANUP_TRANSPORT |
| 443 | && s->session_state != SESSION_STATE_TRANSPORT_DELETED) |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | app_wrk = app_worker_get_if_valid (s->app_wrk_index); |
| 447 | if (!app_wrk) |
| 448 | return; |
| 449 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 450 | m.handle = session_handle (s); |
| 451 | m.type = ntf; |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 452 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 453 | app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_CLEANUP, &m, sizeof (m)); |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 456 | static int |
| 457 | mq_send_io_rx_event (session_t *s) |
| 458 | { |
| 459 | session_event_t *mq_evt; |
| 460 | svm_msg_q_msg_t mq_msg; |
| 461 | app_worker_t *app_wrk; |
| 462 | svm_msg_q_t *mq; |
| 463 | |
| 464 | if (svm_fifo_has_event (s->rx_fifo)) |
| 465 | return 0; |
| 466 | |
| 467 | app_wrk = app_worker_get (s->app_wrk_index); |
| 468 | mq = app_wrk->event_queue; |
| 469 | |
| 470 | mq_msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_IO_EVT_RING); |
| 471 | mq_evt = svm_msg_q_msg_data (mq, &mq_msg); |
| 472 | |
| 473 | mq_evt->event_type = SESSION_IO_EVT_RX; |
| 474 | mq_evt->session_index = s->rx_fifo->shr->client_session_index; |
| 475 | |
| 476 | (void) svm_fifo_set_event (s->rx_fifo); |
| 477 | |
| 478 | svm_msg_q_add_raw (mq, &mq_msg); |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | static int |
| 484 | mq_send_io_tx_event (session_t *s) |
| 485 | { |
| 486 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
| 487 | svm_msg_q_t *mq = app_wrk->event_queue; |
| 488 | session_event_t *mq_evt; |
| 489 | svm_msg_q_msg_t mq_msg; |
| 490 | |
| 491 | mq_msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_IO_EVT_RING); |
| 492 | mq_evt = svm_msg_q_msg_data (mq, &mq_msg); |
| 493 | |
| 494 | mq_evt->event_type = SESSION_IO_EVT_TX; |
| 495 | mq_evt->session_index = s->tx_fifo->shr->client_session_index; |
| 496 | |
| 497 | svm_msg_q_add_raw (mq, &mq_msg); |
| 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 502 | static session_cb_vft_t session_mq_cb_vft = { |
| 503 | .session_accept_callback = mq_send_session_accepted_cb, |
| 504 | .session_disconnect_callback = mq_send_session_disconnected_cb, |
| 505 | .session_connected_callback = mq_send_session_connected_cb, |
| 506 | .session_reset_callback = mq_send_session_reset_cb, |
| 507 | .session_migrate_callback = mq_send_session_migrate_cb, |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 508 | .session_cleanup_callback = mq_send_session_cleanup_cb, |
Florin Coras | 4f3da9c | 2024-02-29 18:19:30 -0800 | [diff] [blame] | 509 | .session_listened_callback = mq_send_session_bound_cb, |
| 510 | .session_unlistened_callback = mq_send_unlisten_cb, |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 511 | .add_segment_callback = mq_send_add_segment_cb, |
| 512 | .del_segment_callback = mq_send_del_segment_cb, |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 513 | .builtin_app_rx_callback = mq_send_io_rx_event, |
| 514 | .builtin_app_tx_callback = mq_send_io_tx_event, |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 515 | }; |
| 516 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 517 | static void |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 518 | vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp) |
| 519 | { |
| 520 | vl_api_session_enable_disable_reply_t *rmp; |
| 521 | vlib_main_t *vm = vlib_get_main (); |
| 522 | int rv = 0; |
| 523 | |
| 524 | vnet_session_enable_disable (vm, mp->is_enable); |
| 525 | REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY); |
| 526 | } |
| 527 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 528 | static void |
Nathan Skrzypczak | 7b3a3df | 2021-07-28 14:09:50 +0200 | [diff] [blame] | 529 | vl_api_session_sapi_enable_disable_t_handler ( |
| 530 | vl_api_session_sapi_enable_disable_t *mp) |
| 531 | { |
| 532 | vl_api_session_sapi_enable_disable_reply_t *rmp; |
| 533 | int rv = 0; |
| 534 | |
| 535 | rv = appns_sapi_enable_disable (mp->is_enable); |
| 536 | REPLY_MACRO (VL_API_SESSION_SAPI_ENABLE_DISABLE_REPLY); |
| 537 | } |
| 538 | |
| 539 | static void |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 540 | vl_api_app_attach_t_handler (vl_api_app_attach_t * mp) |
| 541 | { |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 542 | int rv = 0, *fds = 0, n_fds = 0, n_workers, i; |
| 543 | fifo_segment_t *segp, *rx_mqs_seg = 0; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 544 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 545 | vl_api_app_attach_reply_t *rmp; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 546 | u8 fd_flags = 0, ctrl_thread; |
| 547 | vl_api_registration_t *reg; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 548 | svm_msg_q_t *rx_mq; |
| 549 | application_t *app; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 550 | |
| 551 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 552 | if (!reg) |
| 553 | return; |
| 554 | |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 555 | n_workers = vlib_num_workers (); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 556 | if (!session_main_is_enabled () || appns_sapi_enabled ()) |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 557 | { |
| 558 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 559 | goto done; |
| 560 | } |
Florin Coras | 6c10ab2 | 2020-11-08 16:50:39 -0800 | [diff] [blame] | 561 | /* Only support binary api with socket transport */ |
| 562 | if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
| 563 | { |
| 564 | rv = VNET_API_ERROR_APP_UNSUPPORTED_CFG; |
| 565 | goto done; |
| 566 | } |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 567 | |
| 568 | STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <= |
| 569 | sizeof (mp->options), |
| 570 | "Out of options, fix api message definition"); |
| 571 | |
| 572 | clib_memset (a, 0, sizeof (*a)); |
| 573 | a->api_client_index = mp->client_index; |
| 574 | a->options = mp->options; |
| 575 | a->session_cb_vft = &session_mq_cb_vft; |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 576 | a->namespace_id = vl_api_from_api_to_new_vec (mp, &mp->namespace_id); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 577 | |
| 578 | if ((rv = vnet_application_attach (a))) |
| 579 | { |
Filip Tehlar | 0028e6f | 2023-06-28 10:47:32 +0200 | [diff] [blame] | 580 | clib_warning ("attach returned: %U", format_session_error, rv); |
| 581 | rv = VNET_API_ERROR_UNSPECIFIED; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 582 | vec_free (a->namespace_id); |
| 583 | goto done; |
| 584 | } |
| 585 | vec_free (a->namespace_id); |
| 586 | |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 587 | vec_validate (fds, 3 /* segs + tx evtfd */ + n_workers); |
| 588 | |
| 589 | /* Send rx mqs segment */ |
| 590 | app = application_get (a->app_index); |
| 591 | rx_mqs_seg = application_get_rx_mqs_segment (app); |
| 592 | |
| 593 | fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT; |
| 594 | fds[n_fds] = rx_mqs_seg->ssvm.fd; |
| 595 | n_fds += 1; |
| 596 | |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 597 | /* Send fifo segment fd if needed */ |
| 598 | if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD) |
| 599 | { |
| 600 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 601 | fds[n_fds] = a->segment->fd; |
| 602 | n_fds += 1; |
| 603 | } |
| 604 | if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD) |
| 605 | { |
| 606 | fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 607 | fds[n_fds] = svm_msg_q_get_eventfd (a->app_evt_q); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 608 | n_fds += 1; |
| 609 | } |
| 610 | |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 611 | if (application_use_private_rx_mqs ()) |
| 612 | { |
| 613 | fd_flags |= SESSION_FD_F_VPP_MQ_EVENTFD; |
| 614 | for (i = 0; i < n_workers + 1; i++) |
| 615 | { |
| 616 | rx_mq = application_rx_mq_get (app, i); |
| 617 | fds[n_fds] = svm_msg_q_get_eventfd (rx_mq); |
| 618 | n_fds += 1; |
| 619 | } |
| 620 | } |
| 621 | |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 622 | done: |
Klement Sekera | 0eb83f4 | 2021-12-02 16:36:34 +0000 | [diff] [blame] | 623 | REPLY_MACRO3 ( |
| 624 | VL_API_APP_ATTACH_REPLY, |
| 625 | ((!rv) ? vec_len (((fifo_segment_t *) a->segment)->ssvm.name) : 0), ({ |
| 626 | if (!rv) |
| 627 | { |
| 628 | ctrl_thread = n_workers ? 1 : 0; |
| 629 | segp = (fifo_segment_t *) a->segment; |
| 630 | rmp->app_index = clib_host_to_net_u32 (a->app_index); |
| 631 | rmp->app_mq = fifo_segment_msg_q_offset (segp, 0); |
| 632 | rmp->vpp_ctrl_mq = |
| 633 | fifo_segment_msg_q_offset (rx_mqs_seg, ctrl_thread); |
| 634 | rmp->vpp_ctrl_mq_thread = ctrl_thread; |
| 635 | rmp->n_fds = n_fds; |
| 636 | rmp->fd_flags = fd_flags; |
| 637 | if (vec_len (segp->ssvm.name)) |
| 638 | { |
| 639 | vl_api_vec_to_api_string (segp->ssvm.name, &rmp->segment_name); |
| 640 | } |
| 641 | rmp->segment_size = segp->ssvm.ssvm_size; |
| 642 | rmp->segment_handle = clib_host_to_net_u64 (a->segment_handle); |
| 643 | } |
| 644 | })); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 645 | |
| 646 | if (n_fds) |
| 647 | session_send_fds (reg, fds, n_fds); |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 648 | vec_free (fds); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 651 | static void |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 652 | vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp) |
| 653 | { |
| 654 | int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0; |
| 655 | vl_api_app_worker_add_del_reply_t *rmp; |
| 656 | vl_api_registration_t *reg; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 657 | application_t *app; |
| 658 | u8 fd_flags = 0; |
| 659 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 660 | if (!session_main_is_enabled () || appns_sapi_enabled ()) |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 661 | { |
| 662 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 663 | goto done; |
| 664 | } |
| 665 | |
| 666 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 667 | if (!reg) |
| 668 | return; |
| 669 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 670 | app = application_get_if_valid (clib_net_to_host_u32 (mp->app_index)); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 671 | if (!app) |
| 672 | { |
| 673 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 674 | goto done; |
| 675 | } |
| 676 | |
| 677 | vnet_app_worker_add_del_args_t args = { |
| 678 | .app_index = app->app_index, |
Florin Coras | 349f8ca | 2018-11-20 16:52:49 -0800 | [diff] [blame] | 679 | .wrk_map_index = clib_net_to_host_u32 (mp->wrk_index), |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 680 | .api_client_index = mp->client_index, |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 681 | .is_add = mp->is_add |
| 682 | }; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 683 | rv = vnet_app_worker_add_del (&args); |
| 684 | if (rv) |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 685 | { |
Filip Tehlar | 0028e6f | 2023-06-28 10:47:32 +0200 | [diff] [blame] | 686 | clib_warning ("app worker add/del returned: %U", format_session_error, |
| 687 | rv); |
| 688 | rv = VNET_API_ERROR_UNSPECIFIED; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 689 | goto done; |
| 690 | } |
| 691 | |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 692 | if (!mp->is_add) |
| 693 | goto done; |
Florin Coras | c3638fe | 2018-08-24 13:58:49 -0700 | [diff] [blame] | 694 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 695 | /* Send fifo segment fd if needed */ |
| 696 | if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD) |
| 697 | { |
| 698 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 699 | fds[n_fds] = args.segment->fd; |
| 700 | n_fds += 1; |
| 701 | } |
| 702 | if (application_segment_manager_properties (app)->use_mq_eventfd) |
| 703 | { |
| 704 | fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 705 | fds[n_fds] = svm_msg_q_get_eventfd (args.evt_q); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 706 | n_fds += 1; |
| 707 | } |
| 708 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 709 | done: |
Klement Sekera | 0eb83f4 | 2021-12-02 16:36:34 +0000 | [diff] [blame] | 710 | REPLY_MACRO3 ( |
| 711 | VL_API_APP_WORKER_ADD_DEL_REPLY, |
| 712 | ((!rv && mp->is_add) ? vec_len (args.segment->name) : 0), ({ |
| 713 | rmp->is_add = mp->is_add; |
Florin Coras | ea5d5bd | 2024-03-29 18:28:35 -0700 | [diff] [blame] | 714 | rmp->wrk_index = mp->wrk_index; |
Klement Sekera | 0eb83f4 | 2021-12-02 16:36:34 +0000 | [diff] [blame] | 715 | if (!rv && mp->is_add) |
| 716 | { |
Florin Coras | ea5d5bd | 2024-03-29 18:28:35 -0700 | [diff] [blame] | 717 | rmp->wrk_index = clib_host_to_net_u32 (args.wrk_map_index); |
Florin Coras | 94a52d7 | 2023-12-01 18:47:45 -0800 | [diff] [blame] | 718 | rmp->segment_handle = clib_host_to_net_u64 (args.segment_handle); |
Klement Sekera | 0eb83f4 | 2021-12-02 16:36:34 +0000 | [diff] [blame] | 719 | rmp->app_event_queue_address = |
| 720 | fifo_segment_msg_q_offset ((fifo_segment_t *) args.segment, 0); |
| 721 | rmp->n_fds = n_fds; |
| 722 | rmp->fd_flags = fd_flags; |
| 723 | if (vec_len (args.segment->name)) |
| 724 | { |
| 725 | vl_api_vec_to_api_string (args.segment->name, |
| 726 | &rmp->segment_name); |
| 727 | } |
| 728 | } |
| 729 | })); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 730 | |
| 731 | if (n_fds) |
| 732 | session_send_fds (reg, fds, n_fds); |
| 733 | } |
| 734 | |
| 735 | static void |
Florin Coras | 888d9f0 | 2020-04-02 23:00:13 +0000 | [diff] [blame] | 736 | vl_api_application_detach_t_handler (vl_api_application_detach_t * mp) |
| 737 | { |
| 738 | vl_api_application_detach_reply_t *rmp; |
| 739 | int rv = VNET_API_ERROR_INVALID_VALUE_2; |
| 740 | vnet_app_detach_args_t _a, *a = &_a; |
| 741 | application_t *app; |
| 742 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 743 | if (!session_main_is_enabled () || appns_sapi_enabled ()) |
Florin Coras | 888d9f0 | 2020-04-02 23:00:13 +0000 | [diff] [blame] | 744 | { |
| 745 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 746 | goto done; |
| 747 | } |
| 748 | |
| 749 | app = application_lookup (mp->client_index); |
| 750 | if (app) |
| 751 | { |
| 752 | a->app_index = app->app_index; |
| 753 | a->api_client_index = mp->client_index; |
| 754 | rv = vnet_application_detach (a); |
Filip Tehlar | 0028e6f | 2023-06-28 10:47:32 +0200 | [diff] [blame] | 755 | if (rv) |
| 756 | { |
| 757 | clib_warning ("vnet_application_detach: %U", format_session_error, |
| 758 | rv); |
| 759 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 760 | } |
Florin Coras | 888d9f0 | 2020-04-02 23:00:13 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | done: |
| 764 | REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY); |
| 765 | } |
| 766 | |
| 767 | static void |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 768 | vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp) |
| 769 | { |
| 770 | vl_api_app_namespace_add_del_reply_t *rmp; |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 771 | u32 appns_index = 0; |
| 772 | u8 *ns_id = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 773 | int rv = 0; |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 774 | if (session_main_is_enabled () == 0) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 775 | { |
| 776 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 777 | goto done; |
| 778 | } |
| 779 | |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 780 | ns_id = vl_api_from_api_to_new_vec (mp, &mp->namespace_id); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 781 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 782 | vnet_app_namespace_add_del_args_t args = { |
| 783 | .ns_id = ns_id, |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 784 | .sock_name = 0, |
Florin Coras | 9a9adb2 | 2017-10-26 08:16:59 -0700 | [diff] [blame] | 785 | .secret = clib_net_to_host_u64 (mp->secret), |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 786 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 787 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 788 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 789 | .is_add = 1 |
| 790 | }; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 791 | rv = vnet_app_namespace_add_del (&args); |
| 792 | if (!rv) |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 793 | { |
| 794 | appns_index = app_namespace_index_from_id (ns_id); |
| 795 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 796 | { |
| 797 | clib_warning ("app ns lookup failed"); |
| 798 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 799 | } |
| 800 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 801 | vec_free (ns_id); |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 802 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 803 | done: |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 804 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({ |
| 805 | if (!rv) |
| 806 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 807 | })); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 810 | static void |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 811 | vl_api_app_namespace_add_del_v2_t_handler ( |
| 812 | vl_api_app_namespace_add_del_v2_t *mp) |
| 813 | { |
| 814 | vl_api_app_namespace_add_del_v2_reply_t *rmp; |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 815 | u8 *ns_id = 0; |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 816 | u32 appns_index = 0; |
| 817 | int rv = 0; |
| 818 | |
| 819 | if (session_main_is_enabled () == 0) |
| 820 | { |
| 821 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 822 | goto done; |
| 823 | } |
| 824 | |
| 825 | mp->namespace_id[sizeof (mp->namespace_id) - 1] = 0; |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 826 | ns_id = format (0, "%s", &mp->namespace_id); |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 827 | |
| 828 | vnet_app_namespace_add_del_args_t args = { |
| 829 | .ns_id = ns_id, |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 830 | .sock_name = 0, |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 831 | .secret = clib_net_to_host_u64 (mp->secret), |
| 832 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 833 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 834 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 835 | .is_add = 1 |
| 836 | }; |
| 837 | rv = vnet_app_namespace_add_del (&args); |
| 838 | if (!rv) |
| 839 | { |
| 840 | appns_index = app_namespace_index_from_id (ns_id); |
| 841 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 842 | { |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 843 | clib_warning ("app ns lookup failed id:%s", ns_id); |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 844 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 845 | } |
| 846 | } |
| 847 | vec_free (ns_id); |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 848 | |
| 849 | done: |
| 850 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_V2_REPLY, ({ |
| 851 | if (!rv) |
| 852 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 853 | })); |
| 854 | } |
| 855 | |
| 856 | static void |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 857 | vl_api_app_namespace_add_del_v4_t_handler ( |
| 858 | vl_api_app_namespace_add_del_v4_t *mp) |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 859 | { |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 860 | vl_api_app_namespace_add_del_v4_reply_t *rmp; |
| 861 | u8 *ns_id = 0, *sock_name = 0; |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 862 | u32 appns_index = 0; |
| 863 | int rv = 0; |
| 864 | if (session_main_is_enabled () == 0) |
| 865 | { |
| 866 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 867 | goto done; |
| 868 | } |
| 869 | mp->namespace_id[sizeof (mp->namespace_id) - 1] = 0; |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 870 | ns_id = format (0, "%s", &mp->namespace_id); |
Nathan Skrzypczak | b3ea73e | 2021-08-05 10:22:52 +0200 | [diff] [blame] | 871 | sock_name = vl_api_from_api_to_new_vec (mp, &mp->sock_name); |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 872 | vnet_app_namespace_add_del_args_t args = { |
| 873 | .ns_id = ns_id, |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 874 | .sock_name = sock_name, |
| 875 | .secret = clib_net_to_host_u64 (mp->secret), |
| 876 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 877 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 878 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 879 | .is_add = mp->is_add, |
| 880 | }; |
| 881 | rv = vnet_app_namespace_add_del (&args); |
| 882 | if (!rv && mp->is_add) |
| 883 | { |
| 884 | appns_index = app_namespace_index_from_id (ns_id); |
| 885 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 886 | { |
| 887 | clib_warning ("app ns lookup failed id:%s", ns_id); |
| 888 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 889 | } |
| 890 | } |
| 891 | vec_free (ns_id); |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 892 | vec_free (sock_name); |
| 893 | done: |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 894 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_V4_REPLY, ({ |
| 895 | if (!rv) |
| 896 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 897 | })); |
| 898 | } |
| 899 | |
| 900 | static void |
| 901 | vl_api_app_namespace_add_del_v3_t_handler ( |
| 902 | vl_api_app_namespace_add_del_v3_t *mp) |
| 903 | { |
| 904 | vl_api_app_namespace_add_del_v3_reply_t *rmp; |
| 905 | u8 *ns_id = 0, *sock_name = 0, *api_sock_name = 0; |
| 906 | u32 appns_index = 0; |
| 907 | int rv = 0; |
| 908 | if (session_main_is_enabled () == 0) |
| 909 | { |
| 910 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 911 | goto done; |
| 912 | } |
| 913 | mp->namespace_id[sizeof (mp->namespace_id) - 1] = 0; |
| 914 | ns_id = format (0, "%s", &mp->namespace_id); |
| 915 | api_sock_name = vl_api_from_api_to_new_vec (mp, &mp->sock_name); |
| 916 | mp->netns[sizeof (mp->netns) - 1] = 0; |
| 917 | if (strlen ((char *) mp->netns) != 0) |
| 918 | { |
| 919 | sock_name = |
| 920 | format (0, "abstract:%v,netns_name=%s", api_sock_name, &mp->netns); |
| 921 | } |
| 922 | else |
| 923 | { |
| 924 | sock_name = api_sock_name; |
| 925 | api_sock_name = 0; // for vec_free |
| 926 | } |
| 927 | |
| 928 | vnet_app_namespace_add_del_args_t args = { |
| 929 | .ns_id = ns_id, |
| 930 | .sock_name = sock_name, |
| 931 | .secret = clib_net_to_host_u64 (mp->secret), |
| 932 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 933 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 934 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 935 | .is_add = mp->is_add, |
| 936 | }; |
| 937 | rv = vnet_app_namespace_add_del (&args); |
| 938 | if (!rv && mp->is_add) |
| 939 | { |
| 940 | appns_index = app_namespace_index_from_id (ns_id); |
| 941 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 942 | { |
| 943 | clib_warning ("app ns lookup failed id:%s", ns_id); |
| 944 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 945 | } |
| 946 | } |
| 947 | vec_free (ns_id); |
| 948 | vec_free (sock_name); |
| 949 | vec_free (api_sock_name); |
| 950 | done: |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 951 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_V3_REPLY, ({ |
| 952 | if (!rv) |
| 953 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 954 | })); |
| 955 | } |
| 956 | |
| 957 | static void |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 958 | vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp) |
| 959 | { |
| 960 | vl_api_session_rule_add_del_reply_t *rmp; |
| 961 | session_rule_add_del_args_t args; |
| 962 | session_rule_table_add_del_args_t *table_args = &args.table_args; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 963 | int rv = 0; |
| 964 | |
Steven Luong | 2da273a | 2024-06-28 13:15:33 -0700 | [diff] [blame] | 965 | if (session_main_is_enabled () == 0) |
| 966 | { |
| 967 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 968 | goto done; |
| 969 | } |
| 970 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 971 | clib_memset (&args, 0, sizeof (args)); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 972 | |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 973 | ip_prefix_decode (&mp->lcl, &table_args->lcl); |
| 974 | ip_prefix_decode (&mp->rmt, &table_args->rmt); |
| 975 | |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 976 | table_args->lcl_port = mp->lcl_port; |
| 977 | table_args->rmt_port = mp->rmt_port; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 978 | table_args->action_index = clib_net_to_host_u32 (mp->action_index); |
| 979 | table_args->is_add = mp->is_add; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 980 | mp->tag[sizeof (mp->tag) - 1] = 0; |
| 981 | table_args->tag = format (0, "%s", mp->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 982 | args.appns_index = clib_net_to_host_u32 (mp->appns_index); |
| 983 | args.scope = mp->scope; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 984 | args.transport_proto = |
| 985 | api_session_transport_proto_decode (&mp->transport_proto) == |
| 986 | TRANSPORT_PROTO_UDP ? 1 : 0; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 987 | |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 988 | rv = vnet_session_rule_add_del (&args); |
| 989 | if (rv) |
Filip Tehlar | 0028e6f | 2023-06-28 10:47:32 +0200 | [diff] [blame] | 990 | { |
| 991 | clib_warning ("rule add del returned: %U", format_session_error, rv); |
| 992 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 993 | } |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 994 | vec_free (table_args->tag); |
Steven Luong | 2da273a | 2024-06-28 13:15:33 -0700 | [diff] [blame] | 995 | done: |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 996 | REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY); |
| 997 | } |
| 998 | |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 999 | static void |
| 1000 | send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1001 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1002 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1003 | { |
| 1004 | vl_api_session_rules_details_t *rmp = 0; |
| 1005 | session_mask_or_match_4_t *match = |
| 1006 | (session_mask_or_match_4_t *) & rule->match; |
| 1007 | session_mask_or_match_4_t *mask = |
| 1008 | (session_mask_or_match_4_t *) & rule->mask; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 1009 | fib_prefix_t lcl, rmt; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1010 | |
| 1011 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1012 | clib_memset (rmp, 0, sizeof (*rmp)); |
Filip Tehlar | 0046e97 | 2021-06-26 22:12:08 +0000 | [diff] [blame] | 1013 | rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SESSION_RULES_DETAILS); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1014 | rmp->context = context; |
| 1015 | |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 1016 | clib_memset (&lcl, 0, sizeof (lcl)); |
| 1017 | clib_memset (&rmt, 0, sizeof (rmt)); |
| 1018 | ip_set (&lcl.fp_addr, &match->lcl_ip, 1); |
| 1019 | ip_set (&rmt.fp_addr, &match->rmt_ip, 1); |
| 1020 | lcl.fp_len = ip4_mask_to_preflen (&mask->lcl_ip); |
| 1021 | rmt.fp_len = ip4_mask_to_preflen (&mask->rmt_ip); |
Steven Luong | 3dd81c0 | 2024-08-07 10:53:48 -0700 | [diff] [blame] | 1022 | lcl.fp_proto = FIB_PROTOCOL_IP4; |
| 1023 | rmt.fp_proto = FIB_PROTOCOL_IP4; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 1024 | |
| 1025 | ip_prefix_encode (&lcl, &rmp->lcl); |
| 1026 | ip_prefix_encode (&rmt, &rmp->rmt); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1027 | rmp->lcl_port = match->lcl_port; |
| 1028 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1029 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
| 1030 | rmp->scope = |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 1031 | is_local ? SESSION_RULE_SCOPE_API_LOCAL : SESSION_RULE_SCOPE_API_GLOBAL; |
| 1032 | rmp->transport_proto = api_session_transport_proto_encode (transport_proto); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1033 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1034 | if (tag) |
| 1035 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1036 | clib_memcpy_fast (rmp->tag, tag, vec_len (tag)); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1037 | rmp->tag[vec_len (tag)] = 0; |
| 1038 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1039 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1040 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | static void |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1044 | send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local, |
| 1045 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1046 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1047 | { |
| 1048 | vl_api_session_rules_details_t *rmp = 0; |
| 1049 | session_mask_or_match_6_t *match = |
| 1050 | (session_mask_or_match_6_t *) & rule->match; |
| 1051 | session_mask_or_match_6_t *mask = |
| 1052 | (session_mask_or_match_6_t *) & rule->mask; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 1053 | fib_prefix_t lcl, rmt; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1054 | |
| 1055 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1056 | clib_memset (rmp, 0, sizeof (*rmp)); |
Filip Tehlar | 0046e97 | 2021-06-26 22:12:08 +0000 | [diff] [blame] | 1057 | rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SESSION_RULES_DETAILS); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1058 | rmp->context = context; |
| 1059 | |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 1060 | clib_memset (&lcl, 0, sizeof (lcl)); |
| 1061 | clib_memset (&rmt, 0, sizeof (rmt)); |
| 1062 | ip_set (&lcl.fp_addr, &match->lcl_ip, 0); |
| 1063 | ip_set (&rmt.fp_addr, &match->rmt_ip, 0); |
| 1064 | lcl.fp_len = ip6_mask_to_preflen (&mask->lcl_ip); |
| 1065 | rmt.fp_len = ip6_mask_to_preflen (&mask->rmt_ip); |
Steven Luong | 3dd81c0 | 2024-08-07 10:53:48 -0700 | [diff] [blame] | 1066 | lcl.fp_proto = FIB_PROTOCOL_IP6; |
| 1067 | rmt.fp_proto = FIB_PROTOCOL_IP6; |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 1068 | |
| 1069 | ip_prefix_encode (&lcl, &rmp->lcl); |
| 1070 | ip_prefix_encode (&rmt, &rmp->rmt); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1071 | rmp->lcl_port = match->lcl_port; |
| 1072 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1073 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1074 | rmp->scope = |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 1075 | is_local ? SESSION_RULE_SCOPE_API_LOCAL : SESSION_RULE_SCOPE_API_GLOBAL; |
| 1076 | rmp->transport_proto = api_session_transport_proto_encode (transport_proto); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1077 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1078 | if (tag) |
| 1079 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1080 | clib_memcpy_fast (rmp->tag, tag, vec_len (tag)); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1081 | rmp->tag[vec_len (tag)] = 0; |
| 1082 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1083 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1084 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static void |
| 1088 | send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1089 | u8 tp, u8 is_local, u32 appns_index, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1090 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1091 | { |
| 1092 | mma_rule_16_t *rule16; |
| 1093 | mma_rule_40_t *rule40; |
| 1094 | mma_rules_table_16_t *srt16; |
| 1095 | mma_rules_table_40_t *srt40; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1096 | u32 ri; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1097 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1098 | if (is_local || fib_proto == FIB_PROTOCOL_IP4) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1099 | { |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1100 | u8 *tag = 0; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1101 | srt16 = &srt->session_rules_tables_16; |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1102 | pool_foreach (rule16, srt16->rules) { |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1103 | ri = mma_rules_table_rule_index_16 (srt16, rule16); |
| 1104 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1105 | send_session_rule_details4 (rule16, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1106 | reg, context); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1107 | } |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1108 | } |
| 1109 | if (is_local || fib_proto == FIB_PROTOCOL_IP6) |
| 1110 | { |
| 1111 | u8 *tag = 0; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1112 | srt40 = &srt->session_rules_tables_40; |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1113 | pool_foreach (rule40, srt40->rules) { |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1114 | ri = mma_rules_table_rule_index_40 (srt40, rule40); |
| 1115 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1116 | send_session_rule_details6 (rule40, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1117 | reg, context); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1118 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | static void |
Neale Ranns | 2b202bc | 2020-09-21 08:17:51 +0000 | [diff] [blame] | 1123 | vl_api_session_rules_dump_t_handler (vl_api_session_rules_dump_t * mp) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1124 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1125 | vl_api_registration_t *reg; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1126 | session_table_t *st; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1127 | u8 tp; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1128 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1129 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1130 | if (!reg) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1131 | return; |
| 1132 | |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1133 | session_table_foreach (st, ({ |
Florin Coras | 07063b8 | 2020-03-13 04:44:51 +0000 | [diff] [blame] | 1134 | for (tp = 0; tp < TRANSPORT_N_PROTOS; tp++) |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1135 | { |
| 1136 | send_session_rules_table_details (&st->session_rules[tp], |
| 1137 | st->active_fib_proto, tp, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1138 | st->is_local, st->appns_index, reg, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1139 | mp->context); |
| 1140 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1141 | })); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1144 | static void |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1145 | vl_api_app_add_cert_key_pair_t_handler (vl_api_app_add_cert_key_pair_t * mp) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1146 | { |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1147 | vl_api_app_add_cert_key_pair_reply_t *rmp; |
| 1148 | vnet_app_add_cert_key_pair_args_t _a, *a = &_a; |
| 1149 | u32 certkey_len, key_len, cert_len; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1150 | int rv = 0; |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1151 | if (session_main_is_enabled () == 0) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1152 | { |
| 1153 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1154 | goto done; |
| 1155 | } |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1156 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1157 | cert_len = clib_net_to_host_u16 (mp->cert_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1158 | if (cert_len > 10000) |
| 1159 | { |
| 1160 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1161 | goto done; |
| 1162 | } |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1163 | |
| 1164 | certkey_len = clib_net_to_host_u16 (mp->certkey_len); |
| 1165 | if (certkey_len < cert_len) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1166 | { |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1167 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1168 | goto done; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1169 | } |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1170 | |
| 1171 | key_len = certkey_len - cert_len; |
| 1172 | if (key_len > 10000) |
| 1173 | { |
| 1174 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1175 | goto done; |
| 1176 | } |
| 1177 | |
| 1178 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | a5a9efd | 2021-01-05 17:03:29 -0800 | [diff] [blame] | 1179 | a->cert = mp->certkey; |
| 1180 | a->key = mp->certkey + cert_len; |
| 1181 | a->cert_len = cert_len; |
| 1182 | a->key_len = key_len; |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1183 | rv = vnet_app_add_cert_key_pair (a); |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1184 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1185 | done: |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1186 | REPLY_MACRO2 (VL_API_APP_ADD_CERT_KEY_PAIR_REPLY, ({ |
| 1187 | if (!rv) |
Nathan Skrzypczak | 45ec9f4 | 2019-11-06 14:47:40 +0100 | [diff] [blame] | 1188 | rmp->index = clib_host_to_net_u32 (a->index); |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1189 | })); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | static void |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1193 | vl_api_app_del_cert_key_pair_t_handler (vl_api_app_del_cert_key_pair_t * mp) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1194 | { |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1195 | vl_api_app_del_cert_key_pair_reply_t *rmp; |
Nathan Skrzypczak | 45ec9f4 | 2019-11-06 14:47:40 +0100 | [diff] [blame] | 1196 | u32 ckpair_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1197 | int rv = 0; |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1198 | if (session_main_is_enabled () == 0) |
| 1199 | { |
| 1200 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1201 | goto done; |
| 1202 | } |
Nathan Skrzypczak | 45ec9f4 | 2019-11-06 14:47:40 +0100 | [diff] [blame] | 1203 | ckpair_index = clib_net_to_host_u32 (mp->index); |
| 1204 | rv = vnet_app_del_cert_key_pair (ckpair_index); |
Filip Tehlar | 0028e6f | 2023-06-28 10:47:32 +0200 | [diff] [blame] | 1205 | if (rv) |
| 1206 | { |
| 1207 | clib_warning ("vnet_app_del_cert_key_pair: %U", format_session_error, |
| 1208 | rv); |
| 1209 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1210 | } |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1211 | |
| 1212 | done: |
Nathan Skrzypczak | 45ec9f4 | 2019-11-06 14:47:40 +0100 | [diff] [blame] | 1213 | REPLY_MACRO (VL_API_APP_DEL_CERT_KEY_PAIR_REPLY); |
Nathan Skrzypczak | 79f8953 | 2019-09-13 11:08:13 +0200 | [diff] [blame] | 1214 | } |
| 1215 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1216 | static clib_error_t * |
| 1217 | application_reaper_cb (u32 client_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1218 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1219 | application_t *app = application_lookup (client_index); |
| 1220 | vnet_app_detach_args_t _a, *a = &_a; |
| 1221 | if (app) |
| 1222 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1223 | a->app_index = app->app_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 1224 | a->api_client_index = client_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1225 | vnet_application_detach (a); |
| 1226 | } |
| 1227 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1228 | } |
| 1229 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1230 | VL_MSG_API_REAPER_FUNCTION (application_reaper_cb); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1231 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1232 | /* |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1233 | * Socket api functions |
| 1234 | */ |
| 1235 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1236 | static int |
| 1237 | mq_send_add_segment_sapi_cb (u32 app_wrk_index, u64 segment_handle) |
| 1238 | { |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 1239 | session_app_add_segment_msg_t m = { 0 }; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1240 | app_worker_t *app_wrk; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1241 | fifo_segment_t *fs; |
| 1242 | ssvm_private_t *sp; |
| 1243 | u8 fd_flags = 0; |
| 1244 | |
| 1245 | app_wrk = app_worker_get (app_wrk_index); |
| 1246 | |
| 1247 | fs = segment_manager_get_segment_w_handle (segment_handle); |
| 1248 | sp = &fs->ssvm; |
| 1249 | ASSERT (ssvm_type (sp) == SSVM_SEGMENT_MEMFD); |
| 1250 | |
| 1251 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1252 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 1253 | m.segment_size = sp->ssvm_size; |
| 1254 | m.fd_flags = fd_flags; |
| 1255 | m.segment_handle = segment_handle; |
| 1256 | strncpy ((char *) m.segment_name, (char *) sp->name, |
| 1257 | sizeof (m.segment_name) - 1); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1258 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 1259 | app_wrk_send_ctrl_evt_fd (app_wrk, SESSION_CTRL_EVT_APP_ADD_SEGMENT, &m, |
| 1260 | sizeof (m), sp->fd); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1261 | |
| 1262 | return 0; |
| 1263 | } |
| 1264 | |
| 1265 | static int |
| 1266 | mq_send_del_segment_sapi_cb (u32 app_wrk_index, u64 segment_handle) |
| 1267 | { |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 1268 | session_app_del_segment_msg_t m = { 0 }; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1269 | app_worker_t *app_wrk; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1270 | |
| 1271 | app_wrk = app_worker_get (app_wrk_index); |
| 1272 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 1273 | m.segment_handle = segment_handle; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1274 | |
Florin Coras | 20c2423 | 2021-11-22 21:19:01 -0800 | [diff] [blame] | 1275 | app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_APP_DEL_SEGMENT, &m, |
| 1276 | sizeof (m)); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1277 | |
| 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | static session_cb_vft_t session_mq_sapi_cb_vft = { |
| 1282 | .session_accept_callback = mq_send_session_accepted_cb, |
| 1283 | .session_disconnect_callback = mq_send_session_disconnected_cb, |
| 1284 | .session_connected_callback = mq_send_session_connected_cb, |
| 1285 | .session_reset_callback = mq_send_session_reset_cb, |
| 1286 | .session_migrate_callback = mq_send_session_migrate_cb, |
| 1287 | .session_cleanup_callback = mq_send_session_cleanup_cb, |
Florin Coras | 4f3da9c | 2024-02-29 18:19:30 -0800 | [diff] [blame] | 1288 | .session_listened_callback = mq_send_session_bound_cb, |
| 1289 | .session_unlistened_callback = mq_send_unlisten_cb, |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1290 | .add_segment_callback = mq_send_add_segment_sapi_cb, |
| 1291 | .del_segment_callback = mq_send_del_segment_sapi_cb, |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 1292 | .builtin_app_rx_callback = mq_send_io_rx_event, |
| 1293 | .builtin_app_tx_callback = mq_send_io_tx_event, |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1294 | }; |
| 1295 | |
| 1296 | static void |
| 1297 | session_api_attach_handler (app_namespace_t * app_ns, clib_socket_t * cs, |
| 1298 | app_sapi_attach_msg_t * mp) |
| 1299 | { |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1300 | int rv = 0, *fds = 0, n_fds = 0, i, n_workers; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1301 | vnet_app_attach_args_t _a, *a = &_a; |
| 1302 | app_sapi_attach_reply_msg_t *rmp; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1303 | u8 fd_flags = 0, ctrl_thread; |
| 1304 | app_ns_api_handle_t *handle; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1305 | fifo_segment_t *rx_mqs_seg; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1306 | app_sapi_msg_t msg = { 0 }; |
| 1307 | app_worker_t *app_wrk; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1308 | application_t *app; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1309 | svm_msg_q_t *rx_mq; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1310 | |
| 1311 | /* Make sure name is null terminated */ |
| 1312 | mp->name[63] = 0; |
| 1313 | |
| 1314 | clib_memset (a, 0, sizeof (*a)); |
| 1315 | a->api_client_index = appns_sapi_socket_handle (app_ns, cs); |
| 1316 | a->name = format (0, "%s", (char *) mp->name); |
| 1317 | a->options = mp->options; |
| 1318 | a->session_cb_vft = &session_mq_sapi_cb_vft; |
| 1319 | a->use_sock_api = 1; |
| 1320 | a->options[APP_OPTIONS_NAMESPACE] = app_namespace_index (app_ns); |
| 1321 | |
| 1322 | if ((rv = vnet_application_attach (a))) |
| 1323 | { |
| 1324 | clib_warning ("attach returned: %d", rv); |
| 1325 | goto done; |
| 1326 | } |
| 1327 | |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1328 | n_workers = vlib_num_workers (); |
| 1329 | vec_validate (fds, 3 /* segs + tx evtfd */ + n_workers); |
| 1330 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1331 | /* Send event queues segment */ |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1332 | app = application_get (a->app_index); |
| 1333 | rx_mqs_seg = application_get_rx_mqs_segment (app); |
| 1334 | |
| 1335 | fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT; |
| 1336 | fds[n_fds] = rx_mqs_seg->ssvm.fd; |
| 1337 | n_fds += 1; |
| 1338 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1339 | /* Send fifo segment fd if needed */ |
| 1340 | if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD) |
| 1341 | { |
| 1342 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 1343 | fds[n_fds] = a->segment->fd; |
| 1344 | n_fds += 1; |
| 1345 | } |
| 1346 | if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD) |
| 1347 | { |
| 1348 | fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 1349 | fds[n_fds] = svm_msg_q_get_eventfd (a->app_evt_q); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1350 | n_fds += 1; |
| 1351 | } |
| 1352 | |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1353 | if (application_use_private_rx_mqs ()) |
| 1354 | { |
| 1355 | fd_flags |= SESSION_FD_F_VPP_MQ_EVENTFD; |
| 1356 | for (i = 0; i < n_workers + 1; i++) |
| 1357 | { |
| 1358 | rx_mq = application_rx_mq_get (app, i); |
| 1359 | fds[n_fds] = svm_msg_q_get_eventfd (rx_mq); |
| 1360 | n_fds += 1; |
| 1361 | } |
| 1362 | } |
| 1363 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1364 | done: |
| 1365 | |
| 1366 | msg.type = APP_SAPI_MSG_TYPE_ATTACH_REPLY; |
| 1367 | rmp = &msg.attach_reply; |
| 1368 | rmp->retval = rv; |
| 1369 | if (!rv) |
| 1370 | { |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1371 | ctrl_thread = n_workers ? 1 : 0; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1372 | rmp->app_index = a->app_index; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 1373 | rmp->app_mq = |
| 1374 | fifo_segment_msg_q_offset ((fifo_segment_t *) a->segment, 0); |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1375 | rmp->vpp_ctrl_mq = fifo_segment_msg_q_offset (rx_mqs_seg, ctrl_thread); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1376 | rmp->vpp_ctrl_mq_thread = ctrl_thread; |
| 1377 | rmp->n_fds = n_fds; |
| 1378 | rmp->fd_flags = fd_flags; |
| 1379 | /* No segment name and size since we only support memfds |
| 1380 | * in this configuration */ |
| 1381 | rmp->segment_handle = a->segment_handle; |
| 1382 | rmp->api_client_handle = a->api_client_index; |
| 1383 | |
| 1384 | /* Update app index for socket */ |
| 1385 | handle = (app_ns_api_handle_t *) & cs->private_data; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1386 | app_wrk = application_get_worker (app, 0); |
| 1387 | handle->aah_app_wrk_index = app_wrk->wrk_index; |
| 1388 | } |
| 1389 | |
| 1390 | clib_socket_sendmsg (cs, &msg, sizeof (msg), fds, n_fds); |
| 1391 | vec_free (a->name); |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 1392 | vec_free (fds); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Florin Coras | 98078ab | 2021-08-12 18:12:09 -0700 | [diff] [blame] | 1395 | void |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1396 | sapi_socket_close_w_handle (u32 api_handle) |
| 1397 | { |
| 1398 | app_namespace_t *app_ns = app_namespace_get (api_handle >> 16); |
| 1399 | u16 sock_index = api_handle & 0xffff; |
| 1400 | app_ns_api_handle_t *handle; |
| 1401 | clib_socket_t *cs; |
| 1402 | clib_file_t *cf; |
| 1403 | |
| 1404 | cs = appns_sapi_get_socket (app_ns, sock_index); |
| 1405 | if (!cs) |
| 1406 | return; |
| 1407 | |
| 1408 | handle = (app_ns_api_handle_t *) & cs->private_data; |
| 1409 | cf = clib_file_get (&file_main, handle->aah_file_index); |
| 1410 | clib_file_del (&file_main, cf); |
| 1411 | |
| 1412 | clib_socket_close (cs); |
| 1413 | appns_sapi_free_socket (app_ns, cs); |
| 1414 | } |
| 1415 | |
| 1416 | static void |
| 1417 | sapi_add_del_worker_handler (app_namespace_t * app_ns, |
| 1418 | clib_socket_t * cs, |
| 1419 | app_sapi_worker_add_del_msg_t * mp) |
| 1420 | { |
| 1421 | int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0; |
| 1422 | app_sapi_worker_add_del_reply_msg_t *rmp; |
| 1423 | app_ns_api_handle_t *handle; |
| 1424 | app_sapi_msg_t msg = { 0 }; |
| 1425 | app_worker_t *app_wrk; |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 1426 | u32 sapi_handle = -1; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1427 | application_t *app; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1428 | u8 fd_flags = 0; |
| 1429 | |
| 1430 | app = application_get_if_valid (mp->app_index); |
| 1431 | if (!app) |
| 1432 | { |
Filip Tehlar | 0028e6f | 2023-06-28 10:47:32 +0200 | [diff] [blame] | 1433 | rv = SESSION_E_INVALID; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1434 | goto done; |
| 1435 | } |
| 1436 | |
| 1437 | sapi_handle = appns_sapi_socket_handle (app_ns, cs); |
| 1438 | |
| 1439 | vnet_app_worker_add_del_args_t args = { |
| 1440 | .app_index = app->app_index, |
| 1441 | .wrk_map_index = mp->wrk_index, |
| 1442 | .api_client_index = sapi_handle, |
| 1443 | .is_add = mp->is_add |
| 1444 | }; |
| 1445 | rv = vnet_app_worker_add_del (&args); |
| 1446 | if (rv) |
| 1447 | { |
Filip Tehlar | 0028e6f | 2023-06-28 10:47:32 +0200 | [diff] [blame] | 1448 | clib_warning ("app worker add/del returned: %U", format_session_error, |
| 1449 | rv); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1450 | goto done; |
| 1451 | } |
| 1452 | |
| 1453 | if (!mp->is_add) |
Florin Coras | 98078ab | 2021-08-12 18:12:09 -0700 | [diff] [blame] | 1454 | goto done; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1455 | |
| 1456 | /* Send fifo segment fd if needed */ |
| 1457 | if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD) |
| 1458 | { |
| 1459 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 1460 | fds[n_fds] = args.segment->fd; |
| 1461 | n_fds += 1; |
| 1462 | } |
| 1463 | if (application_segment_manager_properties (app)->use_mq_eventfd) |
| 1464 | { |
| 1465 | fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 1466 | fds[n_fds] = svm_msg_q_get_eventfd (args.evt_q); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1467 | n_fds += 1; |
| 1468 | } |
| 1469 | |
| 1470 | done: |
| 1471 | |
Florin Coras | 18710d5 | 2023-11-28 15:28:16 -0800 | [diff] [blame] | 1472 | /* With app sock api socket expected to be closed, no reply */ |
| 1473 | if (!mp->is_add && appns_sapi_enabled ()) |
| 1474 | return; |
| 1475 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1476 | msg.type = APP_SAPI_MSG_TYPE_ADD_DEL_WORKER_REPLY; |
| 1477 | rmp = &msg.worker_add_del_reply; |
| 1478 | rmp->retval = rv; |
| 1479 | rmp->is_add = mp->is_add; |
Florin Coras | ea5d5bd | 2024-03-29 18:28:35 -0700 | [diff] [blame] | 1480 | rmp->wrk_index = mp->wrk_index; |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 1481 | rmp->api_client_handle = sapi_handle; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1482 | if (!rv && mp->is_add) |
| 1483 | { |
Florin Coras | ea5d5bd | 2024-03-29 18:28:35 -0700 | [diff] [blame] | 1484 | rmp->wrk_index = args.wrk_map_index; |
Florin Coras | 94a52d7 | 2023-12-01 18:47:45 -0800 | [diff] [blame] | 1485 | rmp->segment_handle = args.segment_handle; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1486 | /* No segment name and size. This supports only memfds */ |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 1487 | rmp->app_event_queue_address = |
| 1488 | fifo_segment_msg_q_offset ((fifo_segment_t *) args.segment, 0); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1489 | rmp->n_fds = n_fds; |
| 1490 | rmp->fd_flags = fd_flags; |
| 1491 | |
| 1492 | /* Update app index for socket */ |
| 1493 | handle = (app_ns_api_handle_t *) & cs->private_data; |
| 1494 | app_wrk = application_get_worker (app, args.wrk_map_index); |
| 1495 | handle->aah_app_wrk_index = app_wrk->wrk_index; |
| 1496 | } |
| 1497 | |
| 1498 | clib_socket_sendmsg (cs, &msg, sizeof (msg), fds, n_fds); |
| 1499 | } |
| 1500 | |
Filip Tehlar | 447e51d | 2022-02-18 08:49:43 +0000 | [diff] [blame] | 1501 | /* This is a workaround for the case when session layer starts reading |
| 1502 | * the socket before the client actualy sends the data |
| 1503 | */ |
| 1504 | static clib_error_t * |
| 1505 | sapi_socket_receive_wait (clib_socket_t *cs, u8 *msg, u32 msg_len) |
| 1506 | { |
| 1507 | clib_error_t *err; |
| 1508 | int n_tries = 5; |
| 1509 | |
| 1510 | while (1) |
| 1511 | { |
| 1512 | err = clib_socket_recvmsg (cs, msg, msg_len, 0, 0); |
| 1513 | if (!err) |
| 1514 | break; |
| 1515 | |
| 1516 | if (!n_tries) |
| 1517 | return err; |
| 1518 | |
| 1519 | n_tries--; |
| 1520 | usleep (1); |
| 1521 | } |
| 1522 | |
| 1523 | return err; |
| 1524 | } |
| 1525 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1526 | static void |
Florin Coras | e191d76 | 2021-08-11 14:55:49 -0700 | [diff] [blame] | 1527 | sapi_add_del_cert_key_handler (app_namespace_t *app_ns, clib_socket_t *cs, |
| 1528 | app_sapi_cert_key_add_del_msg_t *mp) |
| 1529 | { |
| 1530 | vnet_app_add_cert_key_pair_args_t _a, *a = &_a; |
| 1531 | app_sapi_cert_key_add_del_reply_msg_t *rmp; |
| 1532 | app_sapi_msg_t msg = { 0 }; |
| 1533 | int rv = 0; |
| 1534 | |
| 1535 | if (mp->is_add) |
| 1536 | { |
| 1537 | const u32 max_certkey_len = 2e4, max_cert_len = 1e4, max_key_len = 1e4; |
| 1538 | clib_error_t *err; |
| 1539 | u8 *certkey = 0; |
| 1540 | u32 key_len; |
| 1541 | |
| 1542 | if (mp->certkey_len > max_certkey_len) |
| 1543 | { |
| 1544 | rv = SESSION_E_INVALID; |
| 1545 | goto send_reply; |
| 1546 | } |
| 1547 | |
| 1548 | vec_validate (certkey, mp->certkey_len - 1); |
Filip Tehlar | 447e51d | 2022-02-18 08:49:43 +0000 | [diff] [blame] | 1549 | |
| 1550 | err = sapi_socket_receive_wait (cs, certkey, mp->certkey_len); |
Florin Coras | e191d76 | 2021-08-11 14:55:49 -0700 | [diff] [blame] | 1551 | if (err) |
| 1552 | { |
| 1553 | clib_error_report (err); |
Florin Coras | e191d76 | 2021-08-11 14:55:49 -0700 | [diff] [blame] | 1554 | rv = SESSION_E_INVALID; |
| 1555 | goto send_reply; |
| 1556 | } |
| 1557 | |
| 1558 | if (mp->cert_len > max_cert_len) |
| 1559 | { |
| 1560 | rv = SESSION_E_INVALID; |
| 1561 | goto send_reply; |
| 1562 | } |
| 1563 | |
| 1564 | if (mp->certkey_len < mp->cert_len) |
| 1565 | { |
| 1566 | rv = SESSION_E_INVALID; |
| 1567 | goto send_reply; |
| 1568 | } |
| 1569 | |
| 1570 | key_len = mp->certkey_len - mp->cert_len; |
| 1571 | if (key_len > max_key_len) |
| 1572 | { |
| 1573 | rv = SESSION_E_INVALID; |
| 1574 | goto send_reply; |
| 1575 | } |
| 1576 | |
| 1577 | clib_memset (a, 0, sizeof (*a)); |
| 1578 | a->cert = certkey; |
| 1579 | a->key = certkey + mp->cert_len; |
| 1580 | a->cert_len = mp->cert_len; |
| 1581 | a->key_len = key_len; |
| 1582 | rv = vnet_app_add_cert_key_pair (a); |
| 1583 | |
| 1584 | vec_free (certkey); |
| 1585 | } |
| 1586 | else |
| 1587 | { |
| 1588 | rv = vnet_app_del_cert_key_pair (mp->index); |
| 1589 | } |
| 1590 | |
| 1591 | send_reply: |
| 1592 | |
| 1593 | msg.type = APP_SAPI_MSG_TYPE_ADD_DEL_CERT_KEY_REPLY; |
| 1594 | rmp = &msg.cert_key_add_del_reply; |
| 1595 | rmp->retval = rv; |
| 1596 | rmp->context = mp->context; |
| 1597 | if (!rv && mp->is_add) |
| 1598 | rmp->index = a->index; |
| 1599 | |
| 1600 | clib_socket_sendmsg (cs, &msg, sizeof (msg), 0, 0); |
| 1601 | } |
| 1602 | |
| 1603 | static void |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1604 | sapi_socket_detach (app_namespace_t * app_ns, clib_socket_t * cs) |
| 1605 | { |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1606 | app_ns_api_handle_t *handle; |
| 1607 | app_worker_t *app_wrk; |
| 1608 | u32 api_client_handle; |
| 1609 | |
| 1610 | api_client_handle = appns_sapi_socket_handle (app_ns, cs); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1611 | |
Florin Coras | f99a7d6 | 2020-09-14 10:29:29 -0700 | [diff] [blame] | 1612 | /* Cleanup everything because app worker closed socket or crashed */ |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1613 | handle = (app_ns_api_handle_t *) & cs->private_data; |
Filip Tehlar | 9c32f05 | 2022-03-11 11:12:56 +0000 | [diff] [blame] | 1614 | app_wrk = app_worker_get_if_valid (handle->aah_app_wrk_index); |
| 1615 | if (!app_wrk) |
| 1616 | return; |
Florin Coras | f99a7d6 | 2020-09-14 10:29:29 -0700 | [diff] [blame] | 1617 | |
| 1618 | vnet_app_worker_add_del_args_t args = { |
| 1619 | .app_index = app_wrk->app_index, |
| 1620 | .wrk_map_index = app_wrk->wrk_map_index, |
| 1621 | .api_client_index = api_client_handle, |
| 1622 | .is_add = 0 |
| 1623 | }; |
| 1624 | /* Send rpc to main thread for worker barrier */ |
| 1625 | vlib_rpc_call_main_thread (vnet_app_worker_add_del, (u8 *) & args, |
| 1626 | sizeof (args)); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | static clib_error_t * |
| 1630 | sapi_sock_read_ready (clib_file_t * cf) |
| 1631 | { |
| 1632 | app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data; |
Florin Coras | 7360e3d | 2020-09-18 16:15:47 -0700 | [diff] [blame] | 1633 | vlib_main_t *vm = vlib_get_main (); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1634 | app_sapi_msg_t msg = { 0 }; |
| 1635 | app_namespace_t *app_ns; |
| 1636 | clib_error_t *err = 0; |
| 1637 | clib_socket_t *cs; |
| 1638 | |
| 1639 | app_ns = app_namespace_get (handle->aah_app_ns_index); |
| 1640 | cs = appns_sapi_get_socket (app_ns, handle->aah_sock_index); |
| 1641 | if (!cs) |
| 1642 | goto error; |
| 1643 | |
| 1644 | err = clib_socket_recvmsg (cs, &msg, sizeof (msg), 0, 0); |
| 1645 | if (err) |
| 1646 | { |
| 1647 | clib_error_free (err); |
| 1648 | sapi_socket_detach (app_ns, cs); |
| 1649 | goto error; |
| 1650 | } |
| 1651 | |
| 1652 | handle = (app_ns_api_handle_t *) & cs->private_data; |
| 1653 | |
Florin Coras | 7360e3d | 2020-09-18 16:15:47 -0700 | [diff] [blame] | 1654 | vlib_worker_thread_barrier_sync (vm); |
| 1655 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1656 | switch (msg.type) |
| 1657 | { |
| 1658 | case APP_SAPI_MSG_TYPE_ATTACH: |
| 1659 | session_api_attach_handler (app_ns, cs, &msg.attach); |
| 1660 | break; |
| 1661 | case APP_SAPI_MSG_TYPE_ADD_DEL_WORKER: |
| 1662 | sapi_add_del_worker_handler (app_ns, cs, &msg.worker_add_del); |
| 1663 | break; |
Florin Coras | e191d76 | 2021-08-11 14:55:49 -0700 | [diff] [blame] | 1664 | case APP_SAPI_MSG_TYPE_ADD_DEL_CERT_KEY: |
| 1665 | sapi_add_del_cert_key_handler (app_ns, cs, &msg.cert_key_add_del); |
| 1666 | break; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1667 | default: |
| 1668 | clib_warning ("app wrk %u unknown message type: %u", |
| 1669 | handle->aah_app_wrk_index, msg.type); |
| 1670 | break; |
| 1671 | } |
| 1672 | |
Florin Coras | 7360e3d | 2020-09-18 16:15:47 -0700 | [diff] [blame] | 1673 | vlib_worker_thread_barrier_release (vm); |
| 1674 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1675 | error: |
| 1676 | return 0; |
| 1677 | } |
| 1678 | |
| 1679 | static clib_error_t * |
| 1680 | sapi_sock_write_ready (clib_file_t * cf) |
| 1681 | { |
| 1682 | app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data; |
| 1683 | clib_warning ("called for app ns %u", handle->aah_app_ns_index); |
| 1684 | return 0; |
| 1685 | } |
| 1686 | |
| 1687 | static clib_error_t * |
| 1688 | sapi_sock_error (clib_file_t * cf) |
| 1689 | { |
| 1690 | app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data; |
| 1691 | app_namespace_t *app_ns; |
| 1692 | clib_socket_t *cs; |
| 1693 | |
| 1694 | app_ns = app_namespace_get (handle->aah_app_ns_index); |
| 1695 | cs = appns_sapi_get_socket (app_ns, handle->aah_sock_index); |
| 1696 | if (!cs) |
| 1697 | return 0; |
| 1698 | |
| 1699 | sapi_socket_detach (app_ns, cs); |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
| 1703 | static clib_error_t * |
| 1704 | sapi_sock_accept_ready (clib_file_t * scf) |
| 1705 | { |
| 1706 | app_ns_api_handle_t handle = *(app_ns_api_handle_t *) & scf->private_data; |
| 1707 | app_namespace_t *app_ns; |
| 1708 | clib_file_t cf = { 0 }; |
| 1709 | clib_error_t *err = 0; |
| 1710 | clib_socket_t *ccs, *scs; |
| 1711 | |
| 1712 | /* Listener files point to namespace */ |
| 1713 | app_ns = app_namespace_get (handle.aah_app_ns_index); |
| 1714 | |
| 1715 | /* |
| 1716 | * Initialize client socket |
| 1717 | */ |
| 1718 | ccs = appns_sapi_alloc_socket (app_ns); |
| 1719 | |
| 1720 | /* Grab server socket after client is initialized */ |
| 1721 | scs = appns_sapi_get_socket (app_ns, handle.aah_sock_index); |
| 1722 | if (!scs) |
| 1723 | goto error; |
| 1724 | |
| 1725 | err = clib_socket_accept (scs, ccs); |
| 1726 | if (err) |
| 1727 | { |
| 1728 | clib_error_report (err); |
| 1729 | goto error; |
| 1730 | } |
| 1731 | |
| 1732 | cf.read_function = sapi_sock_read_ready; |
| 1733 | cf.write_function = sapi_sock_write_ready; |
| 1734 | cf.error_function = sapi_sock_error; |
| 1735 | cf.file_descriptor = ccs->fd; |
| 1736 | /* File points to app namespace and socket */ |
| 1737 | handle.aah_sock_index = appns_sapi_socket_index (app_ns, ccs); |
Florin Coras | 6b6c10b | 2020-09-24 11:58:28 -0700 | [diff] [blame] | 1738 | cf.private_data = handle.as_u64; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1739 | cf.description = format (0, "app sock conn fd: %d", ccs->fd); |
| 1740 | |
| 1741 | /* Poll until we get an attach message. Socket points to file and |
| 1742 | * application that owns the socket */ |
| 1743 | handle.aah_app_wrk_index = APP_INVALID_INDEX; |
| 1744 | handle.aah_file_index = clib_file_add (&file_main, &cf); |
Florin Coras | 6b6c10b | 2020-09-24 11:58:28 -0700 | [diff] [blame] | 1745 | ccs->private_data = handle.as_u64; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1746 | |
| 1747 | return err; |
| 1748 | |
| 1749 | error: |
| 1750 | appns_sapi_free_socket (app_ns, ccs); |
| 1751 | return err; |
| 1752 | } |
| 1753 | |
Nathan Skrzypczak | b3ea73e | 2021-08-05 10:22:52 +0200 | [diff] [blame] | 1754 | void |
| 1755 | appns_sapi_del_ns_socket (app_namespace_t *app_ns) |
| 1756 | { |
| 1757 | app_ns_api_handle_t *handle; |
| 1758 | clib_socket_t *cs; |
| 1759 | |
| 1760 | pool_foreach (cs, app_ns->app_sockets) |
| 1761 | { |
| 1762 | handle = (app_ns_api_handle_t *) &cs->private_data; |
| 1763 | clib_file_del_by_index (&file_main, handle->aah_file_index); |
| 1764 | |
| 1765 | clib_socket_close (cs); |
| 1766 | clib_socket_free (cs); |
| 1767 | } |
| 1768 | pool_free (app_ns->app_sockets); |
| 1769 | } |
| 1770 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1771 | int |
| 1772 | appns_sapi_add_ns_socket (app_namespace_t * app_ns) |
| 1773 | { |
| 1774 | char *subdir = "/app_ns_sockets/"; |
| 1775 | app_ns_api_handle_t *handle; |
| 1776 | clib_file_t cf = { 0 }; |
| 1777 | struct stat file_stat; |
| 1778 | clib_error_t *err; |
| 1779 | clib_socket_t *cs; |
Benoît Ganne | 0bb670e | 2021-09-09 12:00:00 +0200 | [diff] [blame] | 1780 | char dir[4096]; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1781 | |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 1782 | snprintf (dir, sizeof (dir), "%s%s", vlib_unix_get_runtime_dir (), subdir); |
Nathan Skrzypczak | 1a9e2f9 | 2021-07-28 19:35:08 +0200 | [diff] [blame] | 1783 | |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 1784 | if (!app_ns->sock_name) |
| 1785 | app_ns->sock_name = format (0, "%s%v%c", dir, app_ns->ns_id, 0); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1786 | |
| 1787 | /* |
| 1788 | * Create and initialize socket to listen on |
| 1789 | */ |
| 1790 | cs = appns_sapi_alloc_socket (app_ns); |
Nathan Skrzypczak | b3ea73e | 2021-08-05 10:22:52 +0200 | [diff] [blame] | 1791 | cs->config = (char *) vec_dup (app_ns->sock_name); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1792 | cs->flags = CLIB_SOCKET_F_IS_SERVER | |
| 1793 | CLIB_SOCKET_F_ALLOW_GROUP_WRITE | |
| 1794 | CLIB_SOCKET_F_SEQPACKET | CLIB_SOCKET_F_PASSCRED; |
| 1795 | |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 1796 | if (clib_socket_prefix_get_type (cs->config) == CLIB_SOCKET_TYPE_UNIX) |
| 1797 | { |
| 1798 | err = vlib_unix_recursive_mkdir ((char *) dir); |
| 1799 | if (err) |
| 1800 | { |
| 1801 | clib_error_report (err); |
Filip Tehlar | 0028e6f | 2023-06-28 10:47:32 +0200 | [diff] [blame] | 1802 | return SESSION_E_SYSCALL; |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | if ((err = clib_socket_init (cs))) |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1807 | { |
| 1808 | clib_error_report (err); |
Benoît Ganne | 0bb670e | 2021-09-09 12:00:00 +0200 | [diff] [blame] | 1809 | return -1; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 1812 | if (clib_socket_prefix_get_type (cs->config) == CLIB_SOCKET_TYPE_UNIX && |
| 1813 | stat ((char *) app_ns->sock_name, &file_stat) == -1) |
Benoît Ganne | 0bb670e | 2021-09-09 12:00:00 +0200 | [diff] [blame] | 1814 | return -1; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1815 | |
| 1816 | /* |
| 1817 | * Start polling it |
| 1818 | */ |
| 1819 | cf.read_function = sapi_sock_accept_ready; |
| 1820 | cf.file_descriptor = cs->fd; |
| 1821 | /* File points to namespace */ |
| 1822 | handle = (app_ns_api_handle_t *) & cf.private_data; |
| 1823 | handle->aah_app_ns_index = app_namespace_index (app_ns); |
| 1824 | handle->aah_sock_index = appns_sapi_socket_index (app_ns, cs); |
| 1825 | cf.description = format (0, "app sock listener: %s", app_ns->sock_name); |
| 1826 | |
| 1827 | /* Socket points to clib file index */ |
| 1828 | handle = (app_ns_api_handle_t *) & cs->private_data; |
| 1829 | handle->aah_file_index = clib_file_add (&file_main, &cf); |
| 1830 | handle->aah_app_wrk_index = APP_INVALID_INDEX; |
| 1831 | |
Benoît Ganne | 0bb670e | 2021-09-09 12:00:00 +0200 | [diff] [blame] | 1832 | return 0; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Filip Tehlar | 0046e97 | 2021-06-26 22:12:08 +0000 | [diff] [blame] | 1835 | #include <vnet/session/session.api.c> |
| 1836 | static clib_error_t * |
| 1837 | session_api_hookup (vlib_main_t *vm) |
| 1838 | { |
| 1839 | /* |
| 1840 | * Set up the (msg_name, crc, message-id) table |
| 1841 | */ |
| 1842 | REPLY_MSG_ID_BASE = setup_message_id_table (); |
| 1843 | |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
| 1847 | VLIB_API_INIT_FUNCTION (session_api_hookup); |
| 1848 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 1849 | /* |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1850 | * fd.io coding-style-patch-verification: ON |
| 1851 | * |
| 1852 | * Local Variables: |
| 1853 | * eval: (c-set-style "gnu") |
| 1854 | * End: |
| 1855 | */ |