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