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