17551d83pfg/*-
27551d83pfg * SPDX-License-Identifier: BSD-4-Clause
37551d83pfg *
454b5e92peter * Copyright (c) 1997 Peter Wemm.
554b5e92peter * All rights reserved.
654b5e92peter *
754b5e92peter * Redistribution and use in source and binary forms, with or without
854b5e92peter * modification, are permitted provided that the following conditions
954b5e92peter * are met:
1054b5e92peter * 1. Redistributions of source code must retain the above copyright
1154b5e92peter *    notice, this list of conditions and the following disclaimer.
1254b5e92peter * 2. Redistributions in binary form must reproduce the above copyright
1354b5e92peter *    notice, this list of conditions and the following disclaimer in the
1454b5e92peter *    documentation and/or other materials provided with the distribution.
1554b5e92peter * 3. All advertising materials mentioning features or use of this software
1654b5e92peter *    must display the following acknowledgement:
1754b5e92peter *      This product includes software developed for the FreeBSD Project
1854b5e92peter *	by Peter Wemm.
1954b5e92peter * 4. The name of the author may not be used to endorse or promote products
2054b5e92peter *    derived from this software without specific prior written permission.
2154b5e92peter *
2254b5e92peter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2354b5e92peter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2454b5e92peter * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2554b5e92peter * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2654b5e92peter * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2754b5e92peter * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2854b5e92peter * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2954b5e92peter * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3054b5e92peter * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3154b5e92peter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3254b5e92peter * SUCH DAMAGE.
3354b5e92peter *
3454b5e92peter * so there!
3554b5e92peter *
3676f0c92peter * $FreeBSD$
3754b5e92peter */
3854b5e92peter
3968cd876sam#define	__constructor	__attribute__((constructor))
4054b5e92peter
416f36e2epeterstruct afswtch;
4268cd876samstruct cmd;
4354b5e92peter
4468cd876samtypedef	void c_func(const char *cmd, int arg, int s, const struct afswtch *afp);
4568cd876samtypedef	void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp);
4668cd876sam
4768cd876samstruct cmd {
4868cd876sam	const char *c_name;
4968cd876sam	int	c_parameter;
5068cd876sam#define	NEXTARG		0xffffff	/* has following arg */
5168cd876sam#define	NEXTARG2	0xfffffe	/* has 2 following args */
5268cd876sam#define	OPTARG		0xfffffd	/* has optional following arg */
5368cd876sam	union {
5468cd876sam		c_func	*c_func;
5568cd876sam		c_func2	*c_func2;
5693dc7c6stefanf	} c_u;
571cec369sam	int	c_iscloneop;
5868cd876sam	struct cmd *c_next;
5968cd876sam};
6068cd876samvoid	cmd_register(struct cmd *);
6168cd876sam
62476c9d3samtypedef	void callback_func(int s, void *);
63476c9d3samvoid	callback_register(callback_func *, void *);
64476c9d3sam
6568cd876sam/*
6668cd876sam * Macros for declaring command functions and initializing entries.
6768cd876sam */
6868cd876sam#define	DECL_CMD_FUNC(name, cmd, arg) \
6968cd876sam	void name(const char *cmd, int arg, int s, const struct afswtch *afp)
7068cd876sam#define	DECL_CMD_FUNC2(name, arg1, arg2) \
7168cd876sam	void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp)
7268cd876sam
73e55dc5cdelphij#define	DEF_CMD(name, param, func)	{ name, param, { .c_func = func }, 0, NULL }
74e55dc5cdelphij#define	DEF_CMD_ARG(name, func)		{ name, NEXTARG, { .c_func = func }, 0, NULL }
75e55dc5cdelphij#define	DEF_CMD_OPTARG(name, func)	{ name, OPTARG, { .c_func = func }, 0, NULL }
76e55dc5cdelphij#define	DEF_CMD_ARG2(name, func)	{ name, NEXTARG2, { .c_func2 = func }, 0, NULL }
77e55dc5cdelphij#define	DEF_CLONE_CMD(name, param, func) { name, param, { .c_func = func }, 1, NULL }
78e55dc5cdelphij#define	DEF_CLONE_CMD_ARG(name, func)	{ name, NEXTARG, { .c_func = func }, 1, NULL }
7980ccb24bryanv#define	DEF_CLONE_CMD_ARG2(name, func)	{ name, NEXTARG2, { .c_func2 = func }, 1, NULL }
8068cd876sam
81cd822ecsamstruct ifaddrs;
8268cd876samstruct addrinfo;
8368cd876sam
8468cd876samenum {
8568cd876sam	RIDADDR,
8668cd876sam	ADDR,
8768cd876sam	MASK,
8868cd876sam	DSTADDR,
8968cd876sam};
9068cd876sam
9168cd876samstruct afswtch {
9268cd876sam	const char	*af_name;	/* as given on cmd line, e.g. "inet" */
9368cd876sam	short		af_af;		/* AF_* */
9465cf57fsam	/*
9565cf57fsam	 * Status is handled one of two ways; if there is an
9665cf57fsam	 * address associated with the interface then the
9765cf57fsam	 * associated address family af_status method is invoked
9865cf57fsam	 * with the appropriate addressin info.  Otherwise, if
9965cf57fsam	 * all possible info is to be displayed and af_other_status
10065cf57fsam	 * is defined then it is invoked after all address status
10165cf57fsam	 * is presented.
10265cf57fsam	 */
103cd822ecsam	void		(*af_status)(int, const struct ifaddrs *);
10465cf57fsam	void		(*af_other_status)(int);
10568cd876sam					/* parse address method */
10668cd876sam	void		(*af_getaddr)(const char *, int);
10768cd876sam					/* parse prefix method (IPv6) */
10868cd876sam	void		(*af_getprefix)(const char *, int);
10968cd876sam	void		(*af_postproc)(int s, const struct afswtch *);
11068cd876sam	u_long		af_difaddr;	/* set dst if address ioctl */
11168cd876sam	u_long		af_aifaddr;	/* set if address ioctl */
11268cd876sam	void		*af_ridreq;	/* */
11368cd876sam	void		*af_addreq;	/* */
11468cd876sam	struct afswtch	*af_next;
11568cd876sam
11668cd876sam	/* XXX doesn't fit model */
11768cd876sam	void		(*af_status_tunnel)(int);
11868cd876sam	void		(*af_settunnel)(int s, struct addrinfo *srcres,
11968cd876sam				struct addrinfo *dstres);
12068cd876sam};
12168cd876samvoid	af_register(struct afswtch *);
12268cd876sam
12368cd876samstruct option {
12468cd876sam	const char *opt;
12568cd876sam	const char *opt_usage;
12668cd876sam	void	(*cb)(const char *arg);
12768cd876sam	struct option *next;
12868cd876sam};
12968cd876samvoid	opt_register(struct option *);
13068cd876sam
13168cd876samextern	struct ifreq ifr;
13268cd876samextern	char name[IFNAMSIZ];	/* name of interface */
13368cd876samextern	int allmedia;
13468cd876samextern	int supmedia;
1352df666arwatsonextern	int printkeys;
13668cd876samextern	int newaddr;
13768cd876samextern	int verbose;
13833ef68fkpextern	int printifname;
139dde41c9gallatinextern	int exit_code;
14068cd876sam
14168cd876samvoid	setifcap(const char *, int value, int s, const struct afswtch *);
14268cd876sam
14368cd876samvoid	Perror(const char *cmd);
14468cd876samvoid	printb(const char *s, unsigned value, const char *bits);
14568cd876sam
146cd822ecsamvoid	ifmaybeload(const char *name);
14768cd876sam
1485fe5db7samtypedef void clone_callback_func(int, struct ifreq *);
1492af9e81rpaulovoid	clone_setdefcallback(const char *, clone_callback_func *);
1503271b46sam
1510c02adamelifarovoid	sfp_status(int s, struct ifreq *ifr, int verbose);
1520c02adamelifaro
1533271b46sam/*
1543271b46sam * XXX expose this so modules that neeed to know of any pending
1553271b46sam * operations on ifmedia can avoid cmd line ordering confusion.
1563271b46sam */
1573271b46samstruct ifmediareq *ifmedia_getstate(int s);
15827a36f6glebius
15927a36f6glebiusvoid print_vhid(const struct ifaddrs *, const char *);
16027a36f6glebius
161