bundle.h revision 40561
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 *
2640561Sbrian *	$Id: bundle.h,v 1.13 1998/08/25 17:48:42 brian Exp $
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 */
3636285Sbrian#define OPT_IDCHECK	0x01
3736285Sbrian#define OPT_LOOPBACK	0x02
3836285Sbrian#define OPT_PASSWDAUTH	0x04
3936285Sbrian#define OPT_PROXY	0x08
4036285Sbrian#define OPT_SROUTES	0x10
4136285Sbrian#define OPT_THROUGHPUT	0x20
4236285Sbrian#define OPT_UTMP	0x40
4340561Sbrian#define OPT_IFACEALIAS	0x80
4436285Sbrian
4536285Sbrian#define MAX_ENDDISC_CLASS 5
4636285Sbrian
4736285Sbrian#define Enabled(b, o) ((b)->cfg.opt & (o))
4836285Sbrian
4936285Sbrianstruct sockaddr_un;
5036285Sbrianstruct datalink;
5136285Sbrianstruct physical;
5236285Sbrianstruct link;
5336285Sbrianstruct server;
5436285Sbrianstruct prompt;
5540561Sbrianstruct iface;
5636285Sbrian
5736285Sbrianstruct bundle {
5836285Sbrian  struct descriptor desc;     /* really all our datalinks */
5936285Sbrian  int unit;                   /* The device/interface unit number */
6036467Sbrian  const char **argv;          /* From main() */
6136285Sbrian
6236285Sbrian  struct {
6336285Sbrian    char Name[20];            /* The /dev/XXXX name */
6436285Sbrian    int fd;                   /* The /dev/XXXX descriptor */
6536285Sbrian  } dev;
6636285Sbrian
6740561Sbrian#if 0
6836285Sbrian  struct {
6936285Sbrian    int Index;                /* The interface index */
7036285Sbrian    char *Name;               /* The interface name */
7136285Sbrian  } ifp;
7240561Sbrian#endif
7336285Sbrian
7440561Sbrian  u_long ifSpeed;             /* struct tuninfo speed */
7540561Sbrian  struct iface *iface;        /* Interface information */
7640561Sbrian
7736285Sbrian  int routing_seq;            /* The current routing sequence number */
7836285Sbrian  u_int phase;                /* Curent phase */
7936285Sbrian
8036928Sbrian  struct {
8136928Sbrian    int all;                  /* Union of all physical::type's */
8236928Sbrian    int open;                 /* Union of all open physical::type's */
8336928Sbrian  } phys_type;
8436928Sbrian
8536285Sbrian  unsigned CleaningUp : 1;    /* Going to exit.... */
8637191Sbrian  unsigned AliasEnabled : 1;  /* Are we using libalias ? */
8736285Sbrian
8836285Sbrian  struct fsm_parent fsm;      /* Our callback functions */
8936285Sbrian  struct datalink *links;     /* Our data links */
9036285Sbrian
9136285Sbrian  struct {
9236285Sbrian    int idle_timeout;         /* NCP Idle timeout value */
9336285Sbrian    struct {
9436285Sbrian      char name[50];          /* PAP/CHAP system name */
9536285Sbrian      char key[50];           /* PAP/CHAP key */
9636285Sbrian    } auth;
9736285Sbrian    unsigned opt;             /* Uses OPT_ bits from above */
9836285Sbrian    char label[50];           /* last thing `load'ed */
9936285Sbrian    u_short mtu;              /* Interface mtu */
10036285Sbrian
10136285Sbrian    struct {                  /* We need/don't need another link when  */
10236285Sbrian      struct {                /* more/less than                        */
10336285Sbrian        int packets;          /* this number of packets are queued for */
10436285Sbrian        int timeout;          /* this number of seconds                */
10536285Sbrian      } max, min;
10636285Sbrian    } autoload;
10738544Sbrian
10838544Sbrian    struct {
10938544Sbrian      int timeout;		/* How long to leave the output queue choked */
11038544Sbrian    } choked;
11136285Sbrian  } cfg;
11236285Sbrian
11336285Sbrian  struct {
11436285Sbrian    struct ipcp ipcp;         /* Our IPCP FSM */
11536285Sbrian    struct mp mp;             /* Our MP */
11636285Sbrian  } ncp;
11736285Sbrian
11836285Sbrian  struct {
11936285Sbrian    struct filter in;		/* incoming packet filter */
12036285Sbrian    struct filter out;		/* outgoing packet filter */
12136285Sbrian    struct filter dial;		/* dial-out packet filter */
12236285Sbrian    struct filter alive;	/* keep-alive packet filter */
12336285Sbrian  } filter;
12436285Sbrian
12536285Sbrian  struct {
12636285Sbrian    struct pppTimer timer;      /* timeout after cfg.idle_timeout */
12736285Sbrian    time_t done;
12836285Sbrian  } idle;
12936285Sbrian
13036285Sbrian  struct {
13136285Sbrian    int fd;                     /* write status here */
13236285Sbrian  } notify;
13336285Sbrian
13436285Sbrian  struct {
13536285Sbrian    struct pppTimer timer;
13636285Sbrian    time_t done;
13736285Sbrian    unsigned running : 1;
13836285Sbrian    unsigned comingup : 1;
13936285Sbrian  } autoload;
14038544Sbrian
14138544Sbrian  struct {
14238544Sbrian    struct pppTimer timer;      /* choked output queue timer */
14338544Sbrian  } choked;
14436285Sbrian};
14536285Sbrian
14636285Sbrian#define descriptor2bundle(d) \
14736285Sbrian  ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
14836285Sbrian
14936467Sbrianextern struct bundle *bundle_Create(const char *, int, const char **);
15036285Sbrianextern void bundle_Destroy(struct bundle *);
15136285Sbrianextern const char *bundle_PhaseName(struct bundle *);
15236285Sbrian#define bundle_Phase(b) ((b)->phase)
15336285Sbrianextern void bundle_NewPhase(struct bundle *, u_int);
15438174Sbrianextern void bundle_LinksRemoved(struct bundle *);
15536285Sbrianextern int  bundle_LinkIsUp(const struct bundle *);
15636285Sbrianextern int bundle_SetRoute(struct bundle *, int, struct in_addr,
15737927Sbrian                           struct in_addr, struct in_addr, int, int);
15836285Sbrianextern void bundle_Close(struct bundle *, const char *, int);
15937018Sbrianextern void bundle_Down(struct bundle *, int);
16037955Sbrianextern void bundle_Open(struct bundle *, const char *, int, int);
16136285Sbrianextern void bundle_LinkClosed(struct bundle *, struct datalink *);
16236285Sbrian
16336285Sbrianextern int bundle_FillQueues(struct bundle *);
16436285Sbrianextern int bundle_ShowLinks(struct cmdargs const *);
16536285Sbrianextern int bundle_ShowStatus(struct cmdargs const *);
16636285Sbrianextern void bundle_StartIdleTimer(struct bundle *);
16736285Sbrianextern void bundle_SetIdleTimer(struct bundle *, int);
16836285Sbrianextern void bundle_StopIdleTimer(struct bundle *);
16936285Sbrianextern int bundle_IsDead(struct bundle *);
17036285Sbrianextern struct datalink *bundle2datalink(struct bundle *, const char *);
17136285Sbrian
17236285Sbrianextern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *);
17336285Sbrianextern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *);
17436285Sbrian
17536285Sbrianextern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
17636285Sbrian
17736285Sbrianextern int bundle_DatalinkClone(struct bundle *, struct datalink *,
17836285Sbrian                                const char *);
17936285Sbrianextern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
18036285Sbrianextern void bundle_CleanDatalinks(struct bundle *);
18136285Sbrianextern void bundle_SetLabel(struct bundle *, const char *);
18236285Sbrianextern const char *bundle_GetLabel(struct bundle *);
18336285Sbrianextern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
18436285Sbrianextern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *);
18536285Sbrianextern int bundle_SetMode(struct bundle *, struct datalink *, int);
18636285Sbrianextern int bundle_RenameDatalink(struct bundle *, struct datalink *,
18736285Sbrian                                 const char *);
18836452Sbrianextern void bundle_setsid(struct bundle *, int);
18936709Sbrianextern void bundle_LockTun(struct bundle *);
190