1193664Shrs/*- 2193664Shrs * Copyright (c) 2009 Hiroki Sato. All rights reserved. 3193664Shrs * 4193664Shrs * Redistribution and use in source and binary forms, with or without 5193664Shrs * modification, are permitted provided that the following conditions 6193664Shrs * are met: 7193664Shrs * 1. Redistributions of source code must retain the above copyright 8193664Shrs * notice, this list of conditions and the following disclaimer. 9193664Shrs * 2. Redistributions in binary form must reproduce the above copyright 10193664Shrs * notice, this list of conditions and the following disclaimer in the 11193664Shrs * documentation and/or other materials provided with the distribution. 12193664Shrs * 13193664Shrs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14193664Shrs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15193664Shrs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16193664Shrs * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 17193664Shrs * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18193664Shrs * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19193664Shrs * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20193664Shrs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21193664Shrs * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 22193664Shrs * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23193664Shrs * THE POSSIBILITY OF SUCH DAMAGE. 24193664Shrs */ 25193664Shrs 26193664Shrs#ifndef lint 27193664Shrsstatic const char rcsid[] = 28193664Shrs "$FreeBSD: releng/10.3/sbin/ifconfig/ifgif.c 288055 2015-09-21 03:03:57Z hrs $"; 29193664Shrs#endif 30193664Shrs 31193664Shrs#include <sys/param.h> 32193664Shrs#include <sys/ioctl.h> 33193664Shrs#include <sys/socket.h> 34193664Shrs#include <sys/sockio.h> 35193664Shrs 36193664Shrs#include <stdlib.h> 37193664Shrs#include <unistd.h> 38193664Shrs 39193664Shrs#include <net/ethernet.h> 40193664Shrs#include <net/if.h> 41193664Shrs#include <net/if_gif.h> 42193664Shrs#include <net/route.h> 43193664Shrs 44193664Shrs#include <ctype.h> 45193664Shrs#include <stdio.h> 46193664Shrs#include <string.h> 47193664Shrs#include <stdlib.h> 48193664Shrs#include <unistd.h> 49193664Shrs#include <err.h> 50193664Shrs#include <errno.h> 51193664Shrs 52193664Shrs#include "ifconfig.h" 53193664Shrs 54287730Shrs#define GIFBITS "\020\2IGNORE_SOURCE" 55196931Shrs 56193664Shrsstatic void gif_status(int); 57193664Shrs 58193664Shrsstatic void 59193664Shrsgif_status(int s) 60193664Shrs{ 61193664Shrs int opts; 62193664Shrs 63193664Shrs ifr.ifr_data = (caddr_t)&opts; 64193664Shrs if (ioctl(s, GIFGOPTS, &ifr) == -1) 65193664Shrs return; 66196929Sume if (opts == 0) 67196929Sume return; 68196931Shrs printb("\toptions", opts, GIFBITS); 69196931Shrs putchar('\n'); 70193664Shrs} 71193664Shrs 72193664Shrsstatic void 73287730Shrssetgifopts(const char *val, int d, int s, const struct afswtch *afp) 74193664Shrs{ 75193664Shrs int opts; 76193664Shrs 77288055Shrs if (d == 0) 78288055Shrs return; 79193664Shrs ifr.ifr_data = (caddr_t)&opts; 80193664Shrs if (ioctl(s, GIFGOPTS, &ifr) == -1) { 81193664Shrs warn("ioctl(GIFGOPTS)"); 82193664Shrs return; 83193664Shrs } 84193664Shrs 85193664Shrs if (d < 0) 86193664Shrs opts &= ~(-d); 87193664Shrs else 88193664Shrs opts |= d; 89193664Shrs 90193664Shrs if (ioctl(s, GIFSOPTS, &ifr) == -1) { 91193664Shrs warn("ioctl(GIFSOPTS)"); 92193664Shrs return; 93193664Shrs } 94193664Shrs} 95193664Shrs 96193664Shrsstatic struct cmd gif_cmds[] = { 97288055Shrs DEF_CMD("accept_rev_ethip_ver", 0, setgifopts), 98288055Shrs DEF_CMD("-accept_rev_ethip_ver",0, setgifopts), 99283852Sae DEF_CMD("ignore_source", GIF_IGNORE_SOURCE, setgifopts), 100283852Sae DEF_CMD("-ignore_source", -GIF_IGNORE_SOURCE, setgifopts), 101288055Shrs DEF_CMD("send_rev_ethip_ver", 0, setgifopts), 102288055Shrs DEF_CMD("-send_rev_ethip_ver", 0, setgifopts), 103193664Shrs}; 104193664Shrs 105193664Shrsstatic struct afswtch af_gif = { 106193664Shrs .af_name = "af_gif", 107193664Shrs .af_af = AF_UNSPEC, 108193664Shrs .af_other_status = gif_status, 109193664Shrs}; 110193664Shrs 111193664Shrsstatic __constructor void 112193664Shrsgif_ctor(void) 113193664Shrs{ 114194799Sdelphij size_t i; 115193664Shrs 116287730Shrs for (i = 0; i < nitems(gif_cmds); i++) 117193664Shrs cmd_register(&gif_cmds[i]); 118193664Shrs af_register(&af_gif); 119193664Shrs} 120