Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
| 3 | * Copyright (c) 2014, 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 | /* nss_ipsecmgr.c |
| 18 | * NSS to HLOS IPSec Manager |
| 19 | */ |
| 20 | #include <linux/types.h> |
| 21 | #include <linux/ip.h> |
| 22 | #include <linux/skbuff.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/rtnetlink.h> |
| 26 | #include <asm/atomic.h> |
| 27 | #include <nss_api_if.h> |
| 28 | #include <nss_ipsec.h> |
| 29 | #include "nss_ipsecmgr.h" |
| 30 | |
| 31 | |
| 32 | #if defined(CONFIG_DYNAMIC_DEBUG) |
| 33 | /* |
| 34 | * Compile messages for dynamic enable/disable |
| 35 | */ |
| 36 | #define nss_ipsecmgr_error(s, ...) pr_debug("%s[%d]:" s, __FUNCTION__, __LINE__, ##__VA_ARGS__) |
| 37 | #define nss_ipsecmgr_warn(s, ...) pr_debug("%s[%d]:" s, __FUNCTION__, __LINE__, ##__VA_ARGS__) |
| 38 | #define nss_ipsecmgr_info(s, ...) pr_debug("%s[%d]:" s, __FUNCTION__, __LINE__, ##__VA_ARGS__) |
| 39 | #define nss_ipsecmgr_trace(s, ...) pr_debug("%s[%d]:" s, __FUNCTION__, __LINE__, ##__VA_ARGS__) |
| 40 | |
| 41 | #else |
| 42 | /* |
| 43 | * Statically compile messages at different levels |
| 44 | */ |
| 45 | #define nss_ipsecmgr_error(s, ...) { \ |
| 46 | if (NSS_IPSECMGR_DEBUG_LEVEL < NSS_IPSECMGR_DEBUG_LVL_ERROR) { \ |
| 47 | pr_alert("%s[%d]:" s, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ |
| 48 | } \ |
| 49 | } |
| 50 | #define nss_ipsecmgr_warn(s, ...) { \ |
| 51 | if (NSS_IPSECMGR_DEBUG_LEVEL < NSS_IPSECMGR_DEBUG_LVL_WARN) { \ |
| 52 | pr_warn("%s[%d]:" s, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ |
| 53 | } \ |
| 54 | } |
| 55 | #define nss_ipsecmgr_info(s, ...) { \ |
| 56 | if (NSS_IPSECMGR_DEBUG_LEVEL < NSS_IPSECMGR_DEBUG_LVL_INFO) { \ |
| 57 | pr_notice("%s[%d]:" s, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ |
| 58 | } \ |
| 59 | } |
| 60 | #define nss_ipsecmgr_trace(s, ...) { \ |
| 61 | if (NSS_IPSECMGR_DEBUG_LEVEL < NSS_IPSECMGR_DEBUG_LVL_TRACE) { \ |
| 62 | pr_info("%s[%d]:" s, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ |
| 63 | } \ |
| 64 | } |
| 65 | |
| 66 | #endif /* !CONFIG_DYNAMIC_DEBUG */ |
| 67 | |
| 68 | /* NSS IPsec entry state */ |
| 69 | enum nss_ipsecmgr_entry_state { |
| 70 | NSS_IPSECMGR_ENTRY_STATE_INIT = 0, /* init state of the entry */ |
| 71 | NSS_IPSECMGR_ENTRY_STATE_VALID = 1, /* entry is valid */ |
| 72 | NSS_IPSECMGR_ENTRY_STATE_INVALID = 2, /* entry is invalid */ |
| 73 | NSS_IPSECMGR_ENTRY_STATE_MAX |
| 74 | }; |
| 75 | |
| 76 | /* IPsec table entry */ |
| 77 | struct nss_ipsecmgr_tbl_entry { |
| 78 | struct nss_ipsec_rule_sel sel; /* rule selector */ |
| 79 | struct nss_ipsec_sa_stats stats; /* per entry stats */ |
| 80 | enum nss_ipsecmgr_entry_state state; /* state */ |
| 81 | }; |
| 82 | |
| 83 | /* NSS IPsec table type */ |
| 84 | struct nss_ipsecmgr_tbl { |
| 85 | uint32_t total_tx; /* total packets tx'ed from ENCAP/DECAP */ |
| 86 | uint32_t total_rx; /* total packets rx'ed at ENCAP/DECAP */ |
| 87 | uint32_t total_dropped; /* total dropped packets at ENCAP/DECAP */ |
| 88 | struct nss_ipsecmgr_tbl_entry entry[NSS_IPSEC_MAX_SA]; /* table entry */ |
| 89 | uint32_t count; /* number of entries */ |
| 90 | spinlock_t lock; |
| 91 | }; |
| 92 | |
| 93 | /* NSS IPsec manager private structure */ |
| 94 | struct nss_ipsecmgr_priv { |
| 95 | struct nss_ipsecmgr_tbl encap; /* encap table */ |
| 96 | struct nss_ipsecmgr_tbl decap; /* decap table */ |
| 97 | |
| 98 | void *cb_ctx; /* callback context */ |
| 99 | nss_ipsecmgr_callback_t cb_fn; /* callback function */ |
| 100 | struct nss_ctx_instance *nss_ctx; /* NSS context */ |
| 101 | }; |
| 102 | |
| 103 | typedef bool (*nss_ipsecmgr_op_t)(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim); |
| 104 | |
| 105 | /* NSS IPsec manager operation (message types) complete routines */ |
| 106 | struct nss_ipsecmgr_ops { |
| 107 | nss_ipsecmgr_op_t verify_fn; /* verify function for the op */ |
| 108 | nss_ipsecmgr_op_t commit_fn; /* commit function for the op */ |
| 109 | }; |
| 110 | |
| 111 | /* driver global info */ |
| 112 | struct nss_ipsecmgr_drv { |
| 113 | atomic_t sa_count; /* number of SA's available for */ |
| 114 | }; |
| 115 | |
| 116 | /* |
| 117 | ********************** |
| 118 | * globals |
| 119 | ********************** |
| 120 | */ |
| 121 | |
| 122 | static struct nss_ipsecmgr_drv gbl_drv_ctx; /* global driver context */ |
| 123 | |
| 124 | /* |
| 125 | ********************** |
| 126 | * Helper Functions |
| 127 | ********************** |
| 128 | */ |
| 129 | |
| 130 | /* |
| 131 | * nss_ipsecmgr_get_tbl() |
| 132 | * return the table associated with the interface number |
| 133 | */ |
| 134 | static inline struct nss_ipsecmgr_tbl *nss_ipsecmgr_get_tbl(struct nss_ipsecmgr_priv *priv, uint16_t if_num) |
| 135 | { |
| 136 | switch (if_num) { |
| 137 | case NSS_IPSEC_ENCAP_IF_NUMBER: |
| 138 | return &priv->encap; |
| 139 | |
| 140 | case NSS_IPSEC_DECAP_IF_NUMBER: |
| 141 | return &priv->decap; |
| 142 | |
| 143 | default: |
| 144 | return NULL; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * nss_ipsecmgr_copy_encap_add() |
| 150 | * prepare the IPsec message for encap add operation |
| 151 | */ |
| 152 | static void nss_ipsecmgr_copy_encap_add(struct net_device *dev, struct nss_ipsec_rule *msg, union nss_ipsecmgr_rule *rule) |
| 153 | { |
| 154 | struct nss_ipsecmgr_encap_add *encap = &rule->encap_add; |
| 155 | struct nss_ipsec_rule_sel *sel = &msg->sel; |
| 156 | struct nss_ipsec_rule_oip *oip = &msg->oip; |
| 157 | struct nss_ipsec_rule_data *data = &msg->data; |
| 158 | |
| 159 | /* |
| 160 | * Populate the selectors for encap direction |
| 161 | */ |
| 162 | sel->ipv4_src = encap->inner_ipv4_src; |
| 163 | sel->ipv4_dst = encap->inner_ipv4_dst; |
| 164 | |
| 165 | sel->src_port = encap->inner_src_port; |
| 166 | sel->dst_port = encap->inner_dst_port; |
| 167 | |
| 168 | sel->ipv4_proto = encap->inner_ipv4_proto; |
| 169 | |
| 170 | /* |
| 171 | * Populate the outer IP data for encap direction |
| 172 | */ |
| 173 | oip->ipv4_dst = encap->outer_ipv4_dst; |
| 174 | oip->ipv4_src = encap->outer_ipv4_src; |
| 175 | |
| 176 | oip->esp_spi = encap->esp_spi; |
| 177 | |
| 178 | oip->ipv4_ttl = encap->outer_ipv4_ttl; |
| 179 | |
| 180 | /* |
| 181 | * Populate the data part |
| 182 | */ |
Radha krishna Simha Jiguru | ca4f85c | 2014-08-23 17:00:07 +0530 | [diff] [blame^] | 183 | data->cipher_algo = encap->cipher_algo; |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 184 | data->esp_seq_skip = (encap->esp_seq_skip == 1); |
| 185 | |
Radha krishna Simha Jiguru | ca4f85c | 2014-08-23 17:00:07 +0530 | [diff] [blame^] | 186 | data->esp_icv_len = encap->esp_icv_len; |
| 187 | data->auth_algo = encap->auth_algo; |
| 188 | |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 189 | data->crypto_index = encap->crypto_index; |
| 190 | |
| 191 | data->nat_t_req = encap->nat_t_req; |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | * nss_ipsecmgr_copy_decap_add() |
| 196 | * prepare the IPsec message for decap add operation |
| 197 | */ |
| 198 | static void nss_ipsecmgr_copy_decap_add(struct net_device *dev, struct nss_ipsec_rule *msg, union nss_ipsecmgr_rule *rule) |
| 199 | { |
| 200 | struct nss_ipsecmgr_decap_add *decap = &rule->decap_add; |
| 201 | struct nss_ipsec_rule_sel *sel = &msg->sel; |
| 202 | struct nss_ipsec_rule_data *data = &msg->data; |
| 203 | /* |
| 204 | * Populate the selectors for encap direction |
| 205 | */ |
| 206 | sel->ipv4_src = decap->outer_ipv4_src; |
| 207 | sel->ipv4_dst = decap->outer_ipv4_dst; |
| 208 | |
| 209 | sel->esp_spi = decap->esp_spi; |
| 210 | |
| 211 | sel->ipv4_proto = IPPROTO_ESP; |
| 212 | |
| 213 | /* |
| 214 | * Populate the data part |
| 215 | */ |
Radha krishna Simha Jiguru | ca4f85c | 2014-08-23 17:00:07 +0530 | [diff] [blame^] | 216 | data->cipher_algo = decap->cipher_algo; |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 217 | |
Radha krishna Simha Jiguru | ca4f85c | 2014-08-23 17:00:07 +0530 | [diff] [blame^] | 218 | data->esp_icv_len = decap->esp_icv_len; |
| 219 | data->auth_algo = decap->auth_algo; |
| 220 | |
Samarjeet Banerjee | 7733231 | 2014-08-07 14:48:22 +0530 | [diff] [blame] | 221 | data->crypto_index = decap->crypto_index; |
| 222 | |
| 223 | data->window_size = decap->window_size; |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * nss_ipsecmgr_copy_encap_del() |
| 228 | * prepare the IPsec message for encap del operation |
| 229 | */ |
| 230 | static void nss_ipsecmgr_copy_encap_del(struct net_device *dev, struct nss_ipsec_rule *msg, union nss_ipsecmgr_rule *rule) |
| 231 | { |
| 232 | struct nss_ipsecmgr_encap_del *encap = &rule->encap_del; |
| 233 | struct nss_ipsec_rule_sel *sel = &msg->sel; |
| 234 | |
| 235 | /* |
| 236 | * Populate the selectors for encap direction |
| 237 | */ |
| 238 | sel->ipv4_src = encap->inner_ipv4_src; |
| 239 | sel->ipv4_dst = encap->inner_ipv4_dst; |
| 240 | |
| 241 | sel->src_port = encap->inner_src_port; |
| 242 | sel->dst_port = encap->inner_dst_port; |
| 243 | |
| 244 | sel->ipv4_proto = encap->inner_ipv4_proto; |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * nss_ipsecmgr_copy_decap_del() |
| 249 | * prepare the IPsec message for decap del operation |
| 250 | */ |
| 251 | static void nss_ipsecmgr_copy_decap_del(struct net_device *dev, struct nss_ipsec_rule *msg, union nss_ipsecmgr_rule *rule) |
| 252 | { |
| 253 | struct nss_ipsecmgr_decap_del *decap = &rule->decap_del; |
| 254 | struct nss_ipsec_rule_sel *sel = &msg->sel; |
| 255 | /* |
| 256 | * Populate the selectors for encap direction |
| 257 | */ |
| 258 | sel->ipv4_src = decap->outer_ipv4_src; |
| 259 | sel->ipv4_dst = decap->outer_ipv4_dst; |
| 260 | |
| 261 | sel->esp_spi = decap->esp_spi; |
| 262 | |
| 263 | sel->ipv4_proto = IPPROTO_ESP; |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | ********************** |
| 268 | * message handlers |
| 269 | ********************** |
| 270 | */ |
| 271 | /* |
| 272 | * nss_ipsecmgr_verify_add() |
| 273 | * verify the Add operation before committing |
| 274 | */ |
| 275 | static bool nss_ipsecmgr_verify_add(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim) |
| 276 | { |
| 277 | struct nss_ipsec_rule *rule = &nim->msg.push; |
| 278 | struct nss_ipsecmgr_tbl_entry *entry; |
| 279 | uint32_t tbl_idx; |
| 280 | |
| 281 | tbl_idx = rule->index; |
| 282 | if (tbl_idx >= NSS_IPSEC_MAX_SA) { |
| 283 | nss_ipsecmgr_error("table index out of range\n"); |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | entry = &tbl->entry[tbl_idx]; |
| 288 | |
| 289 | /* |
| 290 | * XXX:Duplicate hit or hash collision; We need to handle |
| 291 | * hash collision |
| 292 | */ |
| 293 | if (entry->state == NSS_IPSECMGR_ENTRY_STATE_VALID) { |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Table full, XXX:must increment stats |
| 299 | */ |
| 300 | if ((tbl->count + 1) >= NSS_IPSEC_MAX_SA) { |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | return true; |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * nss_ipsecmgr_commit_add() |
| 309 | * commit the Add operation |
| 310 | */ |
| 311 | static bool nss_ipsecmgr_commit_add(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim) |
| 312 | { |
| 313 | struct nss_ipsec_rule *rule = &nim->msg.push; |
| 314 | struct nss_ipsecmgr_tbl_entry *entry; |
| 315 | uint32_t tbl_idx; |
| 316 | |
| 317 | /* Reduce the number of availabe SA(s) as we have successfully added one */ |
| 318 | atomic_dec(&gbl_drv_ctx.sa_count); |
| 319 | |
| 320 | tbl_idx = rule->index; |
| 321 | entry = &tbl->entry[tbl_idx]; |
| 322 | |
| 323 | tbl->count++; |
| 324 | |
| 325 | memcpy(&entry->sel, &rule->sel, sizeof(struct nss_ipsec_rule_sel)); |
| 326 | entry->state = NSS_IPSECMGR_ENTRY_STATE_VALID; |
| 327 | |
| 328 | return true; |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * nss_ipsecmgr_verify_del() |
| 333 | * verify the del operation before committing |
| 334 | */ |
| 335 | static bool nss_ipsecmgr_verify_del(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim) |
| 336 | { |
| 337 | struct nss_ipsec_rule *rule = &nim->msg.push; |
| 338 | struct nss_ipsecmgr_tbl_entry *entry; |
| 339 | uint32_t tbl_idx; |
| 340 | |
| 341 | tbl_idx = rule->index; |
| 342 | if (tbl_idx >= NSS_IPSEC_MAX_SA) { |
| 343 | nss_ipsecmgr_error("table index out of range\n"); |
| 344 | return false; |
| 345 | } |
| 346 | |
| 347 | entry = &tbl->entry[tbl_idx]; |
| 348 | |
| 349 | /* |
| 350 | * Entry already deleted, XXX:must increment stats |
| 351 | */ |
| 352 | if (entry->state == NSS_IPSECMGR_ENTRY_STATE_INVALID) { |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | * Entry never existed, XXX:must increment stats |
| 358 | */ |
| 359 | if (entry->state == NSS_IPSECMGR_ENTRY_STATE_INIT) { |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | * Table empty, XXX:must increment stats |
| 365 | */ |
| 366 | if (tbl->count == 0) { |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | return true; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * nss_ipsecmgr_commit_del() |
| 375 | * commit the Del operation |
| 376 | */ |
| 377 | static bool nss_ipsecmgr_commit_del(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim) |
| 378 | { |
| 379 | struct nss_ipsec_rule *rule = &nim->msg.push; |
| 380 | struct nss_ipsecmgr_tbl_entry *entry; |
| 381 | uint32_t tbl_idx; |
| 382 | |
| 383 | /* Increase the number of available SA(s) as we have successfully freed one */ |
| 384 | atomic_inc(&gbl_drv_ctx.sa_count); |
| 385 | |
| 386 | tbl_idx = rule->index; |
| 387 | entry = &tbl->entry[tbl_idx]; |
| 388 | |
| 389 | tbl->count--; |
| 390 | |
| 391 | memset(&entry->sel, 0, sizeof(struct nss_ipsec_rule_sel)); |
| 392 | entry->state = NSS_IPSECMGR_ENTRY_STATE_INVALID; |
| 393 | |
| 394 | return true; |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * nss_ipsecmgr_verify_stats() |
| 399 | * verify stats update operation |
| 400 | */ |
| 401 | static bool nss_ipsecmgr_verify_stats(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim) |
| 402 | { |
| 403 | struct nss_ipsec_stats *stats = &nim->msg.stats; |
| 404 | |
| 405 | /* |
| 406 | * Table empty, nothing to update |
| 407 | */ |
| 408 | if (tbl->count == 0) { |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * nothing to update |
| 414 | */ |
| 415 | if (stats->num_entries == 0) { |
| 416 | return false; |
| 417 | } |
| 418 | |
| 419 | return true; |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * nss_ipsecmgr_commit_stats() |
| 424 | * commit stats for the SA |
| 425 | */ |
| 426 | static bool nss_ipsecmgr_commit_stats(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim) |
| 427 | { |
| 428 | struct nss_ipsec_stats *stats = &nim->msg.stats; |
| 429 | struct nss_ipsec_sa_stats *sa_stats; |
| 430 | struct nss_ipsecmgr_tbl_entry *entry; |
| 431 | uint32_t tbl_idx; |
| 432 | int i; |
| 433 | |
| 434 | tbl->total_tx = stats->total_tx; |
| 435 | tbl->total_rx = stats->total_rx; |
| 436 | tbl->total_dropped = stats->total_dropped; |
| 437 | |
| 438 | for (i = 0; i < stats->num_entries; i++) { |
| 439 | sa_stats = &stats->sa[i]; |
| 440 | tbl_idx = sa_stats->index; |
| 441 | |
| 442 | entry = &tbl->entry[tbl_idx]; |
| 443 | |
| 444 | memcpy(&entry->stats, sa_stats, sizeof(struct nss_ipsec_sa_stats)); |
| 445 | } |
| 446 | |
| 447 | return true; |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | * nss_ipsecmgr_verify_flush() |
| 452 | * verify the flush operation |
| 453 | */ |
| 454 | static bool nss_ipsecmgr_verify_flush(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim) |
| 455 | { |
| 456 | return true; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * nss_ipsecmgr_commit_flush() |
| 461 | * commit the flush operation |
| 462 | */ |
| 463 | static bool nss_ipsecmgr_commit_flush(struct net_device *dev, struct nss_ipsecmgr_tbl *tbl, struct nss_ipsec_msg *nim) |
| 464 | { |
| 465 | tbl->count = 0; |
| 466 | |
| 467 | return true; |
| 468 | } |
| 469 | |
| 470 | /* |
| 471 | * callback operation |
| 472 | */ |
| 473 | const static struct nss_ipsecmgr_ops cb_ops[NSS_IPSEC_MSG_TYPE_MAX] = { |
| 474 | [NSS_IPSEC_MSG_TYPE_ADD_RULE] = {nss_ipsecmgr_verify_add, nss_ipsecmgr_commit_add}, |
| 475 | [NSS_IPSEC_MSG_TYPE_DEL_RULE] = {nss_ipsecmgr_verify_del, nss_ipsecmgr_commit_del}, |
| 476 | [NSS_IPSEC_MSG_TYPE_SYNC_STATS] = {nss_ipsecmgr_verify_stats, nss_ipsecmgr_commit_stats}, |
| 477 | [NSS_IPSEC_MSG_TYPE_FLUSH_TUN] = {nss_ipsecmgr_verify_flush, nss_ipsecmgr_commit_flush} |
| 478 | }; |
| 479 | |
| 480 | /* |
| 481 | * nss_ipsecmgr_op_receive() |
| 482 | * asynchronous event reception |
| 483 | */ |
| 484 | static void nss_ipsecmgr_op_receive(void *app_data, struct nss_ipsec_msg *nim) |
| 485 | { |
| 486 | struct net_device *tun_dev = (struct net_device *)app_data; |
| 487 | struct nss_ipsecmgr_priv *priv; |
| 488 | struct nss_ipsecmgr_tbl *tbl; |
| 489 | nss_ipsecmgr_op_t verify_fn; |
| 490 | nss_ipsecmgr_op_t commit_fn; |
| 491 | struct net_device *dev; |
| 492 | |
| 493 | BUG_ON(tun_dev == NULL); |
| 494 | BUG_ON(nim == NULL); |
| 495 | |
| 496 | /* this holds the ref_cnt for the device */ |
| 497 | dev = dev_get_by_index(&init_net, nim->tunnel_id); |
| 498 | if (dev == NULL) { |
| 499 | nss_ipsecmgr_error("event received on deallocated I/F (%d)\n", nim->tunnel_id); |
| 500 | return; |
| 501 | } |
| 502 | |
| 503 | if (dev != tun_dev) { |
| 504 | nss_ipsecmgr_error("event received on incorrect I/F (%d)\n", nim->tunnel_id); |
| 505 | goto done; |
| 506 | } |
| 507 | |
| 508 | priv = netdev_priv(dev); |
| 509 | |
| 510 | tbl = nss_ipsecmgr_get_tbl(priv, nim->cm.interface); |
| 511 | if (tbl == NULL) { |
| 512 | nss_ipsecmgr_error("invalid interface number(%d)\n", nim->cm.interface); |
| 513 | goto done; |
| 514 | } |
| 515 | |
| 516 | verify_fn = cb_ops[nim->cm.type].verify_fn; |
| 517 | commit_fn = cb_ops[nim->cm.type].commit_fn; |
| 518 | |
| 519 | if (!verify_fn || !commit_fn) { |
| 520 | nss_ipsecmgr_error("unhandled type (%d)\n", nim->cm.type); |
| 521 | goto done; |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * Now we can operate on the entry of the table |
| 526 | */ |
| 527 | spin_lock_bh(&tbl->lock); |
| 528 | |
| 529 | if (verify_fn(dev, tbl, nim) == true) { |
| 530 | commit_fn(dev, tbl, nim); |
| 531 | } |
| 532 | |
| 533 | spin_unlock_bh(&tbl->lock); |
| 534 | done: |
| 535 | /* release the device as we are done */ |
| 536 | dev_put(dev); |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * nss_ipsecmgr_op_send() |
| 541 | * Push a IPsec rule to NSS |
| 542 | */ |
| 543 | static bool nss_ipsecmgr_op_send(struct net_device *dev, struct nss_ipsec_msg *nim, uint32_t if_num, enum nss_ipsec_msg_type type) |
| 544 | { |
| 545 | struct nss_ipsecmgr_priv *priv; |
| 546 | nss_tx_status_t status; |
| 547 | |
| 548 | priv = netdev_priv(dev); |
| 549 | if (priv->nss_ctx == NULL) { |
| 550 | nss_ipsecmgr_error("Tunnel registration or de-registration is underway\n"); |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | nim->tunnel_id = dev->ifindex; |
| 555 | |
| 556 | nss_cmn_msg_init(&nim->cm, if_num, type, NSS_IPSEC_MSG_LEN, nss_ipsecmgr_op_receive, dev); |
| 557 | |
| 558 | status = nss_ipsec_tx_msg(priv->nss_ctx, nim); |
| 559 | if (status != NSS_TX_SUCCESS) { |
| 560 | nss_ipsecmgr_error("unable to push rule(%d) for %s\n", type, dev->name); |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | return true; |
| 565 | } |
| 566 | |
| 567 | /* |
| 568 | * nss_ipsecmgr_buf_receive() |
| 569 | * receive NSS exception packets |
| 570 | */ |
| 571 | static void nss_ipsecmgr_buf_receive(void *app_data, void *os_buf, __attribute((unused)) struct napi_struct *napi) |
| 572 | { |
| 573 | struct net_device *dev = (struct net_device *)app_data; |
| 574 | struct sk_buff *skb = (struct sk_buff *)os_buf; |
| 575 | struct nss_ipsecmgr_priv *priv; |
| 576 | nss_ipsecmgr_callback_t cb_fn; |
| 577 | void *cb_ctx; |
| 578 | struct iphdr *ip; |
| 579 | |
| 580 | BUG_ON(dev == NULL); |
| 581 | BUG_ON(skb == NULL); |
| 582 | |
| 583 | /* hold the device till we process it */ |
| 584 | dev_hold(dev); |
| 585 | |
| 586 | /* |
| 587 | * XXX:need to ensure that the dev being accessed is not deleted |
| 588 | */ |
| 589 | priv = netdev_priv(dev); |
| 590 | |
| 591 | skb->dev = dev; |
| 592 | |
| 593 | cb_fn = priv->cb_fn; |
| 594 | cb_ctx = priv->cb_ctx; |
| 595 | |
| 596 | /* |
| 597 | * if tunnel creator gave a callback then send the packet without |
| 598 | * any modifications to him |
| 599 | */ |
| 600 | if (cb_fn && cb_ctx) { |
| 601 | cb_fn(cb_ctx, skb); |
| 602 | goto done; |
| 603 | } |
| 604 | |
| 605 | ip = (struct iphdr *)skb->data; |
| 606 | if ((ip->version != IPVERSION) || (ip->ihl != 5)) { |
| 607 | nss_ipsecmgr_error("dropping packets(IP version:%x, Header len:%x)\n", ip->version, ip->ihl); |
| 608 | dev_kfree_skb_any(skb); |
| 609 | goto done; |
| 610 | } |
| 611 | |
| 612 | skb_reset_network_header(skb); |
| 613 | skb_reset_mac_header(skb); |
| 614 | |
| 615 | skb->pkt_type = PACKET_HOST; |
| 616 | skb->protocol = cpu_to_be16(ETH_P_IP); |
| 617 | skb->skb_iif = dev->ifindex; |
| 618 | |
| 619 | netif_receive_skb(skb); |
| 620 | done: |
| 621 | /* release the device as we are done */ |
| 622 | dev_put(dev); |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | * nss_ipsecmgr_buf_drop() |
| 627 | * invalid buffer received;drop it and account it |
| 628 | */ |
| 629 | static void nss_ipsecmgr_buf_drop(void *app_data, void *os_buf, __attribute((unused)) struct napi_struct *napi) |
| 630 | { |
| 631 | struct sk_buff *skb = (struct sk_buff *)os_buf; |
| 632 | struct iphdr *ip; |
| 633 | |
| 634 | BUG_ON(skb == NULL); |
| 635 | |
| 636 | ip = (struct iphdr *)skb->data; |
| 637 | if ((ip->version != IPVERSION) || (ip->ihl != 5)) { |
| 638 | nss_ipsecmgr_error("dropping packets(IP version:%x, Header len:%x)\n", ip->version, ip->ihl); |
| 639 | } |
| 640 | |
| 641 | /* XXX: increment stats */ |
| 642 | |
| 643 | dev_kfree_skb_any(skb); |
| 644 | } |
| 645 | /* |
| 646 | ********************** |
| 647 | * Netdev ops |
| 648 | ********************** |
| 649 | */ |
| 650 | |
| 651 | /* |
| 652 | * nss_ipsecmgr_tunnel_init() |
| 653 | * initiallizes the tunnel |
| 654 | */ |
| 655 | static int nss_ipsecmgr_tunnel_init(struct net_device *dev) |
| 656 | { |
| 657 | struct nss_ipsecmgr_priv *priv; |
| 658 | |
| 659 | priv = netdev_priv(dev); |
| 660 | |
| 661 | priv->nss_ctx = nss_ipsec_get_context(); |
| 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | /* |
| 667 | * nss_ipsecmgr_tunnel_exit() |
| 668 | * deinitiallizes the tunnel |
| 669 | */ |
| 670 | static void nss_ipsecmgr_tunnel_exit(struct net_device *dev) |
| 671 | { |
| 672 | struct nss_ipsecmgr_priv *priv; |
| 673 | |
| 674 | priv = netdev_priv(dev); |
| 675 | |
| 676 | priv->nss_ctx = NULL; |
| 677 | } |
| 678 | |
| 679 | /* |
| 680 | * nss_ipsecmgr_tunnel_open() |
| 681 | * open the tunnel for usage |
| 682 | */ |
| 683 | static int nss_ipsecmgr_tunnel_open(struct net_device *dev) |
| 684 | { |
| 685 | struct nss_ipsecmgr_priv *priv; |
| 686 | |
| 687 | priv = netdev_priv(dev); |
| 688 | |
| 689 | netif_start_queue(dev); |
| 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | /* |
| 695 | * nss_ipsecmgr_tunnel_stop() |
| 696 | * stop the IPsec tunnel |
| 697 | */ |
| 698 | static int nss_ipsecmgr_tunnel_stop(struct net_device *dev) |
| 699 | { |
| 700 | struct nss_ipsecmgr_priv *priv; |
| 701 | |
| 702 | priv = netdev_priv(dev); |
| 703 | |
| 704 | netif_stop_queue(dev); |
| 705 | |
| 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | /* |
| 710 | * nss_ipsecmgr_tunnel_xmit() |
| 711 | * tunnel transmit function |
| 712 | */ |
| 713 | static netdev_tx_t nss_ipsecmgr_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) |
| 714 | { |
| 715 | nss_ipsecmgr_warn("tunnel transmit not implemented, freeing the skb\n"); |
| 716 | |
| 717 | dev_kfree_skb_any(skb); |
| 718 | |
| 719 | return NETDEV_TX_OK; |
| 720 | } |
| 721 | |
| 722 | /* |
| 723 | * nss_ipsecmgr_tunnel_stats() |
| 724 | * get tunnel statistics |
| 725 | */ |
| 726 | static struct net_device_stats *nss_ipsecmgr_tunnel_stats(struct net_device *dev) |
| 727 | { |
| 728 | struct net_device_stats *stats = &dev->stats; |
| 729 | struct nss_ipsecmgr_priv *priv; |
| 730 | struct nss_ipsecmgr_tbl *encap; |
| 731 | struct nss_ipsecmgr_tbl *decap; |
| 732 | |
| 733 | priv = netdev_priv(dev); |
| 734 | |
| 735 | encap = &priv->encap; |
| 736 | decap = &priv->decap; |
| 737 | |
| 738 | stats->rx_packets = encap->total_rx + decap->total_rx; |
| 739 | stats->tx_packets = encap->total_tx + decap->total_tx; |
| 740 | stats->tx_dropped = encap->total_dropped + decap->total_dropped; |
| 741 | |
| 742 | return stats; |
| 743 | } |
| 744 | |
| 745 | /* NSS IPsec tunnel operation */ |
| 746 | static const struct net_device_ops nss_ipsecmgr_tunnel_ops = { |
| 747 | .ndo_init = nss_ipsecmgr_tunnel_init, |
| 748 | .ndo_uninit = nss_ipsecmgr_tunnel_exit, |
| 749 | .ndo_start_xmit = nss_ipsecmgr_tunnel_xmit, |
| 750 | .ndo_open = nss_ipsecmgr_tunnel_open, |
| 751 | .ndo_stop = nss_ipsecmgr_tunnel_stop, |
| 752 | .ndo_get_stats = nss_ipsecmgr_tunnel_stats, |
| 753 | }; |
| 754 | |
| 755 | /* |
| 756 | * nss_ipsecmgr_tunnel_free() |
| 757 | * free an existing IPsec tunnel interface |
| 758 | */ |
| 759 | static void nss_ipsecmgr_tunnel_free(struct net_device *dev) |
| 760 | { |
| 761 | struct nss_ipsecmgr_priv *priv = netdev_priv(dev); |
| 762 | struct nss_ipsecmgr_tbl *encap_tbl; |
| 763 | struct nss_ipsecmgr_tbl *decap_tbl; |
| 764 | |
| 765 | encap_tbl = &priv->encap; |
| 766 | decap_tbl = &priv->decap; |
| 767 | |
| 768 | nss_ipsecmgr_info("IPsec tunnel device(%s) freed\n", dev->name); |
| 769 | nss_ipsecmgr_info("Entries left: encap(%d), decap(%d)\n", encap_tbl->count, decap_tbl->count); |
| 770 | |
| 771 | free_netdev(dev); |
| 772 | } |
| 773 | |
| 774 | /* |
| 775 | * nss_ipsecmr_setup_tunnel() |
| 776 | * setup the IPsec tunnel |
| 777 | */ |
| 778 | static void nss_ipsecmgr_tunnel_setup(struct net_device *dev) |
| 779 | { |
| 780 | dev->addr_len = ETH_ALEN; |
| 781 | dev->mtu = NSS_IPSECMGR_TUN_MTU(ETH_DATA_LEN); |
| 782 | |
| 783 | dev->hard_header_len = NSS_IPSECMGR_TUN_MAX_HDR_LEN; |
| 784 | dev->needed_headroom = NSS_IPSECMGR_TUN_HEADROOM; |
| 785 | dev->needed_tailroom = NSS_IPSECMGR_TUN_TAILROOM; |
| 786 | |
| 787 | dev->type = NSS_IPSEC_ARPHRD_IPSEC; |
| 788 | |
| 789 | dev->ethtool_ops = NULL; |
| 790 | dev->header_ops = NULL; |
| 791 | dev->netdev_ops = &nss_ipsecmgr_tunnel_ops; |
| 792 | |
| 793 | dev->destructor = nss_ipsecmgr_tunnel_free; |
| 794 | |
| 795 | /* |
| 796 | * XXX:should get the MAC address from the ethernet device |
| 797 | */ |
| 798 | memcpy(dev->dev_addr, "\xaa\xbb\xcc\xdd\xee\xff", dev->addr_len); |
| 799 | memset(dev->broadcast, 0xff, dev->addr_len); |
| 800 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
| 801 | } |
| 802 | |
| 803 | /* |
| 804 | ********************** |
| 805 | * Exported Functions |
| 806 | ********************** |
| 807 | */ |
| 808 | |
| 809 | /* |
| 810 | * nss_ipsecmgr_tunnel_add() |
| 811 | * add a IPsec pseudo tunnel device |
| 812 | */ |
| 813 | struct net_device *nss_ipsecmgr_tunnel_add(void *cb_ctx, nss_ipsecmgr_callback_t cb) |
| 814 | { |
| 815 | struct net_device *dev; |
| 816 | struct nss_ipsecmgr_priv *priv; |
| 817 | int status; |
| 818 | |
| 819 | dev = alloc_netdev(sizeof(struct nss_ipsecmgr_priv), NSS_IPSECMGR_TUN_NAME, nss_ipsecmgr_tunnel_setup); |
| 820 | if (!dev) { |
| 821 | nss_ipsecmgr_error("unable to allocate a tunnel device\n"); |
| 822 | return NULL; |
| 823 | } |
| 824 | |
| 825 | priv = netdev_priv(dev); |
| 826 | |
| 827 | priv->cb_ctx = cb_ctx; |
| 828 | priv->cb_fn = cb; |
| 829 | |
| 830 | spin_lock_init(&priv->encap.lock); |
| 831 | spin_lock_init(&priv->decap.lock); |
| 832 | |
| 833 | status = rtnl_is_locked() ? register_netdevice(dev) : register_netdev(dev); |
| 834 | if (status < 0) { |
| 835 | goto fail; |
| 836 | } |
| 837 | |
| 838 | /* if IPsec encap delivers a packet as exeception, then there is something wrong */ |
| 839 | nss_ipsec_data_register(NSS_IPSEC_ENCAP_IF_NUMBER, nss_ipsecmgr_buf_drop, dev); |
| 840 | |
| 841 | nss_ipsec_data_register(NSS_C2C_TX_INTERFACE, nss_ipsecmgr_buf_receive, dev); |
| 842 | nss_ipsec_data_register(NSS_IPSEC_DECAP_IF_NUMBER, nss_ipsecmgr_buf_receive, dev); |
| 843 | |
| 844 | nss_ipsec_notify_register(NSS_IPSEC_ENCAP_IF_NUMBER, nss_ipsecmgr_op_receive, dev); |
| 845 | nss_ipsec_notify_register(NSS_IPSEC_DECAP_IF_NUMBER, nss_ipsecmgr_op_receive, dev); |
| 846 | |
| 847 | return dev; |
| 848 | |
| 849 | fail: |
| 850 | free_netdev(dev); |
| 851 | |
| 852 | return NULL; |
| 853 | } |
| 854 | EXPORT_SYMBOL(nss_ipsecmgr_tunnel_add); |
| 855 | |
| 856 | /* |
| 857 | * nss_ipsecmgr_del_tunnel() |
| 858 | * delete an existing IPsec tunnel |
| 859 | */ |
| 860 | bool nss_ipsecmgr_tunnel_del(struct net_device *dev) |
| 861 | { |
| 862 | struct nss_ipsecmgr_priv *priv; |
| 863 | struct nss_ipsecmgr_tbl *encap; |
| 864 | struct nss_ipsecmgr_tbl *decap; |
| 865 | struct nss_ipsec_msg nim; |
| 866 | bool status; |
| 867 | |
| 868 | priv = netdev_priv(dev); |
| 869 | |
| 870 | encap = &priv->encap; |
| 871 | decap = &priv->decap; |
| 872 | |
| 873 | /* |
| 874 | * Unregister the callbacks from the HLOS as we are no longer |
| 875 | * interested in exception data & async messages |
| 876 | */ |
| 877 | |
| 878 | nss_ipsec_data_unregister(priv->nss_ctx, NSS_C2C_TX_INTERFACE); |
| 879 | |
| 880 | nss_ipsec_notify_unregister(priv->nss_ctx, NSS_IPSEC_ENCAP_IF_NUMBER); |
| 881 | nss_ipsec_notify_unregister(priv->nss_ctx, NSS_IPSEC_DECAP_IF_NUMBER); |
| 882 | |
| 883 | nss_ipsec_data_unregister(priv->nss_ctx, NSS_IPSEC_DECAP_IF_NUMBER); |
| 884 | nss_ipsec_data_unregister(priv->nss_ctx, NSS_IPSEC_ENCAP_IF_NUMBER); |
| 885 | |
| 886 | priv->cb_fn = NULL; |
| 887 | priv->cb_ctx = NULL; |
| 888 | |
| 889 | /* |
| 890 | * Prepare to flush all SA(s) inside a tunnel |
| 891 | */ |
| 892 | memset(&nim, 0, sizeof(struct nss_ipsec_msg)); |
| 893 | |
| 894 | status = nss_ipsecmgr_op_send(dev, &nim, NSS_IPSEC_ENCAP_IF_NUMBER, NSS_IPSEC_MSG_TYPE_FLUSH_TUN); |
| 895 | if (status != true) { |
| 896 | nss_ipsecmgr_error("unable complete tunnel deletion, for ingress rules\n"); |
| 897 | goto fail; |
| 898 | } |
| 899 | |
| 900 | /* release all SA(s) associated with the encap */ |
| 901 | atomic_sub(encap->count, &gbl_drv_ctx.sa_count); |
| 902 | |
| 903 | status = nss_ipsecmgr_op_send(dev, &nim, NSS_IPSEC_DECAP_IF_NUMBER, NSS_IPSEC_MSG_TYPE_FLUSH_TUN); |
| 904 | if (status != true) { |
| 905 | nss_ipsecmgr_error("unable complete tunnel deletion, for egress rules\n"); |
| 906 | goto fail; |
| 907 | } |
| 908 | |
| 909 | /* release all SA(s) associated with the decap */ |
| 910 | atomic_sub(decap->count, &gbl_drv_ctx.sa_count); |
| 911 | |
| 912 | /* |
| 913 | * The unregister should start here but the expectation is that the free would |
| 914 | * happen when the reference count goes down to '0' |
| 915 | */ |
| 916 | rtnl_is_locked() ? unregister_netdevice(dev) : unregister_netdev(dev); |
| 917 | |
| 918 | return true; |
| 919 | fail: |
| 920 | /* caller must retry */ |
| 921 | return false; |
| 922 | } |
| 923 | EXPORT_SYMBOL(nss_ipsecmgr_tunnel_del); |
| 924 | |
| 925 | /* |
| 926 | * nss_ipsecmgr_sa_add() |
| 927 | * add a new SA to the tunnel |
| 928 | */ |
| 929 | bool nss_ipsecmgr_sa_add(struct net_device *dev, union nss_ipsecmgr_rule *rule, enum nss_ipsecmgr_rule_type type) |
| 930 | { |
| 931 | struct nss_ipsecmgr_priv *priv; |
| 932 | struct nss_ipsec_msg nim; |
| 933 | uint32_t if_num; |
| 934 | |
| 935 | priv = netdev_priv(dev); |
| 936 | |
| 937 | /* check if there are free SA(s) */ |
| 938 | if (atomic_read(&gbl_drv_ctx.sa_count) == 0) { |
| 939 | return false; |
| 940 | } |
| 941 | |
| 942 | memset(&nim, 0, sizeof(struct nss_ipsec_msg)); |
| 943 | |
| 944 | /* XXX: some basic validation of the passed rule needs to happen */ |
| 945 | |
| 946 | switch (type) { |
| 947 | case NSS_IPSECMGR_RULE_TYPE_ENCAP: |
| 948 | if_num = NSS_IPSEC_ENCAP_IF_NUMBER; |
| 949 | nss_ipsecmgr_copy_encap_add(dev, &nim.msg.push, rule); |
| 950 | break; |
| 951 | |
| 952 | case NSS_IPSECMGR_RULE_TYPE_DECAP: |
| 953 | if_num = NSS_IPSEC_DECAP_IF_NUMBER; |
| 954 | nss_ipsecmgr_copy_decap_add(dev, &nim.msg.push, rule); |
| 955 | break; |
| 956 | |
| 957 | default: |
| 958 | nss_ipsecmgr_error("Unknown rule type(%d) for Add operation\n", type); |
| 959 | return false; |
| 960 | } |
| 961 | |
| 962 | return nss_ipsecmgr_op_send(dev, &nim, if_num, NSS_IPSEC_MSG_TYPE_ADD_RULE); |
| 963 | |
| 964 | } |
| 965 | EXPORT_SYMBOL(nss_ipsecmgr_sa_add); |
| 966 | |
| 967 | /* |
| 968 | * nss_ipsecmgr_sa_del() |
| 969 | * |
| 970 | */ |
| 971 | bool nss_ipsecmgr_sa_del(struct net_device *dev, union nss_ipsecmgr_rule *rule, enum nss_ipsecmgr_rule_type type) |
| 972 | { |
| 973 | struct nss_ipsecmgr_priv *priv; |
| 974 | struct nss_ipsec_msg nim; |
| 975 | uint32_t if_num; |
| 976 | |
| 977 | priv = netdev_priv(dev); |
| 978 | |
| 979 | /* check if all SA(s) are already freed */ |
| 980 | if (atomic_read(&gbl_drv_ctx.sa_count) == NSS_IPSEC_MAX_SA) { |
| 981 | return false; |
| 982 | } |
| 983 | |
| 984 | memset(&nim, 0, sizeof(struct nss_ipsec_msg)); |
| 985 | |
| 986 | /* XXX: some basic validation of the passed rule needs to happen */ |
| 987 | |
| 988 | switch (type) { |
| 989 | case NSS_IPSECMGR_RULE_TYPE_ENCAP: |
| 990 | if_num = NSS_IPSEC_ENCAP_IF_NUMBER; |
| 991 | nss_ipsecmgr_copy_encap_del(dev, &nim.msg.push, rule); |
| 992 | break; |
| 993 | |
| 994 | case NSS_IPSECMGR_RULE_TYPE_DECAP: |
| 995 | if_num = NSS_IPSEC_DECAP_IF_NUMBER; |
| 996 | nss_ipsecmgr_copy_decap_del(dev, &nim.msg.push, rule); |
| 997 | break; |
| 998 | |
| 999 | default: |
| 1000 | nss_ipsecmgr_error("Unknown rule type(%d) for Del operation\n", type); |
| 1001 | return false; |
| 1002 | } |
| 1003 | |
| 1004 | return nss_ipsecmgr_op_send(dev, &nim, if_num, NSS_IPSEC_MSG_TYPE_DEL_RULE); |
| 1005 | } |
| 1006 | EXPORT_SYMBOL(nss_ipsecmgr_sa_del); |
| 1007 | |
| 1008 | static int __init nss_ipsecmgr_init(void) |
| 1009 | { |
| 1010 | nss_ipsecmgr_info("NSS IPsec manager loaded: Build date %s\n", __DATE__); |
| 1011 | |
| 1012 | memset(&gbl_drv_ctx, 0, sizeof(struct nss_ipsecmgr_drv)); |
| 1013 | |
| 1014 | atomic_set(&gbl_drv_ctx.sa_count, NSS_IPSEC_MAX_SA); |
| 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | static void __exit nss_ipsecmgr_exit(void) |
| 1021 | { |
| 1022 | nss_ipsecmgr_info("NSS IPsec manager unloader\n"); |
| 1023 | } |
| 1024 | |
| 1025 | module_init(nss_ipsecmgr_init); |
| 1026 | module_exit(nss_ipsecmgr_exit); |