136285Sbrian/*-
236285Sbrian * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
336285Sbrian * All rights reserved.
436285Sbrian *
536285Sbrian * Redistribution and use in source and binary forms, with or without
636285Sbrian * modification, are permitted provided that the following conditions
736285Sbrian * are met:
836285Sbrian * 1. Redistributions of source code must retain the above copyright
936285Sbrian *    notice, this list of conditions and the following disclaimer.
1036285Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1136285Sbrian *    notice, this list of conditions and the following disclaimer in the
1236285Sbrian *    documentation and/or other materials provided with the distribution.
1336285Sbrian *
1436285Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1536285Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1636285Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1736285Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1836285Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1936285Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2036285Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2136285Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2236285Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2336285Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2436285Sbrian * SUCH DAMAGE.
2536285Sbrian *
2650479Speter * $FreeBSD$
2736285Sbrian */
2836285Sbrian
2936285Sbrian#define	PHASE_DEAD		0	/* Link is dead */
3036285Sbrian#define	PHASE_ESTABLISH		1	/* Establishing link */
3136285Sbrian#define	PHASE_AUTHENTICATE	2	/* Being authenticated */
3236285Sbrian#define	PHASE_NETWORK		3	/* We're alive ! */
3336285Sbrian#define	PHASE_TERMINATE		4	/* Terminating link */
3436285Sbrian
3536285Sbrian/* cfg.opt bit settings */
36138198Sbrian#define OPT_FILTERDECAP		1
37138198Sbrian#define OPT_FORCE_SCRIPTS	2 /* force chat scripts */
38138198Sbrian#define OPT_IDCHECK		3
39138198Sbrian#define OPT_IFACEALIAS		4
4081634Sbrian#ifndef NOINET6
41138198Sbrian#define OPT_IPCP		5
42138198Sbrian#define OPT_IPV6CP		6
4381634Sbrian#endif
44138198Sbrian#define OPT_KEEPSESSION		7
45138198Sbrian#define OPT_LOOPBACK		8
46138198Sbrian#define OPT_NAS_IP_ADDRESS	9
47138198Sbrian#define OPT_NAS_IDENTIFIER	10
48138198Sbrian#define OPT_PASSWDAUTH		11
49138198Sbrian#define OPT_PROXY		12
50138198Sbrian#define OPT_PROXYALL		13
51138198Sbrian#define OPT_SROUTES		14
52138198Sbrian#define OPT_TCPMSSFIXUP		15
53138198Sbrian#define OPT_THROUGHPUT		16
54138198Sbrian#define OPT_UTMP		17
55138198Sbrian#define OPT_MAX			17
5636285Sbrian
5736285Sbrian#define MAX_ENDDISC_CLASS 5
5836285Sbrian
59138198Sbrian#define Enabled(b, o)		((b)->cfg.optmask & (1ull << (o)))
60138198Sbrian#define opt_enable(b, o)	((b)->cfg.optmask |= (1ull << (o)))
61138198Sbrian#define opt_disable(b, o)	((b)->cfg.optmask &= ~(1ull << (o)))
6236285Sbrian
6349434Sbrian/* AutoAdjust() values */
6449434Sbrian#define AUTO_UP		1
6549434Sbrian#define AUTO_DOWN	2
6649434Sbrian
6736285Sbrianstruct sockaddr_un;
6836285Sbrianstruct datalink;
6936285Sbrianstruct physical;
7036285Sbrianstruct link;
7136285Sbrianstruct server;
7236285Sbrianstruct prompt;
7340561Sbrianstruct iface;
7436285Sbrian
7536285Sbrianstruct bundle {
7658040Sbrian  struct fdescriptor desc;    /* really all our datalinks */
7736285Sbrian  int unit;                   /* The device/interface unit number */
7836285Sbrian
7936285Sbrian  struct {
8036285Sbrian    char Name[20];            /* The /dev/XXXX name */
8158038Sbrian    int fd;                   /* The /dev/XXXX descriptor */
8256413Sbrian    unsigned header : 1;      /* Family header sent & received ? */
8336285Sbrian  } dev;
8436285Sbrian
8549434Sbrian  u_long bandwidth;           /* struct tuninfo speed */
8640561Sbrian  struct iface *iface;        /* Interface information */
8740561Sbrian
8836285Sbrian  int routing_seq;            /* The current routing sequence number */
8936285Sbrian  u_int phase;                /* Curent phase */
9036285Sbrian
9136928Sbrian  struct {
9236928Sbrian    int all;                  /* Union of all physical::type's */
9336928Sbrian    int open;                 /* Union of all open physical::type's */
9436928Sbrian  } phys_type;
9536928Sbrian
9636285Sbrian  unsigned CleaningUp : 1;    /* Going to exit.... */
9750059Sbrian  unsigned NatEnabled : 1;    /* Are we using libalias ? */
9836285Sbrian
9936285Sbrian  struct fsm_parent fsm;      /* Our callback functions */
10036285Sbrian  struct datalink *links;     /* Our data links */
10136285Sbrian
10249978Sbrian  time_t upat;                /* When the link came up */
10349978Sbrian
10436285Sbrian  struct {
10536285Sbrian    struct {
106138198Sbrian      unsigned timeout;          /* NCP Idle timeout value */
107138198Sbrian      unsigned min_timeout;      /* Don't idle out before this */
10849978Sbrian    } idle;
10949978Sbrian    struct {
110138198Sbrian      char name[AUTHLEN];        /* PAP/CHAP system name */
111138198Sbrian      char key[AUTHLEN];         /* PAP/CHAP key */
11236285Sbrian    } auth;
113138198Sbrian    unsigned long long optmask;  /* Uses OPT_ bits from above */
114138198Sbrian    char label[50];              /* last thing `load'ed */
115138198Sbrian    u_short ifqueue;             /* Interface queue size */
11636285Sbrian
11738544Sbrian    struct {
118138198Sbrian      unsigned timeout;          /* How long to leave the output queue choked */
11938544Sbrian    } choked;
12036285Sbrian  } cfg;
12136285Sbrian
12281634Sbrian  struct ncp ncp;
12336285Sbrian
12436285Sbrian  struct {
12543313Sbrian    struct filter in;         /* incoming packet filter */
12643313Sbrian    struct filter out;        /* outgoing packet filter */
12743313Sbrian    struct filter dial;       /* dial-out packet filter */
12843313Sbrian    struct filter alive;      /* keep-alive packet filter */
12936285Sbrian  } filter;
13036285Sbrian
13136285Sbrian  struct {
13243313Sbrian    struct pppTimer timer;    /* timeout after cfg.idle_timeout */
13336285Sbrian    time_t done;
13436285Sbrian  } idle;
13536285Sbrian
13696153Sbrian#ifndef NORADIUS
13736285Sbrian  struct {
13896153Sbrian    struct pppTimer timer;
13996153Sbrian    time_t done;
14096153Sbrian  } session;
14196153Sbrian#endif
14296153Sbrian
14396153Sbrian  struct {
14443313Sbrian    int fd;                   /* write status here */
14536285Sbrian  } notify;
14636285Sbrian
14736285Sbrian  struct {
14843313Sbrian    struct pppTimer timer;    /* choked output queue timer */
14938544Sbrian  } choked;
15043313Sbrian
15143313Sbrian#ifndef NORADIUS
15243313Sbrian  struct radius radius;       /* Info retrieved from radius server */
15365178Sbrian  struct radacct radacct;
154116588Sume#ifndef NOINET6
155116588Sume  struct radacct radacct6;
15643313Sbrian#endif
157116588Sume#endif
15836285Sbrian};
15936285Sbrian
16036285Sbrian#define descriptor2bundle(d) \
16136285Sbrian  ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
16236285Sbrian
16353298Sbrianextern struct bundle *bundle_Create(const char *, int, int);
16436285Sbrianextern void bundle_Destroy(struct bundle *);
16536285Sbrianextern const char *bundle_PhaseName(struct bundle *);
16636285Sbrian#define bundle_Phase(b) ((b)->phase)
16736285Sbrianextern void bundle_NewPhase(struct bundle *, u_int);
16838174Sbrianextern void bundle_LinksRemoved(struct bundle *);
16936285Sbrianextern void bundle_Close(struct bundle *, const char *, int);
17037018Sbrianextern void bundle_Down(struct bundle *, int);
17137955Sbrianextern void bundle_Open(struct bundle *, const char *, int, int);
17236285Sbrianextern void bundle_LinkClosed(struct bundle *, struct datalink *);
17336285Sbrian
17436285Sbrianextern int bundle_ShowLinks(struct cmdargs const *);
17536285Sbrianextern int bundle_ShowStatus(struct cmdargs const *);
17662977Sbrianextern void bundle_StartIdleTimer(struct bundle *, unsigned secs);
177134789Sbrianextern void bundle_SetIdleTimer(struct bundle *, unsigned, unsigned);
17836285Sbrianextern void bundle_StopIdleTimer(struct bundle *);
17936285Sbrianextern int bundle_IsDead(struct bundle *);
18036285Sbrianextern struct datalink *bundle2datalink(struct bundle *, const char *);
18136285Sbrian
18296153Sbrian#ifndef NORADIUS
18396153Sbrianextern void bundle_StartSessionTimer(struct bundle *, unsigned secs);
18496153Sbrianextern void bundle_StopSessionTimer(struct bundle *);
18596153Sbrian#endif
18696153Sbrian
18758028Sbrianextern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *);
18858028Sbrianextern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *);
18936285Sbrian
19036285Sbrianextern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
19136285Sbrian
19236285Sbrianextern int bundle_DatalinkClone(struct bundle *, struct datalink *,
19336285Sbrian                                const char *);
19436285Sbrianextern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
19536285Sbrianextern void bundle_CleanDatalinks(struct bundle *);
19636285Sbrianextern void bundle_SetLabel(struct bundle *, const char *);
19736285Sbrianextern const char *bundle_GetLabel(struct bundle *);
19836285Sbrianextern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
19953684Sbrianextern int bundle_LinkSize(void);
20053684Sbrianextern void bundle_ReceiveDatalink(struct bundle *, int);
20136285Sbrianextern int bundle_SetMode(struct bundle *, struct datalink *, int);
20236285Sbrianextern int bundle_RenameDatalink(struct bundle *, struct datalink *,
20336285Sbrian                                 const char *);
20436452Sbrianextern void bundle_setsid(struct bundle *, int);
20536709Sbrianextern void bundle_LockTun(struct bundle *);
206134789Sbrianextern unsigned bundle_HighestState(struct bundle *);
20741654Sbrianextern int bundle_Exception(struct bundle *, int);
20881634Sbrianextern void bundle_AdjustFilters(struct bundle *, struct ncpaddr *,
20981634Sbrian                                 struct ncpaddr *);
21081634Sbrianextern void bundle_AdjustDNS(struct bundle *);
21149434Sbrianextern void bundle_CalculateBandwidth(struct bundle *);
21249434Sbrianextern void bundle_AutoAdjust(struct bundle *, int, int);
21349434Sbrianextern int bundle_WantAutoloadTimer(struct bundle *);
21456350Sbrianextern void bundle_ChangedPID(struct bundle *);
21559084Sbrianextern void bundle_Notify(struct bundle *, char);
21685991Sbrianextern int bundle_Uptime(struct bundle *);
217