Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 1 | /* |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 2 | ************************************************************************** |
Murat Sezgin | f7ddd08 | 2017-06-29 15:09:34 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +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 |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 6 | * above copyright notice and this permission notice appear in all copies. |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 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. |
Murat Sezgin | 84ca651 | 2014-04-14 13:57:24 -0700 | [diff] [blame] | 14 | ************************************************************************** |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 15 | */ |
| 16 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 17 | #include "nss_tx_rx_common.h" |
Sachin Shashidhar | 4743045 | 2018-08-13 16:36:18 -0700 | [diff] [blame] | 18 | #include "nss_tun6rd_log.h" |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 19 | |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 20 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 21 | * nss_tun6rd_handler() |
| 22 | * Handle NSS -> HLOS messages for 6rd tunnel |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 23 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 24 | static void nss_tun6rd_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 25 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 26 | struct nss_tun6rd_msg *ntm = (struct nss_tun6rd_msg *)ncm; |
| 27 | void *ctx; |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 28 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 29 | nss_tun6rd_msg_callback_t cb; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 30 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 31 | BUG_ON(!nss_is_dynamic_interface(ncm->interface)); |
| 32 | |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 33 | /* |
Sachin Shashidhar | 4743045 | 2018-08-13 16:36:18 -0700 | [diff] [blame] | 34 | * Trace Messages |
| 35 | */ |
| 36 | nss_tun6rd_log_rx_msg(ntm); |
| 37 | |
| 38 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 39 | * Is this a valid request/response packet? |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 40 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 41 | if (ncm->type >= NSS_TUN6RD_MAX) { |
| 42 | nss_warning("%p: received invalid message %d for Tun6RD interface", nss_ctx, ncm->type); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 43 | return; |
| 44 | } |
| 45 | |
Suruchi Agarwal | ef8a870 | 2016-01-08 12:40:08 -0800 | [diff] [blame] | 46 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_tun6rd_msg)) { |
| 47 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 48 | return; |
| 49 | } |
| 50 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 51 | /* |
| 52 | * Update the callback and app_data for NOTIFY messages, tun6rd sends all notify messages |
| 53 | * to the same callback/app_data. |
| 54 | */ |
Suruchi Agarwal | e4ad24a | 2018-06-11 12:03:46 +0530 | [diff] [blame] | 55 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 56 | ncm->cb = (nss_ptr_t)nss_ctx->nss_top->tun6rd_msg_callback; |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 57 | } |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 58 | |
| 59 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 60 | * Log failures |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 61 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 62 | nss_core_log_msg_failures(nss_ctx, ncm); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 63 | |
| 64 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 65 | * Do we have a call back |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 66 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 67 | if (!ncm->cb) { |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 68 | return; |
| 69 | } |
| 70 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 71 | /* |
| 72 | * callback |
| 73 | */ |
| 74 | cb = (nss_tun6rd_msg_callback_t)ncm->cb; |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 75 | ctx = nss_ctx->subsys_dp_register[ncm->interface].ndev; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 76 | |
| 77 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 78 | * call 6rd tunnel callback |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 79 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 80 | if (!ctx) { |
| 81 | nss_warning("%p: Event received for 6rd tunnel interface %d before registration", nss_ctx, ncm->interface); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 82 | return; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 83 | } |
| 84 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 85 | cb(ctx, ntm); |
| 86 | } |
| 87 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 88 | /* |
| 89 | * nss_tun6rd_tx() |
| 90 | * Transmit a tun6rd message to NSSFW |
| 91 | */ |
| 92 | nss_tx_status_t nss_tun6rd_tx(struct nss_ctx_instance *nss_ctx, struct nss_tun6rd_msg *msg) |
| 93 | { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 94 | struct nss_cmn_msg *ncm = &msg->cm; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 95 | |
| 96 | /* |
Sachin Shashidhar | 4743045 | 2018-08-13 16:36:18 -0700 | [diff] [blame] | 97 | * Trace Messages |
| 98 | */ |
| 99 | nss_tun6rd_log_tx_msg(msg); |
| 100 | |
| 101 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 102 | * Sanity check the message |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 103 | */ |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 104 | if (!nss_is_dynamic_interface(ncm->interface)) { |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 105 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 106 | return NSS_TX_FAILURE; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 107 | } |
| 108 | |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 109 | if (ncm->type > NSS_TUN6RD_MAX) { |
| 110 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 111 | return NSS_TX_FAILURE; |
| 112 | } |
| 113 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 114 | return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 118 | *********************************** |
| 119 | * Register/Unregister/Miscellaneous APIs |
| 120 | *********************************** |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 121 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * nss_register_tun6rd_if() |
| 125 | */ |
Murat Sezgin | f7ddd08 | 2017-06-29 15:09:34 -0700 | [diff] [blame] | 126 | struct nss_ctx_instance *nss_register_tun6rd_if(uint32_t if_num, uint32_t type, nss_tun6rd_callback_t tun6rd_callback, |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 127 | nss_tun6rd_msg_callback_t event_callback, struct net_device *netdev, uint32_t features) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 128 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 129 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tun6rd_handler_id]; |
| 130 | |
| 131 | nss_assert(nss_ctx); |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 132 | nss_assert((if_num >= NSS_DYNAMIC_IF_START) && (if_num < NSS_SPECIAL_IF_START)); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 133 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 134 | nss_core_register_subsys_dp(nss_ctx, if_num, tun6rd_callback, NULL, NULL, netdev, features); |
Murat Sezgin | f7ddd08 | 2017-06-29 15:09:34 -0700 | [diff] [blame] | 135 | nss_ctx->subsys_dp_register[if_num].type = type; |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 136 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 137 | nss_top_main.tun6rd_msg_callback = event_callback; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 138 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 139 | nss_core_register_handler(nss_ctx, if_num, nss_tun6rd_handler, NULL); |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 140 | |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 141 | return nss_ctx; |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 145 | * nss_tun6rd_get_context() |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 146 | */ |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 147 | struct nss_ctx_instance *nss_tun6rd_get_context() |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 148 | { |
| 149 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tun6rd_handler_id]; |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 153 | * nss_unregister_tun6rd_if() |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 154 | */ |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 155 | void nss_unregister_tun6rd_if(uint32_t if_num) |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 156 | { |
Stephen Wang | 84e0e99 | 2016-09-07 12:31:40 -0700 | [diff] [blame] | 157 | struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.tun6rd_handler_id]; |
| 158 | |
| 159 | nss_assert(nss_ctx); |
Sakthi Vignesh Radhakrishnan | 7a8fbe9 | 2015-02-23 16:23:29 -0800 | [diff] [blame] | 160 | nss_assert(nss_is_dynamic_interface(if_num)); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 161 | |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 162 | nss_core_unregister_subsys_dp(nss_ctx, if_num); |
Murat Sezgin | f7ddd08 | 2017-06-29 15:09:34 -0700 | [diff] [blame] | 163 | nss_ctx->subsys_dp_register[if_num].type = 0; |
Sundarajan Srinivasan | 7037484 | 2014-11-19 15:22:52 -0800 | [diff] [blame] | 164 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 165 | nss_top_main.tun6rd_msg_callback = NULL; |
| 166 | |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 167 | nss_core_unregister_handler(nss_ctx, if_num); |
Bharath M Kumar | 0d87e91 | 2013-08-12 18:32:57 +0530 | [diff] [blame] | 168 | } |
| 169 | |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 170 | /* |
| 171 | * nss_tun6rd_msg_init() |
| 172 | * Initialize nss_tun6rd msg. |
| 173 | */ |
| 174 | void nss_tun6rd_msg_init(struct nss_tun6rd_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data) |
| 175 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 176 | nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data); |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Zhu Ken | 0308242 | 2014-08-11 15:21:42 +0800 | [diff] [blame] | 179 | EXPORT_SYMBOL(nss_tun6rd_get_context); |
Radha krishna Simha Jiguru | 62a29e6 | 2014-04-04 17:28:53 +0530 | [diff] [blame] | 180 | EXPORT_SYMBOL(nss_tun6rd_tx); |
| 181 | EXPORT_SYMBOL(nss_register_tun6rd_if); |
| 182 | EXPORT_SYMBOL(nss_unregister_tun6rd_if); |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 183 | EXPORT_SYMBOL(nss_tun6rd_msg_init); |