2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008 Andrew Thompson. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/ioctl.h>
33 #include <sys/socket.h>
34 #include <sys/sockio.h>
36 #include <net/if_gre.h>
47 #define GREBITS "\020\01ENABLE_CSUM\02ENABLE_SEQ"
49 static void gre_status(int s);
56 ifr.ifr_data = (caddr_t)&opts;
57 if (ioctl(s, GREGKEY, &ifr) == 0)
59 printf("\tgrekey: 0x%x (%u)\n", opts, opts);
61 if (ioctl(s, GREGOPTS, &ifr) != 0 || opts == 0)
63 printb("\toptions", opts, GREBITS);
68 setifgrekey(const char *val, int dummy __unused, int s,
69 const struct afswtch *afp)
71 uint32_t grekey = strtol(val, NULL, 0);
73 strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
74 ifr.ifr_data = (caddr_t)&grekey;
75 if (ioctl(s, GRESKEY, (caddr_t)&ifr) < 0)
76 warn("ioctl (set grekey)");
80 setifgreopts(const char *val, int d, int s, const struct afswtch *afp)
84 ifr.ifr_data = (caddr_t)&opts;
85 if (ioctl(s, GREGOPTS, &ifr) == -1) {
86 warn("ioctl(GREGOPTS)");
95 if (ioctl(s, GRESOPTS, &ifr) == -1) {
96 warn("ioctl(GIFSOPTS)");
102 static struct cmd gre_cmds[] = {
103 DEF_CMD_ARG("grekey", setifgrekey),
104 DEF_CMD("enable_csum", GRE_ENABLE_CSUM, setifgreopts),
105 DEF_CMD("-enable_csum",-GRE_ENABLE_CSUM,setifgreopts),
106 DEF_CMD("enable_seq", GRE_ENABLE_SEQ, setifgreopts),
107 DEF_CMD("-enable_seq",-GRE_ENABLE_SEQ, setifgreopts),
109 static struct afswtch af_gre = {
112 .af_other_status = gre_status,
115 static __constructor void
120 for (i = 0; i < nitems(gre_cmds); i++)
121 cmd_register(&gre_cmds[i]);
122 af_register(&af_gre);