ifgre.c (256281) | ifgre.c (284066) |
---|---|
1/*- 2 * Copyright (c) 2008 Andrew Thompson. 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 unchanged lines hidden (view full) --- 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 | 1/*- 2 * Copyright (c) 2008 Andrew Thompson. 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 unchanged lines hidden (view full) --- 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 27static const char rcsid[] = 28 "$FreeBSD: stable/10/sbin/ifconfig/ifgre.c 194799 2009-06-23 23:49:52Z delphij $"; 29#endif | 26#include <sys/cdefs.h> 27__FBSDID("$FreeBSD: stable/10/sbin/ifconfig/ifgre.c 284066 2015-06-06 12:44:42Z ae $"); |
30 31#include <sys/param.h> 32#include <sys/ioctl.h> 33#include <sys/socket.h> 34#include <sys/sockio.h> | 28 29#include <sys/param.h> 30#include <sys/ioctl.h> 31#include <sys/socket.h> 32#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#include <net/if_gre.h> | 33#include <net/if.h> 34#include <net/if_gre.h> |
42#include <net/route.h> | |
43 44#include <ctype.h> | 35 36#include <ctype.h> |
37#include <limits.h> |
|
45#include <stdio.h> | 38#include <stdio.h> |
46#include <string.h> | |
47#include <stdlib.h> | 39#include <stdlib.h> |
48#include <unistd.h> | 40#include <string.h> |
49#include <err.h> | 41#include <err.h> |
50#include <errno.h> | |
51 52#include "ifconfig.h" 53 | 42 43#include "ifconfig.h" 44 |
45#define GREBITS "\020\01ENABLE_CSUM\02ENABLE_SEQ" 46 |
|
54static void gre_status(int s); 55 56static void 57gre_status(int s) 58{ | 47static void gre_status(int s); 48 49static void 50gre_status(int s) 51{ |
59 int grekey = 0; | 52 uint32_t opts = 0; |
60 | 53 |
61 ifr.ifr_data = (caddr_t)&grekey; | 54 ifr.ifr_data = (caddr_t)&opts; |
62 if (ioctl(s, GREGKEY, &ifr) == 0) | 55 if (ioctl(s, GREGKEY, &ifr) == 0) |
63 if (grekey != 0) 64 printf("\tgrekey: %d\n", grekey); | 56 if (opts != 0) 57 printf("\tgrekey: 0x%x (%u)\n", opts, opts); 58 opts = 0; 59 if (ioctl(s, GREGOPTS, &ifr) != 0 || opts == 0) 60 return; 61 printb("\toptions", opts, GREBITS); 62 putchar('\n'); |
65} 66 67static void 68setifgrekey(const char *val, int dummy __unused, int s, 69 const struct afswtch *afp) 70{ | 63} 64 65static void 66setifgrekey(const char *val, int dummy __unused, int s, 67 const struct afswtch *afp) 68{ |
71 uint32_t grekey = atol(val); | 69 uint32_t grekey = strtol(val, NULL, 0); |
72 73 strncpy(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)"); 77} 78 | 70 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)"); 75} 76 |
77static void 78setifgreopts(const char *val, int d, int s, const struct afswtch *afp) 79{ 80 uint32_t opts; 81 82 ifr.ifr_data = (caddr_t)&opts; 83 if (ioctl(s, GREGOPTS, &ifr) == -1) { 84 warn("ioctl(GREGOPTS)"); 85 return; 86 } 87 88 if (d < 0) 89 opts &= ~(-d); 90 else 91 opts |= d; 92 93 if (ioctl(s, GRESOPTS, &ifr) == -1) { 94 warn("ioctl(GIFSOPTS)"); 95 return; 96 } 97} 98 99 |
|
79static struct cmd gre_cmds[] = { 80 DEF_CMD_ARG("grekey", setifgrekey), | 100static 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), |
|
81}; 82static struct afswtch af_gre = { 83 .af_name = "af_gre", 84 .af_af = AF_UNSPEC, 85 .af_other_status = gre_status, 86}; 87 88static __constructor void 89gre_ctor(void) 90{ 91#define N(a) (sizeof(a) / sizeof(a[0])) 92 size_t i; 93 94 for (i = 0; i < N(gre_cmds); i++) 95 cmd_register(&gre_cmds[i]); 96 af_register(&af_gre); 97#undef N 98} | 106}; 107static struct afswtch af_gre = { 108 .af_name = "af_gre", 109 .af_af = AF_UNSPEC, 110 .af_other_status = gre_status, 111}; 112 113static __constructor void 114gre_ctor(void) 115{ 116#define N(a) (sizeof(a) / sizeof(a[0])) 117 size_t i; 118 119 for (i = 0; i < N(gre_cmds); i++) 120 cmd_register(&gre_cmds[i]); 121 af_register(&af_gre); 122#undef N 123} |