Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
lwip_ppp.c
00001 /***************************************************************************** 00002 * ppp.c - Network Point to Point Protocol program file. 00003 * 00004 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. 00005 * portions Copyright (c) 1997 by Global Election Systems Inc. 00006 * 00007 * The authors hereby grant permission to use, copy, modify, distribute, 00008 * and license this software and its documentation for any purpose, provided 00009 * that existing copyright notices are retained in all copies and that this 00010 * notice and the following disclaimer are included verbatim in any 00011 * distributions. No written agreement, license, or royalty fee is required 00012 * for any of the authorized uses. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR 00015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00017 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 * 00025 ****************************************************************************** 00026 * REVISION HISTORY 00027 * 00028 * 03-01-01 Marc Boucher <marc@mbsi.ca> 00029 * Ported to lwIP. 00030 * 97-11-05 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. 00031 * Original. 00032 *****************************************************************************/ 00033 00034 /* 00035 * ppp_defs.h - PPP definitions. 00036 * 00037 * if_pppvar.h - private structures and declarations for PPP. 00038 * 00039 * Copyright (c) 1994 The Australian National University. 00040 * All rights reserved. 00041 * 00042 * Permission to use, copy, modify, and distribute this software and its 00043 * documentation is hereby granted, provided that the above copyright 00044 * notice appears in all copies. This software is provided without any 00045 * warranty, express or implied. The Australian National University 00046 * makes no representations about the suitability of this software for 00047 * any purpose. 00048 * 00049 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY 00050 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 00051 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 00052 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY 00053 * OF SUCH DAMAGE. 00054 * 00055 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00056 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00057 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00058 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO 00059 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, 00060 * OR MODIFICATIONS. 00061 */ 00062 00063 /* 00064 * if_ppp.h - Point-to-Point Protocol definitions. 00065 * 00066 * Copyright (c) 1989 Carnegie Mellon University. 00067 * All rights reserved. 00068 * 00069 * Redistribution and use in source and binary forms are permitted 00070 * provided that the above copyright notice and this paragraph are 00071 * duplicated in all such forms and that any documentation, 00072 * advertising materials, and other materials related to such 00073 * distribution and use acknowledge that the software was developed 00074 * by Carnegie Mellon University. The name of the 00075 * University may not be used to endorse or promote products derived 00076 * from this software without specific prior written permission. 00077 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 00078 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 00079 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00080 */ 00081 00082 /** 00083 * @defgroup ppp PPP netif 00084 * @ingroup addons 00085 * @verbinclude "ppp.txt" 00086 */ 00087 00088 #include "netif/ppp/ppp_opts.h" 00089 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 00090 00091 #include "lwip/pbuf.h" 00092 #include "lwip/stats.h" 00093 #include "lwip/sys.h" 00094 #include "lwip/tcpip.h" 00095 #include "lwip/api.h" 00096 #include "lwip/snmp.h" 00097 #include "lwip/ip4.h" /* for ip4_input() */ 00098 #if PPP_IPV6_SUPPORT 00099 #include "lwip/ip6.h" /* for ip6_input() */ 00100 #endif /* PPP_IPV6_SUPPORT */ 00101 #include "lwip/dns.h" 00102 00103 #include "netif/ppp/ppp_impl.h" 00104 #include "netif/ppp/pppos.h" 00105 00106 #include "netif/ppp/fsm.h" 00107 #include "netif/ppp/lcp.h" 00108 #include "netif/ppp/magic.h" 00109 00110 #if PAP_SUPPORT 00111 #include "netif/ppp/upap.h" 00112 #endif /* PAP_SUPPORT */ 00113 #if CHAP_SUPPORT 00114 #include "netif/ppp/chap-new.h" 00115 #endif /* CHAP_SUPPORT */ 00116 #if EAP_SUPPORT 00117 #include "netif/ppp/eap.h" 00118 #endif /* EAP_SUPPORT */ 00119 #if CCP_SUPPORT 00120 #include "netif/ppp/ccp.h" 00121 #endif /* CCP_SUPPORT */ 00122 #if MPPE_SUPPORT 00123 #include "netif/ppp/mppe.h" 00124 #endif /* MPPE_SUPPORT */ 00125 #if ECP_SUPPORT 00126 #include "netif/ppp/ecp.h" 00127 #endif /* EAP_SUPPORT */ 00128 #if VJ_SUPPORT 00129 #include "netif/ppp/vj.h" 00130 #endif /* VJ_SUPPORT */ 00131 #if PPP_IPV4_SUPPORT 00132 #include "netif/ppp/ipcp.h" 00133 #endif /* PPP_IPV4_SUPPORT */ 00134 #if PPP_IPV6_SUPPORT 00135 #include "netif/ppp/ipv6cp.h" 00136 #endif /* PPP_IPV6_SUPPORT */ 00137 00138 /*************************/ 00139 /*** LOCAL DEFINITIONS ***/ 00140 /*************************/ 00141 00142 /* Memory pools */ 00143 #if PPPOS_SUPPORT 00144 LWIP_MEMPOOL_PROTOTYPE(PPPOS_PCB); 00145 #endif 00146 #if PPPOE_SUPPORT 00147 LWIP_MEMPOOL_PROTOTYPE(PPPOE_IF); 00148 #endif 00149 #if PPPOL2TP_SUPPORT 00150 LWIP_MEMPOOL_PROTOTYPE(PPPOL2TP_PCB); 00151 #endif 00152 #if LWIP_PPP_API && LWIP_MPU_COMPATIBLE 00153 LWIP_MEMPOOL_PROTOTYPE(PPPAPI_MSG); 00154 #endif 00155 LWIP_MEMPOOL_DECLARE(PPP_PCB, MEMP_NUM_PPP_PCB, sizeof(ppp_pcb), "PPP_PCB") 00156 00157 /* FIXME: add stats per PPP session */ 00158 #if PPP_STATS_SUPPORT 00159 static struct timeval start_time; /* Time when link was started. */ 00160 static struct pppd_stats old_link_stats; 00161 struct pppd_stats link_stats; 00162 unsigned link_connect_time; 00163 int link_stats_valid; 00164 #endif /* PPP_STATS_SUPPORT */ 00165 00166 /* 00167 * PPP Data Link Layer "protocol" table. 00168 * One entry per supported protocol. 00169 * The last entry must be NULL. 00170 */ 00171 const struct protent* const protocols[] = { 00172 &lcp_protent, 00173 #if PAP_SUPPORT 00174 &pap_protent, 00175 #endif /* PAP_SUPPORT */ 00176 #if CHAP_SUPPORT 00177 &chap_protent, 00178 #endif /* CHAP_SUPPORT */ 00179 #if CBCP_SUPPORT 00180 &cbcp_protent, 00181 #endif /* CBCP_SUPPORT */ 00182 #if PPP_IPV4_SUPPORT 00183 &ipcp_protent, 00184 #endif /* PPP_IPV4_SUPPORT */ 00185 #if PPP_IPV6_SUPPORT 00186 &ipv6cp_protent, 00187 #endif /* PPP_IPV6_SUPPORT */ 00188 #if CCP_SUPPORT 00189 &ccp_protent, 00190 #endif /* CCP_SUPPORT */ 00191 #if ECP_SUPPORT 00192 &ecp_protent, 00193 #endif /* ECP_SUPPORT */ 00194 #ifdef AT_CHANGE 00195 &atcp_protent, 00196 #endif /* AT_CHANGE */ 00197 #if EAP_SUPPORT 00198 &eap_protent, 00199 #endif /* EAP_SUPPORT */ 00200 NULL 00201 }; 00202 00203 /* Prototypes for procedures local to this file. */ 00204 static void ppp_do_connect(void *arg); 00205 static err_t ppp_netif_init_cb(struct netif *netif); 00206 #if LWIP_IPV4 00207 static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr); 00208 #endif /* LWIP_IPV4 */ 00209 #if PPP_IPV6_SUPPORT 00210 static err_t ppp_netif_output_ip6(struct netif *netif, struct pbuf *pb, const ip6_addr_t *ipaddr); 00211 #endif /* PPP_IPV6_SUPPORT */ 00212 static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protocol); 00213 00214 /***********************************/ 00215 /*** PUBLIC FUNCTION DEFINITIONS ***/ 00216 /***********************************/ 00217 #if PPP_AUTH_SUPPORT 00218 void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd) { 00219 #if PAP_SUPPORT 00220 pcb->settings.refuse_pap = !(authtype & PPPAUTHTYPE_PAP); 00221 #endif /* PAP_SUPPORT */ 00222 #if CHAP_SUPPORT 00223 pcb->settings.refuse_chap = !(authtype & PPPAUTHTYPE_CHAP); 00224 #if MSCHAP_SUPPORT 00225 pcb->settings.refuse_mschap = !(authtype & PPPAUTHTYPE_MSCHAP); 00226 pcb->settings.refuse_mschap_v2 = !(authtype & PPPAUTHTYPE_MSCHAP_V2); 00227 #endif /* MSCHAP_SUPPORT */ 00228 #endif /* CHAP_SUPPORT */ 00229 #if EAP_SUPPORT 00230 pcb->settings.refuse_eap = !(authtype & PPPAUTHTYPE_EAP); 00231 #endif /* EAP_SUPPORT */ 00232 pcb->settings.user = user; 00233 pcb->settings.passwd = passwd; 00234 } 00235 #endif /* PPP_AUTH_SUPPORT */ 00236 00237 #if MPPE_SUPPORT 00238 /* Set MPPE configuration */ 00239 void ppp_set_mppe(ppp_pcb *pcb, u8_t flags) { 00240 if (flags == PPP_MPPE_DISABLE) { 00241 pcb->settings.require_mppe = 0; 00242 return; 00243 } 00244 00245 pcb->settings.require_mppe = 1; 00246 pcb->settings.refuse_mppe_stateful = !(flags & PPP_MPPE_ALLOW_STATEFUL); 00247 pcb->settings.refuse_mppe_40 = !!(flags & PPP_MPPE_REFUSE_40); 00248 pcb->settings.refuse_mppe_128 = !!(flags & PPP_MPPE_REFUSE_128); 00249 } 00250 #endif /* MPPE_SUPPORT */ 00251 00252 #if PPP_NOTIFY_PHASE 00253 void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb) { 00254 pcb->notify_phase_cb = notify_phase_cb; 00255 notify_phase_cb(pcb, pcb->phase, pcb->ctx_cb); 00256 } 00257 #endif /* PPP_NOTIFY_PHASE */ 00258 00259 /* 00260 * Initiate a PPP connection. 00261 * 00262 * This can only be called if PPP is in the dead phase. 00263 * 00264 * Holdoff is the time to wait (in seconds) before initiating 00265 * the connection. 00266 * 00267 * If this port connects to a modem, the modem connection must be 00268 * established before calling this. 00269 */ 00270 err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff) { 00271 if (pcb->phase != PPP_PHASE_DEAD) { 00272 return ERR_ALREADY; 00273 } 00274 00275 PPPDEBUG(LOG_DEBUG, ("ppp_connect[%d]: holdoff=%d\n", pcb->netif->num, holdoff)); 00276 00277 if (holdoff == 0) { 00278 new_phase(pcb, PPP_PHASE_INITIALIZE); 00279 return pcb->link_cb->connect(pcb, pcb->link_ctx_cb); 00280 } 00281 00282 new_phase(pcb, PPP_PHASE_HOLDOFF); 00283 sys_timeout((u32_t)(holdoff*1000), ppp_do_connect, pcb); 00284 return ERR_OK; 00285 } 00286 00287 #if PPP_SERVER 00288 /* 00289 * Listen for an incoming PPP connection. 00290 * 00291 * This can only be called if PPP is in the dead phase. 00292 * 00293 * If this port connects to a modem, the modem connection must be 00294 * established before calling this. 00295 */ 00296 err_t ppp_listen(ppp_pcb *pcb) { 00297 if (pcb->phase != PPP_PHASE_DEAD) { 00298 return ERR_ALREADY; 00299 } 00300 00301 PPPDEBUG(LOG_DEBUG, ("ppp_listen[%d]\n", pcb->netif->num)); 00302 00303 if (pcb->link_cb->listen) { 00304 new_phase(pcb, PPP_PHASE_INITIALIZE); 00305 return pcb->link_cb->listen(pcb, pcb->link_ctx_cb); 00306 } 00307 return ERR_IF; 00308 } 00309 #endif /* PPP_SERVER */ 00310 00311 /* 00312 * Initiate the end of a PPP connection. 00313 * Any outstanding packets in the queues are dropped. 00314 * 00315 * Setting nocarrier to 1 close the PPP connection without initiating the 00316 * shutdown procedure. Always using nocarrier = 0 is still recommended, 00317 * this is going to take a little longer time if your link is down, but 00318 * is a safer choice for the PPP state machine. 00319 * 00320 * Return 0 on success, an error code on failure. 00321 */ 00322 err_t 00323 ppp_close(ppp_pcb *pcb, u8_t nocarrier) 00324 { 00325 pcb->err_code = PPPERR_USER; 00326 00327 /* holdoff phase, cancel the reconnection */ 00328 if (pcb->phase == PPP_PHASE_HOLDOFF) { 00329 sys_untimeout(ppp_do_connect, pcb); 00330 new_phase(pcb, PPP_PHASE_DEAD); 00331 } 00332 00333 /* dead phase, nothing to do, call the status callback to be consistent */ 00334 if (pcb->phase == PPP_PHASE_DEAD) { 00335 pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb); 00336 return ERR_OK; 00337 } 00338 00339 /* Already terminating, nothing to do */ 00340 if (pcb->phase >= PPP_PHASE_TERMINATE) { 00341 return ERR_INPROGRESS; 00342 } 00343 00344 /* LCP not open, close link protocol */ 00345 if (pcb->phase < PPP_PHASE_ESTABLISH) { 00346 new_phase(pcb, PPP_PHASE_DISCONNECT); 00347 ppp_link_terminated(pcb); 00348 return ERR_OK; 00349 } 00350 00351 /* 00352 * Only accept carrier lost signal on the stable running phase in order 00353 * to prevent changing the PPP phase FSM in transition phases. 00354 * 00355 * Always using nocarrier = 0 is still recommended, this is going to 00356 * take a little longer time, but is a safer choice from FSM point of view. 00357 */ 00358 if (nocarrier && pcb->phase == PPP_PHASE_RUNNING) { 00359 PPPDEBUG(LOG_DEBUG, ("ppp_close[%d]: carrier lost -> lcp_lowerdown\n", pcb->netif->num)); 00360 lcp_lowerdown(pcb); 00361 /* forced link termination, this will force link protocol to disconnect. */ 00362 link_terminated(pcb); 00363 return ERR_OK; 00364 } 00365 00366 /* Disconnect */ 00367 PPPDEBUG(LOG_DEBUG, ("ppp_close[%d]: kill_link -> lcp_close\n", pcb->netif->num)); 00368 /* LCP soft close request. */ 00369 lcp_close(pcb, "User request"); 00370 return ERR_OK; 00371 } 00372 00373 /* 00374 * Release the control block. 00375 * 00376 * This can only be called if PPP is in the dead phase. 00377 * 00378 * You must use ppp_close() before if you wish to terminate 00379 * an established PPP session. 00380 * 00381 * Return 0 on success, an error code on failure. 00382 */ 00383 err_t ppp_free(ppp_pcb *pcb) { 00384 err_t err; 00385 if (pcb->phase != PPP_PHASE_DEAD) { 00386 return ERR_CONN; 00387 } 00388 00389 PPPDEBUG(LOG_DEBUG, ("ppp_free[%d]\n", pcb->netif->num)); 00390 00391 netif_remove(pcb->netif); 00392 00393 err = pcb->link_cb->free(pcb, pcb->link_ctx_cb); 00394 00395 LWIP_MEMPOOL_FREE(PPP_PCB, pcb); 00396 return err; 00397 } 00398 00399 /* Get and set parameters for the given connection. 00400 * Return 0 on success, an error code on failure. */ 00401 err_t 00402 ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg) 00403 { 00404 if (pcb == NULL) { 00405 return ERR_VAL; 00406 } 00407 00408 switch(cmd) { 00409 case PPPCTLG_UPSTATUS: /* Get the PPP up status. */ 00410 if (!arg) { 00411 goto fail; 00412 } 00413 *(int *)arg = (int)(0 00414 #if PPP_IPV4_SUPPORT 00415 || pcb->if4_up 00416 #endif /* PPP_IPV4_SUPPORT */ 00417 #if PPP_IPV6_SUPPORT 00418 || pcb->if6_up 00419 #endif /* PPP_IPV6_SUPPORT */ 00420 ); 00421 return ERR_OK; 00422 00423 case PPPCTLG_ERRCODE: /* Get the PPP error code. */ 00424 if (!arg) { 00425 goto fail; 00426 } 00427 *(int *)arg = (int)(pcb->err_code); 00428 return ERR_OK; 00429 00430 default: 00431 goto fail; 00432 } 00433 00434 fail: 00435 return ERR_VAL; 00436 } 00437 00438 00439 /**********************************/ 00440 /*** LOCAL FUNCTION DEFINITIONS ***/ 00441 /**********************************/ 00442 00443 static void ppp_do_connect(void *arg) { 00444 ppp_pcb *pcb = (ppp_pcb*)arg; 00445 00446 LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF); 00447 00448 new_phase(pcb, PPP_PHASE_INITIALIZE); 00449 pcb->link_cb->connect(pcb, pcb->link_ctx_cb); 00450 } 00451 00452 /* 00453 * ppp_netif_init_cb - netif init callback 00454 */ 00455 static err_t ppp_netif_init_cb(struct netif *netif) { 00456 netif->name[0] = 'p'; 00457 netif->name[1] = 'p'; 00458 #if LWIP_IPV4 00459 /* FIXME: change that when netif_null_output_ip4() will materialize */ 00460 netif->output = ppp_netif_output_ip4; 00461 #endif /* LWIP_IPV4 */ 00462 #if PPP_IPV6_SUPPORT 00463 netif->output_ip6 = ppp_netif_output_ip6; 00464 #endif /* PPP_IPV6_SUPPORT */ 00465 netif->flags = NETIF_FLAG_UP; 00466 #if LWIP_NETIF_HOSTNAME 00467 /* @todo: Initialize interface hostname */ 00468 /* netif_set_hostname(netif, "lwip"); */ 00469 #endif /* LWIP_NETIF_HOSTNAME */ 00470 return ERR_OK; 00471 } 00472 00473 #if LWIP_IPV4 00474 /* 00475 * Send an IPv4 packet on the given connection. 00476 */ 00477 static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr) { 00478 LWIP_UNUSED_ARG(ipaddr); 00479 #if PPP_IPV4_SUPPORT 00480 return ppp_netif_output(netif, pb, PPP_IP); 00481 #else /* PPP_IPV4_SUPPORT */ 00482 LWIP_UNUSED_ARG(netif); 00483 LWIP_UNUSED_ARG(pb); 00484 return ERR_IF; 00485 #endif /* PPP_IPV4_SUPPORT */ 00486 } 00487 #endif /* LWIP_IPV4 */ 00488 00489 #if PPP_IPV6_SUPPORT 00490 /* 00491 * Send an IPv6 packet on the given connection. 00492 */ 00493 static err_t ppp_netif_output_ip6(struct netif *netif, struct pbuf *pb, const ip6_addr_t *ipaddr) { 00494 LWIP_UNUSED_ARG(ipaddr); 00495 return ppp_netif_output(netif, pb, PPP_IPV6); 00496 } 00497 #endif /* PPP_IPV6_SUPPORT */ 00498 00499 static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protocol) { 00500 ppp_pcb *pcb = (ppp_pcb*)netif->state; 00501 err_t err; 00502 struct pbuf *fpb = NULL; 00503 00504 /* Check that the link is up. */ 00505 if (0 00506 #if PPP_IPV4_SUPPORT 00507 || (protocol == PPP_IP && !pcb->if4_up) 00508 #endif /* PPP_IPV4_SUPPORT */ 00509 #if PPP_IPV6_SUPPORT 00510 || (protocol == PPP_IPV6 && !pcb->if6_up) 00511 #endif /* PPP_IPV6_SUPPORT */ 00512 ) { 00513 PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: link not up\n", pcb->netif->num)); 00514 goto err_rte_drop; 00515 } 00516 00517 #if MPPE_SUPPORT 00518 /* If MPPE is required, refuse any IP packet until we are able to crypt them. */ 00519 if (pcb->settings.require_mppe && pcb->ccp_transmit_method != CI_MPPE) { 00520 PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: MPPE required, not up\n", pcb->netif->num)); 00521 goto err_rte_drop; 00522 } 00523 #endif /* MPPE_SUPPORT */ 00524 00525 #if VJ_SUPPORT 00526 /* 00527 * Attempt Van Jacobson header compression if VJ is configured and 00528 * this is an IP packet. 00529 */ 00530 if (protocol == PPP_IP && pcb->vj_enabled) { 00531 switch (vj_compress_tcp(&pcb->vj_comp, &pb)) { 00532 case TYPE_IP: 00533 /* No change... 00534 protocol = PPP_IP; */ 00535 break; 00536 case TYPE_COMPRESSED_TCP: 00537 /* vj_compress_tcp() returns a new allocated pbuf, indicate we should free 00538 * our duplicated pbuf later */ 00539 fpb = pb; 00540 protocol = PPP_VJC_COMP; 00541 break; 00542 case TYPE_UNCOMPRESSED_TCP: 00543 /* vj_compress_tcp() returns a new allocated pbuf, indicate we should free 00544 * our duplicated pbuf later */ 00545 fpb = pb; 00546 protocol = PPP_VJC_UNCOMP; 00547 break; 00548 default: 00549 PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad IP packet\n", pcb->netif->num)); 00550 LINK_STATS_INC(link.proterr); 00551 LINK_STATS_INC(link.drop); 00552 MIB2_STATS_NETIF_INC(pcb->netif, ifoutdiscards); 00553 return ERR_VAL; 00554 } 00555 } 00556 #endif /* VJ_SUPPORT */ 00557 00558 #if CCP_SUPPORT 00559 switch (pcb->ccp_transmit_method) { 00560 case 0: 00561 break; /* Don't compress */ 00562 #if MPPE_SUPPORT 00563 case CI_MPPE: 00564 if ((err = mppe_compress(pcb, &pcb->mppe_comp, &pb, protocol)) != ERR_OK) { 00565 LINK_STATS_INC(link.memerr); 00566 LINK_STATS_INC(link.drop); 00567 MIB2_STATS_NETIF_INC(netif, ifoutdiscards); 00568 goto err; 00569 } 00570 /* if VJ compressor returned a new allocated pbuf, free it */ 00571 if (fpb) { 00572 pbuf_free(fpb); 00573 } 00574 /* mppe_compress() returns a new allocated pbuf, indicate we should free 00575 * our duplicated pbuf later */ 00576 fpb = pb; 00577 protocol = PPP_COMP; 00578 break; 00579 #endif /* MPPE_SUPPORT */ 00580 default: 00581 PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: bad CCP transmit method\n", pcb->netif->num)); 00582 goto err_rte_drop; /* Cannot really happen, we only negotiate what we are able to do */ 00583 } 00584 #endif /* CCP_SUPPORT */ 00585 00586 err = pcb->link_cb->netif_output(pcb, pcb->link_ctx_cb, pb, protocol); 00587 goto err; 00588 00589 err_rte_drop: 00590 err = ERR_RTE; 00591 LINK_STATS_INC(link.rterr); 00592 LINK_STATS_INC(link.drop); 00593 MIB2_STATS_NETIF_INC(netif, ifoutdiscards); 00594 err: 00595 if (fpb) { 00596 pbuf_free(fpb); 00597 } 00598 return err; 00599 } 00600 00601 /************************************/ 00602 /*** PRIVATE FUNCTION DEFINITIONS ***/ 00603 /************************************/ 00604 00605 /* Initialize the PPP subsystem. */ 00606 int ppp_init(void) 00607 { 00608 #if PPPOS_SUPPORT 00609 LWIP_MEMPOOL_INIT(PPPOS_PCB); 00610 #endif 00611 #if PPPOE_SUPPORT 00612 LWIP_MEMPOOL_INIT(PPPOE_IF); 00613 #endif 00614 #if PPPOL2TP_SUPPORT 00615 LWIP_MEMPOOL_INIT(PPPOL2TP_PCB); 00616 #endif 00617 #if LWIP_PPP_API && LWIP_MPU_COMPATIBLE 00618 LWIP_MEMPOOL_INIT(PPPAPI_MSG); 00619 #endif 00620 00621 LWIP_MEMPOOL_INIT(PPP_PCB); 00622 00623 /* 00624 * Initialize magic number generator now so that protocols may 00625 * use magic numbers in initialization. 00626 */ 00627 magic_init(); 00628 00629 return 0; 00630 } 00631 00632 /* 00633 * Create a new PPP control block. 00634 * 00635 * This initializes the PPP control block but does not 00636 * attempt to negotiate the LCP session. 00637 * 00638 * Return a new PPP connection control block pointer 00639 * on success or a null pointer on failure. 00640 */ 00641 ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) { 00642 ppp_pcb *pcb; 00643 const struct protent *protp; 00644 int i; 00645 00646 /* PPP is single-threaded: without a callback, 00647 * there is no way to know when the link is up. */ 00648 if (link_status_cb == NULL) { 00649 return NULL; 00650 } 00651 00652 pcb = (ppp_pcb*)LWIP_MEMPOOL_ALLOC(PPP_PCB); 00653 if (pcb == NULL) { 00654 return NULL; 00655 } 00656 00657 memset(pcb, 0, sizeof(ppp_pcb)); 00658 00659 /* default configuration */ 00660 #if PAP_SUPPORT 00661 pcb->settings.pap_timeout_time = UPAP_DEFTIMEOUT; 00662 pcb->settings.pap_max_transmits = UPAP_DEFTRANSMITS; 00663 #if PPP_SERVER 00664 pcb->settings.pap_req_timeout = UPAP_DEFREQTIME; 00665 #endif /* PPP_SERVER */ 00666 #endif /* PAP_SUPPORT */ 00667 00668 #if CHAP_SUPPORT 00669 pcb->settings.chap_timeout_time = CHAP_DEFTIMEOUT; 00670 pcb->settings.chap_max_transmits = CHAP_DEFTRANSMITS; 00671 #if PPP_SERVER 00672 pcb->settings.chap_rechallenge_time = CHAP_DEFRECHALLENGETIME; 00673 #endif /* PPP_SERVER */ 00674 #endif /* CHAP_SUPPPORT */ 00675 00676 #if EAP_SUPPORT 00677 pcb->settings.eap_req_time = EAP_DEFREQTIME; 00678 pcb->settings.eap_allow_req = EAP_DEFALLOWREQ; 00679 #if PPP_SERVER 00680 pcb->settings.eap_timeout_time = EAP_DEFTIMEOUT; 00681 pcb->settings.eap_max_transmits = EAP_DEFTRANSMITS; 00682 #endif /* PPP_SERVER */ 00683 #endif /* EAP_SUPPORT */ 00684 00685 pcb->settings.lcp_loopbackfail = LCP_DEFLOOPBACKFAIL; 00686 pcb->settings.lcp_echo_interval = LCP_ECHOINTERVAL; 00687 pcb->settings.lcp_echo_fails = LCP_MAXECHOFAILS; 00688 00689 pcb->settings.fsm_timeout_time = FSM_DEFTIMEOUT; 00690 pcb->settings.fsm_max_conf_req_transmits = FSM_DEFMAXCONFREQS; 00691 pcb->settings.fsm_max_term_transmits = FSM_DEFMAXTERMREQS; 00692 pcb->settings.fsm_max_nak_loops = FSM_DEFMAXNAKLOOPS; 00693 00694 pcb->netif = pppif; 00695 MIB2_INIT_NETIF(pppif, snmp_ifType_ppp, 0); 00696 if (!netif_add(pcb->netif, 00697 #if LWIP_IPV4 00698 IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4, 00699 #endif /* LWIP_IPV4 */ 00700 (void *)pcb, ppp_netif_init_cb, NULL)) { 00701 LWIP_MEMPOOL_FREE(PPP_PCB, pcb); 00702 PPPDEBUG(LOG_ERR, ("ppp_new: netif_add failed\n")); 00703 return NULL; 00704 } 00705 00706 pcb->link_cb = callbacks; 00707 pcb->link_ctx_cb = link_ctx_cb; 00708 pcb->link_status_cb = link_status_cb; 00709 pcb->ctx_cb = ctx_cb; 00710 00711 /* 00712 * Initialize each protocol. 00713 */ 00714 for (i = 0; (protp = protocols[i]) != NULL; ++i) { 00715 (*protp->init)(pcb); 00716 } 00717 00718 new_phase(pcb, PPP_PHASE_DEAD); 00719 return pcb; 00720 } 00721 00722 /** Initiate LCP open request */ 00723 void ppp_start(ppp_pcb *pcb) { 00724 PPPDEBUG(LOG_DEBUG, ("ppp_start[%d]\n", pcb->netif->num)); 00725 00726 /* Clean data not taken care by anything else, mostly shared data. */ 00727 #if PPP_STATS_SUPPORT 00728 link_stats_valid = 0; 00729 #endif /* PPP_STATS_SUPPORT */ 00730 #if MPPE_SUPPORT 00731 pcb->mppe_keys_set = 0; 00732 memset(&pcb->mppe_comp, 0, sizeof(pcb->mppe_comp)); 00733 memset(&pcb->mppe_decomp, 0, sizeof(pcb->mppe_decomp)); 00734 #endif /* MPPE_SUPPORT */ 00735 #if VJ_SUPPORT 00736 vj_compress_init(&pcb->vj_comp); 00737 #endif /* VJ_SUPPORT */ 00738 00739 /* Start protocol */ 00740 new_phase(pcb, PPP_PHASE_ESTABLISH); 00741 lcp_open(pcb); 00742 lcp_lowerup(pcb); 00743 PPPDEBUG(LOG_DEBUG, ("ppp_start[%d]: finished\n", pcb->netif->num)); 00744 } 00745 00746 /** Called when link failed to setup */ 00747 void ppp_link_failed(ppp_pcb *pcb) { 00748 PPPDEBUG(LOG_DEBUG, ("ppp_link_failed[%d]\n", pcb->netif->num)); 00749 new_phase(pcb, PPP_PHASE_DEAD); 00750 pcb->err_code = PPPERR_OPEN; 00751 pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb); 00752 } 00753 00754 /** Called when link is normally down (i.e. it was asked to end) */ 00755 void ppp_link_end(ppp_pcb *pcb) { 00756 PPPDEBUG(LOG_DEBUG, ("ppp_link_end[%d]\n", pcb->netif->num)); 00757 new_phase(pcb, PPP_PHASE_DEAD); 00758 if (pcb->err_code == PPPERR_NONE) { 00759 pcb->err_code = PPPERR_CONNECT; 00760 } 00761 pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb); 00762 } 00763 00764 /* 00765 * Pass the processed input packet to the appropriate handler. 00766 * This function and all handlers run in the context of the tcpip_thread 00767 */ 00768 void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { 00769 u16_t protocol; 00770 #if PPP_DEBUG && PPP_PROTOCOLNAME 00771 const char *pname; 00772 #endif /* PPP_DEBUG && PPP_PROTOCOLNAME */ 00773 00774 magic_randomize(); 00775 00776 if (pb->len < 2) { 00777 PPPDEBUG(LOG_ERR, ("ppp_input[%d]: packet too short\n", pcb->netif->num)); 00778 goto drop; 00779 } 00780 protocol = (((u8_t *)pb->payload)[0] << 8) | ((u8_t*)pb->payload)[1]; 00781 00782 #if PRINTPKT_SUPPORT 00783 ppp_dump_packet(pcb, "rcvd", (unsigned char *)pb->payload, pb->len); 00784 #endif /* PRINTPKT_SUPPORT */ 00785 00786 pbuf_header(pb, -(s16_t)sizeof(protocol)); 00787 00788 LINK_STATS_INC(link.recv); 00789 MIB2_STATS_NETIF_INC(pcb->netif, ifinucastpkts); 00790 MIB2_STATS_NETIF_ADD(pcb->netif, ifinoctets, pb->tot_len); 00791 00792 /* 00793 * Toss all non-LCP packets unless LCP is OPEN. 00794 */ 00795 if (protocol != PPP_LCP && pcb->lcp_fsm.state != PPP_FSM_OPENED) { 00796 ppp_dbglog("Discarded non-LCP packet when LCP not open"); 00797 goto drop; 00798 } 00799 00800 /* 00801 * Until we get past the authentication phase, toss all packets 00802 * except LCP, LQR and authentication packets. 00803 */ 00804 if (pcb->phase <= PPP_PHASE_AUTHENTICATE 00805 && !(protocol == PPP_LCP 00806 #if LQR_SUPPORT 00807 || protocol == PPP_LQR 00808 #endif /* LQR_SUPPORT */ 00809 #if PAP_SUPPORT 00810 || protocol == PPP_PAP 00811 #endif /* PAP_SUPPORT */ 00812 #if CHAP_SUPPORT 00813 || protocol == PPP_CHAP 00814 #endif /* CHAP_SUPPORT */ 00815 #if EAP_SUPPORT 00816 || protocol == PPP_EAP 00817 #endif /* EAP_SUPPORT */ 00818 )) { 00819 ppp_dbglog("discarding proto 0x%x in phase %d", protocol, pcb->phase); 00820 goto drop; 00821 } 00822 00823 #if CCP_SUPPORT 00824 #if MPPE_SUPPORT 00825 /* 00826 * MPPE is required and unencrypted data has arrived (this 00827 * should never happen!). We should probably drop the link if 00828 * the protocol is in the range of what should be encrypted. 00829 * At the least, we drop this packet. 00830 */ 00831 if (pcb->settings.require_mppe && protocol != PPP_COMP && protocol < 0x8000) { 00832 PPPDEBUG(LOG_ERR, ("ppp_input[%d]: MPPE required, received unencrypted data!\n", pcb->netif->num)); 00833 goto drop; 00834 } 00835 #endif /* MPPE_SUPPORT */ 00836 00837 if (protocol == PPP_COMP) { 00838 u8_t *pl; 00839 00840 switch (pcb->ccp_receive_method) { 00841 #if MPPE_SUPPORT 00842 case CI_MPPE: 00843 if (mppe_decompress(pcb, &pcb->mppe_decomp, &pb) != ERR_OK) { 00844 goto drop; 00845 } 00846 break; 00847 #endif /* MPPE_SUPPORT */ 00848 default: 00849 PPPDEBUG(LOG_ERR, ("ppp_input[%d]: bad CCP receive method\n", pcb->netif->num)); 00850 goto drop; /* Cannot really happen, we only negotiate what we are able to do */ 00851 } 00852 00853 /* Assume no PFC */ 00854 if (pb->len < 2) { 00855 goto drop; 00856 } 00857 00858 /* Extract and hide protocol (do PFC decompression if necessary) */ 00859 pl = (u8_t*)pb->payload; 00860 if (pl[0] & 0x01) { 00861 protocol = pl[0]; 00862 pbuf_header(pb, -(s16_t)1); 00863 } else { 00864 protocol = (pl[0] << 8) | pl[1]; 00865 pbuf_header(pb, -(s16_t)2); 00866 } 00867 } 00868 #endif /* CCP_SUPPORT */ 00869 00870 switch(protocol) { 00871 00872 #if PPP_IPV4_SUPPORT 00873 case PPP_IP: /* Internet Protocol */ 00874 PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip in pbuf len=%d\n", pcb->netif->num, pb->tot_len)); 00875 ip4_input(pb, pcb->netif); 00876 return; 00877 #endif /* PPP_IPV4_SUPPORT */ 00878 00879 #if PPP_IPV6_SUPPORT 00880 case PPP_IPV6: /* Internet Protocol Version 6 */ 00881 PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip6 in pbuf len=%d\n", pcb->netif->num, pb->tot_len)); 00882 ip6_input(pb, pcb->netif); 00883 return; 00884 #endif /* PPP_IPV6_SUPPORT */ 00885 00886 #if VJ_SUPPORT 00887 case PPP_VJC_COMP: /* VJ compressed TCP */ 00888 /* 00889 * Clip off the VJ header and prepend the rebuilt TCP/IP header and 00890 * pass the result to IP. 00891 */ 00892 PPPDEBUG(LOG_INFO, ("ppp_input[%d]: vj_comp in pbuf len=%d\n", pcb->netif->num, pb->tot_len)); 00893 if (pcb->vj_enabled && vj_uncompress_tcp(&pb, &pcb->vj_comp) >= 0) { 00894 ip4_input(pb, pcb->netif); 00895 return; 00896 } 00897 /* Something's wrong so drop it. */ 00898 PPPDEBUG(LOG_WARNING, ("ppp_input[%d]: Dropping VJ compressed\n", pcb->netif->num)); 00899 break; 00900 00901 case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */ 00902 /* 00903 * Process the TCP/IP header for VJ header compression and then pass 00904 * the packet to IP. 00905 */ 00906 PPPDEBUG(LOG_INFO, ("ppp_input[%d]: vj_un in pbuf len=%d\n", pcb->netif->num, pb->tot_len)); 00907 if (pcb->vj_enabled && vj_uncompress_uncomp(pb, &pcb->vj_comp) >= 0) { 00908 ip4_input(pb, pcb->netif); 00909 return; 00910 } 00911 /* Something's wrong so drop it. */ 00912 PPPDEBUG(LOG_WARNING, ("ppp_input[%d]: Dropping VJ uncompressed\n", pcb->netif->num)); 00913 break; 00914 #endif /* VJ_SUPPORT */ 00915 00916 default: { 00917 int i; 00918 const struct protent *protp; 00919 00920 /* 00921 * Upcall the proper protocol input routine. 00922 */ 00923 for (i = 0; (protp = protocols[i]) != NULL; ++i) { 00924 if (protp->protocol == protocol) { 00925 pb = ppp_singlebuf(pb); 00926 (*protp->input)(pcb, (u8_t*)pb->payload, pb->len); 00927 goto out; 00928 } 00929 #if 0 /* UNUSED 00930 * 00931 * This is actually a (hacked?) way for the Linux kernel to pass a data 00932 * packet to pppd. pppd in normal condition only do signaling 00933 * (LCP, PAP, CHAP, IPCP, ...) and does not handle any data packet at all. 00934 * 00935 * We don't even need this interface, which is only there because of PPP 00936 * interface limitation between Linux kernel and pppd. For MPPE, which uses 00937 * CCP to negotiate although it is not really a (de)compressor, we added 00938 * ccp_resetrequest() in CCP and MPPE input data flow is calling either 00939 * ccp_resetrequest() or lcp_close() if the issue is, respectively, non-fatal 00940 * or fatal, this is what ccp_datainput() really do. 00941 */ 00942 if (protocol == (protp->protocol & ~0x8000) 00943 && protp->datainput != NULL) { 00944 (*protp->datainput)(pcb, pb->payload, pb->len); 00945 goto out; 00946 } 00947 #endif /* UNUSED */ 00948 } 00949 00950 #if PPP_DEBUG 00951 #if PPP_PROTOCOLNAME 00952 pname = protocol_name(protocol); 00953 if (pname != NULL) { 00954 ppp_warn("Unsupported protocol '%s' (0x%x) received", pname, protocol); 00955 } else 00956 #endif /* PPP_PROTOCOLNAME */ 00957 ppp_warn("Unsupported protocol 0x%x received", protocol); 00958 #endif /* PPP_DEBUG */ 00959 pbuf_header(pb, (s16_t)sizeof(protocol)); 00960 lcp_sprotrej(pcb, (u8_t*)pb->payload, pb->len); 00961 } 00962 break; 00963 } 00964 00965 drop: 00966 LINK_STATS_INC(link.drop); 00967 MIB2_STATS_NETIF_INC(pcb->netif, ifindiscards); 00968 00969 out: 00970 pbuf_free(pb); 00971 } 00972 00973 /* merge a pbuf chain into one pbuf */ 00974 struct pbuf *ppp_singlebuf(struct pbuf *p) { 00975 struct pbuf *q, *b; 00976 u8_t *pl; 00977 00978 if(p->tot_len == p->len) { 00979 return p; 00980 } 00981 00982 q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); 00983 if(!q) { 00984 PPPDEBUG(LOG_ERR, 00985 ("ppp_singlebuf: unable to alloc new buf (%d)\n", p->tot_len)); 00986 return p; /* live dangerously */ 00987 } 00988 00989 for(b = p, pl = (u8_t*)q->payload; b != NULL; b = b->next) { 00990 MEMCPY(pl, b->payload, b->len); 00991 pl += b->len; 00992 } 00993 00994 pbuf_free(p); 00995 00996 return q; 00997 } 00998 00999 /* 01000 * Write a pbuf to a ppp link, only used from PPP functions 01001 * to send PPP packets. 01002 * 01003 * IPv4 and IPv6 packets from lwIP are sent, respectively, 01004 * with ppp_netif_output_ip4() and ppp_netif_output_ip6() 01005 * functions (which are callbacks of the netif PPP interface). 01006 */ 01007 err_t ppp_write(ppp_pcb *pcb, struct pbuf *p) { 01008 #if PRINTPKT_SUPPORT 01009 ppp_dump_packet(pcb, "sent", (unsigned char *)p->payload+2, p->len-2); 01010 #endif /* PRINTPKT_SUPPORT */ 01011 return pcb->link_cb->write(pcb, pcb->link_ctx_cb, p); 01012 } 01013 01014 void ppp_link_terminated(ppp_pcb *pcb) { 01015 PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated[%d]\n", pcb->netif->num)); 01016 pcb->link_cb->disconnect(pcb, pcb->link_ctx_cb); 01017 PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated[%d]: finished.\n", pcb->netif->num)); 01018 } 01019 01020 01021 /************************************************************************ 01022 * Functions called by various PPP subsystems to configure 01023 * the PPP interface or change the PPP phase. 01024 */ 01025 01026 /* 01027 * new_phase - signal the start of a new phase of pppd's operation. 01028 */ 01029 void new_phase(ppp_pcb *pcb, int p) { 01030 pcb->phase = p; 01031 PPPDEBUG(LOG_DEBUG, ("ppp phase changed[%d]: phase=%d\n", pcb->netif->num, pcb->phase)); 01032 #if PPP_NOTIFY_PHASE 01033 if (pcb->notify_phase_cb != NULL) { 01034 pcb->notify_phase_cb(pcb, p, pcb->ctx_cb); 01035 } 01036 #endif /* PPP_NOTIFY_PHASE */ 01037 } 01038 01039 /* 01040 * ppp_send_config - configure the transmit-side characteristics of 01041 * the ppp interface. 01042 */ 01043 int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp) { 01044 LWIP_UNUSED_ARG(mtu); 01045 /* pcb->mtu = mtu; -- set correctly with netif_set_mtu */ 01046 01047 if (pcb->link_cb->send_config) { 01048 pcb->link_cb->send_config(pcb, pcb->link_ctx_cb, accm, pcomp, accomp); 01049 } 01050 01051 PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]\n", pcb->netif->num) ); 01052 return 0; 01053 } 01054 01055 /* 01056 * ppp_recv_config - configure the receive-side characteristics of 01057 * the ppp interface. 01058 */ 01059 int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp) { 01060 LWIP_UNUSED_ARG(mru); 01061 01062 if (pcb->link_cb->recv_config) { 01063 pcb->link_cb->recv_config(pcb, pcb->link_ctx_cb, accm, pcomp, accomp); 01064 } 01065 01066 PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]\n", pcb->netif->num)); 01067 return 0; 01068 } 01069 01070 #if PPP_IPV4_SUPPORT 01071 /* 01072 * sifaddr - Config the interface IP addresses and netmask. 01073 */ 01074 int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask) { 01075 ip4_addr_t ip, nm, gw; 01076 01077 ip4_addr_set_u32(&ip, our_adr); 01078 ip4_addr_set_u32(&nm, netmask); 01079 ip4_addr_set_u32(&gw, his_adr); 01080 netif_set_addr(pcb->netif, &ip, &nm, &gw); 01081 return 1; 01082 } 01083 01084 /******************************************************************** 01085 * 01086 * cifaddr - Clear the interface IP addresses, and delete routes 01087 * through the interface if possible. 01088 */ 01089 int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr) { 01090 LWIP_UNUSED_ARG(our_adr); 01091 LWIP_UNUSED_ARG(his_adr); 01092 01093 netif_set_addr(pcb->netif, IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4); 01094 return 1; 01095 } 01096 01097 #if 0 /* UNUSED - PROXY ARP */ 01098 /******************************************************************** 01099 * 01100 * sifproxyarp - Make a proxy ARP entry for the peer. 01101 */ 01102 01103 int sifproxyarp(ppp_pcb *pcb, u32_t his_adr) { 01104 LWIP_UNUSED_ARG(pcb); 01105 LWIP_UNUSED_ARG(his_adr); 01106 return 0; 01107 } 01108 01109 /******************************************************************** 01110 * 01111 * cifproxyarp - Delete the proxy ARP entry for the peer. 01112 */ 01113 01114 int cifproxyarp(ppp_pcb *pcb, u32_t his_adr) { 01115 LWIP_UNUSED_ARG(pcb); 01116 LWIP_UNUSED_ARG(his_adr); 01117 return 0; 01118 } 01119 #endif /* UNUSED - PROXY ARP */ 01120 01121 #if LWIP_DNS 01122 /* 01123 * sdns - Config the DNS servers 01124 */ 01125 int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) { 01126 ip_addr_t ns; 01127 LWIP_UNUSED_ARG(pcb); 01128 01129 ip_addr_set_ip4_u32(&ns, ns1); 01130 dns_setserver(0, &ns); 01131 ip_addr_set_ip4_u32(&ns, ns2); 01132 dns_setserver(1, &ns); 01133 return 1; 01134 } 01135 01136 /******************************************************************** 01137 * 01138 * cdns - Clear the DNS servers 01139 */ 01140 int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) { 01141 const ip_addr_t *nsa; 01142 ip_addr_t nsb; 01143 LWIP_UNUSED_ARG(pcb); 01144 01145 nsa = dns_getserver(0); 01146 ip_addr_set_ip4_u32(&nsb, ns1); 01147 if (ip_addr_cmp(nsa, &nsb)) { 01148 dns_setserver(0, IP_ADDR_ANY); 01149 } 01150 nsa = dns_getserver(1); 01151 ip_addr_set_ip4_u32(&nsb, ns2); 01152 if (ip_addr_cmp(nsa, &nsb)) { 01153 dns_setserver(1, IP_ADDR_ANY); 01154 } 01155 return 1; 01156 } 01157 #endif /* LWIP_DNS */ 01158 01159 #if VJ_SUPPORT 01160 /******************************************************************** 01161 * 01162 * sifvjcomp - config tcp header compression 01163 */ 01164 int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid) { 01165 pcb->vj_enabled = vjcomp; 01166 pcb->vj_comp.compressSlot = cidcomp; 01167 pcb->vj_comp.maxSlotIndex = maxcid; 01168 PPPDEBUG(LOG_INFO, ("sifvjcomp[%d]: VJ compress enable=%d slot=%d max slot=%d\n", 01169 pcb->netif->num, vjcomp, cidcomp, maxcid)); 01170 return 0; 01171 } 01172 #endif /* VJ_SUPPORT */ 01173 01174 /* 01175 * sifup - Config the interface up and enable IP packets to pass. 01176 */ 01177 int sifup(ppp_pcb *pcb) { 01178 pcb->if4_up = 1; 01179 pcb->err_code = PPPERR_NONE; 01180 netif_set_link_up(pcb->netif); 01181 01182 PPPDEBUG(LOG_DEBUG, ("sifup[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code)); 01183 pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb); 01184 return 1; 01185 } 01186 01187 /******************************************************************** 01188 * 01189 * sifdown - Disable the indicated protocol and config the interface 01190 * down if there are no remaining protocols. 01191 */ 01192 int sifdown(ppp_pcb *pcb) { 01193 01194 pcb->if4_up = 0; 01195 01196 if (1 01197 #if PPP_IPV6_SUPPORT 01198 /* set the interface down if IPv6 is down as well */ 01199 && !pcb->if6_up 01200 #endif /* PPP_IPV6_SUPPORT */ 01201 ) { 01202 /* make sure the netif link callback is called */ 01203 netif_set_link_down(pcb->netif); 01204 } 01205 PPPDEBUG(LOG_DEBUG, ("sifdown[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code)); 01206 return 1; 01207 } 01208 01209 /******************************************************************** 01210 * 01211 * Return user specified netmask, modified by any mask we might determine 01212 * for address `addr' (in network byte order). 01213 * Here we scan through the system's list of interfaces, looking for 01214 * any non-point-to-point interfaces which might appear to be on the same 01215 * network as `addr'. If we find any, we OR in their netmask to the 01216 * user-specified netmask. 01217 */ 01218 u32_t get_mask(u32_t addr) { 01219 #if 0 01220 u32_t mask, nmask; 01221 01222 addr = lwip_htonl(addr); 01223 if (IP_CLASSA(addr)) { /* determine network mask for address class */ 01224 nmask = IP_CLASSA_NET; 01225 } else if (IP_CLASSB(addr)) { 01226 nmask = IP_CLASSB_NET; 01227 } else { 01228 nmask = IP_CLASSC_NET; 01229 } 01230 01231 /* class D nets are disallowed by bad_ip_adrs */ 01232 mask = PP_HTONL(0xffffff00UL) | lwip_htonl(nmask); 01233 01234 /* XXX 01235 * Scan through the system's network interfaces. 01236 * Get each netmask and OR them into our mask. 01237 */ 01238 /* return mask; */ 01239 return mask; 01240 #endif /* 0 */ 01241 LWIP_UNUSED_ARG(addr); 01242 return IPADDR_BROADCAST; 01243 } 01244 #endif /* PPP_IPV4_SUPPORT */ 01245 01246 #if PPP_IPV6_SUPPORT 01247 #define IN6_LLADDR_FROM_EUI64(ip6, eui64) do { \ 01248 ip6.addr[0] = PP_HTONL(0xfe800000); \ 01249 ip6.addr[1] = 0; \ 01250 eui64_copy(eui64, ip6.addr[2]); \ 01251 } while (0) 01252 01253 /******************************************************************** 01254 * 01255 * sif6addr - Config the interface with an IPv6 link-local address 01256 */ 01257 int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64) { 01258 ip6_addr_t ip6; 01259 LWIP_UNUSED_ARG(his_eui64); 01260 01261 IN6_LLADDR_FROM_EUI64(ip6, our_eui64); 01262 netif_ip6_addr_set(pcb->netif, 0, &ip6); 01263 netif_ip6_addr_set_state(pcb->netif, 0, IP6_ADDR_PREFERRED); 01264 /* FIXME: should we add an IPv6 static neighbor using his_eui64 ? */ 01265 return 1; 01266 } 01267 01268 /******************************************************************** 01269 * 01270 * cif6addr - Remove IPv6 address from interface 01271 */ 01272 int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64) { 01273 LWIP_UNUSED_ARG(our_eui64); 01274 LWIP_UNUSED_ARG(his_eui64); 01275 01276 netif_ip6_addr_set(pcb->netif, 0, IP6_ADDR_ANY6); 01277 netif_ip6_addr_set_state(pcb->netif, 0, IP6_ADDR_INVALID); 01278 return 1; 01279 } 01280 01281 /* 01282 * sif6up - Config the interface up and enable IPv6 packets to pass. 01283 */ 01284 int sif6up(ppp_pcb *pcb) { 01285 01286 pcb->if6_up = 1; 01287 pcb->err_code = PPPERR_NONE; 01288 netif_set_link_up(pcb->netif); 01289 01290 PPPDEBUG(LOG_DEBUG, ("sif6up[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code)); 01291 pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb); 01292 return 1; 01293 } 01294 01295 /******************************************************************** 01296 * 01297 * sif6down - Disable the indicated protocol and config the interface 01298 * down if there are no remaining protocols. 01299 */ 01300 int sif6down(ppp_pcb *pcb) { 01301 01302 pcb->if6_up = 0; 01303 01304 if (1 01305 #if PPP_IPV4_SUPPORT 01306 /* set the interface down if IPv4 is down as well */ 01307 && !pcb->if4_up 01308 #endif /* PPP_IPV4_SUPPORT */ 01309 ) { 01310 /* make sure the netif link callback is called */ 01311 netif_set_link_down(pcb->netif); 01312 } 01313 PPPDEBUG(LOG_DEBUG, ("sif6down[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code)); 01314 return 1; 01315 } 01316 #endif /* PPP_IPV6_SUPPORT */ 01317 01318 #if DEMAND_SUPPORT 01319 /* 01320 * sifnpmode - Set the mode for handling packets for a given NP. 01321 */ 01322 int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode) { 01323 LWIP_UNUSED_ARG(pcb); 01324 LWIP_UNUSED_ARG(proto); 01325 LWIP_UNUSED_ARG(mode); 01326 return 0; 01327 } 01328 #endif /* DEMAND_SUPPORT */ 01329 01330 /* 01331 * netif_set_mtu - set the MTU on the PPP network interface. 01332 */ 01333 void netif_set_mtu(ppp_pcb *pcb, int mtu) { 01334 01335 pcb->netif->mtu = mtu; 01336 PPPDEBUG(LOG_INFO, ("netif_set_mtu[%d]: mtu=%d\n", pcb->netif->num, mtu)); 01337 } 01338 01339 /* 01340 * netif_get_mtu - get PPP interface MTU 01341 */ 01342 int netif_get_mtu(ppp_pcb *pcb) { 01343 01344 return pcb->netif->mtu; 01345 } 01346 01347 #if CCP_SUPPORT 01348 #if 0 /* unused */ 01349 /* 01350 * ccp_test - whether a given compression method is acceptable for use. 01351 */ 01352 int 01353 ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit) 01354 { 01355 LWIP_UNUSED_ARG(pcb); 01356 LWIP_UNUSED_ARG(opt_ptr); 01357 LWIP_UNUSED_ARG(opt_len); 01358 LWIP_UNUSED_ARG(for_transmit); 01359 return -1; 01360 } 01361 #endif /* unused */ 01362 01363 /* 01364 * ccp_set - inform about the current state of CCP. 01365 */ 01366 void 01367 ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method) 01368 { 01369 LWIP_UNUSED_ARG(isopen); 01370 LWIP_UNUSED_ARG(isup); 01371 pcb->ccp_receive_method = receive_method; 01372 pcb->ccp_transmit_method = transmit_method; 01373 PPPDEBUG(LOG_DEBUG, ("ccp_set[%d]: is_open=%d, is_up=%d, receive_method=%u, transmit_method=%u\n", 01374 pcb->netif->num, isopen, isup, receive_method, transmit_method)); 01375 } 01376 01377 void 01378 ccp_reset_comp(ppp_pcb *pcb) 01379 { 01380 switch (pcb->ccp_transmit_method) { 01381 #if MPPE_SUPPORT 01382 case CI_MPPE: 01383 mppe_comp_reset(pcb, &pcb->mppe_comp); 01384 break; 01385 #endif /* MPPE_SUPPORT */ 01386 default: 01387 break; 01388 } 01389 } 01390 01391 void 01392 ccp_reset_decomp(ppp_pcb *pcb) 01393 { 01394 switch (pcb->ccp_receive_method) { 01395 #if MPPE_SUPPORT 01396 case CI_MPPE: 01397 mppe_decomp_reset(pcb, &pcb->mppe_decomp); 01398 break; 01399 #endif /* MPPE_SUPPORT */ 01400 default: 01401 break; 01402 } 01403 } 01404 01405 #if 0 /* unused */ 01406 /* 01407 * ccp_fatal_error - returns 1 if decompression was disabled as a 01408 * result of an error detected after decompression of a packet, 01409 * 0 otherwise. This is necessary because of patent nonsense. 01410 */ 01411 int 01412 ccp_fatal_error(ppp_pcb *pcb) 01413 { 01414 LWIP_UNUSED_ARG(pcb); 01415 return 1; 01416 } 01417 #endif /* unused */ 01418 #endif /* CCP_SUPPORT */ 01419 01420 #if PPP_IDLETIMELIMIT 01421 /******************************************************************** 01422 * 01423 * get_idle_time - return how long the link has been idle. 01424 */ 01425 int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip) { 01426 /* FIXME: add idle time support and make it optional */ 01427 LWIP_UNUSED_ARG(pcb); 01428 LWIP_UNUSED_ARG(ip); 01429 return 1; 01430 } 01431 #endif /* PPP_IDLETIMELIMIT */ 01432 01433 #if DEMAND_SUPPORT 01434 /******************************************************************** 01435 * 01436 * get_loop_output - get outgoing packets from the ppp device, 01437 * and detect when we want to bring the real link up. 01438 * Return value is 1 if we need to bring up the link, 0 otherwise. 01439 */ 01440 int get_loop_output(void) { 01441 return 0; 01442 } 01443 #endif /* DEMAND_SUPPORT */ 01444 01445 #if PPP_PROTOCOLNAME 01446 /* List of protocol names, to make our messages a little more informative. */ 01447 struct protocol_list { 01448 u_short proto; 01449 const char *name; 01450 } const protocol_list[] = { 01451 { 0x21, "IP" }, 01452 { 0x23, "OSI Network Layer" }, 01453 { 0x25, "Xerox NS IDP" }, 01454 { 0x27, "DECnet Phase IV" }, 01455 { 0x29, "Appletalk" }, 01456 { 0x2b, "Novell IPX" }, 01457 { 0x2d, "VJ compressed TCP/IP" }, 01458 { 0x2f, "VJ uncompressed TCP/IP" }, 01459 { 0x31, "Bridging PDU" }, 01460 { 0x33, "Stream Protocol ST-II" }, 01461 { 0x35, "Banyan Vines" }, 01462 { 0x39, "AppleTalk EDDP" }, 01463 { 0x3b, "AppleTalk SmartBuffered" }, 01464 { 0x3d, "Multi-Link" }, 01465 { 0x3f, "NETBIOS Framing" }, 01466 { 0x41, "Cisco Systems" }, 01467 { 0x43, "Ascom Timeplex" }, 01468 { 0x45, "Fujitsu Link Backup and Load Balancing (LBLB)" }, 01469 { 0x47, "DCA Remote Lan" }, 01470 { 0x49, "Serial Data Transport Protocol (PPP-SDTP)" }, 01471 { 0x4b, "SNA over 802.2" }, 01472 { 0x4d, "SNA" }, 01473 { 0x4f, "IP6 Header Compression" }, 01474 { 0x51, "KNX Bridging Data" }, 01475 { 0x53, "Encryption" }, 01476 { 0x55, "Individual Link Encryption" }, 01477 { 0x57, "IPv6" }, 01478 { 0x59, "PPP Muxing" }, 01479 { 0x5b, "Vendor-Specific Network Protocol" }, 01480 { 0x61, "RTP IPHC Full Header" }, 01481 { 0x63, "RTP IPHC Compressed TCP" }, 01482 { 0x65, "RTP IPHC Compressed non-TCP" }, 01483 { 0x67, "RTP IPHC Compressed UDP 8" }, 01484 { 0x69, "RTP IPHC Compressed RTP 8" }, 01485 { 0x6f, "Stampede Bridging" }, 01486 { 0x73, "MP+" }, 01487 { 0xc1, "NTCITS IPI" }, 01488 { 0xfb, "single-link compression" }, 01489 { 0xfd, "Compressed Datagram" }, 01490 { 0x0201, "802.1d Hello Packets" }, 01491 { 0x0203, "IBM Source Routing BPDU" }, 01492 { 0x0205, "DEC LANBridge100 Spanning Tree" }, 01493 { 0x0207, "Cisco Discovery Protocol" }, 01494 { 0x0209, "Netcs Twin Routing" }, 01495 { 0x020b, "STP - Scheduled Transfer Protocol" }, 01496 { 0x020d, "EDP - Extreme Discovery Protocol" }, 01497 { 0x0211, "Optical Supervisory Channel Protocol" }, 01498 { 0x0213, "Optical Supervisory Channel Protocol" }, 01499 { 0x0231, "Luxcom" }, 01500 { 0x0233, "Sigma Network Systems" }, 01501 { 0x0235, "Apple Client Server Protocol" }, 01502 { 0x0281, "MPLS Unicast" }, 01503 { 0x0283, "MPLS Multicast" }, 01504 { 0x0285, "IEEE p1284.4 standard - data packets" }, 01505 { 0x0287, "ETSI TETRA Network Protocol Type 1" }, 01506 { 0x0289, "Multichannel Flow Treatment Protocol" }, 01507 { 0x2063, "RTP IPHC Compressed TCP No Delta" }, 01508 { 0x2065, "RTP IPHC Context State" }, 01509 { 0x2067, "RTP IPHC Compressed UDP 16" }, 01510 { 0x2069, "RTP IPHC Compressed RTP 16" }, 01511 { 0x4001, "Cray Communications Control Protocol" }, 01512 { 0x4003, "CDPD Mobile Network Registration Protocol" }, 01513 { 0x4005, "Expand accelerator protocol" }, 01514 { 0x4007, "ODSICP NCP" }, 01515 { 0x4009, "DOCSIS DLL" }, 01516 { 0x400B, "Cetacean Network Detection Protocol" }, 01517 { 0x4021, "Stacker LZS" }, 01518 { 0x4023, "RefTek Protocol" }, 01519 { 0x4025, "Fibre Channel" }, 01520 { 0x4027, "EMIT Protocols" }, 01521 { 0x405b, "Vendor-Specific Protocol (VSP)" }, 01522 { 0x8021, "Internet Protocol Control Protocol" }, 01523 { 0x8023, "OSI Network Layer Control Protocol" }, 01524 { 0x8025, "Xerox NS IDP Control Protocol" }, 01525 { 0x8027, "DECnet Phase IV Control Protocol" }, 01526 { 0x8029, "Appletalk Control Protocol" }, 01527 { 0x802b, "Novell IPX Control Protocol" }, 01528 { 0x8031, "Bridging NCP" }, 01529 { 0x8033, "Stream Protocol Control Protocol" }, 01530 { 0x8035, "Banyan Vines Control Protocol" }, 01531 { 0x803d, "Multi-Link Control Protocol" }, 01532 { 0x803f, "NETBIOS Framing Control Protocol" }, 01533 { 0x8041, "Cisco Systems Control Protocol" }, 01534 { 0x8043, "Ascom Timeplex" }, 01535 { 0x8045, "Fujitsu LBLB Control Protocol" }, 01536 { 0x8047, "DCA Remote Lan Network Control Protocol (RLNCP)" }, 01537 { 0x8049, "Serial Data Control Protocol (PPP-SDCP)" }, 01538 { 0x804b, "SNA over 802.2 Control Protocol" }, 01539 { 0x804d, "SNA Control Protocol" }, 01540 { 0x804f, "IP6 Header Compression Control Protocol" }, 01541 { 0x8051, "KNX Bridging Control Protocol" }, 01542 { 0x8053, "Encryption Control Protocol" }, 01543 { 0x8055, "Individual Link Encryption Control Protocol" }, 01544 { 0x8057, "IPv6 Control Protocol" }, 01545 { 0x8059, "PPP Muxing Control Protocol" }, 01546 { 0x805b, "Vendor-Specific Network Control Protocol (VSNCP)" }, 01547 { 0x806f, "Stampede Bridging Control Protocol" }, 01548 { 0x8073, "MP+ Control Protocol" }, 01549 { 0x80c1, "NTCITS IPI Control Protocol" }, 01550 { 0x80fb, "Single Link Compression Control Protocol" }, 01551 { 0x80fd, "Compression Control Protocol" }, 01552 { 0x8207, "Cisco Discovery Protocol Control" }, 01553 { 0x8209, "Netcs Twin Routing" }, 01554 { 0x820b, "STP - Control Protocol" }, 01555 { 0x820d, "EDPCP - Extreme Discovery Protocol Ctrl Prtcl" }, 01556 { 0x8235, "Apple Client Server Protocol Control" }, 01557 { 0x8281, "MPLSCP" }, 01558 { 0x8285, "IEEE p1284.4 standard - Protocol Control" }, 01559 { 0x8287, "ETSI TETRA TNP1 Control Protocol" }, 01560 { 0x8289, "Multichannel Flow Treatment Protocol" }, 01561 { 0xc021, "Link Control Protocol" }, 01562 { 0xc023, "Password Authentication Protocol" }, 01563 { 0xc025, "Link Quality Report" }, 01564 { 0xc027, "Shiva Password Authentication Protocol" }, 01565 { 0xc029, "CallBack Control Protocol (CBCP)" }, 01566 { 0xc02b, "BACP Bandwidth Allocation Control Protocol" }, 01567 { 0xc02d, "BAP" }, 01568 { 0xc05b, "Vendor-Specific Authentication Protocol (VSAP)" }, 01569 { 0xc081, "Container Control Protocol" }, 01570 { 0xc223, "Challenge Handshake Authentication Protocol" }, 01571 { 0xc225, "RSA Authentication Protocol" }, 01572 { 0xc227, "Extensible Authentication Protocol" }, 01573 { 0xc229, "Mitsubishi Security Info Exch Ptcl (SIEP)" }, 01574 { 0xc26f, "Stampede Bridging Authorization Protocol" }, 01575 { 0xc281, "Proprietary Authentication Protocol" }, 01576 { 0xc283, "Proprietary Authentication Protocol" }, 01577 { 0xc481, "Proprietary Node ID Authentication Protocol" }, 01578 { 0, NULL }, 01579 }; 01580 01581 /* 01582 * protocol_name - find a name for a PPP protocol. 01583 */ 01584 const char * protocol_name(int proto) { 01585 const struct protocol_list *lp; 01586 01587 for (lp = protocol_list; lp->proto != 0; ++lp) { 01588 if (proto == lp->proto) { 01589 return lp->name; 01590 } 01591 } 01592 return NULL; 01593 } 01594 #endif /* PPP_PROTOCOLNAME */ 01595 01596 #if PPP_STATS_SUPPORT 01597 01598 /* ---- Note on PPP Stats support ---- 01599 * 01600 * The one willing link stats support should add the get_ppp_stats() 01601 * to fetch statistics from lwIP. 01602 */ 01603 01604 /* 01605 * reset_link_stats - "reset" stats when link goes up. 01606 */ 01607 void reset_link_stats(int u) { 01608 if (!get_ppp_stats(u, &old_link_stats)) { 01609 return; 01610 } 01611 gettimeofday(&start_time, NULL); 01612 } 01613 01614 /* 01615 * update_link_stats - get stats at link termination. 01616 */ 01617 void update_link_stats(int u) { 01618 struct timeval now; 01619 char numbuf[32]; 01620 01621 if (!get_ppp_stats(u, &link_stats) || gettimeofday(&now, NULL) < 0) { 01622 return; 01623 } 01624 link_connect_time = now.tv_sec - start_time.tv_sec; 01625 link_stats_valid = 1; 01626 01627 link_stats.bytes_in -= old_link_stats.bytes_in; 01628 link_stats.bytes_out -= old_link_stats.bytes_out; 01629 link_stats.pkts_in -= old_link_stats.pkts_in; 01630 link_stats.pkts_out -= old_link_stats.pkts_out; 01631 } 01632 01633 void print_link_stats() { 01634 /* 01635 * Print connect time and statistics. 01636 */ 01637 if (link_stats_valid) { 01638 int t = (link_connect_time + 5) / 6; /* 1/10ths of minutes */ 01639 info("Connect time %d.%d minutes.", t/10, t%10); 01640 info("Sent %u bytes, received %u bytes.", link_stats.bytes_out, link_stats.bytes_in); 01641 link_stats_valid = 0; 01642 } 01643 } 01644 #endif /* PPP_STATS_SUPPORT */ 01645 01646 #endif /* PPP_SUPPORT */
Generated on Tue Jul 12 2022 11:02:27 by
1.7.2