bundle.h revision 58038
1105828Srwatson/*-
2105828Srwatson * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3105828Srwatson * All rights reserved.
4105828Srwatson *
5105828Srwatson * Redistribution and use in source and binary forms, with or without
6105828Srwatson * modification, are permitted provided that the following conditions
7105828Srwatson * are met:
8106393Srwatson * 1. Redistributions of source code must retain the above copyright
9106393Srwatson *    notice, this list of conditions and the following disclaimer.
10106393Srwatson * 2. Redistributions in binary form must reproduce the above copyright
11106393Srwatson *    notice, this list of conditions and the following disclaimer in the
12105828Srwatson *    documentation and/or other materials provided with the distribution.
13105828Srwatson *
14105828Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15105828Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16105828Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17105828Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18105828Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19105828Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20105828Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21105828Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22105828Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23105828Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24105828Srwatson * SUCH DAMAGE.
25105828Srwatson *
26105828Srwatson * $FreeBSD: head/usr.sbin/ppp/bundle.h 58038 2000-03-14 01:47:07Z brian $
27105828Srwatson */
28105828Srwatson
29105828Srwatson#define	PHASE_DEAD		0	/* Link is dead */
30105828Srwatson#define	PHASE_ESTABLISH		1	/* Establishing link */
31105828Srwatson#define	PHASE_AUTHENTICATE	2	/* Being authenticated */
32105828Srwatson#define	PHASE_NETWORK		3	/* We're alive ! */
33105828Srwatson#define	PHASE_TERMINATE		4	/* Terminating link */
34105828Srwatson
35105828Srwatson/* cfg.opt bit settings */
36105828Srwatson#define OPT_IDCHECK	0x0001
37105828Srwatson#define OPT_IFACEALIAS	0x0002
38105828Srwatson#define OPT_KEEPSESSION	0x0004
39105828Srwatson#define OPT_LOOPBACK	0x0008
40105828Srwatson#define OPT_PASSWDAUTH	0x0010
41105828Srwatson#define OPT_PROXY	0x0020
42105828Srwatson#define OPT_PROXYALL	0x0040
43105828Srwatson#define OPT_SROUTES	0x0080
44105828Srwatson#define OPT_THROUGHPUT	0x0100
45105828Srwatson#define OPT_UTMP	0x0200
46105828Srwatson
47105828Srwatson#define MAX_ENDDISC_CLASS 5
48105828Srwatson
49105828Srwatson#define Enabled(b, o) ((b)->cfg.opt & (o))
50105828Srwatson
51105828Srwatson/* AutoAdjust() values */
52105828Srwatson#define AUTO_UP		1
53105828Srwatson#define AUTO_DOWN	2
54105828Srwatson
55105828Srwatsonstruct sockaddr_un;
56105828Srwatsonstruct datalink;
57105828Srwatsonstruct physical;
58105828Srwatsonstruct link;
59105828Srwatsonstruct server;
60105828Srwatsonstruct prompt;
61105828Srwatsonstruct iface;
62105828Srwatson
63105828Srwatsonstruct bundle {
64105828Srwatson  struct fdescriptor desc;     /* really all our datalinks */
65105828Srwatson  int unit;                   /* The device/interface unit number */
66105828Srwatson
67105828Srwatson  struct {
68105828Srwatson    char Name[20];            /* The /dev/XXXX name */
69105828Srwatson    int fd;                   /* The /dev/XXXX descriptor */
70105828Srwatson    unsigned header : 1;      /* Family header sent & received ? */
71105828Srwatson  } dev;
72105828Srwatson
73105828Srwatson  u_long bandwidth;           /* struct tuninfo speed */
74105828Srwatson  struct iface *iface;        /* Interface information */
75105828Srwatson
76105828Srwatson  int routing_seq;            /* The current routing sequence number */
77105828Srwatson  u_int phase;                /* Curent phase */
78105828Srwatson
79105828Srwatson  struct {
80105828Srwatson    int all;                  /* Union of all physical::type's */
81105828Srwatson    int open;                 /* Union of all open physical::type's */
82105828Srwatson  } phys_type;
83105828Srwatson
84105828Srwatson  unsigned CleaningUp : 1;    /* Going to exit.... */
85105828Srwatson  unsigned NatEnabled : 1;    /* Are we using libalias ? */
86105828Srwatson
87105828Srwatson  struct fsm_parent fsm;      /* Our callback functions */
88105828Srwatson  struct datalink *links;     /* Our data links */
89105828Srwatson
90105828Srwatson  time_t upat;                /* When the link came up */
91105828Srwatson
92105828Srwatson  struct {
93105828Srwatson    struct {
94105828Srwatson      int timeout;              /* NCP Idle timeout value */
95105828Srwatson      int min_timeout;          /* Don't idle out before this */
96105828Srwatson    } idle;
97105828Srwatson    struct {
98105828Srwatson      char name[AUTHLEN];     /* PAP/CHAP system name */
99105828Srwatson      char key[AUTHLEN];      /* PAP/CHAP key */
100105828Srwatson    } auth;
101105828Srwatson    unsigned opt;             /* Uses OPT_ bits from above */
102105828Srwatson    char label[50];           /* last thing `load'ed */
103105828Srwatson    u_short mtu;              /* Interface mtu */
104105828Srwatson
105105828Srwatson    struct {
106105828Srwatson      int timeout;            /* How long to leave the output queue choked */
107105828Srwatson    } choked;
108105828Srwatson  } cfg;
109105828Srwatson
110105828Srwatson  struct {
111105828Srwatson    struct ipcp ipcp;         /* Our IPCP FSM */
112105828Srwatson    struct mp mp;             /* Our MP */
113105828Srwatson  } ncp;
114105828Srwatson
115105828Srwatson  struct {
116105828Srwatson    struct filter in;         /* incoming packet filter */
117105828Srwatson    struct filter out;        /* outgoing packet filter */
118105828Srwatson    struct filter dial;       /* dial-out packet filter */
119105828Srwatson    struct filter alive;      /* keep-alive packet filter */
120105828Srwatson  } filter;
121105828Srwatson
122105828Srwatson  struct {
123105828Srwatson    struct pppTimer timer;    /* timeout after cfg.idle_timeout */
124105828Srwatson    time_t done;
125105828Srwatson  } idle;
126105828Srwatson
127105828Srwatson  struct {
128105828Srwatson    int fd;                   /* write status here */
129105828Srwatson  } notify;
130105828Srwatson
131105828Srwatson  struct {
132105828Srwatson    struct pppTimer timer;    /* choked output queue timer */
133105828Srwatson  } choked;
134105828Srwatson
135105828Srwatson#ifndef NORADIUS
136105828Srwatson  struct radius radius;       /* Info retrieved from radius server */
137105828Srwatson#endif
138105828Srwatson};
139105828Srwatson
140105828Srwatson#define descriptor2bundle(d) \
141105828Srwatson  ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
142105828Srwatson
143105828Srwatsonextern struct bundle *bundle_Create(const char *, int, int);
144105828Srwatsonextern void bundle_Destroy(struct bundle *);
145105828Srwatsonextern const char *bundle_PhaseName(struct bundle *);
146105828Srwatson#define bundle_Phase(b) ((b)->phase)
147105828Srwatsonextern void bundle_NewPhase(struct bundle *, u_int);
148105828Srwatsonextern void bundle_LinksRemoved(struct bundle *);
149105828Srwatsonextern int  bundle_LinkIsUp(const struct bundle *);
150105828Srwatsonextern int bundle_SetRoute(struct bundle *, int, struct in_addr,
151105828Srwatson                           struct in_addr, struct in_addr, int, int);
152105828Srwatsonextern void bundle_Close(struct bundle *, const char *, int);
153105828Srwatsonextern void bundle_Down(struct bundle *, int);
154105828Srwatsonextern void bundle_Open(struct bundle *, const char *, int, int);
155105828Srwatsonextern void bundle_LinkClosed(struct bundle *, struct datalink *);
156105828Srwatson
157105828Srwatsonextern int bundle_ShowLinks(struct cmdargs const *);
158105828Srwatsonextern int bundle_ShowStatus(struct cmdargs const *);
159105828Srwatsonextern void bundle_StartIdleTimer(struct bundle *);
160105828Srwatsonextern void bundle_SetIdleTimer(struct bundle *, int, int);
161105828Srwatsonextern void bundle_StopIdleTimer(struct bundle *);
162105828Srwatsonextern int bundle_IsDead(struct bundle *);
163105828Srwatsonextern struct datalink *bundle2datalink(struct bundle *, const char *);
164105828Srwatson
165105828Srwatsonextern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *);
166105828Srwatsonextern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *);
167105828Srwatson
168105828Srwatsonextern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
169105828Srwatson
170105828Srwatsonextern int bundle_DatalinkClone(struct bundle *, struct datalink *,
171105828Srwatson                                const char *);
172105828Srwatsonextern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
173105828Srwatsonextern void bundle_CleanDatalinks(struct bundle *);
174105828Srwatsonextern void bundle_SetLabel(struct bundle *, const char *);
175105828Srwatsonextern const char *bundle_GetLabel(struct bundle *);
176105828Srwatsonextern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
177105828Srwatsonextern int bundle_LinkSize(void);
178105828Srwatsonextern void bundle_ReceiveDatalink(struct bundle *, int);
179105828Srwatsonextern int bundle_SetMode(struct bundle *, struct datalink *, int);
180105828Srwatsonextern int bundle_RenameDatalink(struct bundle *, struct datalink *,
181105828Srwatson                                 const char *);
182105828Srwatsonextern void bundle_setsid(struct bundle *, int);
183105828Srwatsonextern void bundle_LockTun(struct bundle *);
184106367Srwatsonextern int bundle_HighestState(struct bundle *);
185106367Srwatsonextern int bundle_Exception(struct bundle *, int);
186106367Srwatsonextern void bundle_AdjustFilters(struct bundle *, struct in_addr *,
187106367Srwatson                                 struct in_addr *);
188105828Srwatsonextern void bundle_CalculateBandwidth(struct bundle *);
189105828Srwatsonextern void bundle_AutoAdjust(struct bundle *, int, int);
190105828Srwatsonextern int bundle_WantAutoloadTimer(struct bundle *);
191105828Srwatsonextern void bundle_ChangedPID(struct bundle *);
192105828Srwatson