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