bundle.h revision 36452
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 *	$Id: bundle.h,v 1.3 1998/05/23 22:24:30 brian Exp $
27 */
28
29#define	PHASE_DEAD		0	/* Link is dead */
30#define	PHASE_ESTABLISH		1	/* Establishing link */
31#define	PHASE_AUTHENTICATE	2	/* Being authenticated */
32#define	PHASE_NETWORK		3	/* We're alive ! */
33#define	PHASE_TERMINATE		4	/* Terminating link */
34
35/* cfg.opt bit settings */
36#define OPT_IDCHECK	0x01
37#define OPT_LOOPBACK	0x02
38#define OPT_PASSWDAUTH	0x04
39#define OPT_PROXY	0x08
40#define OPT_SROUTES	0x10
41#define OPT_THROUGHPUT	0x20
42#define OPT_UTMP	0x40
43
44#define MAX_ENDDISC_CLASS 5
45
46#define Enabled(b, o) ((b)->cfg.opt & (o))
47
48struct sockaddr_un;
49struct datalink;
50struct physical;
51struct link;
52struct server;
53struct prompt;
54
55struct bundle {
56  struct descriptor desc;     /* really all our datalinks */
57  int unit;                   /* The device/interface unit number */
58
59  struct {
60    char Name[20];            /* The /dev/XXXX name */
61    int fd;                   /* The /dev/XXXX descriptor */
62  } dev;
63
64  struct {
65    u_long Speed;             /* struct tuninfo speed */
66    int Index;                /* The interface index */
67    char *Name;               /* The interface name */
68  } ifp;
69
70  int routing_seq;            /* The current routing sequence number */
71  u_int phase;                /* Curent phase */
72  int phys_type;              /* Union of all physical::type's */
73
74  unsigned CleaningUp : 1;    /* Going to exit.... */
75
76  struct fsm_parent fsm;      /* Our callback functions */
77  struct datalink *links;     /* Our data links */
78
79  struct {
80    int idle_timeout;         /* NCP Idle timeout value */
81    struct {
82      char name[50];          /* PAP/CHAP system name */
83      char key[50];           /* PAP/CHAP key */
84    } auth;
85    unsigned opt;             /* Uses OPT_ bits from above */
86    char label[50];           /* last thing `load'ed */
87    u_short mtu;              /* Interface mtu */
88
89    struct {                  /* We need/don't need another link when  */
90      struct {                /* more/less than                        */
91        int packets;          /* this number of packets are queued for */
92        int timeout;          /* this number of seconds                */
93      } max, min;
94    } autoload;
95  } cfg;
96
97  struct {
98    struct ipcp ipcp;         /* Our IPCP FSM */
99    struct mp mp;             /* Our MP */
100  } ncp;
101
102  struct {
103    struct filter in;		/* incoming packet filter */
104    struct filter out;		/* outgoing packet filter */
105    struct filter dial;		/* dial-out packet filter */
106    struct filter alive;	/* keep-alive packet filter */
107  } filter;
108
109  struct {
110    struct pppTimer timer;      /* timeout after cfg.idle_timeout */
111    time_t done;
112  } idle;
113
114  struct {
115    int fd;                     /* write status here */
116  } notify;
117
118  struct {
119    struct pppTimer timer;
120    time_t done;
121    unsigned running : 1;
122    unsigned comingup : 1;
123  } autoload;
124};
125
126#define descriptor2bundle(d) \
127  ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
128
129extern struct bundle *bundle_Create(const char *, int);
130extern void bundle_Destroy(struct bundle *);
131extern const char *bundle_PhaseName(struct bundle *);
132#define bundle_Phase(b) ((b)->phase)
133extern void bundle_NewPhase(struct bundle *, u_int);
134extern int  bundle_LinkIsUp(const struct bundle *);
135extern int bundle_SetRoute(struct bundle *, int, struct in_addr,
136                           struct in_addr, struct in_addr, int);
137extern void bundle_Close(struct bundle *, const char *, int);
138extern void bundle_Down(struct bundle *);
139extern void bundle_Open(struct bundle *, const char *, int);
140extern void bundle_LinkClosed(struct bundle *, struct datalink *);
141
142extern int bundle_FillQueues(struct bundle *);
143extern int bundle_ShowLinks(struct cmdargs const *);
144extern int bundle_ShowStatus(struct cmdargs const *);
145extern void bundle_StartIdleTimer(struct bundle *);
146extern void bundle_SetIdleTimer(struct bundle *, int);
147extern void bundle_StopIdleTimer(struct bundle *);
148extern int bundle_IsDead(struct bundle *);
149extern struct datalink *bundle2datalink(struct bundle *, const char *);
150
151extern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *);
152extern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *);
153
154extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
155
156extern int bundle_DatalinkClone(struct bundle *, struct datalink *,
157                                const char *);
158extern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
159extern void bundle_CleanDatalinks(struct bundle *);
160extern void bundle_SetLabel(struct bundle *, const char *);
161extern const char *bundle_GetLabel(struct bundle *);
162extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
163extern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *);
164extern int bundle_SetMode(struct bundle *, struct datalink *, int);
165extern int bundle_RenameDatalink(struct bundle *, struct datalink *,
166                                 const char *);
167extern void bundle_setsid(struct bundle *, int);
168