Bring in new ifconfig(8) from FreeBSD6. It is more modular and flexible with
[dragonfly.git] / sbin / ifconfig / ifconfig.h
CommitLineData
984263bc
MD
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 *
ca74a0a2
SZ
34 * $FreeBSD: src/sbin/ifconfig/ifconfig.h,v 1.16.2.1 2005/07/21 12:25:40 rwatson Exp $
35 * $DragonFly: src/sbin/ifconfig/ifconfig.h,v 1.6 2006/04/02 03:33:59 sephe Exp $
984263bc
MD
36 */
37
ca74a0a2 38#define __constructor __attribute__((constructor))
984263bc 39
984263bc 40struct afswtch;
ca74a0a2 41struct cmd;
984263bc 42
ca74a0a2
SZ
43typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp);
44typedef void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp);
45
46struct cmd {
47 const char *c_name;
48 int c_parameter;
49#define NEXTARG 0xffffff /* has following arg */
50#define NEXTARG2 0xfffffe /* has 2 following args */
51#define OPTARG 0xfffffd /* has optional following arg */
52 union {
53 c_func *c_func;
54 c_func2 *c_func2;
55 } c_u;
56 struct cmd *c_next;
57};
58void cmd_register(struct cmd *);
59
60typedef void callback_func(int s, void *);
61void callback_register(callback_func *, void *);
62
63/*
64 * Macros for declaring command functions and initializing entries.
65 */
66#define DECL_CMD_FUNC(name, cmd, arg) \
67 void name(const char *cmd, int arg, int s, const struct afswtch *afp)
68#define DECL_CMD_FUNC2(name, arg1, arg2) \
69 void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp)
70
71#define DEF_CMD(name, param, func) { name, param, { .c_func = func } }
72#define DEF_CMD_ARG(name, func) \
73 { .c_name = name, .c_parameter = NEXTARG, .c_u = { .c_func = func } }
74#define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func } }
75#define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func } }
76
77struct rt_addrinfo;
78struct addrinfo;
79
80enum {
81 RIDADDR,
82 ADDR,
83 MASK,
84 DSTADDR,
85};
86
87struct afswtch {
88 const char *af_name; /* as given on cmd line, e.g. "inet" */
89 short af_af; /* AF_* */
90 /*
91 * Status is handled one of two ways; if there is an
92 * address associated with the interface then the
93 * associated address family af_status method is invoked
94 * with the appropriate addressin info. Otherwise, if
95 * all possible info is to be displayed and af_other_status
96 * is defined then it is invoked after all address status
97 * is presented.
98 */
99 void (*af_status)(int, const struct rt_addrinfo *);
100 void (*af_other_status)(int);
101 /* parse address method */
102 void (*af_getaddr)(const char *, int);
103 /* parse prefix method (IPv6) */
104 void (*af_getprefix)(const char *, int);
105 void (*af_postproc)(int s, const struct afswtch *);
106 u_long af_difaddr; /* set dst if address ioctl */
107 u_long af_aifaddr; /* set if address ioctl */
108 void *af_ridreq; /* */
109 void *af_addreq; /* */
110 struct afswtch *af_next;
111
112 /* XXX doesn't fit model */
113 void (*af_status_tunnel)(int);
114 void (*af_settunnel)(int s, struct addrinfo *srcres,
115 struct addrinfo *dstres);
116};
117void af_register(struct afswtch *);
118
119struct option {
120 const char *opt;
121 const char *opt_usage;
122 void (*cb)(const char *arg);
123 struct option *next;
124};
125void opt_register(struct option *);
126
127extern struct ifreq ifr;
128extern char name[IFNAMSIZ]; /* name of interface */
129extern int allmedia;
130extern int supmedia;
131extern int printkeys;
132extern int printname;
133extern int flags;
134extern int newaddr;
135extern int verbose;
136extern int setipdst;
137
138void setifcap(const char *, int value, int s, const struct afswtch *);
139
140void Perror(const char *cmd);
141void printb(const char *s, unsigned value, const char *bits);
142
143void ifmaybeload(char *);
144
145void clone_create(void);