VPP-651: Ensure sw_if_index to node mapping for L2 output path is only done via l2out...
[vpp.git] / src / plugins / acl / acl.h
1 /*
2  * Copyright (c) 2016 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 #ifndef included_acl_h
16 #define included_acl_h
17
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/l2/l2_output.h>
21
22
23 #include <vppinfra/hash.h>
24 #include <vppinfra/error.h>
25 #include <vppinfra/elog.h>
26
27 #define  ACL_PLUGIN_VERSION_MAJOR 1
28 #define  ACL_PLUGIN_VERSION_MINOR 1
29
30 extern vlib_node_registration_t acl_in_node;
31 extern vlib_node_registration_t acl_out_node;
32
33 void input_acl_packet_match(u32 sw_if_index, vlib_buffer_t * b0, u32 *nextp, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap);
34 void output_acl_packet_match(u32 sw_if_index, vlib_buffer_t * b0, u32 *nextp, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap);
35
36 enum address_e { IP4, IP6 };
37 typedef struct
38 {
39   enum address_e type;
40   union {
41     ip6_address_t ip6;
42     ip4_address_t ip4;
43   } addr;
44 } address_t;
45
46 /*
47  * ACL rules
48  */
49 typedef struct
50 {
51   u8 is_permit;
52   u8 is_ipv6;
53   ip46_address_t src;
54   u8 src_prefixlen;
55   ip46_address_t dst;
56   u8 dst_prefixlen;
57   u8 proto;
58   u16 src_port_or_type_first;
59   u16 src_port_or_type_last;
60   u16 dst_port_or_code_first;
61   u16 dst_port_or_code_last;
62   u8 tcp_flags_value;
63   u8 tcp_flags_mask;
64 } acl_rule_t;
65
66 typedef struct
67 {
68   u8 is_permit;
69   u8 is_ipv6;
70   u8 src_mac[6];
71   u8 src_mac_mask[6];
72   ip46_address_t src_ip_addr;
73   u8 src_prefixlen;
74 } macip_acl_rule_t;
75
76 /*
77  * ACL
78  */
79 typedef struct
80 {
81   u8 tag[64];
82   u32 count;
83   acl_rule_t *rules;
84 } acl_list_t;
85
86 typedef struct
87 {
88   u8 tag[64];
89   u32 count;
90   macip_acl_rule_t *rules;
91   /* References to the classifier tables that will enforce the rules */
92   u32 ip4_table_index;
93   u32 ip6_table_index;
94   u32 l2_table_index;
95 } macip_acl_list_t;
96
97 typedef struct {
98   /* API message ID base */
99   u16 msg_id_base;
100
101   acl_list_t *acls;     /* Pool of ACLs */
102   macip_acl_list_t *macip_acls; /* Pool of MAC-IP ACLs */
103
104   /* ACLs associated with interfaces */
105   u32 **input_acl_vec_by_sw_if_index;
106   u32 **output_acl_vec_by_sw_if_index;
107
108   /*
109    * Classify tables used to grab the packets for the ACL check,
110    * and serving as the 5-tuple session tables at the same time
111    */
112   u32 *acl_ip4_input_classify_table_by_sw_if_index;
113   u32 *acl_ip6_input_classify_table_by_sw_if_index;
114   u32 *acl_ip4_output_classify_table_by_sw_if_index;
115   u32 *acl_ip6_output_classify_table_by_sw_if_index;
116
117   /* MACIP (input) ACLs associated with the interfaces */
118   u32 *macip_acl_by_sw_if_index;
119
120   /* next indices for our nodes in the l2-classify tables */
121   u32 l2_input_classify_next_acl;
122   u32 l2_output_classify_next_acl;
123
124   /* next node indices for feature bitmap */
125   u32 acl_in_node_feat_next_node_index[32];
126   u32 acl_out_node_feat_next_node_index[32];
127
128   /* ACL match actions (must be coherent across in/out ACLs to next indices (can differ) */
129
130   u32 acl_in_ip4_match_next[256];
131   u32 acl_in_ip6_match_next[256];
132   u32 acl_out_ip4_match_next[256];
133   u32 acl_out_ip6_match_next[256];
134   u32 n_match_actions;
135
136
137   /* convenience */
138   vlib_main_t * vlib_main;
139   vnet_main_t * vnet_main;
140 } acl_main_t;
141
142 extern acl_main_t acl_main;
143
144
145 #endif