1 | /*- |
---|
2 | * Copyright (c) 2009 Hiroki Sato. All rights reserved. |
---|
3 | * |
---|
4 | * Redistribution and use in source and binary forms, with or without |
---|
5 | * modification, are permitted provided that the following conditions |
---|
6 | * are met: |
---|
7 | * 1. Redistributions of source code must retain the above copyright |
---|
8 | * notice, this list of conditions and the following disclaimer. |
---|
9 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer in the |
---|
11 | * documentation and/or other materials provided with the distribution. |
---|
12 | * |
---|
13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
---|
14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
---|
15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
---|
16 | * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, |
---|
17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
---|
19 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
---|
21 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
---|
22 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef lint |
---|
27 | static const char rcsid[] = |
---|
28 | "$FreeBSD$"; |
---|
29 | #endif |
---|
30 | |
---|
31 | #include <sys/param.h> |
---|
32 | #include <sys/ioctl.h> |
---|
33 | #include <sys/socket.h> |
---|
34 | #include <sys/sockio.h> |
---|
35 | |
---|
36 | #include <stdlib.h> |
---|
37 | #include <unistd.h> |
---|
38 | |
---|
39 | #include <net/ethernet.h> |
---|
40 | #include <net/if.h> |
---|
41 | #ifdef __rtems__ |
---|
42 | #include <freebsd/net/if_gif.h> |
---|
43 | #else |
---|
44 | #include <net/if_gif.h> |
---|
45 | #endif |
---|
46 | #include <net/route.h> |
---|
47 | |
---|
48 | #include <ctype.h> |
---|
49 | #include <stdio.h> |
---|
50 | #include <string.h> |
---|
51 | #include <stdlib.h> |
---|
52 | #include <unistd.h> |
---|
53 | #include <err.h> |
---|
54 | #include <errno.h> |
---|
55 | |
---|
56 | #include "ifconfig.h" |
---|
57 | |
---|
58 | static void gif_status(int); |
---|
59 | |
---|
60 | static struct { |
---|
61 | const char *label; |
---|
62 | u_int mask; |
---|
63 | } gif_opts[] = { |
---|
64 | { "ACCEPT_REV_ETHIP_VER", GIF_ACCEPT_REVETHIP }, |
---|
65 | { "SEND_REV_ETHIP_VER", GIF_SEND_REVETHIP }, |
---|
66 | }; |
---|
67 | |
---|
68 | static void |
---|
69 | gif_status(int s) |
---|
70 | { |
---|
71 | int opts; |
---|
72 | int nopts = 0; |
---|
73 | size_t i; |
---|
74 | |
---|
75 | ifr.ifr_data = (caddr_t)&opts; |
---|
76 | if (ioctl(s, GIFGOPTS, &ifr) == -1) |
---|
77 | return; |
---|
78 | if (opts == 0) |
---|
79 | return; |
---|
80 | |
---|
81 | printf("\toptions=%d<", opts); |
---|
82 | for (i=0; i < sizeof(gif_opts)/sizeof(gif_opts[0]); i++) { |
---|
83 | if (opts & gif_opts[i].mask) { |
---|
84 | if (nopts++) |
---|
85 | printf(","); |
---|
86 | printf("%s", gif_opts[i].label); |
---|
87 | } |
---|
88 | } |
---|
89 | printf(">\n"); |
---|
90 | } |
---|
91 | |
---|
92 | static void |
---|
93 | setgifopts(const char *val, |
---|
94 | int d, int s, const struct afswtch *afp) |
---|
95 | { |
---|
96 | int opts; |
---|
97 | |
---|
98 | ifr.ifr_data = (caddr_t)&opts; |
---|
99 | if (ioctl(s, GIFGOPTS, &ifr) == -1) { |
---|
100 | warn("ioctl(GIFGOPTS)"); |
---|
101 | return; |
---|
102 | } |
---|
103 | |
---|
104 | if (d < 0) |
---|
105 | opts &= ~(-d); |
---|
106 | else |
---|
107 | opts |= d; |
---|
108 | |
---|
109 | if (ioctl(s, GIFSOPTS, &ifr) == -1) { |
---|
110 | warn("ioctl(GIFSOPTS)"); |
---|
111 | return; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | static struct cmd gif_cmds[] = { |
---|
116 | DEF_CMD("accept_rev_ethip_ver", GIF_ACCEPT_REVETHIP, setgifopts), |
---|
117 | DEF_CMD("-accept_rev_ethip_ver",-GIF_ACCEPT_REVETHIP, setgifopts), |
---|
118 | DEF_CMD("send_rev_ethip_ver", GIF_SEND_REVETHIP, setgifopts), |
---|
119 | DEF_CMD("-send_rev_ethip_ver", -GIF_SEND_REVETHIP, setgifopts), |
---|
120 | }; |
---|
121 | |
---|
122 | static struct afswtch af_gif = { |
---|
123 | .af_name = "af_gif", |
---|
124 | .af_af = AF_UNSPEC, |
---|
125 | .af_other_status = gif_status, |
---|
126 | }; |
---|
127 | |
---|
128 | static __constructor void |
---|
129 | gif_ctor(void) |
---|
130 | { |
---|
131 | #define N(a) (sizeof(a) / sizeof(a[0])) |
---|
132 | size_t i; |
---|
133 | |
---|
134 | for (i = 0; i < N(gif_cmds); i++) |
---|
135 | cmd_register(&gif_cmds[i]); |
---|
136 | af_register(&af_gif); |
---|
137 | #undef N |
---|
138 | } |
---|