dpdk-cryptodev: fix coverity issues
[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_link_sync_cb_t) (void);
25 typedef void (*nl_rt_addr_cb_t) (struct rtnl_addr *ra);
26 typedef void (*nl_rt_addr_sync_cb_t) (void);
27 typedef void (*nl_rt_neigh_cb_t) (struct rtnl_neigh *rr);
28 typedef void (*nl_rt_neigh_sync_cb_t) (void);
29 typedef void (*nl_rt_route_add_cb_t) (struct rtnl_route *rn, int is_replace);
30 typedef void (*nl_rt_route_del_cb_t) (struct rtnl_route *rn);
31 typedef void (*nl_rt_route_sync_cb_t) (void);
32
33 #define NL_RT_COMMON uword is_mp_safe
34
35 typedef struct nl_rt_link_t_
36 {
37   NL_RT_COMMON;
38
39   nl_rt_link_cb_t cb;
40 } nl_rt_link_t;
41
42 typedef struct nl_rt_link_sync_t_
43 {
44   NL_RT_COMMON;
45
46   nl_rt_link_sync_cb_t cb;
47 } nl_rt_link_sync_t;
48
49 typedef struct nl_rt_addr_t_
50 {
51   NL_RT_COMMON;
52
53   nl_rt_addr_cb_t cb;
54 } nl_rt_addr_t;
55
56 typedef struct nl_rt_addr_sync_t_
57 {
58   NL_RT_COMMON;
59
60   nl_rt_addr_sync_cb_t cb;
61 } nl_rt_addr_sync_t;
62
63 typedef struct nl_rt_neigh_t_
64 {
65   NL_RT_COMMON;
66
67   nl_rt_neigh_cb_t cb;
68 } nl_rt_neigh_t;
69
70 typedef struct nl_rt_neigh_sync_t_
71 {
72   NL_RT_COMMON;
73
74   nl_rt_neigh_sync_cb_t cb;
75 } nl_rt_neigh_sync_t;
76
77 typedef struct nl_rt_route_add_t_
78 {
79   NL_RT_COMMON;
80
81   nl_rt_route_add_cb_t cb;
82 } nl_rt_route_add_t;
83
84 typedef struct nl_rt_route_del_t_
85 {
86   NL_RT_COMMON;
87
88   nl_rt_route_del_cb_t cb;
89 } nl_rt_route_del_t;
90
91 typedef struct nl_rt_route_sync_t_
92 {
93   NL_RT_COMMON;
94
95   nl_rt_route_sync_cb_t cb;
96 } nl_rt_route_sync_t;
97
98 #undef NL_RT_COMMON
99
100 typedef struct nl_vft_t_
101 {
102   nl_rt_link_t nvl_rt_link_add;
103   nl_rt_link_t nvl_rt_link_del;
104   nl_rt_link_sync_t nvl_rt_link_sync_begin;
105   nl_rt_link_sync_t nvl_rt_link_sync_end;
106   nl_rt_addr_t nvl_rt_addr_add;
107   nl_rt_addr_t nvl_rt_addr_del;
108   nl_rt_addr_sync_t nvl_rt_addr_sync_begin;
109   nl_rt_addr_sync_t nvl_rt_addr_sync_end;
110   nl_rt_neigh_t nvl_rt_neigh_add;
111   nl_rt_neigh_t nvl_rt_neigh_del;
112   nl_rt_neigh_sync_t nvl_rt_neigh_sync_begin;
113   nl_rt_neigh_sync_t nvl_rt_neigh_sync_end;
114   nl_rt_route_add_t nvl_rt_route_add;
115   nl_rt_route_del_t nvl_rt_route_del;
116   nl_rt_route_sync_t nvl_rt_route_sync_begin;
117   nl_rt_route_sync_t nvl_rt_route_sync_end;
118 } nl_vft_t;
119
120 extern void nl_register_vft (const nl_vft_t *nv);
121
122 typedef enum lcp_nl_obj_t_
123 {
124   LCP_NL_LINK,
125   LCP_NL_ADDR,
126   LCP_NL_NEIGH,
127   LCP_NL_ROUTE,
128 } lcp_nl_obj_t;
129
130 /* struct type to hold context on the netlink message being processed.
131  *
132  * At creation of a pair, a tap/tun is created and configured to match its
133  * corresponding hardware interface (MAC address, link state, MTU). Netlink
134  * messages are sent announcing the creation and subsequent configuration.
135  * We do not need to (and should not) act on those messages since applying
136  * those same configurations again is unnecessary and can be disruptive. So
137  * a timestamp for a message is stored and can be compared against the time
138  * the interface came under linux-cp management in order to figure out
139  * whether we should apply any configuration.
140  */
141 typedef struct nl_msg_info
142 {
143   struct nl_msg *msg;
144   f64 ts;
145 } nl_msg_info_t;
146
147 #define LCP_NL_N_OBJS (LCP_NL_ROUTE + 1)
148
149 extern struct nl_cache *lcp_nl_get_cache (lcp_nl_obj_t t);
150 extern int lcp_nl_drain_messages (void);
151 extern void lcp_nl_set_buffer_size (u32 buf_size);
152 extern void lcp_nl_set_batch_size (u32 batch_size);
153 extern void lcp_nl_set_batch_delay (u32 batch_delay_ms);
154
155 /*
156  * fd.io coding-style-patch-verification: ON
157  *
158  * Local Variables:
159  * eval: (c-set-style "gnu")
160  * End:
161  */