2 * Copyright (c) 2008 Andrew Thompson. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
30 #include <sys/ioctl.h>
31 #include <sys/socket.h>
32 #include <sys/sockio.h>
34 #include <net/if_gre.h>
45 #define GREBITS "\020\01ENABLE_CSUM\02ENABLE_SEQ"
47 static void gre_status(int s);
54 ifr.ifr_data = (caddr_t)&opts;
55 if (ioctl(s, GREGKEY, &ifr) == 0)
57 printf("\tgrekey: 0x%x (%u)\n", opts, opts);
59 if (ioctl(s, GREGOPTS, &ifr) != 0 || opts == 0)
61 printb("\toptions", opts, GREBITS);
66 setifgrekey(const char *val, int dummy __unused, int s,
67 const struct afswtch *afp)
69 uint32_t grekey = strtol(val, NULL, 0);
71 strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
72 ifr.ifr_data = (caddr_t)&grekey;
73 if (ioctl(s, GRESKEY, (caddr_t)&ifr) < 0)
74 warn("ioctl (set grekey)");
78 setifgreopts(const char *val, int d, int s, const struct afswtch *afp)
82 ifr.ifr_data = (caddr_t)&opts;
83 if (ioctl(s, GREGOPTS, &ifr) == -1) {
84 warn("ioctl(GREGOPTS)");
93 if (ioctl(s, GRESOPTS, &ifr) == -1) {
94 warn("ioctl(GIFSOPTS)");
100 static struct cmd gre_cmds[] = {
101 DEF_CMD_ARG("grekey", setifgrekey),
102 DEF_CMD("enable_csum", GRE_ENABLE_CSUM, setifgreopts),
103 DEF_CMD("-enable_csum",-GRE_ENABLE_CSUM,setifgreopts),
104 DEF_CMD("enable_seq", GRE_ENABLE_SEQ, setifgreopts),
105 DEF_CMD("-enable_seq",-GRE_ENABLE_SEQ, setifgreopts),
107 static struct afswtch af_gre = {
110 .af_other_status = gre_status,
113 static __constructor void
116 #define N(a) (sizeof(a) / sizeof(a[0]))
119 for (i = 0; i < N(gre_cmds); i++)
120 cmd_register(&gre_cmds[i]);
121 af_register(&af_gre);