xref: /freebsd/sbin/ifconfig/ifconfig.h (revision c508bf7a545dd0acbcdd906fb119c9f8222e5026)
19906480aSPeter Wemm /*
29906480aSPeter Wemm  * Copyright (c) 1997 Peter Wemm.
39906480aSPeter Wemm  * All rights reserved.
49906480aSPeter Wemm  *
59906480aSPeter Wemm  * Redistribution and use in source and binary forms, with or without
69906480aSPeter Wemm  * modification, are permitted provided that the following conditions
79906480aSPeter Wemm  * are met:
89906480aSPeter Wemm  * 1. Redistributions of source code must retain the above copyright
99906480aSPeter Wemm  *    notice, this list of conditions and the following disclaimer.
109906480aSPeter Wemm  * 2. Redistributions in binary form must reproduce the above copyright
119906480aSPeter Wemm  *    notice, this list of conditions and the following disclaimer in the
129906480aSPeter Wemm  *    documentation and/or other materials provided with the distribution.
139906480aSPeter Wemm  * 3. All advertising materials mentioning features or use of this software
149906480aSPeter Wemm  *    must display the following acknowledgement:
159906480aSPeter Wemm  *      This product includes software developed for the FreeBSD Project
169906480aSPeter Wemm  *	by Peter Wemm.
179906480aSPeter Wemm  * 4. The name of the author may not be used to endorse or promote products
189906480aSPeter Wemm  *    derived from this software without specific prior written permission.
199906480aSPeter Wemm  *
209906480aSPeter Wemm  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
219906480aSPeter Wemm  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
229906480aSPeter Wemm  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
239906480aSPeter Wemm  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
249906480aSPeter Wemm  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
259906480aSPeter Wemm  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
269906480aSPeter Wemm  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
279906480aSPeter Wemm  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
289906480aSPeter Wemm  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
299906480aSPeter Wemm  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
309906480aSPeter Wemm  * SUCH DAMAGE.
319906480aSPeter Wemm  *
329906480aSPeter Wemm  * so there!
339906480aSPeter Wemm  *
347f3dea24SPeter Wemm  * $FreeBSD$
359906480aSPeter Wemm  */
369906480aSPeter Wemm 
375faf8dcbSSam Leffler #define	__constructor	__attribute__((constructor))
389906480aSPeter Wemm 
395faf8dcbSSam Leffler struct afswtch;
405faf8dcbSSam Leffler struct cmd;
415faf8dcbSSam Leffler 
425faf8dcbSSam Leffler typedef	void c_func(const char *cmd, int arg, int s, const struct afswtch *afp);
435faf8dcbSSam Leffler typedef	void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp);
445faf8dcbSSam Leffler 
455faf8dcbSSam Leffler struct cmd {
465faf8dcbSSam Leffler 	const char *c_name;
475faf8dcbSSam Leffler 	int	c_parameter;
485faf8dcbSSam Leffler #define	NEXTARG		0xffffff	/* has following arg */
495faf8dcbSSam Leffler #define	NEXTARG2	0xfffffe	/* has 2 following args */
505faf8dcbSSam Leffler #define	OPTARG		0xfffffd	/* has optional following arg */
515faf8dcbSSam Leffler 	union {
525faf8dcbSSam Leffler 		c_func	*c_func;
535faf8dcbSSam Leffler 		c_func2	*c_func2;
54c508bf7aSStefan Farfeleder 	} c_u;
555faf8dcbSSam Leffler 	struct cmd *c_next;
565faf8dcbSSam Leffler };
575faf8dcbSSam Leffler void	cmd_register(struct cmd *);
585faf8dcbSSam Leffler 
5958ac5e5bSSam Leffler typedef	void callback_func(int s, void *);
6058ac5e5bSSam Leffler void	callback_register(callback_func *, void *);
6158ac5e5bSSam Leffler 
625faf8dcbSSam Leffler /*
635faf8dcbSSam Leffler  * Macros for declaring command functions and initializing entries.
645faf8dcbSSam Leffler  */
655faf8dcbSSam Leffler #define	DECL_CMD_FUNC(name, cmd, arg) \
665faf8dcbSSam Leffler 	void name(const char *cmd, int arg, int s, const struct afswtch *afp)
675faf8dcbSSam Leffler #define	DECL_CMD_FUNC2(name, arg1, arg2) \
685faf8dcbSSam Leffler 	void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp)
695faf8dcbSSam Leffler 
705faf8dcbSSam Leffler #define	DEF_CMD(name, param, func)	{ name, param, { .c_func = func } }
715faf8dcbSSam Leffler #define	DEF_CMD_ARG(name, func)		{ name, NEXTARG, { .c_func = func } }
725faf8dcbSSam Leffler #define	DEF_CMD_OPTARG(name, func)	{ name, OPTARG, { .c_func = func } }
735faf8dcbSSam Leffler #define	DEF_CMD_ARG2(name, func)	{ name, NEXTARG2, { .c_func2 = func } }
745faf8dcbSSam Leffler 
755faf8dcbSSam Leffler struct rt_addrinfo;
765faf8dcbSSam Leffler struct addrinfo;
775faf8dcbSSam Leffler 
785faf8dcbSSam Leffler enum {
795faf8dcbSSam Leffler 	RIDADDR,
805faf8dcbSSam Leffler 	ADDR,
815faf8dcbSSam Leffler 	MASK,
825faf8dcbSSam Leffler 	DSTADDR,
835faf8dcbSSam Leffler };
845faf8dcbSSam Leffler 
855faf8dcbSSam Leffler struct afswtch {
865faf8dcbSSam Leffler 	const char	*af_name;	/* as given on cmd line, e.g. "inet" */
875faf8dcbSSam Leffler 	short		af_af;		/* AF_* */
8890c4b74cSSam Leffler 	/*
8990c4b74cSSam Leffler 	 * Status is handled one of two ways; if there is an
9090c4b74cSSam Leffler 	 * address associated with the interface then the
9190c4b74cSSam Leffler 	 * associated address family af_status method is invoked
9290c4b74cSSam Leffler 	 * with the appropriate addressin info.  Otherwise, if
9390c4b74cSSam Leffler 	 * all possible info is to be displayed and af_other_status
9490c4b74cSSam Leffler 	 * is defined then it is invoked after all address status
9590c4b74cSSam Leffler 	 * is presented.
9690c4b74cSSam Leffler 	 */
975faf8dcbSSam Leffler 	void		(*af_status)(int, const struct rt_addrinfo *);
9890c4b74cSSam Leffler 	void		(*af_other_status)(int);
995faf8dcbSSam Leffler 					/* parse address method */
1005faf8dcbSSam Leffler 	void		(*af_getaddr)(const char *, int);
1015faf8dcbSSam Leffler 					/* parse prefix method (IPv6) */
1025faf8dcbSSam Leffler 	void		(*af_getprefix)(const char *, int);
1035faf8dcbSSam Leffler 	void		(*af_postproc)(int s, const struct afswtch *);
1045faf8dcbSSam Leffler 	u_long		af_difaddr;	/* set dst if address ioctl */
1055faf8dcbSSam Leffler 	u_long		af_aifaddr;	/* set if address ioctl */
1065faf8dcbSSam Leffler 	void		*af_ridreq;	/* */
1075faf8dcbSSam Leffler 	void		*af_addreq;	/* */
1085faf8dcbSSam Leffler 	struct afswtch	*af_next;
1095faf8dcbSSam Leffler 
1105faf8dcbSSam Leffler 	/* XXX doesn't fit model */
1115faf8dcbSSam Leffler 	void		(*af_status_tunnel)(int);
1125faf8dcbSSam Leffler 	void		(*af_settunnel)(int s, struct addrinfo *srcres,
1135faf8dcbSSam Leffler 				struct addrinfo *dstres);
1145faf8dcbSSam Leffler };
1155faf8dcbSSam Leffler void	af_register(struct afswtch *);
1165faf8dcbSSam Leffler 
1175faf8dcbSSam Leffler struct option {
1185faf8dcbSSam Leffler 	const char *opt;
1195faf8dcbSSam Leffler 	const char *opt_usage;
1205faf8dcbSSam Leffler 	void	(*cb)(const char *arg);
1215faf8dcbSSam Leffler 	struct option *next;
1225faf8dcbSSam Leffler };
1235faf8dcbSSam Leffler void	opt_register(struct option *);
1245faf8dcbSSam Leffler 
1255faf8dcbSSam Leffler extern	struct ifreq ifr;
126a4fa9864SBrooks Davis extern	char name[IFNAMSIZ];	/* name of interface */
1279906480aSPeter Wemm extern	int allmedia;
128ca299b1fSPoul-Henning Kamp extern	int supmedia;
1295faf8dcbSSam Leffler extern	int printname;
1305faf8dcbSSam Leffler extern	int flags;
1315faf8dcbSSam Leffler extern	int newaddr;
1325faf8dcbSSam Leffler extern	int verbose;
1335faf8dcbSSam Leffler extern	int setipdst;
1349906480aSPeter Wemm 
1355faf8dcbSSam Leffler void	setifcap(const char *, int value, int s, const struct afswtch *);
13697ed1257SBill Paul 
1375faf8dcbSSam Leffler void	Perror(const char *cmd);
1385faf8dcbSSam Leffler void	printb(const char *s, unsigned value, const char *bits);
139419d8080SPoul-Henning Kamp 
1405faf8dcbSSam Leffler void	ifmaybeload(char *name);
1415faf8dcbSSam Leffler 
1425faf8dcbSSam Leffler void	clone_create(void);
143