Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vnet/lawful-intercept/lawful_intercept.h> |
| 17 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 18 | li_main_t li_main; |
| 19 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | static clib_error_t * |
| 21 | set_li_command_fn (vlib_main_t * vm, |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 22 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 23 | { |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 24 | li_main_t *lm = &li_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | ip4_address_t collector; |
| 26 | u8 collector_set = 0; |
| 27 | ip4_address_t src; |
| 28 | u8 src_set = 0; |
| 29 | u32 tmp; |
| 30 | u16 udp_port = 0; |
| 31 | u8 is_add = 1; |
| 32 | int i; |
| 33 | |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 34 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 35 | { |
| 36 | if (unformat (input, "collector %U", unformat_ip4_address, &collector)) |
| 37 | collector_set = 1; |
| 38 | if (unformat (input, "src %U", unformat_ip4_address, &src)) |
| 39 | src_set = 1; |
| 40 | else if (unformat (input, "udp-port %d", &tmp)) |
| 41 | udp_port = tmp; |
| 42 | else if (unformat (input, "del")) |
| 43 | is_add = 0; |
| 44 | else |
| 45 | break; |
| 46 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | |
| 48 | if (collector_set == 0) |
| 49 | return clib_error_return (0, "collector must be set..."); |
| 50 | if (src_set == 0) |
| 51 | return clib_error_return (0, "src must be set..."); |
| 52 | if (udp_port == 0) |
| 53 | return clib_error_return (0, "udp-port must be set..."); |
| 54 | |
| 55 | if (is_add == 1) |
| 56 | { |
| 57 | for (i = 0; i < vec_len (lm->collectors); i++) |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 58 | { |
| 59 | if (lm->collectors[i].as_u32 == collector.as_u32) |
| 60 | { |
| 61 | if (lm->ports[i] == udp_port) |
hemant_mnkcg | 1691da6 | 2021-04-27 18:02:13 -0400 | [diff] [blame] | 62 | return clib_error_return ( |
| 63 | 0, "collector %U:%d already configured", format_ip4_address, |
| 64 | &collector, udp_port); |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 65 | else |
hemant_mnkcg | 1691da6 | 2021-04-27 18:02:13 -0400 | [diff] [blame] | 66 | return clib_error_return ( |
| 67 | 0, "collector %U already configured with port %d", |
| 68 | format_ip4_address, &collector, (int) (lm->ports[i])); |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 69 | } |
| 70 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | vec_add1 (lm->collectors, collector); |
| 72 | vec_add1 (lm->ports, udp_port); |
| 73 | vec_add1 (lm->src_addrs, src); |
| 74 | return 0; |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | for (i = 0; i < vec_len (lm->collectors); i++) |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 79 | { |
| 80 | if ((lm->collectors[i].as_u32 == collector.as_u32) |
| 81 | && lm->ports[i] == udp_port) |
| 82 | { |
| 83 | vec_delete (lm->collectors, 1, i); |
| 84 | vec_delete (lm->ports, 1, i); |
| 85 | vec_delete (lm->src_addrs, 1, i); |
| 86 | return 0; |
| 87 | } |
| 88 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | return clib_error_return (0, "collector %U:%d not configured", |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 90 | &collector, udp_port); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | } |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | VLIB_CLI_COMMAND (set_li_command, static) = { |
| 96 | .path = "set li", |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 97 | .short_help = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | "set li src <ip4-address> collector <ip4-address> udp-port <nnnn>", |
| 99 | .function = set_li_command_fn, |
| 100 | }; |
| 101 | |
| 102 | static clib_error_t * |
| 103 | li_init (vlib_main_t * vm) |
| 104 | { |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 105 | li_main_t *lm = &li_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 106 | |
| 107 | lm->vlib_main = vm; |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 108 | lm->vnet_main = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | lm->hit_node_index = li_hit_node.index; |
| 110 | return 0; |
| 111 | } |
| 112 | |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 113 | VLIB_INIT_FUNCTION (li_init); |
Dave Barach | bfdedbd | 2016-01-20 09:11:55 -0500 | [diff] [blame] | 114 | |
satish.karunanithi | 93fbcc6 | 2017-12-06 16:11:59 +0530 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * fd.io coding-style-patch-verification: ON |
| 118 | * |
| 119 | * Local Variables: |
| 120 | * eval: (c-set-style "gnu") |
| 121 | * End: |
| 122 | */ |