linux-cp: Linux Control Plane Netlink Listener
[vpp.git] / src / plugins / linux-cp / lcp_nl.h
1 /*
2  * Copyright (c) 2019 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
16 #include <vlib/vlib.h>
17
18 #include <netlink/route/link.h>
19 #include <netlink/route/route.h>
20 #include <netlink/route/neighbour.h>
21 #include <netlink/route/addr.h>
22
23 typedef void (*nl_rt_link_cb_t) (struct rtnl_link *rl, void *ctx);
24 typedef void (*nl_rt_addr_cb_t) (struct rtnl_addr *ra);
25 typedef void (*nl_rt_neigh_cb_t) (struct rtnl_neigh *rr);
26 typedef void (*nl_rt_route_cb_t) (struct rtnl_route *rn);
27
28 #define NL_RT_COMMON uword is_mp_safe
29
30 typedef struct nl_rt_link_t_
31 {
32   NL_RT_COMMON;
33
34   nl_rt_link_cb_t cb;
35 } nl_rt_link_t;
36
37 typedef struct nl_rt_addr_t_
38 {
39   NL_RT_COMMON;
40
41   nl_rt_addr_cb_t cb;
42 } nl_rt_addr_t;
43
44 typedef struct nl_rt_neigh_t_
45 {
46   NL_RT_COMMON;
47
48   nl_rt_neigh_cb_t cb;
49 } nl_rt_neigh_t;
50
51 typedef struct nl_rt_route_t_
52 {
53   NL_RT_COMMON;
54
55   nl_rt_route_cb_t cb;
56 } nl_rt_route_t;
57
58 #undef NL_RT_COMMON
59
60 typedef struct nl_vft_t_
61 {
62   nl_rt_link_t nvl_rt_link_add;
63   nl_rt_link_t nvl_rt_link_del;
64   nl_rt_addr_t nvl_rt_addr_add;
65   nl_rt_addr_t nvl_rt_addr_del;
66   nl_rt_neigh_t nvl_rt_neigh_add;
67   nl_rt_neigh_t nvl_rt_neigh_del;
68   nl_rt_route_t nvl_rt_route_add;
69   nl_rt_route_t nvl_rt_route_del;
70 } nl_vft_t;
71
72 extern void nl_register_vft (const nl_vft_t *nv);
73
74 typedef enum lcp_nl_obj_t_
75 {
76   LCP_NL_LINK,
77   LCP_NL_ADDR,
78   LCP_NL_NEIGH,
79   LCP_NL_ROUTE,
80 } lcp_nl_obj_t;
81
82 /* struct type to hold context on the netlink message being processed.
83  *
84  * At creation of a pair, a tap/tun is created and configured to match its
85  * corresponding hardware interface (MAC address, link state, MTU). Netlink
86  * messages are sent announcing the creation and subsequent configuration.
87  * We do not need to (and should not) act on those messages since applying
88  * those same configurations again is unnecessary and can be disruptive. So
89  * a timestamp for a message is stored and can be compared against the time
90  * the interface came under linux-cp management in order to figure out
91  * whether we should apply any configuration.
92  */
93 typedef struct nl_msg_info
94 {
95   struct nl_msg *msg;
96   f64 ts;
97 } nl_msg_info_t;
98
99 #define LCP_NL_N_OBJS (LCP_NL_ROUTE + 1)
100
101 extern struct nl_cache *lcp_nl_get_cache (lcp_nl_obj_t t);
102 extern int lcp_nl_drain_messages (void);
103 extern void lcp_nl_set_buffer_size (u32 buf_size);
104 extern void lcp_nl_set_batch_size (u32 batch_size);
105 extern void lcp_nl_set_batch_delay (u32 batch_delay_ms);
106
107 /*
108  * fd.io coding-style-patch-verification: ON
109  *
110  * Local Variables:
111  * eval: (c-set-style "gnu")
112  * End:
113  */