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 #pragma once 40 41 #include <libifconfig.h> 42 43 #define __constructor __attribute__((constructor)) 44 45 struct afswtch; 46 struct cmd; 47 48 typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp); 49 typedef void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp); 50 51 struct cmd { 52 const char *c_name; 53 int c_parameter; 54 #define NEXTARG 0xffffff /* has following arg */ 55 #define NEXTARG2 0xfffffe /* has 2 following args */ 56 #define OPTARG 0xfffffd /* has optional following arg */ 57 union { 58 c_func *c_func; 59 c_func2 *c_func2; 60 } c_u; 61 int c_iscloneop; 62 struct cmd *c_next; 63 }; 64 void cmd_register(struct cmd *); 65 66 typedef void callback_func(int s, void *); 67 void callback_register(callback_func *, void *); 68 69 /* 70 * Macros for declaring command functions and initializing entries. 71 */ 72 #define DECL_CMD_FUNC(name, cmd, arg) \ 73 void name(const char *cmd, int arg, int s, const struct afswtch *afp) 74 #define DECL_CMD_FUNC2(name, arg1, arg2) \ 75 void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp) 76 77 #define DEF_CMD(name, param, func) { name, param, { .c_func = func }, 0, NULL } 78 #define DEF_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 0, NULL } 79 #define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func }, 0, NULL } 80 #define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func }, 0, NULL } 81 #define DEF_CLONE_CMD(name, param, func) { name, param, { .c_func = func }, 1, NULL } 82 #define DEF_CLONE_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 1, NULL } 83 #define DEF_CLONE_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func }, 1, NULL } 84 85 struct ifaddrs; 86 struct addrinfo; 87 88 enum { 89 RIDADDR, 90 ADDR, 91 MASK, 92 DSTADDR, 93 }; 94 95 struct afswtch { 96 const char *af_name; /* as given on cmd line, e.g. "inet" */ 97 short af_af; /* AF_* */ 98 /* 99 * Status is handled one of two ways; if there is an 100 * address associated with the interface then the 101 * associated address family af_status method is invoked 102 * with the appropriate addressin info. Otherwise, if 103 * all possible info is to be displayed and af_other_status 104 * is defined then it is invoked after all address status 105 * is presented. 106 */ 107 void (*af_status)(int, const struct ifaddrs *); 108 void (*af_other_status)(int); 109 /* parse address method */ 110 void (*af_getaddr)(const char *, int); 111 /* parse prefix method (IPv6) */ 112 void (*af_getprefix)(const char *, int); 113 void (*af_postproc)(int s, const struct afswtch *, 114 int newaddr, int ifflags); 115 u_long af_difaddr; /* set dst if address ioctl */ 116 u_long af_aifaddr; /* set if address ioctl */ 117 void *af_ridreq; /* */ 118 void *af_addreq; /* */ 119 struct afswtch *af_next; 120 121 /* XXX doesn't fit model */ 122 void (*af_status_tunnel)(int); 123 void (*af_settunnel)(int s, struct addrinfo *srcres, 124 struct addrinfo *dstres); 125 }; 126 void af_register(struct afswtch *); 127 128 struct option { 129 const char *opt; 130 const char *opt_usage; 131 void (*cb)(const char *arg); 132 struct option *next; 133 }; 134 void opt_register(struct option *); 135 136 extern ifconfig_handle_t *lifh; 137 extern struct ifreq ifr; 138 extern char name[IFNAMSIZ]; /* name of interface */ 139 extern int allmedia; 140 extern int supmedia; 141 extern int printkeys; 142 extern int newaddr; 143 extern int verbose; 144 extern int printifname; 145 extern int exit_code; 146 147 void setifcap(const char *, int value, int s, const struct afswtch *); 148 149 void Perror(const char *cmd); 150 void printb(const char *s, unsigned value, const char *bits); 151 152 void ifmaybeload(const char *name); 153 154 typedef int clone_match_func(const char *); 155 typedef void clone_callback_func(int, struct ifreq *); 156 void clone_setdefcallback_prefix(const char *, clone_callback_func *); 157 void clone_setdefcallback_filter(clone_match_func *, clone_callback_func *); 158 159 void sfp_status(int s, struct ifreq *ifr, int verbose); 160 161 /* 162 * XXX expose this so modules that neeed to know of any pending 163 * operations on ifmedia can avoid cmd line ordering confusion. 164 */ 165 struct ifmediareq *ifmedia_getstate(void); 166 167 void print_vhid(const struct ifaddrs *, const char *); 168 169 void ioctl_ifcreate(int s, struct ifreq *); 170