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