From 44b527415f48400c679bf4a9a9e14563a5c4f601 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Mon, 22 Apr 2013 23:58:51 +0200 Subject: [PATCH] PPP, slight API change, great code factorisation Created new ppp_over_X_create() functions which only prepare the PPP session without starting it Removed ppp_reopen() and all of its sub ppp_over_X_reopen() Removed PPPoL2TP reconnect() function, merged to connect() Added ppp_open() able to start or restart any session --- src/api/pppapi.c | 94 +++++++++++++-------------- src/include/lwip/pppapi.h | 16 ++--- src/include/netif/ppp/ppp.h | 16 ++--- src/include/netif/ppp/pppol2tp.h | 10 ++- src/netif/ppp/ppp.c | 108 +++++++------------------------ src/netif/ppp/pppol2tp.c | 41 +++--------- 6 files changed, 98 insertions(+), 187 deletions(-) diff --git a/src/api/pppapi.c b/src/api/pppapi.c index 274b5ed5..e4e198a9 100644 --- a/src/api/pppapi.c +++ b/src/api/pppapi.c @@ -104,25 +104,25 @@ void pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd) { #if PPPOS_SUPPORT /** - * Call ppp_over_serial_open() inside the tcpip_thread context. + * Call ppp_over_serial_create() inside the tcpip_thread context. */ -static void pppapi_do_ppp_over_serial_open(struct pppapi_msg_msg *msg) { - msg->err = ppp_over_serial_open(msg->ppp, msg->msg.serialopen.fd, - msg->msg.serialopen.link_status_cb, msg->msg.serialopen.link_status_ctx); +static void pppapi_do_ppp_over_serial_create(struct pppapi_msg_msg *msg) { + msg->err = ppp_over_serial_create(msg->ppp, msg->msg.serialcreate.fd, + msg->msg.serialcreate.link_status_cb, msg->msg.serialcreate.link_status_ctx); TCPIP_PPPAPI_ACK(msg); } /** - * Call ppp_over_serial_open() in a thread-safe way by running that function inside the + * Call ppp_over_serial_create() in a thread-safe way by running that function inside the * tcpip_thread context. */ -int pppapi_over_serial_open(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { +int pppapi_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { struct pppapi_msg msg; - msg.function = pppapi_do_ppp_over_serial_open; + msg.function = pppapi_do_ppp_over_serial_create; msg.msg.ppp = pcb; - msg.msg.msg.serialopen.fd = fd; - msg.msg.msg.serialopen.link_status_cb = link_status_cb; - msg.msg.msg.serialopen.link_status_ctx = link_status_ctx; + msg.msg.msg.serialcreate.fd = fd; + msg.msg.msg.serialcreate.link_status_cb = link_status_cb; + msg.msg.msg.serialcreate.link_status_ctx = link_status_ctx; TCPIP_PPPAPI(&msg); return msg.msg.err; } @@ -131,31 +131,31 @@ int pppapi_over_serial_open(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn lin #if PPPOE_SUPPORT /** - * Call ppp_over_ethernet_open() inside the tcpip_thread context. + * Call ppp_over_ethernet_create() inside the tcpip_thread context. */ -static void pppapi_do_ppp_over_ethernet_open(struct pppapi_msg_msg *msg) { +static void pppapi_do_ppp_over_ethernet_create(struct pppapi_msg_msg *msg) { - msg->err = ppp_over_ethernet_open(msg->ppp, msg->msg.ethernetopen.ethif, - msg->msg.ethernetopen.service_name, msg->msg.ethernetopen.concentrator_name, - msg->msg.ethernetopen.link_status_cb, msg->msg.ethernetopen.link_status_ctx); + msg->err = ppp_over_ethernet_create(msg->ppp, msg->msg.ethernetcreate.ethif, + msg->msg.ethernetcreate.service_name, msg->msg.ethernetcreate.concentrator_name, + msg->msg.ethernetcreate.link_status_cb, msg->msg.ethernetcreate.link_status_ctx); TCPIP_PPPAPI_ACK(msg); } /** - * Call ppp_over_ethernet_open() in a thread-safe way by running that function inside the + * Call ppp_over_ethernet_create() in a thread-safe way by running that function inside the * tcpip_thread context. */ -int pppapi_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *service_name, +int pppapi_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { struct pppapi_msg msg; - msg.function = pppapi_do_ppp_over_ethernet_open; + msg.function = pppapi_do_ppp_over_ethernet_create; msg.msg.ppp = pcb; - msg.msg.msg.ethernetopen.ethif = ethif; - msg.msg.msg.ethernetopen.service_name = service_name; - msg.msg.msg.ethernetopen.concentrator_name = concentrator_name; - msg.msg.msg.ethernetopen.link_status_cb = link_status_cb; - msg.msg.msg.ethernetopen.link_status_ctx = link_status_ctx; + msg.msg.msg.ethernetcreate.ethif = ethif; + msg.msg.msg.ethernetcreate.service_name = service_name; + msg.msg.msg.ethernetcreate.concentrator_name = concentrator_name; + msg.msg.msg.ethernetcreate.link_status_cb = link_status_cb; + msg.msg.msg.ethernetcreate.link_status_ctx = link_status_ctx; TCPIP_PPPAPI(&msg); return msg.msg.err; } @@ -164,41 +164,41 @@ int pppapi_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *ser #if PPPOL2TP_SUPPORT /** - * Call ppp_over_l2tp_open() inside the tcpip_thread context. + * Call ppp_over_l2tp_create() inside the tcpip_thread context. */ -static void pppapi_do_ppp_over_l2tp_open(struct pppapi_msg_msg *msg) { +static void pppapi_do_ppp_over_l2tp_create(struct pppapi_msg_msg *msg) { - msg->err = ppp_over_l2tp_open(msg->ppp, - msg->msg.l2tpopen.netif, msg->msg.l2tpopen.ipaddr, msg->msg.l2tpopen.port, + msg->err = ppp_over_l2tp_create(msg->ppp, + msg->msg.l2tpcreate.netif, msg->msg.l2tpcreate.ipaddr, msg->msg.l2tpcreate.port, #if PPPOL2TP_AUTH_SUPPORT - msg->msg.l2tpopen.secret, - msg->msg.l2tpopen.secret_len, + msg->msg.l2tpcreate.secret, + msg->msg.l2tpcreate.secret_len, #else /* PPPOL2TP_AUTH_SUPPORT */ NULL, #endif /* PPPOL2TP_AUTH_SUPPORT */ - msg->msg.l2tpopen.link_status_cb, msg->msg.l2tpopen.link_status_ctx); + msg->msg.l2tpcreate.link_status_cb, msg->msg.l2tpcreate.link_status_ctx); TCPIP_PPPAPI_ACK(msg); } /** - * Call ppp_over_l2tp_open() in a thread-safe way by running that function inside the + * Call ppp_over_l2tp_create() in a thread-safe way by running that function inside the * tcpip_thread context. */ -int pppapi_over_l2tp_open(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, +int pppapi_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, u8_t *secret, u8_t secret_len, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { struct pppapi_msg msg; - msg.function = pppapi_do_ppp_over_l2tp_open; + msg.function = pppapi_do_ppp_over_l2tp_create; msg.msg.ppp = pcb; - msg.msg.msg.l2tpopen.netif = netif; - msg.msg.msg.l2tpopen.ipaddr = ipaddr; - msg.msg.msg.l2tpopen.port = port; + msg.msg.msg.l2tpcreate.netif = netif; + msg.msg.msg.l2tpcreate.ipaddr = ipaddr; + msg.msg.msg.l2tpcreate.port = port; #if PPPOL2TP_AUTH_SUPPORT - msg.msg.msg.l2tpopen.secret = secret; - msg.msg.msg.l2tpopen.secret_len = secret_len; + msg.msg.msg.l2tpcreate.secret = secret; + msg.msg.msg.l2tpcreate.secret_len = secret_len; #endif /* PPPOL2TP_AUTH_SUPPORT */ - msg.msg.msg.l2tpopen.link_status_cb = link_status_cb; - msg.msg.msg.l2tpopen.link_status_ctx = link_status_ctx; + msg.msg.msg.l2tpcreate.link_status_cb = link_status_cb; + msg.msg.msg.l2tpcreate.link_status_ctx = link_status_ctx; TCPIP_PPPAPI(&msg); return msg.msg.err; } @@ -206,22 +206,22 @@ int pppapi_over_l2tp_open(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, /** - * Call ppp_reopen() inside the tcpip_thread context. + * Call ppp_open() inside the tcpip_thread context. */ -static void pppapi_do_ppp_reopen(struct pppapi_msg_msg *msg) { - msg->err = ppp_reopen(msg->ppp, msg->msg.reopen.holdoff); +static void pppapi_do_ppp_open(struct pppapi_msg_msg *msg) { + msg->err = ppp_open(msg->ppp, msg->msg.open.holdoff); TCPIP_PPPAPI_ACK(msg); } /** - * Call ppp_reopen() in a thread-safe way by running that function inside the + * Call ppp_open() in a thread-safe way by running that function inside the * tcpip_thread context. */ -int pppapi_reopen(ppp_pcb *pcb, u16_t holdoff) { +int pppapi_open(ppp_pcb *pcb, u16_t holdoff) { struct pppapi_msg msg; - msg.function = pppapi_do_ppp_reopen; + msg.function = pppapi_do_ppp_open; msg.msg.ppp = pcb; - msg.msg.msg.reopen.holdoff = holdoff; + msg.msg.msg.open.holdoff = holdoff; TCPIP_PPPAPI(&msg); return msg.msg.err; } diff --git a/src/include/lwip/pppapi.h b/src/include/lwip/pppapi.h index 90518dc3..27660cad 100644 --- a/src/include/lwip/pppapi.h +++ b/src/include/lwip/pppapi.h @@ -56,7 +56,7 @@ struct pppapi_msg_msg { sio_fd_t fd; ppp_link_status_cb_fn link_status_cb; void *link_status_ctx; - } serialopen; + } serialcreate; #endif /* PPPOS_SUPPORT */ #if PPPOE_SUPPORT struct { @@ -65,7 +65,7 @@ struct pppapi_msg_msg { const char *concentrator_name; ppp_link_status_cb_fn link_status_cb; void *link_status_ctx; - } ethernetopen; + } ethernetcreate; #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT struct { @@ -78,11 +78,11 @@ struct pppapi_msg_msg { #endif /* PPPOL2TP_AUTH_SUPPORT */ ppp_link_status_cb_fn link_status_cb; void *link_status_ctx; - } l2tpopen; + } l2tpcreate; #endif /* PPPOL2TP_SUPPORT */ struct { u16_t holdoff; - } reopen; + } open; struct { int cmd; void *arg; @@ -110,19 +110,19 @@ ppp_pcb *pppapi_new(void); void pppapi_set_default(ppp_pcb *pcb); void pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd); #if PPPOS_SUPPORT -int pppapi_over_serial_open(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); +int pppapi_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); #endif /* PPPOS_SUPPORT */ #if PPPOE_SUPPORT -int pppapi_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *service_name, +int pppapi_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT -int pppapi_over_l2tp_open(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, +int pppapi_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, u8_t *secret, u8_t secret_len, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); #endif /* PPPOL2TP_SUPPORT */ -int pppapi_reopen(ppp_pcb *pcb, u16_t holdoff); +int pppapi_open(ppp_pcb *pcb, u16_t holdoff); int pppapi_close(ppp_pcb *pcb); void pppapi_sighup(ppp_pcb *pcb); int pppapi_delete(ppp_pcb *pcb); diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index 7010d2e2..fc4d2c91 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -488,44 +488,44 @@ typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx); #if PPPOS_SUPPORT /* - * Start a new PPP connection using the given serial I/O device. + * Create a new PPP connection using the given serial I/O device. * * If this port connects to a modem, the modem connection must be * established before calling this. * * Return 0 on success, an error code on failure. */ -int ppp_over_serial_open(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); +int ppp_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); #endif /* PPPOS_SUPPORT */ #if PPPOE_SUPPORT /* - * Start a new PPP Over Ethernet (PPPoE) connection. + * Create a new PPP Over Ethernet (PPPoE) connection. * * Return 0 on success, an error code on failure. */ -int ppp_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, +int ppp_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT /* - * Open a new PPP Over L2TP (PPPoL2TP) connection. + * Create a new PPP Over L2TP (PPPoL2TP) connection. */ -int ppp_over_l2tp_open(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, +int ppp_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, u8_t *secret, u8_t secret_len, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); #endif /* PPPOL2TP_SUPPORT */ /* - * Open a previously opened PPP connection. + * Open a PPP connection. * * This can only be called if PPP is in the dead phase. * * Holdoff is the time to wait (in seconds) before initiating * the connection. */ -int ppp_reopen(ppp_pcb *pcb, u16_t holdoff); +int ppp_open(ppp_pcb *pcb, u16_t holdoff); /* * Initiate the end of a PPP connection. diff --git a/src/include/netif/ppp/pppol2tp.h b/src/include/netif/ppp/pppol2tp.h index c7beaaae..5b869ae9 100644 --- a/src/include/netif/ppp/pppol2tp.h +++ b/src/include/netif/ppp/pppol2tp.h @@ -197,21 +197,19 @@ struct pppol2tp_pcb_s { /* Create a new L2TP session. */ -err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int status), - pppol2tp_pcb **l2tpptr, u8_t *secret, u8_t secret_len); +err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int status), pppol2tp_pcb **l2tpptr, + struct netif *netif, ip_addr_t *ipaddr, u16_t port, + u8_t *secret, u8_t secret_len); /* Destroy a L2TP control block */ err_t pppol2tp_destroy(pppol2tp_pcb *l2tp); /* Be a LAC, connect to a LNS. */ -err_t pppol2tp_connect(pppol2tp_pcb *l2tp, struct netif *netif, ip_addr_t *ipaddr, u16_t port); +err_t pppol2tp_connect(pppol2tp_pcb *l2tp); /* Disconnect */ void pppol2tp_disconnect(pppol2tp_pcb *l2tp); -/* Reconnect to a LNS, using previously set L2TP server IP address and port. */ -void pppol2tp_reconnect(pppol2tp_pcb *l2tp); - /* Data packet from PPP to L2TP */ err_t pppol2tp_xmit(pppol2tp_pcb *l2tp, struct pbuf *pb); diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 75216f81..c00a129a 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -184,7 +184,7 @@ const struct protent* const protocols[] = { /* Prototypes for procedures local to this file. */ static void ppp_clear(ppp_pcb *pcb); -static void ppp_do_reopen(void *arg); +static void ppp_do_open(void *arg); static void ppp_start(ppp_pcb *pcb); /** Initiate LCP open request */ static void ppp_stop(ppp_pcb *pcb); static void ppp_hup(ppp_pcb *pcb); @@ -198,7 +198,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u_short prot #if PPPOS_SUPPORT #define ESCAPE_P(accm, c) ((accm)[(c) >> 3] & ppp_accm_mask[c & 0x07]) -static void ppp_over_serial_reopen(ppp_pcb *pcb); +static void ppp_over_serial_open(ppp_pcb *pcb); static err_t ppp_netif_output_over_serial(ppp_pcb *pcb, struct pbuf *pb, u_short protocol); static int ppp_write_over_serial(ppp_pcb *pcb, struct pbuf *p); #if PPP_INPROC_OWNTHREAD @@ -214,13 +214,13 @@ static void ppp_free_current_input_packet(ppp_pcb_rx *pcrx); #endif /* PPPOS_SUPPORT */ #if PPPOE_SUPPORT -static void ppp_over_ethernet_reopen(ppp_pcb *pcb); +static void ppp_over_ethernet_open(ppp_pcb *pcb); static err_t ppp_netif_output_over_ethernet(ppp_pcb *pcb, struct pbuf *p, u_short protocol); static int ppp_write_over_ethernet(ppp_pcb *pcb, struct pbuf *p); #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT -static void ppp_over_l2tp_reopen(ppp_pcb *pcb); +static void ppp_over_l2tp_open(ppp_pcb *pcb); static err_t ppp_netif_output_over_l2tp(ppp_pcb *pcb, struct pbuf *p, u_short protocol); static int ppp_write_over_l2tp(ppp_pcb *pcb, struct pbuf *p); #endif /* PPPOL2TP_SUPPORT */ @@ -352,7 +352,7 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd) { } #if PPPOS_SUPPORT -int ppp_over_serial_open(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { +int ppp_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { /* PPP is single-threaded: without a callback, * there is no way to know when the link is up. */ @@ -360,39 +360,9 @@ int ppp_over_serial_open(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_s return PPPERR_PARAM; } - /* input pbuf left over from last session? */ - ppp_free_current_input_packet(&pcb->rx); - - ppp_clear(pcb); - pcb->fd = fd; - - pcb->rx.pcb = pcb; - pcb->rx.fd = fd; - -#if VJ_SUPPORT - vj_compress_init(&pcb->vj_comp); -#endif /* VJ_SUPPORT */ - - /* - * Default the in and out accm so that escape and flag characters - * are always escaped. - */ - pcb->rx.in_accm[15] = 0x60; /* no need to protect since RX is not running */ - pcb->out_accm[15] = 0x60; - pcb->link_status_cb = link_status_cb; pcb->link_status_ctx = link_status_ctx; - - /* - * Start the connection and handle incoming events (packet or timeout). - */ - PPPDEBUG(LOG_INFO, ("ppp_over_serial_open: unit %d: connecting\n", pcb->num)); - ppp_start(pcb); -#if PPP_INPROC_OWNTHREAD - sys_thread_new(PPP_THREAD_NAME, ppp_input_thread, (void*)&pcb->rx, PPP_THREAD_STACKSIZE, PPP_THREAD_PRIO); -#endif /* PPP_INPROC_OWNTHREAD */ - return PPPERR_NONE; } @@ -413,12 +383,9 @@ void ppp_set_xaccm(ppp_pcb *pcb, ext_accm *accm) { #if PPPOE_SUPPORT static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state); -int ppp_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, +int ppp_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { - lcp_options *wo = &pcb->lcp_wantoptions; - lcp_options *ao = &pcb->lcp_allowoptions; - LWIP_UNUSED_ARG(service_name); LWIP_UNUSED_ARG(concentrator_name); @@ -428,26 +395,13 @@ int ppp_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *servic return PPPERR_PARAM; } - ppp_clear(pcb); - pcb->link_status_cb = link_status_cb; pcb->link_status_ctx = link_status_ctx; - wo->mru = ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ - wo->neg_asyncmap = 0; - wo->neg_pcompression = 0; - wo->neg_accompression = 0; - - ao->mru = ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ - ao->neg_asyncmap = 0; - ao->neg_pcompression = 0; - ao->neg_accompression = 0; - if (pppoe_create(ethif, pcb, ppp_over_ethernet_link_status_cb, &pcb->pppoe_sc) != ERR_OK) { return PPPERR_OPEN; } - pppoe_connect(pcb->pppoe_sc); return PPPERR_NONE; } #endif /* PPPOE_SUPPORT */ @@ -455,67 +409,49 @@ int ppp_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *servic #if PPPOL2TP_SUPPORT static void ppp_over_l2tp_link_status_cb(ppp_pcb *pcb, int state); -int ppp_over_l2tp_open(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, +int ppp_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, u8_t *secret, u8_t secret_len, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { - lcp_options *wo = &pcb->lcp_wantoptions; - lcp_options *ao = &pcb->lcp_allowoptions; - /* PPP is single-threaded: without a callback, * there is no way to know when the link is up. */ if (link_status_cb == NULL) { return PPPERR_PARAM; } - ppp_clear(pcb); - pcb->link_status_cb = link_status_cb; pcb->link_status_ctx = link_status_ctx; - wo->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ - wo->neg_asyncmap = 0; - wo->neg_pcompression = 0; - wo->neg_accompression = 0; - - ao->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ - ao->neg_asyncmap = 0; - ao->neg_pcompression = 0; - ao->neg_accompression = 0; - - if (pppol2tp_create(pcb, ppp_over_l2tp_link_status_cb, &pcb->l2tp_pcb, secret, secret_len) != ERR_OK) { + if (pppol2tp_create(pcb, ppp_over_l2tp_link_status_cb, &pcb->l2tp_pcb, netif, ipaddr, port, secret, secret_len) != ERR_OK) { return PPPERR_OPEN; } - if (pppol2tp_connect(pcb->l2tp_pcb, netif, ipaddr, port) != ERR_OK) { - return PPPERR_OPEN; - } return PPPERR_NONE; } #endif /* PPPOL2TP_SUPPORT */ /* - * Open a previously opened PPP connection. + * Open a PPP connection. * * This can only be called if PPP is in the dead phase. * * Holdoff is the time to wait (in seconds) before initiating * the connection. */ -int ppp_reopen(ppp_pcb *pcb, u16_t holdoff) { +int ppp_open(ppp_pcb *pcb, u16_t holdoff) { if (pcb->phase != PHASE_DEAD) { return PPPERR_PARAM; } - PPPDEBUG(LOG_DEBUG, ("ppp_reopen() called, holdoff=%d\n", holdoff)); + PPPDEBUG(LOG_DEBUG, ("ppp_open() called, holdoff=%d\n", holdoff)); if (holdoff == 0) { - ppp_do_reopen(pcb); + ppp_do_open(pcb); return PPPERR_NONE; } new_phase(pcb, PHASE_HOLDOFF); - sys_timeout((u32_t)(holdoff*1000), ppp_do_reopen, pcb); + sys_timeout((u32_t)(holdoff*1000), ppp_do_open, pcb); return PPPERR_NONE; } @@ -539,7 +475,7 @@ ppp_close(ppp_pcb *pcb) /* holdoff phase, cancel the reconnection and call the status callback */ if (pcb->phase == PHASE_HOLDOFF) { - sys_untimeout(ppp_do_reopen, pcb); + sys_untimeout(ppp_do_open, pcb); pcb->link_status_cb(pcb, pcb->err_code, pcb->link_status_ctx); return PPPERR_NONE; } @@ -653,27 +589,27 @@ static void ppp_clear(ppp_pcb *pcb) { new_phase(pcb, PHASE_INITIALIZE); } -static void ppp_do_reopen(void *arg) { +static void ppp_do_open(void *arg) { ppp_pcb *pcb = (ppp_pcb*)arg; LWIP_ASSERT("pcb->phase == PHASE_DEAD || pcb->phase == PHASE_HOLDOFF", pcb->phase == PHASE_DEAD || pcb->phase == PHASE_HOLDOFF); #if PPPOE_SUPPORT if (pcb->pppoe_sc) { - ppp_over_ethernet_reopen(pcb); + ppp_over_ethernet_open(pcb); return; } #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT if (pcb->l2tp_pcb) { - ppp_over_l2tp_reopen(pcb); + ppp_over_l2tp_open(pcb); return; } #endif /* PPPOL2TP_SUPPORT */ #if PPPOS_SUPPORT - ppp_over_serial_reopen(pcb); + ppp_over_serial_open(pcb); #endif /* PPPOS_SUPPORT */ } @@ -957,7 +893,7 @@ static err_t ppp_netif_init_cb(struct netif *netif) { /**********************************/ #if PPPOS_SUPPORT -static void ppp_over_serial_reopen(ppp_pcb *pcb) { +static void ppp_over_serial_open(ppp_pcb *pcb) { /* input pbuf left over from last session? */ ppp_free_current_input_packet(&pcb->rx); @@ -1920,7 +1856,7 @@ static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state) { pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : pppoe_err_code, pcb->link_status_ctx); } -static void ppp_over_ethernet_reopen(ppp_pcb *pcb) { +static void ppp_over_ethernet_open(ppp_pcb *pcb) { lcp_options *wo = &pcb->lcp_wantoptions; lcp_options *ao = &pcb->lcp_allowoptions; @@ -1970,7 +1906,7 @@ static void ppp_over_l2tp_link_status_cb(ppp_pcb *pcb, int state) { pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : pppol2tp_err_code, pcb->link_status_ctx); } -static void ppp_over_l2tp_reopen(ppp_pcb *pcb) { +static void ppp_over_l2tp_open(ppp_pcb *pcb) { lcp_options *wo = &pcb->lcp_wantoptions; lcp_options *ao = &pcb->lcp_allowoptions; @@ -1987,7 +1923,7 @@ static void ppp_over_l2tp_reopen(ppp_pcb *pcb) { ao->neg_pcompression = 0; ao->neg_accompression = 0; - pppol2tp_reconnect(pcb->l2tp_pcb); + pppol2tp_connect(pcb->l2tp_pcb); } #endif /* PPPOL2TP_SUPPORT */ diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index fe5badf1..dad340aa 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -87,8 +87,9 @@ static err_t pppol2tp_send_stopccn(pppol2tp_pcb *l2tp, u16_t ns); /* Create a new L2TP session. */ -err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int status), - pppol2tp_pcb **l2tpptr, u8_t *secret, u8_t secret_len) { +err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int status), pppol2tp_pcb **l2tpptr, + struct netif *netif, ip_addr_t *ipaddr, u16_t port, + u8_t *secret, u8_t secret_len) { pppol2tp_pcb *l2tp; struct udp_pcb *udp; @@ -111,7 +112,10 @@ err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int sta l2tp->ppp = ppp; l2tp->udp = udp; l2tp->link_status_cb = link_status_cb; -#if PPPOL2TP_AUTH_SUPPORT + l2tp->netif = netif; + ip_addr_set(&l2tp->remote_ip, ipaddr); + l2tp->remote_port = port; + #if PPPOL2TP_AUTH_SUPPORT l2tp->secret = secret; l2tp->secret_len = secret_len; #endif /* PPPOL2TP_AUTH_SUPPORT */ @@ -132,16 +136,14 @@ err_t pppol2tp_destroy(pppol2tp_pcb *l2tp) { } /* Be a LAC, connect to a LNS. */ -err_t pppol2tp_connect(pppol2tp_pcb *l2tp, struct netif *netif, ip_addr_t *ipaddr, u16_t port) { +err_t pppol2tp_connect(pppol2tp_pcb *l2tp) { err_t err; if (l2tp->phase != PPPOL2TP_STATE_INITIAL) { return ERR_VAL; } - l2tp->netif = netif; - ip_addr_set(&l2tp->remote_ip, ipaddr); - l2tp->remote_port = l2tp->tunnel_port = port; + pppol2tp_clear(l2tp); /* Listen to a random source port, we need to do that instead of using udp_connect() * because the L2TP LNS might answer with its own random source port (!= 1701) @@ -168,31 +170,6 @@ err_t pppol2tp_connect(pppol2tp_pcb *l2tp, struct netif *netif, ip_addr_t *ipadd return err; } -/* Reconnect to a LNS, using previously set L2TP server IP address and port. */ -void pppol2tp_reconnect(pppol2tp_pcb *l2tp) { - err_t err; - - if (l2tp->phase != PPPOL2TP_STATE_INITIAL) { - return; - } - - pppol2tp_clear(l2tp); - - udp_bind(l2tp->udp, IP_ADDR_ANY, 0); - - do { - l2tp->remote_tunnel_id = magic(); - } while(l2tp->remote_tunnel_id == 0); - /* save state, in case we fail to send SCCRQ */ - l2tp->sccrq_retried = 0; - l2tp->phase = PPPOL2TP_STATE_SCCRQ_SENT; - if ((err = pppol2tp_send_sccrq(l2tp)) != 0) { - PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send SCCRQ, error=%d\n", err)); - } - sys_timeout(PPPOL2TP_CONTROL_TIMEOUT, pppol2tp_timeout, l2tp); - return; -} - /* Disconnect */ void pppol2tp_disconnect(pppol2tp_pcb *l2tp) {