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$"; 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 54196931Shrs#define GIFBITS "\020\1ACCEPT_REV_ETHIP_VER\5SEND_REV_ETHIP_VER" 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 73193664Shrssetgifopts(const char *val, 74193664Shrs int d, int s, const struct afswtch *afp) 75193664Shrs{ 76193664Shrs int opts; 77193664Shrs 78193664Shrs ifr.ifr_data = (caddr_t)&opts; 79193664Shrs if (ioctl(s, GIFGOPTS, &ifr) == -1) { 80193664Shrs warn("ioctl(GIFGOPTS)"); 81193664Shrs return; 82193664Shrs } 83193664Shrs 84193664Shrs if (d < 0) 85193664Shrs opts &= ~(-d); 86193664Shrs else 87193664Shrs opts |= d; 88193664Shrs 89193664Shrs if (ioctl(s, GIFSOPTS, &ifr) == -1) { 90193664Shrs warn("ioctl(GIFSOPTS)"); 91193664Shrs return; 92193664Shrs } 93193664Shrs} 94193664Shrs 95193664Shrsstatic struct cmd gif_cmds[] = { 96193664Shrs DEF_CMD("accept_rev_ethip_ver", GIF_ACCEPT_REVETHIP, setgifopts), 97193664Shrs DEF_CMD("-accept_rev_ethip_ver",-GIF_ACCEPT_REVETHIP, setgifopts), 98193664Shrs DEF_CMD("send_rev_ethip_ver", GIF_SEND_REVETHIP, setgifopts), 99193664Shrs DEF_CMD("-send_rev_ethip_ver", -GIF_SEND_REVETHIP, setgifopts), 100193664Shrs}; 101193664Shrs 102193664Shrsstatic struct afswtch af_gif = { 103193664Shrs .af_name = "af_gif", 104193664Shrs .af_af = AF_UNSPEC, 105193664Shrs .af_other_status = gif_status, 106193664Shrs}; 107193664Shrs 108193664Shrsstatic __constructor void 109193664Shrsgif_ctor(void) 110193664Shrs{ 111193664Shrs#define N(a) (sizeof(a) / sizeof(a[0])) 112194799Sdelphij size_t i; 113193664Shrs 114193664Shrs for (i = 0; i < N(gif_cmds); i++) 115193664Shrs cmd_register(&gif_cmds[i]); 116193664Shrs af_register(&af_gif); 117193664Shrs#undef N 118193664Shrs} 119