FD.io VPP  v21.06-3-gbb25fbf28
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 
19 
20 static clib_error_t *
22  unformat_input_t * input, vlib_cli_command_t * cmd)
23 {
24  li_main_t *lm = &li_main;
25  ip4_address_t collector;
26  u8 collector_set = 0;
28  u8 src_set = 0;
29  u32 tmp;
30  u16 udp_port = 0;
31  u8 is_add = 1;
32  int i;
33 
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  }
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++)
58  {
59  if (lm->collectors[i].as_u32 == collector.as_u32)
60  {
61  if (lm->ports[i] == udp_port)
62  return clib_error_return (
63  0, "collector %U:%d already configured", format_ip4_address,
64  &collector, udp_port);
65  else
66  return clib_error_return (
67  0, "collector %U already configured with port %d",
68  format_ip4_address, &collector, (int) (lm->ports[i]));
69  }
70  }
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++)
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  }
89  return clib_error_return (0, "collector %U:%d not configured",
90  &collector, udp_port);
91  }
92  return 0;
93 }
94 
95 /* *INDENT-OFF* */
97  .path = "set li",
98  .short_help =
99  "set li src <ip4-address> collector <ip4-address> udp-port <nnnn>",
100  .function = set_li_command_fn,
101 };
102 /* *INDENT-ON* */
103 
104 static clib_error_t *
106 {
107  li_main_t *lm = &li_main;
108 
109  lm->vlib_main = vm;
110  lm->vnet_main = vnet_get_main ();
111  lm->hit_node_index = li_hit_node.index;
112  return 0;
113 }
114 
116 
117 
118 /*
119  * fd.io coding-style-patch-verification: ON
120  *
121  * Local Variables:
122  * eval: (c-set-style "gnu")
123  * End:
124  */
li_main_t::vnet_main
vnet_main_t * vnet_main
Definition: lawful_intercept.h:34
tmp
u32 * tmp
Definition: interface_output.c:1078
lawful_intercept.h
set_li_command_fn
static clib_error_t * set_li_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: lawful_intercept.c:21
format_ip4_address
format_function_t format_ip4_address
Definition: format.h:73
li_main_t::ports
u16 * ports
Definition: lawful_intercept.h:27
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
ip4_address_t::as_u32
u32 as_u32
Definition: ip4_packet.h:57
li_main_t
Definition: lawful_intercept.h:22
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vec_delete
#define vec_delete(V, N, M)
Delete N elements starting at element M.
Definition: vec.h:875
li_main
li_main_t li_main
Definition: lawful_intercept.c:18
unformat_input_t
struct _unformat_input_t unformat_input_t
li_main_t::collectors
ip4_address_t * collectors
Definition: lawful_intercept.h:26
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
set_li_command
static vlib_cli_command_t set_li_command
(constructor) VLIB_CLI_COMMAND (set_li_command)
Definition: lawful_intercept.c:96
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
li_main_t::hit_node_index
u32 hit_node_index
Definition: lawful_intercept.h:30
li_main_t::src_addrs
ip4_address_t * src_addrs
Definition: lawful_intercept.h:25
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
unformat_ip4_address
unformat_function_t unformat_ip4_address
Definition: format.h:68
li_init
static clib_error_t * li_init(vlib_main_t *vm)
Definition: lawful_intercept.c:105
vlib_cli_command_t
Definition: cli.h:92
li_hit_node
vlib_node_registration_t li_hit_node
(constructor) VLIB_REGISTER_NODE (li_hit_node)
Definition: node.c:264
li_main_t::vlib_main
vlib_main_t * vlib_main
Definition: lawful_intercept.h:33
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137