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