1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 #define PHASE_DEAD 0 /* Link is dead */ 32 #define PHASE_ESTABLISH 1 /* Establishing link */ 33 #define PHASE_AUTHENTICATE 2 /* Being authenticated */ 34 #define PHASE_NETWORK 3 /* We're alive ! */ 35 #define PHASE_TERMINATE 4 /* Terminating link */ 36 37 /* cfg.opt bit settings */ 38 #define OPT_FILTERDECAP 1 39 #define OPT_FORCE_SCRIPTS 2 /* force chat scripts */ 40 #define OPT_IDCHECK 3 41 #define OPT_IFACEALIAS 4 42 #ifndef NOINET6 43 #define OPT_IPCP 5 44 #define OPT_IPV6CP 6 45 #endif 46 #define OPT_KEEPSESSION 7 47 #define OPT_LOOPBACK 8 48 #define OPT_NAS_IP_ADDRESS 9 49 #define OPT_NAS_IDENTIFIER 10 50 #define OPT_PASSWDAUTH 11 51 #define OPT_PROXY 12 52 #define OPT_PROXYALL 13 53 #define OPT_SROUTES 14 54 #define OPT_TCPMSSFIXUP 15 55 #define OPT_THROUGHPUT 16 56 #define OPT_UTMP 17 57 #define OPT_MAX 17 58 59 #define MAX_ENDDISC_CLASS 5 60 61 #define Enabled(b, o) ((b)->cfg.optmask & (1ull << (o))) 62 #define opt_enable(b, o) ((b)->cfg.optmask |= (1ull << (o))) 63 #define opt_disable(b, o) ((b)->cfg.optmask &= ~(1ull << (o))) 64 65 /* AutoAdjust() values */ 66 #define AUTO_UP 1 67 #define AUTO_DOWN 2 68 69 struct sockaddr_un; 70 struct datalink; 71 struct physical; 72 struct link; 73 struct server; 74 struct prompt; 75 struct iface; 76 77 struct bundle { 78 struct fdescriptor desc; /* really all our datalinks */ 79 int unit; /* The device/interface unit number */ 80 81 struct { 82 char Name[20]; /* The /dev/XXXX name */ 83 int fd; /* The /dev/XXXX descriptor */ 84 unsigned header : 1; /* Family header sent & received ? */ 85 } dev; 86 87 u_long bandwidth; /* struct tuninfo speed */ 88 struct iface *iface; /* Interface information */ 89 90 int routing_seq; /* The current routing sequence number */ 91 u_int phase; /* Curent phase */ 92 93 struct { 94 int all; /* Union of all physical::type's */ 95 int open; /* Union of all open physical::type's */ 96 } phys_type; 97 98 unsigned CleaningUp : 1; /* Going to exit.... */ 99 unsigned NatEnabled : 1; /* Are we using libalias ? */ 100 101 struct fsm_parent fsm; /* Our callback functions */ 102 struct datalink *links; /* Our data links */ 103 104 time_t upat; /* When the link came up */ 105 106 struct { 107 struct { 108 unsigned timeout; /* NCP Idle timeout value */ 109 unsigned min_timeout; /* Don't idle out before this */ 110 } idle; 111 struct { 112 char name[AUTHLEN]; /* PAP/CHAP system name */ 113 char key[AUTHLEN]; /* PAP/CHAP key */ 114 } auth; 115 unsigned long long optmask; /* Uses OPT_ bits from above */ 116 char label[50]; /* last thing `load'ed */ 117 u_short ifqueue; /* Interface queue size */ 118 119 struct { 120 unsigned timeout; /* How long to leave the output queue choked */ 121 } choked; 122 } cfg; 123 124 struct ncp ncp; 125 126 struct { 127 struct filter in; /* incoming packet filter */ 128 struct filter out; /* outgoing packet filter */ 129 struct filter dial; /* dial-out packet filter */ 130 struct filter alive; /* keep-alive packet filter */ 131 } filter; 132 133 struct { 134 struct pppTimer timer; /* timeout after cfg.idle_timeout */ 135 time_t done; 136 } idle; 137 138 #ifndef NORADIUS 139 struct { 140 struct pppTimer timer; 141 time_t done; 142 } session; 143 #endif 144 145 struct { 146 int fd; /* write status here */ 147 } notify; 148 149 struct { 150 struct pppTimer timer; /* choked output queue timer */ 151 } choked; 152 153 #ifndef NORADIUS 154 struct radius radius; /* Info retrieved from radius server */ 155 struct radacct radacct; 156 #ifndef NOINET6 157 struct radacct radacct6; 158 #endif 159 #endif 160 }; 161 162 #define descriptor2bundle(d) \ 163 ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) 164 165 extern struct bundle *bundle_Create(const char *, int, int); 166 extern void bundle_Destroy(struct bundle *); 167 extern const char *bundle_PhaseName(struct bundle *); 168 #define bundle_Phase(b) ((b)->phase) 169 extern void bundle_NewPhase(struct bundle *, u_int); 170 extern void bundle_LinksRemoved(struct bundle *); 171 extern void bundle_Close(struct bundle *, const char *, int); 172 extern void bundle_Down(struct bundle *, int); 173 extern void bundle_Open(struct bundle *, const char *, int, int); 174 extern void bundle_LinkClosed(struct bundle *, struct datalink *); 175 176 extern int bundle_ShowLinks(struct cmdargs const *); 177 extern int bundle_ShowStatus(struct cmdargs const *); 178 extern void bundle_StartIdleTimer(struct bundle *, unsigned secs); 179 extern void bundle_SetIdleTimer(struct bundle *, unsigned, unsigned); 180 extern void bundle_StopIdleTimer(struct bundle *); 181 extern int bundle_IsDead(struct bundle *); 182 extern struct datalink *bundle2datalink(struct bundle *, const char *); 183 184 #ifndef NORADIUS 185 extern void bundle_StartSessionTimer(struct bundle *, unsigned secs); 186 extern void bundle_StopSessionTimer(struct bundle *); 187 #endif 188 189 extern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *); 190 extern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *); 191 192 extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *); 193 194 extern int bundle_DatalinkClone(struct bundle *, struct datalink *, 195 const char *); 196 extern void bundle_DatalinkRemove(struct bundle *, struct datalink *); 197 extern void bundle_CleanDatalinks(struct bundle *); 198 extern void bundle_SetLabel(struct bundle *, const char *); 199 extern const char *bundle_GetLabel(struct bundle *); 200 extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *); 201 extern int bundle_LinkSize(void); 202 extern void bundle_ReceiveDatalink(struct bundle *, int); 203 extern int bundle_SetMode(struct bundle *, struct datalink *, int); 204 extern int bundle_RenameDatalink(struct bundle *, struct datalink *, 205 const char *); 206 extern void bundle_setsid(struct bundle *, int); 207 extern void bundle_LockTun(struct bundle *); 208 extern unsigned bundle_HighestState(struct bundle *); 209 extern int bundle_Exception(struct bundle *, int); 210 extern void bundle_AdjustFilters(struct bundle *, struct ncpaddr *, 211 struct ncpaddr *); 212 extern void bundle_AdjustDNS(struct bundle *); 213 extern void bundle_CalculateBandwidth(struct bundle *); 214 extern void bundle_AutoAdjust(struct bundle *, int, int); 215 extern int bundle_WantAutoloadTimer(struct bundle *); 216 extern void bundle_ChangedPID(struct bundle *); 217 extern void bundle_Notify(struct bundle *, char); 218 extern int bundle_Uptime(struct bundle *); 219