[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] bridgeif.c questions
From: |
Gisle Vanem |
Subject: |
[lwip-devel] bridgeif.c questions |
Date: |
Tue, 4 Apr 2017 16:55:38 +0200 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 |
I've been playing a bit with the new bridgeif.c functions
in my Windows test-app. But it seems to be a real memory hog.
Even with '#define BRIDGEIF_MAX_PORTS 1',
it reports:
allocating 244256 bytes for private data
out of memory
Then after increasing MEM_SIZE to 300kByte, it continues to allocate
484952 bytes more in bridgeif_fdb_init(). It fails and crashes.
Here is a patch I used:
--- a/src/netif/bridgeif.c 2017-04-04 11:18:19
+++ b/src/netif/bridgeif.c 2017-04-04 15:37:39
@@ -221,8 +221,9 @@
bridgeif_dfdb_t *fdb;
mem_size_t alloc_len = sizeof(bridgeif_dfdb_t) +
(max_fdb_entries*sizeof(bridgeif_dfdb_entry_t));
LWIP_DEBUGF(BRIDGEIF_DEBUG, ("bridgeif_init: allocating %d bytes for private
data\n", (int)alloc_len));
- fdb = (bridgeif_dfdb_t*)mem_malloc(alloc_len);
- memset(fdb, 0, alloc_len);
+ fdb = (bridgeif_dfdb_t*)mem_calloc(alloc_len,1);
+ if (!fdb)
+ return NULL;
fdb->max_fdb_entries = max_fdb_entries;
fdb->fdb = (bridgeif_dfdb_entry_t *)(fdb + 1);
return fdb;
@@ -579,12 +580,11 @@
alloc_len = sizeof(bridgeif_private_t) + (init_data->max_ports*sizeof(bridgeif_port_t) +
(init_data->max_fdb_static_e ntries*sizeof(bridgeif_fdb_static_entry_t)));
LWIP_DEBUGF(BRIDGEIF_DEBUG, ("bridgeif_init: allocating %d bytes for private
data\n", (int)alloc_len));
- br = (bridgeif_private_t*)mem_malloc(alloc_len);
+ br = (bridgeif_private_t*)mem_calloc(alloc_len,1);
if (br == NULL) {
LWIP_DEBUGF(NETIF_DEBUG, ("bridgeif_init: out of memory\n"));
return ERR_MEM;
}
- memset(br, 0, alloc_len);
memcpy(&br->ethaddr, &init_data->ethaddr, sizeof(br->ethaddr));
br->netif = netif;
@@ -596,6 +596,10 @@
br->max_fdbd_entries = init_data->max_fdb_dynamic_entries;
br->fdbd = bridgeif_fdb_init(init_data->max_fdb_static_entries);
+ if (br->fdbd == NULL) {
+ LWIP_DEBUGF(NETIF_DEBUG, ("bridgeif_init: out of memory\n"));
+ return ERR_MEM;
+ }
#if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname */
---------------
But I'm not sure how this bridge should work with pcapif.c.
Do I need 2 WPcap ifaces and somehow join those with bridge_add_port()?
Since there's no example for it AFAICS, I'm now sure how to initialise it.
Which 'struct netif *' should I use in bridgeif_init()?
Thanks.
--
--gv
- [lwip-devel] bridgeif.c questions,
Gisle Vanem <=