1 /*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $Id: bundle.h,v 1.1.2.26 1998/04/05 22:48:02 brian Exp $ 27 */ 28 29 #define PHASE_DEAD 0 /* Link is dead */ 30 #define PHASE_ESTABLISH 1 /* Establishing link */ 31 #define PHASE_AUTHENTICATE 2 /* Being authenticated */ 32 #define PHASE_NETWORK 3 /* We're alive ! */ 33 #define PHASE_TERMINATE 4 /* Terminating link */ 34 35 36 struct datalink; 37 struct physical; 38 struct link; 39 struct server; 40 struct prompt; 41 42 struct bundle { 43 struct descriptor desc; /* really all our datalinks */ 44 int unit; /* The tun number */ 45 int ifIndex; /* The interface number */ 46 int tun_fd; /* The /dev/tunX descriptor */ 47 char dev[20]; /* The /dev/tunX name */ 48 char *ifname; /* The interface name */ 49 int routing_seq; /* The current routing sequence number */ 50 u_int phase; /* Curent phase */ 51 int phys_type; /* Union of all physical::type's */ 52 53 unsigned CleaningUp : 1; /* Going to exit.... */ 54 55 struct fsm_parent fsm; /* Our callback functions */ 56 struct datalink *links; /* Our data links */ 57 58 struct { 59 int idle_timeout; /* NCP Idle timeout value */ 60 struct { 61 char name[50]; /* PAP/CHAP system name */ 62 char key[50]; /* PAP/CHAP key */ 63 } auth; 64 } cfg; 65 66 struct { 67 struct ipcp ipcp; /* Our IPCP FSM */ 68 struct mp mp; /* Our MP */ 69 } ncp; 70 71 struct { 72 struct filter in; /* incoming packet filter */ 73 struct filter out; /* outgoing packet filter */ 74 struct filter dial; /* dial-out packet filter */ 75 struct filter alive; /* keep-alive packet filter */ 76 } filter; 77 78 struct { 79 struct pppTimer timer; /* timeout after cfg.idle_timeout */ 80 time_t done; 81 } idle; 82 83 struct { 84 int fd; /* write status here */ 85 } notify; 86 }; 87 88 #define descriptor2bundle(d) \ 89 ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL) 90 91 extern struct bundle *bundle_Create(const char *, struct prompt *, int); 92 extern void bundle_Destroy(struct bundle *); 93 extern const char *bundle_PhaseName(struct bundle *); 94 #define bundle_Phase(b) ((b)->phase) 95 extern void bundle_NewPhase(struct bundle *, u_int); 96 extern int bundle_LinkIsUp(const struct bundle *); 97 extern void bundle_SetRoute(struct bundle *, int, struct in_addr, 98 struct in_addr, struct in_addr, int); 99 extern void bundle_LinkLost(struct bundle *, struct physical *, int); 100 extern void bundle_Close(struct bundle *, const char *, int); 101 extern void bundle_Open(struct bundle *, const char *, int); 102 extern void bundle_LinkClosed(struct bundle *, struct datalink *); 103 104 extern int bundle_FillQueues(struct bundle *); 105 extern int bundle_ShowLinks(struct cmdargs const *); 106 extern void bundle_StartIdleTimer(struct bundle *); 107 extern void bundle_SetIdleTimer(struct bundle *, int); 108 extern void bundle_StopIdleTimer(struct bundle *); 109 extern int bundle_RemainingIdleTime(struct bundle *); 110 extern void bundle_LayerUp(struct bundle *, struct fsm *); 111 extern int bundle_IsDead(struct bundle *); 112 extern struct datalink *bundle2datalink(struct bundle *, const char *); 113 114 extern void bundle_RegisterDescriptor(struct bundle *, struct descriptor *); 115 extern void bundle_UnRegisterDescriptor(struct bundle *, struct descriptor *); 116 117 extern void bundle_DelPromptDescriptors(struct bundle *, struct server *); 118 extern void bundle_DisplayPrompt(struct bundle *); 119 extern void bundle_WriteTermPrompt(struct bundle *, struct datalink *, 120 const char *, int); 121 extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *); 122 123 extern void bundle_DatalinkClone(struct bundle *, struct datalink *, 124 const char *); 125 extern void bundle_DatalinkRemove(struct bundle *, struct datalink *); 126 extern void bundle_CleanDatalinks(struct bundle *); 127