bundle.h revision 138198
11556Srgrimes/*-
21556Srgrimes * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
31556Srgrimes * All rights reserved.
41556Srgrimes *
51556Srgrimes * Redistribution and use in source and binary forms, with or without
61556Srgrimes * modification, are permitted provided that the following conditions
71556Srgrimes * are met:
81556Srgrimes * 1. Redistributions of source code must retain the above copyright
91556Srgrimes *    notice, this list of conditions and the following disclaimer.
101556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111556Srgrimes *    notice, this list of conditions and the following disclaimer in the
121556Srgrimes *    documentation and/or other materials provided with the distribution.
131556Srgrimes *
141556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241556Srgrimes * SUCH DAMAGE.
251556Srgrimes *
261556Srgrimes * $FreeBSD: head/usr.sbin/ppp/bundle.h 138198 2004-11-29 17:11:15Z brian $
271556Srgrimes */
281556Srgrimes
291556Srgrimes#define	PHASE_DEAD		0	/* Link is dead */
301556Srgrimes#define	PHASE_ESTABLISH		1	/* Establishing link */
311556Srgrimes#define	PHASE_AUTHENTICATE	2	/* Being authenticated */
321556Srgrimes#define	PHASE_NETWORK		3	/* We're alive ! */
331556Srgrimes#define	PHASE_TERMINATE		4	/* Terminating link */
3436150Scharnier
3536150Scharnier/* cfg.opt bit settings */
3636150Scharnier#define OPT_FILTERDECAP		1
371556Srgrimes#define OPT_FORCE_SCRIPTS	2 /* force chat scripts */
3899110Sobrien#define OPT_IDCHECK		3
3999110Sobrien#define OPT_IFACEALIAS		4
401556Srgrimes#ifndef NOINET6
4117987Speter#define OPT_IPCP		5
42149017Sstefanf#define OPT_IPV6CP		6
4317987Speter#endif
441556Srgrimes#define OPT_KEEPSESSION		7
451556Srgrimes#define OPT_LOOPBACK		8
461556Srgrimes#define OPT_NAS_IP_ADDRESS	9
471556Srgrimes#define OPT_NAS_IDENTIFIER	10
481556Srgrimes#define OPT_PASSWDAUTH		11
491556Srgrimes#define OPT_PROXY		12
501556Srgrimes#define OPT_PROXYALL		13
511556Srgrimes#define OPT_SROUTES		14
521556Srgrimes#define OPT_TCPMSSFIXUP		15
531556Srgrimes#define OPT_THROUGHPUT		16
541556Srgrimes#define OPT_UTMP		17
551556Srgrimes#define OPT_MAX			17
561556Srgrimes
5717987Speter#define MAX_ENDDISC_CLASS 5
5859436Scracauer
5917987Speter#define Enabled(b, o)		((b)->cfg.optmask & (1ull << (o)))
601556Srgrimes#define opt_enable(b, o)	((b)->cfg.optmask |= (1ull << (o)))
6117987Speter#define opt_disable(b, o)	((b)->cfg.optmask &= ~(1ull << (o)))
621556Srgrimes
631556Srgrimes/* AutoAdjust() values */
641556Srgrimes#define AUTO_UP		1
651556Srgrimes#define AUTO_DOWN	2
661556Srgrimes
67142845Sobrienstruct sockaddr_un;
68142845Sobrienstruct datalink;
691556Srgrimesstruct physical;
701556Srgrimesstruct link;
7117987Speterstruct server;
721556Srgrimesstruct prompt;
731556Srgrimesstruct iface;
741556Srgrimes
751556Srgrimesstruct bundle {
761556Srgrimes  struct fdescriptor desc;    /* really all our datalinks */
771556Srgrimes  int unit;                   /* The device/interface unit number */
781556Srgrimes
791556Srgrimes  struct {
801556Srgrimes    char Name[20];            /* The /dev/XXXX name */
811556Srgrimes    int fd;                   /* The /dev/XXXX descriptor */
82206145Sjilles    unsigned header : 1;      /* Family header sent & received ? */
83206145Sjilles  } dev;
84206145Sjilles
85206145Sjilles  u_long bandwidth;           /* struct tuninfo speed */
861556Srgrimes  struct iface *iface;        /* Interface information */
871556Srgrimes
88117261Sdds  int routing_seq;            /* The current routing sequence number */
89117261Sdds  u_int phase;                /* Curent phase */
90117261Sdds
91117261Sdds  struct {
921556Srgrimes    int all;                  /* Union of all physical::type's */
93117261Sdds    int open;                 /* Union of all open physical::type's */
941556Srgrimes  } phys_type;
95117261Sdds
96117261Sdds  unsigned CleaningUp : 1;    /* Going to exit.... */
97117261Sdds  unsigned NatEnabled : 1;    /* Are we using libalias ? */
98117261Sdds
99117261Sdds  struct fsm_parent fsm;      /* Our callback functions */
100179022Sstefanf  struct datalink *links;     /* Our data links */
101206145Sjilles
1021556Srgrimes  time_t upat;                /* When the link came up */
10318018Speter
10418018Speter  struct {
1051556Srgrimes    struct {
1061556Srgrimes      unsigned timeout;          /* NCP Idle timeout value */
10790111Simp      unsigned min_timeout;      /* Don't idle out before this */
10890111Simp    } idle;
10990111Simp    struct {
11090111Simp      char name[AUTHLEN];        /* PAP/CHAP system name */
11190111Simp      char key[AUTHLEN];         /* PAP/CHAP key */
11290111Simp    } auth;
11390111Simp    unsigned long long optmask;  /* Uses OPT_ bits from above */
11490111Simp    char label[50];              /* last thing `load'ed */
11590111Simp    u_short ifqueue;             /* Interface queue size */
11690111Simp
11790111Simp    struct {
11890111Simp      unsigned timeout;          /* How long to leave the output queue choked */
11990111Simp    } choked;
12090111Simp  } cfg;
121201053Sjilles
12290111Simp  struct ncp ncp;
1231556Srgrimes
12417987Speter  struct {
125206145Sjilles    struct filter in;         /* incoming packet filter */
126206145Sjilles    struct filter out;        /* outgoing packet filter */
127206145Sjilles    struct filter dial;       /* dial-out packet filter */
128206145Sjilles    struct filter alive;      /* keep-alive packet filter */
129206145Sjilles  } filter;
130206145Sjilles
131206145Sjilles  struct {
132206145Sjilles    struct pppTimer timer;    /* timeout after cfg.idle_timeout */
133206145Sjilles    time_t done;
134206145Sjilles  } idle;
135206145Sjilles
136206145Sjilles#ifndef NORADIUS
137206145Sjilles  struct {
138206145Sjilles    struct pppTimer timer;
139206145Sjilles    time_t done;
140206145Sjilles  } session;
141206145Sjilles#endif
142206145Sjilles
143206145Sjilles  struct {
144206145Sjilles    int fd;                   /* write status here */
145206145Sjilles  } notify;
146206145Sjilles
147206145Sjilles  struct {
148206145Sjilles    struct pppTimer timer;    /* choked output queue timer */
149206145Sjilles  } choked;
150206145Sjilles
151206145Sjilles#ifndef NORADIUS
152206145Sjilles  struct radius radius;       /* Info retrieved from radius server */
153206145Sjilles  struct radacct radacct;
154206145Sjilles#ifndef NOINET6
155206145Sjilles  struct radacct radacct6;
156206145Sjilles#endif
157206145Sjilles#endif
158206145Sjilles};
159206145Sjilles
160206145Sjilles#define descriptor2bundle(d) \
161206145Sjilles  ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
162206145Sjilles
163206145Sjillesextern struct bundle *bundle_Create(const char *, int, int);
164206145Sjillesextern void bundle_Destroy(struct bundle *);
165206145Sjillesextern const char *bundle_PhaseName(struct bundle *);
166206145Sjilles#define bundle_Phase(b) ((b)->phase)
167206145Sjillesextern void bundle_NewPhase(struct bundle *, u_int);
168206145Sjillesextern void bundle_LinksRemoved(struct bundle *);
169206145Sjillesextern void bundle_Close(struct bundle *, const char *, int);
170206145Sjillesextern void bundle_Down(struct bundle *, int);
171206145Sjillesextern void bundle_Open(struct bundle *, const char *, int, int);
172206145Sjillesextern void bundle_LinkClosed(struct bundle *, struct datalink *);
173206145Sjilles
174206145Sjillesextern int bundle_ShowLinks(struct cmdargs const *);
175206145Sjillesextern int bundle_ShowStatus(struct cmdargs const *);
176206145Sjillesextern void bundle_StartIdleTimer(struct bundle *, unsigned secs);
177206145Sjillesextern void bundle_SetIdleTimer(struct bundle *, unsigned, unsigned);
178206145Sjillesextern void bundle_StopIdleTimer(struct bundle *);
179206145Sjillesextern int bundle_IsDead(struct bundle *);
180206145Sjillesextern struct datalink *bundle2datalink(struct bundle *, const char *);
181206145Sjilles
182206145Sjilles#ifndef NORADIUS
183206145Sjillesextern void bundle_StartSessionTimer(struct bundle *, unsigned secs);
184206145Sjillesextern void bundle_StopSessionTimer(struct bundle *);
185206145Sjilles#endif
186206145Sjilles
187206145Sjillesextern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *);
188206145Sjillesextern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *);
189206145Sjilles
190206145Sjillesextern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
191206145Sjilles
1921556Srgrimesextern int bundle_DatalinkClone(struct bundle *, struct datalink *,
1931556Srgrimes                                const char *);
1941556Srgrimesextern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
1951556Srgrimesextern void bundle_CleanDatalinks(struct bundle *);
1961556Srgrimesextern void bundle_SetLabel(struct bundle *, const char *);
1971556Srgrimesextern const char *bundle_GetLabel(struct bundle *);
19890111Simpextern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
19917987Speterextern int bundle_LinkSize(void);
2001556Srgrimesextern void bundle_ReceiveDatalink(struct bundle *, int);
2011556Srgrimesextern int bundle_SetMode(struct bundle *, struct datalink *, int);
202206145Sjillesextern int bundle_RenameDatalink(struct bundle *, struct datalink *,
203206145Sjilles                                 const char *);
204206145Sjillesextern void bundle_setsid(struct bundle *, int);
205206145Sjillesextern void bundle_LockTun(struct bundle *);
206206145Sjillesextern unsigned bundle_HighestState(struct bundle *);
20760593Scracauerextern int bundle_Exception(struct bundle *, int);
2081556Srgrimesextern void bundle_AdjustFilters(struct bundle *, struct ncpaddr *,
2091556Srgrimes                                 struct ncpaddr *);
2101556Srgrimesextern void bundle_AdjustDNS(struct bundle *);
2111556Srgrimesextern void bundle_CalculateBandwidth(struct bundle *);
2121556Srgrimesextern void bundle_AutoAdjust(struct bundle *, int, int);
2131556Srgrimesextern int bundle_WantAutoloadTimer(struct bundle *);
2141556Srgrimesextern void bundle_ChangedPID(struct bundle *);
2151556Srgrimesextern void bundle_Notify(struct bundle *, char);
2161556Srgrimesextern int bundle_Uptime(struct bundle *);
2171556Srgrimes