rtadvd.h revision 1.14 1 1.14 roy /* $NetBSD: rtadvd.h,v 1.14 2015/06/05 14:09:20 roy Exp $ */
2 1.10 rpaulo /* $KAME: rtadvd.h,v 1.30 2005/10/17 14:40:02 suz Exp $ */
3 1.2 itojun
4 1.1 itojun /*
5 1.1 itojun * Copyright (C) 1998 WIDE Project.
6 1.1 itojun * All rights reserved.
7 1.1 itojun *
8 1.1 itojun * Redistribution and use in source and binary forms, with or without
9 1.1 itojun * modification, are permitted provided that the following conditions
10 1.1 itojun * are met:
11 1.1 itojun * 1. Redistributions of source code must retain the above copyright
12 1.1 itojun * notice, this list of conditions and the following disclaimer.
13 1.1 itojun * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 itojun * notice, this list of conditions and the following disclaimer in the
15 1.1 itojun * documentation and/or other materials provided with the distribution.
16 1.1 itojun * 3. Neither the name of the project nor the names of its contributors
17 1.1 itojun * may be used to endorse or promote products derived from this software
18 1.1 itojun * without specific prior written permission.
19 1.1 itojun *
20 1.1 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 1.1 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.1 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.1 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 1.1 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.1 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.1 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.1 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.1 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1 itojun * SUCH DAMAGE.
31 1.1 itojun */
32 1.1 itojun
33 1.13 roy #define RTADVD_USER "_rtadvd"
34 1.13 roy
35 1.1 itojun #define ALLNODES "ff02::1"
36 1.6 itojun #define ALLROUTERS_LINK "ff02::2"
37 1.6 itojun #define ALLROUTERS_SITE "ff05::2"
38 1.11 roy
39 1.11 roy #define IN6ADDR_SITELOCAL_ALLROUTERS_INIT \
40 1.11 roy {{{ 0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
41 1.11 roy 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
42 1.11 roy
43 1.11 roy //extern struct sockaddr_in6 sin6_linklocal_allnodes;
44 1.11 roy //extern struct sockaddr_in6 sin6_linklocal_allrouters;
45 1.11 roy extern struct sockaddr_in6 sin6_sitelocal_allrouters;
46 1.1 itojun
47 1.1 itojun /* protocol constants and default values */
48 1.1 itojun #define DEF_MAXRTRADVINTERVAL 600
49 1.1 itojun #define DEF_ADVLINKMTU 0
50 1.1 itojun #define DEF_ADVREACHABLETIME 0
51 1.1 itojun #define DEF_ADVRETRANSTIMER 0
52 1.1 itojun #define DEF_ADVCURHOPLIMIT 64
53 1.1 itojun #define DEF_ADVVALIDLIFETIME 2592000
54 1.1 itojun #define DEF_ADVPREFERREDLIFETIME 604800
55 1.1 itojun
56 1.1 itojun #define MAXROUTERLIFETIME 9000
57 1.10 rpaulo #define MIN_MAXINTERVAL 4
58 1.1 itojun #define MAX_MAXINTERVAL 1800
59 1.10 rpaulo #define MIN_MININTERVAL 3
60 1.1 itojun #define MAXREACHABLETIME 3600000
61 1.1 itojun
62 1.1 itojun #define MAX_INITIAL_RTR_ADVERT_INTERVAL 16
63 1.1 itojun #define MAX_INITIAL_RTR_ADVERTISEMENTS 3
64 1.1 itojun #define MAX_FINAL_RTR_ADVERTISEMENTS 3
65 1.1 itojun #define MIN_DELAY_BETWEEN_RAS 3
66 1.14 roy #define MAX_RA_DELAY_TIME 500000000 /* nsec */
67 1.1 itojun
68 1.4 itojun #define PREFIX_FROM_KERNEL 1
69 1.4 itojun #define PREFIX_FROM_CONFIG 2
70 1.4 itojun #define PREFIX_FROM_DYNAMIC 3
71 1.4 itojun
72 1.1 itojun struct prefix {
73 1.11 roy TAILQ_ENTRY(prefix) next;
74 1.1 itojun
75 1.10 rpaulo struct rainfo *rainfo; /* back pointer to the interface */
76 1.10 rpaulo
77 1.10 rpaulo struct rtadvd_timer *timer; /* expiration timer. used when a prefix
78 1.10 rpaulo * derived from the kernel is deleted.
79 1.10 rpaulo */
80 1.10 rpaulo
81 1.11 roy uint32_t validlifetime; /* AdvValidLifetime */
82 1.6 itojun long vltimeexpire; /* expiration of vltime; decrement case only */
83 1.11 roy uint32_t preflifetime; /* AdvPreferredLifetime */
84 1.6 itojun long pltimeexpire; /* expiration of pltime; decrement case only */
85 1.11 roy uint16_t onlinkflg; /* bool: AdvOnLinkFlag */
86 1.11 roy uint16_t autoconfflg; /* bool: AdvAutonomousFlag */
87 1.4 itojun int prefixlen;
88 1.10 rpaulo int origin; /* from kernel or config */
89 1.1 itojun struct in6_addr prefix;
90 1.1 itojun };
91 1.1 itojun
92 1.10 rpaulo struct rtinfo {
93 1.11 roy TAILQ_ENTRY(rtinfo) next;
94 1.10 rpaulo
95 1.11 roy uint32_t ltime; /* route lifetime */
96 1.11 roy uint16_t rtpref; /* route preference */
97 1.10 rpaulo int prefixlen;
98 1.10 rpaulo struct in6_addr prefix;
99 1.10 rpaulo };
100 1.11 roy
101 1.11 roy struct rdnss_addr {
102 1.11 roy TAILQ_ENTRY(rdnss_addr) next;
103 1.11 roy
104 1.11 roy struct in6_addr addr;
105 1.11 roy };
106 1.11 roy
107 1.11 roy struct rdnss {
108 1.11 roy TAILQ_ENTRY(rdnss) next;
109 1.11 roy
110 1.11 roy TAILQ_HEAD(, rdnss_addr) list;
111 1.11 roy uint32_t lifetime;
112 1.11 roy };
113 1.11 roy
114 1.11 roy struct dnssl_domain {
115 1.11 roy TAILQ_ENTRY(dnssl_domain) next;
116 1.11 roy
117 1.11 roy int len;
118 1.11 roy char domain[256];
119 1.11 roy };
120 1.11 roy
121 1.11 roy struct dnssl {
122 1.11 roy TAILQ_ENTRY(dnssl) next;
123 1.11 roy
124 1.11 roy TAILQ_HEAD(, dnssl_domain) list;
125 1.11 roy uint32_t lifetime;
126 1.11 roy };
127 1.9 itojun
128 1.5 itojun struct soliciter {
129 1.11 roy TAILQ_ENTRY(soliciter) next;
130 1.11 roy
131 1.5 itojun struct sockaddr_in6 addr;
132 1.5 itojun };
133 1.5 itojun
134 1.1 itojun struct rainfo {
135 1.11 roy TAILQ_ENTRY(rainfo) next;
136 1.1 itojun
137 1.1 itojun /* timer related parameters */
138 1.1 itojun struct rtadvd_timer *timer;
139 1.1 itojun int initcounter; /* counter for the first few advertisements */
140 1.14 roy struct timespec lastsent; /* timestamp when the latest RA was sent */
141 1.1 itojun int waiting; /* number of RS waiting for RA */
142 1.12 roy struct rainfo *leaving; /* the config which is leaving */
143 1.12 roy struct rainfo *leaving_for; /* the new config to activate */
144 1.12 roy int leaving_adv; /* number of RA left to send */
145 1.1 itojun
146 1.1 itojun /* interface information */
147 1.11 roy uint16_t ifindex;
148 1.12 roy int ifflags;
149 1.1 itojun int advlinkopt; /* bool: whether include link-layer addr opt */
150 1.1 itojun struct sockaddr_dl *sdl;
151 1.1 itojun char ifname[16];
152 1.11 roy uint32_t phymtu; /* mtu of the physical interface */
153 1.1 itojun
154 1.1 itojun /* Router configuration variables */
155 1.11 roy uint16_t lifetime; /* AdvDefaultLifetime */
156 1.11 roy uint16_t maxinterval; /* MaxRtrAdvInterval */
157 1.11 roy uint16_t mininterval; /* MinRtrAdvInterval */
158 1.1 itojun int managedflg; /* AdvManagedFlag */
159 1.1 itojun int otherflg; /* AdvOtherConfigFlag */
160 1.10 rpaulo
161 1.9 itojun int rtpref; /* router preference */
162 1.11 roy uint32_t linkmtu; /* AdvLinkMTU */
163 1.11 roy uint32_t reachabletime; /* AdvReachableTime */
164 1.11 roy uint32_t retranstimer; /* AdvRetransTimer */
165 1.11 roy uint16_t hoplimit; /* AdvCurHopLimit */
166 1.11 roy TAILQ_HEAD(, prefix) prefix; /* AdvPrefixList(link head) */
167 1.11 roy int pfxs;
168 1.11 roy uint16_t clockskew;/* used for consisitency check of lifetimes */
169 1.11 roy
170 1.11 roy TAILQ_HEAD(, rtinfo) route;
171 1.11 roy TAILQ_HEAD(, rdnss) rdnss; /* RDNSS list */
172 1.11 roy TAILQ_HEAD(, dnssl) dnssl; /* DNS Search List */
173 1.3 itojun
174 1.1 itojun /* actual RA packet data and its length */
175 1.1 itojun size_t ra_datalen;
176 1.11 roy char *ra_data;
177 1.4 itojun
178 1.4 itojun /* statistics */
179 1.11 roy uint64_t raoutput; /* number of RAs sent */
180 1.11 roy uint64_t rainput; /* number of RAs received */
181 1.11 roy uint64_t rainconsistent; /* number of RAs inconsistent with ours */
182 1.11 roy uint64_t rsinput; /* number of RSs received */
183 1.5 itojun
184 1.5 itojun /* info about soliciter */
185 1.11 roy TAILQ_HEAD(, soliciter) soliciter; /* recent solication source */
186 1.1 itojun };
187 1.1 itojun
188 1.11 roy extern TAILQ_HEAD(ralist_head_t, rainfo) ralist;
189 1.3 itojun
190 1.11 roy struct rtadvd_timer *ra_timeout(void *);
191 1.14 roy void ra_timer_update(void *, struct timespec *);
192 1.12 roy void ra_timer_set_short_delay(struct rainfo *);
193 1.6 itojun
194 1.11 roy int prefix_match(struct in6_addr *, int, struct in6_addr *, int);
195 1.11 roy struct rainfo *if_indextorainfo(unsigned int);
196 1.11 roy struct prefix *find_prefix(struct rainfo *, struct in6_addr *, int);
197