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