FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
lawful_intercept.c
Go to the documentation of this file.
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 
17 
18 static clib_error_t *
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 *
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 
112 
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
vlib_main_t * vlib_main
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
unformat_function_t unformat_ip4_address
Definition: format.h:76
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
vlib_main_t * vm
Definition: buffer.c:276
vlib_node_registration_t li_hit_node
(constructor) VLIB_REGISTER_NODE (li_hit_node)
Definition: node.c:43
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
unsigned int u32
Definition: types.h:88
#define vec_delete(V, N, M)
Delete N elements starting at element M.
Definition: vec.h:785
unsigned short u16
Definition: types.h:57
ip4_address_t * src_addrs
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
static clib_error_t * set_li_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * li_init(vlib_main_t *vm)
li_main_t li_main
vnet_main_t * vnet_main
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:971
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
ip4_address_t * collectors