mactime: upstream new features
[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 <vnet/ethernet/arp.h>
25 #include <vlib/counter.h>
26
27 #include <vppinfra/hash.h>
28 #include <vppinfra/error.h>
29 #include <vppinfra/time_range.h>
30 #include <vppinfra/bihash_8_8.h>
31
32 #define MACTIME_RANGE_TYPE_DROP 0
33 #define MACTIME_RANGE_TYPE_ALLOW 1
34
35 typedef struct
36 {
37   u8 *device_name;
38   u8 mac_address[6];
39   u64 data_quota;
40   u32 flags;
41   clib_timebase_range_t *ranges;
42 } mactime_device_t;
43
44 /** Always drop packets from this device */
45 #define MACTIME_DEVICE_FLAG_STATIC_DROP         (1<<0)
46 #define MACTIME_DEVICE_FLAG_STATIC_ALLOW        (1<<1)
47 #define MACTIME_DEVICE_FLAG_DYNAMIC_DROP        (1<<2)
48 #define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW       (1<<3)
49 #define MACTIME_DEVICE_FLAG_DROP_UDP_10001      (1<<4)
50
51 typedef struct
52 {
53   union
54   {
55     u8 mac_address[6];
56     u64 as_u64;
57   };
58 } mactime_key_t;
59
60 typedef struct
61 {
62   /* API message ID base */
63   u16 msg_id_base;
64
65   /* Timebase */
66   clib_timebase_t timebase;
67
68   /* cached sunday midnight */
69   f64 sunday_midnight;
70
71   /* Lookup table */
72   clib_bihash_8_8_t lookup_table;
73
74   /* Device table */
75   mactime_device_t *devices;
76
77   /* Counters */
78   vlib_combined_counter_main_t allow_counters;
79   vlib_combined_counter_main_t drop_counters;
80
81   /* config parameters */
82   u32 lookup_table_num_buckets;
83   uword lookup_table_memory_size;
84   i32 timezone_offset;
85
86   /* Once-only data structure create flag */
87   int feature_initialized;
88
89   /* arp cache copy, for "show mactime" */
90   ethernet_arp_ip4_entry_t *arp_cache_copy;
91
92   /* convenience */
93   vlib_main_t *vlib_main;
94   vnet_main_t *vnet_main;
95   ethernet_main_t *ethernet_main;
96 } mactime_main_t;
97
98 /* size for an hgw use-case */
99 #define MACTIME_NUM_BUCKETS     128
100 #define MACTIME_MEMORY_SIZE     (256<<10)
101
102 extern mactime_main_t mactime_main;
103
104 extern vlib_node_registration_t mactime_node;
105 extern vlib_node_registration_t mactime_tx_node;
106
107 void mactime_send_create_entry_message (u8 * mac_address);
108
109 /* Periodic function events */
110 #define MACTIME_EVENT1 1
111 #define MACTIME_EVENT2 2
112 #define MACTIME_EVENT_PERIODIC_ENABLE_DISABLE 3
113
114 #endif /* __included_mactime_h__ */
115
116 /*
117  * fd.io coding-style-patch-verification: ON
118  *
119  * Local Variables:
120  * eval: (c-set-style "gnu")
121  * End:
122  */