bundle.h revision 62778
1234353Sdim/*- 2204642Srdivacky * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3204642Srdivacky * All rights reserved. 4204642Srdivacky * 5204642Srdivacky * Redistribution and use in source and binary forms, with or without 6204642Srdivacky * modification, are permitted provided that the following conditions 7204642Srdivacky * are met: 8204642Srdivacky * 1. Redistributions of source code must retain the above copyright 9204642Srdivacky * notice, this list of conditions and the following disclaimer. 10204642Srdivacky * 2. Redistributions in binary form must reproduce the above copyright 11204642Srdivacky * notice, this list of conditions and the following disclaimer in the 12204642Srdivacky * documentation and/or other materials provided with the distribution. 13204642Srdivacky * 14204642Srdivacky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15204642Srdivacky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16204642Srdivacky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17218893Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18204642Srdivacky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19249423Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20204642Srdivacky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21204642Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22204642Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23204642Srdivacky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24204642Srdivacky * SUCH DAMAGE. 25204642Srdivacky * 26204642Srdivacky * $FreeBSD: head/usr.sbin/ppp/bundle.h 62778 2000-07-07 14:22:08Z brian $ 27234353Sdim */ 28204642Srdivacky 29218893Sdim#define PHASE_DEAD 0 /* Link is dead */ 30204642Srdivacky#define PHASE_ESTABLISH 1 /* Establishing link */ 31204642Srdivacky#define PHASE_AUTHENTICATE 2 /* Being authenticated */ 32204642Srdivacky#define PHASE_NETWORK 3 /* We're alive ! */ 33218893Sdim#define PHASE_TERMINATE 4 /* Terminating link */ 34204642Srdivacky 35204642Srdivacky/* cfg.opt bit settings */ 36204642Srdivacky#define OPT_FILTERDECAP 0x0001 37204642Srdivacky#define OPT_IDCHECK 0x0002 38204642Srdivacky#define OPT_IFACEALIAS 0x0004 39204642Srdivacky#define OPT_KEEPSESSION 0x0008 40204642Srdivacky#define OPT_LOOPBACK 0x0010 41204642Srdivacky#define OPT_PASSWDAUTH 0x0020 42204642Srdivacky#define OPT_PROXY 0x0040 43204642Srdivacky#define OPT_PROXYALL 0x0080 44204642Srdivacky#define OPT_SROUTES 0x0100 45204642Srdivacky#define OPT_THROUGHPUT 0x0200 46204642Srdivacky#define OPT_UTMP 0x0400 47218893Sdim 48218893Sdim#define MAX_ENDDISC_CLASS 5 49218893Sdim 50204642Srdivacky#define Enabled(b, o) ((b)->cfg.opt & (o)) 51204642Srdivacky 52204642Srdivacky/* AutoAdjust() values */ 53204642Srdivacky#define AUTO_UP 1 54218893Sdim#define AUTO_DOWN 2 55218893Sdim 56204642Srdivackystruct sockaddr_un; 57204642Srdivackystruct datalink; 58204642Srdivackystruct physical; 59218893Sdimstruct link; 60218893Sdimstruct server; 61204642Srdivackystruct prompt; 62218893Sdimstruct iface; 63204642Srdivacky 64204642Srdivackystruct bundle { 65204642Srdivacky struct fdescriptor desc; /* really all our datalinks */ 66218893Sdim int unit; /* The device/interface unit number */ 67218893Sdim 68218893Sdim struct { 69218893Sdim char Name[20]; /* The /dev/XXXX name */ 70218893Sdim int fd; /* The /dev/XXXX descriptor */ 71204642Srdivacky unsigned header : 1; /* Family header sent & received ? */ 72204642Srdivacky } dev; 73204642Srdivacky 74204642Srdivacky u_long bandwidth; /* struct tuninfo speed */ 75204642Srdivacky struct iface *iface; /* Interface information */ 76204642Srdivacky 77204642Srdivacky int routing_seq; /* The current routing sequence number */ 78204642Srdivacky u_int phase; /* Curent phase */ 79204642Srdivacky 80204642Srdivacky struct { 81207618Srdivacky int all; /* Union of all physical::type's */ 82207618Srdivacky int open; /* Union of all open physical::type's */ 83207618Srdivacky } phys_type; 84218893Sdim 85218893Sdim unsigned CleaningUp : 1; /* Going to exit.... */ 86218893Sdim unsigned NatEnabled : 1; /* Are we using libalias ? */ 87218893Sdim 88204642Srdivacky struct fsm_parent fsm; /* Our callback functions */ 89218893Sdim struct datalink *links; /* Our data links */ 90218893Sdim 91218893Sdim time_t upat; /* When the link came up */ 92218893Sdim 93204642Srdivacky struct { 94204642Srdivacky struct { 95204642Srdivacky int timeout; /* NCP Idle timeout value */ 96204642Srdivacky int min_timeout; /* Don't idle out before this */ 97204642Srdivacky } idle; 98204642Srdivacky struct { 99204642Srdivacky char name[AUTHLEN]; /* PAP/CHAP system name */ 100204642Srdivacky char key[AUTHLEN]; /* PAP/CHAP key */ 101204642Srdivacky } auth; 102204642Srdivacky unsigned opt; /* Uses OPT_ bits from above */ 103204642Srdivacky char label[50]; /* last thing `load'ed */ 104204642Srdivacky u_short mtu; /* Interface mtu */ 105204642Srdivacky u_short ifqueue; /* Interface queue size */ 106204642Srdivacky 107204642Srdivacky struct { 108218893Sdim int timeout; /* How long to leave the output queue choked */ 109204642Srdivacky } choked; 110218893Sdim } cfg; 111218893Sdim 112218893Sdim struct { 113218893Sdim struct ipcp ipcp; /* Our IPCP FSM */ 114218893Sdim struct mp mp; /* Our MP */ 115218893Sdim } ncp; 116218893Sdim 117218893Sdim struct { 118218893Sdim struct filter in; /* incoming packet filter */ 119218893Sdim struct filter out; /* outgoing packet filter */ 120218893Sdim struct filter dial; /* dial-out packet filter */ 121218893Sdim struct filter alive; /* keep-alive packet filter */ 122218893Sdim } filter; 123218893Sdim 124218893Sdim struct { 125218893Sdim struct pppTimer timer; /* timeout after cfg.idle_timeout */ 126218893Sdim time_t done; 127218893Sdim } idle; 128218893Sdim 129218893Sdim struct { 130218893Sdim int fd; /* write status here */ 131218893Sdim } notify; 132218893Sdim 133218893Sdim struct { 134218893Sdim struct pppTimer timer; /* choked output queue timer */ 135204642Srdivacky } choked; 136204642Srdivacky 137204642Srdivacky#ifndef NORADIUS 138204642Srdivacky struct radius radius; /* Info retrieved from radius server */ 139218893Sdim#endif 140204642Srdivacky}; 141204642Srdivacky 142204642Srdivacky#define descriptor2bundle(d) \ 143204642Srdivacky ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) 144204642Srdivacky 145204642Srdivackyextern struct bundle *bundle_Create(const char *, int, int); 146204642Srdivackyextern void bundle_Destroy(struct bundle *); 147218893Sdimextern const char *bundle_PhaseName(struct bundle *); 148218893Sdim#define bundle_Phase(b) ((b)->phase) 149204642Srdivackyextern void bundle_NewPhase(struct bundle *, u_int); 150218893Sdimextern void bundle_LinksRemoved(struct bundle *); 151204642Srdivackyextern int bundle_LinkIsUp(const struct bundle *); 152218893Sdimextern int bundle_SetRoute(struct bundle *, int, struct in_addr, 153218893Sdim struct in_addr, struct in_addr, int, int); 154218893Sdimextern void bundle_Close(struct bundle *, const char *, int); 155204642Srdivackyextern void bundle_Down(struct bundle *, int); 156204642Srdivackyextern void bundle_Open(struct bundle *, const char *, int, int); 157204642Srdivackyextern void bundle_LinkClosed(struct bundle *, struct datalink *); 158204642Srdivacky 159204642Srdivackyextern int bundle_ShowLinks(struct cmdargs const *); 160204642Srdivackyextern int bundle_ShowStatus(struct cmdargs const *); 161204642Srdivackyextern void bundle_StartIdleTimer(struct bundle *); 162207618Srdivackyextern void bundle_SetIdleTimer(struct bundle *, int, int); 163207618Srdivackyextern void bundle_StopIdleTimer(struct bundle *); 164207618Srdivackyextern int bundle_IsDead(struct bundle *); 165204642Srdivackyextern struct datalink *bundle2datalink(struct bundle *, const char *); 166204642Srdivacky 167204642Srdivackyextern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *); 168204642Srdivackyextern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *); 169204642Srdivacky 170extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *); 171 172extern int bundle_DatalinkClone(struct bundle *, struct datalink *, 173 const char *); 174extern void bundle_DatalinkRemove(struct bundle *, struct datalink *); 175extern void bundle_CleanDatalinks(struct bundle *); 176extern void bundle_SetLabel(struct bundle *, const char *); 177extern const char *bundle_GetLabel(struct bundle *); 178extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *); 179extern int bundle_LinkSize(void); 180extern void bundle_ReceiveDatalink(struct bundle *, int); 181extern int bundle_SetMode(struct bundle *, struct datalink *, int); 182extern int bundle_RenameDatalink(struct bundle *, struct datalink *, 183 const char *); 184extern void bundle_setsid(struct bundle *, int); 185extern void bundle_LockTun(struct bundle *); 186extern int bundle_HighestState(struct bundle *); 187extern int bundle_Exception(struct bundle *, int); 188extern void bundle_AdjustFilters(struct bundle *, struct in_addr *, 189 struct in_addr *); 190extern void bundle_AdjustDNS(struct bundle *, struct in_addr [2]); 191extern void bundle_CalculateBandwidth(struct bundle *); 192extern void bundle_AutoAdjust(struct bundle *, int, int); 193extern int bundle_WantAutoloadTimer(struct bundle *); 194extern void bundle_ChangedPID(struct bundle *); 195extern void bundle_Notify(struct bundle *, char); 196