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