session: rules tables
[vpp.git] / src / vnet / session / session_rules_table.h
1 /*
2  * Copyright (c) 2017 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 SRC_VNET_SESSION_SESSION_RULES_TABLE_H_
17 #define SRC_VNET_SESSION_SESSION_RULES_TABLE_H_
18
19 #include <vnet/vnet.h>
20 #include <vnet/fib/fib.h>
21 #include <vnet/session/transport.h>
22 #include <vnet/session/mma_16.h>
23 #include <vnet/session/mma_40.h>
24
25 /* *INDENT-OFF* */
26 typedef CLIB_PACKED (struct
27 {
28   union
29     {
30       struct
31         {
32           ip4_address_t rmt_ip;
33           ip4_address_t lcl_ip;
34           u16 rmt_port;
35           u16 lcl_port;
36         };
37       u64 as_u64[2];
38     };
39 }) session_mask_or_match_4_t;
40
41 typedef CLIB_PACKED (struct
42 {
43   union
44     {
45       struct
46         {
47           ip6_address_t rmt_ip;
48           ip6_address_t lcl_ip;
49           u16 rmt_port;
50           u16 lcl_port;
51         };
52       u64 as_u64[5];
53     };
54 }) session_mask_or_match_6_t;
55 /* *INDENT-ON* */
56
57 typedef struct _session_rules_table_add_del_args
58 {
59   u8 transport_proto;
60   fib_prefix_t lcl;
61   fib_prefix_t rmt;
62   u16 lcl_port;
63   u16 rmt_port;
64   u32 action_index;
65   u8 is_add;
66 } session_rule_table_add_del_args_t;
67
68 typedef struct _session_rules_table_t
69 {
70   /**
71    * Per fib proto and transport proto session rules tables
72    */
73   mma_rules_table_16_t session_rules_tables_16[TRANSPORT_N_PROTO];
74   mma_rules_table_40_t session_rules_tables_40[TRANSPORT_N_PROTO];
75 } session_rules_table_t;
76
77 void *session_rules_table_get (session_rules_table_t * srt,
78                                u8 transport_proto, u8 fib_proto);
79 u32 session_rules_table_lookup4 (session_rules_table_t * srt,
80                                  u8 transport_proto, ip4_address_t * lcl_ip,
81                                  ip4_address_t * rmt_ip, u16 lcl_port,
82                                  u16 rmt_port);
83 u32 session_rules_table_lookup6 (session_rules_table_t * srt,
84                                  u8 transport_proto, ip6_address_t * lcl_ip,
85                                  ip6_address_t * rmt_ip, u16 lcl_port,
86                                  u16 rmt_port);
87 void session_rules_table_cli_dump (vlib_main_t * vm,
88                                    session_rules_table_t * srt, u8 fib_proto,
89                                    u8 transport_proto);
90 void session_rules_table_show_rule (vlib_main_t * vm,
91                                     session_rules_table_t * srt,
92                                     u8 transport_proto,
93                                     ip46_address_t * lcl_ip, u16 lcl_port,
94                                     ip46_address_t * rmt_ip, u16 rmt_port,
95                                     u8 is_ip4);
96 clib_error_t *session_rules_table_add_del (session_rules_table_t * srt,
97                                            session_rule_table_add_del_args_t *
98                                            args);
99 void session_rules_table_init (session_rules_table_t * srt);
100 #endif /* SRC_VNET_SESSION_SESSION_RULES_TABLE_H_ */
101 /*
102  * fd.io coding-style-patch-verification: ON
103  *
104  * Local Variables:
105  * eval: (c-set-style "gnu")
106  * End:
107  */