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