bundle.h revision 36285
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 *
2636285Sbrian *	$Id: bundle.h,v 1.1.2.42 1998/05/21 01:13:24 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
4336285Sbrian
4436285Sbrian#define MAX_ENDDISC_CLASS 5
4536285Sbrian
4636285Sbrian#define Enabled(b, o) ((b)->cfg.opt & (o))
4736285Sbrian
4836285Sbrianstruct sockaddr_un;
4936285Sbrianstruct datalink;
5036285Sbrianstruct physical;
5136285Sbrianstruct link;
5236285Sbrianstruct server;
5336285Sbrianstruct prompt;
5436285Sbrian
5536285Sbrianstruct bundle {
5636285Sbrian  struct descriptor desc;     /* really all our datalinks */
5736285Sbrian  int unit;                   /* The device/interface unit number */
5836285Sbrian
5936285Sbrian  struct {
6036285Sbrian    char Name[20];            /* The /dev/XXXX name */
6136285Sbrian    int fd;                   /* The /dev/XXXX descriptor */
6236285Sbrian  } dev;
6336285Sbrian
6436285Sbrian  struct {
6536285Sbrian    u_long Speed;             /* struct tuninfo speed */
6636285Sbrian    int Index;                /* The interface index */
6736285Sbrian    char *Name;               /* The interface name */
6836285Sbrian  } ifp;
6936285Sbrian
7036285Sbrian  int routing_seq;            /* The current routing sequence number */
7136285Sbrian  u_int phase;                /* Curent phase */
7236285Sbrian  int phys_type;              /* Union of all physical::type's */
7336285Sbrian
7436285Sbrian  unsigned CleaningUp : 1;    /* Going to exit.... */
7536285Sbrian
7636285Sbrian  struct fsm_parent fsm;      /* Our callback functions */
7736285Sbrian  struct datalink *links;     /* Our data links */
7836285Sbrian
7936285Sbrian  struct {
8036285Sbrian    int idle_timeout;         /* NCP Idle timeout value */
8136285Sbrian    struct {
8236285Sbrian      char name[50];          /* PAP/CHAP system name */
8336285Sbrian      char key[50];           /* PAP/CHAP key */
8436285Sbrian    } auth;
8536285Sbrian    unsigned opt;             /* Uses OPT_ bits from above */
8636285Sbrian    char label[50];           /* last thing `load'ed */
8736285Sbrian    u_short mtu;              /* Interface mtu */
8836285Sbrian
8936285Sbrian    struct {                  /* We need/don't need another link when  */
9036285Sbrian      struct {                /* more/less than                        */
9136285Sbrian        int packets;          /* this number of packets are queued for */
9236285Sbrian        int timeout;          /* this number of seconds                */
9336285Sbrian      } max, min;
9436285Sbrian    } autoload;
9536285Sbrian  } cfg;
9636285Sbrian
9736285Sbrian  struct {
9836285Sbrian    struct ipcp ipcp;         /* Our IPCP FSM */
9936285Sbrian    struct mp mp;             /* Our MP */
10036285Sbrian  } ncp;
10136285Sbrian
10236285Sbrian  struct {
10336285Sbrian    struct filter in;		/* incoming packet filter */
10436285Sbrian    struct filter out;		/* outgoing packet filter */
10536285Sbrian    struct filter dial;		/* dial-out packet filter */
10636285Sbrian    struct filter alive;	/* keep-alive packet filter */
10736285Sbrian  } filter;
10836285Sbrian
10936285Sbrian  struct {
11036285Sbrian    struct pppTimer timer;      /* timeout after cfg.idle_timeout */
11136285Sbrian    time_t done;
11236285Sbrian  } idle;
11336285Sbrian
11436285Sbrian  struct {
11536285Sbrian    int fd;                     /* write status here */
11636285Sbrian  } notify;
11736285Sbrian
11836285Sbrian  struct {
11936285Sbrian    struct pppTimer timer;
12036285Sbrian    time_t done;
12136285Sbrian    unsigned running : 1;
12236285Sbrian    unsigned comingup : 1;
12336285Sbrian  } autoload;
12436285Sbrian};
12536285Sbrian
12636285Sbrian#define descriptor2bundle(d) \
12736285Sbrian  ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
12836285Sbrian
12936285Sbrianextern struct bundle *bundle_Create(const char *, struct prompt *, int);
13036285Sbrianextern void bundle_Destroy(struct bundle *);
13136285Sbrianextern const char *bundle_PhaseName(struct bundle *);
13236285Sbrian#define bundle_Phase(b) ((b)->phase)
13336285Sbrianextern void bundle_NewPhase(struct bundle *, u_int);
13436285Sbrianextern int  bundle_LinkIsUp(const struct bundle *);
13536285Sbrianextern int bundle_SetRoute(struct bundle *, int, struct in_addr,
13636285Sbrian                           struct in_addr, struct in_addr, int);
13736285Sbrianextern void bundle_Close(struct bundle *, const char *, int);
13836285Sbrianextern void bundle_Down(struct bundle *);
13936285Sbrianextern void bundle_Open(struct bundle *, const char *, int);
14036285Sbrianextern void bundle_LinkClosed(struct bundle *, struct datalink *);
14136285Sbrian
14236285Sbrianextern int bundle_FillQueues(struct bundle *);
14336285Sbrianextern int bundle_ShowLinks(struct cmdargs const *);
14436285Sbrianextern int bundle_ShowStatus(struct cmdargs const *);
14536285Sbrianextern void bundle_StartIdleTimer(struct bundle *);
14636285Sbrianextern void bundle_SetIdleTimer(struct bundle *, int);
14736285Sbrianextern void bundle_StopIdleTimer(struct bundle *);
14836285Sbrianextern int bundle_IsDead(struct bundle *);
14936285Sbrianextern struct datalink *bundle2datalink(struct bundle *, const char *);
15036285Sbrian
15136285Sbrianextern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *);
15236285Sbrianextern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *);
15336285Sbrian
15436285Sbrianextern void bundle_DelPromptDescriptors(struct bundle *, struct server *);
15536285Sbrianextern void bundle_DisplayPrompt(struct bundle *);
15636285Sbrianextern void bundle_WriteTermPrompt(struct bundle *, struct datalink *,
15736285Sbrian                                   const char *, int);
15836285Sbrianextern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
15936285Sbrian
16036285Sbrianextern int bundle_DatalinkClone(struct bundle *, struct datalink *,
16136285Sbrian                                const char *);
16236285Sbrianextern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
16336285Sbrianextern void bundle_CleanDatalinks(struct bundle *);
16436285Sbrianextern void bundle_SetLabel(struct bundle *, const char *);
16536285Sbrianextern const char *bundle_GetLabel(struct bundle *);
16636285Sbrianextern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
16736285Sbrianextern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *);
16836285Sbrianextern int bundle_SetMode(struct bundle *, struct datalink *, int);
16936285Sbrianextern int bundle_RenameDatalink(struct bundle *, struct datalink *,
17036285Sbrian                                 const char *);
171