ifconfig.h revision 148001
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: head/sbin/ifconfig/ifconfig.h 148001 2005-07-14 18:33:21Z rwatson $
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;
55138593Ssam	struct cmd *c_next;
56138593Ssam};
57138593Ssamvoid	cmd_register(struct cmd *);
5877217Sphk
59138671Ssamtypedef	void callback_func(int s, void *);
60138671Ssamvoid	callback_register(callback_func *, void *);
61138671Ssam
62138593Ssam/*
63138593Ssam * Macros for declaring command functions and initializing entries.
64138593Ssam */
65138593Ssam#define	DECL_CMD_FUNC(name, cmd, arg) \
66138593Ssam	void name(const char *cmd, int arg, int s, const struct afswtch *afp)
67138593Ssam#define	DECL_CMD_FUNC2(name, arg1, arg2) \
68138593Ssam	void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp)
69138593Ssam
70138593Ssam#define	DEF_CMD(name, param, func)	{ name, param, { .c_func = func } }
71138593Ssam#define	DEF_CMD_ARG(name, func)		{ name, NEXTARG, { .c_func = func } }
72138593Ssam#define	DEF_CMD_OPTARG(name, func)	{ name, OPTARG, { .c_func = func } }
73138593Ssam#define	DEF_CMD_ARG2(name, func)	{ name, NEXTARG2, { .c_func2 = func } }
74138593Ssam
75138593Ssamstruct rt_addrinfo;
76138593Ssamstruct addrinfo;
77138593Ssam
78138593Ssamenum {
79138593Ssam	RIDADDR,
80138593Ssam	ADDR,
81138593Ssam	MASK,
82138593Ssam	DSTADDR,
83138593Ssam};
84138593Ssam
85138593Ssamstruct afswtch {
86138593Ssam	const char	*af_name;	/* as given on cmd line, e.g. "inet" */
87138593Ssam	short		af_af;		/* AF_* */
88139494Ssam	/*
89139494Ssam	 * Status is handled one of two ways; if there is an
90139494Ssam	 * address associated with the interface then the
91139494Ssam	 * associated address family af_status method is invoked
92139494Ssam	 * with the appropriate addressin info.  Otherwise, if
93139494Ssam	 * all possible info is to be displayed and af_other_status
94139494Ssam	 * is defined then it is invoked after all address status
95139494Ssam	 * is presented.
96139494Ssam	 */
97138593Ssam	void		(*af_status)(int, const struct rt_addrinfo *);
98139494Ssam	void		(*af_other_status)(int);
99138593Ssam					/* parse address method */
100138593Ssam	void		(*af_getaddr)(const char *, int);
101138593Ssam					/* parse prefix method (IPv6) */
102138593Ssam	void		(*af_getprefix)(const char *, int);
103138593Ssam	void		(*af_postproc)(int s, const struct afswtch *);
104138593Ssam	u_long		af_difaddr;	/* set dst if address ioctl */
105138593Ssam	u_long		af_aifaddr;	/* set if address ioctl */
106138593Ssam	void		*af_ridreq;	/* */
107138593Ssam	void		*af_addreq;	/* */
108138593Ssam	struct afswtch	*af_next;
109138593Ssam
110138593Ssam	/* XXX doesn't fit model */
111138593Ssam	void		(*af_status_tunnel)(int);
112138593Ssam	void		(*af_settunnel)(int s, struct addrinfo *srcres,
113138593Ssam				struct addrinfo *dstres);
114138593Ssam};
115138593Ssamvoid	af_register(struct afswtch *);
116138593Ssam
117138593Ssamstruct option {
118138593Ssam	const char *opt;
119138593Ssam	const char *opt_usage;
120138593Ssam	void	(*cb)(const char *arg);
121138593Ssam	struct option *next;
122138593Ssam};
123138593Ssamvoid	opt_register(struct option *);
124138593Ssam
125138593Ssamextern	struct ifreq ifr;
126138593Ssamextern	char name[IFNAMSIZ];	/* name of interface */
127138593Ssamextern	int allmedia;
128138593Ssamextern	int supmedia;
129148001Srwatsonextern	int printkeys;
130138593Ssamextern	int printname;
131138593Ssamextern	int flags;
132138593Ssamextern	int newaddr;
133138593Ssamextern	int verbose;
134138593Ssamextern	int setipdst;
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
141138593Ssamvoid	ifmaybeload(char *name);
142138593Ssam
143138593Ssamvoid	clone_create(void);
144