]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/net/tcpip/v2_0/include/netinet6/nd6.h
Initial revision
[karo-tx-redboot.git] / packages / net / tcpip / v2_0 / include / netinet6 / nd6.h
1 //==========================================================================
2 //
3 //      include/netinet6.nd6.h
4 //
5 //      
6 //
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 //
12 // Portions of this software may have been derived from OpenBSD or other sources,
13 // and are covered by the appropriate copyright disclaimers included herein.
14 //
15 // -------------------------------------------
16 //
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
20 //
21 // Author(s):    gthomas
22 // Contributors: gthomas
23 // Date:         2000-01-10
24 // Purpose:      
25 // Description:  
26 //              
27 //
28 //####DESCRIPTIONEND####
29 //
30 //==========================================================================
31
32 /*      $OpenBSD: nd6.h,v 1.1 1999/12/08 06:50:23 itojun Exp $  */
33
34 /*
35  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
36  * All rights reserved.
37  * 
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. Neither the name of the project nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  * 
50  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  */
62
63 #ifndef _NETINET6_ND6_H_
64 #define _NETINET6_ND6_H_
65
66 #include <sys/queue.h>
67
68 struct  llinfo_nd6 {
69         struct  llinfo_nd6 *ln_next;
70         struct  llinfo_nd6 *ln_prev;
71         struct  rtentry *ln_rt;
72         struct  mbuf *ln_hold;  /* last packet until resolved/timeout */
73         long    ln_asked;       /* number of queries already sent for this addr */
74         u_long  ln_expire;      /* lifetime for NDP state transition */
75         short   ln_state;       /* reachability state */
76         short   ln_router;      /* 2^0: ND6 router bit */
77 };
78
79 #define ND6_LLINFO_NOSTATE      -2
80 #define ND6_LLINFO_WAITDELETE   -1
81 #define ND6_LLINFO_INCOMPLETE   0
82 #define ND6_LLINFO_REACHABLE    1
83 #define ND6_LLINFO_STALE        2
84 #define ND6_LLINFO_DELAY        3
85 #define ND6_LLINFO_PROBE        4
86
87 struct nd_ifinfo {
88         u_int32_t linkmtu;              /* LinkMTU */
89         u_int32_t maxmtu;               /* Upper bound of LinkMTU */
90         u_int32_t basereachable;        /* BaseReachableTime */
91         u_int32_t reachable;            /* Reachable Time */
92         u_int32_t retrans;              /* Retrans Timer */
93         int recalctm;                   /* BaseReacable re-calculation timer */
94         u_int8_t chlim;                 /* CurHopLimit */
95         u_int8_t receivedra;
96 };
97
98 struct in6_nbrinfo {
99         char ifname[IFNAMSIZ];  /* if name, e.g. "en0" */
100         struct in6_addr addr;   /* IPv6 address of the neighbor */
101         long    asked;          /* number of queries already sent for this addr */
102         int     isrouter;       /* if it acts as a router */
103         int     state;          /* reachability state */
104         int     expire;         /* lifetime for NDP state transition */
105 };
106
107 #define DRLSTSIZ 10
108 #define PRLSTSIZ 10
109 struct  in6_drlist {
110         char ifname[IFNAMSIZ];
111         struct {
112                 struct  in6_addr rtaddr;
113                 u_char  flags;
114                 u_short rtlifetime;
115                 u_long  expire;
116                 u_short if_index;
117         } defrouter[DRLSTSIZ];
118 };
119
120 struct  in6_prlist {
121         char ifname[IFNAMSIZ];
122         struct {
123                 struct  in6_addr prefix;
124                 struct prf_ra raflags;
125                 u_char  prefixlen;
126                 u_long  vltime;
127                 u_long  pltime;
128                 u_long  expire;
129                 u_short if_index;
130                 u_short advrtrs; /* number of advertisement routers */
131                 struct  in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */
132         } prefix[PRLSTSIZ];
133 };
134
135 struct  in6_ndireq {
136         char ifname[IFNAMSIZ];
137         struct nd_ifinfo ndi;
138 };
139
140 /* protocol constants */
141 #define MAX_RTR_SOLICITATION_DELAY      1       /*1sec*/
142 #define RTR_SOLICITATION_INTERVAL       4       /*4sec*/
143 #define MAX_RTR_SOLICITATIONS           3
144
145 #define ND6_INFINITE_LIFETIME           0xffffffff
146
147 #ifdef _KERNEL
148 /* node constants */
149 #define MAX_REACHABLE_TIME              3600000 /* msec */
150 #define REACHABLE_TIME                  30000   /* msec */
151 #define RETRANS_TIMER                   1000    /* msec */
152 #define MIN_RANDOM_FACTOR               512     /* 1024 * 0.5 */
153 #define MAX_RANDOM_FACTOR               1536    /* 1024 * 1.5 */
154 #define ND_COMPUTE_RTIME(x) \
155                 (((MIN_RANDOM_FACTOR * (x >> 10)) + (random() & \
156                 ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
157
158 struct  nd_defrouter {
159         LIST_ENTRY(nd_defrouter) dr_entry;
160 #define dr_next dr_entry.le_next
161         struct  in6_addr rtaddr;
162         u_char  flags;
163         u_short rtlifetime;
164         u_long  expire;
165         struct  ifnet *ifp;
166 };
167
168 struct nd_prefix {
169         struct ifnet *ndpr_ifp;
170         LIST_ENTRY(nd_prefix) ndpr_entry;
171         struct sockaddr_in6 ndpr_prefix;        /* prefix */
172         struct in6_addr ndpr_mask; /* netmask derived from the prefix */
173         struct in6_addr ndpr_addr; /* address that is derived from the prefix */
174         u_int32_t ndpr_vltime;  /* advertised valid lifetime */
175         u_int32_t ndpr_pltime;  /* advertised preferred lifetime */
176         time_t ndpr_expire;     /* expiration time of the prefix */
177         time_t ndpr_preferred;  /* preferred time of the prefix */
178         struct prf_ra ndpr_flags;
179         /* list of routers that advertise the prefix: */
180         LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs;
181         u_char  ndpr_plen;
182         struct  ndpr_stateflags {
183                 /* if this prefix can be regarded as on-link */
184                 u_char onlink : 1;
185         } ndpr_stateflags;
186 };
187
188 #define ndpr_next               ndpr_entry.le_next
189
190 #define ndpr_raf                ndpr_flags
191 #define ndpr_raf_onlink         ndpr_flags.onlink
192 #define ndpr_raf_auto           ndpr_flags.autonomous
193
194 #define ndpr_statef_onlink      ndpr_stateflags.onlink
195 #define ndpr_statef_addmark     ndpr_stateflags.addmark
196
197 /*
198  * We keep expired prefix for certain amount of time, for validation purposes.
199  * 1800s = MaxRtrAdvInterval
200  */
201 #define NDPR_KEEP_EXPIRED       (1800 * 2)
202
203 /*
204  * Message format for use in obtaining information about prefixes
205  * from inet6 sysctl function
206  */
207 struct inet6_ndpr_msghdr {
208         u_short inpm_msglen;    /* to skip over non-understood messages */
209         u_char  inpm_version;   /* future binary compatability */
210         u_char  inpm_type;      /* message type */
211         struct in6_addr inpm_prefix;
212         u_long  prm_vltim;
213         u_long  prm_pltime;
214         u_long  prm_expire;
215         u_long  prm_preferred;
216         struct in6_prflags prm_flags;
217         u_short prm_index;      /* index for associated ifp */
218         u_char  prm_plen;       /* length of prefix in bits */
219 };
220
221 #define prm_raf_onlink          prm_flags.prf_ra.onlink
222 #define prm_raf_auto            prm_flags.prf_ra.autonomous
223
224 #define prm_statef_onlink       prm_flags.prf_state.onlink
225
226 #define prm_rrf_decrvalid       prm_flags.prf_rr.decrvalid
227 #define prm_rrf_decrprefd       prm_flags.prf_rr.decrprefd
228
229 #define ifpr2ndpr(ifpr) ((struct nd_prefix *)(ifpr))
230 #define ndpr2ifpr(ndpr) ((struct ifprefix *)(ndpr))
231
232 struct nd_pfxrouter {
233         LIST_ENTRY(nd_pfxrouter) pfr_entry;
234 #define pfr_next pfr_entry.le_next
235         struct nd_defrouter *router;
236 };
237
238 LIST_HEAD(nd_drhead, nd_defrouter);
239 LIST_HEAD(nd_prhead, nd_prefix);
240
241 /* nd6.c */
242 extern int nd6_prune;
243 extern int nd6_delay;
244 extern int nd6_umaxtries;
245 extern int nd6_mmaxtries;
246 extern int nd6_useloopback;
247 extern int nd6_proxyall;
248 extern struct llinfo_nd6 llinfo_nd6;
249 extern struct nd_ifinfo *nd_ifinfo;
250 extern struct nd_drhead nd_defrouter;
251 extern struct nd_prhead nd_prefix;
252
253 union nd_opts {
254         struct nd_opt_hdr *nd_opt_array[9];
255         struct {
256                 struct nd_opt_hdr *zero;
257                 struct nd_opt_hdr *src_lladdr;
258                 struct nd_opt_hdr *tgt_lladdr;
259                 struct nd_opt_prefix_info *pi_beg;/* multiple opts, start */
260                 struct nd_opt_rd_hdr *rh;
261                 struct nd_opt_mtu *mtu;
262                 struct nd_opt_hdr *search;      /* multiple opts */
263                 struct nd_opt_hdr *last;        /* multiple opts */
264                 int done;
265                 struct nd_opt_prefix_info *pi_end;/* multiple opts, end */
266         } nd_opt_each;
267 };
268 #define nd_opts_src_lladdr      nd_opt_each.src_lladdr
269 #define nd_opts_tgt_lladdr      nd_opt_each.tgt_lladdr
270 #define nd_opts_pi              nd_opt_each.pi_beg
271 #define nd_opts_pi_end          nd_opt_each.pi_end
272 #define nd_opts_rh              nd_opt_each.rh
273 #define nd_opts_mtu             nd_opt_each.mtu
274 #define nd_opts_search          nd_opt_each.search
275 #define nd_opts_last            nd_opt_each.last
276 #define nd_opts_done            nd_opt_each.done
277
278 /* XXX: need nd6_var.h?? */
279 /* nd6.c */
280 void nd6_init __P((void));
281 void nd6_ifattach __P((struct ifnet *));
282 int nd6_is_addr_neighbor __P((struct in6_addr *, struct ifnet *));
283 void nd6_option_init __P((void *, int, union nd_opts *));
284 struct nd_opt_hdr *nd6_option __P((union nd_opts *));
285 int nd6_options __P((union nd_opts *));
286 struct  rtentry *nd6_lookup __P((struct in6_addr *, int, struct ifnet *));
287 void nd6_setmtu __P((struct ifnet *));
288 void nd6_timer __P((void *));
289 void nd6_free __P((struct rtentry *));
290 void nd6_nud_hint __P((struct rtentry *, struct in6_addr *));
291 int nd6_resolve __P((struct ifnet *, struct rtentry *,
292                      struct mbuf *, struct sockaddr *, u_char *));
293 #if defined(__bsdi__) && _BSDI_VERSION >= 199802
294 void nd6_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
295 void nd6_p2p_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
296 #else
297 void nd6_rtrequest __P((int, struct rtentry *, struct sockaddr *));
298 void nd6_p2p_rtrequest __P((int, struct rtentry *, struct sockaddr *));
299 #endif
300 int nd6_ioctl __P((u_long, caddr_t, struct ifnet *));
301 struct rtentry *nd6_cache_lladdr __P((struct ifnet *, struct in6_addr *,
302         char *, int, int, int));
303 /* for test */
304 int nd6_output __P((struct ifnet *, struct mbuf *, struct sockaddr_in6 *,
305                     struct rtentry *));
306 int nd6_storelladdr __P((struct ifnet *, struct rtentry *, struct mbuf *,
307                          struct sockaddr *, u_char *));
308
309 /* nd6_nbr.c */
310 void nd6_na_input __P((struct mbuf *, int, int));
311 void nd6_na_output __P((struct ifnet *, struct in6_addr *,
312                         struct in6_addr *, u_long, int));
313 void nd6_ns_input __P((struct mbuf *, int, int));
314 void nd6_ns_output __P((struct ifnet *, struct in6_addr *,
315                         struct in6_addr *, struct llinfo_nd6 *, int));
316 caddr_t nd6_ifptomac __P((struct ifnet *));
317 void nd6_dad_start __P((struct ifaddr *, int *));
318 void nd6_dad_duplicated __P((struct ifaddr *));
319
320 /* nd6_rtr.c */
321 void nd6_rs_input __P((struct mbuf *, int, int));
322 void nd6_ra_input __P((struct mbuf *, int, int));
323 void prelist_del __P((struct nd_prefix *));
324 void defrouter_addreq __P((struct nd_defrouter *));
325 void defrouter_delreq __P((struct nd_defrouter *, int));
326 void defrtrlist_del __P((struct nd_defrouter *));
327 void prelist_remove __P((struct nd_prefix *));
328 int prelist_update __P((struct nd_prefix *, struct nd_defrouter *,
329         struct mbuf *));
330 struct nd_defrouter *defrouter_lookup __P((struct in6_addr *,
331                                            struct ifnet *));
332 int in6_ifdel __P((struct ifnet *, struct in6_addr *));
333 int in6_init_prefix_ltimes __P((struct nd_prefix *ndpr));
334 void rt6_flush __P((struct in6_addr *, struct ifnet *));
335
336 #endif /* _KERNEL */
337
338 #endif /* _NETINET6_ND6_H_ */