bundle.h revision 37018
1102227Smike/*- 2102227Smike * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3102227Smike * All rights reserved. 4102227Smike * 5102227Smike * Redistribution and use in source and binary forms, with or without 6102227Smike * modification, are permitted provided that the following conditions 7102227Smike * are met: 8102227Smike * 1. Redistributions of source code must retain the above copyright 9102227Smike * notice, this list of conditions and the following disclaimer. 10102227Smike * 2. Redistributions in binary form must reproduce the above copyright 11102227Smike * notice, this list of conditions and the following disclaimer in the 12102227Smike * documentation and/or other materials provided with the distribution. 13102227Smike * 14102227Smike * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15102227Smike * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16102227Smike * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17102227Smike * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18102227Smike * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19102227Smike * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20102227Smike * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21102227Smike * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22102227Smike * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23102227Smike * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24102227Smike * SUCH DAMAGE. 25102227Smike * 26102227Smike * $Id: bundle.h,v 1.7 1998/06/12 17:45:04 brian Exp $ 27102227Smike */ 28102227Smike 29102227Smike#define PHASE_DEAD 0 /* Link is dead */ 30102227Smike#define PHASE_ESTABLISH 1 /* Establishing link */ 31102227Smike#define PHASE_AUTHENTICATE 2 /* Being authenticated */ 32102227Smike#define PHASE_NETWORK 3 /* We're alive ! */ 33102227Smike#define PHASE_TERMINATE 4 /* Terminating link */ 34102227Smike 35102227Smike/* cfg.opt bit settings */ 36102227Smike#define OPT_IDCHECK 0x01 37102227Smike#define OPT_LOOPBACK 0x02 38143063Sjoerg#define OPT_PASSWDAUTH 0x04 39143063Sjoerg#define OPT_PROXY 0x08 40143063Sjoerg#define OPT_SROUTES 0x10 41143063Sjoerg#define OPT_THROUGHPUT 0x20 42102227Smike#define OPT_UTMP 0x40 43102227Smike 44102227Smike#define MAX_ENDDISC_CLASS 5 45228469Sed 46102227Smike#define Enabled(b, o) ((b)->cfg.opt & (o)) 47102227Smike 48102227Smikestruct sockaddr_un; 49102227Smikestruct datalink; 50102227Smikestruct physical; 51102227Smikestruct link; 52102227Smikestruct server; 53102227Smikestruct prompt; 54102227Smike 55102227Smikestruct bundle { 56102227Smike struct descriptor desc; /* really all our datalinks */ 57102227Smike int unit; /* The device/interface unit number */ 58102227Smike const char **argv; /* From main() */ 59332135Skevans 60110566Smike struct { 61110566Smike char Name[20]; /* The /dev/XXXX name */ 62332135Skevans int fd; /* The /dev/XXXX descriptor */ 63102227Smike } dev; 64102227Smike 65102227Smike struct { 66102227Smike u_long Speed; /* struct tuninfo speed */ 67102227Smike int Index; /* The interface index */ 68102227Smike char *Name; /* The interface name */ 69102227Smike } ifp; 70102227Smike 71102227Smike int routing_seq; /* The current routing sequence number */ 72102227Smike u_int phase; /* Curent phase */ 73102227Smike 74102227Smike struct { 75102227Smike int all; /* Union of all physical::type's */ 76102227Smike int open; /* Union of all open physical::type's */ 77102227Smike } phys_type; 78102227Smike 79126817Sgad unsigned CleaningUp : 1; /* Going to exit.... */ 80102227Smike 81102227Smike struct fsm_parent fsm; /* Our callback functions */ 82102227Smike struct datalink *links; /* Our data links */ 83102227Smike 84102227Smike struct { 85102227Smike int idle_timeout; /* NCP Idle timeout value */ 86102227Smike struct { 87102227Smike char name[50]; /* PAP/CHAP system name */ 88102227Smike char key[50]; /* PAP/CHAP key */ 89102227Smike } auth; 90102227Smike unsigned opt; /* Uses OPT_ bits from above */ 91102227Smike char label[50]; /* last thing `load'ed */ 92102227Smike u_short mtu; /* Interface mtu */ 93112569Sjake 94102227Smike struct { /* We need/don't need another link when */ 95263998Stijl struct { /* more/less than */ 96102227Smike int packets; /* this number of packets are queued for */ 97237517Sandrew int timeout; /* this number of seconds */ 98237517Sandrew } max, min; 99237517Sandrew } autoload; 100102227Smike } cfg; 101102227Smike 102102227Smike struct { 103143063Sjoerg struct ipcp ipcp; /* Our IPCP FSM */ 104102227Smike struct mp mp; /* Our MP */ 105102227Smike } ncp; 106102227Smike 107143063Sjoerg struct { 108143063Sjoerg struct filter in; /* incoming packet filter */ 109143063Sjoerg struct filter out; /* outgoing packet filter */ 110102227Smike struct filter dial; /* dial-out packet filter */ 111102227Smike struct filter alive; /* keep-alive packet filter */ 112102227Smike } filter; 113102227Smike 114102227Smike struct { 115 struct pppTimer timer; /* timeout after cfg.idle_timeout */ 116 time_t done; 117 } idle; 118 119 struct { 120 int fd; /* write status here */ 121 } notify; 122 123 struct { 124 struct pppTimer timer; 125 time_t done; 126 unsigned running : 1; 127 unsigned comingup : 1; 128 } autoload; 129}; 130 131#define descriptor2bundle(d) \ 132 ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) 133 134extern struct bundle *bundle_Create(const char *, int, const char **); 135extern void bundle_Destroy(struct bundle *); 136extern const char *bundle_PhaseName(struct bundle *); 137#define bundle_Phase(b) ((b)->phase) 138extern void bundle_NewPhase(struct bundle *, u_int); 139extern int bundle_LinkIsUp(const struct bundle *); 140extern int bundle_SetRoute(struct bundle *, int, struct in_addr, 141 struct in_addr, struct in_addr, int); 142extern void bundle_Close(struct bundle *, const char *, int); 143extern void bundle_Down(struct bundle *, int); 144extern void bundle_Open(struct bundle *, const char *, int); 145extern void bundle_LinkClosed(struct bundle *, struct datalink *); 146 147extern int bundle_FillQueues(struct bundle *); 148extern int bundle_ShowLinks(struct cmdargs const *); 149extern int bundle_ShowStatus(struct cmdargs const *); 150extern void bundle_StartIdleTimer(struct bundle *); 151extern void bundle_SetIdleTimer(struct bundle *, int); 152extern void bundle_StopIdleTimer(struct bundle *); 153extern int bundle_IsDead(struct bundle *); 154extern struct datalink *bundle2datalink(struct bundle *, const char *); 155 156extern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *); 157extern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *); 158 159extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *); 160 161extern int bundle_DatalinkClone(struct bundle *, struct datalink *, 162 const char *); 163extern void bundle_DatalinkRemove(struct bundle *, struct datalink *); 164extern void bundle_CleanDatalinks(struct bundle *); 165extern void bundle_SetLabel(struct bundle *, const char *); 166extern const char *bundle_GetLabel(struct bundle *); 167extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *); 168extern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *); 169extern int bundle_SetMode(struct bundle *, struct datalink *, int); 170extern int bundle_RenameDatalink(struct bundle *, struct datalink *, 171 const char *); 172extern void bundle_setsid(struct bundle *, int); 173extern void bundle_LockTun(struct bundle *); 174