VPP-651: Ensure sw_if_index to node mapping for L2 output path is only done via l2out...
[vpp.git] / src / plugins / acl / l2sess.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_l2sess_h__
16 #define __included_l2sess_h__
17
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/ethernet/ethernet.h>
21
22 #include <vppinfra/hash.h>
23 #include <vppinfra/error.h>
24 #include <vppinfra/elog.h>
25 #include <vppinfra/timing_wheel.h>
26
27 #include <vnet/l2/l2_output.h>
28 #include <vnet/l2/l2_input.h>
29
30 #define _(node_name, node_var, is_out, is_ip6, is_track)
31 #undef _
32 #define foreach_l2sess_node \
33   _("aclp-l2s-input-ip4-add", l2sess_in_ip4_add, 0, 0, 0)  \
34   _("aclp-l2s-input-ip6-add", l2sess_in_ip6_add, 0, 1, 0)  \
35   _("aclp-l2s-output-ip4-add", l2sess_out_ip4_add, 1, 0, 0) \
36   _("aclp-l2s-output-ip6-add", l2sess_out_ip6_add, 1, 1, 0) \
37   _("aclp-l2s-input-ip4-track", l2sess_in_ip4_track, 0, 0, 1) \
38   _("aclp-l2s-input-ip6-track", l2sess_in_ip6_track, 0, 1, 1) \
39   _("aclp-l2s-output-ip4-track",l2sess_out_ip4_track, 1, 0, 1) \
40   _("aclp-l2s-output-ip6-track", l2sess_out_ip6_track, 1, 1, 1)
41
42 #define _(node_name, node_var, is_out, is_ip6, is_track)  \
43   extern vlib_node_registration_t node_var;
44 foreach_l2sess_node
45 #undef _
46
47 #define TCP_FLAG_FIN    0x01
48 #define TCP_FLAG_SYN    0x02
49 #define TCP_FLAG_RST    0x04
50 #define TCP_FLAG_PUSH   0x08
51 #define TCP_FLAG_ACK    0x10
52 #define TCP_FLAG_URG    0x20
53 #define TCP_FLAG_ECE    0x40
54 #define TCP_FLAG_CWR    0x80
55 #define TCP_FLAGS_RSTFINACKSYN (TCP_FLAG_RST + TCP_FLAG_FIN + TCP_FLAG_SYN + TCP_FLAG_ACK)
56 #define TCP_FLAGS_ACKSYN (TCP_FLAG_SYN + TCP_FLAG_ACK)
57
58 typedef struct {
59   ip46_address_t addr;
60   u64 active_time;
61   u64 n_packets;
62   u64 n_bytes;
63   u16 port;
64 } l2s_session_side_t;
65
66 enum {
67   L2S_SESSION_SIDE_IN = 0,
68   L2S_SESSION_SIDE_OUT,
69   L2S_N_SESSION_SIDES
70 };
71
72 typedef struct {
73   u64 create_time;
74   l2s_session_side_t side[L2S_N_SESSION_SIDES];
75   u8 l4_proto;
76   u8 is_ip6;
77   u16 tcp_flags_seen; /* u16 because of two sides */
78 } l2s_session_t;
79
80 #define PROD
81 #ifdef PROD
82 #define UDP_SESSION_IDLE_TIMEOUT_SEC 600
83 #define TCP_SESSION_IDLE_TIMEOUT_SEC (3600*24)
84 #define TCP_SESSION_TRANSIENT_TIMEOUT_SEC 120
85 #else
86 #define UDP_SESSION_IDLE_TIMEOUT_SEC 15
87 #define TCP_SESSION_IDLE_TIMEOUT_SEC 15
88 #define TCP_SESSION_TRANSIENT_TIMEOUT_SEC 5
89 #endif
90
91 typedef struct {
92     /*
93      * the next two fields are present for all nodes, but
94      *  only one of them is used per node - depending
95      * on whether the node is an input or output one.
96      */
97 #define _(node_name, node_var, is_out, is_ip6, is_track) \
98     u32 node_var ## _feat_next_node_index[32];
99 foreach_l2sess_node
100 #undef _
101     l2_output_next_nodes_st output_next_nodes;
102
103     /* Next indices of the tracker nodes */
104     u32 next_slot_track_node_by_is_ip6_is_out[2][2];
105
106     /* 
107      * Pairing of "forward" and "reverse" tables by table index.
108      * Each relationship has two entries - for one and the other table,
109      * so it is bidirectional.
110      */
111      
112     u32 *fwd_to_rev_by_table_index;
113
114     /*
115      * The vector of per-interface session pools
116      */
117
118     l2s_session_t *sessions;
119
120     /* The session timeouts */
121     u64 tcp_session_transient_timeout;
122     u64 tcp_session_idle_timeout;
123     u64 udp_session_idle_timeout;
124
125     /* Timing wheel to time out the idle sessions */
126     timing_wheel_t timing_wheel;
127     u32 *data_from_advancing_timing_wheel;
128     u64 timer_wheel_next_expiring_time;
129     u64 timer_wheel_tick;
130
131     /* convenience */
132     vlib_main_t * vlib_main;
133     vnet_main_t * vnet_main;
134
135     /* Counter(s) */
136     u64 counter_attempted_delete_free_session;
137 } l2sess_main_t;
138
139 l2sess_main_t l2sess_main;
140
141 /* Just exposed for acl.c */
142
143 void
144 l2sess_vlib_plugin_register (vlib_main_t * vm, void * hh,
145                       int from_early_init);
146
147
148 #endif /* __included_l2sess_h__ */