* Sync comment with code's reality.
[dragonfly.git] / usr.sbin / ppp / bundle.h
1 /*-
2  * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
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  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/usr.sbin/ppp/bundle.h,v 1.33.2.8 2002/09/01 02:12:22 brian Exp $
27  * $DragonFly: src/usr.sbin/ppp/bundle.h,v 1.2 2003/06/17 04:30:00 dillon Exp $
28  */
29
30 #define PHASE_DEAD              0       /* Link is dead */
31 #define PHASE_ESTABLISH         1       /* Establishing link */
32 #define PHASE_AUTHENTICATE      2       /* Being authenticated */
33 #define PHASE_NETWORK           3       /* We're alive ! */
34 #define PHASE_TERMINATE         4       /* Terminating link */
35
36 /* cfg.opt bit settings */
37 #define OPT_FILTERDECAP 0x0001
38 #define OPT_IDCHECK     0x0002
39 #define OPT_IFACEALIAS  0x0004
40 #ifndef NOINET6
41 #define OPT_IPCP        0x0008
42 #define OPT_IPV6CP      0x0010
43 #endif
44 #define OPT_KEEPSESSION 0x0020
45 #define OPT_LOOPBACK    0x0040
46 #define OPT_PASSWDAUTH  0x0080
47 #define OPT_PROXY       0x0100
48 #define OPT_PROXYALL    0x0200
49 #define OPT_SROUTES     0x0400
50 #define OPT_TCPMSSFIXUP 0x0800
51 #define OPT_THROUGHPUT  0x1000
52 #define OPT_UTMP        0x2000
53
54 #define MAX_ENDDISC_CLASS 5
55
56 #define Enabled(b, o) ((b)->cfg.opt & (o))
57
58 /* AutoAdjust() values */
59 #define AUTO_UP         1
60 #define AUTO_DOWN       2
61
62 struct sockaddr_un;
63 struct datalink;
64 struct physical;
65 struct link;
66 struct server;
67 struct prompt;
68 struct iface;
69
70 struct bundle {
71   struct fdescriptor desc;    /* really all our datalinks */
72   int unit;                   /* The device/interface unit number */
73
74   struct {
75     char Name[20];            /* The /dev/XXXX name */
76     int fd;                   /* The /dev/XXXX descriptor */
77     unsigned header : 1;      /* Family header sent & received ? */
78   } dev;
79
80   u_long bandwidth;           /* struct tuninfo speed */
81   struct iface *iface;        /* Interface information */
82
83   int routing_seq;            /* The current routing sequence number */
84   u_int phase;                /* Curent phase */
85
86   struct {
87     int all;                  /* Union of all physical::type's */
88     int open;                 /* Union of all open physical::type's */
89   } phys_type;
90
91   unsigned CleaningUp : 1;    /* Going to exit.... */
92   unsigned NatEnabled : 1;    /* Are we using libalias ? */
93
94   struct fsm_parent fsm;      /* Our callback functions */
95   struct datalink *links;     /* Our data links */
96
97   time_t upat;                /* When the link came up */
98
99   struct {
100     struct {
101       int timeout;              /* NCP Idle timeout value */
102       int min_timeout;          /* Don't idle out before this */
103     } idle;
104     struct {
105       char name[AUTHLEN];     /* PAP/CHAP system name */
106       char key[AUTHLEN];      /* PAP/CHAP key */
107     } auth;
108     unsigned opt;             /* Uses OPT_ bits from above */
109     char label[50];           /* last thing `load'ed */
110     u_short ifqueue;          /* Interface queue size */
111
112     struct {
113       int timeout;            /* How long to leave the output queue choked */
114     } choked;
115   } cfg;
116
117   struct ncp ncp;
118
119   struct {
120     struct filter in;         /* incoming packet filter */
121     struct filter out;        /* outgoing packet filter */
122     struct filter dial;       /* dial-out packet filter */
123     struct filter alive;      /* keep-alive packet filter */
124   } filter;
125
126   struct {
127     struct pppTimer timer;    /* timeout after cfg.idle_timeout */
128     time_t done;
129   } idle;
130
131 #ifndef NORADIUS
132   struct {
133     struct pppTimer timer;
134     time_t done;
135   } session;
136 #endif
137
138   struct {
139     int fd;                   /* write status here */
140   } notify;
141
142   struct {
143     struct pppTimer timer;    /* choked output queue timer */
144   } choked;
145
146 #ifndef NORADIUS
147   struct radius radius;       /* Info retrieved from radius server */
148   struct radacct radacct;
149 #endif
150 };
151
152 #define descriptor2bundle(d) \
153   ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
154
155 extern struct bundle *bundle_Create(const char *, int, int);
156 extern void bundle_Destroy(struct bundle *);
157 extern const char *bundle_PhaseName(struct bundle *);
158 #define bundle_Phase(b) ((b)->phase)
159 extern void bundle_NewPhase(struct bundle *, u_int);
160 extern void bundle_LinksRemoved(struct bundle *);
161 extern void bundle_Close(struct bundle *, const char *, int);
162 extern void bundle_Down(struct bundle *, int);
163 extern void bundle_Open(struct bundle *, const char *, int, int);
164 extern void bundle_LinkClosed(struct bundle *, struct datalink *);
165
166 extern int bundle_ShowLinks(struct cmdargs const *);
167 extern int bundle_ShowStatus(struct cmdargs const *);
168 extern void bundle_StartIdleTimer(struct bundle *, unsigned secs);
169 extern void bundle_SetIdleTimer(struct bundle *, int, int);
170 extern void bundle_StopIdleTimer(struct bundle *);
171 extern int bundle_IsDead(struct bundle *);
172 extern struct datalink *bundle2datalink(struct bundle *, const char *);
173
174 #ifndef NORADIUS
175 extern void bundle_StartSessionTimer(struct bundle *, unsigned secs);
176 extern void bundle_StopSessionTimer(struct bundle *);
177 #endif
178
179 extern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *);
180 extern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *);
181
182 extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
183
184 extern int bundle_DatalinkClone(struct bundle *, struct datalink *,
185                                 const char *);
186 extern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
187 extern void bundle_CleanDatalinks(struct bundle *);
188 extern void bundle_SetLabel(struct bundle *, const char *);
189 extern const char *bundle_GetLabel(struct bundle *);
190 extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
191 extern int bundle_LinkSize(void);
192 extern void bundle_ReceiveDatalink(struct bundle *, int);
193 extern int bundle_SetMode(struct bundle *, struct datalink *, int);
194 extern int bundle_RenameDatalink(struct bundle *, struct datalink *,
195                                  const char *);
196 extern void bundle_setsid(struct bundle *, int);
197 extern void bundle_LockTun(struct bundle *);
198 extern int bundle_HighestState(struct bundle *);
199 extern int bundle_Exception(struct bundle *, int);
200 extern void bundle_AdjustFilters(struct bundle *, struct ncpaddr *,
201                                  struct ncpaddr *);
202 extern void bundle_AdjustDNS(struct bundle *);
203 extern void bundle_CalculateBandwidth(struct bundle *);
204 extern void bundle_AutoAdjust(struct bundle *, int, int);
205 extern int bundle_WantAutoloadTimer(struct bundle *);
206 extern void bundle_ChangedPID(struct bundle *);
207 extern void bundle_Notify(struct bundle *, char);
208 extern int bundle_Uptime(struct bundle *);