• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*****************************************************************************
2 * ppp.c - Network Point to Point Protocol program file.
3 *
4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
5 * portions Copyright (c) 1997 by Global Election Systems Inc.
6 *
7 * The authors hereby grant permission to use, copy, modify, distribute,
8 * and license this software and its documentation for any purpose, provided
9 * that existing copyright notices are retained in all copies and that this
10 * notice and the following disclaimer are included verbatim in any
11 * distributions. No written agreement, license, or royalty fee is required
12 * for any of the authorized uses.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 ******************************************************************************
26 * REVISION HISTORY
27 *
28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
29 *   Ported to lwIP.
30 * 97-11-05 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
31 *   Original.
32 *****************************************************************************/
33 
34 /*
35  * ppp_defs.h - PPP definitions.
36  *
37  * if_pppvar.h - private structures and declarations for PPP.
38  *
39  * Copyright (c) 1994 The Australian National University.
40  * All rights reserved.
41  *
42  * Permission to use, copy, modify, and distribute this software and its
43  * documentation is hereby granted, provided that the above copyright
44  * notice appears in all copies.  This software is provided without any
45  * warranty, express or implied. The Australian National University
46  * makes no representations about the suitability of this software for
47  * any purpose.
48  *
49  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
50  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
51  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
52  * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
53  * OF SUCH DAMAGE.
54  *
55  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
56  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
57  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
58  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
59  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
60  * OR MODIFICATIONS.
61  */
62 
63 /*
64  * if_ppp.h - Point-to-Point Protocol definitions.
65  *
66  * Copyright (c) 1989 Carnegie Mellon University.
67  * All rights reserved.
68  *
69  * Redistribution and use in source and binary forms are permitted
70  * provided that the above copyright notice and this paragraph are
71  * duplicated in all such forms and that any documentation,
72  * advertising materials, and other materials related to such
73  * distribution and use acknowledge that the software was developed
74  * by Carnegie Mellon University.  The name of the
75  * University may not be used to endorse or promote products derived
76  * from this software without specific prior written permission.
77  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
78  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
79  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
80  */
81 
82 /**
83  * @defgroup ppp PPP
84  * @ingroup netifs
85  * @verbinclude "ppp.txt"
86  */
87 
88 #include "netif/ppp/ppp_opts.h"
89 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
90 
91 #include "lwip/pbuf.h"
92 #include "lwip/stats.h"
93 #include "lwip/sys.h"
94 #include "lwip/tcpip.h"
95 #include "lwip/api.h"
96 #include "lwip/snmp.h"
97 #include "lwip/ip4.h" /* for ip4_input() */
98 #if PPP_IPV6_SUPPORT
99 #include "lwip/ip6.h" /* for ip6_input() */
100 #endif /* PPP_IPV6_SUPPORT */
101 #include "lwip/dns.h"
102 
103 #include "netif/ppp/ppp_impl.h"
104 #include "netif/ppp/pppos.h"
105 
106 #include "netif/ppp/fsm.h"
107 #include "netif/ppp/lcp.h"
108 #include "netif/ppp/magic.h"
109 
110 #if PAP_SUPPORT
111 #include "netif/ppp/upap.h"
112 #endif /* PAP_SUPPORT */
113 #if CHAP_SUPPORT
114 #include "netif/ppp/chap-new.h"
115 #endif /* CHAP_SUPPORT */
116 #if EAP_SUPPORT
117 #include "netif/ppp/eap.h"
118 #endif /* EAP_SUPPORT */
119 #if CCP_SUPPORT
120 #include "netif/ppp/ccp.h"
121 #endif /* CCP_SUPPORT */
122 #if MPPE_SUPPORT
123 #include "netif/ppp/mppe.h"
124 #endif /* MPPE_SUPPORT */
125 #if ECP_SUPPORT
126 #include "netif/ppp/ecp.h"
127 #endif /* EAP_SUPPORT */
128 #if VJ_SUPPORT
129 #include "netif/ppp/vj.h"
130 #endif /* VJ_SUPPORT */
131 #if PPP_IPV4_SUPPORT
132 #include "netif/ppp/ipcp.h"
133 #endif /* PPP_IPV4_SUPPORT */
134 #if PPP_IPV6_SUPPORT
135 #include "netif/ppp/ipv6cp.h"
136 #endif /* PPP_IPV6_SUPPORT */
137 
138 /*************************/
139 /*** LOCAL DEFINITIONS ***/
140 /*************************/
141 
142 /* Memory pools */
143 #if PPPOS_SUPPORT
144 LWIP_MEMPOOL_PROTOTYPE(PPPOS_PCB);
145 #endif
146 #if PPPOE_SUPPORT
147 LWIP_MEMPOOL_PROTOTYPE(PPPOE_IF);
148 #endif
149 #if PPPOL2TP_SUPPORT
150 LWIP_MEMPOOL_PROTOTYPE(PPPOL2TP_PCB);
151 #endif
152 #if LWIP_PPP_API && LWIP_MPU_COMPATIBLE
153 LWIP_MEMPOOL_PROTOTYPE(PPPAPI_MSG);
154 #endif
155 LWIP_MEMPOOL_DECLARE(PPP_PCB, MEMP_NUM_PPP_PCB, sizeof(ppp_pcb), "PPP_PCB")
156 
157 /* FIXME: add stats per PPP session */
158 #if PPP_STATS_SUPPORT
159 static struct timeval start_time; /* Time when link was started. */
160 static struct pppd_stats old_link_stats;
161 struct pppd_stats link_stats;
162 unsigned link_connect_time;
163 int link_stats_valid;
164 #endif /* PPP_STATS_SUPPORT */
165 
166 /*
167  * PPP Data Link Layer "protocol" table.
168  * One entry per supported protocol.
169  * The last entry must be NULL.
170  */
171 const struct protent* const protocols[] = {
172     &lcp_protent,
173 #if PAP_SUPPORT
174     &pap_protent,
175 #endif /* PAP_SUPPORT */
176 #if CHAP_SUPPORT
177     &chap_protent,
178 #endif /* CHAP_SUPPORT */
179 #if CBCP_SUPPORT
180     &cbcp_protent,
181 #endif /* CBCP_SUPPORT */
182 #if PPP_IPV4_SUPPORT
183     &ipcp_protent,
184 #endif /* PPP_IPV4_SUPPORT */
185 #if PPP_IPV6_SUPPORT
186     &ipv6cp_protent,
187 #endif /* PPP_IPV6_SUPPORT */
188 #if CCP_SUPPORT
189     &ccp_protent,
190 #endif /* CCP_SUPPORT */
191 #if ECP_SUPPORT
192     &ecp_protent,
193 #endif /* ECP_SUPPORT */
194 #ifdef AT_CHANGE
195     &atcp_protent,
196 #endif /* AT_CHANGE */
197 #if EAP_SUPPORT
198     &eap_protent,
199 #endif /* EAP_SUPPORT */
200     NULL
201 };
202 
203 /* Prototypes for procedures local to this file. */
204 static void ppp_do_connect(void *arg);
205 static err_t ppp_netif_init_cb(struct netif *netif);
206 #if PPP_IPV4_SUPPORT
207 static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr);
208 #endif /* PPP_IPV4_SUPPORT */
209 #if PPP_IPV6_SUPPORT
210 static err_t ppp_netif_output_ip6(struct netif *netif, struct pbuf *pb, const ip6_addr_t *ipaddr);
211 #endif /* PPP_IPV6_SUPPORT */
212 static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protocol);
213 
214 /***********************************/
215 /*** PUBLIC FUNCTION DEFINITIONS ***/
216 /***********************************/
217 #if PPP_AUTH_SUPPORT
ppp_set_auth(ppp_pcb * pcb,u8_t authtype,const char * user,const char * passwd)218 void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd) {
219   LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD", pcb->phase == PPP_PHASE_DEAD);
220 
221 #if PAP_SUPPORT
222   pcb->settings.refuse_pap = !(authtype & PPPAUTHTYPE_PAP);
223 #endif /* PAP_SUPPORT */
224 #if CHAP_SUPPORT
225   pcb->settings.refuse_chap = !(authtype & PPPAUTHTYPE_CHAP);
226 #if MSCHAP_SUPPORT
227   pcb->settings.refuse_mschap = !(authtype & PPPAUTHTYPE_MSCHAP);
228   pcb->settings.refuse_mschap_v2 = !(authtype & PPPAUTHTYPE_MSCHAP_V2);
229 #endif /* MSCHAP_SUPPORT */
230 #endif /* CHAP_SUPPORT */
231 #if EAP_SUPPORT
232   pcb->settings.refuse_eap = !(authtype & PPPAUTHTYPE_EAP);
233 #endif /* EAP_SUPPORT */
234   pcb->settings.user = user;
235   pcb->settings.passwd = passwd;
236 }
237 #endif /* PPP_AUTH_SUPPORT */
238 
239 #if MPPE_SUPPORT
240 /* Set MPPE configuration */
ppp_set_mppe(ppp_pcb * pcb,u8_t flags)241 void ppp_set_mppe(ppp_pcb *pcb, u8_t flags) {
242   LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD", pcb->phase == PPP_PHASE_DEAD);
243 
244   if (flags == PPP_MPPE_DISABLE) {
245     pcb->settings.require_mppe = 0;
246     return;
247   }
248 
249   pcb->settings.require_mppe = 1;
250   pcb->settings.refuse_mppe_stateful = !(flags & PPP_MPPE_ALLOW_STATEFUL);
251   pcb->settings.refuse_mppe_40 = !!(flags & PPP_MPPE_REFUSE_40);
252   pcb->settings.refuse_mppe_128 = !!(flags & PPP_MPPE_REFUSE_128);
253 }
254 #endif /* MPPE_SUPPORT */
255 
256 #if PPP_NOTIFY_PHASE
ppp_set_notify_phase_callback(ppp_pcb * pcb,ppp_notify_phase_cb_fn notify_phase_cb)257 void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb) {
258   pcb->notify_phase_cb = notify_phase_cb;
259   notify_phase_cb(pcb, pcb->phase, pcb->ctx_cb);
260 }
261 #endif /* PPP_NOTIFY_PHASE */
262 
263 /*
264  * Initiate a PPP connection.
265  *
266  * This can only be called if PPP is in the dead phase.
267  *
268  * Holdoff is the time to wait (in seconds) before initiating
269  * the connection.
270  *
271  * If this port connects to a modem, the modem connection must be
272  * established before calling this.
273  */
ppp_connect(ppp_pcb * pcb,u16_t holdoff)274 err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff) {
275   LWIP_ASSERT_CORE_LOCKED();
276   if (pcb->phase != PPP_PHASE_DEAD) {
277     return ERR_ALREADY;
278   }
279 
280   PPPDEBUG(LOG_DEBUG, ("ppp_connect[%d]: holdoff=%d\n", pcb->netif->num, holdoff));
281 
282   magic_randomize();
283 
284   if (holdoff == 0) {
285     ppp_do_connect(pcb);
286     return ERR_OK;
287   }
288 
289   new_phase(pcb, PPP_PHASE_HOLDOFF);
290   sys_timeout((u32_t)(holdoff*1000), ppp_do_connect, pcb);
291   return ERR_OK;
292 }
293 
294 #if PPP_SERVER
295 /*
296  * Listen for an incoming PPP connection.
297  *
298  * This can only be called if PPP is in the dead phase.
299  *
300  * If this port connects to a modem, the modem connection must be
301  * established before calling this.
302  */
ppp_listen(ppp_pcb * pcb)303 err_t ppp_listen(ppp_pcb *pcb) {
304   LWIP_ASSERT_CORE_LOCKED();
305   if (pcb->phase != PPP_PHASE_DEAD) {
306     return ERR_ALREADY;
307   }
308 
309   PPPDEBUG(LOG_DEBUG, ("ppp_listen[%d]\n", pcb->netif->num));
310 
311   magic_randomize();
312 
313   if (pcb->link_cb->listen) {
314     new_phase(pcb, PPP_PHASE_INITIALIZE);
315     pcb->link_cb->listen(pcb, pcb->link_ctx_cb);
316     return ERR_OK;
317   }
318   return ERR_IF;
319 }
320 #endif /* PPP_SERVER */
321 
322 /*
323  * Initiate the end of a PPP connection.
324  * Any outstanding packets in the queues are dropped.
325  *
326  * Setting nocarrier to 1 close the PPP connection without initiating the
327  * shutdown procedure. Always using nocarrier = 0 is still recommended,
328  * this is going to take a little longer time if your link is down, but
329  * is a safer choice for the PPP state machine.
330  *
331  * Return 0 on success, an error code on failure.
332  */
333 err_t
ppp_close(ppp_pcb * pcb,u8_t nocarrier)334 ppp_close(ppp_pcb *pcb, u8_t nocarrier)
335 {
336   LWIP_ASSERT_CORE_LOCKED();
337 
338   pcb->err_code = PPPERR_USER;
339 
340   /* holdoff phase, cancel the reconnection */
341   if (pcb->phase == PPP_PHASE_HOLDOFF) {
342     sys_untimeout(ppp_do_connect, pcb);
343     new_phase(pcb, PPP_PHASE_DEAD);
344   }
345 
346   /* dead phase, nothing to do, call the status callback to be consistent */
347   if (pcb->phase == PPP_PHASE_DEAD) {
348     pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
349     return ERR_OK;
350   }
351 
352   /* Already terminating, nothing to do */
353   if (pcb->phase >= PPP_PHASE_TERMINATE) {
354     return ERR_INPROGRESS;
355   }
356 
357   /* LCP not open, close link protocol */
358   if (pcb->phase < PPP_PHASE_ESTABLISH) {
359     new_phase(pcb, PPP_PHASE_DISCONNECT);
360     ppp_link_terminated(pcb);
361     return ERR_OK;
362   }
363 
364   /*
365    * Only accept carrier lost signal on the stable running phase in order
366    * to prevent changing the PPP phase FSM in transition phases.
367    *
368    * Always using nocarrier = 0 is still recommended, this is going to
369    * take a little longer time, but is a safer choice from FSM point of view.
370    */
371   if (nocarrier && pcb->phase == PPP_PHASE_RUNNING) {
372     PPPDEBUG(LOG_DEBUG, ("ppp_close[%d]: carrier lost -> lcp_lowerdown\n", pcb->netif->num));
373     lcp_lowerdown(pcb);
374     /* forced link termination, this will force link protocol to disconnect. */
375     link_terminated(pcb);
376     return ERR_OK;
377   }
378 
379   /* Disconnect */
380   PPPDEBUG(LOG_DEBUG, ("ppp_close[%d]: kill_link -> lcp_close\n", pcb->netif->num));
381   /* LCP soft close request. */
382   lcp_close(pcb, "User request");
383   return ERR_OK;
384 }
385 
386 /*
387  * Release the control block.
388  *
389  * This can only be called if PPP is in the dead phase.
390  *
391  * You must use ppp_close() before if you wish to terminate
392  * an established PPP session.
393  *
394  * Return 0 on success, an error code on failure.
395  */
ppp_free(ppp_pcb * pcb)396 err_t ppp_free(ppp_pcb *pcb) {
397   err_t err;
398   LWIP_ASSERT_CORE_LOCKED();
399   if (pcb->phase != PPP_PHASE_DEAD) {
400     return ERR_CONN;
401   }
402 
403   PPPDEBUG(LOG_DEBUG, ("ppp_free[%d]\n", pcb->netif->num));
404 
405   netif_remove(pcb->netif);
406 
407   err = pcb->link_cb->free(pcb, pcb->link_ctx_cb);
408 
409   LWIP_MEMPOOL_FREE(PPP_PCB, pcb);
410   return err;
411 }
412 
413 /* Get and set parameters for the given connection.
414  * Return 0 on success, an error code on failure. */
415 err_t
ppp_ioctl(ppp_pcb * pcb,u8_t cmd,void * arg)416 ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg)
417 {
418   LWIP_ASSERT_CORE_LOCKED();
419   if (pcb == NULL) {
420     return ERR_VAL;
421   }
422 
423   switch(cmd) {
424     case PPPCTLG_UPSTATUS:      /* Get the PPP up status. */
425       if (!arg) {
426         goto fail;
427       }
428       *(int *)arg = (int)(0
429 #if PPP_IPV4_SUPPORT
430            || pcb->if4_up
431 #endif /* PPP_IPV4_SUPPORT */
432 #if PPP_IPV6_SUPPORT
433            || pcb->if6_up
434 #endif /* PPP_IPV6_SUPPORT */
435            );
436       return ERR_OK;
437 
438     case PPPCTLG_ERRCODE:       /* Get the PPP error code. */
439       if (!arg) {
440         goto fail;
441       }
442       *(int *)arg = (int)(pcb->err_code);
443       return ERR_OK;
444 
445     default:
446       goto fail;
447   }
448 
449 fail:
450   return ERR_VAL;
451 }
452 
453 
454 /**********************************/
455 /*** LOCAL FUNCTION DEFINITIONS ***/
456 /**********************************/
457 
ppp_do_connect(void * arg)458 static void ppp_do_connect(void *arg) {
459   ppp_pcb *pcb = (ppp_pcb*)arg;
460 
461   LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF);
462 
463   new_phase(pcb, PPP_PHASE_INITIALIZE);
464   pcb->link_cb->connect(pcb, pcb->link_ctx_cb);
465 }
466 
467 /*
468  * ppp_netif_init_cb - netif init callback
469  */
ppp_netif_init_cb(struct netif * netif)470 static err_t ppp_netif_init_cb(struct netif *netif) {
471   netif->name[0] = 'p';
472   netif->name[1] = 'p';
473 #if PPP_IPV4_SUPPORT
474   netif->output = ppp_netif_output_ip4;
475 #endif /* PPP_IPV4_SUPPORT */
476 #if PPP_IPV6_SUPPORT
477   netif->output_ip6 = ppp_netif_output_ip6;
478 #endif /* PPP_IPV6_SUPPORT */
479   netif->flags = NETIF_FLAG_UP;
480 #if LWIP_NETIF_HOSTNAME
481   /* @todo: Initialize interface hostname */
482   /* netif_set_hostname(netif, "lwip"); */
483 #endif /* LWIP_NETIF_HOSTNAME */
484   return ERR_OK;
485 }
486 
487 #if PPP_IPV4_SUPPORT
488 /*
489  * Send an IPv4 packet on the given connection.
490  */
ppp_netif_output_ip4(struct netif * netif,struct pbuf * pb,const ip4_addr_t * ipaddr)491 static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr) {
492   LWIP_UNUSED_ARG(ipaddr);
493   return ppp_netif_output(netif, pb, PPP_IP);
494 }
495 #endif /* PPP_IPV4_SUPPORT */
496 
497 #if PPP_IPV6_SUPPORT
498 /*
499  * Send an IPv6 packet on the given connection.
500  */
ppp_netif_output_ip6(struct netif * netif,struct pbuf * pb,const ip6_addr_t * ipaddr)501 static err_t ppp_netif_output_ip6(struct netif *netif, struct pbuf *pb, const ip6_addr_t *ipaddr) {
502   LWIP_UNUSED_ARG(ipaddr);
503   return ppp_netif_output(netif, pb, PPP_IPV6);
504 }
505 #endif /* PPP_IPV6_SUPPORT */
506 
ppp_netif_output(struct netif * netif,struct pbuf * pb,u16_t protocol)507 static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protocol) {
508   ppp_pcb *pcb = (ppp_pcb*)netif->state;
509   err_t err;
510   struct pbuf *fpb = NULL;
511 
512   /* Check that the link is up. */
513   if (0
514 #if PPP_IPV4_SUPPORT
515       || (protocol == PPP_IP && !pcb->if4_up)
516 #endif /* PPP_IPV4_SUPPORT */
517 #if PPP_IPV6_SUPPORT
518       || (protocol == PPP_IPV6 && !pcb->if6_up)
519 #endif /* PPP_IPV6_SUPPORT */
520       ) {
521     PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: link not up\n", pcb->netif->num));
522     goto err_rte_drop;
523   }
524 
525 #if MPPE_SUPPORT
526   /* If MPPE is required, refuse any IP packet until we are able to crypt them. */
527   if (pcb->settings.require_mppe && pcb->ccp_transmit_method != CI_MPPE) {
528     PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: MPPE required, not up\n", pcb->netif->num));
529     goto err_rte_drop;
530   }
531 #endif /* MPPE_SUPPORT */
532 
533 #if VJ_SUPPORT
534   /*
535    * Attempt Van Jacobson header compression if VJ is configured and
536    * this is an IP packet.
537    */
538   if (protocol == PPP_IP && pcb->vj_enabled) {
539     switch (vj_compress_tcp(&pcb->vj_comp, &pb)) {
540       case TYPE_IP:
541         /* No change...
542            protocol = PPP_IP; */
543         break;
544       case TYPE_COMPRESSED_TCP:
545         /* vj_compress_tcp() returns a new allocated pbuf, indicate we should free
546          * our duplicated pbuf later */
547         fpb = pb;
548         protocol = PPP_VJC_COMP;
549         break;
550       case TYPE_UNCOMPRESSED_TCP:
551         /* vj_compress_tcp() returns a new allocated pbuf, indicate we should free
552          * our duplicated pbuf later */
553         fpb = pb;
554         protocol = PPP_VJC_UNCOMP;
555         break;
556       default:
557         PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad IP packet\n", pcb->netif->num));
558         LINK_STATS_INC(link.proterr);
559         LINK_STATS_INC(link.drop);
560         MIB2_STATS_NETIF_INC(pcb->netif, ifoutdiscards);
561         return ERR_VAL;
562     }
563   }
564 #endif /* VJ_SUPPORT */
565 
566 #if CCP_SUPPORT
567   switch (pcb->ccp_transmit_method) {
568   case 0:
569     break; /* Don't compress */
570 #if MPPE_SUPPORT
571   case CI_MPPE:
572     if ((err = mppe_compress(pcb, &pcb->mppe_comp, &pb, protocol)) != ERR_OK) {
573       LINK_STATS_INC(link.memerr);
574       LINK_STATS_INC(link.drop);
575       MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
576       goto err;
577     }
578     /* if VJ compressor returned a new allocated pbuf, free it */
579     if (fpb) {
580       pbuf_free(fpb);
581     }
582     /* mppe_compress() returns a new allocated pbuf, indicate we should free
583      * our duplicated pbuf later */
584     fpb = pb;
585     protocol = PPP_COMP;
586     break;
587 #endif /* MPPE_SUPPORT */
588   default:
589     PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: bad CCP transmit method\n", pcb->netif->num));
590     goto err_rte_drop; /* Cannot really happen, we only negotiate what we are able to do */
591   }
592 #endif /* CCP_SUPPORT */
593 
594   err = pcb->link_cb->netif_output(pcb, pcb->link_ctx_cb, pb, protocol);
595   goto err;
596 
597 err_rte_drop:
598   err = ERR_RTE;
599   LINK_STATS_INC(link.rterr);
600   LINK_STATS_INC(link.drop);
601   MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
602 err:
603   if (fpb) {
604     pbuf_free(fpb);
605   }
606   return err;
607 }
608 
609 /************************************/
610 /*** PRIVATE FUNCTION DEFINITIONS ***/
611 /************************************/
612 
613 /* Initialize the PPP subsystem. */
ppp_init(void)614 int ppp_init(void)
615 {
616 #if PPPOS_SUPPORT
617   LWIP_MEMPOOL_INIT(PPPOS_PCB);
618 #endif
619 #if PPPOE_SUPPORT
620   LWIP_MEMPOOL_INIT(PPPOE_IF);
621 #endif
622 #if PPPOL2TP_SUPPORT
623   LWIP_MEMPOOL_INIT(PPPOL2TP_PCB);
624 #endif
625 #if LWIP_PPP_API && LWIP_MPU_COMPATIBLE
626   LWIP_MEMPOOL_INIT(PPPAPI_MSG);
627 #endif
628 
629   LWIP_MEMPOOL_INIT(PPP_PCB);
630 
631   /*
632    * Initialize magic number generator now so that protocols may
633    * use magic numbers in initialization.
634    */
635   magic_init();
636 
637   return 0;
638 }
639 
640 /*
641  * Create a new PPP control block.
642  *
643  * This initializes the PPP control block but does not
644  * attempt to negotiate the LCP session.
645  *
646  * Return a new PPP connection control block pointer
647  * on success or a null pointer on failure.
648  */
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)649 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) {
650   ppp_pcb *pcb;
651   const struct protent *protp;
652   int i;
653 
654   /* PPP is single-threaded: without a callback,
655    * there is no way to know when the link is up. */
656   if (link_status_cb == NULL) {
657     return NULL;
658   }
659 
660   pcb = (ppp_pcb*)LWIP_MEMPOOL_ALLOC(PPP_PCB);
661   if (pcb == NULL) {
662     return NULL;
663   }
664 
665   memset(pcb, 0, sizeof(ppp_pcb));
666 
667   /* default configuration */
668 #if PAP_SUPPORT
669   pcb->settings.pap_timeout_time = UPAP_DEFTIMEOUT;
670   pcb->settings.pap_max_transmits = UPAP_DEFTRANSMITS;
671 #if PPP_SERVER
672   pcb->settings.pap_req_timeout = UPAP_DEFREQTIME;
673 #endif /* PPP_SERVER */
674 #endif /* PAP_SUPPORT */
675 
676 #if CHAP_SUPPORT
677   pcb->settings.chap_timeout_time = CHAP_DEFTIMEOUT;
678   pcb->settings.chap_max_transmits = CHAP_DEFTRANSMITS;
679 #if PPP_SERVER
680   pcb->settings.chap_rechallenge_time = CHAP_DEFRECHALLENGETIME;
681 #endif /* PPP_SERVER */
682 #endif /* CHAP_SUPPPORT */
683 
684 #if EAP_SUPPORT
685   pcb->settings.eap_req_time = EAP_DEFREQTIME;
686   pcb->settings.eap_allow_req = EAP_DEFALLOWREQ;
687 #if PPP_SERVER
688   pcb->settings.eap_timeout_time = EAP_DEFTIMEOUT;
689   pcb->settings.eap_max_transmits = EAP_DEFTRANSMITS;
690 #endif /* PPP_SERVER */
691 #endif /* EAP_SUPPORT */
692 
693   pcb->settings.lcp_loopbackfail = LCP_DEFLOOPBACKFAIL;
694   pcb->settings.lcp_echo_interval = LCP_ECHOINTERVAL;
695   pcb->settings.lcp_echo_fails = LCP_MAXECHOFAILS;
696 
697   pcb->settings.fsm_timeout_time = FSM_DEFTIMEOUT;
698   pcb->settings.fsm_max_conf_req_transmits = FSM_DEFMAXCONFREQS;
699   pcb->settings.fsm_max_term_transmits = FSM_DEFMAXTERMREQS;
700   pcb->settings.fsm_max_nak_loops = FSM_DEFMAXNAKLOOPS;
701 
702   pcb->netif = pppif;
703   MIB2_INIT_NETIF(pppif, snmp_ifType_ppp, 0);
704   if (!netif_add(pcb->netif,
705 #if LWIP_IPV4
706                  IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4,
707 #endif /* LWIP_IPV4 */
708                  (void *)pcb, ppp_netif_init_cb, NULL)) {
709     LWIP_MEMPOOL_FREE(PPP_PCB, pcb);
710     PPPDEBUG(LOG_ERR, ("ppp_new: netif_add failed\n"));
711     return NULL;
712   }
713 
714   pcb->link_cb = callbacks;
715   pcb->link_ctx_cb = link_ctx_cb;
716   pcb->link_status_cb = link_status_cb;
717   pcb->ctx_cb = ctx_cb;
718 
719   /*
720    * Initialize each protocol.
721    */
722   for (i = 0; (protp = protocols[i]) != NULL; ++i) {
723       (*protp->init)(pcb);
724   }
725 
726   new_phase(pcb, PPP_PHASE_DEAD);
727   return pcb;
728 }
729 
730 /** Initiate LCP open request */
ppp_start(ppp_pcb * pcb)731 void ppp_start(ppp_pcb *pcb) {
732   PPPDEBUG(LOG_DEBUG, ("ppp_start[%d]\n", pcb->netif->num));
733 
734   /* Clean data not taken care by anything else, mostly shared data. */
735 #if PPP_STATS_SUPPORT
736   link_stats_valid = 0;
737 #endif /* PPP_STATS_SUPPORT */
738 #if MPPE_SUPPORT
739   pcb->mppe_keys_set = 0;
740   memset(&pcb->mppe_comp, 0, sizeof(pcb->mppe_comp));
741   memset(&pcb->mppe_decomp, 0, sizeof(pcb->mppe_decomp));
742 #endif /* MPPE_SUPPORT */
743 #if VJ_SUPPORT
744   vj_compress_init(&pcb->vj_comp);
745 #endif /* VJ_SUPPORT */
746 
747   /* Start protocol */
748   new_phase(pcb, PPP_PHASE_ESTABLISH);
749   lcp_open(pcb);
750   lcp_lowerup(pcb);
751   PPPDEBUG(LOG_DEBUG, ("ppp_start[%d]: finished\n", pcb->netif->num));
752 }
753 
754 /** Called when link failed to setup */
ppp_link_failed(ppp_pcb * pcb)755 void ppp_link_failed(ppp_pcb *pcb) {
756   PPPDEBUG(LOG_DEBUG, ("ppp_link_failed[%d]\n", pcb->netif->num));
757   new_phase(pcb, PPP_PHASE_DEAD);
758   pcb->err_code = PPPERR_OPEN;
759   pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
760 }
761 
762 /** Called when link is normally down (i.e. it was asked to end) */
ppp_link_end(ppp_pcb * pcb)763 void ppp_link_end(ppp_pcb *pcb) {
764   PPPDEBUG(LOG_DEBUG, ("ppp_link_end[%d]\n", pcb->netif->num));
765   new_phase(pcb, PPP_PHASE_DEAD);
766   if (pcb->err_code == PPPERR_NONE) {
767     pcb->err_code = PPPERR_CONNECT;
768   }
769   pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
770 }
771 
772 /*
773  * Pass the processed input packet to the appropriate handler.
774  * This function and all handlers run in the context of the tcpip_thread
775  */
ppp_input(ppp_pcb * pcb,struct pbuf * pb)776 void ppp_input(ppp_pcb *pcb, struct pbuf *pb) {
777   u16_t protocol;
778 #if PPP_DEBUG && PPP_PROTOCOLNAME
779     const char *pname;
780 #endif /* PPP_DEBUG && PPP_PROTOCOLNAME */
781 
782   magic_randomize();
783 
784   if (pb->len < 2) {
785     PPPDEBUG(LOG_ERR, ("ppp_input[%d]: packet too short\n", pcb->netif->num));
786     goto drop;
787   }
788   protocol = (((u8_t *)pb->payload)[0] << 8) | ((u8_t*)pb->payload)[1];
789 
790 #if PRINTPKT_SUPPORT
791   ppp_dump_packet(pcb, "rcvd", (unsigned char *)pb->payload, pb->len);
792 #endif /* PRINTPKT_SUPPORT */
793 
794   pbuf_remove_header(pb, sizeof(protocol));
795 
796   LINK_STATS_INC(link.recv);
797   MIB2_STATS_NETIF_INC(pcb->netif, ifinucastpkts);
798   MIB2_STATS_NETIF_ADD(pcb->netif, ifinoctets, pb->tot_len);
799 
800   /*
801    * Toss all non-LCP packets unless LCP is OPEN.
802    */
803   if (protocol != PPP_LCP && pcb->lcp_fsm.state != PPP_FSM_OPENED) {
804     ppp_dbglog("Discarded non-LCP packet when LCP not open");
805     goto drop;
806   }
807 
808   /*
809    * Until we get past the authentication phase, toss all packets
810    * except LCP, LQR and authentication packets.
811    */
812   if (pcb->phase <= PPP_PHASE_AUTHENTICATE
813    && !(protocol == PPP_LCP
814 #if LQR_SUPPORT
815    || protocol == PPP_LQR
816 #endif /* LQR_SUPPORT */
817 #if PAP_SUPPORT
818    || protocol == PPP_PAP
819 #endif /* PAP_SUPPORT */
820 #if CHAP_SUPPORT
821    || protocol == PPP_CHAP
822 #endif /* CHAP_SUPPORT */
823 #if EAP_SUPPORT
824    || protocol == PPP_EAP
825 #endif /* EAP_SUPPORT */
826    )) {
827     ppp_dbglog("discarding proto 0x%x in phase %d", protocol, pcb->phase);
828     goto drop;
829   }
830 
831 #if CCP_SUPPORT
832 #if MPPE_SUPPORT
833   /*
834    * MPPE is required and unencrypted data has arrived (this
835    * should never happen!). We should probably drop the link if
836    * the protocol is in the range of what should be encrypted.
837    * At the least, we drop this packet.
838    */
839   if (pcb->settings.require_mppe && protocol != PPP_COMP && protocol < 0x8000) {
840     PPPDEBUG(LOG_ERR, ("ppp_input[%d]: MPPE required, received unencrypted data!\n", pcb->netif->num));
841     goto drop;
842   }
843 #endif /* MPPE_SUPPORT */
844 
845   if (protocol == PPP_COMP) {
846     u8_t *pl;
847 
848     switch (pcb->ccp_receive_method) {
849 #if MPPE_SUPPORT
850     case CI_MPPE:
851       if (mppe_decompress(pcb, &pcb->mppe_decomp, &pb) != ERR_OK) {
852         goto drop;
853       }
854       break;
855 #endif /* MPPE_SUPPORT */
856     default:
857       PPPDEBUG(LOG_ERR, ("ppp_input[%d]: bad CCP receive method\n", pcb->netif->num));
858       goto drop; /* Cannot really happen, we only negotiate what we are able to do */
859     }
860 
861     /* Assume no PFC */
862     if (pb->len < 2) {
863       goto drop;
864     }
865 
866     /* Extract and hide protocol (do PFC decompression if necessary) */
867     pl = (u8_t*)pb->payload;
868     if (pl[0] & 0x01) {
869       protocol = pl[0];
870       pbuf_remove_header(pb, 1);
871     } else {
872       protocol = (pl[0] << 8) | pl[1];
873       pbuf_remove_header(pb, 2);
874     }
875   }
876 #endif /* CCP_SUPPORT */
877 
878   switch(protocol) {
879 
880 #if PPP_IPV4_SUPPORT
881     case PPP_IP:            /* Internet Protocol */
882       PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip in pbuf len=%d\n", pcb->netif->num, pb->tot_len));
883       ip4_input(pb, pcb->netif);
884       return;
885 #endif /* PPP_IPV4_SUPPORT */
886 
887 #if PPP_IPV6_SUPPORT
888     case PPP_IPV6:          /* Internet Protocol Version 6 */
889       PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip6 in pbuf len=%d\n", pcb->netif->num, pb->tot_len));
890       ip6_input(pb, pcb->netif);
891       return;
892 #endif /* PPP_IPV6_SUPPORT */
893 
894 #if VJ_SUPPORT
895     case PPP_VJC_COMP:      /* VJ compressed TCP */
896       /*
897        * Clip off the VJ header and prepend the rebuilt TCP/IP header and
898        * pass the result to IP.
899        */
900       PPPDEBUG(LOG_INFO, ("ppp_input[%d]: vj_comp in pbuf len=%d\n", pcb->netif->num, pb->tot_len));
901       if (pcb->vj_enabled && vj_uncompress_tcp(&pb, &pcb->vj_comp) >= 0) {
902         ip4_input(pb, pcb->netif);
903         return;
904       }
905       /* Something's wrong so drop it. */
906       PPPDEBUG(LOG_WARNING, ("ppp_input[%d]: Dropping VJ compressed\n", pcb->netif->num));
907       break;
908 
909     case PPP_VJC_UNCOMP:    /* VJ uncompressed TCP */
910       /*
911        * Process the TCP/IP header for VJ header compression and then pass
912        * the packet to IP.
913        */
914       PPPDEBUG(LOG_INFO, ("ppp_input[%d]: vj_un in pbuf len=%d\n", pcb->netif->num, pb->tot_len));
915       if (pcb->vj_enabled && vj_uncompress_uncomp(pb, &pcb->vj_comp) >= 0) {
916         ip4_input(pb, pcb->netif);
917         return;
918       }
919       /* Something's wrong so drop it. */
920       PPPDEBUG(LOG_WARNING, ("ppp_input[%d]: Dropping VJ uncompressed\n", pcb->netif->num));
921       break;
922 #endif /* VJ_SUPPORT */
923 
924     default: {
925       int i;
926       const struct protent *protp;
927 
928       /*
929        * Upcall the proper protocol input routine.
930        */
931       for (i = 0; (protp = protocols[i]) != NULL; ++i) {
932         if (protp->protocol == protocol) {
933           pb = pbuf_coalesce(pb, PBUF_RAW);
934           (*protp->input)(pcb, (u8_t*)pb->payload, pb->len);
935           goto out;
936         }
937 #if 0   /* UNUSED
938          *
939          * This is actually a (hacked?) way for the Linux kernel to pass a data
940          * packet to pppd. pppd in normal condition only do signaling
941          * (LCP, PAP, CHAP, IPCP, ...) and does not handle any data packet at all.
942          *
943          * We don't even need this interface, which is only there because of PPP
944          * interface limitation between Linux kernel and pppd. For MPPE, which uses
945          * CCP to negotiate although it is not really a (de)compressor, we added
946          * ccp_resetrequest() in CCP and MPPE input data flow is calling either
947          * ccp_resetrequest() or lcp_close() if the issue is, respectively, non-fatal
948          * or fatal, this is what ccp_datainput() really do.
949          */
950         if (protocol == (protp->protocol & ~0x8000)
951           && protp->datainput != NULL) {
952           (*protp->datainput)(pcb, pb->payload, pb->len);
953           goto out;
954         }
955 #endif /* UNUSED */
956       }
957 
958 #if PPP_DEBUG
959 #if PPP_PROTOCOLNAME
960       pname = protocol_name(protocol);
961       if (pname != NULL) {
962         ppp_warn("Unsupported protocol '%s' (0x%x) received", pname, protocol);
963       } else
964 #endif /* PPP_PROTOCOLNAME */
965         ppp_warn("Unsupported protocol 0x%x received", protocol);
966 #endif /* PPP_DEBUG */
967         if (pbuf_add_header(pb, sizeof(protocol))) {
968           PPPDEBUG(LOG_WARNING, ("ppp_input[%d]: Dropping (pbuf_add_header failed)\n", pcb->netif->num));
969           goto drop;
970         }
971         lcp_sprotrej(pcb, (u8_t*)pb->payload, pb->len);
972       }
973       break;
974   }
975 
976 drop:
977   LINK_STATS_INC(link.drop);
978   MIB2_STATS_NETIF_INC(pcb->netif, ifindiscards);
979 
980 out:
981   pbuf_free(pb);
982 }
983 
984 /*
985  * Write a pbuf to a ppp link, only used from PPP functions
986  * to send PPP packets.
987  *
988  * IPv4 and IPv6 packets from lwIP are sent, respectively,
989  * with ppp_netif_output_ip4() and ppp_netif_output_ip6()
990  * functions (which are callbacks of the netif PPP interface).
991  */
ppp_write(ppp_pcb * pcb,struct pbuf * p)992 err_t ppp_write(ppp_pcb *pcb, struct pbuf *p) {
993 #if PRINTPKT_SUPPORT
994   ppp_dump_packet(pcb, "sent", (unsigned char *)p->payload+2, p->len-2);
995 #endif /* PRINTPKT_SUPPORT */
996   return pcb->link_cb->write(pcb, pcb->link_ctx_cb, p);
997 }
998 
ppp_link_terminated(ppp_pcb * pcb)999 void ppp_link_terminated(ppp_pcb *pcb) {
1000   PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated[%d]\n", pcb->netif->num));
1001   pcb->link_cb->disconnect(pcb, pcb->link_ctx_cb);
1002   PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated[%d]: finished.\n", pcb->netif->num));
1003 }
1004 
1005 
1006 /************************************************************************
1007  * Functions called by various PPP subsystems to configure
1008  * the PPP interface or change the PPP phase.
1009  */
1010 
1011 /*
1012  * new_phase - signal the start of a new phase of pppd's operation.
1013  */
new_phase(ppp_pcb * pcb,int p)1014 void new_phase(ppp_pcb *pcb, int p) {
1015   pcb->phase = p;
1016   PPPDEBUG(LOG_DEBUG, ("ppp phase changed[%d]: phase=%d\n", pcb->netif->num, pcb->phase));
1017 #if PPP_NOTIFY_PHASE
1018   if (pcb->notify_phase_cb != NULL) {
1019     pcb->notify_phase_cb(pcb, p, pcb->ctx_cb);
1020   }
1021 #endif /* PPP_NOTIFY_PHASE */
1022 }
1023 
1024 /*
1025  * ppp_send_config - configure the transmit-side characteristics of
1026  * the ppp interface.
1027  */
ppp_send_config(ppp_pcb * pcb,int mtu,u32_t accm,int pcomp,int accomp)1028 int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp) {
1029   LWIP_UNUSED_ARG(mtu);
1030   /* pcb->mtu = mtu; -- set correctly with netif_set_mtu */
1031 
1032   if (pcb->link_cb->send_config) {
1033     pcb->link_cb->send_config(pcb, pcb->link_ctx_cb, accm, pcomp, accomp);
1034   }
1035 
1036   PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]\n", pcb->netif->num) );
1037   return 0;
1038 }
1039 
1040 /*
1041  * ppp_recv_config - configure the receive-side characteristics of
1042  * the ppp interface.
1043  */
ppp_recv_config(ppp_pcb * pcb,int mru,u32_t accm,int pcomp,int accomp)1044 int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp) {
1045   LWIP_UNUSED_ARG(mru);
1046 
1047   if (pcb->link_cb->recv_config) {
1048     pcb->link_cb->recv_config(pcb, pcb->link_ctx_cb, accm, pcomp, accomp);
1049   }
1050 
1051   PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]\n", pcb->netif->num));
1052   return 0;
1053 }
1054 
1055 #if PPP_IPV4_SUPPORT
1056 /*
1057  * sifaddr - Config the interface IP addresses and netmask.
1058  */
sifaddr(ppp_pcb * pcb,u32_t our_adr,u32_t his_adr,u32_t netmask)1059 int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask) {
1060   ip4_addr_t ip, nm, gw;
1061 
1062   ip4_addr_set_u32(&ip, our_adr);
1063   ip4_addr_set_u32(&nm, netmask);
1064   ip4_addr_set_u32(&gw, his_adr);
1065   netif_set_addr(pcb->netif, &ip, &nm, &gw);
1066   return 1;
1067 }
1068 
1069 /********************************************************************
1070  *
1071  * cifaddr - Clear the interface IP addresses, and delete routes
1072  * through the interface if possible.
1073  */
cifaddr(ppp_pcb * pcb,u32_t our_adr,u32_t his_adr)1074 int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr) {
1075   LWIP_UNUSED_ARG(our_adr);
1076   LWIP_UNUSED_ARG(his_adr);
1077 
1078   netif_set_addr(pcb->netif, IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4);
1079   return 1;
1080 }
1081 
1082 #if 0 /* UNUSED - PROXY ARP */
1083 /********************************************************************
1084  *
1085  * sifproxyarp - Make a proxy ARP entry for the peer.
1086  */
1087 
1088 int sifproxyarp(ppp_pcb *pcb, u32_t his_adr) {
1089   LWIP_UNUSED_ARG(pcb);
1090   LWIP_UNUSED_ARG(his_adr);
1091   return 0;
1092 }
1093 
1094 /********************************************************************
1095  *
1096  * cifproxyarp - Delete the proxy ARP entry for the peer.
1097  */
1098 
1099 int cifproxyarp(ppp_pcb *pcb, u32_t his_adr) {
1100   LWIP_UNUSED_ARG(pcb);
1101   LWIP_UNUSED_ARG(his_adr);
1102   return 0;
1103 }
1104 #endif /* UNUSED - PROXY ARP */
1105 
1106 #if LWIP_DNS
1107 /*
1108  * sdns - Config the DNS servers
1109  */
sdns(ppp_pcb * pcb,u32_t ns1,u32_t ns2)1110 int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) {
1111   ip_addr_t ns;
1112   LWIP_UNUSED_ARG(pcb);
1113 
1114   ip_addr_set_ip4_u32_val(ns, ns1);
1115   dns_setserver(0, &ns);
1116   ip_addr_set_ip4_u32_val(ns, ns2);
1117   dns_setserver(1, &ns);
1118   return 1;
1119 }
1120 
1121 /********************************************************************
1122  *
1123  * cdns - Clear the DNS servers
1124  */
cdns(ppp_pcb * pcb,u32_t ns1,u32_t ns2)1125 int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) {
1126   const ip_addr_t *nsa;
1127   ip_addr_t nsb;
1128   LWIP_UNUSED_ARG(pcb);
1129 
1130   nsa = dns_getserver(0);
1131   ip_addr_set_ip4_u32_val(nsb, ns1);
1132   if (ip_addr_cmp(nsa, &nsb)) {
1133     dns_setserver(0, IP_ADDR_ANY);
1134   }
1135   nsa = dns_getserver(1);
1136   ip_addr_set_ip4_u32_val(nsb, ns2);
1137   if (ip_addr_cmp(nsa, &nsb)) {
1138     dns_setserver(1, IP_ADDR_ANY);
1139   }
1140   return 1;
1141 }
1142 #endif /* LWIP_DNS */
1143 
1144 #if VJ_SUPPORT
1145 /********************************************************************
1146  *
1147  * sifvjcomp - config tcp header compression
1148  */
sifvjcomp(ppp_pcb * pcb,int vjcomp,int cidcomp,int maxcid)1149 int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid) {
1150   pcb->vj_enabled = vjcomp;
1151   pcb->vj_comp.compressSlot = cidcomp;
1152   pcb->vj_comp.maxSlotIndex = maxcid;
1153   PPPDEBUG(LOG_INFO, ("sifvjcomp[%d]: VJ compress enable=%d slot=%d max slot=%d\n",
1154             pcb->netif->num, vjcomp, cidcomp, maxcid));
1155   return 0;
1156 }
1157 #endif /* VJ_SUPPORT */
1158 
1159 /*
1160  * sifup - Config the interface up and enable IP packets to pass.
1161  */
sifup(ppp_pcb * pcb)1162 int sifup(ppp_pcb *pcb) {
1163   pcb->if4_up = 1;
1164   pcb->err_code = PPPERR_NONE;
1165   netif_set_link_up(pcb->netif);
1166 
1167   PPPDEBUG(LOG_DEBUG, ("sifup[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code));
1168   pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
1169   return 1;
1170 }
1171 
1172 /********************************************************************
1173  *
1174  * sifdown - Disable the indicated protocol and config the interface
1175  *           down if there are no remaining protocols.
1176  */
sifdown(ppp_pcb * pcb)1177 int sifdown(ppp_pcb *pcb) {
1178 
1179   pcb->if4_up = 0;
1180 
1181   if (1
1182 #if PPP_IPV6_SUPPORT
1183    /* set the interface down if IPv6 is down as well */
1184    && !pcb->if6_up
1185 #endif /* PPP_IPV6_SUPPORT */
1186   ) {
1187     /* make sure the netif link callback is called */
1188     netif_set_link_down(pcb->netif);
1189   }
1190   PPPDEBUG(LOG_DEBUG, ("sifdown[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code));
1191   return 1;
1192 }
1193 
1194 /********************************************************************
1195  *
1196  * Return user specified netmask, modified by any mask we might determine
1197  * for address `addr' (in network byte order).
1198  * Here we scan through the system's list of interfaces, looking for
1199  * any non-point-to-point interfaces which might appear to be on the same
1200  * network as `addr'.  If we find any, we OR in their netmask to the
1201  * user-specified netmask.
1202  */
get_mask(u32_t addr)1203 u32_t get_mask(u32_t addr) {
1204 #if 0
1205   u32_t mask, nmask;
1206 
1207   addr = lwip_htonl(addr);
1208   if (IP_CLASSA(addr)) { /* determine network mask for address class */
1209     nmask = IP_CLASSA_NET;
1210   } else if (IP_CLASSB(addr)) {
1211     nmask = IP_CLASSB_NET;
1212   } else {
1213     nmask = IP_CLASSC_NET;
1214   }
1215 
1216   /* class D nets are disallowed by bad_ip_adrs */
1217   mask = PP_HTONL(0xffffff00UL) | lwip_htonl(nmask);
1218 
1219   /* XXX
1220    * Scan through the system's network interfaces.
1221    * Get each netmask and OR them into our mask.
1222    */
1223   /* return mask; */
1224   return mask;
1225 #endif /* 0 */
1226   LWIP_UNUSED_ARG(addr);
1227   return IPADDR_BROADCAST;
1228 }
1229 #endif /* PPP_IPV4_SUPPORT */
1230 
1231 #if PPP_IPV6_SUPPORT
1232 #define IN6_LLADDR_FROM_EUI64(ip6, eui64) do {    \
1233   ip6.addr[0] = PP_HTONL(0xfe800000);             \
1234   ip6.addr[1] = 0;                                \
1235   eui64_copy(eui64, ip6.addr[2]);                 \
1236   } while (0)
1237 
1238 /********************************************************************
1239  *
1240  * sif6addr - Config the interface with an IPv6 link-local address
1241  */
sif6addr(ppp_pcb * pcb,eui64_t our_eui64,eui64_t his_eui64)1242 int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64) {
1243   ip6_addr_t ip6;
1244   LWIP_UNUSED_ARG(his_eui64);
1245 
1246   IN6_LLADDR_FROM_EUI64(ip6, our_eui64);
1247   netif_ip6_addr_set(pcb->netif, 0, &ip6);
1248   netif_ip6_addr_set_state(pcb->netif, 0, IP6_ADDR_PREFERRED);
1249   /* FIXME: should we add an IPv6 static neighbor using his_eui64 ? */
1250   return 1;
1251 }
1252 
1253 /********************************************************************
1254  *
1255  * cif6addr - Remove IPv6 address from interface
1256  */
cif6addr(ppp_pcb * pcb,eui64_t our_eui64,eui64_t his_eui64)1257 int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64) {
1258   LWIP_UNUSED_ARG(our_eui64);
1259   LWIP_UNUSED_ARG(his_eui64);
1260 
1261   netif_ip6_addr_set_state(pcb->netif, 0, IP6_ADDR_INVALID);
1262   netif_ip6_addr_set(pcb->netif, 0, IP6_ADDR_ANY6);
1263   return 1;
1264 }
1265 
1266 /*
1267  * sif6up - Config the interface up and enable IPv6 packets to pass.
1268  */
sif6up(ppp_pcb * pcb)1269 int sif6up(ppp_pcb *pcb) {
1270 
1271   pcb->if6_up = 1;
1272   pcb->err_code = PPPERR_NONE;
1273   netif_set_link_up(pcb->netif);
1274 
1275   PPPDEBUG(LOG_DEBUG, ("sif6up[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code));
1276   pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
1277   return 1;
1278 }
1279 
1280 /********************************************************************
1281  *
1282  * sif6down - Disable the indicated protocol and config the interface
1283  *            down if there are no remaining protocols.
1284  */
sif6down(ppp_pcb * pcb)1285 int sif6down(ppp_pcb *pcb) {
1286 
1287   pcb->if6_up = 0;
1288 
1289   if (1
1290 #if PPP_IPV4_SUPPORT
1291    /* set the interface down if IPv4 is down as well */
1292    && !pcb->if4_up
1293 #endif /* PPP_IPV4_SUPPORT */
1294   ) {
1295     /* make sure the netif link callback is called */
1296     netif_set_link_down(pcb->netif);
1297   }
1298   PPPDEBUG(LOG_DEBUG, ("sif6down[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code));
1299   return 1;
1300 }
1301 #endif /* PPP_IPV6_SUPPORT */
1302 
1303 #if DEMAND_SUPPORT
1304 /*
1305  * sifnpmode - Set the mode for handling packets for a given NP.
1306  */
sifnpmode(ppp_pcb * pcb,int proto,enum NPmode mode)1307 int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode) {
1308   LWIP_UNUSED_ARG(pcb);
1309   LWIP_UNUSED_ARG(proto);
1310   LWIP_UNUSED_ARG(mode);
1311   return 0;
1312 }
1313 #endif /* DEMAND_SUPPORT */
1314 
1315 /*
1316  * netif_set_mtu - set the MTU on the PPP network interface.
1317  */
netif_set_mtu(ppp_pcb * pcb,int mtu)1318 void netif_set_mtu(ppp_pcb *pcb, int mtu) {
1319 
1320   pcb->netif->mtu = mtu;
1321   PPPDEBUG(LOG_INFO, ("netif_set_mtu[%d]: mtu=%d\n", pcb->netif->num, mtu));
1322 }
1323 
1324 /*
1325  * netif_get_mtu - get PPP interface MTU
1326  */
netif_get_mtu(ppp_pcb * pcb)1327 int netif_get_mtu(ppp_pcb *pcb) {
1328 
1329   return pcb->netif->mtu;
1330 }
1331 
1332 #if CCP_SUPPORT
1333 #if 0 /* unused */
1334 /*
1335  * ccp_test - whether a given compression method is acceptable for use.
1336  */
1337 int
1338 ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit)
1339 {
1340   LWIP_UNUSED_ARG(pcb);
1341   LWIP_UNUSED_ARG(opt_ptr);
1342   LWIP_UNUSED_ARG(opt_len);
1343   LWIP_UNUSED_ARG(for_transmit);
1344   return -1;
1345 }
1346 #endif /* unused */
1347 
1348 /*
1349  * ccp_set - inform about the current state of CCP.
1350  */
1351 void
ccp_set(ppp_pcb * pcb,u8_t isopen,u8_t isup,u8_t receive_method,u8_t transmit_method)1352 ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method)
1353 {
1354   LWIP_UNUSED_ARG(isopen);
1355   LWIP_UNUSED_ARG(isup);
1356   pcb->ccp_receive_method = receive_method;
1357   pcb->ccp_transmit_method = transmit_method;
1358   PPPDEBUG(LOG_DEBUG, ("ccp_set[%d]: is_open=%d, is_up=%d, receive_method=%u, transmit_method=%u\n",
1359            pcb->netif->num, isopen, isup, receive_method, transmit_method));
1360 }
1361 
1362 void
ccp_reset_comp(ppp_pcb * pcb)1363 ccp_reset_comp(ppp_pcb *pcb)
1364 {
1365   switch (pcb->ccp_transmit_method) {
1366 #if MPPE_SUPPORT
1367   case CI_MPPE:
1368     mppe_comp_reset(pcb, &pcb->mppe_comp);
1369     break;
1370 #endif /* MPPE_SUPPORT */
1371   default:
1372     break;
1373   }
1374 }
1375 
1376 void
ccp_reset_decomp(ppp_pcb * pcb)1377 ccp_reset_decomp(ppp_pcb *pcb)
1378 {
1379   switch (pcb->ccp_receive_method) {
1380 #if MPPE_SUPPORT
1381   case CI_MPPE:
1382     mppe_decomp_reset(pcb, &pcb->mppe_decomp);
1383     break;
1384 #endif /* MPPE_SUPPORT */
1385   default:
1386     break;
1387   }
1388 }
1389 
1390 #if 0 /* unused */
1391 /*
1392  * ccp_fatal_error - returns 1 if decompression was disabled as a
1393  * result of an error detected after decompression of a packet,
1394  * 0 otherwise.  This is necessary because of patent nonsense.
1395  */
1396 int
1397 ccp_fatal_error(ppp_pcb *pcb)
1398 {
1399   LWIP_UNUSED_ARG(pcb);
1400   return 1;
1401 }
1402 #endif /* unused */
1403 #endif /* CCP_SUPPORT */
1404 
1405 #if PPP_IDLETIMELIMIT
1406 /********************************************************************
1407  *
1408  * get_idle_time - return how long the link has been idle.
1409  */
get_idle_time(ppp_pcb * pcb,struct ppp_idle * ip)1410 int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip) {
1411   /* FIXME: add idle time support and make it optional */
1412   LWIP_UNUSED_ARG(pcb);
1413   LWIP_UNUSED_ARG(ip);
1414   return 1;
1415 }
1416 #endif /* PPP_IDLETIMELIMIT */
1417 
1418 #if DEMAND_SUPPORT
1419 /********************************************************************
1420  *
1421  * get_loop_output - get outgoing packets from the ppp device,
1422  * and detect when we want to bring the real link up.
1423  * Return value is 1 if we need to bring up the link, 0 otherwise.
1424  */
get_loop_output(void)1425 int get_loop_output(void) {
1426   return 0;
1427 }
1428 #endif /* DEMAND_SUPPORT */
1429 
1430 #if PPP_PROTOCOLNAME
1431 /* List of protocol names, to make our messages a little more informative. */
1432 struct protocol_list {
1433   u_short proto;
1434   const char *name;
1435 } const protocol_list[] = {
1436   { 0x21, "IP" },
1437   { 0x23, "OSI Network Layer" },
1438   { 0x25, "Xerox NS IDP" },
1439   { 0x27, "DECnet Phase IV" },
1440   { 0x29, "Appletalk" },
1441   { 0x2b, "Novell IPX" },
1442   { 0x2d, "VJ compressed TCP/IP" },
1443   { 0x2f, "VJ uncompressed TCP/IP" },
1444   { 0x31, "Bridging PDU" },
1445   { 0x33, "Stream Protocol ST-II" },
1446   { 0x35, "Banyan Vines" },
1447   { 0x39, "AppleTalk EDDP" },
1448   { 0x3b, "AppleTalk SmartBuffered" },
1449   { 0x3d, "Multi-Link" },
1450   { 0x3f, "NETBIOS Framing" },
1451   { 0x41, "Cisco Systems" },
1452   { 0x43, "Ascom Timeplex" },
1453   { 0x45, "Fujitsu Link Backup and Load Balancing (LBLB)" },
1454   { 0x47, "DCA Remote Lan" },
1455   { 0x49, "Serial Data Transport Protocol (PPP-SDTP)" },
1456   { 0x4b, "SNA over 802.2" },
1457   { 0x4d, "SNA" },
1458   { 0x4f, "IP6 Header Compression" },
1459   { 0x51, "KNX Bridging Data" },
1460   { 0x53, "Encryption" },
1461   { 0x55, "Individual Link Encryption" },
1462   { 0x57, "IPv6" },
1463   { 0x59, "PPP Muxing" },
1464   { 0x5b, "Vendor-Specific Network Protocol" },
1465   { 0x61, "RTP IPHC Full Header" },
1466   { 0x63, "RTP IPHC Compressed TCP" },
1467   { 0x65, "RTP IPHC Compressed non-TCP" },
1468   { 0x67, "RTP IPHC Compressed UDP 8" },
1469   { 0x69, "RTP IPHC Compressed RTP 8" },
1470   { 0x6f, "Stampede Bridging" },
1471   { 0x73, "MP+" },
1472   { 0xc1, "NTCITS IPI" },
1473   { 0xfb, "single-link compression" },
1474   { 0xfd, "Compressed Datagram" },
1475   { 0x0201, "802.1d Hello Packets" },
1476   { 0x0203, "IBM Source Routing BPDU" },
1477   { 0x0205, "DEC LANBridge100 Spanning Tree" },
1478   { 0x0207, "Cisco Discovery Protocol" },
1479   { 0x0209, "Netcs Twin Routing" },
1480   { 0x020b, "STP - Scheduled Transfer Protocol" },
1481   { 0x020d, "EDP - Extreme Discovery Protocol" },
1482   { 0x0211, "Optical Supervisory Channel Protocol" },
1483   { 0x0213, "Optical Supervisory Channel Protocol" },
1484   { 0x0231, "Luxcom" },
1485   { 0x0233, "Sigma Network Systems" },
1486   { 0x0235, "Apple Client Server Protocol" },
1487   { 0x0281, "MPLS Unicast" },
1488   { 0x0283, "MPLS Multicast" },
1489   { 0x0285, "IEEE p1284.4 standard - data packets" },
1490   { 0x0287, "ETSI TETRA Network Protocol Type 1" },
1491   { 0x0289, "Multichannel Flow Treatment Protocol" },
1492   { 0x2063, "RTP IPHC Compressed TCP No Delta" },
1493   { 0x2065, "RTP IPHC Context State" },
1494   { 0x2067, "RTP IPHC Compressed UDP 16" },
1495   { 0x2069, "RTP IPHC Compressed RTP 16" },
1496   { 0x4001, "Cray Communications Control Protocol" },
1497   { 0x4003, "CDPD Mobile Network Registration Protocol" },
1498   { 0x4005, "Expand accelerator protocol" },
1499   { 0x4007, "ODSICP NCP" },
1500   { 0x4009, "DOCSIS DLL" },
1501   { 0x400B, "Cetacean Network Detection Protocol" },
1502   { 0x4021, "Stacker LZS" },
1503   { 0x4023, "RefTek Protocol" },
1504   { 0x4025, "Fibre Channel" },
1505   { 0x4027, "EMIT Protocols" },
1506   { 0x405b, "Vendor-Specific Protocol (VSP)" },
1507   { 0x8021, "Internet Protocol Control Protocol" },
1508   { 0x8023, "OSI Network Layer Control Protocol" },
1509   { 0x8025, "Xerox NS IDP Control Protocol" },
1510   { 0x8027, "DECnet Phase IV Control Protocol" },
1511   { 0x8029, "Appletalk Control Protocol" },
1512   { 0x802b, "Novell IPX Control Protocol" },
1513   { 0x8031, "Bridging NCP" },
1514   { 0x8033, "Stream Protocol Control Protocol" },
1515   { 0x8035, "Banyan Vines Control Protocol" },
1516   { 0x803d, "Multi-Link Control Protocol" },
1517   { 0x803f, "NETBIOS Framing Control Protocol" },
1518   { 0x8041, "Cisco Systems Control Protocol" },
1519   { 0x8043, "Ascom Timeplex" },
1520   { 0x8045, "Fujitsu LBLB Control Protocol" },
1521   { 0x8047, "DCA Remote Lan Network Control Protocol (RLNCP)" },
1522   { 0x8049, "Serial Data Control Protocol (PPP-SDCP)" },
1523   { 0x804b, "SNA over 802.2 Control Protocol" },
1524   { 0x804d, "SNA Control Protocol" },
1525   { 0x804f, "IP6 Header Compression Control Protocol" },
1526   { 0x8051, "KNX Bridging Control Protocol" },
1527   { 0x8053, "Encryption Control Protocol" },
1528   { 0x8055, "Individual Link Encryption Control Protocol" },
1529   { 0x8057, "IPv6 Control Protocol" },
1530   { 0x8059, "PPP Muxing Control Protocol" },
1531   { 0x805b, "Vendor-Specific Network Control Protocol (VSNCP)" },
1532   { 0x806f, "Stampede Bridging Control Protocol" },
1533   { 0x8073, "MP+ Control Protocol" },
1534   { 0x80c1, "NTCITS IPI Control Protocol" },
1535   { 0x80fb, "Single Link Compression Control Protocol" },
1536   { 0x80fd, "Compression Control Protocol" },
1537   { 0x8207, "Cisco Discovery Protocol Control" },
1538   { 0x8209, "Netcs Twin Routing" },
1539   { 0x820b, "STP - Control Protocol" },
1540   { 0x820d, "EDPCP - Extreme Discovery Protocol Ctrl Prtcl" },
1541   { 0x8235, "Apple Client Server Protocol Control" },
1542   { 0x8281, "MPLSCP" },
1543   { 0x8285, "IEEE p1284.4 standard - Protocol Control" },
1544   { 0x8287, "ETSI TETRA TNP1 Control Protocol" },
1545   { 0x8289, "Multichannel Flow Treatment Protocol" },
1546   { 0xc021, "Link Control Protocol" },
1547   { 0xc023, "Password Authentication Protocol" },
1548   { 0xc025, "Link Quality Report" },
1549   { 0xc027, "Shiva Password Authentication Protocol" },
1550   { 0xc029, "CallBack Control Protocol (CBCP)" },
1551   { 0xc02b, "BACP Bandwidth Allocation Control Protocol" },
1552   { 0xc02d, "BAP" },
1553   { 0xc05b, "Vendor-Specific Authentication Protocol (VSAP)" },
1554   { 0xc081, "Container Control Protocol" },
1555   { 0xc223, "Challenge Handshake Authentication Protocol" },
1556   { 0xc225, "RSA Authentication Protocol" },
1557   { 0xc227, "Extensible Authentication Protocol" },
1558   { 0xc229, "Mitsubishi Security Info Exch Ptcl (SIEP)" },
1559   { 0xc26f, "Stampede Bridging Authorization Protocol" },
1560   { 0xc281, "Proprietary Authentication Protocol" },
1561   { 0xc283, "Proprietary Authentication Protocol" },
1562   { 0xc481, "Proprietary Node ID Authentication Protocol" },
1563   { 0, NULL },
1564 };
1565 
1566 /*
1567  * protocol_name - find a name for a PPP protocol.
1568  */
protocol_name(int proto)1569 const char * protocol_name(int proto) {
1570   const struct protocol_list *lp;
1571 
1572   for (lp = protocol_list; lp->proto != 0; ++lp) {
1573     if (proto == lp->proto) {
1574       return lp->name;
1575     }
1576   }
1577   return NULL;
1578 }
1579 #endif /* PPP_PROTOCOLNAME */
1580 
1581 #if PPP_STATS_SUPPORT
1582 
1583 /* ---- Note on PPP Stats support ----
1584  *
1585  * The one willing link stats support should add the get_ppp_stats()
1586  * to fetch statistics from lwIP.
1587  */
1588 
1589 /*
1590  * reset_link_stats - "reset" stats when link goes up.
1591  */
reset_link_stats(int u)1592 void reset_link_stats(int u) {
1593   if (!get_ppp_stats(u, &old_link_stats)) {
1594     return;
1595   }
1596   gettimeofday(&start_time, NULL);
1597 }
1598 
1599 /*
1600  * update_link_stats - get stats at link termination.
1601  */
update_link_stats(int u)1602 void update_link_stats(int u) {
1603   struct timeval now;
1604   char numbuf[32];
1605 
1606   if (!get_ppp_stats(u, &link_stats) || gettimeofday(&now, NULL) < 0) {
1607     return;
1608   }
1609   link_connect_time = now.tv_sec - start_time.tv_sec;
1610   link_stats_valid = 1;
1611 
1612   link_stats.bytes_in  -= old_link_stats.bytes_in;
1613   link_stats.bytes_out -= old_link_stats.bytes_out;
1614   link_stats.pkts_in   -= old_link_stats.pkts_in;
1615   link_stats.pkts_out  -= old_link_stats.pkts_out;
1616 }
1617 
print_link_stats()1618 void print_link_stats() {
1619   /*
1620    * Print connect time and statistics.
1621    */
1622   if (link_stats_valid) {
1623     int t = (link_connect_time + 5) / 6;    /* 1/10ths of minutes */
1624     info("Connect time %d.%d minutes.", t/10, t%10);
1625     info("Sent %u bytes, received %u bytes.", link_stats.bytes_out, link_stats.bytes_in);
1626     link_stats_valid = 0;
1627   }
1628 }
1629 #endif /* PPP_STATS_SUPPORT */
1630 
1631 #endif /* PPP_SUPPORT */
1632