bundle.h revision 53298
1253923Smarcel/*-
2263409Smarcel * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3253923Smarcel * All rights reserved.
4253923Smarcel *
5253923Smarcel * Redistribution and use in source and binary forms, with or without
6253923Smarcel * modification, are permitted provided that the following conditions
7253923Smarcel * are met:
8253923Smarcel * 1. Redistributions of source code must retain the above copyright
9253923Smarcel *    notice, this list of conditions and the following disclaimer.
10253923Smarcel * 2. Redistributions in binary form must reproduce the above copyright
11253923Smarcel *    notice, this list of conditions and the following disclaimer in the
12253923Smarcel *    documentation and/or other materials provided with the distribution.
13253923Smarcel *
14253923Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15253923Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16253923Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17253923Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18253923Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19253923Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20253923Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21253923Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22253923Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23253923Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24253923Smarcel * SUCH DAMAGE.
25253923Smarcel *
26253923Smarcel * $FreeBSD: head/usr.sbin/ppp/bundle.h 53298 1999-11-17 21:12:35Z brian $
27253923Smarcel */
28253923Smarcel
29253923Smarcel#define	PHASE_DEAD		0	/* Link is dead */
30253923Smarcel#define	PHASE_ESTABLISH		1	/* Establishing link */
31263409Smarcel#define	PHASE_AUTHENTICATE	2	/* Being authenticated */
32263382Smarcel#define	PHASE_NETWORK		3	/* We're alive ! */
33263537Smarcel#define	PHASE_TERMINATE		4	/* Terminating link */
34279128Smarcel
35253923Smarcel/* cfg.opt bit settings */
36253923Smarcel#define OPT_IDCHECK	0x0001
37279128Smarcel#define OPT_IFACEALIAS	0x0002
38253923Smarcel#define OPT_KEEPSESSION	0x0004
39263537Smarcel#define OPT_LOOPBACK	0x0008
40263466Smarcel#define OPT_PASSWDAUTH	0x0010
41253923Smarcel#define OPT_PROXY	0x0020
42253923Smarcel#define OPT_PROXYALL	0x0040
43266176Smarcel#define OPT_SROUTES	0x0080
44263382Smarcel#define OPT_THROUGHPUT	0x0100
45253923Smarcel#define OPT_UTMP	0x0200
46253923Smarcel
47263487Smarcel#define MAX_ENDDISC_CLASS 5
48263487Smarcel
49263487Smarcel#define Enabled(b, o) ((b)->cfg.opt & (o))
50263487Smarcel
51263672Smarcel/* AutoAdjust() values */
52263487Smarcel#define AUTO_UP		1
53289349Semaste#define AUTO_DOWN	2
54263672Smarcel
55263487Smarcelstruct sockaddr_un;
56263487Smarcelstruct datalink;
57263487Smarcelstruct physical;
58263487Smarcelstruct link;
59263487Smarcelstruct server;
60263487Smarcelstruct prompt;
61263487Smarcelstruct iface;
62263487Smarcel
63284883Smarcelstruct bundle {
64292082Simp  struct descriptor desc;     /* really all our datalinks */
65263487Smarcel  int unit;                   /* The device/interface unit number */
66263487Smarcel
67263487Smarcel  struct {
68263409Smarcel    char Name[20];            /* The /dev/XXXX name */
69263537Smarcel    int fd;                   /* The /dev/XXXX descriptor */
70253923Smarcel  } dev;
71263487Smarcel
72263487Smarcel  u_long bandwidth;           /* struct tuninfo speed */
73263487Smarcel  struct iface *iface;        /* Interface information */
74263487Smarcel
75263487Smarcel  int routing_seq;            /* The current routing sequence number */
76263487Smarcel  u_int phase;                /* Curent phase */
77263487Smarcel
78263487Smarcel  struct {
79263487Smarcel    int all;                  /* Union of all physical::type's */
80263487Smarcel    int open;                 /* Union of all open physical::type's */
81263487Smarcel  } phys_type;
82263487Smarcel
83263487Smarcel  unsigned CleaningUp : 1;    /* Going to exit.... */
84263487Smarcel  unsigned NatEnabled : 1;    /* Are we using libalias ? */
85253923Smarcel
86253923Smarcel  struct fsm_parent fsm;      /* Our callback functions */
87253923Smarcel  struct datalink *links;     /* Our data links */
88263409Smarcel
89253923Smarcel  time_t upat;                /* When the link came up */
90263409Smarcel
91263409Smarcel  struct {
92263409Smarcel    struct {
93263409Smarcel      int timeout;              /* NCP Idle timeout value */
94253923Smarcel      int min_timeout;          /* Don't idle out before this */
95253923Smarcel    } idle;
96253923Smarcel    struct {
97253923Smarcel      char name[AUTHLEN];     /* PAP/CHAP system name */
98253923Smarcel      char key[AUTHLEN];      /* PAP/CHAP key */
99253923Smarcel    } auth;
100263409Smarcel    unsigned opt;             /* Uses OPT_ bits from above */
101253923Smarcel    char label[50];           /* last thing `load'ed */
102253923Smarcel    u_short mtu;              /* Interface mtu */
103253923Smarcel
104253923Smarcel    struct {
105253923Smarcel      int timeout;            /* How long to leave the output queue choked */
106253923Smarcel    } choked;
107253923Smarcel  } cfg;
108263537Smarcel
109263537Smarcel  struct {
110263537Smarcel    struct ipcp ipcp;         /* Our IPCP FSM */
111263537Smarcel    struct mp mp;             /* Our MP */
112279128Smarcel  } ncp;
113263537Smarcel
114263537Smarcel  struct {
115266511Smarcel    struct filter in;         /* incoming packet filter */
116266511Smarcel    struct filter out;        /* outgoing packet filter */
117263537Smarcel    struct filter dial;       /* dial-out packet filter */
118263537Smarcel    struct filter alive;      /* keep-alive packet filter */
119263537Smarcel  } filter;
120263537Smarcel
121263537Smarcel  struct {
122263537Smarcel    struct pppTimer timer;    /* timeout after cfg.idle_timeout */
123263537Smarcel    time_t done;
124263537Smarcel  } idle;
125263537Smarcel
126263537Smarcel  struct {
127263537Smarcel    int fd;                   /* write status here */
128263537Smarcel  } notify;
129263537Smarcel
130263537Smarcel  struct {
131263537Smarcel    struct pppTimer timer;    /* choked output queue timer */
132263537Smarcel  } choked;
133263409Smarcel
134253923Smarcel#ifndef NORADIUS
135263487Smarcel  struct radius radius;       /* Info retrieved from radius server */
136263487Smarcel#endif
137253923Smarcel};
138279128Smarcel
139279128Smarcel#define descriptor2bundle(d) \
140263414Smarcel  ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
141263487Smarcel
142263487Smarcelextern struct bundle *bundle_Create(const char *, int, int);
143263487Smarcelextern void bundle_Destroy(struct bundle *);
144263487Smarcelextern const char *bundle_PhaseName(struct bundle *);
145263414Smarcel#define bundle_Phase(b) ((b)->phase)
146263487Smarcelextern void bundle_NewPhase(struct bundle *, u_int);
147263487Smarcelextern void bundle_LinksRemoved(struct bundle *);
148263414Smarcelextern int  bundle_LinkIsUp(const struct bundle *);
149263414Smarcelextern int bundle_SetRoute(struct bundle *, int, struct in_addr,
150263414Smarcel                           struct in_addr, struct in_addr, int, int);
151263487Smarcelextern void bundle_Close(struct bundle *, const char *, int);
152263414Smarcelextern void bundle_Down(struct bundle *, int);
153263461Smarcelextern void bundle_Open(struct bundle *, const char *, int, int);
154263466Smarcelextern void bundle_LinkClosed(struct bundle *, struct datalink *);
155263466Smarcel
156263466Smarcelextern int bundle_FillQueues(struct bundle *);
157263466Smarcelextern int bundle_ShowLinks(struct cmdargs const *);
158263487Smarcelextern int bundle_ShowStatus(struct cmdargs const *);
159263466Smarcelextern void bundle_StartIdleTimer(struct bundle *);
160263466Smarcelextern void bundle_SetIdleTimer(struct bundle *, int, int);
161253923Smarcelextern void bundle_StopIdleTimer(struct bundle *);
162253923Smarcelextern int bundle_IsDead(struct bundle *);
163253923Smarcelextern struct datalink *bundle2datalink(struct bundle *, const char *);
164253923Smarcel
165253923Smarcelextern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *);
166253923Smarcelextern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *);
167253923Smarcel
168279128Smarcelextern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
169253923Smarcel
170253923Smarcelextern int bundle_DatalinkClone(struct bundle *, struct datalink *,
171263829Smarcel                                const char *);
172263829Smarcelextern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
173263829Smarcelextern void bundle_CleanDatalinks(struct bundle *);
174263829Smarcelextern void bundle_SetLabel(struct bundle *, const char *);
175279128Smarcelextern const char *bundle_GetLabel(struct bundle *);
176263829Smarcelextern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
177263829Smarcelextern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *);
178263653Smarcelextern int bundle_SetMode(struct bundle *, struct datalink *, int);
179263844Smarcelextern int bundle_RenameDatalink(struct bundle *, struct datalink *,
180263442Smarcel                                 const char *);
181263442Smarcelextern void bundle_setsid(struct bundle *, int);
182279128Smarcelextern void bundle_LockTun(struct bundle *);
183263442Smarcelextern int bundle_HighestState(struct bundle *);
184263442Smarcelextern int bundle_Exception(struct bundle *, int);
185263442Smarcelextern void bundle_AdjustFilters(struct bundle *, struct in_addr *,
186266176Smarcel                                 struct in_addr *);
187253923Smarcelextern void bundle_CalculateBandwidth(struct bundle *);
188253923Smarcelextern void bundle_AutoAdjust(struct bundle *, int, int);
189279128Smarcelextern int bundle_WantAutoloadTimer(struct bundle *);
190253923Smarcel