1 /*- 2 * SPDX-License-Identifier: BSD-4-Clause 3 * 4 * Copyright (c) 1997 Peter Wemm. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed for the FreeBSD Project 18 * by Peter Wemm. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * so there! 35 * 36 * $FreeBSD$ 37 */ 38 39 #define __constructor __attribute__((constructor)) 40 41 #ifdef FSTACK 42 #include "compat.h" 43 44 #ifndef __unused 45 #define __unused __attribute__((unused)) 46 #endif 47 48 int fake_socket(int domain, int type, int protocol); 49 int fake_close(int fd); 50 51 #define socket(a, b, c) fake_socket((a), (b), (c)) 52 #define close(a) fake_close((a)) 53 54 #endif 55 56 struct afswtch; 57 struct cmd; 58 59 typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp); 60 typedef void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp); 61 62 struct cmd { 63 const char *c_name; 64 int c_parameter; 65 #define NEXTARG 0xffffff /* has following arg */ 66 #define NEXTARG2 0xfffffe /* has 2 following args */ 67 #define OPTARG 0xfffffd /* has optional following arg */ 68 union { 69 c_func *c_func; 70 c_func2 *c_func2; 71 } c_u; 72 int c_iscloneop; 73 struct cmd *c_next; 74 }; 75 void cmd_register(struct cmd *); 76 77 typedef void callback_func(int s, void *); 78 void callback_register(callback_func *, void *); 79 80 /* 81 * Macros for declaring command functions and initializing entries. 82 */ 83 #define DECL_CMD_FUNC(name, cmd, arg) \ 84 void name(const char *cmd, int arg, int s, const struct afswtch *afp) 85 #define DECL_CMD_FUNC2(name, arg1, arg2) \ 86 void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp) 87 88 #define DEF_CMD(name, param, func) { name, param, { .c_func = func }, 0, NULL } 89 #define DEF_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 0, NULL } 90 #define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func }, 0, NULL } 91 #define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func }, 0, NULL } 92 #define DEF_CLONE_CMD(name, param, func) { name, param, { .c_func = func }, 1, NULL } 93 #define DEF_CLONE_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 1, NULL } 94 #define DEF_CLONE_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func }, 1, NULL } 95 96 struct ifaddrs; 97 struct addrinfo; 98 99 enum { 100 RIDADDR, 101 ADDR, 102 MASK, 103 DSTADDR, 104 }; 105 106 struct afswtch { 107 const char *af_name; /* as given on cmd line, e.g. "inet" */ 108 short af_af; /* AF_* */ 109 /* 110 * Status is handled one of two ways; if there is an 111 * address associated with the interface then the 112 * associated address family af_status method is invoked 113 * with the appropriate addressin info. Otherwise, if 114 * all possible info is to be displayed and af_other_status 115 * is defined then it is invoked after all address status 116 * is presented. 117 */ 118 void (*af_status)(int, const struct ifaddrs *); 119 void (*af_other_status)(int); 120 /* parse address method */ 121 void (*af_getaddr)(const char *, int); 122 /* parse prefix method (IPv6) */ 123 void (*af_getprefix)(const char *, int); 124 void (*af_postproc)(int s, const struct afswtch *); 125 u_long af_difaddr; /* set dst if address ioctl */ 126 u_long af_aifaddr; /* set if address ioctl */ 127 void *af_ridreq; /* */ 128 void *af_addreq; /* */ 129 struct afswtch *af_next; 130 131 /* XXX doesn't fit model */ 132 void (*af_status_tunnel)(int); 133 void (*af_settunnel)(int s, struct addrinfo *srcres, 134 struct addrinfo *dstres); 135 }; 136 void af_register(struct afswtch *); 137 138 struct option { 139 const char *opt; 140 const char *opt_usage; 141 void (*cb)(const char *arg); 142 struct option *next; 143 }; 144 void opt_register(struct option *); 145 146 extern struct ifreq ifr; 147 extern char name[IFNAMSIZ]; /* name of interface */ 148 extern int allmedia; 149 extern int supmedia; 150 extern int printkeys; 151 extern int newaddr; 152 extern int verbose; 153 extern int printifname; 154 extern int exit_code; 155 156 void setifcap(const char *, int value, int s, const struct afswtch *); 157 158 void Perror(const char *cmd); 159 void printb(const char *s, unsigned value, const char *bits); 160 161 void ifmaybeload(const char *name); 162 163 typedef int clone_match_func(const char *); 164 typedef void clone_callback_func(int, struct ifreq *); 165 void clone_setdefcallback_prefix(const char *, clone_callback_func *); 166 void clone_setdefcallback_filter(clone_match_func *, clone_callback_func *); 167 168 void sfp_status(int s, struct ifreq *ifr, int verbose); 169 170 /* 171 * XXX expose this so modules that neeed to know of any pending 172 * operations on ifmedia can avoid cmd line ordering confusion. 173 */ 174 struct ifmediareq *ifmedia_getstate(int s); 175 176 void print_vhid(const struct ifaddrs *, const char *); 177 178 void ioctl_ifcreate(int s, struct ifreq *); 179