Driver level time-based src mac filter
[vpp.git] / src / plugins / mactime / mactime.h
1
2 /*
3  * mactime.h - time-based src mac address filtration
4  *
5  * Copyright (c) <current-year> <your-organization>
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef __included_mactime_h__
19 #define __included_mactime_h__
20
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vlib/counter.h>
25
26 #include <vppinfra/hash.h>
27 #include <vppinfra/error.h>
28 #include <vppinfra/time_range.h>
29 #include <vppinfra/bihash_8_8.h>
30
31 #define MACTIME_RANGE_TYPE_DROP 0
32 #define MACTIME_RANGE_TYPE_ALLOW 1
33
34 typedef struct
35 {
36   u8 *device_name;
37   u8 mac_address[6];
38   u32 flags;
39   clib_timebase_range_t *ranges;
40 } mactime_device_t;
41
42 /** Always drop packets from this device */
43 #define MACTIME_DEVICE_FLAG_STATIC_DROP         (1<<0)
44 #define MACTIME_DEVICE_FLAG_STATIC_ALLOW        (1<<1)
45 #define MACTIME_DEVICE_FLAG_DYNAMIC_DROP        (1<<2)
46 #define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW       (1<<3)
47
48 typedef struct
49 {
50   union
51   {
52     u8 mac_address[6];
53     u64 as_u64;
54   };
55 } mactime_key_t;
56
57 typedef struct
58 {
59   /* API message ID base */
60   u16 msg_id_base;
61
62   /* Timebase */
63   clib_timebase_t timebase;
64
65   /* cached sunday midnight */
66   f64 sunday_midnight;
67
68   /* Lookup table */
69   clib_bihash_8_8_t lookup_table;
70
71   /* Device table */
72   mactime_device_t *devices;
73
74   /* Counters */
75   vlib_simple_counter_main_t allow_counters;
76   vlib_simple_counter_main_t drop_counters;
77
78   /* config parameters */
79   u32 lookup_table_num_buckets;
80   uword lookup_table_memory_size;
81   i32 timezone_offset;
82
83   /* Once-only data structure create flag */
84   int feature_initialized;
85
86   /* convenience */
87   vlib_main_t *vlib_main;
88   vnet_main_t *vnet_main;
89   ethernet_main_t *ethernet_main;
90 } mactime_main_t;
91
92 /* size for an hgw use-case */
93 #define MACTIME_NUM_BUCKETS     128
94 #define MACTIME_MEMORY_SIZE     (256<<10)
95
96 extern mactime_main_t mactime_main;
97
98 extern vlib_node_registration_t mactime_node;
99
100 /* Periodic function events */
101 #define MACTIME_EVENT1 1
102 #define MACTIME_EVENT2 2
103 #define MACTIME_EVENT_PERIODIC_ENABLE_DISABLE 3
104
105 #endif /* __included_mactime_h__ */
106
107 /*
108  * fd.io coding-style-patch-verification: ON
109  *
110  * Local Variables:
111  * eval: (c-set-style "gnu")
112  * End:
113  */