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