From 5d0785e47aeaf115b49ba0ec4c2554205e279590 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Sun, 16 May 2010 14:34:16 +0000 Subject: [PATCH] PPPoE now uses its own MEMP pool instead of the heap (moved struct pppoe_softc from ppp_oe.c to ppp_oe.h) --- CHANGELOG | 4 ++++ src/core/memp.c | 1 + src/include/lwip/memp_std.h | 3 +++ src/include/lwip/opt.h | 8 +++++++ src/include/netif/ppp_oe.h | 30 +++++++++++++++++++++++-- src/netif/ppp/ppp_oe.c | 44 +++++-------------------------------- 6 files changed, 50 insertions(+), 40 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 360de32c..46b807e6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,10 @@ HISTORY ++ New features: + 2010-05-16: Simon Goldschmidt + * opt.h, memp_std.h, memp.c, ppp_oe.h/.c: PPPoE now uses its own MEMP pool + instead of the heap (moved struct pppoe_softc from ppp_oe.c to ppp_oe.h) + 2010-05-16: Simon Goldschmidt * opt.h, memp_std.h, dns.h/.c: DNS_LOCAL_HOSTLIST_IS_DYNAMIC uses its own MEMP pool instead of the heap diff --git a/src/core/memp.c b/src/core/memp.c index d69f4b07..4da879a5 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -57,6 +57,7 @@ #include "lwip/snmp_structs.h" #include "lwip/snmp_msg.h" #include "lwip/dns.h" +#include "netif/ppp_oe.h" #include diff --git a/src/include/lwip/memp_std.h b/src/include/lwip/memp_std.h index 448d6f91..c64f7b88 100644 --- a/src/include/lwip/memp_std.h +++ b/src/include/lwip/memp_std.h @@ -82,6 +82,9 @@ LWIP_MEMPOOL(NETDB, MEMP_NUM_NETDB, NETDB_ELEM_SIZE, #if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC LWIP_MEMPOOL(LOCALHOSTLIST, MEMP_NUM_LOCALHOSTLIST, LOCALHOSTLIST_ELEM_SIZE, "LOCALHOSTLIST") #endif /* LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ +#if PPP_SUPPORT && PPPOE_SUPPORT +LWIP_MEMPOOL(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF") +#endif /* PPP_SUPPORT && PPPOE_SUPPORT */ /* * A list of pools of pbuf's used by LWIP. diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 9617eaaa..d4e74d4a 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -378,6 +378,14 @@ #define MEMP_NUM_LOCALHOSTLIST 1 #endif +/** + * MEMP_NUM_PPPOE_INTERFACES: the number of concurrently active PPPoE + * interfaces (only used with PPPOE_SUPPORT==1) + */ +#ifndef MEMP_NUM_PPPOE_INTERFACES +#define MEMP_NUM_PPPOE_INTERFACES 1 +#endif + /** * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ diff --git a/src/include/netif/ppp_oe.h b/src/include/netif/ppp_oe.h index 6182fad7..e1cdfa51 100644 --- a/src/include/netif/ppp_oe.h +++ b/src/include/netif/ppp_oe.h @@ -140,10 +140,36 @@ PACK_STRUCT_END /* two byte PPP protocol discriminator, then IP data */ #define PPPOE_MAXMTU (ETHERMTU-PPPOE_HEADERLEN-2) -struct pppoe_softc; +#ifndef PPPOE_MAX_AC_COOKIE_LEN +#define PPPOE_MAX_AC_COOKIE_LEN 64 +#endif + +struct pppoe_softc { + struct pppoe_softc *next; + struct netif *sc_ethif; /* ethernet interface we are using */ + int sc_pd; /* ppp unit number */ + void (*sc_linkStatusCB)(int pd, int up); + + int sc_state; /* discovery phase or session connected */ + struct eth_addr sc_dest; /* hardware address of concentrator */ + u16_t sc_session; /* PPPoE session id */ + +#ifdef PPPOE_TODO + char *sc_service_name; /* if != NULL: requested name of service */ + char *sc_concentrator_name; /* if != NULL: requested concentrator id */ +#endif /* PPPOE_TODO */ + u8_t sc_ac_cookie[PPPOE_MAX_AC_COOKIE_LEN]; /* content of AC cookie we must echo back */ + size_t sc_ac_cookie_len; /* length of cookie data */ +#ifdef PPPOE_SERVER + u8_t *sc_hunique; /* content of host unique we must echo back */ + size_t sc_hunique_len; /* length of host unique */ +#endif + int sc_padi_retried; /* number of PADI retries already done */ + int sc_padr_retried; /* number of PADR retries already done */ +}; -void pppoe_init(void); +#define pppoe_init() /* compatibility define, no initialization needed */ err_t pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr); err_t pppoe_destroy(struct netif *ifp); diff --git a/src/netif/ppp/ppp_oe.c b/src/netif/ppp/ppp_oe.c index 962a9ea8..5e9cbcef 100644 --- a/src/netif/ppp/ppp_oe.c +++ b/src/netif/ppp/ppp_oe.c @@ -72,12 +72,13 @@ #if PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#include "netif/ppp_oe.h" + #include "ppp.h" #include "pppdebug.h" #include "lwip/timers.h" - -#include "netif/ppp_oe.h" +#include "lwip/memp.h" #include #include @@ -111,33 +112,6 @@ #endif static char pppoe_error_tmp[PPPOE_ERRORSTRING_LEN]; -#ifndef PPPOE_MAX_AC_COOKIE_LEN -#define PPPOE_MAX_AC_COOKIE_LEN 64 -#endif - -struct pppoe_softc { - struct pppoe_softc *next; - struct netif *sc_ethif; /* ethernet interface we are using */ - int sc_pd; /* ppp unit number */ - void (*sc_linkStatusCB)(int pd, int up); - - int sc_state; /* discovery phase or session connected */ - struct eth_addr sc_dest; /* hardware address of concentrator */ - u16_t sc_session; /* PPPoE session id */ - -#ifdef PPPOE_TODO - char *sc_service_name; /* if != NULL: requested name of service */ - char *sc_concentrator_name; /* if != NULL: requested concentrator id */ -#endif /* PPPOE_TODO */ - u8_t sc_ac_cookie[PPPOE_MAX_AC_COOKIE_LEN]; /* content of AC cookie we must echo back */ - size_t sc_ac_cookie_len; /* length of cookie data */ -#ifdef PPPOE_SERVER - u8_t *sc_hunique; /* content of host unique we must echo back */ - size_t sc_hunique_len; /* length of host unique */ -#endif - int sc_padi_retried; /* number of PADI retries already done */ - int sc_padr_retried; /* number of PADR retries already done */ -}; /* input routines */ static void pppoe_dispatch_disc_pkt(struct netif *, struct pbuf *); @@ -166,19 +140,13 @@ static struct pppoe_softc * pppoe_find_softc_by_hunique(u8_t *, size_t, struct n /** linked list of created pppoe interfaces */ static struct pppoe_softc *pppoe_softc_list; -void -pppoe_init(void) -{ - pppoe_softc_list = NULL; -} - err_t pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr) { struct pppoe_softc *sc; - sc = mem_malloc(sizeof(struct pppoe_softc)); - if(!sc) { + sc = (struct pppoe_softc *)memp_malloc(MEMP_PPPOE_IF); + if (sc == NULL) { *scptr = NULL; return ERR_MEM; } @@ -232,7 +200,7 @@ pppoe_destroy(struct netif *ifp) mem_free(sc->sc_service_name); } #endif /* PPPOE_TODO */ - mem_free(sc); + memp_free(MEMP_PPPOE_IF, sc); return ERR_OK; }