2 /* Interface function header.
3 * Copyright (C) 1999 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
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
22 #ifndef _ZEBRA_INTERFACE_H
23 #define _ZEBRA_INTERFACE_H
25 #include "redistribute.h"
30 #include "zebra/zebra_l2.h"
31 #include "zebra/zebra_nhg_private.h"
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
42 /* For interface shutdown configuration. */
43 #define IF_ZEBRA_SHUTDOWN_OFF 0
44 #define IF_ZEBRA_SHUTDOWN_ON 1
46 #define IF_VLAN_BITMAP_MAX 4096
48 #if defined(HAVE_RTADV)
49 /* Router advertisement parameter. From RFC4861, RFC6275 and RFC4191. */
51 /* A flag indicating whether or not the router sends periodic Router
52 Advertisements and responds to Router Solicitations.
54 int AdvSendAdvertisements
;
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].
61 Default: 600000 milliseconds */
62 int MaxRtrAdvInterval
;
63 #define RTADV_MAX_RTR_ADV_INTERVAL 600000
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.
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)
74 /* Unsolicited Router Advertisements' interval timer. */
77 /* The true/false value to be placed in the "Managed address
78 configuration" flag field in the Router Advertisement. See
85 /* The true/false value to be placed in the "Other stateful
86 configuration" flag field in the Router Advertisement. See
90 int AdvOtherConfigFlag
;
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.
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).
105 uint32_t AdvReachableTime
;
106 #define RTADV_MAX_REACHABLE_TIME 3600000
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).
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).
120 Default: The value specified in the "Assigned Numbers" RFC
121 [ASSIGNED] that was in effect at the time of implementation. */
123 #define RTADV_DEFAULT_HOPLIMIT 64 /* 64 hops */
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
131 Default: 3 * MaxRtrAdvInterval */
132 int AdvDefaultLifetime
;
133 #define RTADV_MAX_RTRLIFETIME 9000 /* 2.5 hours */
135 /* A list of prefixes to be placed in Prefix Information options in
136 Router Advertisement messages sent from the interface.
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
;
144 /* The true/false value to be placed in the "Home agent"
145 flag field in the Router Advertisement. See [RFC6275 7.1].
148 int AdvHomeAgentFlag
;
149 #ifndef ND_RA_FLAG_HOME_AGENT
150 #define ND_RA_FLAG_HOME_AGENT 0x20
153 /* The value to be placed in Home Agent Information option if Home
156 int HomeAgentPreference
;
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
161 The value 0 has special meaning: use of AdvDefaultLifetime value.
164 int HomeAgentLifetime
;
165 #define RTADV_MAX_HALIFETIME 65520 /* 18.2 hours */
167 /* The true/false value to insert or not an Advertisement Interval
168 option. See [RFC 6275 7.3]
171 int AdvIntervalOption
;
173 /* The value to be placed in the Default Router Preference field of
174 a router advertisement. See [RFC 4191 2.1 & 2.2]
176 Default: 0 (medium) */
177 int DefaultPreference
;
178 #define RTADV_PREF_MEDIUM 0x0 /* Per RFC4191. */
181 * List of recursive DNS servers to include in the RDNSS option.
184 * Default: empty list; do not emit RDNSS option
186 struct list
*AdvRDNSSList
;
189 * List of DNS search domains to include in the DNSSL option.
192 * Default: empty list; do not emit DNSSL option
194 struct list
*AdvDNSSLList
;
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.
201 bool UseFastRexmit
; /* True if fast rexmits are enabled */
203 uint8_t inFastRexmit
; /* True if we're rexmits faster than usual */
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
213 #define RTADV_FAST_REXMIT_PERIOD 1 /* 1 sec */
214 #define RTADV_NUM_FAST_REXMITS 4 /* Fast Rexmit RA 4 times on certain events */
218 /* Address of recursive DNS server to advertise */
219 struct in6_addr addr
;
222 * Lifetime in seconds; all-ones means infinity, zero
227 /* If lifetime not set, use a default of 3*MaxRtrAdvInterval */
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.
235 #define RTADV_MAX_ENCODED_DOMAIN_NAME 255
238 /* Domain name without trailing root zone dot (NUL-terminated) */
239 char name
[RTADV_MAX_ENCODED_DOMAIN_NAME
- 1];
241 /* Name encoded as in [RFC1035 3.1] */
242 uint8_t encoded_name
[RTADV_MAX_ENCODED_DOMAIN_NAME
];
244 /* Actual length of encoded_name */
247 /* Lifetime as for RDNSS */
252 #endif /* HAVE_RTADV */
254 /* Zebra interface type - ones of interest. */
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 */
267 /* Zebra "slave" interface type */
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
;
276 struct irdp_interface
;
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 */
286 /* `zebra' daemon local interface structure. */
288 /* back pointer to the interface */
289 struct interface
*ifp
;
291 /* Shutdown configuration. */
294 /* Multicast configuration. */
297 /* Router advertise configuration. */
298 uint8_t rtadv_enable
;
300 /* Installed addresses chains tree. */
301 struct route_table
*ipv4_subnets
;
303 /* Nexthops pointing to this interface */
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.
310 struct nhg_connected_tree_head nhg_dependents
;
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
];
318 #if defined(HAVE_RTADV)
319 struct rtadvconf rtadv
;
320 unsigned int ra_sent
, ra_rcvd
;
321 #endif /* HAVE_RTADV */
323 struct irdp_interface
*irdp
;
325 #ifdef HAVE_STRUCT_SOCKADDR_DL
327 /* note that sdl_storage is never accessed, it only exists to
329 * all actual uses refer to sdl - but use sizeof(sdl_storage)!
331 * best with C aliasing rules. */
332 struct sockaddr_dl sdl
;
333 struct sockaddr_storage sdl_storage
;
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.
343 uint8_t primary_state
;
346 /* ptm enable configuration */
349 /* Zebra interface and "slave" interface type */
350 zebra_iftype_t zif_type
;
351 zebra_slave_iftype_t zif_slave_type
;
353 /* Additional L2 info, depends on zif_type */
354 union zebra_l2if_info l2info
;
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.
360 struct zebra_l2info_brslave brslave_info
;
362 struct zebra_l2info_bondslave bondslave_info
;
364 /* ethernet segment */
365 struct zebra_es_if_info es_info
;
367 /* bitmap of vlans associated with this interface */
368 bitfield_t vlan_bitmap
;
370 /* Link fields - for sub-interfaces. */
371 ifindex_t link_ifindex
;
372 struct interface
*link
;
374 struct thread
*speed_update
;
377 * Does this interface have a v6 to v4 ll neighbor entry
378 * for bgp unnumbered?
380 bool v6_2_v4_ll_neigh_entry
;
382 struct in6_addr v6_2_v4_ll_addr6
;
384 /* The description of the interface */
388 DECLARE_HOOK(zebra_if_extra_info
, (struct vty
* vty
, struct interface
*ifp
),
390 DECLARE_HOOK(zebra_if_config_wr
, (struct vty
* vty
, struct interface
*ifp
),
393 #define IS_ZEBRA_IF_VRF(ifp) \
394 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VRF)
396 #define IS_ZEBRA_IF_BRIDGE(ifp) \
397 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BRIDGE)
399 #define IS_ZEBRA_IF_VLAN(ifp) \
400 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VLAN)
402 #define IS_ZEBRA_IF_VXLAN(ifp) \
403 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VXLAN)
405 #define IS_ZEBRA_IF_MACVLAN(ifp) \
406 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_MACVLAN)
408 #define IS_ZEBRA_IF_VETH(ifp) \
409 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VETH)
411 #define IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) \
412 (((struct zebra_if *)(ifp->info))->zif_slave_type \
413 == ZEBRA_IF_SLAVE_BRIDGE)
415 #define IS_ZEBRA_IF_VRF_SLAVE(ifp) \
416 (((struct zebra_if *)(ifp->info))->zif_slave_type == ZEBRA_IF_SLAVE_VRF)
418 #define IS_ZEBRA_IF_BOND_SLAVE(ifp) \
419 (((struct zebra_if *)(ifp->info))->zif_slave_type \
420 == ZEBRA_IF_SLAVE_BOND)
422 extern void zebra_if_init(void);
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
*,
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);
430 extern void if_unlink_per_ns(struct interface
*);
431 extern void if_nbr_mac_to_ipv4ll_neigh_update(struct interface
*fip
,
433 struct in6_addr
*address
,
435 extern void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface
*ifp
,
436 struct in6_addr
*address
,
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
,
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
,
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
);
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
);
473 extern void vrf_add_update(struct vrf
*vrfp
);
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);
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 */
493 #endif /* _ZEBRA_INTERFACE_H */