bundle.h revision 49434
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 * 2649434Sbrian * $Id: bundle.h,v 1.23 1999/06/02 00:46:52 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 */ 3640665Sbrian#define OPT_IDCHECK 0x0001 3740666Sbrian#define OPT_IFACEALIAS 0x0002 3847689Sbrian#define OPT_KEEPSESSION 0x0004 3947689Sbrian#define OPT_LOOPBACK 0x0008 4047689Sbrian#define OPT_PASSWDAUTH 0x0010 4147689Sbrian#define OPT_PROXY 0x0020 4247689Sbrian#define OPT_PROXYALL 0x0040 4347689Sbrian#define OPT_SROUTES 0x0080 4447689Sbrian#define OPT_THROUGHPUT 0x0100 4547689Sbrian#define OPT_UTMP 0x0200 4636285Sbrian 4736285Sbrian#define MAX_ENDDISC_CLASS 5 4836285Sbrian 4936285Sbrian#define Enabled(b, o) ((b)->cfg.opt & (o)) 5036285Sbrian 5149434Sbrian/* AutoAdjust() values */ 5249434Sbrian#define AUTO_UP 1 5349434Sbrian#define AUTO_DOWN 2 5449434Sbrian 5536285Sbrianstruct sockaddr_un; 5636285Sbrianstruct datalink; 5736285Sbrianstruct physical; 5836285Sbrianstruct link; 5936285Sbrianstruct server; 6036285Sbrianstruct prompt; 6140561Sbrianstruct iface; 6236285Sbrian 6336285Sbrianstruct bundle { 6436285Sbrian struct descriptor desc; /* really all our datalinks */ 6536285Sbrian int unit; /* The device/interface unit number */ 6636467Sbrian const char **argv; /* From main() */ 6740679Sbrian const char *argv0; /* Original */ 6840679Sbrian const char *argv1; /* Original */ 6936285Sbrian 7036285Sbrian struct { 7136285Sbrian char Name[20]; /* The /dev/XXXX name */ 7236285Sbrian int fd; /* The /dev/XXXX descriptor */ 7336285Sbrian } dev; 7436285Sbrian 7549434Sbrian u_long bandwidth; /* struct tuninfo speed */ 7640561Sbrian struct iface *iface; /* Interface information */ 7740561Sbrian 7836285Sbrian int routing_seq; /* The current routing sequence number */ 7936285Sbrian u_int phase; /* Curent phase */ 8036285Sbrian 8136928Sbrian struct { 8236928Sbrian int all; /* Union of all physical::type's */ 8336928Sbrian int open; /* Union of all open physical::type's */ 8436928Sbrian } phys_type; 8536928Sbrian 8636285Sbrian unsigned CleaningUp : 1; /* Going to exit.... */ 8737191Sbrian unsigned AliasEnabled : 1; /* Are we using libalias ? */ 8836285Sbrian 8936285Sbrian struct fsm_parent fsm; /* Our callback functions */ 9036285Sbrian struct datalink *links; /* Our data links */ 9136285Sbrian 9236285Sbrian struct { 9336285Sbrian int idle_timeout; /* NCP Idle timeout value */ 9436285Sbrian struct { 9543313Sbrian char name[AUTHLEN]; /* PAP/CHAP system name */ 9643313Sbrian char key[AUTHLEN]; /* PAP/CHAP key */ 9736285Sbrian } auth; 9836285Sbrian unsigned opt; /* Uses OPT_ bits from above */ 9936285Sbrian char label[50]; /* last thing `load'ed */ 10036285Sbrian u_short mtu; /* Interface mtu */ 10136285Sbrian 10238544Sbrian struct { 10343313Sbrian int timeout; /* How long to leave the output queue choked */ 10438544Sbrian } choked; 10536285Sbrian } cfg; 10636285Sbrian 10736285Sbrian struct { 10836285Sbrian struct ipcp ipcp; /* Our IPCP FSM */ 10936285Sbrian struct mp mp; /* Our MP */ 11036285Sbrian } ncp; 11136285Sbrian 11236285Sbrian struct { 11343313Sbrian struct filter in; /* incoming packet filter */ 11443313Sbrian struct filter out; /* outgoing packet filter */ 11543313Sbrian struct filter dial; /* dial-out packet filter */ 11643313Sbrian struct filter alive; /* keep-alive packet filter */ 11736285Sbrian } filter; 11836285Sbrian 11936285Sbrian struct { 12043313Sbrian struct pppTimer timer; /* timeout after cfg.idle_timeout */ 12136285Sbrian time_t done; 12236285Sbrian } idle; 12336285Sbrian 12436285Sbrian struct { 12543313Sbrian int fd; /* write status here */ 12636285Sbrian } notify; 12736285Sbrian 12836285Sbrian struct { 12943313Sbrian struct pppTimer timer; /* choked output queue timer */ 13038544Sbrian } choked; 13143313Sbrian 13243313Sbrian#ifndef NORADIUS 13343313Sbrian struct radius radius; /* Info retrieved from radius server */ 13443313Sbrian#endif 13536285Sbrian}; 13636285Sbrian 13736285Sbrian#define descriptor2bundle(d) \ 13836285Sbrian ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) 13936285Sbrian 14036467Sbrianextern struct bundle *bundle_Create(const char *, int, const char **); 14136285Sbrianextern void bundle_Destroy(struct bundle *); 14236285Sbrianextern const char *bundle_PhaseName(struct bundle *); 14336285Sbrian#define bundle_Phase(b) ((b)->phase) 14436285Sbrianextern void bundle_NewPhase(struct bundle *, u_int); 14538174Sbrianextern void bundle_LinksRemoved(struct bundle *); 14636285Sbrianextern int bundle_LinkIsUp(const struct bundle *); 14736285Sbrianextern int bundle_SetRoute(struct bundle *, int, struct in_addr, 14837927Sbrian struct in_addr, struct in_addr, int, int); 14936285Sbrianextern void bundle_Close(struct bundle *, const char *, int); 15037018Sbrianextern void bundle_Down(struct bundle *, int); 15137955Sbrianextern void bundle_Open(struct bundle *, const char *, int, int); 15236285Sbrianextern void bundle_LinkClosed(struct bundle *, struct datalink *); 15336285Sbrian 15436285Sbrianextern int bundle_FillQueues(struct bundle *); 15536285Sbrianextern int bundle_ShowLinks(struct cmdargs const *); 15636285Sbrianextern int bundle_ShowStatus(struct cmdargs const *); 15736285Sbrianextern void bundle_StartIdleTimer(struct bundle *); 15836285Sbrianextern void bundle_SetIdleTimer(struct bundle *, int); 15936285Sbrianextern void bundle_StopIdleTimer(struct bundle *); 16036285Sbrianextern int bundle_IsDead(struct bundle *); 16136285Sbrianextern struct datalink *bundle2datalink(struct bundle *, const char *); 16236285Sbrian 16336285Sbrianextern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *); 16436285Sbrianextern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *); 16536285Sbrian 16636285Sbrianextern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *); 16736285Sbrian 16836285Sbrianextern int bundle_DatalinkClone(struct bundle *, struct datalink *, 16936285Sbrian const char *); 17036285Sbrianextern void bundle_DatalinkRemove(struct bundle *, struct datalink *); 17136285Sbrianextern void bundle_CleanDatalinks(struct bundle *); 17236285Sbrianextern void bundle_SetLabel(struct bundle *, const char *); 17336285Sbrianextern const char *bundle_GetLabel(struct bundle *); 17436285Sbrianextern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *); 17536285Sbrianextern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *); 17636285Sbrianextern int bundle_SetMode(struct bundle *, struct datalink *, int); 17736285Sbrianextern int bundle_RenameDatalink(struct bundle *, struct datalink *, 17836285Sbrian const char *); 17936452Sbrianextern void bundle_setsid(struct bundle *, int); 18036709Sbrianextern void bundle_LockTun(struct bundle *); 18140622Sbrianextern int bundle_HighestState(struct bundle *); 18241654Sbrianextern int bundle_Exception(struct bundle *, int); 18347648Sbrianextern void bundle_AdjustFilters(struct bundle *, struct in_addr *, 18447648Sbrian struct in_addr *); 18549434Sbrianextern void bundle_CalculateBandwidth(struct bundle *); 18649434Sbrianextern void bundle_AutoAdjust(struct bundle *, int, int); 18749434Sbrianextern int bundle_WantAutoloadTimer(struct bundle *); 188