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 | |
| 18 | static clib_error_t * |
| 19 | set_li_command_fn (vlib_main_t * vm, |
| 20 | unformat_input_t * input, |
| 21 | vlib_cli_command_t * cmd) |
| 22 | { |
| 23 | li_main_t * lm = &li_main; |
| 24 | ip4_address_t collector; |
| 25 | u8 collector_set = 0; |
| 26 | ip4_address_t src; |
| 27 | u8 src_set = 0; |
| 28 | u32 tmp; |
| 29 | u16 udp_port = 0; |
| 30 | u8 is_add = 1; |
| 31 | int i; |
| 32 | |
| 33 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { |
| 34 | if (unformat (input, "collector %U", unformat_ip4_address, &collector)) |
| 35 | collector_set = 1; |
| 36 | if (unformat (input, "src %U", unformat_ip4_address, &src)) |
| 37 | src_set = 1; |
| 38 | else if (unformat (input, "udp-port %d", &tmp)) |
| 39 | udp_port = tmp; |
| 40 | else if (unformat (input, "del")) |
| 41 | is_add = 0; |
| 42 | else |
| 43 | break; |
| 44 | } |
| 45 | |
| 46 | if (collector_set == 0) |
| 47 | return clib_error_return (0, "collector must be set..."); |
| 48 | if (src_set == 0) |
| 49 | return clib_error_return (0, "src must be set..."); |
| 50 | if (udp_port == 0) |
| 51 | return clib_error_return (0, "udp-port must be set..."); |
| 52 | |
| 53 | if (is_add == 1) |
| 54 | { |
| 55 | for (i = 0; i < vec_len (lm->collectors); i++) |
| 56 | { |
| 57 | if (lm->collectors[i].as_u32 == collector.as_u32) |
| 58 | { |
| 59 | if (lm->ports[i] == udp_port) |
| 60 | return clib_error_return |
| 61 | (0, "collector %U:%d already configured", |
| 62 | &collector, udp_port); |
| 63 | else |
| 64 | return clib_error_return |
| 65 | (0, "collector %U already configured with port %d", |
| 66 | &collector, (int)(lm->ports[i])); |
| 67 | } |
| 68 | } |
| 69 | vec_add1 (lm->collectors, collector); |
| 70 | vec_add1 (lm->ports, udp_port); |
| 71 | vec_add1 (lm->src_addrs, src); |
| 72 | return 0; |
| 73 | } |
| 74 | else |
| 75 | { |
| 76 | for (i = 0; i < vec_len (lm->collectors); i++) |
| 77 | { |
| 78 | if ((lm->collectors[i].as_u32 == collector.as_u32) |
| 79 | && lm->ports[i] == udp_port) |
| 80 | { |
| 81 | vec_delete (lm->collectors, 1, i); |
| 82 | vec_delete (lm->ports, 1, i); |
| 83 | vec_delete (lm->src_addrs, 1, i); |
| 84 | return 0; |
| 85 | } |
| 86 | } |
| 87 | return clib_error_return (0, "collector %U:%d not configured", |
| 88 | &collector, udp_port); |
| 89 | } |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | VLIB_CLI_COMMAND (set_li_command, static) = { |
| 94 | .path = "set li", |
| 95 | .short_help = |
| 96 | "set li src <ip4-address> collector <ip4-address> udp-port <nnnn>", |
| 97 | .function = set_li_command_fn, |
| 98 | }; |
| 99 | |
| 100 | static clib_error_t * |
| 101 | li_init (vlib_main_t * vm) |
| 102 | { |
| 103 | li_main_t * lm = &li_main; |
| 104 | |
| 105 | lm->vlib_main = vm; |
| 106 | lm->vnet_main = vnet_get_main(); |
| 107 | lm->hit_node_index = li_hit_node.index; |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | VLIB_INIT_FUNCTION(li_init); |
Dave Barach | bfdedbd | 2016-01-20 09:11:55 -0500 | [diff] [blame] | 112 | |