-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.h
178 lines (168 loc) · 6.58 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* $KAME: common.h,v 1.42 2005/09/16 11:30:13 suz Exp $ */
/*
* Copyright (C) 1998 and 1999 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#define IN6_IFF_INVALID (IN6_IFF_ANYCAST|IN6_IFF_TENTATIVE|\
IN6_IFF_DUPLICATED|IN6_IFF_DETACHED)
#ifdef HAVE_ANSI_FUNC
#define FNAME __func__
#elif defined (HAVE_GCC_FUNCTION)
#define FNAME __FUNCTION__
#else
#define FNAME ""
#endif
/* XXX: bsdi4 does not have TAILQ_EMPTY */
#ifndef TAILQ_EMPTY
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
#endif
/* and linux *_FIRST and *_NEXT */
#ifndef LIST_EMPTY
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
#endif
#ifndef LIST_FIRST
#define LIST_FIRST(head) ((head)->lh_first)
#endif
#ifndef LIST_NEXT
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#endif
#ifndef LIST_FOREACH
#define LIST_FOREACH(var, head, field) \
for ((var) = LIST_FIRST((head)); \
(var); \
(var) = LIST_NEXT((var), field))
#endif
#ifndef TAILQ_FIRST
#define TAILQ_FIRST(head) ((head)->tqh_first)
#endif
#ifndef TAILQ_LAST
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))
#endif
#ifndef TAILQ_PREV
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
#endif
#ifndef TAILQ_NEXT
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#endif
#ifndef TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field) \
for ((var) = TAILQ_FIRST((head)); \
(var); \
(var) = TAILQ_NEXT((var), field))
#endif
#ifdef HAVE_TAILQ_FOREACH_REVERSE_OLD
#undef TAILQ_FOREACH_REVERSE
#endif
#ifndef TAILQ_FOREACH_REVERSE
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for ((var) = TAILQ_LAST((head), headname); \
(var); \
(var) = TAILQ_PREV((var), headname, field))
#endif
#ifndef SO_REUSEPORT
#define SO_REUSEPORT SO_REUSEADDR
#endif
/* s*_len stuff */
static __inline u_int8_t
sysdep_sa_len (const struct sockaddr *sa)
{
#ifndef HAVE_SA_LEN
switch (sa->sa_family)
{
case AF_INET:
return sizeof (struct sockaddr_in);
case AF_INET6:
return sizeof (struct sockaddr_in6);
}
return sizeof (struct sockaddr_in);
#else
return sa->sa_len;
#endif
}
extern int foreground;
extern int debug_thresh;
extern char *device;
/* search option for dhcp6_find_listval() */
#define MATCHLIST_PREFIXLEN 0x1
/* common.c */
typedef enum { IFADDRCONF_ADD, IFADDRCONF_REMOVE } ifaddrconf_cmd_t;
extern int dhcp6_copy_list(struct dhcp6_list *, struct dhcp6_list *);
extern void dhcp6_move_list(struct dhcp6_list *, struct dhcp6_list *);
extern void dhcp6_clear_list(struct dhcp6_list *);
extern void dhcp6_clear_listval(struct dhcp6_listval *);
extern struct dhcp6_listval *dhcp6_find_listval(struct dhcp6_list *,
dhcp6_listval_type_t, void *, int);
extern struct dhcp6_listval *dhcp6_add_listval(struct dhcp6_list *,
dhcp6_listval_type_t, void *, struct dhcp6_list *);
extern int dhcp6_vbuf_copy(struct dhcp6_vbuf *, struct dhcp6_vbuf *);
extern void dhcp6_vbuf_free(struct dhcp6_vbuf *);
extern int dhcp6_vbuf_cmp(struct dhcp6_vbuf *, struct dhcp6_vbuf *);
extern struct dhcp6_event *dhcp6_create_event(struct dhcp6_if *, int);
extern void dhcp6_remove_event(struct dhcp6_event *);
extern void dhcp6_remove_evdata(struct dhcp6_event *);
extern struct authparam *new_authparam(int, int, int);
extern struct authparam *copy_authparam(struct authparam *);
extern int dhcp6_auth_replaycheck(int, u_int64_t, u_int64_t);
extern int getifaddr(struct in6_addr *, char *, struct in6_addr *,
int, int, int);
extern int getifidfromaddr(struct in6_addr *, unsigned int *);
extern int transmit_sa(int, struct sockaddr *, char *, size_t);
extern long random_between(long, long);
extern int prefix6_mask(struct in6_addr *, int);
extern int sa6_plen2mask(struct sockaddr_in6 *, int);
extern char *addr2str(struct sockaddr *);
extern char *in6addr2str(struct in6_addr *, int);
extern int in6_addrscopebyif(struct in6_addr *, char *);
extern int in6_scope(struct in6_addr *);
extern void setloglevel(int);
extern void debugprintf(int, const char *, const char *, ...)
__attribute__((__format__ (printf, 3, 4)));
extern int get_duid(const char *, struct duid *);
extern void dhcp6_init_options(struct dhcp6_optinfo *);
extern void dhcp6_clear_options(struct dhcp6_optinfo *);
extern int dhcp6_copy_options(struct dhcp6_optinfo *,
struct dhcp6_optinfo *);
extern int dhcp6_get_options(struct dhcp6opt *, struct dhcp6opt *,
struct dhcp6_optinfo *);
extern int dhcp6_set_options(int, struct dhcp6opt *, struct dhcp6opt *,
struct dhcp6_optinfo *);
extern void dhcp6_set_timeoparam(struct dhcp6_event *);
extern void dhcp6_reset_timer(struct dhcp6_event *);
extern const char *dhcp6optstr(int);
extern const char *dhcp6msgstr(int);
extern const char *dhcp6_stcodestr(u_int16_t);
extern char *duidstr(struct duid *);
extern const char *dhcp6_event_statestr(struct dhcp6_event *);
extern int get_rdvalue(int, void *, size_t);
extern int duidcpy(struct duid *, struct duid *);
extern int duidcmp(struct duid *, struct duid *);
extern void duidfree(struct duid *);
extern int ifaddrconf(ifaddrconf_cmd_t, char *, struct sockaddr_in6 *,
int, int, int);
extern int safefile(const char *);