xref: /freebsd/usr.sbin/rtadvd/rtadvd.h (revision 6f9c8e5b074419423648ffb89b83fd2f257e90b7)
1 /*	$FreeBSD$	*/
2 /*	$KAME: rtadvd.h,v 1.26 2003/08/05 12:34:23 itojun Exp $	*/
3 
4 /*
5  * Copyright (C) 1998 WIDE Project.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the project nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 #define IN6ADDR_LINKLOCAL_ALLNODES_INIT				\
34 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	\
35 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
36 
37 #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT			\
38 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	\
39 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
40 
41 #define IN6ADDR_SITELOCAL_ALLROUTERS_INIT			\
42 	{{{ 0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	\
43 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
44 
45 extern struct sockaddr_in6 sin6_linklocal_allnodes;
46 extern struct sockaddr_in6 sin6_linklocal_allrouters;
47 extern struct sockaddr_in6 sin6_sitelocal_allrouters;
48 
49 /*
50  * RFC 3542 API deprecates IPV6_PKTINFO in favor of
51  * IPV6_RECVPKTINFO
52  */
53 #ifndef IPV6_RECVPKTINFO
54 #ifdef IPV6_PKTINFO
55 #define IPV6_RECVPKTINFO	IPV6_PKTINFO
56 #endif
57 #endif
58 
59 /*
60  * RFC 3542 API deprecates IPV6_HOPLIMIT in favor of
61  * IPV6_RECVHOPLIMIT
62  */
63 #ifndef IPV6_RECVHOPLIMIT
64 #ifdef IPV6_HOPLIMIT
65 #define IPV6_RECVHOPLIMIT	IPV6_HOPLIMIT
66 #endif
67 #endif
68 
69 /* protocol constants and default values */
70 #define DEF_MAXRTRADVINTERVAL 600
71 #define DEF_ADVLINKMTU 0
72 #define DEF_ADVREACHABLETIME 0
73 #define DEF_ADVRETRANSTIMER 0
74 #define DEF_ADVCURHOPLIMIT 64
75 #define DEF_ADVVALIDLIFETIME 2592000
76 #define DEF_ADVPREFERREDLIFETIME 604800
77 
78 #define MAXROUTERLIFETIME 9000
79 #define MIN_MAXINTERVAL 4
80 #define MAX_MAXINTERVAL 1800
81 #define MIN_MININTERVAL 3
82 #define MAXREACHABLETIME 3600000
83 
84 #define MAX_INITIAL_RTR_ADVERT_INTERVAL  16
85 #define MAX_INITIAL_RTR_ADVERTISEMENTS    3
86 #define MAX_FINAL_RTR_ADVERTISEMENTS      3
87 #define MIN_DELAY_BETWEEN_RAS             3
88 #define MAX_RA_DELAY_TIME                 500000 /* usec */
89 
90 #define PREFIX_FROM_KERNEL 1
91 #define PREFIX_FROM_CONFIG 2
92 #define PREFIX_FROM_DYNAMIC 3
93 
94 struct prefix {
95 	TAILQ_ENTRY(prefix)	pfx_next;
96 
97 	struct rainfo *pfx_rainfo;	/* back pointer to the interface */
98 	/*
99 	 * Expiration timer.  This is used when a prefix derived from
100 	 * the kernel is deleted.
101 	 */
102 	struct rtadvd_timer *pfx_timer;
103 
104 	u_int32_t	pfx_validlifetime;	/* AdvValidLifetime */
105 	long		pfx_vltimeexpire;	/* Expiration of vltime */
106 	u_int32_t	pfx_preflifetime;	/* AdvPreferredLifetime */
107 	long		pfx_pltimeexpire;	/* Expiration of pltime */
108 	u_int		pfx_onlinkflg;		/* bool: AdvOnLinkFlag */
109 	u_int		pfx_autoconfflg;	/* bool: AdvAutonomousFlag */
110 	int		pfx_prefixlen;
111 	int		pfx_origin;		/* From kernel or config */
112 
113 	struct in6_addr	pfx_prefix;
114 };
115 
116 #ifdef ROUTEINFO
117 struct rtinfo {
118 	TAILQ_ENTRY(rtinfo)	rti_next;
119 
120 	u_int32_t	rti_ltime;	/* route lifetime */
121 	u_int		rti_rtpref;	/* route preference */
122 	int		rti_prefixlen;
123 	struct in6_addr	rti_prefix;
124 };
125 #endif
126 
127 struct rdnss_addr {
128 	TAILQ_ENTRY(rdnss_addr)	ra_next;
129 
130 	struct in6_addr ra_dns;	/* DNS server entry */
131 };
132 
133 struct rdnss {
134 	TAILQ_ENTRY(rdnss) rd_next;
135 
136 	TAILQ_HEAD(, rdnss_addr) rd_list;	/* list of DNS servers */
137 	int rd_cnt;		/* number of DNS servers */
138 	u_int32_t rd_ltime;	/* number of seconds valid */
139 };
140 
141 /*
142  * The maximum length of a domain name in a DNS search list is calculated
143  * by a domain name + length fields per 63 octets + a zero octet at
144  * the tail and adding 8 octet boundary padding.
145  */
146 #define _DNAME_LABELENC_MAXLEN \
147 	(NI_MAXHOST + (NI_MAXHOST / 64 + 1) + 1)
148 
149 #define DNAME_LABELENC_MAXLEN \
150 	(_DNAME_LABELENC_MAXLEN + 8 - _DNAME_LABELENC_MAXLEN % 8)
151 
152 struct dnssl_addr {
153 	TAILQ_ENTRY(dnssl_addr)	da_next;
154 
155 	int da_len;				/* length of entry */
156 	char da_dom[DNAME_LABELENC_MAXLEN];	/* search domain name entry */
157 };
158 
159 struct dnssl {
160 	TAILQ_ENTRY(dnssl)	dn_next;
161 
162 	TAILQ_HEAD(, dnssl_addr) dn_list;	/* list of search domains */
163 	u_int32_t dn_ltime;			/* number of seconds valid */
164 };
165 
166 struct soliciter {
167 	TAILQ_ENTRY(soliciter)	sol_next;
168 
169 	struct sockaddr_in6	sol_addr;
170 };
171 
172 struct	rainfo {
173 	/* pointer for list */
174 	TAILQ_ENTRY(rainfo)	rai_next;
175 
176 	/* timer related parameters */
177 	struct rtadvd_timer	*rai_timer;
178 	/* counter for the first few advertisements */
179 	int			rai_initcounter;
180 	/* timestamp when the latest RA was sent */
181 	struct timeval		rai_lastsent;
182 	/* number of RS waiting for RA */
183 	int			rai_waiting;
184 
185 	/* interface information */
186 	int	rai_ifindex;
187 	int	rai_advlinkopt;	/* bool: whether include link-layer addr opt */
188 	int	rai_advifprefix;	/* bool: gather IF prefixes? */
189 	struct sockaddr_dl *rai_sdl;
190 	char	rai_ifname[IFNAMSIZ];
191 	u_int32_t	rai_phymtu;	/* mtu of the physical interface */
192 
193 	/* Router configuration variables */
194 	u_short	rai_lifetime;		/* AdvDefaultLifetime */
195 	u_int	rai_maxinterval;	/* MaxRtrAdvInterval */
196 	u_int	rai_mininterval;	/* MinRtrAdvInterval */
197 	int 	rai_managedflg;		/* AdvManagedFlag */
198 	int	rai_otherflg;		/* AdvOtherConfigFlag */
199 
200 	int	rai_rtpref;		/* router preference */
201 	u_int32_t rai_linkmtu;		/* AdvLinkMTU */
202 	u_int32_t rai_reachabletime;	/* AdvReachableTime */
203 	u_int32_t rai_retranstimer;	/* AdvRetransTimer */
204 	u_int	rai_hoplimit;		/* AdvCurHopLimit */
205 
206 	TAILQ_HEAD(, prefix) rai_prefix;/* AdvPrefixList(link head) */
207 	int	rai_pfxs;		/* number of prefixes */
208 
209 	long	rai_clockskew;	/* used for consisitency check of lifetimes */
210 
211 	TAILQ_HEAD(, rdnss) rai_rdnss;	/* DNS server list */
212 	TAILQ_HEAD(, dnssl) rai_dnssl;	/* search domain list */
213 #ifdef ROUTEINFO
214 	TAILQ_HEAD(, rtinfo) rai_route;	/* route information option (link head) */
215 	int	rai_routes;		/* number of route information options */
216 #endif
217 	/* actual RA packet data and its length */
218 	size_t	rai_ra_datalen;
219 	u_char	*rai_ra_data;
220 
221 	/* statistics */
222 	u_quad_t rai_raoutput;		/* # of RAs sent */
223 	u_quad_t rai_rainput;		/* # of RAs received */
224 	u_quad_t rai_rainconsistent;	/* # of RAs inconsistent with ours */
225 	u_quad_t rai_rsinput;		/* # of RSs received */
226 
227 	/* info about soliciter */
228 	TAILQ_HEAD(, soliciter) rai_soliciter;	/* recent solication source */
229 };
230 
231 /* Interface list including RA information */
232 extern TAILQ_HEAD(railist_head_t, rainfo) railist;
233 
234 struct rtadvd_timer	*ra_timeout(void *);
235 void			ra_timer_update(void *, struct timeval *);
236 void			ra_output(struct rainfo *);
237 
238 int			prefix_match(struct in6_addr *, int,
239 			    struct in6_addr *, int);
240 struct rainfo		*if_indextorainfo(int);
241 struct prefix		*find_prefix(struct rainfo *,
242 			    struct in6_addr *, int);
243