From d6fdf7d4b1dce122c1e35a460c65cb114dd43bdb Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 11 Apr 2015 13:15:06 +0200 Subject: [PATCH] PPP, PPPoL2TP, switched to dual stack IPv4/IPv6 Replaced ip4_addr_t to ip_addr_t in pppapi_pppol2tp_create() prototype, now binding to UDPv6 or UDPv4 depending on the passed ip_addr_t type. Removed pppol2tp_create_ip6() and pppapi_pppol2tp_create_ip6(). --- src/api/pppapi.c | 48 +---------------------- src/include/lwip/pppapi.h | 23 +---------- src/include/netif/ppp/pppol2tp.h | 12 +----- src/netif/ppp/pppol2tp.c | 67 ++++++-------------------------- 4 files changed, 16 insertions(+), 134 deletions(-) diff --git a/src/api/pppapi.c b/src/api/pppapi.c index 1d578a7d..5b7940d1 100644 --- a/src/api/pppapi.c +++ b/src/api/pppapi.c @@ -213,7 +213,7 @@ pppapi_do_pppol2tp_create(struct pppapi_msg_msg *msg) * tcpip_thread context. */ ppp_pcb* -pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip4_addr_t *ipaddr, u16_t port, +pppapi_pppol2tp_create(struct netif *pppif, 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 *ctx_cb) { @@ -232,52 +232,6 @@ pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip4_addr_t *ipa TCPIP_PPPAPI(&msg); return msg.msg.ppp; } - - -#if LWIP_IPV6 -/** - * Call pppol2tp_create_ip6() inside the tcpip_thread context. - */ -static void -pppapi_do_pppol2tp_create_ip6(struct pppapi_msg_msg *msg) -{ - msg->ppp = pppol2tp_create_ip6(msg->msg.l2tpcreateip6.pppif, - msg->msg.l2tpcreateip6.netif, msg->msg.l2tpcreateip6.ip6addr, msg->msg.l2tpcreateip6.port, -#if PPPOL2TP_AUTH_SUPPORT - msg->msg.l2tpcreateip6.secret, - msg->msg.l2tpcreateip6.secret_len, -#else /* PPPOL2TP_AUTH_SUPPORT */ - NULL, -#endif /* PPPOL2TP_AUTH_SUPPORT */ - msg->msg.l2tpcreateip6.link_status_cb, msg->msg.l2tpcreateip6.ctx_cb); - TCPIP_PPPAPI_ACK(msg); -} - -/** - * Call pppol2tp_create_ip6() in a thread-safe way by running that function inside the - * tcpip_thread context. - */ -ppp_pcb* -pppapi_pppol2tp_create_ip6(struct netif *pppif, struct netif *netif, ip6_addr_t *ip6addr, u16_t port, - u8_t *secret, u8_t secret_len, - ppp_link_status_cb_fn link_status_cb, void *ctx_cb) -{ - struct pppapi_msg msg; - msg.function = pppapi_do_pppol2tp_create_ip6; - msg.msg.msg.l2tpcreateip6.pppif = pppif; - msg.msg.msg.l2tpcreateip6.netif = netif; - msg.msg.msg.l2tpcreateip6.ip6addr = ip6addr; - msg.msg.msg.l2tpcreateip6.port = port; -#if PPPOL2TP_AUTH_SUPPORT - msg.msg.msg.l2tpcreateip6.secret = secret; - msg.msg.msg.l2tpcreateip6.secret_len = secret_len; -#endif /* PPPOL2TP_AUTH_SUPPORT */ - msg.msg.msg.l2tpcreateip6.link_status_cb = link_status_cb; - msg.msg.msg.l2tpcreateip6.ctx_cb = ctx_cb; - TCPIP_PPPAPI(&msg); - return msg.msg.ppp; -} -#endif /* LWIP_IPV6 */ #endif /* PPPOL2TP_SUPPORT */ diff --git a/src/include/lwip/pppapi.h b/src/include/lwip/pppapi.h index a941b90e..270c5fc7 100644 --- a/src/include/lwip/pppapi.h +++ b/src/include/lwip/pppapi.h @@ -79,7 +79,7 @@ struct pppapi_msg_msg { struct { struct netif *pppif; struct netif *netif; - ip4_addr_t *ipaddr; + ip_addr_t *ipaddr; u16_t port; #if PPPOL2TP_AUTH_SUPPORT u8_t *secret; @@ -88,20 +88,6 @@ struct pppapi_msg_msg { ppp_link_status_cb_fn link_status_cb; void *ctx_cb; } l2tpcreate; -#if LWIP_IPV6 - struct { - struct netif *pppif; - struct netif *netif; - ip6_addr_t *ip6addr; - u16_t port; -#if PPPOL2TP_AUTH_SUPPORT - u8_t *secret; - u8_t secret_len; -#endif /* PPPOL2TP_AUTH_SUPPORT */ - ppp_link_status_cb_fn link_status_cb; - void *ctx_cb; - } l2tpcreateip6; -#endif /* LWIP_IPV6 */ #endif /* PPPOL2TP_SUPPORT */ struct { u16_t holdoff; @@ -141,14 +127,9 @@ ppp_pcb *pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const cha void *ctx_cb); #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT -ppp_pcb *pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip4_addr_t *ipaddr, u16_t port, +ppp_pcb *pppapi_pppol2tp_create(struct netif *pppif, 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 *ctx_cb); -#if LWIP_IPV6 -ppp_pcb *pppapi_pppol2tp_create_ip6(struct netif *pppif, struct netif *netif, ip6_addr_t *ip6addr, u16_t port, - u8_t *secret, u8_t secret_len, - ppp_link_status_cb_fn link_status_cb, void *ctx_cb); -#endif /* LWIP_IPV6 */ #endif /* PPPOL2TP_SUPPORT */ err_t pppapi_connect(ppp_pcb *pcb, u16_t holdoff); #if PPP_SERVER diff --git a/src/include/netif/ppp/pppol2tp.h b/src/include/netif/ppp/pppol2tp.h index 03857769..df57c189 100644 --- a/src/include/netif/ppp/pppol2tp.h +++ b/src/include/netif/ppp/pppol2tp.h @@ -191,19 +191,11 @@ struct pppol2tp_pcb_s { }; -/* Create a new L2TP session over IPv4. */ +/* Create a new L2TP session. */ ppp_pcb *pppol2tp_create(struct netif *pppif, - struct netif *netif, ip4_addr_t *ipaddr, u16_t port, + 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 *ctx_cb); -#if LWIP_IPV6 -/* Create a new L2TP session over IPv6. */ -ppp_pcb *pppol2tp_create_ip6(struct netif *pppif, - struct netif *netif, ip6_addr_t *ip6addr, u16_t port, - u8_t *secret, u8_t secret_len, - ppp_link_status_cb_fn link_status_cb, void *ctx_cb); -#endif /* LWIP_IPV6 */ - #endif /* PPPOL2TP_H_ */ #endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */ diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index 37900593..1f5f43f8 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -119,13 +119,17 @@ static const struct link_callbacks pppol2tp_callbacks = { /* Create a new L2TP session. */ ppp_pcb *pppol2tp_create(struct netif *pppif, - struct netif *netif, ip4_addr_t *ipaddr, u16_t port, + 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 *ctx_cb) { ppp_pcb *ppp; pppol2tp_pcb *l2tp; struct udp_pcb *udp; + if (ipaddr == NULL) { + return NULL; + } + ppp = ppp_new(pppif, link_status_cb, ctx_cb); if (ppp == NULL) { return NULL; @@ -137,6 +141,11 @@ ppp_pcb *pppol2tp_create(struct netif *pppif, return NULL; } +#if LWIP_IPV6 + if (IP_IS_V6_L(ipaddr)) { + udp = udp_new_ip6(); + } else +#endif /* LWIP_IPV6 */ udp = udp_new(); if (udp == NULL) { memp_free(MEMP_PPPOL2TP_PCB, l2tp); @@ -150,11 +159,7 @@ ppp_pcb *pppol2tp_create(struct netif *pppif, l2tp->ppp = ppp; l2tp->udp = udp; l2tp->netif = netif; - if (ipaddr) { - ip_addr_copy_from_ip4(l2tp->remote_ip, *ipaddr); - } else { - ip_addr_set_any(0, &l2tp->remote_ip); - } + ip_addr_copy(l2tp->remote_ip, *ipaddr); l2tp->remote_port = port; #if PPPOL2TP_AUTH_SUPPORT l2tp->secret = secret; @@ -165,56 +170,6 @@ ppp_pcb *pppol2tp_create(struct netif *pppif, return ppp; } -#if LWIP_IPV6 -/* Create a new L2TP session over IPv6. */ -ppp_pcb *pppol2tp_create_ip6(struct netif *pppif, - struct netif *netif, ip6_addr_t *ip6addr, u16_t port, - u8_t *secret, u8_t secret_len, - ppp_link_status_cb_fn link_status_cb, void *ctx_cb) { - ppp_pcb *ppp; - pppol2tp_pcb *l2tp; - struct udp_pcb *udp; - - ppp = ppp_new(pppif, link_status_cb, ctx_cb); - if (ppp == NULL) { - return NULL; - } - - l2tp = (pppol2tp_pcb *)memp_malloc(MEMP_PPPOL2TP_PCB); - if (l2tp == NULL) { - ppp_free(ppp); - return NULL; - } - - udp = udp_new_ip6(); - if (udp == NULL) { - memp_free(MEMP_PPPOL2TP_PCB, l2tp); - ppp_free(ppp); - return NULL; - } - udp_recv(udp, pppol2tp_input_ip, l2tp); - - memset(l2tp, 0, sizeof(pppol2tp_pcb)); - l2tp->phase = PPPOL2TP_STATE_INITIAL; - l2tp->ppp = ppp; - l2tp->udp = udp; - l2tp->netif = netif; - if (ip6addr) { - ip_addr_copy_from_ip6(l2tp->remote_ip, *ip6addr); - } else { - ip_addr_set_any(1, &l2tp->remote_ip); - } - l2tp->remote_port = port; -#if PPPOL2TP_AUTH_SUPPORT - l2tp->secret = secret; - l2tp->secret_len = secret_len; -#endif /* PPPOL2TP_AUTH_SUPPORT */ - - ppp_link_set_callbacks(ppp, &pppol2tp_callbacks, l2tp); - return ppp; -} -#endif /* LWIP_IPV6 */ - /* Called by PPP core */ static err_t pppol2tp_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) { pppol2tp_pcb *l2tp = (pppol2tp_pcb *)ctx;