bundle.h revision 69303
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: head/usr.sbin/ppp/bundle.h 69303 2000-11-28 13:18:35Z brian $
27 */
28
29#define	PHASE_DEAD		0	/* Link is dead */
30#define	PHASE_ESTABLISH		1	/* Establishing link */
31#define	PHASE_AUTHENTICATE	2	/* Being authenticated */
32#define	PHASE_NETWORK		3	/* We're alive ! */
33#define	PHASE_TERMINATE		4	/* Terminating link */
34
35/* cfg.opt bit settings */
36#define OPT_FILTERDECAP	0x0001
37#define OPT_IDCHECK	0x0002
38#define OPT_IFACEALIAS	0x0004
39#define OPT_KEEPSESSION	0x0008
40#define OPT_LOOPBACK	0x0010
41#define OPT_PASSWDAUTH	0x0020
42#define OPT_PROXY	0x0040
43#define OPT_PROXYALL	0x0080
44#define OPT_SROUTES	0x0100
45#define OPT_TCPMSSFIXUP	0x0200
46#define OPT_THROUGHPUT	0x0400
47#define OPT_UTMP	0x0800
48
49#define MAX_ENDDISC_CLASS 5
50
51#define Enabled(b, o) ((b)->cfg.opt & (o))
52
53/* AutoAdjust() values */
54#define AUTO_UP		1
55#define AUTO_DOWN	2
56
57struct sockaddr_un;
58struct datalink;
59struct physical;
60struct link;
61struct server;
62struct prompt;
63struct iface;
64
65struct bundle {
66  struct fdescriptor desc;    /* really all our datalinks */
67  int unit;                   /* The device/interface unit number */
68
69  struct {
70    char Name[20];            /* The /dev/XXXX name */
71    int fd;                   /* The /dev/XXXX descriptor */
72    unsigned header : 1;      /* Family header sent & received ? */
73  } dev;
74
75  u_long bandwidth;           /* struct tuninfo speed */
76  int mtu;                    /* struct tuninfo MTU */
77  struct iface *iface;        /* Interface information */
78
79  int routing_seq;            /* The current routing sequence number */
80  u_int phase;                /* Curent phase */
81
82  struct {
83    int all;                  /* Union of all physical::type's */
84    int open;                 /* Union of all open physical::type's */
85  } phys_type;
86
87  unsigned CleaningUp : 1;    /* Going to exit.... */
88  unsigned NatEnabled : 1;    /* Are we using libalias ? */
89
90  struct fsm_parent fsm;      /* Our callback functions */
91  struct datalink *links;     /* Our data links */
92
93  time_t upat;                /* When the link came up */
94
95  struct {
96    struct {
97      int timeout;              /* NCP Idle timeout value */
98      int min_timeout;          /* Don't idle out before this */
99    } idle;
100    struct {
101      char name[AUTHLEN];     /* PAP/CHAP system name */
102      char key[AUTHLEN];      /* PAP/CHAP key */
103    } auth;
104    unsigned opt;             /* Uses OPT_ bits from above */
105    char label[50];           /* last thing `load'ed */
106    u_short mtu;              /* Required interface MTU */
107    u_short ifqueue;          /* Interface queue size */
108
109    struct {
110      int timeout;            /* How long to leave the output queue choked */
111    } choked;
112  } cfg;
113
114  struct {
115    struct ipcp ipcp;         /* Our IPCP FSM */
116    struct mp mp;             /* Our MP */
117  } 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  struct {
132    int fd;                   /* write status here */
133  } notify;
134
135  struct {
136    struct pppTimer timer;    /* choked output queue timer */
137  } choked;
138
139#ifndef NORADIUS
140  struct radius radius;       /* Info retrieved from radius server */
141  struct radacct radacct;
142#endif
143};
144
145#define descriptor2bundle(d) \
146  ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
147
148extern struct bundle *bundle_Create(const char *, int, int);
149extern void bundle_Destroy(struct bundle *);
150extern const char *bundle_PhaseName(struct bundle *);
151#define bundle_Phase(b) ((b)->phase)
152extern void bundle_NewPhase(struct bundle *, u_int);
153extern void bundle_LinksRemoved(struct bundle *);
154extern int  bundle_LinkIsUp(const struct bundle *);
155extern int bundle_SetRoute(struct bundle *, int, struct in_addr,
156                           struct in_addr, struct in_addr, int, int);
157extern void bundle_Close(struct bundle *, const char *, int);
158extern void bundle_Down(struct bundle *, int);
159extern void bundle_Open(struct bundle *, const char *, int, int);
160extern void bundle_LinkClosed(struct bundle *, struct datalink *);
161
162extern int bundle_ShowLinks(struct cmdargs const *);
163extern int bundle_ShowStatus(struct cmdargs const *);
164extern void bundle_StartIdleTimer(struct bundle *, unsigned secs);
165extern void bundle_SetIdleTimer(struct bundle *, int, int);
166extern void bundle_StopIdleTimer(struct bundle *);
167extern int bundle_IsDead(struct bundle *);
168extern struct datalink *bundle2datalink(struct bundle *, const char *);
169
170extern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *);
171extern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *);
172
173extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
174
175extern int bundle_DatalinkClone(struct bundle *, struct datalink *,
176                                const char *);
177extern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
178extern void bundle_CleanDatalinks(struct bundle *);
179extern void bundle_SetLabel(struct bundle *, const char *);
180extern const char *bundle_GetLabel(struct bundle *);
181extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
182extern int bundle_LinkSize(void);
183extern void bundle_ReceiveDatalink(struct bundle *, int);
184extern int bundle_SetMode(struct bundle *, struct datalink *, int);
185extern int bundle_RenameDatalink(struct bundle *, struct datalink *,
186                                 const char *);
187extern void bundle_setsid(struct bundle *, int);
188extern void bundle_LockTun(struct bundle *);
189extern int bundle_HighestState(struct bundle *);
190extern int bundle_Exception(struct bundle *, int);
191extern void bundle_AdjustFilters(struct bundle *, struct in_addr *,
192                                 struct in_addr *);
193extern void bundle_AdjustDNS(struct bundle *, struct in_addr [2]);
194extern void bundle_CalculateBandwidth(struct bundle *);
195extern void bundle_AutoAdjust(struct bundle *, int, int);
196extern int bundle_WantAutoloadTimer(struct bundle *);
197extern void bundle_ChangedPID(struct bundle *);
198extern void bundle_Notify(struct bundle *, char);
199