ipcp.c (31171) | ipcp.c (31272) |
---|---|
1/* 2 * PPP IP Control Protocol (IPCP) Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * | 1/* 2 * PPP IP Control Protocol (IPCP) Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * |
20 * $Id: ipcp.c,v 1.35 1997/11/11 22:58:11 brian Exp $ | 20 * $Id: ipcp.c,v 1.36 1997/11/14 15:39:14 brian Exp $ |
21 * 22 * TODO: 23 * o More RFC1772 backwoard compatibility 24 */ 25#include <sys/param.h> 26#include <netinet/in_systm.h> 27#include <netinet/in.h> 28#include <netinet/ip.h> 29#include <arpa/inet.h> 30#include <sys/socket.h> 31#include <netdb.h> 32 33#include <limits.h> 34#include <stdio.h> 35#include <string.h> | 21 * 22 * TODO: 23 * o More RFC1772 backwoard compatibility 24 */ 25#include <sys/param.h> 26#include <netinet/in_systm.h> 27#include <netinet/in.h> 28#include <netinet/ip.h> 29#include <arpa/inet.h> 30#include <sys/socket.h> 31#include <netdb.h> 32 33#include <limits.h> 34#include <stdio.h> 35#include <string.h> |
36#include <time.h> |
|
36#include <unistd.h> 37 38#include "mbuf.h" 39#include "log.h" 40#include "defs.h" 41#include "timer.h" 42#include "fsm.h" 43#include "lcpproto.h" 44#include "lcp.h" 45#include "ipcp.h" 46#include "slcompress.h" 47#include "os.h" 48#include "phase.h" 49#include "loadalias.h" 50#include "command.h" 51#include "vars.h" 52#include "vjcomp.h" 53#include "ip.h" | 37#include <unistd.h> 38 39#include "mbuf.h" 40#include "log.h" 41#include "defs.h" 42#include "timer.h" 43#include "fsm.h" 44#include "lcpproto.h" 45#include "lcp.h" 46#include "ipcp.h" 47#include "slcompress.h" 48#include "os.h" 49#include "phase.h" 50#include "loadalias.h" 51#include "command.h" 52#include "vars.h" 53#include "vjcomp.h" 54#include "ip.h" |
55#include "throughput.h" |
|
54 55#ifndef NOMSEXT 56struct in_addr ns_entries[2]; 57struct in_addr nbns_entries[2]; 58#endif 59 60struct ipcpstate IpcpInfo; 61struct in_range DefMyAddress; 62struct in_range DefHisAddress; 63struct in_addr TriggerAddress; 64int HaveTriggerAddress; | 56 57#ifndef NOMSEXT 58struct in_addr ns_entries[2]; 59struct in_addr nbns_entries[2]; 60#endif 61 62struct ipcpstate IpcpInfo; 63struct in_range DefMyAddress; 64struct in_range DefHisAddress; 65struct in_addr TriggerAddress; 66int HaveTriggerAddress; |
65struct pppTimer IpcpReportTimer; | |
66 67static void IpcpSendConfigReq(struct fsm *); 68static void IpcpSendTerminateAck(struct fsm *); 69static void IpcpSendTerminateReq(struct fsm *); 70static void IpcpDecodeConfig(u_char *, int, int); 71static void IpcpLayerStart(struct fsm *); 72static void IpcpLayerFinish(struct fsm *); 73static void IpcpLayerUp(struct fsm *); 74static void IpcpLayerDown(struct fsm *); 75static void IpcpInitRestartCounter(struct fsm *); | 67 68static void IpcpSendConfigReq(struct fsm *); 69static void IpcpSendTerminateAck(struct fsm *); 70static void IpcpSendTerminateReq(struct fsm *); 71static void IpcpDecodeConfig(u_char *, int, int); 72static void IpcpLayerStart(struct fsm *); 73static void IpcpLayerFinish(struct fsm *); 74static void IpcpLayerUp(struct fsm *); 75static void IpcpLayerDown(struct fsm *); 76static void IpcpInitRestartCounter(struct fsm *); |
76static int IpcpOctetsIn(void); 77static int IpcpOctetsOut(void); | |
78 | 77 |
79static int lastInOctets, lastOutOctets; 80static int StartingIpIn, StartingIpOut; 81 | |
82#define REJECTED(p, x) (p->his_reject & (1<<x)) 83 84struct fsm IpcpFsm = { 85 "IPCP", 86 PROTO_IPCP, 87 IPCP_MAXCODE, 88 OPEN_ACTIVE, 89 ST_INITIAL, --- 31 unchanged lines hidden (view full) --- 121 "PRIDNS", /* 129: Primary DNS Server Address */ 122 "PRINBNS", /* 130: Primary NBNS Server Address */ 123 "SECDNS", /* 131: Secondary DNS Server Address */ 124 "SECNBNS", /* 132: Secondary NBNS Server Address */ 125}; 126 127#define NCFTYPES128 (sizeof(cftypes)/sizeof(char *)) 128 | 78#define REJECTED(p, x) (p->his_reject & (1<<x)) 79 80struct fsm IpcpFsm = { 81 "IPCP", 82 PROTO_IPCP, 83 IPCP_MAXCODE, 84 OPEN_ACTIVE, 85 ST_INITIAL, --- 31 unchanged lines hidden (view full) --- 117 "PRIDNS", /* 129: Primary DNS Server Address */ 118 "PRINBNS", /* 130: Primary NBNS Server Address */ 119 "SECDNS", /* 131: Secondary DNS Server Address */ 120 "SECNBNS", /* 132: Secondary NBNS Server Address */ 121}; 122 123#define NCFTYPES128 (sizeof(cftypes)/sizeof(char *)) 124 |
129/* 130 * Function called every second. Updates connection period and idle period, 131 * also update LQR information. 132 */ 133static void 134IpcpReportFunc() | 125struct pppThroughput throughput; 126 127void 128IpcpAddInOctets(int n) |
135{ | 129{ |
136 ipConnectSecs++; 137 if (lastInOctets == ipInOctets && lastOutOctets == ipOutOctets) 138 ipIdleSecs++; 139 lastInOctets = ipInOctets; 140 lastOutOctets = ipOutOctets; 141 StopTimer(&IpcpReportTimer); 142 IpcpReportTimer.state = TIMER_STOPPED; 143 StartTimer(&IpcpReportTimer); | 130 throughput_addin(&throughput, n); |
144} 145 | 131} 132 |
146static void 147IpcpStartReport() | 133void 134IpcpAddOutOctets(int n) |
148{ | 135{ |
149 ipIdleSecs = ipConnectSecs = 0; 150 StopTimer(&IpcpReportTimer); 151 IpcpReportTimer.state = TIMER_STOPPED; 152 IpcpReportTimer.load = SECTICKS; 153 IpcpReportTimer.func = IpcpReportFunc; 154 StartTimer(&IpcpReportTimer); | 136 throughput_addout(&throughput, n); |
155} 156 157int 158ReportIpcpStatus() 159{ 160 struct ipcpstate *icp = &IpcpInfo; 161 struct fsm *fp = &IpcpFsm; 162 163 if (!VarTerm) 164 return 1; 165 fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]); 166 fprintf(VarTerm, " his side: %s, %lx\n", 167 inet_ntoa(icp->his_ipaddr), icp->his_compproto); 168 fprintf(VarTerm, " my side: %s, %lx\n", 169 inet_ntoa(icp->want_ipaddr), icp->want_compproto); | 137} 138 139int 140ReportIpcpStatus() 141{ 142 struct ipcpstate *icp = &IpcpInfo; 143 struct fsm *fp = &IpcpFsm; 144 145 if (!VarTerm) 146 return 1; 147 fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]); 148 fprintf(VarTerm, " his side: %s, %lx\n", 149 inet_ntoa(icp->his_ipaddr), icp->his_compproto); 150 fprintf(VarTerm, " my side: %s, %lx\n", 151 inet_ntoa(icp->want_ipaddr), icp->want_compproto); |
170 fprintf(VarTerm, "Connected: %d secs, idle: %d secs\n\n", 171 ipConnectSecs, ipIdleSecs); 172 fprintf(VarTerm, " %d octets in, %d octets out\n", 173 IpcpOctetsIn(), IpcpOctetsOut()); | |
174 175 fprintf(VarTerm, "Defaults:\n"); 176 fprintf(VarTerm, " My Address: %s/%d\n", 177 inet_ntoa(DefMyAddress.ipaddr), DefMyAddress.width); 178 fprintf(VarTerm, " His Address: %s/%d\n", 179 inet_ntoa(DefHisAddress.ipaddr), DefHisAddress.width); 180 if (HaveTriggerAddress) 181 fprintf(VarTerm, " Negotiation(trigger): %s\n", inet_ntoa(TriggerAddress)); 182 else 183 fprintf(VarTerm, " Negotiation(trigger): MYADDR\n"); 184 | 152 153 fprintf(VarTerm, "Defaults:\n"); 154 fprintf(VarTerm, " My Address: %s/%d\n", 155 inet_ntoa(DefMyAddress.ipaddr), DefMyAddress.width); 156 fprintf(VarTerm, " His Address: %s/%d\n", 157 inet_ntoa(DefHisAddress.ipaddr), DefHisAddress.width); 158 if (HaveTriggerAddress) 159 fprintf(VarTerm, " Negotiation(trigger): %s\n", inet_ntoa(TriggerAddress)); 160 else 161 fprintf(VarTerm, " Negotiation(trigger): MYADDR\n"); 162 |
163 fprintf(VarTerm, "\n"); 164 throughput_disp(&throughput, VarTerm); 165 |
|
185 return 0; 186} 187 188void 189IpcpDefAddress() 190{ 191 struct hostent *hp; 192 char name[200]; --- 34 unchanged lines hidden (view full) --- 227 LogPrintf(LogIPCP, "Using trigger address %s\n", inet_ntoa(TriggerAddress)); 228 } 229 if (Enabled(ConfVjcomp)) 230 icp->want_compproto = (PROTO_VJCOMP << 16) | ((MAX_STATES - 1) << 8) | 1; 231 else 232 icp->want_compproto = 0; 233 icp->heis1172 = 0; 234 IpcpFsm.maxconfig = 10; | 166 return 0; 167} 168 169void 170IpcpDefAddress() 171{ 172 struct hostent *hp; 173 char name[200]; --- 34 unchanged lines hidden (view full) --- 208 LogPrintf(LogIPCP, "Using trigger address %s\n", inet_ntoa(TriggerAddress)); 209 } 210 if (Enabled(ConfVjcomp)) 211 icp->want_compproto = (PROTO_VJCOMP << 16) | ((MAX_STATES - 1) << 8) | 1; 212 else 213 icp->want_compproto = 0; 214 icp->heis1172 = 0; 215 IpcpFsm.maxconfig = 10; |
235 StartingIpIn = ipInOctets; 236 StartingIpOut = ipOutOctets; | 216 throughput_init(&throughput); |
237} 238 239static void 240IpcpInitRestartCounter(struct fsm * fp) 241{ 242 fp->FsmTimer.load = VarRetryTimeout * SECTICKS; 243 fp->restart = 5; 244} --- 42 unchanged lines hidden (view full) --- 287IpcpLayerFinish(struct fsm * fp) 288{ 289 LogPrintf(LogIPCP, "IpcpLayerFinish.\n"); 290 reconnect(RECON_FALSE); 291 LcpClose(); 292 NewPhase(PHASE_TERMINATE); 293} 294 | 217} 218 219static void 220IpcpInitRestartCounter(struct fsm * fp) 221{ 222 fp->FsmTimer.load = VarRetryTimeout * SECTICKS; 223 fp->restart = 5; 224} --- 42 unchanged lines hidden (view full) --- 267IpcpLayerFinish(struct fsm * fp) 268{ 269 LogPrintf(LogIPCP, "IpcpLayerFinish.\n"); 270 reconnect(RECON_FALSE); 271 LcpClose(); 272 NewPhase(PHASE_TERMINATE); 273} 274 |
295static int 296IpcpOctetsIn() 297{ 298 return ipInOctets < StartingIpIn ? 299 INT_MAX - StartingIpIn + ipInOctets - INT_MIN + 1 : 300 ipInOctets - StartingIpIn; 301} 302 303static int 304IpcpOctetsOut() 305{ 306 return ipOutOctets < StartingIpOut ? 307 INT_MAX - StartingIpOut + ipOutOctets - INT_MIN + 1 : 308 ipOutOctets - StartingIpOut; 309} 310 | |
311static void 312IpcpLayerDown(struct fsm * fp) 313{ 314 LogPrintf(LogIPCP, "IpcpLayerDown.\n"); | 275static void 276IpcpLayerDown(struct fsm * fp) 277{ 278 LogPrintf(LogIPCP, "IpcpLayerDown.\n"); |
315 LogPrintf(LogIPCP, "%d octets in, %d octets out\n", 316 IpcpOctetsIn(), IpcpOctetsOut()); 317 StopTimer(&IpcpReportTimer); 318 Prompt(); | 279 throughput_stop(&throughput); 280 throughput_log(&throughput, LogIPCP, NULL); |
319} 320 321/* 322 * Called when IPCP has reached to OPEN state 323 */ 324static void 325IpcpLayerUp(struct fsm * fp) 326{ --- 12 unchanged lines hidden (view full) --- 339 if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask) < 0) { 340 if (VarTerm) 341 LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n"); 342 return; 343 } 344 if (mode & MODE_ALIAS) 345 VarPacketAliasSetAddress(IpcpInfo.want_ipaddr); 346 OsLinkup(); | 281} 282 283/* 284 * Called when IPCP has reached to OPEN state 285 */ 286static void 287IpcpLayerUp(struct fsm * fp) 288{ --- 12 unchanged lines hidden (view full) --- 301 if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask) < 0) { 302 if (VarTerm) 303 LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n"); 304 return; 305 } 306 if (mode & MODE_ALIAS) 307 VarPacketAliasSetAddress(IpcpInfo.want_ipaddr); 308 OsLinkup(); |
347 StartingIpIn = ipInOctets; 348 StartingIpOut = ipOutOctets; 349 IpcpStartReport(); | 309 throughput_start(&throughput); |
350 StartIdleTimer(); 351} 352 353void 354IpcpUp() 355{ 356 FsmUp(&IpcpFsm); 357 LogPrintf(LogIPCP, "IPCP Up event!!\n"); --- 282 unchanged lines hidden --- | 310 StartIdleTimer(); 311} 312 313void 314IpcpUp() 315{ 316 FsmUp(&IpcpFsm); 317 LogPrintf(LogIPCP, "IPCP Up event!!\n"); --- 282 unchanged lines hidden --- |