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