2 * BIRD -- Router Advertisement
4 * (c) 2011--2019 Ondrej Zajicek <santiago@crfreenet.org>
5 * (c) 2011--2019 CZ.NIC z.s.p.o.
7 * Can be freely distributed and used under the terms of the GNU GPL.
13 #include "nest/bird.h"
16 #include "lib/lists.h"
17 #include "lib/socket.h"
18 #include "lib/timer.h"
19 #include "lib/resource.h"
20 #include "nest/protocol.h"
21 #include "nest/iface.h"
22 #include "nest/route.h"
24 #include "nest/locks.h"
25 #include "conf/conf.h"
26 #include "lib/string.h"
29 #define ICMPV6_PROTO 58
34 #define MAX_INITIAL_RTR_ADVERTISEMENTS 3
35 #define MAX_INITIAL_RTR_ADVERT_INTERVAL (16 S_)
37 #define DEFAULT_MAX_RA_INT 600
38 #define DEFAULT_MIN_DELAY 3
39 #define DEFAULT_CURRENT_HOP_LIMIT 64
41 #define DEFAULT_VALID_LIFETIME 86400
42 #define DEFAULT_PREFERRED_LIFETIME 14400
44 #define DEFAULT_DNS_LIFETIME_MULT 3
49 struct proto_config c
;
50 list patt_list
; /* List of iface configs (struct radv_iface_config) */
51 list pref_list
; /* Global list of prefix configs (struct radv_prefix_config) */
52 list rdnss_list
; /* Global list of RDNSS configs (struct radv_rdnss_config) */
53 list dnssl_list
; /* Global list of DNSSL configs (struct radv_dnssl_config) */
55 net_addr trigger
; /* Prefix of a trigger route, if defined */
56 u8 propagate_routes
; /* Do we propagate more specific routes (RFC 4191)? */
57 u32 max_linger_time
; /* Maximum of interface route_linger_time */
60 struct radv_iface_config
63 list pref_list
; /* Local list of prefix configs (struct radv_prefix_config) */
64 list rdnss_list
; /* Local list of RDNSS configs (struct radv_rdnss_config) */
65 list dnssl_list
; /* Local list of DNSSL configs (struct radv_dnssl_config) */
67 u32 min_ra_int
; /* Standard options from RFC 4861 */
71 u8 solicited_ra_unicast
; /* Send solicited RAs as unicast */
73 u32 prefix_linger_time
; /* How long we advertise dead prefixes with lifetime 0 */
74 u32 route_linger_time
; /* How long we advertise dead routes with lifetime 0 */
76 u8 rdnss_local
; /* Global list is not used for RDNSS */
77 u8 dnssl_local
; /* Global list is not used for DNSSL */
79 u8 managed
; /* Standard options from RFC 4861 */
84 u32 current_hop_limit
;
86 u32 route_lifetime
; /* Lifetime for the RFC 4191 routes */
87 u8 default_lifetime_sensitive
; /* Whether default_lifetime depends on trigger */
88 u8 route_lifetime_sensitive
; /* Whether route_lifetime depends on trigger */
89 u8 default_preference
; /* Default Router Preference (RFC 4191) */
90 u8 route_preference
; /* Specific Route Preference (RFC 4191) */
93 struct radv_prefix_config
98 u8 skip
; /* Do not include this prefix to RA */
99 u8 onlink
; /* Standard options from RFC 4861 */
102 u32 preferred_lifetime
;
103 u8 valid_lifetime_sensitive
; /* Whether valid_lifetime depends on trigger */
104 u8 preferred_lifetime_sensitive
; /* Whether preferred_lifetime depends on trigger */
107 struct radv_rdnss_config
110 u32 lifetime
; /* Valid if lifetime_mult is 0 */
111 u16 lifetime_mult
; /* Lifetime specified as multiple of max_ra_int */
112 ip6_addr server
; /* IP address of recursive DNS server */
115 struct radv_dnssl_config
118 u32 lifetime
; /* Valid if lifetime_mult is 0 */
119 u16 lifetime_mult
; /* Lifetime specified as multiple of max_ra_int */
120 u8 dlen_first
; /* Length of first label in domain */
121 u8 dlen_all
; /* Both dlen_ filled in radv_process_domain() */
122 char *domain
; /* Domain for DNS search list, in processed form */
126 * One more specific route as per RFC 4191.
128 * Note that it does *not* contain the next hop field. The next hop is always
129 * the router sending the advertisment and the more specific route only allows
130 * overriding the preference of the route.
134 u32 lifetime
; /* Lifetime from an attribute */
135 u8 lifetime_set
; /* Whether lifetime is defined */
136 u8 preference
; /* Preference of the route, RA_PREF_* */
137 u8 preference_set
; /* Whether preference is defined */
138 u8 valid
; /* Whethe route is valid or withdrawn */
139 btime changed
; /* Last time when the route changed */
147 list iface_list
; /* List of active ifaces */
148 u8 valid
; /* Router is valid for forwarding, used for shutdown */
149 u8 active
; /* Whether radv is active w.r.t. triggers */
150 u8 fib_up
; /* FIB table (routes) is initialized */
151 struct fib routes
; /* FIB table of specific routes (struct radv_route) */
152 btime prune_time
; /* Next time of route table pruning */
155 struct radv_prefix
/* One prefix we advertise */
160 u8 valid
; /* Is the prefix valid? If not, we advertise it
161 with 0 lifetime, so clients stop using it */
162 u8 mark
; /* A temporary mark for processing */
163 btime changed
; /* Last time when the prefix changed */
164 struct radv_prefix_config
*cf
; /* The config tied to this prefix */
170 struct radv_proto
*ra
;
171 struct radv_iface_config
*cf
; /* Related config, must be updated in reconfigure */
173 struct ifa
*addr
; /* Link-local address of iface */
174 struct pool
*pool
; /* A pool for interface-specific things */
175 list prefixes
; /* The prefixes we advertise (struct radv_prefix) */
176 btime prune_time
; /* Next time of prefix list pruning */
177 btime valid_time
; /* Cached packet is valid until first linger timeout */
180 struct object_lock
*lock
;
183 btime last
; /* Time of last sending of RA */
184 u16 plen
; /* Length of prepared RA in tbuf, or 0 if not valid */
185 byte initial
; /* How many RAs are still to be sent as initial */
188 #define RA_EV_INIT 1 /* Switch to initial mode */
189 #define RA_EV_CHANGE 2 /* Change of options or prefixes */
190 #define RA_EV_RS 3 /* Received RS */
192 /* Default Router Preferences (RFC 4191) */
193 #define RA_PREF_LOW 0x18
194 #define RA_PREF_MEDIUM 0x00
195 #define RA_PREF_HIGH 0x08
196 #define RA_PREF_MASK 0x18
199 #define EA_RA_PREFERENCE EA_CODE(PROTOCOL_RADV, 0)
200 #define EA_RA_LIFETIME EA_CODE(PROTOCOL_RADV, 1)
203 #define RADV_FORCE_DEBUG 1
205 #define RADV_FORCE_DEBUG 0
207 #define RADV_TRACE(flags, msg, args...) do { if ((p->p.debug & flags) || RADV_FORCE_DEBUG) \
208 log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
211 /* Invalidate cached RA packet */
212 static inline void radv_invalidate(struct radv_iface
*ifa
)
216 void radv_iface_notify(struct radv_iface
*ifa
, int event
);
219 int radv_process_domain(struct radv_dnssl_config
*cf
);
220 void radv_send_ra(struct radv_iface
*ifa
, ip_addr to
);
221 int radv_sk_open(struct radv_iface
*ifa
);
225 #endif /* _BIRD_RADV_H_ */