Add MAC address support to LISP map-cache
[vpp.git] / vnet / vnet / lawful-intercept / lawful_intercept.c
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
17 #include <vnet/lawful-intercept/lawful_intercept.h>
18
19 static clib_error_t *
20 set_li_command_fn (vlib_main_t * vm,
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 *
102 li_init (vlib_main_t * vm)
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
112 VLIB_INIT_FUNCTION(li_init);
113 #else
114 #endif /* DPDK */
115