| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *	BIRD -- Router Advertisement | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-08-12 00:41:36 +02:00
										 |  |  |  *	(c) 2011--2019 Ondrej Zajicek <santiago@crfreenet.org> | 
					
						
							|  |  |  |  *	(c) 2011--2019 CZ.NIC z.s.p.o. | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  *	Can be freely distributed and used under the terms of the GNU GPL. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _BIRD_RADV_H_
 | 
					
						
							|  |  |  | #define _BIRD_RADV_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "nest/bird.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "lib/ip.h"
 | 
					
						
							|  |  |  | #include "lib/lists.h"
 | 
					
						
							|  |  |  | #include "lib/socket.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-28 17:43:20 +01:00
										 |  |  | #include "lib/timer.h"
 | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | #include "lib/resource.h"
 | 
					
						
							|  |  |  | #include "nest/protocol.h"
 | 
					
						
							|  |  |  | #include "nest/iface.h"
 | 
					
						
							| 
									
										
										
										
											2022-03-31 19:09:38 +02:00
										 |  |  | #include "nest/rt.h"
 | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | #include "nest/cli.h"
 | 
					
						
							|  |  |  | #include "nest/locks.h"
 | 
					
						
							|  |  |  | #include "conf/conf.h"
 | 
					
						
							|  |  |  | #include "lib/string.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define ICMPV6_PROTO 58
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define ICMPV6_RS 133
 | 
					
						
							|  |  |  | #define ICMPV6_RA 134
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MAX_INITIAL_RTR_ADVERTISEMENTS 3
 | 
					
						
							| 
									
										
										
										
											2017-06-14 17:02:11 +02:00
										 |  |  | #define MAX_INITIAL_RTR_ADVERT_INTERVAL (16 S_)
 | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define DEFAULT_MAX_RA_INT 600
 | 
					
						
							|  |  |  | #define DEFAULT_MIN_DELAY 3
 | 
					
						
							|  |  |  | #define DEFAULT_CURRENT_HOP_LIMIT 64
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DEFAULT_VALID_LIFETIME 86400
 | 
					
						
							|  |  |  | #define DEFAULT_PREFERRED_LIFETIME 14400
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  | #define DEFAULT_DNS_LIFETIME_MULT 3
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct radv_config | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   struct proto_config c; | 
					
						
							| 
									
										
										
										
											2011-11-07 00:31:23 +01:00
										 |  |  |   list patt_list;		/* List of iface configs (struct radv_iface_config) */ | 
					
						
							|  |  |  |   list pref_list;		/* Global list of prefix configs (struct radv_prefix_config) */ | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  |   list rdnss_list;		/* Global list of RDNSS configs (struct radv_rdnss_config) */ | 
					
						
							|  |  |  |   list dnssl_list;		/* Global list of DNSSL configs (struct radv_dnssl_config) */ | 
					
						
							| 
									
										
										
										
											2013-02-08 23:58:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 11:48:58 +01:00
										 |  |  |   net_addr trigger;		/* Prefix of a trigger route, if defined */ | 
					
						
							| 
									
										
										
										
											2017-08-31 15:40:23 +02:00
										 |  |  |   u8 propagate_routes;		/* Do we propagate more specific routes (RFC 4191)? */ | 
					
						
							| 
									
										
										
										
											2017-10-06 12:22:18 +02:00
										 |  |  |   u32 max_linger_time;		/* Maximum of interface route_linger_time */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct radv_iface_config | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   struct iface_patt i; | 
					
						
							| 
									
										
										
										
											2011-11-07 00:31:23 +01:00
										 |  |  |   list pref_list;		/* Local list of prefix configs (struct radv_prefix_config) */ | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  |   list rdnss_list;		/* Local list of RDNSS configs (struct radv_rdnss_config) */ | 
					
						
							|  |  |  |   list dnssl_list;		/* Local list of DNSSL configs (struct radv_dnssl_config) */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 10:52:57 +02:00
										 |  |  |   u32 min_ra_int;		/* Standard options from RFC 4861 */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  |   u32 max_ra_int; | 
					
						
							|  |  |  |   u32 min_delay; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 00:41:36 +02:00
										 |  |  |   u8 solicited_ra_unicast;	/* Send solicited RAs as unicast */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-06 12:22:18 +02:00
										 |  |  |   u32 prefix_linger_time;	/* How long we advertise dead prefixes with lifetime 0 */ | 
					
						
							|  |  |  |   u32 route_linger_time;	/* How long we advertise dead routes with lifetime 0 */ | 
					
						
							| 
									
										
										
										
											2017-08-17 11:34:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  |   u8 rdnss_local;		/* Global list is not used for RDNSS */ | 
					
						
							|  |  |  |   u8 dnssl_local;		/* Global list is not used for DNSSL */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 10:52:57 +02:00
										 |  |  |   u8 managed;			/* Standard options from RFC 4861 */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  |   u8 other_config; | 
					
						
							|  |  |  |   u32 link_mtu; | 
					
						
							|  |  |  |   u32 reachable_time; | 
					
						
							|  |  |  |   u32 retrans_timer; | 
					
						
							| 
									
										
										
										
											2011-11-07 00:31:23 +01:00
										 |  |  |   u32 current_hop_limit; | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  |   u32 default_lifetime; | 
					
						
							| 
									
										
										
										
											2017-10-06 12:22:18 +02:00
										 |  |  |   u32 route_lifetime;		/* Lifetime for the RFC 4191 routes */ | 
					
						
							| 
									
										
										
										
											2013-02-08 23:58:27 +01:00
										 |  |  |   u8 default_lifetime_sensitive; /* Whether default_lifetime depends on trigger */ | 
					
						
							| 
									
										
										
										
											2017-10-06 12:22:18 +02:00
										 |  |  |   u8 route_lifetime_sensitive;	/* Whether route_lifetime depends on trigger */ | 
					
						
							|  |  |  |   u8 default_preference;	/* Default Router Preference (RFC 4191) */ | 
					
						
							|  |  |  |   u8 route_preference;		/* Specific Route Preference (RFC 4191) */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct radv_prefix_config | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   node n; | 
					
						
							| 
									
										
										
										
											2015-11-12 02:03:59 +01:00
										 |  |  |   net_addr_ip6 prefix; | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   u8 skip;			/* Do not include this prefix to RA */ | 
					
						
							| 
									
										
										
										
											2017-08-04 10:52:57 +02:00
										 |  |  |   u8 onlink;			/* Standard options from RFC 4861 */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  |   u8 autonomous; | 
					
						
							|  |  |  |   u32 valid_lifetime; | 
					
						
							|  |  |  |   u32 preferred_lifetime; | 
					
						
							| 
									
										
										
										
											2013-02-08 23:58:27 +01:00
										 |  |  |   u8 valid_lifetime_sensitive;	 /* Whether valid_lifetime depends on trigger */ | 
					
						
							|  |  |  |   u8 preferred_lifetime_sensitive; /* Whether preferred_lifetime depends on trigger */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  | struct radv_rdnss_config | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   node n; | 
					
						
							|  |  |  |   u32 lifetime;			/* Valid if lifetime_mult is 0 */ | 
					
						
							|  |  |  |   u16 lifetime_mult;		/* Lifetime specified as multiple of max_ra_int */ | 
					
						
							| 
									
										
										
										
											2015-11-12 02:03:59 +01:00
										 |  |  |   ip6_addr server;		/* IP address of recursive DNS server */ | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct radv_dnssl_config | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   node n; | 
					
						
							|  |  |  |   u32 lifetime;			/* Valid if lifetime_mult is 0 */ | 
					
						
							|  |  |  |   u16 lifetime_mult;		/* Lifetime specified as multiple of max_ra_int */ | 
					
						
							|  |  |  |   u8 dlen_first;		/* Length of first label in domain */ | 
					
						
							|  |  |  |   u8 dlen_all;			/* Both dlen_ filled in radv_process_domain() */ | 
					
						
							| 
									
										
										
										
											2020-04-08 22:25:15 +02:00
										 |  |  |   const char *domain;		/* Domain for DNS search list, in processed form */ | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-31 15:40:23 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * One more specific route as per RFC 4191. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note that it does *not* contain the next hop field. The next hop is always | 
					
						
							|  |  |  |  * the router sending the advertisment and the more specific route only allows | 
					
						
							|  |  |  |  * overriding the preference of the route. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct radv_route | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   u32 lifetime;			/* Lifetime from an attribute */ | 
					
						
							| 
									
										
										
										
											2017-10-06 12:22:18 +02:00
										 |  |  |   u8 lifetime_set;		/* Whether lifetime is defined */ | 
					
						
							| 
									
										
										
										
											2017-08-31 15:40:23 +02:00
										 |  |  |   u8 preference;		/* Preference of the route, RA_PREF_* */ | 
					
						
							| 
									
										
										
										
											2017-10-06 12:22:18 +02:00
										 |  |  |   u8 preference_set;		/* Whether preference is defined */ | 
					
						
							|  |  |  |   u8 valid;			/* Whethe route is valid or withdrawn */ | 
					
						
							| 
									
										
										
										
											2017-12-07 21:54:47 +01:00
										 |  |  |   btime changed;		/* Last time when the route changed */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   struct fib_node n; | 
					
						
							| 
									
										
										
										
											2017-08-31 15:40:23 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-08 14:40:51 +02:00
										 |  |  | struct radv_proto | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |   struct proto p; | 
					
						
							|  |  |  |   list iface_list;		/* List of active ifaces */ | 
					
						
							| 
									
										
										
										
											2017-08-31 15:40:23 +02:00
										 |  |  |   u8 valid;			/* Router is valid for forwarding, used for shutdown */ | 
					
						
							| 
									
										
										
										
											2013-02-08 23:58:27 +01:00
										 |  |  |   u8 active;			/* Whether radv is active w.r.t. triggers */ | 
					
						
							| 
									
										
										
										
											2017-08-31 15:40:23 +02:00
										 |  |  |   u8 fib_up;			/* FIB table (routes) is initialized */ | 
					
						
							|  |  |  |   struct fib routes;		/* FIB table of specific routes (struct radv_route) */ | 
					
						
							| 
									
										
										
										
											2017-12-07 21:54:47 +01:00
										 |  |  |   btime prune_time;		/* Next time of route table pruning */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 12:25:36 +02:00
										 |  |  | struct radv_prefix		/* One prefix we advertise */ | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   node n; | 
					
						
							| 
									
										
										
										
											2017-12-07 17:41:09 +01:00
										 |  |  |   net_addr_ip6 prefix; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-06 12:22:18 +02:00
										 |  |  |   u8 valid;			/* Is the prefix valid? If not, we advertise it
 | 
					
						
							| 
									
										
										
										
											2017-08-29 19:17:35 +02:00
										 |  |  | 				   with 0 lifetime, so clients stop using it */ | 
					
						
							| 
									
										
										
										
											2017-08-11 12:25:36 +02:00
										 |  |  |   u8 mark;			/* A temporary mark for processing */ | 
					
						
							| 
									
										
										
										
											2017-12-07 21:54:47 +01:00
										 |  |  |   btime changed;		/* Last time when the prefix changed */ | 
					
						
							| 
									
										
										
										
											2017-08-29 19:17:35 +02:00
										 |  |  |   struct radv_prefix_config *cf; /* The config tied to this prefix */ | 
					
						
							| 
									
										
										
										
											2017-08-11 12:25:36 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | struct radv_iface | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   node n; | 
					
						
							| 
									
										
										
										
											2017-08-08 14:40:51 +02:00
										 |  |  |   struct radv_proto *ra; | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  |   struct radv_iface_config *cf;	/* Related config, must be updated in reconfigure */ | 
					
						
							|  |  |  |   struct iface *iface; | 
					
						
							|  |  |  |   struct ifa *addr;		/* Link-local address of iface */ | 
					
						
							| 
									
										
										
										
											2017-08-11 12:25:36 +02:00
										 |  |  |   struct pool *pool;		/* A pool for interface-specific things */ | 
					
						
							| 
									
										
										
										
											2017-08-29 19:17:35 +02:00
										 |  |  |   list prefixes;		/* The prefixes we advertise (struct radv_prefix) */ | 
					
						
							| 
									
										
										
										
											2017-12-07 21:54:47 +01:00
										 |  |  |   btime prune_time;		/* Next time of prefix list pruning */ | 
					
						
							|  |  |  |   btime valid_time;		/* Cached packet is valid until first linger timeout */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   timer *timer; | 
					
						
							|  |  |  |   struct object_lock *lock; | 
					
						
							|  |  |  |   sock *sk; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-14 17:02:11 +02:00
										 |  |  |   btime last;			/* Time of last sending of RA */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  |   u16 plen;			/* Length of prepared RA in tbuf, or 0 if not valid */ | 
					
						
							| 
									
										
										
										
											2017-08-11 12:25:36 +02:00
										 |  |  |   byte initial;			/* How many RAs are still to be sent as initial */ | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define RA_EV_INIT 1		/* Switch to initial mode */
 | 
					
						
							|  |  |  | #define RA_EV_CHANGE 2		/* Change of options or prefixes */
 | 
					
						
							|  |  |  | #define RA_EV_RS 3		/* Received RS */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-07 22:56:21 +02:00
										 |  |  | /* Default Router Preferences (RFC 4191) */ | 
					
						
							|  |  |  | #define RA_PREF_LOW	0x18
 | 
					
						
							|  |  |  | #define RA_PREF_MEDIUM	0x00
 | 
					
						
							|  |  |  | #define RA_PREF_HIGH	0x08
 | 
					
						
							|  |  |  | #define RA_PREF_MASK	0x18
 | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-31 15:40:23 +02:00
										 |  |  | /* Attributes */ | 
					
						
							| 
									
										
										
										
											2018-05-07 14:47:00 +02:00
										 |  |  | #define EA_RA_PREFERENCE	EA_CODE(PROTOCOL_RADV, 0)
 | 
					
						
							|  |  |  | #define EA_RA_LIFETIME		EA_CODE(PROTOCOL_RADV, 1)
 | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef LOCAL_DEBUG
 | 
					
						
							|  |  |  | #define RADV_FORCE_DEBUG 1
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define RADV_FORCE_DEBUG 0
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-08-08 14:40:51 +02:00
										 |  |  | #define RADV_TRACE(flags, msg, args...) do { if ((p->p.debug & flags) || RADV_FORCE_DEBUG) \
 | 
					
						
							|  |  |  | 	log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0) | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 00:41:36 +02:00
										 |  |  | /* Invalidate cached RA packet */ | 
					
						
							|  |  |  | static inline void radv_invalidate(struct radv_iface *ifa) | 
					
						
							|  |  |  | { ifa->plen = 0; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | /* radv.c */ | 
					
						
							|  |  |  | void radv_iface_notify(struct radv_iface *ifa, int event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* packets.c */ | 
					
						
							| 
									
										
										
										
											2012-07-07 10:40:00 +02:00
										 |  |  | int radv_process_domain(struct radv_dnssl_config *cf); | 
					
						
							| 
									
										
										
										
											2019-08-12 00:41:36 +02:00
										 |  |  | void radv_send_ra(struct radv_iface *ifa, ip_addr to); | 
					
						
							| 
									
										
										
										
											2011-03-13 11:33:50 +01:00
										 |  |  | int radv_sk_open(struct radv_iface *ifa); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* _BIRD_RADV_H_ */
 |