1223735Sbz/*- 2223735Sbz * Copyright (c) 2011 Alexander V. Chernikov 3223735Sbz * Copyright (c) 2011 Christian S.J. Peron 4223735Sbz * Copyright (c) 2011 Bjoern A. Zeeb 5223735Sbz * All rights reserved. 6223735Sbz * 7223735Sbz * Redistribution and use in source and binary forms, with or without 8223735Sbz * modification, are permitted provided that the following conditions 9223735Sbz * are met: 10223735Sbz * 1. Redistributions of source code must retain the above copyright 11223735Sbz * notice, this list of conditions and the following disclaimer. 12223735Sbz * 2. Redistributions in binary form must reproduce the above copyright 13223735Sbz * notice, this list of conditions and the following disclaimer in the 14223735Sbz * documentation and/or other materials provided with the distribution. 15223735Sbz * 16223735Sbz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17223735Sbz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18223735Sbz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19223735Sbz * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20223735Sbz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21223735Sbz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22223735Sbz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23223735Sbz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24223735Sbz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25223735Sbz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26223735Sbz * SUCH DAMAGE. 27223735Sbz * 28223735Sbz * $FreeBSD$ 29223735Sbz */ 30223735Sbz 31223735Sbz#include <sys/param.h> 32223735Sbz#include <sys/ioctl.h> 33223735Sbz#include <sys/socket.h> 34223735Sbz#include <sys/sockio.h> 35223735Sbz 36223735Sbz#include <net/if.h> 37223735Sbz#include <net/route.h> 38223735Sbz 39223735Sbz#include <stdio.h> 40223735Sbz#include <stdlib.h> 41223735Sbz#include <string.h> 42223735Sbz#include <err.h> 43223735Sbz 44223735Sbz#include "ifconfig.h" 45223735Sbz 46223735Sbzstatic void 47223735Sbzfib_status(int s) 48223735Sbz{ 49223735Sbz struct ifreq ifr; 50223735Sbz 51223735Sbz memset(&ifr, 0, sizeof(ifr)); 52223735Sbz strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 53223735Sbz 54223735Sbz if (ioctl(s, SIOCGIFFIB, (caddr_t)&ifr) < 0) 55223735Sbz return; 56223735Sbz 57223735Sbz /* Ignore if it is the default. */ 58223735Sbz if (ifr.ifr_fib == 0) 59223735Sbz return; 60223735Sbz 61223735Sbz printf("\tfib: %u\n", ifr.ifr_fib); 62223735Sbz} 63223735Sbz 64223735Sbzstatic void 65223735Sbzsetiffib(const char *val, int dummy __unused, int s, 66223735Sbz const struct afswtch *afp) 67223735Sbz{ 68223735Sbz unsigned long fib; 69223735Sbz char *ep; 70223735Sbz 71223735Sbz fib = strtoul(val, &ep, 0); 72223735Sbz if (*ep != '\0' || fib > UINT_MAX) { 73223735Sbz warn("fib %s not valid", val); 74223735Sbz return; 75223735Sbz } 76223735Sbz 77223735Sbz strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); 78223735Sbz ifr.ifr_fib = fib; 79223735Sbz if (ioctl(s, SIOCSIFFIB, (caddr_t)&ifr) < 0) 80223735Sbz warn("ioctl (SIOCSIFFIB)"); 81223735Sbz} 82223735Sbz 83223735Sbzstatic struct cmd fib_cmds[] = { 84223735Sbz DEF_CMD_ARG("fib", setiffib), 85223735Sbz}; 86223735Sbz 87223735Sbzstatic struct afswtch af_fib = { 88223735Sbz .af_name = "af_fib", 89223735Sbz .af_af = AF_UNSPEC, 90223735Sbz .af_other_status = fib_status, 91223735Sbz}; 92223735Sbz 93223735Sbzstatic __constructor void 94223735Sbzfib_ctor(void) 95223735Sbz{ 96223735Sbz#define N(a) (sizeof(a) / sizeof(a[0])) 97223735Sbz size_t i; 98223735Sbz 99223735Sbz for (i = 0; i < N(fib_cmds); i++) 100223735Sbz cmd_register(&fib_cmds[i]); 101223735Sbz af_register(&af_fib); 102223735Sbz#undef N 103223735Sbz} 104