]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/radv/radv.h
RAdv: Allow solicited RAs to be sent as unicast
[thirdparty/bird.git] / proto / radv / radv.h
1 /*
2 * BIRD -- Router Advertisement
3 *
4 * (c) 2011--2019 Ondrej Zajicek <santiago@crfreenet.org>
5 * (c) 2011--2019 CZ.NIC z.s.p.o.
6 *
7 * Can be freely distributed and used under the terms of the GNU GPL.
8 */
9
10 #ifndef _BIRD_RADV_H_
11 #define _BIRD_RADV_H_
12
13 #include "nest/bird.h"
14
15 #include "lib/ip.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"
23 #include "nest/cli.h"
24 #include "nest/locks.h"
25 #include "conf/conf.h"
26 #include "lib/string.h"
27
28
29 #define ICMPV6_PROTO 58
30
31 #define ICMPV6_RS 133
32 #define ICMPV6_RA 134
33
34 #define MAX_INITIAL_RTR_ADVERTISEMENTS 3
35 #define MAX_INITIAL_RTR_ADVERT_INTERVAL (16 S_)
36
37 #define DEFAULT_MAX_RA_INT 600
38 #define DEFAULT_MIN_DELAY 3
39 #define DEFAULT_CURRENT_HOP_LIMIT 64
40
41 #define DEFAULT_VALID_LIFETIME 86400
42 #define DEFAULT_PREFERRED_LIFETIME 14400
43
44 #define DEFAULT_DNS_LIFETIME_MULT 3
45
46
47 struct radv_config
48 {
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) */
54
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 */
58 };
59
60 struct radv_iface_config
61 {
62 struct iface_patt i;
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) */
66
67 u32 min_ra_int; /* Standard options from RFC 4861 */
68 u32 max_ra_int;
69 u32 min_delay;
70
71 u8 solicited_ra_unicast; /* Send solicited RAs as unicast */
72
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 */
75
76 u8 rdnss_local; /* Global list is not used for RDNSS */
77 u8 dnssl_local; /* Global list is not used for DNSSL */
78
79 u8 managed; /* Standard options from RFC 4861 */
80 u8 other_config;
81 u32 link_mtu;
82 u32 reachable_time;
83 u32 retrans_timer;
84 u32 current_hop_limit;
85 u32 default_lifetime;
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) */
91 };
92
93 struct radv_prefix_config
94 {
95 node n;
96 net_addr_ip6 prefix;
97
98 u8 skip; /* Do not include this prefix to RA */
99 u8 onlink; /* Standard options from RFC 4861 */
100 u8 autonomous;
101 u32 valid_lifetime;
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 */
105 };
106
107 struct radv_rdnss_config
108 {
109 node n;
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 */
113 };
114
115 struct radv_dnssl_config
116 {
117 node n;
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 */
123 };
124
125 /*
126 * One more specific route as per RFC 4191.
127 *
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.
131 */
132 struct radv_route
133 {
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 */
140
141 struct fib_node n;
142 };
143
144 struct radv_proto
145 {
146 struct proto p;
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 */
153 };
154
155 struct radv_prefix /* One prefix we advertise */
156 {
157 node n;
158 net_addr_ip6 prefix;
159
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 */
165 };
166
167 struct radv_iface
168 {
169 node n;
170 struct radv_proto *ra;
171 struct radv_iface_config *cf; /* Related config, must be updated in reconfigure */
172 struct iface *iface;
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 */
178
179 timer *timer;
180 struct object_lock *lock;
181 sock *sk;
182
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 */
186 };
187
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 */
191
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
197
198 /* Attributes */
199 #define EA_RA_PREFERENCE EA_CODE(PROTOCOL_RADV, 0)
200 #define EA_RA_LIFETIME EA_CODE(PROTOCOL_RADV, 1)
201
202 #ifdef LOCAL_DEBUG
203 #define RADV_FORCE_DEBUG 1
204 #else
205 #define RADV_FORCE_DEBUG 0
206 #endif
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)
209
210
211 /* Invalidate cached RA packet */
212 static inline void radv_invalidate(struct radv_iface *ifa)
213 { ifa->plen = 0; }
214
215 /* radv.c */
216 void radv_iface_notify(struct radv_iface *ifa, int event);
217
218 /* packets.c */
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);
222
223
224
225 #endif /* _BIRD_RADV_H_ */