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 }
77284347Sbryanv#define	DEF_CLONE_CMD_ARG2(name, func)	{ name, NEXTARG2, { .c_func2 = func }, 1, NULL }
78138593Ssam
79166956Ssamstruct ifaddrs;
80138593Ssamstruct addrinfo;
81138593Ssam
82138593Ssamenum {
83138593Ssam	RIDADDR,
84138593Ssam	ADDR,
85138593Ssam	MASK,
86138593Ssam	DSTADDR,
87138593Ssam};
88138593Ssam
89138593Ssamstruct afswtch {
90138593Ssam	const char	*af_name;	/* as given on cmd line, e.g. "inet" */
91138593Ssam	short		af_af;		/* AF_* */
92139494Ssam	/*
93139494Ssam	 * Status is handled one of two ways; if there is an
94139494Ssam	 * address associated with the interface then the
95139494Ssam	 * associated address family af_status method is invoked
96139494Ssam	 * with the appropriate addressin info.  Otherwise, if
97139494Ssam	 * all possible info is to be displayed and af_other_status
98139494Ssam	 * is defined then it is invoked after all address status
99139494Ssam	 * is presented.
100139494Ssam	 */
101166956Ssam	void		(*af_status)(int, const struct ifaddrs *);
102139494Ssam	void		(*af_other_status)(int);
103138593Ssam					/* parse address method */
104138593Ssam	void		(*af_getaddr)(const char *, int);
105138593Ssam					/* parse prefix method (IPv6) */
106138593Ssam	void		(*af_getprefix)(const char *, int);
107138593Ssam	void		(*af_postproc)(int s, const struct afswtch *);
108138593Ssam	u_long		af_difaddr;	/* set dst if address ioctl */
109138593Ssam	u_long		af_aifaddr;	/* set if address ioctl */
110138593Ssam	void		*af_ridreq;	/* */
111138593Ssam	void		*af_addreq;	/* */
112138593Ssam	struct afswtch	*af_next;
113138593Ssam
114138593Ssam	/* XXX doesn't fit model */
115138593Ssam	void		(*af_status_tunnel)(int);
116138593Ssam	void		(*af_settunnel)(int s, struct addrinfo *srcres,
117138593Ssam				struct addrinfo *dstres);
118138593Ssam};
119138593Ssamvoid	af_register(struct afswtch *);
120138593Ssam
121138593Ssamstruct option {
122138593Ssam	const char *opt;
123138593Ssam	const char *opt_usage;
124138593Ssam	void	(*cb)(const char *arg);
125138593Ssam	struct option *next;
126138593Ssam};
127138593Ssamvoid	opt_register(struct option *);
128138593Ssam
129138593Ssamextern	struct ifreq ifr;
130138593Ssamextern	char name[IFNAMSIZ];	/* name of interface */
131138593Ssamextern	int allmedia;
132138593Ssamextern	int supmedia;
133148001Srwatsonextern	int printkeys;
134138593Ssamextern	int newaddr;
135138593Ssamextern	int verbose;
136296425Skpextern	int printifname;
137138593Ssam
138138593Ssamvoid	setifcap(const char *, int value, int s, const struct afswtch *);
139138593Ssam
140138593Ssamvoid	Perror(const char *cmd);
141138593Ssamvoid	printb(const char *s, unsigned value, const char *bits);
142138593Ssam
143166956Ssamvoid	ifmaybeload(const char *name);
144138593Ssam
145160196Ssamtypedef void clone_callback_func(int, struct ifreq *);
146189096Srpaulovoid	clone_setdefcallback(const char *, clone_callback_func *);
147170531Ssam
148286810Smelifarovoid	sfp_status(int s, struct ifreq *ifr, int verbose);
149286810Smelifaro
150170531Ssam/*
151170531Ssam * XXX expose this so modules that neeed to know of any pending
152170531Ssam * operations on ifmedia can avoid cmd line ordering confusion.
153170531Ssam */
154170531Ssamstruct ifmediareq *ifmedia_getstate(int s);
155228571Sglebius
156228571Sglebiusvoid print_vhid(const struct ifaddrs *, const char *);
157228571Sglebius
158