bundle.h revision 40679
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.17 1998/10/26 19:07:42 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 0x0001 37#define OPT_IFACEALIAS 0x0002 38#define OPT_LOOPBACK 0x0004 39#define OPT_PASSWDAUTH 0x0008 40#define OPT_PROXY 0x0010 41#define OPT_PROXYALL 0x0020 42#define OPT_SROUTES 0x0040 43#define OPT_THROUGHPUT 0x0080 44#define OPT_UTMP 0x0100 45 46#define MAX_ENDDISC_CLASS 5 47 48#define Enabled(b, o) ((b)->cfg.opt & (o)) 49 50struct sockaddr_un; 51struct datalink; 52struct physical; 53struct link; 54struct server; 55struct prompt; 56struct iface; 57 58struct bundle { 59 struct descriptor desc; /* really all our datalinks */ 60 int unit; /* The device/interface unit number */ 61 const char **argv; /* From main() */ 62 const char *argv0; /* Original */ 63 const char *argv1; /* Original */ 64 65 struct { 66 char Name[20]; /* The /dev/XXXX name */ 67 int fd; /* The /dev/XXXX descriptor */ 68 } dev; 69 70#if 0 71 struct { 72 int Index; /* The interface index */ 73 char *Name; /* The interface name */ 74 } ifp; 75#endif 76 77 u_long ifSpeed; /* struct tuninfo speed */ 78 struct iface *iface; /* Interface information */ 79 80 int routing_seq; /* The current routing sequence number */ 81 u_int phase; /* Curent phase */ 82 83 struct { 84 int all; /* Union of all physical::type's */ 85 int open; /* Union of all open physical::type's */ 86 } phys_type; 87 88 unsigned CleaningUp : 1; /* Going to exit.... */ 89 unsigned AliasEnabled : 1; /* Are we using libalias ? */ 90 91 struct fsm_parent fsm; /* Our callback functions */ 92 struct datalink *links; /* Our data links */ 93 94 struct { 95 int idle_timeout; /* NCP Idle timeout value */ 96 struct { 97 char name[50]; /* PAP/CHAP system name */ 98 char key[50]; /* PAP/CHAP key */ 99 } auth; 100 unsigned opt; /* Uses OPT_ bits from above */ 101 char label[50]; /* last thing `load'ed */ 102 u_short mtu; /* Interface mtu */ 103 104 struct { /* We need/don't need another link when */ 105 struct { /* more/less than */ 106 int packets; /* this number of packets are queued for */ 107 int timeout; /* this number of seconds */ 108 } max, min; 109 } autoload; 110 111 struct { 112 int timeout; /* How long to leave the output queue choked */ 113 } choked; 114 } cfg; 115 116 struct { 117 struct ipcp ipcp; /* Our IPCP FSM */ 118 struct mp mp; /* Our MP */ 119 } ncp; 120 121 struct { 122 struct filter in; /* incoming packet filter */ 123 struct filter out; /* outgoing packet filter */ 124 struct filter dial; /* dial-out packet filter */ 125 struct filter alive; /* keep-alive packet filter */ 126 } filter; 127 128 struct { 129 struct pppTimer timer; /* timeout after cfg.idle_timeout */ 130 time_t done; 131 } idle; 132 133 struct { 134 int fd; /* write status here */ 135 } notify; 136 137 struct { 138 struct pppTimer timer; 139 time_t done; 140 unsigned running : 1; 141 unsigned comingup : 1; 142 } autoload; 143 144 struct { 145 struct pppTimer timer; /* choked output queue timer */ 146 } choked; 147}; 148 149#define descriptor2bundle(d) \ 150 ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) 151 152extern struct bundle *bundle_Create(const char *, int, const char **); 153extern void bundle_Destroy(struct bundle *); 154extern const char *bundle_PhaseName(struct bundle *); 155#define bundle_Phase(b) ((b)->phase) 156extern void bundle_NewPhase(struct bundle *, u_int); 157extern void bundle_LinksRemoved(struct bundle *); 158extern int bundle_LinkIsUp(const struct bundle *); 159extern int bundle_SetRoute(struct bundle *, int, struct in_addr, 160 struct in_addr, struct in_addr, int, int); 161extern void bundle_Close(struct bundle *, const char *, int); 162extern void bundle_Down(struct bundle *, int); 163extern void bundle_Open(struct bundle *, const char *, int, int); 164extern void bundle_LinkClosed(struct bundle *, struct datalink *); 165 166extern int bundle_FillQueues(struct bundle *); 167extern int bundle_ShowLinks(struct cmdargs const *); 168extern int bundle_ShowStatus(struct cmdargs const *); 169extern void bundle_StartIdleTimer(struct bundle *); 170extern void bundle_SetIdleTimer(struct bundle *, int); 171extern void bundle_StopIdleTimer(struct bundle *); 172extern int bundle_IsDead(struct bundle *); 173extern struct datalink *bundle2datalink(struct bundle *, const char *); 174 175extern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *); 176extern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *); 177 178extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *); 179 180extern int bundle_DatalinkClone(struct bundle *, struct datalink *, 181 const char *); 182extern void bundle_DatalinkRemove(struct bundle *, struct datalink *); 183extern void bundle_CleanDatalinks(struct bundle *); 184extern void bundle_SetLabel(struct bundle *, const char *); 185extern const char *bundle_GetLabel(struct bundle *); 186extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *); 187extern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *); 188extern int bundle_SetMode(struct bundle *, struct datalink *, int); 189extern int bundle_RenameDatalink(struct bundle *, struct datalink *, 190 const char *); 191extern void bundle_setsid(struct bundle *, int); 192extern void bundle_LockTun(struct bundle *); 193extern int bundle_HighestState(struct bundle *); 194