]> git.proxmox.com Git - mirror_frr.git/blob - zebra/interface.h
Merge pull request #12191 from manojvn/463777
[mirror_frr.git] / zebra / interface.h
1
2 /* Interface function header.
3 * Copyright (C) 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _ZEBRA_INTERFACE_H
23 #define _ZEBRA_INTERFACE_H
24
25 #include "redistribute.h"
26 #include "vrf.h"
27 #include "hook.h"
28 #include "bitfield.h"
29
30 #include "zebra/zebra_l2.h"
31 #include "zebra/zebra_nhg_private.h"
32 #include "zebra/zebra_router.h"
33 #include "zebra/rtadv.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /* For interface configuration. */
40 #define IF_ZEBRA_DATA_UNSPEC 0
41 #define IF_ZEBRA_DATA_ON 1
42 #define IF_ZEBRA_DATA_OFF 2
43
44 #define IF_VLAN_BITMAP_MAX 4096
45
46 /* Zebra interface type - ones of interest. */
47 enum zebra_iftype {
48 ZEBRA_IF_OTHER = 0, /* Anything else */
49 ZEBRA_IF_VXLAN, /* VxLAN interface */
50 ZEBRA_IF_VRF, /* VRF device */
51 ZEBRA_IF_BRIDGE, /* bridge device */
52 ZEBRA_IF_VLAN, /* VLAN sub-interface */
53 ZEBRA_IF_MACVLAN, /* MAC VLAN interface*/
54 ZEBRA_IF_VETH, /* VETH interface*/
55 ZEBRA_IF_BOND, /* Bond */
56 ZEBRA_IF_BOND_SLAVE, /* Bond */
57 ZEBRA_IF_GRE, /* GRE interface */
58 };
59
60 /* Zebra "slave" interface type */
61 enum zebra_slave_iftype {
62 ZEBRA_IF_SLAVE_NONE, /* Not a slave */
63 ZEBRA_IF_SLAVE_VRF, /* Member of a VRF */
64 ZEBRA_IF_SLAVE_BRIDGE, /* Member of a bridge */
65 ZEBRA_IF_SLAVE_BOND, /* Bond member */
66 ZEBRA_IF_SLAVE_OTHER, /* Something else - e.g., bond slave */
67 };
68
69 struct irdp_interface;
70
71 /* Ethernet segment info used for setting up EVPN multihoming */
72 struct zebra_evpn_es;
73 struct zebra_es_if_info {
74 /* type-3 esi config */
75 struct ethaddr sysmac;
76 uint32_t lid; /* local-id; has to be unique per-ES-sysmac */
77
78 esi_t esi;
79
80 uint16_t df_pref;
81 uint8_t flags;
82 #define ZIF_CFG_ES_FLAG_BYPASS (1 << 0)
83
84 struct zebra_evpn_es *es; /* local ES */
85 };
86
87 enum zebra_if_flags {
88 /* device has been configured as an uplink for
89 * EVPN multihoming
90 */
91 ZIF_FLAG_EVPN_MH_UPLINK = (1 << 0),
92 ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP = (1 << 1),
93
94 /* Dataplane protodown-on */
95 ZIF_FLAG_PROTODOWN = (1 << 2),
96 /* Dataplane protodown-on Queued to the dplane */
97 ZIF_FLAG_SET_PROTODOWN = (1 << 3),
98 /* Dataplane protodown-off Queued to the dplane */
99 ZIF_FLAG_UNSET_PROTODOWN = (1 << 4),
100
101 /* LACP bypass state is set by the dataplane on a bond member
102 * and inherited by the bond (if one or more bond members are in
103 * a bypass state the bond is placed in a bypass state)
104 */
105 ZIF_FLAG_LACP_BYPASS = (1 << 5)
106 };
107
108 #define ZEBRA_IF_IS_PROTODOWN(zif) ((zif)->flags & ZIF_FLAG_PROTODOWN)
109 #define ZEBRA_IF_IS_PROTODOWN_ONLY_EXTERNAL(zif) \
110 ((zif)->protodown_rc == ZEBRA_PROTODOWN_EXTERNAL)
111
112 /* Mem type for zif desc */
113 DECLARE_MTYPE(ZIF_DESC);
114
115 /* `zebra' daemon local interface structure. */
116 struct zebra_if {
117 /* back pointer to the interface */
118 struct interface *ifp;
119
120 enum zebra_if_flags flags;
121
122 /* Shutdown configuration. */
123 uint8_t shutdown;
124
125 /* Multicast configuration. */
126 uint8_t multicast;
127
128 /* MPLS status. */
129 bool mpls;
130
131 /* Linkdown status */
132 bool linkdown, linkdownv6;
133
134 /* Is Multicast Forwarding on? */
135 bool v4mcast_on, v6mcast_on;
136
137 /* Router advertise configuration. */
138 uint8_t rtadv_enable;
139
140 /* Installed addresses chains tree. */
141 struct route_table *ipv4_subnets;
142
143 /* Nexthops pointing to this interface */
144 /**
145 * Any nexthop that we get should have an
146 * interface. When an interface goes down,
147 * we will use this list to update the nexthops
148 * pointing to it with that info.
149 */
150 struct nhg_connected_tree_head nhg_dependents;
151
152 /* Information about up/down changes */
153 unsigned int up_count;
154 char up_last[FRR_TIMESTAMP_LEN];
155 unsigned int down_count;
156 char down_last[FRR_TIMESTAMP_LEN];
157
158 struct rtadvconf rtadv;
159 unsigned int ra_sent, ra_rcvd;
160
161 struct irdp_interface *irdp;
162
163 #ifdef HAVE_STRUCT_SOCKADDR_DL
164 union {
165 /* note that sdl_storage is never accessed, it only exists to
166 * make space.
167 * all actual uses refer to sdl - but use sizeof(sdl_storage)!
168 * this fits
169 * best with C aliasing rules. */
170 struct sockaddr_dl sdl;
171 struct sockaddr_storage sdl_storage;
172 };
173 #endif
174
175 /* ptm enable configuration */
176 uint8_t ptm_enable;
177
178 /* Zebra interface and "slave" interface type */
179 enum zebra_iftype zif_type;
180 enum zebra_slave_iftype zif_slave_type;
181
182 /* Additional L2 info, depends on zif_type */
183 union zebra_l2if_info l2info;
184
185 /* For members of a bridge, link to bridge. */
186 /* Note: If additional fields become necessary, this can be modified to
187 * be a pointer to a dynamically allocd struct.
188 */
189 struct zebra_l2info_brslave brslave_info;
190
191 struct zebra_l2info_bondslave bondslave_info;
192 struct zebra_l2info_bond bond_info;
193
194 /* ethernet segment */
195 struct zebra_es_if_info es_info;
196
197 /* bitmap of vlans associated with this interface */
198 bitfield_t vlan_bitmap;
199
200 /* An interface can be error-disabled if a protocol (such as EVPN or
201 * VRRP) detects a problem with keeping it operationally-up.
202 * If any of the protodown bits are set protodown-on is programmed
203 * in the dataplane. This results in a carrier/L1 down on the
204 * physical device.
205 */
206 uint32_t protodown_rc;
207
208 /* list of zebra_mac entries using this interface as destination */
209 struct list *mac_list;
210
211 /* Link fields - for sub-interfaces. */
212 ifindex_t link_ifindex;
213 struct interface *link;
214
215 uint8_t speed_update_count;
216 struct thread *speed_update;
217
218 /*
219 * Does this interface have a v6 to v4 ll neighbor entry
220 * for bgp unnumbered?
221 */
222 bool v6_2_v4_ll_neigh_entry;
223 char neigh_mac[6];
224 struct in6_addr v6_2_v4_ll_addr6;
225
226 /* The description of the interface */
227 char *desc;
228 };
229
230 DECLARE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
231 (vty, ifp));
232 DECLARE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp),
233 (vty, ifp));
234
235 #define IS_ZEBRA_IF_VRF(ifp) \
236 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VRF)
237
238 #define IS_ZEBRA_IF_BRIDGE(ifp) \
239 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BRIDGE)
240
241 #define IS_ZEBRA_IF_VLAN(ifp) \
242 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VLAN)
243
244 #define IS_ZEBRA_IF_VXLAN(ifp) \
245 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VXLAN)
246
247 #define IS_ZEBRA_IF_MACVLAN(ifp) \
248 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_MACVLAN)
249
250 #define IS_ZEBRA_IF_VETH(ifp) \
251 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VETH)
252
253 #define IS_ZEBRA_IF_BOND(ifp) \
254 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BOND)
255
256 #define IS_ZEBRA_IF_GRE(ifp) \
257 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_GRE)
258
259 #define IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) \
260 (((struct zebra_if *)(ifp->info))->zif_slave_type \
261 == ZEBRA_IF_SLAVE_BRIDGE)
262
263 #define IS_ZEBRA_IF_VRF_SLAVE(ifp) \
264 (((struct zebra_if *)(ifp->info))->zif_slave_type == ZEBRA_IF_SLAVE_VRF)
265
266 #define IS_ZEBRA_IF_BOND_SLAVE(ifp) \
267 (((struct zebra_if *)(ifp->info))->zif_slave_type \
268 == ZEBRA_IF_SLAVE_BOND)
269
270 extern void zebra_if_init(void);
271
272 extern struct interface *if_lookup_by_index_per_ns(struct zebra_ns *, uint32_t);
273 extern struct interface *if_lookup_by_name_per_ns(struct zebra_ns *,
274 const char *);
275 extern struct interface *if_link_per_ns(struct zebra_ns *, struct interface *);
276 extern const char *ifindex2ifname_per_ns(struct zebra_ns *, unsigned int);
277
278 extern void if_unlink_per_ns(struct interface *);
279 extern void if_nbr_mac_to_ipv4ll_neigh_update(struct interface *fip,
280 char mac[6],
281 struct in6_addr *address,
282 int add);
283 extern void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp,
284 struct in6_addr *address,
285 int add);
286 extern void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface *ifp);
287 extern void if_delete_update(struct interface **ifp);
288 extern void if_add_update(struct interface *ifp);
289 extern void if_up(struct interface *ifp, bool install_connected);
290 extern void if_down(struct interface *);
291 extern void if_refresh(struct interface *);
292 extern void if_flags_update(struct interface *, uint64_t);
293 extern int if_subnet_add(struct interface *, struct connected *);
294 extern int if_subnet_delete(struct interface *, struct connected *);
295 extern int ipv6_address_configured(struct interface *ifp);
296 extern void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id);
297 extern void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex,
298 ns_id_t ns_id);
299 extern void zebra_if_update_all_links(struct zebra_ns *zns);
300 /**
301 * Directly update entire protodown & reason code bitfield.
302 */
303 extern int zebra_if_update_protodown_rc(struct interface *ifp, bool new_down,
304 uint32_t new_protodown_rc);
305 /**
306 * Set protodown with single reason.
307 */
308 extern int zebra_if_set_protodown(struct interface *ifp, bool down,
309 enum protodown_reasons new_reason);
310 extern int if_ip_address_install(struct interface *ifp, struct prefix *prefix,
311 const char *label, struct prefix *pp);
312 extern int if_ipv6_address_install(struct interface *ifp, struct prefix *prefix,
313 const char *label);
314 extern int if_ip_address_uinstall(struct interface *ifp, struct prefix *prefix);
315 extern int if_shutdown(struct interface *ifp);
316 extern int if_no_shutdown(struct interface *ifp);
317 extern int if_multicast_set(struct interface *ifp);
318 extern int if_multicast_unset(struct interface *ifp);
319 extern int if_linkdetect(struct interface *ifp, bool detect);
320 extern void if_addr_wakeup(struct interface *ifp);
321
322 /* Nexthop group connected functions */
323 extern void if_nhg_dependents_add(struct interface *ifp,
324 struct nhg_hash_entry *nhe);
325 extern void if_nhg_dependents_del(struct interface *ifp,
326 struct nhg_hash_entry *nhe);
327 extern unsigned int if_nhg_dependents_count(const struct interface *ifp);
328 extern bool if_nhg_dependents_is_empty(const struct interface *ifp);
329
330 extern void vrf_add_update(struct vrf *vrfp);
331 extern void zebra_l2_map_slave_to_bond(struct zebra_if *zif, vrf_id_t vrf);
332 extern void zebra_l2_unmap_slave_from_bond(struct zebra_if *zif);
333 extern const char *zebra_protodown_rc_str(uint32_t protodown_rc, char *pd_buf,
334 uint32_t pd_buf_len);
335 void zebra_if_dplane_result(struct zebra_dplane_ctx *ctx);
336
337 #ifdef HAVE_PROC_NET_DEV
338 extern void ifstat_update_proc(void);
339 #endif /* HAVE_PROC_NET_DEV */
340 #ifdef HAVE_NET_RT_IFLIST
341 extern void ifstat_update_sysctl(void);
342
343 #endif /* HAVE_NET_RT_IFLIST */
344 #ifdef HAVE_PROC_NET_DEV
345 extern int interface_list_proc(void);
346 #endif /* HAVE_PROC_NET_DEV */
347 #ifdef HAVE_PROC_NET_IF_INET6
348 extern int ifaddr_proc_ipv6(void);
349 #endif /* HAVE_PROC_NET_IF_INET6 */
350
351 #ifdef __cplusplus
352 }
353 #endif
354
355 #endif /* _ZEBRA_INTERFACE_H */