netif_add fills in a preallocated struct netif, does no longer use malloc

This commit is contained in:
jani 2003-11-24 08:23:54 +00:00
parent 00ce7401d3
commit b8d1ff810d
3 changed files with 19 additions and 34 deletions

View File

@ -39,7 +39,6 @@
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/tcp.h" #include "lwip/tcp.h"
@ -61,22 +60,15 @@ struct netif *netif_default = NULL;
* @return netif, or NULL if failed. * @return netif, or NULL if failed.
*/ */
struct netif * struct netif *
netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask, netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw, struct ip_addr *gw,
void *state, void *state,
err_t (* init)(struct netif *netif), err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif)) err_t (* input)(struct pbuf *p, struct netif *netif))
{ {
struct netif *netif;
static int netifnum = 0; static int netifnum = 0;
/* allocate netif structure */
netif = mem_malloc(sizeof(struct netif));
if (netif == NULL) {
LWIP_DEBUGF(NETIF_DEBUG, ("netif_add(): out of memory for netif\n"));
return NULL;
}
#if LWIP_DHCP #if LWIP_DHCP
/* netif not under DHCP control by default */ /* netif not under DHCP control by default */
netif->dhcp = NULL; netif->dhcp = NULL;
@ -90,7 +82,6 @@ netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
/* call user specified initialization function for netif */ /* call user specified initialization function for netif */
if (init(netif) != ERR_OK) { if (init(netif) != ERR_OK) {
mem_free(netif);
return NULL; return NULL;
} }
@ -142,7 +133,6 @@ void netif_remove(struct netif * netif)
/* reset default netif */ /* reset default netif */
netif_default = NULL; netif_default = NULL;
LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") ); LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
mem_free( netif );
} }
struct netif * struct netif *

View File

@ -115,7 +115,7 @@ extern struct netif *netif_default;
/* netif_init() must be called first. */ /* netif_init() must be called first. */
void netif_init(void); void netif_init(void);
struct netif *netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask, struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw, struct ip_addr *gw,
void *state, void *state,
err_t (* init)(struct netif *netif), err_t (* init)(struct netif *netif),

View File

@ -153,7 +153,7 @@ typedef struct PPPControl_s {
struct vjcompress vjComp; /* Van Jabobsen compression header. */ struct vjcompress vjComp; /* Van Jabobsen compression header. */
#endif #endif
struct netif *netif; struct netif netif;
struct ppp_addrs addrs; struct ppp_addrs addrs;
@ -296,7 +296,6 @@ void pppInit(void)
for (i = 0; i < NUM_PPP; i++) { for (i = 0; i < NUM_PPP; i++) {
pppControl[i].openFlag = 0; pppControl[i].openFlag = 0;
pppControl[i].netif = NULL;
subnetMask = htonl(0xffffff00); subnetMask = htonl(0xffffff00);
@ -1003,10 +1002,8 @@ int sifup(int pd)
st = 0; st = 0;
PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd)); PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd));
} else { } else {
if(pc->netif) netif_remove(&pc->netif);
netif_remove(pc->netif); if (netif_add(&pc->netif, &pc->addrs.our_ipaddr, &pc->addrs.netmask, &pc->addrs.his_ipaddr, (void *)pd, pppifNetifInit, ip_input)) {
pc->netif = netif_add(&pc->addrs.our_ipaddr, &pc->addrs.netmask, &pc->addrs.his_ipaddr, (void *)pd, pppifNetifInit, ip_input);
if(pc->netif) {
pc->if_up = 1; pc->if_up = 1;
pc->errCode = PPPERR_NONE; pc->errCode = PPPERR_NONE;
@ -1046,9 +1043,7 @@ int sifdown(int pd)
PPPDEBUG((LOG_WARNING, "sifdown[%d]: bad parms\n", pd)); PPPDEBUG((LOG_WARNING, "sifdown[%d]: bad parms\n", pd));
} else { } else {
pc->if_up = 0; pc->if_up = 0;
if(pc->netif) netif_remove(&pc->netif);
netif_remove(pc->netif);
pc->netif = NULL;
PPPDEBUG((LOG_DEBUG, "sifdown: unit %d: linkStatusCB=%lx errCode=%d\n", pd, pc->linkStatusCB, pc->errCode)); PPPDEBUG((LOG_DEBUG, "sifdown: unit %d: linkStatusCB=%lx errCode=%d\n", pd, pc->linkStatusCB, pc->errCode));
if(pc->linkStatusCB) if(pc->linkStatusCB)
pc->linkStatusCB(pc->linkStatusCtx, PPPERR_CONNECT, NULL); pc->linkStatusCB(pc->linkStatusCtx, PPPERR_CONNECT, NULL);
@ -1126,7 +1121,7 @@ int sifdefaultroute(int pd, u32_t l, u32_t g)
st = 0; st = 0;
PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd)); PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd));
} else { } else {
netif_set_default(pc->netif); netif_set_default(&pc->netif);
} }
/* TODO: check how PPP handled the netMask, previously not set by ipSetDefault */ /* TODO: check how PPP handled the netMask, previously not set by ipSetDefault */
@ -1324,7 +1319,7 @@ static void pppInput(void *arg)
* pass the result to IP. * pass the result to IP.
*/ */
if (vj_uncompress_tcp(&nb, &pppControl[pd].vjComp) >= 0) { if (vj_uncompress_tcp(&nb, &pppControl[pd].vjComp) >= 0) {
pppControl[pd].netif->input(nb, pppControl[pd].netif); pppControl[pd].netif.input(nb, &pppControl[pd].netif);
return; return;
} }
/* Something's wrong so drop it. */ /* Something's wrong so drop it. */
@ -1342,7 +1337,7 @@ static void pppInput(void *arg)
* the packet to IP. * the packet to IP.
*/ */
if (vj_uncompress_uncomp(nb, &pppControl[pd].vjComp) >= 0) { if (vj_uncompress_uncomp(nb, &pppControl[pd].vjComp) >= 0) {
pppControl[pd].netif->input(nb, pppControl[pd].netif); pppControl[pd].netif.input(nb, &pppControl[pd].netif);
return; return;
} }
/* Something's wrong so drop it. */ /* Something's wrong so drop it. */
@ -1356,7 +1351,7 @@ static void pppInput(void *arg)
break; break;
case PPP_IP: /* Internet Protocol */ case PPP_IP: /* Internet Protocol */
PPPDEBUG((LOG_INFO, "pppInput[%d]: ip in pbuf len=%d\n", pd, nb->len)); PPPDEBUG((LOG_INFO, "pppInput[%d]: ip in pbuf len=%d\n", pd, nb->len));
pppControl[pd].netif->input(nb, pppControl[pd].netif); pppControl[pd].netif.input(nb, &pppControl[pd].netif);
return; return;
default: default:
{ {