mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-10 17:43:39 +08:00
Added LWIP_SINGLE_NETIF for small targets with only one netif (see task #13515, there might be more optimizations to come with this option)
This commit is contained in:
@@ -364,9 +364,9 @@ autoip_stop(struct netif *netif)
|
||||
void
|
||||
autoip_tmr(void)
|
||||
{
|
||||
struct netif *netif = netif_list;
|
||||
struct netif *netif;
|
||||
/* loop through netif's */
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
struct autoip* autoip = netif_autoip_data(netif);
|
||||
/* only act on AutoIP configured interfaces */
|
||||
if (autoip != NULL) {
|
||||
@@ -438,8 +438,6 @@ autoip_tmr(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* proceed to next network interface */
|
||||
netif = netif->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -408,10 +408,10 @@ dhcp_select(struct netif *netif)
|
||||
void
|
||||
dhcp_coarse_tmr(void)
|
||||
{
|
||||
struct netif *netif = netif_list;
|
||||
struct netif *netif;
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_coarse_tmr()\n"));
|
||||
/* iterate through all network interfaces */
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
/* only act on DHCP configured interfaces */
|
||||
struct dhcp *dhcp = netif_dhcp_data(netif);
|
||||
if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)) {
|
||||
@@ -433,8 +433,6 @@ dhcp_coarse_tmr(void)
|
||||
dhcp_t1_timeout(netif);
|
||||
}
|
||||
}
|
||||
/* proceed to next netif */
|
||||
netif = netif->next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,9 +446,9 @@ dhcp_coarse_tmr(void)
|
||||
void
|
||||
dhcp_fine_tmr(void)
|
||||
{
|
||||
struct netif *netif = netif_list;
|
||||
struct netif *netif;
|
||||
/* loop through netif's */
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
struct dhcp *dhcp = netif_dhcp_data(netif);
|
||||
/* only act on DHCP configured interfaces */
|
||||
if (dhcp != NULL) {
|
||||
@@ -466,8 +464,6 @@ dhcp_fine_tmr(void)
|
||||
dhcp_timeout(netif);
|
||||
}
|
||||
}
|
||||
/* proceed to next network interface */
|
||||
netif = netif->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -456,8 +456,7 @@ igmp_joingroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
|
||||
LWIP_ERROR("igmp_joingroup: attempt to join allsystems address", (!ip4_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
|
||||
|
||||
/* loop through netif's */
|
||||
netif = netif_list;
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
/* Should we join this interface ? */
|
||||
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip4_addr_isany(ifaddr) || ip4_addr_cmp(netif_ip4_addr(netif), ifaddr)))) {
|
||||
err = igmp_joingroup_netif(netif, groupaddr);
|
||||
@@ -467,8 +466,6 @@ igmp_joingroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
/* proceed to next network interface */
|
||||
netif = netif->next;
|
||||
}
|
||||
|
||||
return err;
|
||||
@@ -552,8 +549,7 @@ igmp_leavegroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
|
||||
LWIP_ERROR("igmp_leavegroup: attempt to leave allsystems address", (!ip4_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
|
||||
|
||||
/* loop through netif's */
|
||||
netif = netif_list;
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
/* Should we leave this interface ? */
|
||||
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip4_addr_isany(ifaddr) || ip4_addr_cmp(netif_ip4_addr(netif), ifaddr)))) {
|
||||
err_t res = igmp_leavegroup_netif(netif, groupaddr);
|
||||
@@ -562,8 +558,6 @@ igmp_leavegroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
|
||||
err = res;
|
||||
}
|
||||
}
|
||||
/* proceed to next network interface */
|
||||
netif = netif->next;
|
||||
}
|
||||
|
||||
return err;
|
||||
@@ -638,9 +632,9 @@ igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr)
|
||||
void
|
||||
igmp_tmr(void)
|
||||
{
|
||||
struct netif *netif = netif_list;
|
||||
struct netif *netif;
|
||||
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
struct igmp_group *group = netif_igmp_data(netif);
|
||||
|
||||
while (group != NULL) {
|
||||
@@ -652,7 +646,6 @@ igmp_tmr(void)
|
||||
}
|
||||
group = group->next;
|
||||
}
|
||||
netif = netif->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)
|
||||
struct netif *
|
||||
ip4_route(const ip4_addr_t *dest)
|
||||
{
|
||||
#if !LWIP_SINGLE_NETIF
|
||||
struct netif *netif;
|
||||
|
||||
#if LWIP_MULTICAST_TX_OPTIONS
|
||||
@@ -205,6 +206,7 @@ ip4_route(const ip4_addr_t *dest)
|
||||
return netif;
|
||||
}
|
||||
#endif
|
||||
#endif /* !LWIP_SINGLE_NETIF */
|
||||
|
||||
if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default) ||
|
||||
ip4_addr_isany_val(*netif_ip4_addr(netif_default))) {
|
||||
@@ -534,7 +536,8 @@ ip4_input(struct pbuf *p, struct netif *inp)
|
||||
if (!ip4_addr_isloopback(ip4_current_dest_addr()))
|
||||
#endif /* !LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF */
|
||||
{
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
#if ! LWIP_SINGLE_NETIF
|
||||
NETIF_FOREACH(netif) {
|
||||
if (netif == inp) {
|
||||
/* we checked that before already */
|
||||
continue;
|
||||
@@ -543,6 +546,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* !LWIP_SINGLE_NETIF */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,10 @@
|
||||
struct netif *
|
||||
ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
|
||||
{
|
||||
#if LWIP_SINGLE_NETIF
|
||||
LWIP_UNUSED_ARG(src);
|
||||
LWIP_UNUSED_ARG(dest);
|
||||
#else /* LWIP_SINGLE_NETIF */
|
||||
struct netif *netif;
|
||||
s8_t i;
|
||||
|
||||
@@ -239,6 +243,7 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */
|
||||
#endif /* !LWIP_SINGLE_NETIF */
|
||||
|
||||
/* no matching netif found, use default netif, if up */
|
||||
if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default)) {
|
||||
@@ -636,7 +641,8 @@ ip6_input(struct pbuf *p, struct netif *inp)
|
||||
goto netif_found;
|
||||
}
|
||||
#endif /* !LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF */
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
#if ! LWIP_SINGLE_NETIF
|
||||
NETIF_FOREACH(netif) {
|
||||
if (netif == inp) {
|
||||
/* we checked that before already */
|
||||
continue;
|
||||
@@ -645,6 +651,7 @@ ip6_input(struct pbuf *p, struct netif *inp)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* !LWIP_SINGLE_NETIF */
|
||||
}
|
||||
netif_found:
|
||||
LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: packet accepted on interface %c%c\n",
|
||||
|
||||
@@ -313,8 +313,7 @@ mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
||||
struct netif *netif;
|
||||
|
||||
/* loop through netif's */
|
||||
netif = netif_list;
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
/* Should we join this interface ? */
|
||||
if (ip6_addr_isany(srcaddr) ||
|
||||
netif_get_ip6_addr_match(netif, srcaddr) >= 0) {
|
||||
@@ -323,9 +322,6 @@ mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* proceed to next network interface */
|
||||
netif = netif->next;
|
||||
}
|
||||
|
||||
return err;
|
||||
@@ -402,8 +398,7 @@ mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
||||
struct netif *netif;
|
||||
|
||||
/* loop through netif's */
|
||||
netif = netif_list;
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
/* Should we leave this interface ? */
|
||||
if (ip6_addr_isany(srcaddr) ||
|
||||
netif_get_ip6_addr_match(netif, srcaddr) >= 0) {
|
||||
@@ -413,8 +408,6 @@ mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
||||
err = res;
|
||||
}
|
||||
}
|
||||
/* proceed to next network interface */
|
||||
netif = netif->next;
|
||||
}
|
||||
|
||||
return err;
|
||||
@@ -489,9 +482,9 @@ mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr)
|
||||
void
|
||||
mld6_tmr(void)
|
||||
{
|
||||
struct netif *netif = netif_list;
|
||||
struct netif *netif;
|
||||
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
struct mld_group *group = netif_mld6_data(netif);
|
||||
|
||||
while (group != NULL) {
|
||||
@@ -508,7 +501,6 @@ mld6_tmr(void)
|
||||
}
|
||||
group = group->next;
|
||||
}
|
||||
netif = netif->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1042,7 +1042,7 @@ nd6_tmr(void)
|
||||
}
|
||||
|
||||
/* Process our own addresses, updating address lifetimes and/or DAD state. */
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
NETIF_FOREACH(netif) {
|
||||
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) {
|
||||
u8_t addr_state;
|
||||
#if LWIP_IPV6_ADDRESS_LIFETIMES
|
||||
@@ -1121,7 +1121,7 @@ nd6_tmr(void)
|
||||
|
||||
#if LWIP_IPV6_SEND_ROUTER_SOLICIT
|
||||
/* Send router solicitation messages, if necessary. */
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
NETIF_FOREACH(netif) {
|
||||
if ((netif->rs_count > 0) && netif_is_up(netif) &&
|
||||
netif_is_link_up(netif) &&
|
||||
!ip6_addr_isinvalid(netif_ip6_addr_state(netif, 0)) &&
|
||||
|
||||
@@ -106,7 +106,9 @@
|
||||
static netif_ext_callback_t* ext_callback;
|
||||
#endif
|
||||
|
||||
#if !LWIP_SINGLE_NETIF
|
||||
struct netif *netif_list;
|
||||
#endif /* !LWIP_SINGLE_NETIF */
|
||||
struct netif *netif_default;
|
||||
|
||||
#define netif_index_to_num(index) ((index) - 1)
|
||||
@@ -250,12 +252,17 @@ netif_add(struct netif *netif,
|
||||
#endif /* LWIP_IPV4 */
|
||||
void *state, netif_init_fn init, netif_input_fn input)
|
||||
{
|
||||
struct netif *netif2;
|
||||
int num_netifs;
|
||||
#if LWIP_IPV6
|
||||
s8_t i;
|
||||
#endif
|
||||
|
||||
#if LWIP_SINGLE_NETIF
|
||||
if (netif_default != NULL) {
|
||||
LWIP_ASSERT("single netif already set", 0);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
LWIP_ASSERT("No init function given", init != NULL);
|
||||
|
||||
/* reset new interface configuration state */
|
||||
@@ -323,30 +330,36 @@ netif_add(struct netif *netif,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if !LWIP_SINGLE_NETIF
|
||||
/* Assign a unique netif number in the range [0..254], so that (num+1) can
|
||||
serve as an interface index that fits in a u8_t.
|
||||
We assume that the new netif has not yet been added to the list here.
|
||||
This algorithm is O(n^2), but that should be OK for lwIP.
|
||||
*/
|
||||
do {
|
||||
if (netif->num == 255) {
|
||||
netif->num = 0;
|
||||
}
|
||||
num_netifs = 0;
|
||||
for (netif2 = netif_list; netif2 != NULL; netif2 = netif2->next) {
|
||||
num_netifs++;
|
||||
LWIP_ASSERT("too many netifs, max. supported number is 255", num_netifs <= 255);
|
||||
if (netif2->num == netif->num) {
|
||||
netif->num++;
|
||||
break;
|
||||
{
|
||||
struct netif *netif2;
|
||||
int num_netifs;
|
||||
do {
|
||||
if (netif->num == 255) {
|
||||
netif->num = 0;
|
||||
}
|
||||
}
|
||||
} while (netif2 != NULL);
|
||||
num_netifs = 0;
|
||||
for (netif2 = netif_list; netif2 != NULL; netif2 = netif2->next) {
|
||||
num_netifs++;
|
||||
LWIP_ASSERT("too many netifs, max. supported number is 255", num_netifs <= 255);
|
||||
if (netif2->num == netif->num) {
|
||||
netif->num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (netif2 != NULL);
|
||||
}
|
||||
netif_num = netif->num + 1;
|
||||
|
||||
/* add this netif to the list */
|
||||
netif->next = netif_list;
|
||||
netif_list = netif;
|
||||
#endif /* "LWIP_SINGLE_NETIF */
|
||||
mib2_netif_added(netif);
|
||||
|
||||
#if LWIP_IGMP
|
||||
@@ -476,6 +489,7 @@ netif_remove(struct netif *netif)
|
||||
/* reset default netif */
|
||||
netif_set_default(NULL);
|
||||
}
|
||||
#if !LWIP_SINGLE_NETIF
|
||||
/* is it the first netif? */
|
||||
if (netif_list == netif) {
|
||||
netif_list = netif->next;
|
||||
@@ -492,6 +506,7 @@ netif_remove(struct netif *netif)
|
||||
return; /* netif is not on the list */
|
||||
}
|
||||
}
|
||||
#endif /* !LWIP_SINGLE_NETIF */
|
||||
mib2_netif_removed(netif);
|
||||
#if LWIP_NETIF_REMOVE_CALLBACK
|
||||
if (netif->remove_callback) {
|
||||
@@ -1037,12 +1052,10 @@ netif_poll(struct netif *netif)
|
||||
void
|
||||
netif_poll_all(void)
|
||||
{
|
||||
struct netif *netif = netif_list;
|
||||
struct netif *netif;
|
||||
/* loop through netifs */
|
||||
while (netif != NULL) {
|
||||
NETIF_FOREACH(netif) {
|
||||
netif_poll(netif);
|
||||
/* proceed to next network interface */
|
||||
netif = netif->next;
|
||||
}
|
||||
}
|
||||
#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
|
||||
@@ -1427,7 +1440,7 @@ netif_get_by_index(u8_t idx)
|
||||
struct netif* netif;
|
||||
|
||||
if (idx != NETIF_NO_INDEX) {
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
NETIF_FOREACH(netif) {
|
||||
if (idx == netif_get_index(netif)) {
|
||||
return netif; /* found! */
|
||||
}
|
||||
@@ -1456,7 +1469,7 @@ netif_find(const char *name)
|
||||
|
||||
num = (u8_t)atoi(&name[2]);
|
||||
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
NETIF_FOREACH(netif) {
|
||||
if (num == netif->num &&
|
||||
name[0] == netif->name[0] &&
|
||||
name[1] == netif->name[1]) {
|
||||
|
||||
Reference in New Issue
Block a user