2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 1997 Peter Wemm.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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
41 #include <libifconfig.h>
43 #define __constructor __attribute__((constructor))
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,
50 const struct afswtch *afp);
51 typedef void c_func3(const char *cmd, const char *arg, int s,
52 const struct afswtch *afp);
57 #define NEXTARG 0xffffff /* has following arg */
58 #define NEXTARG2 0xfffffe /* has 2 following args */
59 #define OPTARG 0xfffffd /* has optional following arg */
60 #define SPARAM 0xfffffc /* parameter is string c_sparameter */
61 const char *c_sparameter;
70 void cmd_register(struct cmd *);
72 typedef void callback_func(int s, void *);
73 void callback_register(callback_func *, void *);
76 * Macros for declaring command functions and initializing entries.
78 #define DECL_CMD_FUNC(name, cmd, arg) \
79 void name(const char *cmd, int arg, int s, const struct afswtch *afp)
80 #define DECL_CMD_FUNC2(name, arg1, arg2) \
81 void name(const char *arg1, const char *arg2, int s, \
82 const struct afswtch *afp)
84 #define DEF_CMD(name, param, func) { \
86 .c_parameter = (param), \
87 .c_u = { .c_func = (func) }, \
91 #define DEF_CMD_ARG(name, func) { \
93 .c_parameter = NEXTARG, \
94 .c_u = { .c_func = (func) }, \
98 #define DEF_CMD_OPTARG(name, func) { \
100 .c_parameter = OPTARG, \
101 .c_u = { .c_func = (func) }, \
105 #define DEF_CMD_ARG2(name, func) { \
107 .c_parameter = NEXTARG2, \
108 .c_u = { .c_func2 = (func) }, \
112 #define DEF_CMD_SARG(name, sparam, func) { \
114 .c_parameter = SPARAM, \
115 .c_sparameter = (sparam), \
116 .c_u = { .c_func3 = (func) }, \
120 #define DEF_CLONE_CMD(name, param, func) { \
122 .c_parameter = (param), \
123 .c_u = { .c_func = (func) }, \
127 #define DEF_CLONE_CMD_ARG(name, func) { \
129 .c_parameter = NEXTARG, \
130 .c_u = { .c_func = (func) }, \
134 #define DEF_CLONE_CMD_ARG2(name, func) { \
136 .c_parameter = NEXTARG2, \
137 .c_u = { .c_func2 = (func) }, \
153 const char *af_name; /* as given on cmd line, e.g. "inet" */
154 short af_af; /* AF_* */
156 * Status is handled one of two ways; if there is an
157 * address associated with the interface then the
158 * associated address family af_status method is invoked
159 * with the appropriate addressin info. Otherwise, if
160 * all possible info is to be displayed and af_other_status
161 * is defined then it is invoked after all address status
164 void (*af_status)(int, const struct ifaddrs *);
165 void (*af_other_status)(int);
166 /* parse address method */
167 void (*af_getaddr)(const char *, int);
168 /* parse prefix method (IPv6) */
169 void (*af_getprefix)(const char *, int);
170 void (*af_postproc)(int s, const struct afswtch *,
171 int newaddr, int ifflags);
172 u_long af_difaddr; /* set dst if address ioctl */
173 u_long af_aifaddr; /* set if address ioctl */
174 void *af_ridreq; /* */
175 void *af_addreq; /* */
176 struct afswtch *af_next;
178 /* XXX doesn't fit model */
179 void (*af_status_tunnel)(int);
180 void (*af_settunnel)(int s, struct addrinfo *srcres,
181 struct addrinfo *dstres);
183 void af_register(struct afswtch *);
187 const char *opt_usage;
188 void (*cb)(const char *arg);
191 void opt_register(struct option *);
193 extern ifconfig_handle_t *lifh;
194 extern struct ifreq ifr;
195 extern char name[IFNAMSIZ]; /* name of interface */
198 extern int printkeys;
201 extern int printifname;
202 extern int exit_code;
204 void setifcap(const char *, int value, int s, const struct afswtch *);
205 void setifcapnv(const char *vname, const char *arg, int s,
206 const struct afswtch *afp);
208 void Perror(const char *cmd);
209 void printb(const char *s, unsigned value, const char *bits);
211 void ifmaybeload(const char *name);
213 typedef int clone_match_func(const char *);
214 typedef void clone_callback_func(int, struct ifreq *);
215 void clone_setdefcallback_prefix(const char *, clone_callback_func *);
216 void clone_setdefcallback_filter(clone_match_func *, clone_callback_func *);
218 void sfp_status(int s, struct ifreq *ifr, int verbose);
221 * XXX expose this so modules that neeed to know of any pending
222 * operations on ifmedia can avoid cmd line ordering confusion.
224 struct ifmediareq *ifmedia_getstate(void);
226 void print_vhid(const struct ifaddrs *, const char *);
228 void ioctl_ifcreate(int s, struct ifreq *);