Allow IPv6 address entry in tools>ping - Loosens valid character check
[tomato/davidwu.git] / release / src / router / dhcpv6 / common.h
blob8f331912948abeaf6ef7b1fadedff413698c1a6b
1 /* $KAME: common.h,v 1.42 2005/09/16 11:30:13 suz Exp $ */
2 /*
3 * Copyright (C) 1998 and 1999 WIDE Project.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the project nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
31 #ifdef __KAME__
32 #define IN6_IFF_INVALID (IN6_IFF_ANYCAST|IN6_IFF_TENTATIVE|\
33 IN6_IFF_DUPLICATED|IN6_IFF_DETACHED)
34 #else
35 #define IN6_IFF_INVALID (0)
36 #endif
38 #ifdef HAVE_ANSI_FUNC
39 #define FNAME __func__
40 #elif defined (HAVE_GCC_FUNCTION)
41 #define FNAME __FUNCTION__
42 #else
43 #define FNAME ""
44 #endif
46 /* XXX: bsdi4 does not have TAILQ_EMPTY */
47 #ifndef TAILQ_EMPTY
48 #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
49 #endif
51 /* and linux *_FIRST and *_NEXT */
52 #ifndef LIST_EMPTY
53 #define LIST_EMPTY(head) ((head)->lh_first == NULL)
54 #endif
55 #ifndef LIST_FIRST
56 #define LIST_FIRST(head) ((head)->lh_first)
57 #endif
58 #ifndef LIST_NEXT
59 #define LIST_NEXT(elm, field) ((elm)->field.le_next)
60 #endif
61 #ifndef LIST_FOREACH
62 #define LIST_FOREACH(var, head, field) \
63 for ((var) = LIST_FIRST((head)); \
64 (var); \
65 (var) = LIST_NEXT((var), field))
66 #endif
67 #ifndef TAILQ_FIRST
68 #define TAILQ_FIRST(head) ((head)->tqh_first)
69 #endif
70 #ifndef TAILQ_LAST
71 #define TAILQ_LAST(head, headname) \
72 (*(((struct headname *)((head)->tqh_last))->tqh_last))
73 #endif
74 #ifndef TAILQ_PREV
75 #define TAILQ_PREV(elm, headname, field) \
76 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
77 #endif
78 #ifndef TAILQ_NEXT
79 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
80 #endif
81 #ifndef TAILQ_FOREACH
82 #define TAILQ_FOREACH(var, head, field) \
83 for ((var) = TAILQ_FIRST((head)); \
84 (var); \
85 (var) = TAILQ_NEXT((var), field))
86 #endif
87 #ifdef HAVE_TAILQ_FOREACH_REVERSE_OLD
88 #undef TAILQ_FOREACH_REVERSE
89 #endif
90 #ifndef TAILQ_FOREACH_REVERSE
91 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
92 for ((var) = TAILQ_LAST((head), headname); \
93 (var); \
94 (var) = TAILQ_PREV((var), headname, field))
95 #endif
98 #ifndef SO_REUSEPORT
99 #define SO_REUSEPORT SO_REUSEADDR
100 #endif
102 /* s*_len stuff */
103 static __inline u_int8_t
104 sysdep_sa_len (const struct sockaddr *sa)
106 #ifndef HAVE_SA_LEN
107 switch (sa->sa_family)
109 case AF_INET:
110 return sizeof (struct sockaddr_in);
111 case AF_INET6:
112 return sizeof (struct sockaddr_in6);
114 return sizeof (struct sockaddr_in);
115 #else
116 return sa->sa_len;
117 #endif
120 extern int foreground;
121 extern int debug_thresh;
122 extern int duid_type;
123 extern char *device;
125 #include "debug.h"
127 /* search option for dhcp6_find_listval() */
128 #define MATCHLIST_PREFIXLEN 0x1
130 /* common.c */
131 typedef enum { IFADDRCONF_ADD, IFADDRCONF_REMOVE } ifaddrconf_cmd_t;
132 extern int dhcp6_copy_list __P((struct dhcp6_list *, struct dhcp6_list *));
133 extern void dhcp6_move_list __P((struct dhcp6_list *, struct dhcp6_list *));
134 extern void dhcp6_clear_list __P((struct dhcp6_list *));
135 extern void dhcp6_clear_listval __P((struct dhcp6_listval *));
136 extern struct dhcp6_listval *dhcp6_find_listval __P((struct dhcp6_list *,
137 dhcp6_listval_type_t, void *, int));
138 extern struct dhcp6_listval *dhcp6_add_listval __P((struct dhcp6_list *,
139 dhcp6_listval_type_t, void *, struct dhcp6_list *));
140 extern int dhcp6_vbuf_copy __P((struct dhcp6_vbuf *, struct dhcp6_vbuf *));
141 extern void dhcp6_vbuf_free __P((struct dhcp6_vbuf *));
142 extern int dhcp6_vbuf_cmp __P((struct dhcp6_vbuf *, struct dhcp6_vbuf *));
143 extern struct dhcp6_event *dhcp6_create_event __P((struct dhcp6_if *, int));
144 extern void dhcp6_remove_event __P((struct dhcp6_event *));
145 extern void dhcp6_remove_evdata __P((struct dhcp6_event *));
146 extern struct authparam *new_authparam __P((int, int, int));
147 extern struct authparam *copy_authparam __P((struct authparam *));
148 extern int dhcp6_auth_replaycheck __P((int, u_int64_t, u_int64_t));
149 extern int getifaddr __P((struct in6_addr *, char *, struct in6_addr *,
150 int, int, int));
151 extern int getifidfromaddr __P((struct in6_addr *, unsigned int *));
152 extern int transmit_sa __P((int, struct sockaddr *, char *, size_t));
153 extern long random_between __P((long, long));
154 extern int prefix6_mask __P((struct in6_addr *, int));
155 extern int sa6_plen2mask __P((struct sockaddr_in6 *, int));
156 extern char *addr2str __P((struct sockaddr *));
157 extern char *in6addr2str __P((struct in6_addr *, int));
158 extern int in6_addrscopebyif __P((struct in6_addr *, char *));
159 extern int in6_scope __P((struct in6_addr *));
160 extern void setloglevel __P((int));
161 extern int get_duid __P((char *, struct duid *));
162 extern void dhcp6_init_options __P((struct dhcp6_optinfo *));
163 extern void dhcp6_clear_options __P((struct dhcp6_optinfo *));
164 extern int dhcp6_copy_options __P((struct dhcp6_optinfo *,
165 struct dhcp6_optinfo *));
166 extern int dhcp6_get_options __P((struct dhcp6opt *, struct dhcp6opt *,
167 struct dhcp6_optinfo *));
168 extern int dhcp6_set_options __P((int, struct dhcp6opt *, struct dhcp6opt *,
169 struct dhcp6_optinfo *));
170 extern void dhcp6_set_timeoparam __P((struct dhcp6_event *));
171 extern void dhcp6_reset_timer __P((struct dhcp6_event *));
172 extern char *dhcp6optstr __P((int));
173 extern char *dhcp6msgstr __P((int));
174 extern char *dhcp6_stcodestr __P((u_int16_t));
175 extern char *duidstr __P((struct duid *));
176 extern char *dhcp6_event_statestr __P((struct dhcp6_event *));
177 extern int get_rdvalue __P((int, void *, size_t));
178 extern int duidcpy __P((struct duid *, struct duid *));
179 extern int duidcmp __P((struct duid *, struct duid *));
180 extern void duidfree __P((struct duid *));
181 extern int ifaddrconf __P((ifaddrconf_cmd_t, char *, struct sockaddr_in6 *,
182 int, int, int));
183 extern int safefile __P((const char *));
185 /* missing */
186 #ifndef HAVE_STRLCAT
187 extern size_t strlcat __P((char *, const char *, size_t));
188 #endif
189 #ifndef HAVE_STRLCPY
190 extern size_t strlcpy __P((char *, const char *, size_t));
191 #endif
194 * compat hacks in case libc and kernel get out of sync:
196 * glibc 2.4 and uClibc 0.9.29 introduce IPV6_RECVPKTINFO etc. and change IPV6_PKTINFO
197 * This is only supported in Linux kernel >= 2.6.14
199 * This is only an approximation because the kernel version that libc was compiled against
200 * could be older or newer than the one being run. But this should not be a problem --
201 * we just keep using the old kernel interface.
203 * these are placed here because they're needed in all of socket.c, recv.c and send.c
205 #ifdef __linux__
206 # if defined IPV6_RECVHOPLIMIT || defined IPV6_RECVPKTINFO
207 # include <linux/version.h>
208 # if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
209 # if defined IPV6_RECVHOPLIMIT && defined IPV6_2292HOPLIMIT
210 # undef IPV6_RECVHOPLIMIT
211 # define IPV6_RECVHOPLIMIT IPV6_2292HOPLIMIT
212 # endif
213 # if defined IPV6_RECVPKTINFO && defined IPV6_2292PKTINFO
214 # undef IPV6_RECVPKTINFO
215 # undef IPV6_PKTINFO
216 # define IPV6_RECVPKTINFO IPV6_2292PKTINFO
217 # define IPV6_PKTINFO IPV6_2292PKTINFO
218 # endif
219 # endif
220 # endif
221 #endif