FD.io VPP  v16.12-rc0-308-g931be3a
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 
16 #if DPDK==1
18 
19 static clib_error_t *
21  unformat_input_t * input,
22  vlib_cli_command_t * cmd)
23 {
24  li_main_t * lm = &li_main;
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 
34  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
35  if (unformat (input, "collector %U", unformat_ip4_address, &collector))
36  collector_set = 1;
37  if (unformat (input, "src %U", unformat_ip4_address, &src))
38  src_set = 1;
39  else if (unformat (input, "udp-port %d", &tmp))
40  udp_port = tmp;
41  else if (unformat (input, "del"))
42  is_add = 0;
43  else
44  break;
45  }
46 
47  if (collector_set == 0)
48  return clib_error_return (0, "collector must be set...");
49  if (src_set == 0)
50  return clib_error_return (0, "src must be set...");
51  if (udp_port == 0)
52  return clib_error_return (0, "udp-port must be set...");
53 
54  if (is_add == 1)
55  {
56  for (i = 0; i < vec_len (lm->collectors); i++)
57  {
58  if (lm->collectors[i].as_u32 == collector.as_u32)
59  {
60  if (lm->ports[i] == udp_port)
61  return clib_error_return
62  (0, "collector %U:%d already configured",
63  &collector, udp_port);
64  else
65  return clib_error_return
66  (0, "collector %U already configured with port %d",
67  &collector, (int)(lm->ports[i]));
68  }
69  }
70  vec_add1 (lm->collectors, collector);
71  vec_add1 (lm->ports, udp_port);
72  vec_add1 (lm->src_addrs, src);
73  return 0;
74  }
75  else
76  {
77  for (i = 0; i < vec_len (lm->collectors); i++)
78  {
79  if ((lm->collectors[i].as_u32 == collector.as_u32)
80  && lm->ports[i] == udp_port)
81  {
82  vec_delete (lm->collectors, 1, i);
83  vec_delete (lm->ports, 1, i);
84  vec_delete (lm->src_addrs, 1, i);
85  return 0;
86  }
87  }
88  return clib_error_return (0, "collector %U:%d not configured",
89  &collector, udp_port);
90  }
91  return 0;
92 }
93 
94 VLIB_CLI_COMMAND (set_li_command, static) = {
95  .path = "set li",
96  .short_help =
97  "set li src <ip4-address> collector <ip4-address> udp-port <nnnn>",
98  .function = set_li_command_fn,
99 };
100 
101 static clib_error_t *
103 {
104  li_main_t * lm = &li_main;
105 
106  lm->vlib_main = vm;
107  lm->vnet_main = vnet_get_main();
108  lm->hit_node_index = li_hit_node.index;
109  return 0;
110 }
111 
113 #else
114 #endif /* DPDK */
115 
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
vlib_main_t * vlib_main
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
unformat_function_t unformat_ip4_address
Definition: format.h:75
vlib_node_registration_t li_hit_node
(constructor) VLIB_REGISTER_NODE (li_hit_node)
Definition: node.c:44
#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:745
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
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
vnet_main_t * vnet_main
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
ip4_address_t * collectors