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