dpdk: Add support for Mellanox ConnectX-4 devices
[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 {
22   /* convenience */
23   vlib_main_t *vlib_main;
24   vnet_main_t *vnet_main;
25 } source_range_check_main_t;
26
27 source_range_check_main_t source_range_check_main;
28
29 typedef enum
30 {
31   IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT,
32   IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT,
33   IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN,
34   IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN,
35   IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS,
36 } ip_source_and_port_range_check_protocol_t;
37
38 typedef struct
39 {
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 {
47   union
48   {
49     u16x8 as_u16x8;
50     u16 as_u16[8];
51   };
52 } u16x8vec_t;
53
54 typedef struct
55 {
56   u16x8vec_t low;
57   u16x8vec_t hi;
58 } protocol_port_range_t;
59
60 /**
61  * @brief The number of supported ranges per-data path object.
62  * If more ranges are required, bump this number.
63  */
64 #define N_PORT_RANGES_PER_DPO  64
65 #define N_RANGES_PER_BLOCK (sizeof(u16x8vec_t)/2)
66 #define N_BLOCKS_PER_DPO (N_PORT_RANGES_PER_DPO/N_RANGES_PER_BLOCK)
67
68 /**
69  * @brief
70  *  The object that is in the data-path to perform the check.
71  *
72  * Some trade-offs here; memory vs performance.
73  *
74  * performance:
75  *  the principle factor is d-cache line misses/hits.
76  *  so we want the data layout to minimise the d-cache misses. This
77  *  means not following dependent reads. i.e. not doing
78  *
79  *   struct B {
80  *     u16 n_ranges;
81  *     range_t *ragnes; // vector of ranges.
82  *   }
83  *
84  *   so to read ranges[0] we would first d-cache miss on the address
85  *   of the object of type B, for which we would need to wait before we
86  *   can get the address of B->ranges.
87  *   So this layout is better:
88  *
89  *  struct B {
90  *    u16 n_ranges;
91  *    range_t ragnes[N];
92  *  }
93  *
94  * memory:
95  *  the latter layout above is more memory hungry. And N needs to be:
96  *   1 - sized for the maximum required
97  *   2 - fixed, so that objects of type B can be pool allocated and so
98  *       'get'-able using an index.
99  *       An option over fixed might be to allocate contiguous chunk from
100  *       the pool (like we used to do for multi-path adjs).
101  */
102 typedef struct protocol_port_range_dpo_t_
103 {
104   /**
105    * The number of blocks from the 'block' array below
106    * that have rnages configured. We keep this count so that in the data-path
107    * we can limit the loop to be only over the blocks we need
108    */
109   u16 n_used_blocks;
110
111   /**
112    * The total number of free ranges from all blocks.
113    * Used to prevent overrun of the ranges available.
114    */
115   u16 n_free_ranges;
116
117   /**
118    * the fixed size array of ranges
119    */
120   protocol_port_range_t blocks[N_BLOCKS_PER_DPO];
121 } protocol_port_range_dpo_t;
122
123 int ip4_source_and_port_range_check_add_del (ip4_address_t * address,
124                                              u32 length,
125                                              u32 vrf_id,
126                                              u16 * low_ports,
127                                              u16 * hi_ports, int is_add);
128
129 // This will be moved to another file in another patch -- for API freeze
130 int ip6_source_and_port_range_check_add_del (ip6_address_t * address,
131                                              u32 length,
132                                              u32 vrf_id,
133                                              u16 * low_ports,
134                                              u16 * hi_ports, int is_add);
135
136 int set_ip_source_and_port_range_check (vlib_main_t * vm,
137                                         u32 * fib_index,
138                                         u32 sw_if_index, u32 is_add);
139
140 #endif /* included ip_source_and_port_range_check_h */
141
142 /*
143  * fd.io coding-style-patch-verification: ON
144  *
145  * Local Variables:
146  * eval: (c-set-style "gnu")
147  * End:
148  */