Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 3 | * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | ************************************************************************** |
| 15 | */ |
| 16 | |
| 17 | #include <net/sock.h> |
| 18 | #include "nss_tx_rx_common.h" |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 19 | #include "nss_pptp_stats.h" |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 20 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 21 | #define NSS_PPTP_TX_TIMEOUT 3000 /* 3 Seconds */ |
| 22 | |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 23 | /* |
| 24 | * Data structures to store pptp nss debug stats |
| 25 | */ |
| 26 | static DEFINE_SPINLOCK(nss_pptp_session_debug_stats_lock); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 27 | static struct nss_pptp_stats_session_debug nss_pptp_session_debug_stats[NSS_MAX_PPTP_DYNAMIC_INTERFACES]; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 28 | |
| 29 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 30 | * Private data structure |
| 31 | */ |
| 32 | static struct nss_pptp_pvt { |
| 33 | struct semaphore sem; |
| 34 | struct completion complete; |
| 35 | int response; |
| 36 | void *cb; |
| 37 | void *app_data; |
| 38 | } pptp_pvt; |
| 39 | |
| 40 | /* |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 41 | * nss_pptp_session_debug_stats_sync |
| 42 | * Per session debug stats for pptp |
| 43 | */ |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame^] | 44 | void nss_pptp_session_debug_stats_sync(struct nss_ctx_instance *nss_ctx, |
| 45 | struct nss_pptp_sync_session_stats_msg *stats_msg, uint16_t if_num) |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 46 | { |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame^] | 47 | int i, j, if_type; |
| 48 | |
| 49 | if_type = nss_dynamic_interface_get_type(nss_pptp_get_context(), if_num); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 50 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 51 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 52 | if (nss_pptp_session_debug_stats[i].if_num == if_num) { |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 53 | break; |
| 54 | } |
| 55 | } |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame^] | 56 | |
| 57 | if (i == NSS_MAX_PPTP_DYNAMIC_INTERFACES) { |
| 58 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if (if_type == NSS_DYNAMIC_INTERFACE_TYPE_PPTP_OUTER) { |
| 63 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_RX_PACKETS] += |
| 64 | stats_msg->node_stats.rx_packets; |
| 65 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_RX_BYTES] += |
| 66 | stats_msg->node_stats.rx_bytes; |
| 67 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_TX_PACKETS] += |
| 68 | stats_msg->node_stats.tx_packets; |
| 69 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_TX_BYTES] += |
| 70 | stats_msg->node_stats.tx_bytes; |
| 71 | for (j = 0; j < NSS_MAX_NUM_PRI; j++) { |
| 72 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_DECAP_RX_QUEUE_0_DROP + j] += |
| 73 | stats_msg->node_stats.rx_dropped[j]; |
| 74 | } |
| 75 | } else { |
| 76 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_RX_PACKETS] += |
| 77 | stats_msg->node_stats.rx_packets; |
| 78 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_RX_BYTES] += |
| 79 | stats_msg->node_stats.rx_bytes; |
| 80 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_TX_PACKETS] += |
| 81 | stats_msg->node_stats.tx_packets; |
| 82 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_TX_BYTES] += |
| 83 | stats_msg->node_stats.tx_bytes; |
| 84 | for (j = 0; j < NSS_MAX_NUM_PRI; j++) { |
| 85 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_ENCAP_RX_QUEUE_0_DROP + j] += |
| 86 | stats_msg->node_stats.rx_dropped[j]; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_ENCAP_HEADROOM_ERR] += |
| 91 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_HEADROOM_ERR]; |
| 92 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_ENCAP_SMALL_SIZE] += |
| 93 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_SMALL_SIZE]; |
| 94 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_ENCAP_PNODE_ENQUEUE_FAIL] += |
| 95 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_ENCAP_PNODE_ENQUEUE_FAIL]; |
| 96 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_NO_SEQ_NOR_ACK] += |
| 97 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_NO_SEQ_NOR_ACK]; |
| 98 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_INVAL_GRE_FLAGS] += |
| 99 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_GRE_FLAGS]; |
| 100 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_INVAL_GRE_PROTO] += |
| 101 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_GRE_PROTO]; |
| 102 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_WRONG_SEQ] += |
| 103 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_WRONG_SEQ]; |
| 104 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_INVAL_PPP_HDR] += |
| 105 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_INVAL_PPP_HDR]; |
| 106 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_PPP_LCP] += |
| 107 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_PPP_LCP]; |
| 108 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_UNSUPPORTED_PPP_PROTO] += |
| 109 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_UNSUPPORTED_PPP_PROTO]; |
| 110 | nss_pptp_session_debug_stats[i].stats[NSS_PPTP_STATS_SESSION_DECAP_PNODE_ENQUEUE_FAIL] += |
| 111 | stats_msg->exception_events[PPTP_EXCEPTION_EVENT_DECAP_PNODE_ENQUEUE_FAIL]; |
| 112 | |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 113 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * nss_pptp_global_session_stats_get() |
| 118 | * Get session pptp statitics. |
| 119 | */ |
| 120 | void nss_pptp_session_debug_stats_get(void *stats_mem) |
| 121 | { |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 122 | struct nss_pptp_stats_session_debug *stats = (struct nss_pptp_stats_session_debug *)stats_mem; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 123 | int i; |
| 124 | |
| 125 | if (!stats) { |
| 126 | nss_warning("No memory to copy pptp session stats"); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 131 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 132 | if (nss_pptp_session_debug_stats[i].valid) { |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 133 | memcpy(stats, &nss_pptp_session_debug_stats[i], sizeof(struct nss_pptp_stats_session_debug)); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 134 | stats++; |
| 135 | } |
| 136 | } |
| 137 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 138 | } |
| 139 | |
| 140 | /* |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame^] | 141 | * nss_pptp_verify_if_num() |
| 142 | * Verify if_num passed to us. |
| 143 | */ |
| 144 | static bool nss_pptp_verify_if_num(uint32_t if_num) |
| 145 | { |
| 146 | uint32_t if_type; |
| 147 | |
| 148 | if (nss_is_dynamic_interface(if_num) == false) { |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | if_type = nss_dynamic_interface_get_type(nss_pptp_get_context(), if_num); |
| 153 | switch(if_type) { |
| 154 | case NSS_DYNAMIC_INTERFACE_TYPE_PPTP_INNER: |
| 155 | case NSS_DYNAMIC_INTERFACE_TYPE_PPTP_OUTER: |
| 156 | case NSS_DYNAMIC_INTERFACE_TYPE_PPTP_HOST_INNER: |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | /* |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 164 | * nss_pptp_handler() |
| 165 | * Handle NSS -> HLOS messages for pptp tunnel |
| 166 | */ |
| 167 | static void nss_pptp_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 168 | { |
| 169 | struct nss_pptp_msg *ntm = (struct nss_pptp_msg *)ncm; |
| 170 | void *ctx; |
| 171 | |
| 172 | nss_pptp_msg_callback_t cb; |
| 173 | |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame^] | 174 | BUG_ON(!nss_pptp_verify_if_num(ncm->interface)); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * Is this a valid request/response packet? |
| 178 | */ |
| 179 | if (ncm->type >= NSS_PPTP_MSG_MAX) { |
| 180 | nss_warning("%p: received invalid message %d for PPTP interface", nss_ctx, ncm->type); |
| 181 | return; |
| 182 | } |
| 183 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 184 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_pptp_msg)) { |
| 185 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 186 | return; |
| 187 | } |
| 188 | |
| 189 | switch (ntm->cm.type) { |
| 190 | |
| 191 | case NSS_PPTP_MSG_SYNC_STATS: |
| 192 | /* |
| 193 | * session debug stats embeded in session stats msg |
| 194 | */ |
| 195 | nss_pptp_session_debug_stats_sync(nss_ctx, &ntm->msg.stats, ncm->interface); |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Update the callback and app_data for NOTIFY messages, pptp sends all notify messages |
| 201 | * to the same callback/app_data. |
| 202 | */ |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 203 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 204 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->pptp_msg_callback; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 205 | ncm->app_data = (nss_ptr_t)nss_ctx->subsys_dp_register[ncm->interface].app_data; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* |
| 209 | * Log failures |
| 210 | */ |
| 211 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 212 | |
| 213 | /* |
| 214 | * Do we have a call back |
| 215 | */ |
| 216 | if (!ncm->cb) { |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * callback |
| 222 | */ |
| 223 | cb = (nss_pptp_msg_callback_t)ncm->cb; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 224 | ctx = (void *)ncm->app_data; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * call pptp tunnel callback |
| 228 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 229 | if (!cb) { |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 230 | nss_warning("%p: Event received for pptp tunnel interface %d before registration", nss_ctx, ncm->interface); |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | cb(ctx, ntm); |
| 235 | } |
| 236 | |
| 237 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 238 | * nss_pptp_tx_msg() |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 239 | * Transmit a pptp message to NSS firmware |
| 240 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 241 | static nss_tx_status_t nss_pptp_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_pptp_msg *msg) |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 242 | { |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 243 | struct nss_cmn_msg *ncm = &msg->cm; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Sanity check the message |
| 247 | */ |
| 248 | if (!nss_is_dynamic_interface(ncm->interface)) { |
| 249 | nss_warning("%p: tx request for non dynamic interface: %d", nss_ctx, ncm->interface); |
| 250 | return NSS_TX_FAILURE; |
| 251 | } |
| 252 | |
| 253 | if (ncm->type > NSS_PPTP_MSG_MAX) { |
| 254 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 255 | return NSS_TX_FAILURE; |
| 256 | } |
| 257 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 258 | return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 262 | * nss_pptp_sync_msg_callback() |
| 263 | * Callback to handle the completion of NSS->HLOS messages. |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 264 | */ |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 265 | static void nss_pptp_sync_msg_callback(void *app_data, struct nss_pptp_msg *nim) |
| 266 | { |
| 267 | nss_pptp_msg_callback_t callback = (nss_pptp_msg_callback_t)pptp_pvt.cb; |
| 268 | void *data = pptp_pvt.app_data; |
| 269 | |
| 270 | pptp_pvt.cb = NULL; |
| 271 | pptp_pvt.app_data = NULL; |
| 272 | |
| 273 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 274 | nss_warning("pptp Error response %d\n", nim->cm.response); |
| 275 | |
| 276 | pptp_pvt.response = NSS_TX_FAILURE; |
| 277 | if (callback) { |
| 278 | callback(data, nim); |
| 279 | } |
| 280 | |
| 281 | complete(&pptp_pvt.complete); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | pptp_pvt.response = NSS_TX_SUCCESS; |
| 286 | if (callback) { |
| 287 | callback(data, nim); |
| 288 | } |
| 289 | |
| 290 | complete(&pptp_pvt.complete); |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * nss_pptp_tx_msg() |
| 295 | * Transmit a pptp message to NSS firmware synchronously. |
| 296 | */ |
| 297 | nss_tx_status_t nss_pptp_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_pptp_msg *msg) |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 298 | { |
| 299 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 300 | nss_tx_status_t status; |
| 301 | int ret = 0; |
| 302 | |
| 303 | down(&pptp_pvt.sem); |
| 304 | pptp_pvt.cb = (void *)msg->cm.cb; |
| 305 | pptp_pvt.app_data = (void *)msg->cm.app_data; |
| 306 | |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 307 | msg->cm.cb = (nss_ptr_t)nss_pptp_sync_msg_callback; |
| 308 | msg->cm.app_data = (nss_ptr_t)NULL; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 309 | |
| 310 | status = nss_pptp_tx_msg(nss_ctx, msg); |
| 311 | if (status != NSS_TX_SUCCESS) { |
| 312 | nss_warning("%p: pptp_tx_msg failed\n", nss_ctx); |
| 313 | up(&pptp_pvt.sem); |
| 314 | return status; |
| 315 | } |
| 316 | |
| 317 | ret = wait_for_completion_timeout(&pptp_pvt.complete, msecs_to_jiffies(NSS_PPTP_TX_TIMEOUT)); |
| 318 | |
| 319 | if (!ret) { |
| 320 | nss_warning("%p: PPTP msg tx failed due to timeout\n", nss_ctx); |
| 321 | pptp_pvt.response = NSS_TX_FAILURE; |
| 322 | } |
| 323 | |
| 324 | status = pptp_pvt.response; |
| 325 | up(&pptp_pvt.sem); |
| 326 | return status; |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | * nss_pptp_tx_buf() |
| 331 | * Send packet to pptp interface owned by NSS |
| 332 | */ |
| 333 | nss_tx_status_t nss_pptp_tx_buf(struct nss_ctx_instance *nss_ctx, uint32_t if_num, struct sk_buff *skb) |
| 334 | { |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 335 | nss_trace("%p: pptp If Tx packet, id:%d, data=%p", nss_ctx, if_num, skb->data); |
| 336 | |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame^] | 337 | return nss_core_send_packet(nss_ctx, skb, if_num, 0); |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /* |
| 341 | * nss_register_pptp_if() |
| 342 | */ |
| 343 | struct nss_ctx_instance *nss_register_pptp_if(uint32_t if_num, |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame^] | 344 | uint32_t type, |
| 345 | nss_pptp_callback_t pptp_data_callback, |
| 346 | nss_pptp_msg_callback_t notification_callback, |
| 347 | struct net_device *netdev, |
| 348 | uint32_t features, |
| 349 | void *app_ctx) |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 350 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 351 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id]; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 352 | int i = 0; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 353 | |
| 354 | nss_assert(nss_ctx); |
Swaraj Sha | 11f9e7c | 2018-08-21 17:53:49 +0530 | [diff] [blame^] | 355 | nss_assert(nss_pptp_verify_if_num()); |
| 356 | |
| 357 | nss_ctx->subsys_dp_register[if_num].type = type; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 358 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 359 | nss_core_register_subsys_dp(nss_ctx, if_num, pptp_data_callback, NULL, app_ctx, netdev, features); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 360 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 361 | nss_top_main.pptp_msg_callback = notification_callback; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 362 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 363 | nss_core_register_handler(nss_ctx, if_num, nss_pptp_handler, NULL); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 364 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 365 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 366 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 367 | if (!nss_pptp_session_debug_stats[i].valid) { |
| 368 | nss_pptp_session_debug_stats[i].valid = true; |
| 369 | nss_pptp_session_debug_stats[i].if_num = if_num; |
| 370 | nss_pptp_session_debug_stats[i].if_index = netdev->ifindex; |
| 371 | break; |
| 372 | } |
| 373 | } |
| 374 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 375 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 376 | return nss_ctx; |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /* |
| 380 | * nss_unregister_pptp_if() |
| 381 | */ |
| 382 | void nss_unregister_pptp_if(uint32_t if_num) |
| 383 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 384 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id]; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 385 | int i; |
adil irfan | b9a45f0 | 2018-04-09 19:13:53 +0530 | [diff] [blame] | 386 | int j; |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 387 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 388 | nss_assert(nss_ctx); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 389 | nss_assert(nss_is_dynamic_interface(if_num)); |
| 390 | |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 391 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 392 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
adil irfan | b9a45f0 | 2018-04-09 19:13:53 +0530 | [diff] [blame] | 393 | if (nss_pptp_session_debug_stats[i].valid == true && |
| 394 | nss_pptp_session_debug_stats[i].if_num == if_num) { |
| 395 | nss_pptp_session_debug_stats[i].valid = false; |
| 396 | nss_pptp_session_debug_stats[i].if_num = 0; |
| 397 | nss_pptp_session_debug_stats[i].if_index = 0; |
| 398 | for (j = 0; j < NSS_PPTP_STATS_SESSION_MAX; j++) |
| 399 | nss_pptp_session_debug_stats[i].stats[j] = 0; |
| 400 | break; |
| 401 | } |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 402 | } |
| 403 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 404 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 405 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 406 | |
| 407 | nss_top_main.pptp_msg_callback = NULL; |
| 408 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 409 | nss_core_unregister_handler(nss_ctx, if_num); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /* |
| 413 | * nss_get_pptp_context() |
| 414 | */ |
| 415 | struct nss_ctx_instance *nss_pptp_get_context() |
| 416 | { |
| 417 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.pptp_handler_id]; |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * nss_pptp_msg_init() |
| 422 | * Initialize nss_pptp msg. |
| 423 | */ |
| 424 | void nss_pptp_msg_init(struct nss_pptp_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data) |
| 425 | { |
| 426 | nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data); |
| 427 | } |
| 428 | |
| 429 | /* nss_pptp_register_handler() |
| 430 | * debugfs stats msg handler received on static pptp interface |
| 431 | */ |
| 432 | void nss_pptp_register_handler(void) |
| 433 | { |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 434 | int i; |
| 435 | |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 436 | nss_info("nss_pptp_register_handler"); |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 437 | nss_core_register_handler(nss_pptp_get_context(), NSS_PPTP_INTERFACE, nss_pptp_handler, NULL); |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 438 | |
| 439 | spin_lock_bh(&nss_pptp_session_debug_stats_lock); |
| 440 | for (i = 0; i < NSS_MAX_PPTP_DYNAMIC_INTERFACES; i++) { |
| 441 | nss_pptp_session_debug_stats[i].valid = false; |
| 442 | nss_pptp_session_debug_stats[i].if_num = 0; |
| 443 | nss_pptp_session_debug_stats[i].if_index = 0; |
| 444 | } |
| 445 | spin_unlock_bh(&nss_pptp_session_debug_stats_lock); |
| 446 | |
| 447 | sema_init(&pptp_pvt.sem, 1); |
| 448 | init_completion(&pptp_pvt.complete); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 449 | |
| 450 | nss_pptp_stats_dentry_create(); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | EXPORT_SYMBOL(nss_pptp_get_context); |
Shyam Sunder | e351f1b | 2015-12-17 14:11:51 +0530 | [diff] [blame] | 454 | EXPORT_SYMBOL(nss_pptp_tx_msg_sync); |
| 455 | EXPORT_SYMBOL(nss_pptp_tx_buf); |
Shyam Sunder | 66e889d | 2015-11-02 15:31:20 +0530 | [diff] [blame] | 456 | EXPORT_SYMBOL(nss_unregister_pptp_if); |
| 457 | EXPORT_SYMBOL(nss_pptp_msg_init); |
| 458 | EXPORT_SYMBOL(nss_register_pptp_if); |