Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
| 3 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 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 | /* |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 18 | * nss_ipv4.c |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 19 | * NSS IPv4 APIs |
| 20 | */ |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame^] | 21 | #include <linux/sysctl.h> |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 22 | #include <linux/ppp_channel.h> |
| 23 | #include "nss_tx_rx_common.h" |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 24 | |
| 25 | extern void nss_rx_metadata_ipv4_rule_establish(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_rule_establish *nire); |
Sakthi Vignesh Radhakrishnan | 515f8c2 | 2014-06-21 15:04:19 -0700 | [diff] [blame] | 26 | extern void nss_rx_metadata_ipv4_create_response(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 27 | extern void nss_rx_ipv4_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs); |
| 28 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame^] | 29 | int nss_ipv4_conn_cfg __read_mostly = 4096; |
| 30 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 31 | /* |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 32 | * nss_ipv4_driver_conn_sync_update() |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 33 | * Update driver specific information from the messsage. |
| 34 | */ |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 35 | static void nss_ipv4_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs) |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 36 | { |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 37 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 38 | struct net_device *pppoe_dev = NULL; |
| 39 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Update statistics maintained by NSS driver |
| 42 | */ |
| 43 | spin_lock_bh(&nss_top->stats_lock); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 44 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count; |
| 45 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count; |
| 46 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count; |
| 47 | nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_BYTES] += nirs->flow_tx_byte_count + nirs->return_tx_byte_count; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 48 | spin_unlock_bh(&nss_top->stats_lock); |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * Update the PPPoE interface stats, if there is any PPPoE session on the interfaces. |
| 52 | */ |
| 53 | if (nirs->flow_pppoe_session_id) { |
| 54 | pppoe_dev = ppp_session_to_netdev(nirs->flow_pppoe_session_id, (uint8_t *)nirs->flow_pppoe_remote_mac); |
| 55 | if (pppoe_dev) { |
| 56 | ppp_update_stats(pppoe_dev, nirs->flow_rx_packet_count, nirs->flow_rx_byte_count, |
| 57 | nirs->flow_tx_packet_count, nirs->flow_tx_byte_count); |
| 58 | dev_put(pppoe_dev); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (nirs->return_pppoe_session_id) { |
| 63 | pppoe_dev = ppp_session_to_netdev(nirs->return_pppoe_session_id, (uint8_t *)nirs->return_pppoe_remote_mac); |
| 64 | if (pppoe_dev) { |
| 65 | ppp_update_stats(pppoe_dev, nirs->return_rx_packet_count, nirs->return_rx_byte_count, |
| 66 | nirs->return_tx_packet_count, nirs->return_tx_byte_count); |
| 67 | dev_put(pppoe_dev); |
| 68 | } |
| 69 | } |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 70 | } |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 71 | |
| 72 | /* |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 73 | * nss_ipv4_driver_node_sync_update) |
| 74 | * Update driver specific information from the messsage. |
| 75 | */ |
| 76 | static void nss_ipv4_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_node_sync *nins) |
| 77 | { |
| 78 | struct nss_top_instance *nss_top = nss_ctx->nss_top; |
| 79 | uint32_t i; |
| 80 | |
| 81 | /* |
| 82 | * Update statistics maintained by NSS driver |
| 83 | */ |
| 84 | spin_lock_bh(&nss_top->stats_lock); |
| 85 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets; |
| 86 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes; |
| 87 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped; |
| 88 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets; |
| 89 | nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes; |
| 90 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 91 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_REQUESTS] += nins->ipv4_connection_create_requests; |
| 92 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_COLLISIONS] += nins->ipv4_connection_create_collisions; |
| 93 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_connection_create_invalid_interface; |
| 94 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_connection_destroy_requests; |
| 95 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_MISSES] += nins->ipv4_connection_destroy_misses; |
| 96 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_HITS] += nins->ipv4_connection_hash_hits; |
| 97 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_REORDERS] += nins->ipv4_connection_hash_reorders; |
| 98 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_FLUSHES] += nins->ipv4_connection_flushes; |
| 99 | nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_EVICTIONS] += nins->ipv4_connection_evictions; |
| 100 | |
| 101 | for (i = 0; i < NSS_EXCEPTION_EVENT_IPV4_MAX; i++) { |
| 102 | nss_top->stats_if_exception_ipv4[i] += nins->exception_events[i]; |
| 103 | } |
| 104 | spin_unlock_bh(&nss_top->stats_lock); |
| 105 | } |
| 106 | |
| 107 | /* |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 108 | * nss_ipv4_rx_msg_handler() |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 109 | * Handle NSS -> HLOS messages for IPv4 bridge/route |
| 110 | */ |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 111 | static void nss_ipv4_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 112 | { |
| 113 | struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm; |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 114 | nss_ipv4_msg_callback_t cb; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 115 | |
| 116 | BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE); |
| 117 | |
| 118 | /* |
| 119 | * Sanity check the message type |
| 120 | */ |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 121 | if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) { |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 122 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | if (ncm->len > sizeof(struct nss_ipv4_msg)) { |
| 127 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 128 | return; |
| 129 | } |
| 130 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 131 | /* |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 132 | * Log failures |
| 133 | */ |
| 134 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 135 | |
| 136 | /* |
| 137 | * Handle deprecated messages. Eventually these messages should be removed. |
| 138 | */ |
| 139 | switch (nim->cm.type) { |
| 140 | case NSS_IPV4_RX_ESTABLISH_RULE_MSG: |
| 141 | return nss_rx_metadata_ipv4_rule_establish(nss_ctx, &nim->msg.rule_establish); |
| 142 | break; |
| 143 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 144 | case NSS_IPV4_RX_NODE_STATS_SYNC_MSG: |
| 145 | /* |
| 146 | * Update driver statistics on node sync. |
| 147 | */ |
| 148 | nss_ipv4_driver_node_sync_update(nss_ctx, &nim->msg.node_stats); |
| 149 | break; |
| 150 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 151 | case NSS_IPV4_RX_CONN_STATS_SYNC_MSG: |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 152 | /* |
| 153 | * Update driver statistics on connection sync. |
| 154 | */ |
| 155 | nss_ipv4_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats); |
Sol Kavy | 4013e28 | 2014-04-06 15:57:00 -0700 | [diff] [blame] | 156 | nss_rx_ipv4_sync(nss_ctx, &nim->msg.conn_stats); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 157 | break; |
Sakthi Vignesh Radhakrishnan | 515f8c2 | 2014-06-21 15:04:19 -0700 | [diff] [blame] | 158 | |
| 159 | case NSS_IPV4_TX_CREATE_RULE_MSG: |
| 160 | nss_rx_metadata_ipv4_create_response(nss_ctx, nim); |
| 161 | break; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 165 | * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages |
| 166 | * to the same callback/app_data. |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 167 | */ |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 168 | if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) { |
| 169 | ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback; |
| 170 | ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx; |
| 171 | } |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 172 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 173 | /* |
| 174 | * Do we have a callback? |
| 175 | */ |
| 176 | if (!ncm->cb) { |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Callback |
| 182 | */ |
Sol Kavy | 57d24b4 | 2014-04-05 13:45:36 -0700 | [diff] [blame] | 183 | cb = (nss_ipv4_msg_callback_t)ncm->cb; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 184 | cb((void *)ncm->app_data, nim); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | * nss_ipv4_tx() |
| 189 | * Transmit an ipv4 message to the FW. |
| 190 | */ |
| 191 | nss_tx_status_t nss_ipv4_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim) |
| 192 | { |
| 193 | struct nss_ipv4_msg *nim2; |
| 194 | struct nss_cmn_msg *ncm = &nim->cm; |
| 195 | struct sk_buff *nbuf; |
| 196 | int32_t status; |
| 197 | |
| 198 | NSS_VERIFY_CTX_MAGIC(nss_ctx); |
| 199 | if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) { |
| 200 | nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx); |
| 201 | return NSS_TX_FAILURE_NOT_READY; |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Sanity check the message |
| 206 | */ |
| 207 | if (ncm->interface != NSS_IPV4_RX_INTERFACE) { |
| 208 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 209 | return NSS_TX_FAILURE; |
| 210 | } |
| 211 | |
Murat Sezgin | 5c8c736 | 2014-09-02 17:58:21 -0700 | [diff] [blame] | 212 | if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) { |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 213 | nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type); |
| 214 | return NSS_TX_FAILURE; |
| 215 | } |
| 216 | |
| 217 | if (ncm->len > sizeof(struct nss_ipv4_msg)) { |
| 218 | nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface); |
| 219 | return NSS_TX_FAILURE; |
| 220 | } |
| 221 | |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 222 | nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 223 | if (unlikely(!nbuf)) { |
| 224 | spin_lock_bh(&nss_ctx->nss_top->stats_lock); |
| 225 | nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++; |
| 226 | spin_unlock_bh(&nss_ctx->nss_top->stats_lock); |
| 227 | nss_warning("%p: msg dropped as command allocation failed", nss_ctx); |
| 228 | return NSS_TX_FAILURE; |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * Copy the message to our skb. |
| 233 | */ |
| 234 | nim2 = (struct nss_ipv4_msg *)skb_put(nbuf, sizeof(struct nss_ipv4_msg)); |
| 235 | memcpy(nim2, nim, sizeof(struct nss_ipv4_msg)); |
| 236 | |
| 237 | status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0); |
| 238 | if (status != NSS_CORE_STATUS_SUCCESS) { |
Pamidipati, Vijay | b6e3884 | 2014-09-16 10:26:05 +0530 | [diff] [blame] | 239 | dev_kfree_skb_any(nbuf); |
Sol Kavy | cd1bd5c | 2014-04-04 11:09:44 -0700 | [diff] [blame] | 240 | nss_warning("%p: unable to enqueue IPv4 msg\n", nss_ctx); |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 241 | return NSS_TX_FAILURE; |
| 242 | } |
| 243 | |
| 244 | nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit, |
| 245 | NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE); |
| 246 | |
| 247 | NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]); |
| 248 | return NSS_TX_SUCCESS; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | ********************************** |
| 253 | Register/Unregister/Miscellaneous APIs |
| 254 | ********************************** |
| 255 | */ |
| 256 | |
| 257 | /* |
| 258 | * nss_ipv4_notify_register() |
| 259 | * Register to received IPv4 events. |
| 260 | * |
| 261 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core? |
| 262 | */ |
| 263 | struct nss_ctx_instance *nss_ipv4_notify_register(nss_ipv4_msg_callback_t cb, void *app_data) |
| 264 | { |
| 265 | /* |
| 266 | * TODO: We need to have a new array in support of the new API |
| 267 | * TODO: If we use a per-context array, we would move the array into nss_ctx based. |
| 268 | */ |
| 269 | nss_top_main.ipv4_callback = cb; |
Abhishek Rastogi | e11f47b | 2014-04-04 18:43:32 +0530 | [diff] [blame] | 270 | nss_top_main.ipv4_ctx = app_data; |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 271 | return &nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
| 272 | } |
| 273 | |
| 274 | /* |
| 275 | * nss_ipv4_notify_unregister() |
| 276 | * Unregister to received IPv4 events. |
| 277 | * |
| 278 | * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core? |
| 279 | */ |
| 280 | void nss_ipv4_notify_unregister(void) |
| 281 | { |
| 282 | nss_top_main.ipv4_callback = NULL; |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * nss_ipv4_get_mgr() |
| 287 | * |
| 288 | * TODO: This only suppports a single ipv4, do we ever want to support more? |
| 289 | */ |
| 290 | struct nss_ctx_instance *nss_ipv4_get_mgr(void) |
| 291 | { |
| 292 | return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id]; |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | * nss_ipv4_register_handler() |
| 297 | * Register our handler to receive messages for this interface |
| 298 | */ |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 299 | void nss_ipv4_register_handler(void) |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 300 | { |
Sol Kavy | 2783c07 | 2014-04-05 12:53:13 -0700 | [diff] [blame] | 301 | if (nss_core_register_handler(NSS_IPV4_RX_INTERFACE, nss_ipv4_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) { |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 302 | nss_warning("IPv4 handler failed to register"); |
| 303 | } |
| 304 | } |
| 305 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame^] | 306 | /* |
| 307 | * nss_ipv4_conn_cfg_callback() |
| 308 | * call back function for the ipv6 connection configuration handler |
| 309 | */ |
| 310 | static void nss_ipv4_conn_cfg_callback(void *app_data, struct nss_if_msg *nim) |
| 311 | { |
| 312 | |
| 313 | if (nim->cm.response != NSS_CMN_RESPONSE_ACK) { |
| 314 | nss_warning("IPv4 connection configuration failed with error: %d\n", nim->cm.error); |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | nss_info("IPv4 connection configuration success: %d\n", nim->cm.error); |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * nss_ipv4_conn_cfg_handler() |
| 323 | * Sets the number of connections for IPv4 |
| 324 | */ |
| 325 | static int nss_ipv4_conn_cfg_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 326 | { |
| 327 | struct nss_top_instance *nss_top = &nss_top_main; |
| 328 | struct nss_ctx_instance *nss_ctx = &nss_top->nss[0]; |
| 329 | struct nss_ipv4_msg nim; |
| 330 | struct nss_ipv4_rule_conn_cfg_msg *nirccm; |
| 331 | nss_tx_status_t nss_tx_status; |
| 332 | int ret = 1; |
| 333 | uint32_t sum_of_conn = nss_ipv4_conn_cfg + nss_ipv6_conn_cfg; |
| 334 | |
| 335 | /* |
| 336 | * The input should be power of 2. |
| 337 | * Input for ipv4 and ipv6 sum togther should not exceed 8k |
| 338 | * Min. value should be at leat 256 connections. This is the |
| 339 | * minimum connections we will support for each of them. |
| 340 | */ |
| 341 | if ((nss_ipv4_conn_cfg & (nss_ipv4_conn_cfg - 1)) || |
| 342 | (sum_of_conn > MAX_TOTAL_NUM_CONN_IPV4_IPV6) || |
| 343 | (nss_ipv4_conn_cfg < MIN_NUM_CONN)) { |
| 344 | nss_warning("%p: input supported connections (%d) does not adhere\ |
| 345 | specifications\n1) not power of 2,\n2) is less than \ |
| 346 | min val: %d, OR\n IPv4/6 total exceeds %d\n", |
| 347 | nss_ctx, |
| 348 | nss_ipv4_conn_cfg, |
| 349 | MIN_NUM_CONN, |
| 350 | MAX_TOTAL_NUM_CONN_IPV4_IPV6); |
| 351 | return ret; |
| 352 | } |
| 353 | |
| 354 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 355 | |
| 356 | if (ret) { |
| 357 | return ret; |
| 358 | } |
| 359 | |
| 360 | if ((!write)) { |
| 361 | nss_warning("%p: IPv4 supported connections write failed: %d\n", nss_ctx, nss_ipv4_conn_cfg); |
| 362 | return ret; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, nss_ipv4_conn_cfg); |
| 367 | |
| 368 | nss_cmn_msg_init(&nim.cm, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG, |
| 369 | sizeof(struct nss_ipv4_rule_conn_cfg_msg), nss_ipv4_conn_cfg_callback, NULL); |
| 370 | |
| 371 | nirccm = &nim.msg.rule_conn_cfg; |
| 372 | nirccm->num_conn = htonl(nss_ipv4_conn_cfg); |
| 373 | nss_tx_status = nss_ipv4_tx(nss_ctx, &nim); |
| 374 | |
| 375 | if (nss_tx_status != NSS_TX_SUCCESS) { |
| 376 | nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n", |
| 377 | nss_ctx, |
| 378 | nss_ipv4_conn_cfg); |
| 379 | } |
| 380 | return ret; |
| 381 | } |
| 382 | |
| 383 | static ctl_table nss_ipv4_table[] = { |
| 384 | { |
| 385 | .procname = "ipv4_conn", |
| 386 | .data = &nss_ipv4_conn_cfg, |
| 387 | .maxlen = sizeof(int), |
| 388 | .mode = 0644, |
| 389 | .proc_handler = &nss_ipv4_conn_cfg_handler, |
| 390 | }, |
| 391 | { } |
| 392 | }; |
| 393 | |
| 394 | static ctl_table nss_ipv4_dir[] = { |
| 395 | { |
| 396 | .procname = "ipv4cfg", |
| 397 | .mode = 0555, |
| 398 | .child = nss_ipv4_table, |
| 399 | }, |
| 400 | { } |
| 401 | }; |
| 402 | |
| 403 | |
| 404 | static ctl_table nss_ipv4_root_dir[] = { |
| 405 | { |
| 406 | .procname = "nss", |
| 407 | .mode = 0555, |
| 408 | .child = nss_ipv4_dir, |
| 409 | }, |
| 410 | { } |
| 411 | }; |
| 412 | |
| 413 | static ctl_table nss_ipv4_root[] = { |
| 414 | { |
| 415 | .procname = "dev", |
| 416 | .mode = 0555, |
| 417 | .child = nss_ipv4_root_dir, |
| 418 | }, |
| 419 | { } |
| 420 | }; |
| 421 | |
| 422 | static struct ctl_table_header *nss_ipv4_header; |
| 423 | |
| 424 | /* |
| 425 | * nss_ipv4_register_sysctl() |
| 426 | * Register sysctl specific to ipv4 |
| 427 | */ |
| 428 | void nss_ipv4_register_sysctl(void) |
| 429 | { |
| 430 | /* |
| 431 | * Register sysctl table. |
| 432 | */ |
| 433 | nss_ipv4_header = register_sysctl_table(nss_ipv4_root); |
| 434 | } |
| 435 | |
| 436 | /* |
| 437 | * nss_ipv4_unregister_sysctl() |
| 438 | * Unregister sysctl specific to ipv4 |
| 439 | */ |
| 440 | void nss_ipv4_unregister_sysctl(void) |
| 441 | { |
| 442 | /* |
| 443 | * Unregister sysctl table. |
| 444 | */ |
| 445 | if (nss_ipv4_header) { |
| 446 | unregister_sysctl_table(nss_ipv4_header); |
| 447 | } |
| 448 | } |
| 449 | |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 450 | EXPORT_SYMBOL(nss_ipv4_tx); |
| 451 | EXPORT_SYMBOL(nss_ipv4_notify_register); |
| 452 | EXPORT_SYMBOL(nss_ipv4_notify_unregister); |
| 453 | EXPORT_SYMBOL(nss_ipv4_get_mgr); |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame^] | 454 | EXPORT_SYMBOL(nss_ipv4_register_sysctl); |
| 455 | EXPORT_SYMBOL(nss_ipv4_unregister_sysctl); |