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