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