bundle.h revision 49434
1112758Ssam/*- 2112758Ssam * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3112758Ssam * All rights reserved. 4112758Ssam * 5112758Ssam * Redistribution and use in source and binary forms, with or without 6112758Ssam * modification, are permitted provided that the following conditions 7112758Ssam * are met: 8112758Ssam * 1. Redistributions of source code must retain the above copyright 9112758Ssam * notice, this list of conditions and the following disclaimer. 10112758Ssam * 2. Redistributions in binary form must reproduce the above copyright 11112758Ssam * notice, this list of conditions and the following disclaimer in the 12112758Ssam * documentation and/or other materials provided with the distribution. 13112758Ssam * 14112758Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15112758Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16112758Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17112758Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18112758Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19112758Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20112758Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21112758Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22112758Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23112758Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24112758Ssam * SUCH DAMAGE. 25112758Ssam * 26112758Ssam * $Id: bundle.h,v 1.23 1999/06/02 00:46:52 brian Exp $ 27112758Ssam */ 28105197Ssam 29105197Ssam#define PHASE_DEAD 0 /* Link is dead */ 30105197Ssam#define PHASE_ESTABLISH 1 /* Establishing link */ 31105197Ssam#define PHASE_AUTHENTICATE 2 /* Being authenticated */ 32105197Ssam#define PHASE_NETWORK 3 /* We're alive ! */ 33105197Ssam#define PHASE_TERMINATE 4 /* Terminating link */ 34105197Ssam 35159965Sthompsa/* cfg.opt bit settings */ 36105197Ssam#define OPT_IDCHECK 0x0001 37105197Ssam#define OPT_IFACEALIAS 0x0002 38105197Ssam#define OPT_KEEPSESSION 0x0004 39105197Ssam#define OPT_LOOPBACK 0x0008 40105197Ssam#define OPT_PASSWDAUTH 0x0010 41105197Ssam#define OPT_PROXY 0x0020 42105197Ssam#define OPT_PROXYALL 0x0040 43105197Ssam#define OPT_SROUTES 0x0080 44105197Ssam#define OPT_THROUGHPUT 0x0100 45105197Ssam#define OPT_UTMP 0x0200 46105197Ssam 47171497Sbz#define MAX_ENDDISC_CLASS 5 48105197Ssam 49195699Srwatson#define Enabled(b, o) ((b)->cfg.opt & (o)) 50105197Ssam 51105197Ssam/* AutoAdjust() values */ 52105197Ssam#define AUTO_UP 1 53105197Ssam#define AUTO_DOWN 2 54105197Ssam 55105197Ssamstruct sockaddr_un; 56105197Ssamstruct datalink; 57105197Ssamstruct physical; 58105197Ssamstruct link; 59105197Ssamstruct server; 60105197Ssamstruct prompt; 61105197Ssamstruct iface; 62105197Ssam 63105197Ssamstruct bundle { 64105197Ssam struct descriptor desc; /* really all our datalinks */ 65105197Ssam int unit; /* The device/interface unit number */ 66105197Ssam const char **argv; /* From main() */ 67105197Ssam const char *argv0; /* Original */ 68105197Ssam const char *argv1; /* Original */ 69105197Ssam 70105197Ssam struct { 71105197Ssam char Name[20]; /* The /dev/XXXX name */ 72105197Ssam int fd; /* The /dev/XXXX descriptor */ 73105197Ssam } dev; 74105197Ssam 75105197Ssam u_long bandwidth; /* struct tuninfo speed */ 76105197Ssam struct iface *iface; /* Interface information */ 77105197Ssam 78105197Ssam int routing_seq; /* The current routing sequence number */ 79105197Ssam u_int phase; /* Curent phase */ 80105197Ssam 81105197Ssam struct { 82105197Ssam int all; /* Union of all physical::type's */ 83105197Ssam int open; /* Union of all open physical::type's */ 84105197Ssam } phys_type; 85105197Ssam 86194062Svanhu unsigned CleaningUp : 1; /* Going to exit.... */ 87194062Svanhu unsigned AliasEnabled : 1; /* Are we using libalias ? */ 88194062Svanhu 89194062Svanhu struct fsm_parent fsm; /* Our callback functions */ 90181627Svanhu struct datalink *links; /* Our data links */ 91181627Svanhu 92181627Svanhu struct { 93181627Svanhu int idle_timeout; /* NCP Idle timeout value */ 94181627Svanhu struct { 95105197Ssam char name[AUTHLEN]; /* PAP/CHAP system name */ 96105197Ssam char key[AUTHLEN]; /* PAP/CHAP key */ 97105197Ssam } auth; 98105197Ssam unsigned opt; /* Uses OPT_ bits from above */ 99105197Ssam char label[50]; /* last thing `load'ed */ 100105197Ssam u_short mtu; /* Interface mtu */ 101105197Ssam 102105197Ssam struct { 103105197Ssam int timeout; /* How long to leave the output queue choked */ 104120585Ssam } choked; 105120585Ssam } cfg; 106105197Ssam 107120585Ssam struct { 108120585Ssam struct ipcp ipcp; /* Our IPCP FSM */ 109105197Ssam struct mp mp; /* Our MP */ 110105197Ssam } ncp; 111105197Ssam 112105197Ssam struct { 113105197Ssam struct filter in; /* incoming packet filter */ 114105197Ssam struct filter out; /* outgoing packet filter */ 115105197Ssam struct filter dial; /* dial-out packet filter */ 116105197Ssam struct filter alive; /* keep-alive packet filter */ 117105197Ssam } filter; 118105197Ssam 119105197Ssam struct { 120105197Ssam struct pppTimer timer; /* timeout after cfg.idle_timeout */ 121105197Ssam time_t done; 122105197Ssam } idle; 123105197Ssam 124105197Ssam struct { 125105197Ssam int fd; /* write status here */ 126105197Ssam } notify; 127105197Ssam 128105197Ssam struct { 129105197Ssam struct pppTimer timer; /* choked output queue timer */ 130105197Ssam } choked; 131105197Ssam 132105197Ssam#ifndef NORADIUS 133105197Ssam struct radius radius; /* Info retrieved from radius server */ 134105197Ssam#endif 135120585Ssam}; 136105197Ssam 137105197Ssam#define descriptor2bundle(d) \ 138105197Ssam ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) 139105197Ssam 140105197Ssamextern struct bundle *bundle_Create(const char *, int, const char **); 141105197Ssamextern void bundle_Destroy(struct bundle *); 142105197Ssamextern const char *bundle_PhaseName(struct bundle *); 143105197Ssam#define bundle_Phase(b) ((b)->phase) 144105197Ssamextern void bundle_NewPhase(struct bundle *, u_int); 145105197Ssamextern void bundle_LinksRemoved(struct bundle *); 146105197Ssamextern int bundle_LinkIsUp(const struct bundle *); 147105197Ssamextern int bundle_SetRoute(struct bundle *, int, struct in_addr, 148120585Ssam struct in_addr, struct in_addr, int, int); 149105197Ssamextern void bundle_Close(struct bundle *, const char *, int); 150105197Ssamextern void bundle_Down(struct bundle *, int); 151105197Ssamextern void bundle_Open(struct bundle *, const char *, int, int); 152105197Ssamextern void bundle_LinkClosed(struct bundle *, struct datalink *); 153105197Ssam 154105197Ssamextern int bundle_FillQueues(struct bundle *); 155105197Ssamextern int bundle_ShowLinks(struct cmdargs const *); 156105197Ssamextern int bundle_ShowStatus(struct cmdargs const *); 157105197Ssamextern void bundle_StartIdleTimer(struct bundle *); 158105197Ssamextern void bundle_SetIdleTimer(struct bundle *, int); 159105197Ssamextern void bundle_StopIdleTimer(struct bundle *); 160105197Ssamextern int bundle_IsDead(struct bundle *); 161105197Ssamextern struct datalink *bundle2datalink(struct bundle *, const char *); 162105197Ssam 163105197Ssamextern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *); 164105197Ssamextern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *); 165105197Ssam 166105197Ssamextern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *); 167181803Sbz 168238700Sbzextern int bundle_DatalinkClone(struct bundle *, struct datalink *, 169221129Sbz const char *); 170221129Sbzextern void bundle_DatalinkRemove(struct bundle *, struct datalink *); 171221129Sbzextern void bundle_CleanDatalinks(struct bundle *); 172221129Sbzextern void bundle_SetLabel(struct bundle *, const char *); 173221129Sbzextern const char *bundle_GetLabel(struct bundle *); 174221129Sbzextern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *); 175221129Sbzextern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *); 176221129Sbzextern int bundle_SetMode(struct bundle *, struct datalink *, int); 177221129Sbzextern int bundle_RenameDatalink(struct bundle *, struct datalink *, 178221129Sbz const char *); 179221129Sbzextern void bundle_setsid(struct bundle *, int); 180221129Sbzextern void bundle_LockTun(struct bundle *); 181221129Sbzextern int bundle_HighestState(struct bundle *); 182221129Sbzextern int bundle_Exception(struct bundle *, int); 183221129Sbzextern void bundle_AdjustFilters(struct bundle *, struct in_addr *, 184221129Sbz struct in_addr *); 185221129Sbzextern void bundle_CalculateBandwidth(struct bundle *); 186221129Sbzextern void bundle_AutoAdjust(struct bundle *, int, int); 187221129Sbzextern int bundle_WantAutoloadTimer(struct bundle *); 188221129Sbz