/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2009 Hiroki Sato. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,18* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES19* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR20* SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,22* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING23* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF24* THE POSSIBILITY OF SUCH DAMAGE.25*/2627#include <sys/param.h>28#include <sys/ioctl.h>29#include <sys/socket.h>30#include <sys/sockio.h>3132#include <stdlib.h>33#include <unistd.h>3435#include <net/ethernet.h>36#include <net/if.h>37#include <net/if_gif.h>38#include <net/route.h>3940#include <ctype.h>41#include <stdio.h>42#include <string.h>43#include <stdlib.h>44#include <unistd.h>45#include <err.h>46#include <errno.h>4748#include "ifconfig.h"4950static const char *GIFBITS[] = {51[0] = "NOCLAMP",52[1] = "IGNORE_SOURCE",53};5455static void56gif_status(if_ctx *ctx)57{58int opts;59struct ifreq ifr = { .ifr_data = (caddr_t)&opts };6061if (ioctl_ctx_ifr(ctx, GIFGOPTS, &ifr) == -1)62return;63if (opts == 0)64return;65printf("\toptions=%x", opts);66print_bits("options", &opts, 1, GIFBITS, nitems(GIFBITS));67putchar('\n');68}6970static void71setgifopts(if_ctx *ctx, const char *val __unused, int d)72{73int opts;74struct ifreq ifr = { .ifr_data = (caddr_t)&opts };7576if (ioctl_ctx_ifr(ctx, GIFGOPTS, &ifr) == -1) {77warn("ioctl(GIFGOPTS)");78return;79}8081if (d < 0)82opts &= ~(-d);83else84opts |= d;8586if (ioctl_ctx(ctx, GIFSOPTS, &ifr) == -1) {87warn("ioctl(GIFSOPTS)");88return;89}90}9192static struct cmd gif_cmds[] = {93DEF_CMD("noclamp", GIF_NOCLAMP, setgifopts),94DEF_CMD("-noclamp", -GIF_NOCLAMP, setgifopts),95DEF_CMD("ignore_source", GIF_IGNORE_SOURCE, setgifopts),96DEF_CMD("-ignore_source", -GIF_IGNORE_SOURCE, setgifopts),97};9899static struct afswtch af_gif = {100.af_name = "af_gif",101.af_af = AF_UNSPEC,102.af_other_status = gif_status,103};104105static __constructor void106gif_ctor(void)107{108size_t i;109110for (i = 0; i < nitems(gif_cmds); i++)111cmd_register(&gif_cmds[i]);112af_register(&af_gif);113}114115116