125451Speter/*
225451Speter * Copyright (c) 1997 Peter Wemm.
325451Speter * All rights reserved.
425451Speter *
525451Speter * Redistribution and use in source and binary forms, with or without
625451Speter * modification, are permitted provided that the following conditions
725451Speter * are met:
825451Speter * 1. Redistributions of source code must retain the above copyright
925451Speter *    notice, this list of conditions and the following disclaimer.
1025451Speter * 2. Redistributions in binary form must reproduce the above copyright
1125451Speter *    notice, this list of conditions and the following disclaimer in the
1225451Speter *    documentation and/or other materials provided with the distribution.
1325451Speter * 3. All advertising materials mentioning features or use of this software
1425451Speter *    must display the following acknowledgement:
1525451Speter *      This product includes software developed for the FreeBSD Project
1625451Speter *	by Peter Wemm.
1725451Speter * 4. The name of the author may not be used to endorse or promote products
1825451Speter *    derived from this software without specific prior written permission.
1925451Speter *
2025451Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2125451Speter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2225451Speter * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2325451Speter * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2425451Speter * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2525451Speter * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2625451Speter * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2725451Speter * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2825451Speter * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2925451Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3025451Speter * SUCH DAMAGE.
3125451Speter *
3225451Speter * so there!
3325451Speter *
3450476Speter * $FreeBSD$
3525451Speter */
3625451Speter
37138593Ssam#define	__constructor	__attribute__((constructor))
3825451Speter
3925660Speterstruct afswtch;
40138593Ssamstruct cmd;
4125451Speter
42138593Ssamtypedef	void c_func(const char *cmd, int arg, int s, const struct afswtch *afp);
43138593Ssamtypedef	void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp);
4444764Swpaul
45138593Ssamstruct cmd {
46138593Ssam	const char *c_name;
47138593Ssam	int	c_parameter;
48138593Ssam#define	NEXTARG		0xffffff	/* has following arg */
49138593Ssam#define	NEXTARG2	0xfffffe	/* has 2 following args */
50138593Ssam#define	OPTARG		0xfffffd	/* has optional following arg */
51138593Ssam	union {
52138593Ssam		c_func	*c_func;
53138593Ssam		c_func2	*c_func2;
54144818Sstefanf	} c_u;
55177799Ssam	int	c_iscloneop;
56138593Ssam	struct cmd *c_next;
57138593Ssam};
58138593Ssamvoid	cmd_register(struct cmd *);
5977217Sphk
60138671Ssamtypedef	void callback_func(int s, void *);
61138671Ssamvoid	callback_register(callback_func *, void *);
62138671Ssam
63138593Ssam/*
64138593Ssam * Macros for declaring command functions and initializing entries.
65138593Ssam */
66138593Ssam#define	DECL_CMD_FUNC(name, cmd, arg) \
67138593Ssam	void name(const char *cmd, int arg, int s, const struct afswtch *afp)
68138593Ssam#define	DECL_CMD_FUNC2(name, arg1, arg2) \
69138593Ssam	void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp)
70138593Ssam
71194799Sdelphij#define	DEF_CMD(name, param, func)	{ name, param, { .c_func = func }, 0, NULL }
72194799Sdelphij#define	DEF_CMD_ARG(name, func)		{ name, NEXTARG, { .c_func = func }, 0, NULL }
73194799Sdelphij#define	DEF_CMD_OPTARG(name, func)	{ name, OPTARG, { .c_func = func }, 0, NULL }
74194799Sdelphij#define	DEF_CMD_ARG2(name, func)	{ name, NEXTARG2, { .c_func2 = func }, 0, NULL }
75194799Sdelphij#define	DEF_CLONE_CMD(name, param, func) { name, param, { .c_func = func }, 1, NULL }
76194799Sdelphij#define	DEF_CLONE_CMD_ARG(name, func)	{ name, NEXTARG, { .c_func = func }, 1, NULL }
77138593Ssam
78166956Ssamstruct ifaddrs;
79138593Ssamstruct addrinfo;
80138593Ssam
81138593Ssamenum {
82138593Ssam	RIDADDR,
83138593Ssam	ADDR,
84138593Ssam	MASK,
85138593Ssam	DSTADDR,
86138593Ssam};
87138593Ssam
88138593Ssamstruct afswtch {
89138593Ssam	const char	*af_name;	/* as given on cmd line, e.g. "inet" */
90138593Ssam	short		af_af;		/* AF_* */
91139494Ssam	/*
92139494Ssam	 * Status is handled one of two ways; if there is an
93139494Ssam	 * address associated with the interface then the
94139494Ssam	 * associated address family af_status method is invoked
95139494Ssam	 * with the appropriate addressin info.  Otherwise, if
96139494Ssam	 * all possible info is to be displayed and af_other_status
97139494Ssam	 * is defined then it is invoked after all address status
98139494Ssam	 * is presented.
99139494Ssam	 */
100166956Ssam	void		(*af_status)(int, const struct ifaddrs *);
101139494Ssam	void		(*af_other_status)(int);
102138593Ssam					/* parse address method */
103138593Ssam	void		(*af_getaddr)(const char *, int);
104138593Ssam					/* parse prefix method (IPv6) */
105138593Ssam	void		(*af_getprefix)(const char *, int);
106138593Ssam	void		(*af_postproc)(int s, const struct afswtch *);
107138593Ssam	u_long		af_difaddr;	/* set dst if address ioctl */
108138593Ssam	u_long		af_aifaddr;	/* set if address ioctl */
109138593Ssam	void		*af_ridreq;	/* */
110138593Ssam	void		*af_addreq;	/* */
111138593Ssam	struct afswtch	*af_next;
112138593Ssam
113138593Ssam	/* XXX doesn't fit model */
114138593Ssam	void		(*af_status_tunnel)(int);
115138593Ssam	void		(*af_settunnel)(int s, struct addrinfo *srcres,
116138593Ssam				struct addrinfo *dstres);
117138593Ssam};
118138593Ssamvoid	af_register(struct afswtch *);
119138593Ssam
120138593Ssamstruct option {
121138593Ssam	const char *opt;
122138593Ssam	const char *opt_usage;
123138593Ssam	void	(*cb)(const char *arg);
124138593Ssam	struct option *next;
125138593Ssam};
126138593Ssamvoid	opt_register(struct option *);
127138593Ssam
128138593Ssamextern	struct ifreq ifr;
129138593Ssamextern	char name[IFNAMSIZ];	/* name of interface */
130138593Ssamextern	int allmedia;
131138593Ssamextern	int supmedia;
132148001Srwatsonextern	int printkeys;
133138593Ssamextern	int newaddr;
134138593Ssamextern	int verbose;
135138593Ssam
136138593Ssamvoid	setifcap(const char *, int value, int s, const struct afswtch *);
137138593Ssam
138138593Ssamvoid	Perror(const char *cmd);
139138593Ssamvoid	printb(const char *s, unsigned value, const char *bits);
140138593Ssam
141166956Ssamvoid	ifmaybeload(const char *name);
142138593Ssam
143160196Ssamtypedef void clone_callback_func(int, struct ifreq *);
144189096Srpaulovoid	clone_setdefcallback(const char *, clone_callback_func *);
145170531Ssam
146170531Ssam/*
147170531Ssam * XXX expose this so modules that neeed to know of any pending
148170531Ssam * operations on ifmedia can avoid cmd line ordering confusion.
149170531Ssam */
150170531Ssamstruct ifmediareq *ifmedia_getstate(int s);
151228571Sglebius
152228571Sglebiusvoid print_vhid(const struct ifaddrs *, const char *);
153228571Sglebius
154