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