if_gif.c revision 1.118 1 1.118 knakahar /* $NetBSD: if_gif.c,v 1.118 2016/07/04 04:40:13 knakahara Exp $ */
2 1.34 itojun /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */
3 1.3 itojun
4 1.2 itojun /*
5 1.2 itojun * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 1.2 itojun * All rights reserved.
7 1.9 itojun *
8 1.2 itojun * Redistribution and use in source and binary forms, with or without
9 1.2 itojun * modification, are permitted provided that the following conditions
10 1.2 itojun * are met:
11 1.2 itojun * 1. Redistributions of source code must retain the above copyright
12 1.2 itojun * notice, this list of conditions and the following disclaimer.
13 1.2 itojun * 2. Redistributions in binary form must reproduce the above copyright
14 1.2 itojun * notice, this list of conditions and the following disclaimer in the
15 1.2 itojun * documentation and/or other materials provided with the distribution.
16 1.2 itojun * 3. Neither the name of the project nor the names of its contributors
17 1.2 itojun * may be used to endorse or promote products derived from this software
18 1.2 itojun * without specific prior written permission.
19 1.9 itojun *
20 1.2 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 1.2 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.2 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.2 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 1.2 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.2 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.2 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.2 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.2 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.2 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.2 itojun * SUCH DAMAGE.
31 1.2 itojun */
32 1.36 lukem
33 1.36 lukem #include <sys/cdefs.h>
34 1.118 knakahar __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.118 2016/07/04 04:40:13 knakahara Exp $");
35 1.2 itojun
36 1.88 pooka #ifdef _KERNEL_OPT
37 1.2 itojun #include "opt_inet.h"
38 1.118 knakahar #include "opt_net_mpsafe.h"
39 1.88 pooka #endif
40 1.2 itojun
41 1.2 itojun #include <sys/param.h>
42 1.2 itojun #include <sys/systm.h>
43 1.2 itojun #include <sys/kernel.h>
44 1.2 itojun #include <sys/mbuf.h>
45 1.2 itojun #include <sys/socket.h>
46 1.2 itojun #include <sys/sockio.h>
47 1.2 itojun #include <sys/errno.h>
48 1.2 itojun #include <sys/ioctl.h>
49 1.2 itojun #include <sys/time.h>
50 1.86 martin #include <sys/socketvar.h>
51 1.2 itojun #include <sys/syslog.h>
52 1.17 martin #include <sys/proc.h>
53 1.72 ad #include <sys/cpu.h>
54 1.72 ad #include <sys/intr.h>
55 1.98 knakahar #include <sys/kmem.h>
56 1.104 knakahar #include <sys/sysctl.h>
57 1.114 knakahar #include <sys/xcall.h>
58 1.2 itojun
59 1.2 itojun #include <net/if.h>
60 1.2 itojun #include <net/if_types.h>
61 1.2 itojun #include <net/netisr.h>
62 1.2 itojun #include <net/route.h>
63 1.2 itojun #include <net/bpf.h>
64 1.2 itojun
65 1.2 itojun #include <netinet/in.h>
66 1.2 itojun #include <netinet/in_systm.h>
67 1.15 itojun #include <netinet/ip.h>
68 1.15 itojun #ifdef INET
69 1.2 itojun #include <netinet/in_var.h>
70 1.57 christos #endif /* INET */
71 1.2 itojun #include <netinet/in_gif.h>
72 1.2 itojun
73 1.2 itojun #ifdef INET6
74 1.2 itojun #ifndef INET
75 1.2 itojun #include <netinet/in.h>
76 1.2 itojun #endif
77 1.2 itojun #include <netinet6/in6_var.h>
78 1.2 itojun #include <netinet/ip6.h>
79 1.2 itojun #include <netinet6/ip6_var.h>
80 1.2 itojun #include <netinet6/in6_gif.h>
81 1.2 itojun #endif /* INET6 */
82 1.2 itojun
83 1.9 itojun #include <netinet/ip_encap.h>
84 1.2 itojun #include <net/if_gif.h>
85 1.2 itojun
86 1.87 christos #include <net/net_osdep.h>
87 1.2 itojun
88 1.87 christos #include "ioconf.h"
89 1.4 itojun
90 1.118 knakahar #ifdef NET_MPSAFE
91 1.118 knakahar #define GIF_MPSAFE 1
92 1.118 knakahar #endif
93 1.118 knakahar
94 1.2 itojun /*
95 1.2 itojun * gif global variable definitions
96 1.2 itojun */
97 1.106 knakahar static LIST_HEAD(, gif_softc) gif_softc_list;
98 1.12 thorpej
99 1.109 knakahar static void gifattach0(struct gif_softc *);
100 1.109 knakahar static int gif_output(struct ifnet *, struct mbuf *,
101 1.109 knakahar const struct sockaddr *, const struct rtentry *);
102 1.111 knakahar static void gif_start(struct ifnet *);
103 1.109 knakahar static int gif_ioctl(struct ifnet *, u_long, void *);
104 1.109 knakahar static int gif_set_tunnel(struct ifnet *, struct sockaddr *,
105 1.109 knakahar struct sockaddr *);
106 1.109 knakahar static void gif_delete_tunnel(struct ifnet *);
107 1.109 knakahar
108 1.104 knakahar static void gif_sysctl_setup(struct sysctllog **);
109 1.104 knakahar
110 1.56 thorpej static int gif_clone_create(struct if_clone *, int);
111 1.56 thorpej static int gif_clone_destroy(struct ifnet *);
112 1.95 knakahar static int gif_check_nesting(struct ifnet *, struct mbuf *);
113 1.12 thorpej
114 1.97 knakahar static int gif_encap_attach(struct gif_softc *);
115 1.97 knakahar static int gif_encap_detach(struct gif_softc *);
116 1.114 knakahar static void gif_encap_pause(struct gif_softc *);
117 1.114 knakahar
118 1.56 thorpej static struct if_clone gif_cloner =
119 1.12 thorpej IF_CLONE_INITIALIZER("gif", gif_clone_create, gif_clone_destroy);
120 1.12 thorpej
121 1.9 itojun #ifndef MAX_GIF_NEST
122 1.9 itojun /*
123 1.9 itojun * This macro controls the upper limitation on nesting of gif tunnels.
124 1.9 itojun * Since, setting a large value to this macro with a careless configuration
125 1.9 itojun * may introduce system crash, we don't allow any nestings by default.
126 1.9 itojun * If you need to configure nested gif tunnels, you can define this macro
127 1.31 itojun * in your kernel configuration file. However, if you do so, please be
128 1.9 itojun * careful to configure the tunnels so that it won't make a loop.
129 1.9 itojun */
130 1.9 itojun #define MAX_GIF_NEST 1
131 1.9 itojun #endif
132 1.9 itojun static int max_gif_nesting = MAX_GIF_NEST;
133 1.2 itojun
134 1.104 knakahar static void
135 1.104 knakahar gif_sysctl_setup(struct sysctllog **clog)
136 1.104 knakahar {
137 1.104 knakahar
138 1.104 knakahar #ifdef INET
139 1.104 knakahar sysctl_createv(clog, 0, NULL, NULL,
140 1.104 knakahar CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
141 1.104 knakahar CTLTYPE_INT, "gifttl",
142 1.104 knakahar SYSCTL_DESCR("Default TTL for a gif tunnel datagram"),
143 1.104 knakahar NULL, 0, &ip_gif_ttl, 0,
144 1.104 knakahar CTL_NET, PF_INET, IPPROTO_IP,
145 1.104 knakahar IPCTL_GIF_TTL, CTL_EOL);
146 1.104 knakahar #endif
147 1.104 knakahar #ifdef INET6
148 1.104 knakahar sysctl_createv(clog, 0, NULL, NULL,
149 1.104 knakahar CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
150 1.104 knakahar CTLTYPE_INT, "gifhlim",
151 1.104 knakahar SYSCTL_DESCR("Default hop limit for a gif tunnel datagram"),
152 1.104 knakahar NULL, 0, &ip6_gif_hlim, 0,
153 1.104 knakahar CTL_NET, PF_INET6, IPPROTO_IPV6,
154 1.104 knakahar IPV6CTL_GIF_HLIM, CTL_EOL);
155 1.104 knakahar #endif
156 1.104 knakahar }
157 1.104 knakahar
158 1.12 thorpej /* ARGSUSED */
159 1.2 itojun void
160 1.63 christos gifattach(int count)
161 1.12 thorpej {
162 1.12 thorpej
163 1.12 thorpej LIST_INIT(&gif_softc_list);
164 1.12 thorpej if_clone_attach(&gif_cloner);
165 1.104 knakahar
166 1.104 knakahar gif_sysctl_setup(NULL);
167 1.12 thorpej }
168 1.12 thorpej
169 1.56 thorpej static int
170 1.56 thorpej gif_clone_create(struct if_clone *ifc, int unit)
171 1.2 itojun {
172 1.12 thorpej struct gif_softc *sc;
173 1.12 thorpej
174 1.98 knakahar sc = kmem_zalloc(sizeof(struct gif_softc), KM_SLEEP);
175 1.101 knakahar if (sc == NULL)
176 1.101 knakahar return ENOMEM;
177 1.2 itojun
178 1.75 christos if_initname(&sc->gif_if, ifc->ifc_name, unit);
179 1.9 itojun
180 1.31 itojun gifattach0(sc);
181 1.31 itojun
182 1.31 itojun LIST_INSERT_HEAD(&gif_softc_list, sc, gif_list);
183 1.31 itojun return (0);
184 1.31 itojun }
185 1.31 itojun
186 1.109 knakahar static void
187 1.56 thorpej gifattach0(struct gif_softc *sc)
188 1.31 itojun {
189 1.31 itojun
190 1.12 thorpej sc->encap_cookie4 = sc->encap_cookie6 = NULL;
191 1.9 itojun
192 1.31 itojun sc->gif_if.if_addrlen = 0;
193 1.12 thorpej sc->gif_if.if_mtu = GIF_MTU;
194 1.12 thorpej sc->gif_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
195 1.113 knakahar sc->gif_if.if_extflags = IFEF_NO_LINK_STATE_CHANGE;
196 1.12 thorpej sc->gif_if.if_ioctl = gif_ioctl;
197 1.12 thorpej sc->gif_if.if_output = gif_output;
198 1.12 thorpej sc->gif_if.if_type = IFT_GIF;
199 1.19 thorpej sc->gif_if.if_dlt = DLT_NULL;
200 1.76 dyoung sc->gif_if.if_softc = sc;
201 1.34 itojun IFQ_SET_READY(&sc->gif_if.if_snd);
202 1.112 knakahar if_initialize(&sc->gif_if);
203 1.112 knakahar if_register(&sc->gif_if);
204 1.20 thorpej if_alloc_sadl(&sc->gif_if);
205 1.78 joerg bpf_attach(&sc->gif_if, DLT_NULL, sizeof(u_int));
206 1.12 thorpej }
207 1.12 thorpej
208 1.56 thorpej static int
209 1.56 thorpej gif_clone_destroy(struct ifnet *ifp)
210 1.12 thorpej {
211 1.12 thorpej struct gif_softc *sc = (void *) ifp;
212 1.12 thorpej
213 1.12 thorpej LIST_REMOVE(sc, gif_list);
214 1.12 thorpej
215 1.94 knakahar gif_delete_tunnel(&sc->gif_if);
216 1.78 joerg bpf_detach(ifp);
217 1.69 dyoung if_detach(ifp);
218 1.66 dyoung rtcache_free(&sc->gif_ro);
219 1.12 thorpej
220 1.98 knakahar kmem_free(sc, sizeof(struct gif_softc));
221 1.47 peter
222 1.47 peter return (0);
223 1.9 itojun }
224 1.9 itojun
225 1.42 itojun #ifdef GIF_ENCAPCHECK
226 1.31 itojun int
227 1.56 thorpej gif_encapcheck(struct mbuf *m, int off, int proto, void *arg)
228 1.9 itojun {
229 1.9 itojun struct ip ip;
230 1.9 itojun struct gif_softc *sc;
231 1.9 itojun
232 1.76 dyoung sc = arg;
233 1.9 itojun if (sc == NULL)
234 1.9 itojun return 0;
235 1.9 itojun
236 1.114 knakahar if ((sc->gif_if.if_flags & (IFF_UP|IFF_RUNNING))
237 1.114 knakahar != (IFF_UP|IFF_RUNNING))
238 1.9 itojun return 0;
239 1.9 itojun
240 1.9 itojun /* no physical address */
241 1.9 itojun if (!sc->gif_psrc || !sc->gif_pdst)
242 1.9 itojun return 0;
243 1.9 itojun
244 1.9 itojun switch (proto) {
245 1.9 itojun #ifdef INET
246 1.9 itojun case IPPROTO_IPV4:
247 1.9 itojun break;
248 1.9 itojun #endif
249 1.9 itojun #ifdef INET6
250 1.9 itojun case IPPROTO_IPV6:
251 1.9 itojun break;
252 1.9 itojun #endif
253 1.9 itojun default:
254 1.9 itojun return 0;
255 1.9 itojun }
256 1.40 christos
257 1.40 christos /* Bail on short packets */
258 1.40 christos KASSERT(m->m_flags & M_PKTHDR);
259 1.40 christos if (m->m_pkthdr.len < sizeof(ip))
260 1.40 christos return 0;
261 1.9 itojun
262 1.76 dyoung m_copydata(m, 0, sizeof(ip), &ip);
263 1.9 itojun
264 1.9 itojun switch (ip.ip_v) {
265 1.9 itojun #ifdef INET
266 1.9 itojun case 4:
267 1.9 itojun if (sc->gif_psrc->sa_family != AF_INET ||
268 1.9 itojun sc->gif_pdst->sa_family != AF_INET)
269 1.9 itojun return 0;
270 1.9 itojun return gif_encapcheck4(m, off, proto, arg);
271 1.9 itojun #endif
272 1.9 itojun #ifdef INET6
273 1.9 itojun case 6:
274 1.41 itojun if (m->m_pkthdr.len < sizeof(struct ip6_hdr))
275 1.41 itojun return 0;
276 1.9 itojun if (sc->gif_psrc->sa_family != AF_INET6 ||
277 1.9 itojun sc->gif_pdst->sa_family != AF_INET6)
278 1.9 itojun return 0;
279 1.9 itojun return gif_encapcheck6(m, off, proto, arg);
280 1.9 itojun #endif
281 1.9 itojun default:
282 1.9 itojun return 0;
283 1.2 itojun }
284 1.2 itojun }
285 1.42 itojun #endif
286 1.2 itojun
287 1.95 knakahar /*
288 1.95 knakahar * gif may cause infinite recursion calls when misconfigured.
289 1.95 knakahar * We'll prevent this by introducing upper limit.
290 1.95 knakahar */
291 1.95 knakahar static int
292 1.95 knakahar gif_check_nesting(struct ifnet *ifp, struct mbuf *m)
293 1.95 knakahar {
294 1.95 knakahar struct m_tag *mtag;
295 1.95 knakahar int *count;
296 1.95 knakahar
297 1.95 knakahar mtag = m_tag_find(m, PACKET_TAG_TUNNEL_INFO, NULL);
298 1.95 knakahar if (mtag != NULL) {
299 1.95 knakahar count = (int *)(mtag + 1);
300 1.95 knakahar if (++(*count) > max_gif_nesting) {
301 1.95 knakahar log(LOG_NOTICE,
302 1.95 knakahar "%s: recursively called too many times(%d)\n",
303 1.95 knakahar if_name(ifp),
304 1.95 knakahar *count);
305 1.95 knakahar return EIO;
306 1.95 knakahar }
307 1.95 knakahar } else {
308 1.95 knakahar mtag = m_tag_get(PACKET_TAG_TUNNEL_INFO, sizeof(*count),
309 1.95 knakahar M_NOWAIT);
310 1.95 knakahar if (mtag != NULL) {
311 1.95 knakahar m_tag_prepend(m, mtag);
312 1.95 knakahar count = (int *)(mtag + 1);
313 1.95 knakahar *count = 0;
314 1.95 knakahar } else {
315 1.95 knakahar log(LOG_DEBUG,
316 1.95 knakahar "%s: m_tag_get() failed, recursion calls are not prevented.\n",
317 1.95 knakahar if_name(ifp));
318 1.95 knakahar }
319 1.95 knakahar }
320 1.95 knakahar
321 1.95 knakahar return 0;
322 1.95 knakahar }
323 1.95 knakahar
324 1.109 knakahar static int
325 1.65 dyoung gif_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
326 1.108 ozaki const struct rtentry *rt)
327 1.2 itojun {
328 1.76 dyoung struct gif_softc *sc = ifp->if_softc;
329 1.2 itojun int error = 0;
330 1.118 knakahar #ifndef GIF_MPSAFE
331 1.33 itojun int s;
332 1.118 knakahar #endif
333 1.33 itojun
334 1.107 knakahar IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family);
335 1.2 itojun
336 1.95 knakahar if ((error = gif_check_nesting(ifp, m)) != 0) {
337 1.95 knakahar m_free(m);
338 1.2 itojun goto end;
339 1.2 itojun }
340 1.2 itojun
341 1.2 itojun m->m_flags &= ~(M_BCAST|M_MCAST);
342 1.114 knakahar if (((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) ||
343 1.111 knakahar sc->gif_psrc == NULL || sc->gif_pdst == NULL) {
344 1.2 itojun m_freem(m);
345 1.2 itojun error = ENETDOWN;
346 1.2 itojun goto end;
347 1.2 itojun }
348 1.2 itojun
349 1.9 itojun /* XXX should we check if our outer source is legal? */
350 1.2 itojun
351 1.33 itojun /* use DLT_NULL encapsulation here to pass inner af type */
352 1.33 itojun M_PREPEND(m, sizeof(int), M_DONTWAIT);
353 1.33 itojun if (!m) {
354 1.33 itojun error = ENOBUFS;
355 1.33 itojun goto end;
356 1.33 itojun }
357 1.33 itojun *mtod(m, int *) = dst->sa_family;
358 1.33 itojun
359 1.79 dyoung /* Clear checksum-offload flags. */
360 1.79 dyoung m->m_pkthdr.csum_flags = 0;
361 1.79 dyoung m->m_pkthdr.csum_data = 0;
362 1.79 dyoung
363 1.118 knakahar #ifndef GIF_MPSAFE
364 1.33 itojun s = splnet();
365 1.118 knakahar #endif
366 1.107 knakahar IFQ_ENQUEUE(&ifp->if_snd, m, error);
367 1.33 itojun if (error) {
368 1.118 knakahar #ifndef GIF_MPSAFE
369 1.33 itojun splx(s);
370 1.118 knakahar #endif
371 1.31 itojun goto end;
372 1.2 itojun }
373 1.118 knakahar #ifndef GIF_MPSAFE
374 1.111 knakahar splx(s);
375 1.118 knakahar #endif
376 1.102 knakahar
377 1.111 knakahar gif_start(ifp);
378 1.33 itojun
379 1.33 itojun error = 0;
380 1.2 itojun
381 1.2 itojun end:
382 1.31 itojun if (error)
383 1.31 itojun ifp->if_oerrors++;
384 1.2 itojun return error;
385 1.2 itojun }
386 1.2 itojun
387 1.56 thorpej static void
388 1.111 knakahar gif_start(struct ifnet *ifp)
389 1.33 itojun {
390 1.33 itojun struct gif_softc *sc;
391 1.33 itojun struct mbuf *m;
392 1.33 itojun int family;
393 1.33 itojun int len;
394 1.118 knakahar #ifndef GIF_MPSAFE
395 1.33 itojun int s;
396 1.118 knakahar #endif
397 1.33 itojun int error;
398 1.33 itojun
399 1.111 knakahar sc = ifp->if_softc;
400 1.102 knakahar
401 1.33 itojun /* output processing */
402 1.33 itojun while (1) {
403 1.118 knakahar #ifndef GIF_MPSAFE
404 1.33 itojun s = splnet();
405 1.118 knakahar #endif
406 1.34 itojun IFQ_DEQUEUE(&sc->gif_if.if_snd, m);
407 1.118 knakahar #ifndef GIF_MPSAFE
408 1.33 itojun splx(s);
409 1.118 knakahar #endif
410 1.33 itojun if (m == NULL)
411 1.33 itojun break;
412 1.33 itojun
413 1.33 itojun /* grab and chop off inner af type */
414 1.33 itojun if (sizeof(int) > m->m_len) {
415 1.33 itojun m = m_pullup(m, sizeof(int));
416 1.33 itojun if (!m) {
417 1.33 itojun ifp->if_oerrors++;
418 1.33 itojun continue;
419 1.33 itojun }
420 1.33 itojun }
421 1.33 itojun family = *mtod(m, int *);
422 1.78 joerg bpf_mtap(ifp, m);
423 1.33 itojun m_adj(m, sizeof(int));
424 1.33 itojun
425 1.33 itojun len = m->m_pkthdr.len;
426 1.33 itojun
427 1.33 itojun /* dispatch to output logic based on outer AF */
428 1.33 itojun switch (sc->gif_psrc->sa_family) {
429 1.33 itojun #ifdef INET
430 1.33 itojun case AF_INET:
431 1.111 knakahar /* XXX
432 1.111 knakahar * To add mutex_enter(softnet_lock) or
433 1.111 knakahar * KASSERT(mutex_owned(softnet_lock)) here, we shold
434 1.111 knakahar * coordinate softnet_lock between in6_if_up() and
435 1.111 knakahar * in6_purgeif().
436 1.111 knakahar */
437 1.33 itojun error = in_gif_output(ifp, family, m);
438 1.33 itojun break;
439 1.33 itojun #endif
440 1.33 itojun #ifdef INET6
441 1.33 itojun case AF_INET6:
442 1.111 knakahar /* XXX
443 1.111 knakahar * the same as in_gif_output()
444 1.111 knakahar */
445 1.33 itojun error = in6_gif_output(ifp, family, m);
446 1.33 itojun break;
447 1.33 itojun #endif
448 1.33 itojun default:
449 1.50 perry m_freem(m);
450 1.33 itojun error = ENETDOWN;
451 1.33 itojun break;
452 1.33 itojun }
453 1.33 itojun
454 1.33 itojun if (error)
455 1.33 itojun ifp->if_oerrors++;
456 1.33 itojun else {
457 1.50 perry ifp->if_opackets++;
458 1.33 itojun ifp->if_obytes += len;
459 1.33 itojun }
460 1.33 itojun }
461 1.33 itojun }
462 1.33 itojun
463 1.33 itojun void
464 1.56 thorpej gif_input(struct mbuf *m, int af, struct ifnet *ifp)
465 1.2 itojun {
466 1.83 rmind pktqueue_t *pktq;
467 1.83 rmind size_t pktlen;
468 1.118 knakahar #ifndef GIF_MPSAFE
469 1.83 rmind int s;
470 1.118 knakahar #endif
471 1.2 itojun
472 1.33 itojun if (ifp == NULL) {
473 1.2 itojun /* just in case */
474 1.2 itojun m_freem(m);
475 1.2 itojun return;
476 1.2 itojun }
477 1.2 itojun
478 1.110 ozaki m_set_rcvif(m, ifp);
479 1.83 rmind pktlen = m->m_pkthdr.len;
480 1.50 perry
481 1.78 joerg bpf_mtap_af(ifp, af, m);
482 1.2 itojun
483 1.2 itojun /*
484 1.2 itojun * Put the packet to the network layer input queue according to the
485 1.83 rmind * specified address family. Note: we avoid direct call to the
486 1.83 rmind * input function of the network layer in order to avoid recursion.
487 1.83 rmind * This may be revisited in the future.
488 1.2 itojun */
489 1.2 itojun switch (af) {
490 1.2 itojun #ifdef INET
491 1.2 itojun case AF_INET:
492 1.83 rmind pktq = ip_pktq;
493 1.2 itojun break;
494 1.2 itojun #endif
495 1.2 itojun #ifdef INET6
496 1.2 itojun case AF_INET6:
497 1.83 rmind pktq = ip6_pktq;
498 1.2 itojun break;
499 1.2 itojun #endif
500 1.2 itojun default:
501 1.2 itojun m_freem(m);
502 1.2 itojun return;
503 1.2 itojun }
504 1.2 itojun
505 1.118 knakahar #ifndef GIF_MPSAFE
506 1.27 thorpej s = splnet();
507 1.118 knakahar #endif
508 1.83 rmind if (__predict_true(pktq_enqueue(pktq, m, 0))) {
509 1.83 rmind ifp->if_ibytes += pktlen;
510 1.83 rmind ifp->if_ipackets++;
511 1.83 rmind } else {
512 1.2 itojun m_freem(m);
513 1.2 itojun }
514 1.118 knakahar #ifndef GIF_MPSAFE
515 1.2 itojun splx(s);
516 1.118 knakahar #endif
517 1.2 itojun }
518 1.2 itojun
519 1.9 itojun /* XXX how should we handle IPv6 scope on SIOC[GS]IFPHYADDR? */
520 1.109 knakahar static int
521 1.67 christos gif_ioctl(struct ifnet *ifp, u_long cmd, void *data)
522 1.2 itojun {
523 1.76 dyoung struct gif_softc *sc = ifp->if_softc;
524 1.2 itojun struct ifreq *ifr = (struct ifreq*)data;
525 1.84 roy struct ifaddr *ifa = (struct ifaddr*)data;
526 1.2 itojun int error = 0, size;
527 1.9 itojun struct sockaddr *dst, *src;
528 1.31 itojun
529 1.2 itojun switch (cmd) {
530 1.76 dyoung case SIOCINITIFADDR:
531 1.32 itojun ifp->if_flags |= IFF_UP;
532 1.84 roy ifa->ifa_rtrequest = p2p_rtrequest;
533 1.2 itojun break;
534 1.50 perry
535 1.2 itojun case SIOCADDMULTI:
536 1.2 itojun case SIOCDELMULTI:
537 1.2 itojun switch (ifr->ifr_addr.sa_family) {
538 1.2 itojun #ifdef INET
539 1.2 itojun case AF_INET: /* IP supports Multicast */
540 1.2 itojun break;
541 1.2 itojun #endif /* INET */
542 1.2 itojun #ifdef INET6
543 1.2 itojun case AF_INET6: /* IP6 supports Multicast */
544 1.2 itojun break;
545 1.2 itojun #endif /* INET6 */
546 1.2 itojun default: /* Other protocols doesn't support Multicast */
547 1.2 itojun error = EAFNOSUPPORT;
548 1.2 itojun break;
549 1.2 itojun }
550 1.2 itojun break;
551 1.2 itojun
552 1.2 itojun case SIOCSIFMTU:
553 1.73 dyoung if (ifr->ifr_mtu < GIF_MTU_MIN || ifr->ifr_mtu > GIF_MTU_MAX)
554 1.73 dyoung return EINVAL;
555 1.73 dyoung else if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET)
556 1.73 dyoung error = 0;
557 1.2 itojun break;
558 1.2 itojun
559 1.31 itojun #ifdef INET
560 1.2 itojun case SIOCSIFPHYADDR:
561 1.31 itojun #endif
562 1.2 itojun #ifdef INET6
563 1.2 itojun case SIOCSIFPHYADDR_IN6:
564 1.2 itojun #endif /* INET6 */
565 1.25 itojun case SIOCSLIFPHYADDR:
566 1.11 itojun switch (cmd) {
567 1.15 itojun #ifdef INET
568 1.11 itojun case SIOCSIFPHYADDR:
569 1.11 itojun src = (struct sockaddr *)
570 1.11 itojun &(((struct in_aliasreq *)data)->ifra_addr);
571 1.11 itojun dst = (struct sockaddr *)
572 1.11 itojun &(((struct in_aliasreq *)data)->ifra_dstaddr);
573 1.11 itojun break;
574 1.15 itojun #endif
575 1.11 itojun #ifdef INET6
576 1.11 itojun case SIOCSIFPHYADDR_IN6:
577 1.11 itojun src = (struct sockaddr *)
578 1.11 itojun &(((struct in6_aliasreq *)data)->ifra_addr);
579 1.11 itojun dst = (struct sockaddr *)
580 1.11 itojun &(((struct in6_aliasreq *)data)->ifra_dstaddr);
581 1.25 itojun break;
582 1.25 itojun #endif
583 1.25 itojun case SIOCSLIFPHYADDR:
584 1.25 itojun src = (struct sockaddr *)
585 1.25 itojun &(((struct if_laddrreq *)data)->addr);
586 1.25 itojun dst = (struct sockaddr *)
587 1.25 itojun &(((struct if_laddrreq *)data)->dstaddr);
588 1.31 itojun break;
589 1.31 itojun default:
590 1.31 itojun return EINVAL;
591 1.25 itojun }
592 1.25 itojun
593 1.25 itojun /* sa_family must be equal */
594 1.25 itojun if (src->sa_family != dst->sa_family)
595 1.25 itojun return EINVAL;
596 1.25 itojun
597 1.25 itojun /* validate sa_len */
598 1.25 itojun switch (src->sa_family) {
599 1.25 itojun #ifdef INET
600 1.25 itojun case AF_INET:
601 1.25 itojun if (src->sa_len != sizeof(struct sockaddr_in))
602 1.16 itojun return EINVAL;
603 1.11 itojun break;
604 1.11 itojun #endif
605 1.25 itojun #ifdef INET6
606 1.25 itojun case AF_INET6:
607 1.25 itojun if (src->sa_len != sizeof(struct sockaddr_in6))
608 1.25 itojun return EINVAL;
609 1.25 itojun break;
610 1.25 itojun #endif
611 1.25 itojun default:
612 1.25 itojun return EAFNOSUPPORT;
613 1.25 itojun }
614 1.25 itojun switch (dst->sa_family) {
615 1.25 itojun #ifdef INET
616 1.25 itojun case AF_INET:
617 1.25 itojun if (dst->sa_len != sizeof(struct sockaddr_in))
618 1.25 itojun return EINVAL;
619 1.25 itojun break;
620 1.25 itojun #endif
621 1.25 itojun #ifdef INET6
622 1.25 itojun case AF_INET6:
623 1.25 itojun if (dst->sa_len != sizeof(struct sockaddr_in6))
624 1.25 itojun return EINVAL;
625 1.25 itojun break;
626 1.25 itojun #endif
627 1.25 itojun default:
628 1.25 itojun return EAFNOSUPPORT;
629 1.25 itojun }
630 1.25 itojun
631 1.25 itojun /* check sa_family looks sane for the cmd */
632 1.25 itojun switch (cmd) {
633 1.25 itojun case SIOCSIFPHYADDR:
634 1.25 itojun if (src->sa_family == AF_INET)
635 1.25 itojun break;
636 1.25 itojun return EAFNOSUPPORT;
637 1.25 itojun #ifdef INET6
638 1.25 itojun case SIOCSIFPHYADDR_IN6:
639 1.25 itojun if (src->sa_family == AF_INET6)
640 1.25 itojun break;
641 1.25 itojun return EAFNOSUPPORT;
642 1.25 itojun #endif /* INET6 */
643 1.25 itojun case SIOCSLIFPHYADDR:
644 1.25 itojun /* checks done in the above */
645 1.25 itojun break;
646 1.11 itojun }
647 1.11 itojun
648 1.31 itojun error = gif_set_tunnel(&sc->gif_if, src, dst);
649 1.9 itojun break;
650 1.9 itojun
651 1.9 itojun #ifdef SIOCDIFPHYADDR
652 1.9 itojun case SIOCDIFPHYADDR:
653 1.31 itojun gif_delete_tunnel(&sc->gif_if);
654 1.2 itojun break;
655 1.9 itojun #endif
656 1.50 perry
657 1.2 itojun case SIOCGIFPSRCADDR:
658 1.2 itojun #ifdef INET6
659 1.2 itojun case SIOCGIFPSRCADDR_IN6:
660 1.2 itojun #endif /* INET6 */
661 1.2 itojun if (sc->gif_psrc == NULL) {
662 1.2 itojun error = EADDRNOTAVAIL;
663 1.2 itojun goto bad;
664 1.2 itojun }
665 1.2 itojun src = sc->gif_psrc;
666 1.16 itojun switch (cmd) {
667 1.2 itojun #ifdef INET
668 1.16 itojun case SIOCGIFPSRCADDR:
669 1.2 itojun dst = &ifr->ifr_addr;
670 1.16 itojun size = sizeof(ifr->ifr_addr);
671 1.2 itojun break;
672 1.2 itojun #endif /* INET */
673 1.2 itojun #ifdef INET6
674 1.16 itojun case SIOCGIFPSRCADDR_IN6:
675 1.2 itojun dst = (struct sockaddr *)
676 1.2 itojun &(((struct in6_ifreq *)data)->ifr_addr);
677 1.16 itojun size = sizeof(((struct in6_ifreq *)data)->ifr_addr);
678 1.2 itojun break;
679 1.2 itojun #endif /* INET6 */
680 1.2 itojun default:
681 1.2 itojun error = EADDRNOTAVAIL;
682 1.2 itojun goto bad;
683 1.2 itojun }
684 1.16 itojun if (src->sa_len > size)
685 1.16 itojun return EINVAL;
686 1.68 dyoung memcpy(dst, src, src->sa_len);
687 1.2 itojun break;
688 1.50 perry
689 1.2 itojun case SIOCGIFPDSTADDR:
690 1.2 itojun #ifdef INET6
691 1.2 itojun case SIOCGIFPDSTADDR_IN6:
692 1.2 itojun #endif /* INET6 */
693 1.2 itojun if (sc->gif_pdst == NULL) {
694 1.2 itojun error = EADDRNOTAVAIL;
695 1.2 itojun goto bad;
696 1.2 itojun }
697 1.2 itojun src = sc->gif_pdst;
698 1.16 itojun switch (cmd) {
699 1.2 itojun #ifdef INET
700 1.16 itojun case SIOCGIFPDSTADDR:
701 1.2 itojun dst = &ifr->ifr_addr;
702 1.16 itojun size = sizeof(ifr->ifr_addr);
703 1.2 itojun break;
704 1.2 itojun #endif /* INET */
705 1.2 itojun #ifdef INET6
706 1.16 itojun case SIOCGIFPDSTADDR_IN6:
707 1.2 itojun dst = (struct sockaddr *)
708 1.2 itojun &(((struct in6_ifreq *)data)->ifr_addr);
709 1.16 itojun size = sizeof(((struct in6_ifreq *)data)->ifr_addr);
710 1.2 itojun break;
711 1.2 itojun #endif /* INET6 */
712 1.2 itojun default:
713 1.2 itojun error = EADDRNOTAVAIL;
714 1.2 itojun goto bad;
715 1.2 itojun }
716 1.25 itojun if (src->sa_len > size)
717 1.25 itojun return EINVAL;
718 1.68 dyoung memcpy(dst, src, src->sa_len);
719 1.25 itojun break;
720 1.25 itojun
721 1.25 itojun case SIOCGLIFPHYADDR:
722 1.25 itojun if (sc->gif_psrc == NULL || sc->gif_pdst == NULL) {
723 1.25 itojun error = EADDRNOTAVAIL;
724 1.25 itojun goto bad;
725 1.25 itojun }
726 1.25 itojun
727 1.25 itojun /* copy src */
728 1.25 itojun src = sc->gif_psrc;
729 1.25 itojun dst = (struct sockaddr *)
730 1.25 itojun &(((struct if_laddrreq *)data)->addr);
731 1.25 itojun size = sizeof(((struct if_laddrreq *)data)->addr);
732 1.25 itojun if (src->sa_len > size)
733 1.25 itojun return EINVAL;
734 1.68 dyoung memcpy(dst, src, src->sa_len);
735 1.25 itojun
736 1.25 itojun /* copy dst */
737 1.25 itojun src = sc->gif_pdst;
738 1.25 itojun dst = (struct sockaddr *)
739 1.25 itojun &(((struct if_laddrreq *)data)->dstaddr);
740 1.25 itojun size = sizeof(((struct if_laddrreq *)data)->dstaddr);
741 1.16 itojun if (src->sa_len > size)
742 1.16 itojun return EINVAL;
743 1.68 dyoung memcpy(dst, src, src->sa_len);
744 1.2 itojun break;
745 1.2 itojun
746 1.2 itojun default:
747 1.76 dyoung return ifioctl_common(ifp, cmd, data);
748 1.2 itojun }
749 1.2 itojun bad:
750 1.2 itojun return error;
751 1.12 thorpej }
752 1.12 thorpej
753 1.97 knakahar static int
754 1.97 knakahar gif_encap_attach(struct gif_softc *sc)
755 1.97 knakahar {
756 1.97 knakahar int error;
757 1.97 knakahar
758 1.97 knakahar if (sc == NULL || sc->gif_psrc == NULL)
759 1.97 knakahar return EINVAL;
760 1.97 knakahar
761 1.97 knakahar switch (sc->gif_psrc->sa_family) {
762 1.97 knakahar #ifdef INET
763 1.97 knakahar case AF_INET:
764 1.97 knakahar error = in_gif_attach(sc);
765 1.97 knakahar break;
766 1.97 knakahar #endif
767 1.97 knakahar #ifdef INET6
768 1.97 knakahar case AF_INET6:
769 1.97 knakahar error = in6_gif_attach(sc);
770 1.97 knakahar break;
771 1.97 knakahar #endif
772 1.97 knakahar default:
773 1.97 knakahar error = EINVAL;
774 1.97 knakahar break;
775 1.97 knakahar }
776 1.97 knakahar
777 1.97 knakahar return error;
778 1.97 knakahar }
779 1.97 knakahar
780 1.97 knakahar static int
781 1.97 knakahar gif_encap_detach(struct gif_softc *sc)
782 1.97 knakahar {
783 1.97 knakahar int error;
784 1.97 knakahar
785 1.97 knakahar if (sc == NULL || sc->gif_psrc == NULL)
786 1.97 knakahar return EINVAL;
787 1.97 knakahar
788 1.97 knakahar switch (sc->gif_psrc->sa_family) {
789 1.97 knakahar #ifdef INET
790 1.97 knakahar case AF_INET:
791 1.97 knakahar error = in_gif_detach(sc);
792 1.97 knakahar break;
793 1.97 knakahar #endif
794 1.97 knakahar #ifdef INET6
795 1.97 knakahar case AF_INET6:
796 1.97 knakahar error = in6_gif_detach(sc);
797 1.97 knakahar break;
798 1.97 knakahar #endif
799 1.97 knakahar default:
800 1.97 knakahar error = EINVAL;
801 1.97 knakahar break;
802 1.97 knakahar }
803 1.97 knakahar
804 1.97 knakahar return error;
805 1.97 knakahar }
806 1.97 knakahar
807 1.114 knakahar static void
808 1.114 knakahar gif_encap_pause(struct gif_softc *sc)
809 1.114 knakahar {
810 1.116 knakahar struct ifnet *ifp;
811 1.114 knakahar uint64_t where;
812 1.114 knakahar
813 1.116 knakahar if (sc == NULL || sc->gif_psrc == NULL)
814 1.116 knakahar return;
815 1.116 knakahar
816 1.116 knakahar ifp = &sc->gif_if;
817 1.116 knakahar if ((ifp->if_flags & IFF_RUNNING) == 0)
818 1.116 knakahar return;
819 1.116 knakahar
820 1.116 knakahar switch (sc->gif_psrc->sa_family) {
821 1.116 knakahar #ifdef INET
822 1.116 knakahar case AF_INET:
823 1.116 knakahar (void)in_gif_pause(sc);
824 1.116 knakahar break;
825 1.116 knakahar #endif
826 1.116 knakahar #ifdef INET6
827 1.116 knakahar case AF_INET6:
828 1.116 knakahar (void)in6_gif_pause(sc);
829 1.116 knakahar break;
830 1.116 knakahar #endif
831 1.116 knakahar }
832 1.116 knakahar
833 1.114 knakahar ifp->if_flags &= ~IFF_RUNNING;
834 1.114 knakahar /* membar_sync() is done in xc_broadcast(). */
835 1.114 knakahar
836 1.114 knakahar /*
837 1.114 knakahar * Wait for softint_execute()(ipintr() or ip6intr())
838 1.114 knakahar * completion done by other CPUs which already run over if_flags
839 1.114 knakahar * check in in_gif_input() or in6_gif_input().
840 1.114 knakahar * Furthermore, wait for gif_output() completion too.
841 1.114 knakahar */
842 1.114 knakahar where = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL);
843 1.114 knakahar xc_wait(where);
844 1.114 knakahar }
845 1.114 knakahar
846 1.109 knakahar static int
847 1.56 thorpej gif_set_tunnel(struct ifnet *ifp, struct sockaddr *src, struct sockaddr *dst)
848 1.31 itojun {
849 1.76 dyoung struct gif_softc *sc = ifp->if_softc;
850 1.31 itojun struct gif_softc *sc2;
851 1.71 dyoung struct sockaddr *osrc, *odst;
852 1.96 knakahar struct sockaddr *nsrc, *ndst;
853 1.118 knakahar int error;
854 1.118 knakahar #ifndef GIF_MPSAFE
855 1.31 itojun int s;
856 1.31 itojun
857 1.31 itojun s = splsoftnet();
858 1.118 knakahar #endif
859 1.117 knakahar error = encap_lock_enter();
860 1.117 knakahar if (error) {
861 1.118 knakahar #ifndef GIF_MPSAFE
862 1.117 knakahar splx(s);
863 1.118 knakahar #endif
864 1.117 knakahar return error;
865 1.117 knakahar }
866 1.31 itojun
867 1.68 dyoung LIST_FOREACH(sc2, &gif_softc_list, gif_list) {
868 1.31 itojun if (sc2 == sc)
869 1.31 itojun continue;
870 1.31 itojun if (!sc2->gif_pdst || !sc2->gif_psrc)
871 1.31 itojun continue;
872 1.31 itojun /* can't configure same pair of address onto two gifs */
873 1.71 dyoung if (sockaddr_cmp(sc2->gif_pdst, dst) == 0 &&
874 1.71 dyoung sockaddr_cmp(sc2->gif_psrc, src) == 0) {
875 1.91 knakahar /* continue to use the old configureation. */
876 1.118 knakahar error = EADDRNOTAVAIL;
877 1.118 knakahar goto out;
878 1.31 itojun }
879 1.31 itojun
880 1.31 itojun /* XXX both end must be valid? (I mean, not 0.0.0.0) */
881 1.31 itojun }
882 1.31 itojun
883 1.96 knakahar if ((nsrc = sockaddr_dup(src, M_WAITOK)) == NULL) {
884 1.118 knakahar error = ENOMEM;
885 1.118 knakahar goto out;
886 1.96 knakahar }
887 1.96 knakahar if ((ndst = sockaddr_dup(dst, M_WAITOK)) == NULL) {
888 1.96 knakahar sockaddr_free(nsrc);
889 1.118 knakahar error = ENOMEM;
890 1.118 knakahar goto out;
891 1.96 knakahar }
892 1.96 knakahar
893 1.114 knakahar gif_encap_pause(sc);
894 1.114 knakahar
895 1.96 knakahar /* Firstly, clear old configurations. */
896 1.31 itojun /* XXX we can detach from both, but be polite just in case */
897 1.31 itojun if (sc->gif_psrc)
898 1.97 knakahar (void)gif_encap_detach(sc);
899 1.31 itojun
900 1.96 knakahar /*
901 1.96 knakahar * Secondly, try to set new configurations.
902 1.96 knakahar * If the setup failed, rollback to old configurations.
903 1.96 knakahar */
904 1.96 knakahar do {
905 1.96 knakahar osrc = sc->gif_psrc;
906 1.96 knakahar odst = sc->gif_pdst;
907 1.96 knakahar sc->gif_psrc = nsrc;
908 1.96 knakahar sc->gif_pdst = ndst;
909 1.33 itojun
910 1.97 knakahar error = gif_encap_attach(sc);
911 1.96 knakahar if (error) {
912 1.96 knakahar /* rollback to the last configuration. */
913 1.96 knakahar nsrc = osrc;
914 1.96 knakahar ndst = odst;
915 1.96 knakahar osrc = sc->gif_psrc;
916 1.96 knakahar odst = sc->gif_pdst;
917 1.31 itojun
918 1.96 knakahar continue;
919 1.96 knakahar }
920 1.96 knakahar } while (error != 0 && (nsrc != NULL && ndst != NULL));
921 1.96 knakahar /* Thirdly, even rollback failed, clear configurations. */
922 1.96 knakahar if (error) {
923 1.96 knakahar osrc = sc->gif_psrc;
924 1.96 knakahar odst = sc->gif_pdst;
925 1.96 knakahar sc->gif_psrc = NULL;
926 1.96 knakahar sc->gif_pdst = NULL;
927 1.31 itojun }
928 1.31 itojun
929 1.31 itojun if (osrc)
930 1.71 dyoung sockaddr_free(osrc);
931 1.31 itojun if (odst)
932 1.71 dyoung sockaddr_free(odst);
933 1.31 itojun
934 1.31 itojun if (sc->gif_psrc && sc->gif_pdst)
935 1.31 itojun ifp->if_flags |= IFF_RUNNING;
936 1.31 itojun else
937 1.31 itojun ifp->if_flags &= ~IFF_RUNNING;
938 1.92 knakahar
939 1.118 knakahar out:
940 1.115 knakahar encap_lock_exit();
941 1.118 knakahar #ifndef GIF_MPSAFE
942 1.31 itojun splx(s);
943 1.118 knakahar #endif
944 1.31 itojun return error;
945 1.31 itojun }
946 1.31 itojun
947 1.109 knakahar static void
948 1.56 thorpej gif_delete_tunnel(struct ifnet *ifp)
949 1.12 thorpej {
950 1.76 dyoung struct gif_softc *sc = ifp->if_softc;
951 1.118 knakahar int error;
952 1.118 knakahar #ifndef GIF_MPSAFE
953 1.12 thorpej int s;
954 1.12 thorpej
955 1.12 thorpej s = splsoftnet();
956 1.118 knakahar #endif
957 1.117 knakahar error = encap_lock_enter();
958 1.117 knakahar if (error) {
959 1.118 knakahar #ifndef GIF_MPSAFE
960 1.117 knakahar splx(s);
961 1.118 knakahar #endif
962 1.117 knakahar return;
963 1.117 knakahar }
964 1.12 thorpej
965 1.114 knakahar gif_encap_pause(sc);
966 1.12 thorpej if (sc->gif_psrc) {
967 1.71 dyoung sockaddr_free(sc->gif_psrc);
968 1.12 thorpej sc->gif_psrc = NULL;
969 1.12 thorpej }
970 1.12 thorpej if (sc->gif_pdst) {
971 1.71 dyoung sockaddr_free(sc->gif_pdst);
972 1.12 thorpej sc->gif_pdst = NULL;
973 1.12 thorpej }
974 1.31 itojun /* it is safe to detach from both */
975 1.31 itojun #ifdef INET
976 1.31 itojun (void)in_gif_detach(sc);
977 1.31 itojun #endif
978 1.31 itojun #ifdef INET6
979 1.31 itojun (void)in6_gif_detach(sc);
980 1.31 itojun #endif
981 1.12 thorpej
982 1.31 itojun if (sc->gif_psrc && sc->gif_pdst)
983 1.31 itojun ifp->if_flags |= IFF_RUNNING;
984 1.31 itojun else
985 1.31 itojun ifp->if_flags &= ~IFF_RUNNING;
986 1.114 knakahar
987 1.115 knakahar encap_lock_exit();
988 1.118 knakahar #ifndef GIF_MPSAFE
989 1.12 thorpej splx(s);
990 1.118 knakahar #endif
991 1.2 itojun }
992