]> git.proxmox.com Git - mirror_frr.git/blob - zebra/interface.h
Merge pull request #10832 from patrasar/2520720
[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
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /* For interface multicast configuration. */
39 #define IF_ZEBRA_MULTICAST_UNSPEC 0
40 #define IF_ZEBRA_MULTICAST_ON 1
41 #define IF_ZEBRA_MULTICAST_OFF 2
42
43 /* For interface shutdown configuration. */
44 #define IF_ZEBRA_SHUTDOWN_OFF 0
45 #define IF_ZEBRA_SHUTDOWN_ON 1
46
47 #define IF_VLAN_BITMAP_MAX 4096
48
49 #if defined(HAVE_RTADV)
50 /* Router advertisement parameter. From RFC4861, RFC6275 and RFC4191. */
51 struct rtadvconf {
52 /* A flag indicating whether or not the router sends periodic Router
53 Advertisements and responds to Router Solicitations.
54 Default: false */
55 int AdvSendAdvertisements;
56
57 /* The maximum time allowed between sending unsolicited multicast
58 Router Advertisements from the interface, in milliseconds.
59 MUST be no less than 70 ms [RFC6275 7.5] and no greater
60 than 1800000 ms [RFC4861 6.2.1].
61
62 Default: 600000 milliseconds */
63 int MaxRtrAdvInterval;
64 #define RTADV_MAX_RTR_ADV_INTERVAL 600000
65
66 /* The minimum time allowed between sending unsolicited multicast
67 Router Advertisements from the interface, in milliseconds.
68 MUST be no less than 30 ms [RFC6275 7.5].
69 MUST be no greater than .75 * MaxRtrAdvInterval.
70
71 Default: 0.33 * MaxRtrAdvInterval */
72 int MinRtrAdvInterval; /* This field is currently unused. */
73 #define RTADV_MIN_RTR_ADV_INTERVAL (0.33 * RTADV_MAX_RTR_ADV_INTERVAL)
74
75 /* Unsolicited Router Advertisements' interval timer. */
76 int AdvIntervalTimer;
77
78 /* The true/false value to be placed in the "Managed address
79 configuration" flag field in the Router Advertisement. See
80 [ADDRCONF].
81
82 Default: false */
83 int AdvManagedFlag;
84 struct timeval lastadvmanagedflag;
85
86
87 /* The true/false value to be placed in the "Other stateful
88 configuration" flag field in the Router Advertisement. See
89 [ADDRCONF].
90
91 Default: false */
92 int AdvOtherConfigFlag;
93 struct timeval lastadvotherconfigflag;
94
95 /* The value to be placed in MTU options sent by the router. A
96 value of zero indicates that no MTU options are sent.
97
98 Default: 0 */
99 int AdvLinkMTU;
100
101
102 /* The value to be placed in the Reachable Time field in the Router
103 Advertisement messages sent by the router. The value zero means
104 unspecified (by this router). MUST be no greater than 3,600,000
105 milliseconds (1 hour).
106
107 Default: 0 */
108 uint32_t AdvReachableTime;
109 #define RTADV_MAX_REACHABLE_TIME 3600000
110 struct timeval lastadvreachabletime;
111
112 /* The value to be placed in the Retrans Timer field in the Router
113 Advertisement messages sent by the router. The value zero means
114 unspecified (by this router).
115
116 Default: 0 */
117 int AdvRetransTimer;
118 struct timeval lastadvretranstimer;
119
120 /* The default value to be placed in the Cur Hop Limit field in the
121 Router Advertisement messages sent by the router. The value
122 should be set to that current diameter of the Internet. The
123 value zero means unspecified (by this router).
124
125 Default: The value specified in the "Assigned Numbers" RFC
126 [ASSIGNED] that was in effect at the time of implementation. */
127 int AdvCurHopLimit;
128 struct timeval lastadvcurhoplimit;
129
130 #define RTADV_DEFAULT_HOPLIMIT 64 /* 64 hops */
131
132 /* The value to be placed in the Router Lifetime field of Router
133 Advertisements sent from the interface, in seconds. MUST be
134 either zero or between MaxRtrAdvInterval and 9000 seconds. A
135 value of zero indicates that the router is not to be used as a
136 default router.
137
138 Default: 3 * MaxRtrAdvInterval */
139 int AdvDefaultLifetime;
140 #define RTADV_MAX_RTRLIFETIME 9000 /* 2.5 hours */
141
142 /* A list of prefixes to be placed in Prefix Information options in
143 Router Advertisement messages sent from the interface.
144
145 Default: all prefixes that the router advertises via routing
146 protocols as being on-link for the interface from which the
147 advertisement is sent. The link-local prefix SHOULD NOT be
148 included in the list of advertised prefixes. */
149 struct list *AdvPrefixList;
150
151 /* The true/false value to be placed in the "Home agent"
152 flag field in the Router Advertisement. See [RFC6275 7.1].
153
154 Default: false */
155 int AdvHomeAgentFlag;
156 #ifndef ND_RA_FLAG_HOME_AGENT
157 #define ND_RA_FLAG_HOME_AGENT 0x20
158 #endif
159
160 /* The value to be placed in Home Agent Information option if Home
161 Flag is set.
162 Default: 0 */
163 int HomeAgentPreference;
164
165 /* The value to be placed in Home Agent Information option if Home
166 Flag is set. Lifetime (seconds) MUST not be greater than 18.2
167 hours.
168 The value 0 has special meaning: use of AdvDefaultLifetime value.
169
170 Default: 0 */
171 int HomeAgentLifetime;
172 #define RTADV_MAX_HALIFETIME 65520 /* 18.2 hours */
173
174 /* The true/false value to insert or not an Advertisement Interval
175 option. See [RFC 6275 7.3]
176
177 Default: false */
178 int AdvIntervalOption;
179
180 /* The value to be placed in the Default Router Preference field of
181 a router advertisement. See [RFC 4191 2.1 & 2.2]
182
183 Default: 0 (medium) */
184 int DefaultPreference;
185 #define RTADV_PREF_MEDIUM 0x0 /* Per RFC4191. */
186
187 /*
188 * List of recursive DNS servers to include in the RDNSS option.
189 * See [RFC8106 5.1]
190 *
191 * Default: empty list; do not emit RDNSS option
192 */
193 struct list *AdvRDNSSList;
194
195 /*
196 * List of DNS search domains to include in the DNSSL option.
197 * See [RFC8106 5.2]
198 *
199 * Default: empty list; do not emit DNSSL option
200 */
201 struct list *AdvDNSSLList;
202
203 /*
204 * rfc4861 states RAs must be sent at least 3 seconds apart.
205 * We allow faster retransmits to speed up convergence but can
206 * turn that capability off to meet the rfc if needed.
207 */
208 bool UseFastRexmit; /* True if fast rexmits are enabled */
209
210 uint8_t inFastRexmit; /* True if we're rexmits faster than usual */
211
212 /* Track if RA was configured by BGP or by the Operator or both */
213 uint8_t ra_configured; /* Was RA configured? */
214 #define BGP_RA_CONFIGURED (1<<0) /* BGP configured RA? */
215 #define VTY_RA_CONFIGURED (1<<1) /* Operator configured RA? */
216 #define VTY_RA_INTERVAL_CONFIGURED (1<<2) /* Operator configured RA interval */
217 int NumFastReXmitsRemain; /* Loaded first with number of fast
218 rexmits to do */
219
220 #define RTADV_FAST_REXMIT_PERIOD 1 /* 1 sec */
221 #define RTADV_NUM_FAST_REXMITS 4 /* Fast Rexmit RA 4 times on certain events */
222 };
223
224 struct rtadv_rdnss {
225 /* Address of recursive DNS server to advertise */
226 struct in6_addr addr;
227
228 /*
229 * Lifetime in seconds; all-ones means infinity, zero
230 * stop using it.
231 */
232 uint32_t lifetime;
233
234 /* If lifetime not set, use a default of 3*MaxRtrAdvInterval */
235 int lifetime_set;
236 };
237
238 /*
239 * [RFC1035 2.3.4] sets the maximum length of a domain name (a sequence of
240 * labels, each prefixed by a length octet) at 255 octets.
241 */
242 #define RTADV_MAX_ENCODED_DOMAIN_NAME 255
243
244 struct rtadv_dnssl {
245 /* Domain name without trailing root zone dot (NUL-terminated) */
246 char name[RTADV_MAX_ENCODED_DOMAIN_NAME - 1];
247
248 /* Name encoded as in [RFC1035 3.1] */
249 uint8_t encoded_name[RTADV_MAX_ENCODED_DOMAIN_NAME];
250
251 /* Actual length of encoded_name */
252 size_t encoded_len;
253
254 /* Lifetime as for RDNSS */
255 uint32_t lifetime;
256 int lifetime_set;
257 };
258
259 #endif /* HAVE_RTADV */
260
261 /* Zebra interface type - ones of interest. */
262 enum zebra_iftype {
263 ZEBRA_IF_OTHER = 0, /* Anything else */
264 ZEBRA_IF_VXLAN, /* VxLAN interface */
265 ZEBRA_IF_VRF, /* VRF device */
266 ZEBRA_IF_BRIDGE, /* bridge device */
267 ZEBRA_IF_VLAN, /* VLAN sub-interface */
268 ZEBRA_IF_MACVLAN, /* MAC VLAN interface*/
269 ZEBRA_IF_VETH, /* VETH interface*/
270 ZEBRA_IF_BOND, /* Bond */
271 ZEBRA_IF_BOND_SLAVE, /* Bond */
272 ZEBRA_IF_GRE, /* GRE interface */
273 };
274
275 /* Zebra "slave" interface type */
276 enum zebra_slave_iftype {
277 ZEBRA_IF_SLAVE_NONE, /* Not a slave */
278 ZEBRA_IF_SLAVE_VRF, /* Member of a VRF */
279 ZEBRA_IF_SLAVE_BRIDGE, /* Member of a bridge */
280 ZEBRA_IF_SLAVE_BOND, /* Bond member */
281 ZEBRA_IF_SLAVE_OTHER, /* Something else - e.g., bond slave */
282 };
283
284 struct irdp_interface;
285
286 /* Ethernet segment info used for setting up EVPN multihoming */
287 struct zebra_evpn_es;
288 struct zebra_es_if_info {
289 /* type-3 esi config */
290 struct ethaddr sysmac;
291 uint32_t lid; /* local-id; has to be unique per-ES-sysmac */
292
293 esi_t esi;
294
295 uint16_t df_pref;
296 uint8_t flags;
297 #define ZIF_CFG_ES_FLAG_BYPASS (1 << 0)
298
299 struct zebra_evpn_es *es; /* local ES */
300 };
301
302 enum zebra_if_flags {
303 /* device has been configured as an uplink for
304 * EVPN multihoming
305 */
306 ZIF_FLAG_EVPN_MH_UPLINK = (1 << 0),
307 ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP = (1 << 1),
308
309 /* Dataplane protodown-on */
310 ZIF_FLAG_PROTODOWN = (1 << 2),
311 /* Dataplane protodown-on Queued to the dplane */
312 ZIF_FLAG_SET_PROTODOWN = (1 << 3),
313 /* Dataplane protodown-off Queued to the dplane */
314 ZIF_FLAG_UNSET_PROTODOWN = (1 << 4),
315
316 /* LACP bypass state is set by the dataplane on a bond member
317 * and inherited by the bond (if one or more bond members are in
318 * a bypass state the bond is placed in a bypass state)
319 */
320 ZIF_FLAG_LACP_BYPASS = (1 << 5)
321 };
322
323 #define ZEBRA_IF_IS_PROTODOWN(zif) ((zif)->flags & ZIF_FLAG_PROTODOWN)
324 #define ZEBRA_IF_IS_PROTODOWN_ONLY_EXTERNAL(zif) \
325 ((zif)->protodown_rc == ZEBRA_PROTODOWN_EXTERNAL)
326
327 /* `zebra' daemon local interface structure. */
328 struct zebra_if {
329 /* back pointer to the interface */
330 struct interface *ifp;
331
332 enum zebra_if_flags flags;
333
334 /* Shutdown configuration. */
335 uint8_t shutdown;
336
337 /* Multicast configuration. */
338 uint8_t multicast;
339
340 /* MPLS status. */
341 bool mpls;
342
343 /* Router advertise configuration. */
344 uint8_t rtadv_enable;
345
346 /* Installed addresses chains tree. */
347 struct route_table *ipv4_subnets;
348
349 /* Nexthops pointing to this interface */
350 /**
351 * Any nexthop that we get should have an
352 * interface. When an interface goes down,
353 * we will use this list to update the nexthops
354 * pointing to it with that info.
355 */
356 struct nhg_connected_tree_head nhg_dependents;
357
358 /* Information about up/down changes */
359 unsigned int up_count;
360 char up_last[FRR_TIMESTAMP_LEN];
361 unsigned int down_count;
362 char down_last[FRR_TIMESTAMP_LEN];
363
364 #if defined(HAVE_RTADV)
365 struct rtadvconf rtadv;
366 unsigned int ra_sent, ra_rcvd;
367 #endif /* HAVE_RTADV */
368
369 struct irdp_interface *irdp;
370
371 #ifdef HAVE_STRUCT_SOCKADDR_DL
372 union {
373 /* note that sdl_storage is never accessed, it only exists to
374 * make space.
375 * all actual uses refer to sdl - but use sizeof(sdl_storage)!
376 * this fits
377 * best with C aliasing rules. */
378 struct sockaddr_dl sdl;
379 struct sockaddr_storage sdl_storage;
380 };
381 #endif
382
383 /* ptm enable configuration */
384 uint8_t ptm_enable;
385
386 /* Zebra interface and "slave" interface type */
387 enum zebra_iftype zif_type;
388 enum zebra_slave_iftype zif_slave_type;
389
390 /* Additional L2 info, depends on zif_type */
391 union zebra_l2if_info l2info;
392
393 /* For members of a bridge, link to bridge. */
394 /* Note: If additional fields become necessary, this can be modified to
395 * be a pointer to a dynamically allocd struct.
396 */
397 struct zebra_l2info_brslave brslave_info;
398
399 struct zebra_l2info_bondslave bondslave_info;
400 struct zebra_l2info_bond bond_info;
401
402 /* ethernet segment */
403 struct zebra_es_if_info es_info;
404
405 /* bitmap of vlans associated with this interface */
406 bitfield_t vlan_bitmap;
407
408 /* An interface can be error-disabled if a protocol (such as EVPN or
409 * VRRP) detects a problem with keeping it operationally-up.
410 * If any of the protodown bits are set protodown-on is programmed
411 * in the dataplane. This results in a carrier/L1 down on the
412 * physical device.
413 */
414 uint32_t protodown_rc;
415
416 /* list of zebra_mac entries using this interface as destination */
417 struct list *mac_list;
418
419 /* Link fields - for sub-interfaces. */
420 ifindex_t link_ifindex;
421 struct interface *link;
422
423 uint8_t speed_update_count;
424 struct thread *speed_update;
425
426 /*
427 * Does this interface have a v6 to v4 ll neighbor entry
428 * for bgp unnumbered?
429 */
430 bool v6_2_v4_ll_neigh_entry;
431 char neigh_mac[6];
432 struct in6_addr v6_2_v4_ll_addr6;
433
434 /* The description of the interface */
435 char *desc;
436 };
437
438 DECLARE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
439 (vty, ifp));
440 DECLARE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp),
441 (vty, ifp));
442
443 #define IS_ZEBRA_IF_VRF(ifp) \
444 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VRF)
445
446 #define IS_ZEBRA_IF_BRIDGE(ifp) \
447 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BRIDGE)
448
449 #define IS_ZEBRA_IF_VLAN(ifp) \
450 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VLAN)
451
452 #define IS_ZEBRA_IF_VXLAN(ifp) \
453 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VXLAN)
454
455 #define IS_ZEBRA_IF_MACVLAN(ifp) \
456 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_MACVLAN)
457
458 #define IS_ZEBRA_IF_VETH(ifp) \
459 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VETH)
460
461 #define IS_ZEBRA_IF_BOND(ifp) \
462 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BOND)
463
464 #define IS_ZEBRA_IF_GRE(ifp) \
465 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_GRE)
466
467 #define IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) \
468 (((struct zebra_if *)(ifp->info))->zif_slave_type \
469 == ZEBRA_IF_SLAVE_BRIDGE)
470
471 #define IS_ZEBRA_IF_VRF_SLAVE(ifp) \
472 (((struct zebra_if *)(ifp->info))->zif_slave_type == ZEBRA_IF_SLAVE_VRF)
473
474 #define IS_ZEBRA_IF_BOND_SLAVE(ifp) \
475 (((struct zebra_if *)(ifp->info))->zif_slave_type \
476 == ZEBRA_IF_SLAVE_BOND)
477
478 extern void zebra_if_init(void);
479
480 extern struct interface *if_lookup_by_index_per_ns(struct zebra_ns *, uint32_t);
481 extern struct interface *if_lookup_by_name_per_ns(struct zebra_ns *,
482 const char *);
483 extern struct interface *if_link_per_ns(struct zebra_ns *, struct interface *);
484 extern const char *ifindex2ifname_per_ns(struct zebra_ns *, unsigned int);
485
486 extern void if_unlink_per_ns(struct interface *);
487 extern void if_nbr_mac_to_ipv4ll_neigh_update(struct interface *fip,
488 char mac[6],
489 struct in6_addr *address,
490 int add);
491 extern void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp,
492 struct in6_addr *address,
493 int add);
494 extern void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface *ifp);
495 extern void if_delete_update(struct interface *ifp);
496 extern void if_add_update(struct interface *ifp);
497 extern void if_up(struct interface *ifp, bool install_connected);
498 extern void if_down(struct interface *);
499 extern void if_refresh(struct interface *);
500 extern void if_flags_update(struct interface *, uint64_t);
501 extern int if_subnet_add(struct interface *, struct connected *);
502 extern int if_subnet_delete(struct interface *, struct connected *);
503 extern int ipv6_address_configured(struct interface *ifp);
504 extern void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id);
505 extern void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex,
506 ns_id_t ns_id);
507 extern void zebra_if_update_all_links(struct zebra_ns *zns);
508 /**
509 * Directly update entire protodown & reason code bitfield.
510 */
511 extern int zebra_if_update_protodown_rc(struct interface *ifp, bool new_down,
512 uint32_t new_protodown_rc);
513 /**
514 * Set protodown with single reason.
515 */
516 extern int zebra_if_set_protodown(struct interface *ifp, bool down,
517 enum protodown_reasons new_reason);
518 extern int if_ip_address_install(struct interface *ifp, struct prefix *prefix,
519 const char *label, struct prefix *pp);
520 extern int if_ipv6_address_install(struct interface *ifp, struct prefix *prefix,
521 const char *label);
522 extern int if_ip_address_uinstall(struct interface *ifp, struct prefix *prefix);
523 extern int if_shutdown(struct interface *ifp);
524 extern int if_no_shutdown(struct interface *ifp);
525 extern int if_multicast_set(struct interface *ifp);
526 extern int if_multicast_unset(struct interface *ifp);
527 extern int if_linkdetect(struct interface *ifp, bool detect);
528 extern void if_addr_wakeup(struct interface *ifp);
529
530 /* Nexthop group connected functions */
531 extern void if_nhg_dependents_add(struct interface *ifp,
532 struct nhg_hash_entry *nhe);
533 extern void if_nhg_dependents_del(struct interface *ifp,
534 struct nhg_hash_entry *nhe);
535 extern unsigned int if_nhg_dependents_count(const struct interface *ifp);
536 extern bool if_nhg_dependents_is_empty(const struct interface *ifp);
537
538 extern void vrf_add_update(struct vrf *vrfp);
539 extern void zebra_l2_map_slave_to_bond(struct zebra_if *zif, vrf_id_t vrf);
540 extern void zebra_l2_unmap_slave_from_bond(struct zebra_if *zif);
541 extern const char *zebra_protodown_rc_str(uint32_t protodown_rc, char *pd_buf,
542 uint32_t pd_buf_len);
543 void zebra_if_dplane_result(struct zebra_dplane_ctx *ctx);
544
545 #ifdef HAVE_PROC_NET_DEV
546 extern void ifstat_update_proc(void);
547 #endif /* HAVE_PROC_NET_DEV */
548 #ifdef HAVE_NET_RT_IFLIST
549 extern void ifstat_update_sysctl(void);
550
551 #endif /* HAVE_NET_RT_IFLIST */
552 #ifdef HAVE_PROC_NET_DEV
553 extern int interface_list_proc(void);
554 #endif /* HAVE_PROC_NET_DEV */
555 #ifdef HAVE_PROC_NET_IF_INET6
556 extern int ifaddr_proc_ipv6(void);
557 #endif /* HAVE_PROC_NET_IF_INET6 */
558
559 #ifdef __cplusplus
560 }
561 #endif
562
563 #endif /* _ZEBRA_INTERFACE_H */