ifgif.c revision 272461
1238730Sdelphij/*- 2330571Sdelphij * Copyright (c) 2009 Hiroki Sato. All rights reserved. 3238730Sdelphij * 4238730Sdelphij * Redistribution and use in source and binary forms, with or without 5238730Sdelphij * modification, are permitted provided that the following conditions 6238730Sdelphij * are met: 7238730Sdelphij * 1. Redistributions of source code must retain the above copyright 8238730Sdelphij * notice, this list of conditions and the following disclaimer. 960786Sps * 2. Redistributions in binary form must reproduce the above copyright 1060786Sps * notice, this list of conditions and the following disclaimer in the 1160786Sps * documentation and/or other materials provided with the distribution. 1260786Sps * 1360786Sps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1460786Sps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1560786Sps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1660786Sps * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 17172471Sdelphij * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1860786Sps * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1960786Sps * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2060786Sps * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 2160786Sps * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 2260786Sps * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 2360786Sps * THE POSSIBILITY OF SUCH DAMAGE. 2460786Sps */ 2560786Sps 2660786Sps#ifndef lint 2760786Spsstatic const char rcsid[] = 2860786Sps "$FreeBSD: releng/10.1/sbin/ifconfig/ifgif.c 196931 2009-09-07 15:52:15Z hrs $"; 29128348Stjr#endif 3063131Sps 31330571Sdelphij#include <sys/param.h> 3260786Sps#include <sys/ioctl.h> 3360786Sps#include <sys/socket.h> 34191930Sdelphij#include <sys/sockio.h> 35191930Sdelphij 3660786Sps#include <stdlib.h> 3760786Sps#include <unistd.h> 3860786Sps 3960786Sps#include <net/ethernet.h> 4060786Sps#include <net/if.h> 4160786Sps#include <net/if_gif.h> 4260786Sps#include <net/route.h> 4360786Sps 44195941Sdelphij#include <ctype.h> 45195941Sdelphij#include <stdio.h> 4660786Sps#include <string.h> 47294286Sdelphij#include <stdlib.h> 48294286Sdelphij#include <unistd.h> 49294286Sdelphij#include <err.h> 50294286Sdelphij#include <errno.h> 51294286Sdelphij 52294286Sdelphij#include "ifconfig.h" 53294286Sdelphij 54294286Sdelphij#define GIFBITS "\020\1ACCEPT_REV_ETHIP_VER\5SEND_REV_ETHIP_VER" 55294286Sdelphij 56294286Sdelphijstatic void gif_status(int); 57294286Sdelphij 58294286Sdelphijstatic void 59294286Sdelphijgif_status(int s) 60294286Sdelphij{ 61294286Sdelphij int opts; 62294286Sdelphij 6360786Sps ifr.ifr_data = (caddr_t)&opts; 6460786Sps if (ioctl(s, GIFGOPTS, &ifr) == -1) 6560786Sps return; 6660786Sps if (opts == 0) 6760786Sps return; 68294286Sdelphij printb("\toptions", opts, GIFBITS); 69294286Sdelphij putchar('\n'); 70294286Sdelphij} 71294286Sdelphij 72294286Sdelphijstatic void 73294286Sdelphijsetgifopts(const char *val, 74294286Sdelphij int d, int s, const struct afswtch *afp) 75294286Sdelphij{ 76294286Sdelphij int opts; 77294286Sdelphij 78294286Sdelphij ifr.ifr_data = (caddr_t)&opts; 79294286Sdelphij if (ioctl(s, GIFGOPTS, &ifr) == -1) { 80294286Sdelphij warn("ioctl(GIFGOPTS)"); 81294286Sdelphij return; 82294286Sdelphij } 83294286Sdelphij 84294286Sdelphij if (d < 0) 85294286Sdelphij opts &= ~(-d); 86294286Sdelphij else 87294286Sdelphij opts |= d; 88294286Sdelphij 89294286Sdelphij if (ioctl(s, GIFSOPTS, &ifr) == -1) { 90294286Sdelphij warn("ioctl(GIFSOPTS)"); 91294286Sdelphij return; 92294286Sdelphij } 93294286Sdelphij} 94294286Sdelphij 95294286Sdelphijstatic struct cmd gif_cmds[] = { 96294286Sdelphij DEF_CMD("accept_rev_ethip_ver", GIF_ACCEPT_REVETHIP, setgifopts), 97294286Sdelphij DEF_CMD("-accept_rev_ethip_ver",-GIF_ACCEPT_REVETHIP, setgifopts), 9860786Sps DEF_CMD("send_rev_ethip_ver", GIF_SEND_REVETHIP, setgifopts), 9960786Sps DEF_CMD("-send_rev_ethip_ver", -GIF_SEND_REVETHIP, setgifopts), 10060786Sps}; 10160786Sps 102195941Sdelphijstatic struct afswtch af_gif = { 10360786Sps .af_name = "af_gif", 104195941Sdelphij .af_af = AF_UNSPEC, 105330571Sdelphij .af_other_status = gif_status, 106195941Sdelphij}; 107195941Sdelphij 108195941Sdelphijstatic __constructor void 109237613Sdelphijgif_ctor(void) 110237613Sdelphij{ 111237613Sdelphij#define N(a) (sizeof(a) / sizeof(a[0])) 112237613Sdelphij size_t i; 113237613Sdelphij 114237613Sdelphij for (i = 0; i < N(gif_cmds); i++) 115195941Sdelphij cmd_register(&gif_cmds[i]); 116195941Sdelphij af_register(&af_gif); 117195941Sdelphij#undef N 11860786Sps} 119173685Sdelphij