1429057bf1d73d8dcfe7d3e0a07e075b40939cad
[vpp.git] / vnet / vnet / ip / ip_source_and_port_range_check.h
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 #ifndef included_ip_ip_source_and_port_range_check_h
17 #define included_ip_ip_source_and_port_range_check_h
18
19
20 typedef struct {
21   u32 ranges_per_adjacency;
22   u32 special_adjacency_format_function_index;
23
24   /* convenience */
25   vlib_main_t *vlib_main;
26   vnet_main_t *vnet_main;
27 } source_range_check_main_t;
28
29 source_range_check_main_t source_range_check_main;
30
31 typedef enum {
32   IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT,
33   IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT,
34   IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN,
35   IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN,
36   IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS,
37 } ip_source_and_port_range_check_protocol_t;
38
39 typedef struct {
40   u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
41 } ip_source_and_port_range_check_config_t;
42
43 #define IP_SOURCE_AND_PORT_RANGE_CHECK_RANGE_LIMIT VLIB_BUFFER_PRE_DATA_SIZE/(2*sizeof(u16x8));
44
45 typedef struct {
46   union {
47     u16x8 as_u16x8;
48     u16 as_u16[8];
49   };
50 } u16x8vec_t;
51
52 typedef struct {
53   u16x8vec_t low;
54   u16x8vec_t hi;
55 } protocol_port_range_t;
56
57 int ip4_source_and_port_range_check_add_del (ip4_address_t * address,
58                                              u32 length,
59                                              u32 vrf_id,
60                                              u16 * low_ports,
61                                              u16 * hi_ports,
62                                              int is_add);
63
64 // This will be moved to another file in another patch -- for API freeze
65 int ip6_source_and_port_range_check_add_del (ip6_address_t * address,
66                                              u32 length,
67                                              u32 vrf_id,
68                                              u16 * low_ports,
69                                              u16 * hi_ports,
70                                              int is_add);
71
72 int set_ip_source_and_port_range_check (vlib_main_t * vm,
73                                         u32 * fib_index,
74                                         u32 sw_if_index,
75                                         u32 is_add);
76
77 #endif /* included ip_source_and_port_range_check_h */