1/*	$KAME: rtsold.h,v 1.19 2003/04/16 09:48:15 itojun Exp $	*/
2
3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * $FreeBSD$
32 */
33
34struct script_msg {
35	TAILQ_ENTRY(script_msg)	sm_next;
36
37	char *sm_msg;
38};
39
40TAILQ_HEAD(script_msg_head_t, script_msg);
41
42struct ra_opt {
43	TAILQ_ENTRY(ra_opt)	rao_next;
44
45	u_int8_t	rao_type;
46	struct timespec	rao_expire;
47	size_t		rao_len;
48	void		*rao_msg;
49};
50
51TAILQ_HEAD(rainfo_head, ra_opt);
52
53struct rainfo {
54	TAILQ_ENTRY(rainfo)	rai_next;
55
56	struct ifinfo		*rai_ifinfo;
57	struct sockaddr_in6	rai_saddr;
58	TAILQ_HEAD(, ra_opt)	rai_ra_opt;
59};
60
61struct ifinfo {
62	TAILQ_ENTRY(ifinfo)	ifi_next;	/* pointer to the next interface */
63
64	struct sockaddr_dl *sdl; /* link-layer address */
65	char ifname[IFNAMSIZ];	/* interface name */
66	u_int32_t linkid;	/* link ID of this interface */
67	int active;		/* interface status */
68	int probeinterval;	/* interval of probe timer (if necessary) */
69	int probetimer;		/* rest of probe timer */
70	int mediareqok;		/* whether the IF supports SIOCGIFMEDIA */
71	int otherconfig;	/* need a separate protocol for the "other"
72				 * configuration */
73	int state;
74	int probes;
75	int dadcount;
76	struct timespec timer;
77	struct timespec expire;
78	int errors;		/* # of errors we've got - detect wedge */
79#define IFI_DNSOPT_STATE_NOINFO		0
80#define IFI_DNSOPT_STATE_RECEIVED     	1
81	int ifi_rdnss;		/* RDNSS option state */
82	int ifi_dnssl;		/* DNSSL option state */
83
84	int racnt;		/* total # of valid RAs it have got */
85	TAILQ_HEAD(, rainfo)	ifi_rainfo;
86
87	size_t rs_datalen;
88	u_char *rs_data;
89};
90
91/* per interface status */
92#define IFS_IDLE	0
93#define IFS_DELAY	1
94#define IFS_PROBE	2
95#define IFS_DOWN	3
96#define IFS_TENTATIVE	4
97
98/* Interface list */
99extern TAILQ_HEAD(ifinfo_head_t, ifinfo) ifinfo_head;
100
101#define	DNSINFO_ORIGIN_LABEL	"slaac"
102/*
103 * RFC 3542 API deprecates IPV6_PKTINFO in favor of
104 * IPV6_RECVPKTINFO
105 */
106#ifndef IPV6_RECVPKTINFO
107#ifdef IPV6_PKTINFO
108#define IPV6_RECVPKTINFO	IPV6_PKTINFO
109#endif
110#endif
111/*
112 * RFC 3542 API deprecates IPV6_HOPLIMIT in favor of
113 * IPV6_RECVHOPLIMIT
114 */
115#ifndef IPV6_RECVHOPLIMIT
116#ifdef IPV6_HOPLIMIT
117#define IPV6_RECVHOPLIMIT	IPV6_HOPLIMIT
118#endif
119#endif
120
121#ifndef IN6ADDR_LINKLOCAL_ALLROUTERS_INIT
122#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT			\
123	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	\
124	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
125#endif
126
127#define	TS_CMP(tsp, usp, cmp)						\
128	(((tsp)->tv_sec == (usp)->tv_sec) ?				\
129	    ((tsp)->tv_nsec cmp (usp)->tv_nsec) :			\
130	    ((tsp)->tv_sec cmp (usp)->tv_sec))
131#define	TS_ADD(tsp, usp, vsp)						\
132	do {								\
133		(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;		\
134		(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;	\
135		if ((vsp)->tv_nsec >= 1000000000L) {			\
136			(vsp)->tv_sec++;				\
137			(vsp)->tv_nsec -= 1000000000L;			\
138		}							\
139	} while (0)
140#define	TS_SUB(tsp, usp, vsp)						\
141	do {								\
142		(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;		\
143		(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;	\
144		if ((vsp)->tv_nsec < 0) {				\
145			(vsp)->tv_sec--;				\
146			(vsp)->tv_nsec += 1000000000L;			\
147		}							\
148	} while (0)
149
150/* rtsold.c */
151extern struct timespec tm_max;
152extern int dflag;
153extern int aflag;
154extern int Fflag;
155extern int uflag;
156extern const char *otherconf_script;
157extern const char *resolvconf_script;
158extern int ifconfig(char *);
159extern void iflist_init(void);
160struct ifinfo *find_ifinfo(int);
161struct rainfo *find_rainfo(struct ifinfo *, struct sockaddr_in6 *);
162void rtsol_timer_update(struct ifinfo *);
163extern void warnmsg(int, const char *, const char *, ...)
164     __attribute__((__format__(__printf__, 3, 4)));
165extern char **autoifprobe(void);
166extern int ra_opt_handler(struct ifinfo *);
167
168/* if.c */
169extern int ifinit(void);
170extern int interface_up(char *);
171extern int interface_status(struct ifinfo *);
172extern int lladdropt_length(struct sockaddr_dl *);
173extern void lladdropt_fill(struct sockaddr_dl *, struct nd_opt_hdr *);
174extern struct sockaddr_dl *if_nametosdl(char *);
175extern int getinet6sysctl(int);
176extern int setinet6sysctl(int, int);
177
178/* rtsol.c */
179extern int rssock;
180extern int sockopen(void);
181extern void sendpacket(struct ifinfo *);
182extern void rtsol_input(int);
183
184/* probe.c */
185extern int probe_init(void);
186extern void defrouter_probe(struct ifinfo *);
187
188/* dump.c */
189extern void rtsold_dump_file(const char *);
190extern const char *sec2str(const struct timespec *);
191
192/* rtsock.c */
193extern int rtsock_open(void);
194extern int rtsock_input(int);
195