Skip to content

Commit 8b243a4

Browse files
Apply latest LWIP 2.1.2 release to MbedOS.
Multihoming fixed according to new LWIP implementation.
1 parent f301d39 commit 8b243a4

File tree

26 files changed

+262
-84
lines changed

26 files changed

+262
-84
lines changed

TESTS/netsocket/tcp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ static void test_failure_handler(const failure_t failure)
194194

195195

196196
Case cases[] = {
197+
Case("TCPSOCKET_OPEN_LIMIT", TCPSOCKET_OPEN_LIMIT),
197198
Case("TCPSOCKET_ECHOTEST", TCPSOCKET_ECHOTEST),
198199
Case("TCPSOCKET_ECHOTEST_NONBLOCK", TCPSOCKET_ECHOTEST_NONBLOCK),
199200
Case("TCPSOCKET_OPEN_CLOSE_REPEAT", TCPSOCKET_OPEN_CLOSE_REPEAT),
200-
Case("TCPSOCKET_OPEN_LIMIT", TCPSOCKET_OPEN_LIMIT),
201201
Case("TCPSOCKET_THREAD_PER_SOCKET_SAFETY", TCPSOCKET_THREAD_PER_SOCKET_SAFETY),
202202
Case("TCPSOCKET_CONNECT_INVALID", TCPSOCKET_CONNECT_INVALID),
203203
Case("TCPSOCKET_ECHOTEST_BURST", TCPSOCKET_ECHOTEST_BURST),

TESTS/network/multihoming/main.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#error [NOT_SUPPORTED] Both Wifi and Ethernet devices are required for multihoming tests.
3030
#endif
3131

32+
#define STRING_VERIFY(str) (str != NULL ? str : "not supported")
33+
3234

3335
#include "greentea-client/test_env.h"
3436
#include "unity/unity.h"
@@ -95,13 +97,12 @@ static void _ifup()
9597
TEST_FAIL_MESSAGE("Wifi connection error!");
9698
return;
9799
}
98-
wifi->get_interface_name(interface_name[interface_num]);
99-
printf("MAC: %s\n", wifi->get_mac_address());
100-
printf("IP: %s\n", wifi->get_ip_address());
101-
printf("Netmask: %s\n", wifi->get_netmask());
102-
printf("Gateway: %s\n", wifi->get_gateway());
100+
printf("Wifi interface name: %s\n\n", STRING_VERIFY (wifi->get_interface_name(interface_name[interface_num])));
101+
printf("MAC: %s\n", STRING_VERIFY(wifi->get_mac_address()));
102+
printf("IP: %s\n", STRING_VERIFY(wifi->get_ip_address()));
103+
printf("Netmask: %s\n",STRING_VERIFY(wifi->get_netmask()));
104+
printf("Gateway: %s\n", STRING_VERIFY(wifi->get_gateway()));
103105
printf("RSSI: %d\n\n", wifi->get_rssi());
104-
printf("Wifi interface name: %s\n\n", interface_name[interface_num]);
105106
interface_num++;
106107
} else {
107108
TEST_FAIL_MESSAGE("ERROR: No WiFiInterface found!");

features/lwipstack/.mbedignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ lwip/test/*
33
lwip/src/apps/*
44
lwip/src/netif/lwip_slipif.c
55
lwip/src/include/lwip/apps/*
6-
lwip/src/include/posix/*
6+
lwip/src/include/compat/stdc/*
77
lwip-eth/*

features/lwipstack/LWIPStack.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,9 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
514514
if (optlen > NSAPI_INTERFACE_NAME_MAX_SIZE) {
515515
return NSAPI_ERROR_UNSUPPORTED;
516516
}
517-
#if LWIP_TCP
518-
if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_TCP) {
519-
s->conn->pcb.tcp->interface_name = (const char *)optval;
520-
}
521-
#endif
522-
if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_UDP) {
523-
s->conn->pcb.udp->interface_name = (const char *)optval;
524-
}
525-
#if LWIP_RAW
526-
if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_RAW) {
527-
s->conn->pcb.raw->interface_name = (const char *)optval;
528-
}
529-
#endif
517+
518+
netconn_bind_if(s->conn, netif_name_to_index((const char *)optval));
519+
530520
return 0;
531521
#if LWIP_TCP
532522
case NSAPI_KEEPALIVE:

features/lwipstack/lwip/src/core/ipv4/lwip_dhcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ dhcp_handle_ack(struct netif *netif, struct dhcp_msg *msg_in)
673673
for (n = 0; (n < LWIP_DHCP_PROVIDE_DNS_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) {
674674
ip_addr_t dns_addr;
675675
ip_addr_set_ip4_u32_val(dns_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n)));
676-
dns_setserver(n, &dns_addr);
676+
dns_setserver(n, &dns_addr,netif);
677677
}
678678
#endif /* LWIP_DHCP_PROVIDE_DNS_SERVERS */
679679
}

features/lwipstack/lwip/src/core/ipv4/lwip_icmp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
382382
{
383383
ip4_addr_t iphdr_dst;
384384
ip4_addr_copy(iphdr_dst, iphdr->dest);
385-
netif = ip4_route_src(&iphdr_dst, &iphdr_src);
385+
netif = ip4_route_src(&iphdr_dst, &iphdr_src, p->if_idx);
386386
}
387387
#else
388-
netif = ip4_route(&iphdr_src);
388+
netif = ip4_route(&iphdr_src,p->if_idx);
389389
#endif
390390
if (netif != NULL) {
391391
/* calculate checksum */

features/lwipstack/lwip/src/core/ipv4/lwip_ip4.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@ ip4_set_default_multicast_netif(struct netif *default_multicast_netif)
126126
* LWIP_HOOK_IP4_ROUTE_SRC(). This function only provides the parameters.
127127
*/
128128
struct netif *
129-
ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest)
129+
ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest, u8_t idx)
130130
{
131131
if (src != NULL) {
132132
/* when src==NULL, the hook is called from ip4_route(dest) */
133-
struct netif *netif = LWIP_HOOK_IP4_ROUTE_SRC(src, dest);
133+
struct netif *netif = LWIP_HOOK_IP4_ROUTE_SRC(src, dest, idx);
134134
if (netif != NULL) {
135135
return netif;
136136
}
137137
}
138-
return ip4_route(dest);
138+
return ip4_route(dest, idx);
139139
}
140140
#endif /* LWIP_HOOK_IP4_ROUTE_SRC */
141141

@@ -149,7 +149,7 @@ ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest)
149149
* @return the netif on which to send to reach dest
150150
*/
151151
struct netif *
152-
ip4_route(const ip4_addr_t *dest)
152+
ip4_route(const ip4_addr_t *dest, u8_t idx)
153153
{
154154
#if !LWIP_SINGLE_NETIF
155155
struct netif *netif;
@@ -165,6 +165,20 @@ ip4_route(const ip4_addr_t *dest)
165165

166166
/* bug #54569: in case LWIP_SINGLE_NETIF=1 and LWIP_DEBUGF() disabled, the following loop is optimized away */
167167
LWIP_UNUSED_ARG(dest);
168+
169+
if(idx != NETIF_NO_INDEX) {
170+
/* iterate through netifs */
171+
NETIF_FOREACH(netif) {
172+
/* is the netif up, does it have a link and a valid address? */
173+
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
174+
/* interface name matches? */
175+
if (netif_get_index(netif) == idx) {
176+
/* return netif with matched name */
177+
return netif;
178+
}
179+
}
180+
}
181+
}
168182

169183
/* iterate through netifs */
170184
NETIF_FOREACH(netif) {
@@ -1032,7 +1046,7 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
10321046

10331047
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
10341048

1035-
if ((netif = ip4_route_src(src, dest)) == NULL) {
1049+
if ((netif = ip4_route_src(src, dest, p->if_idx)) == NULL) {
10361050
LWIP_DEBUGF(IP_DEBUG, ("ip4_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
10371051
ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
10381052
IP_STATS_INC(ip.rterr);

features/lwipstack/lwip/src/core/ipv6/lwip_icmp6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ icmp6_send_response_with_addrs(struct pbuf *p, u8_t code, u32_t data, u8_t type,
360360
/* Swap source and destination for the reply. */
361361
reply_dest = src_addr;
362362
reply_src = dest_addr;
363-
netif = ip6_route(reply_src, reply_dest);
363+
netif = ip6_route(reply_src, reply_dest, p->if_idx);
364364
if (netif == NULL) {
365365
ICMP6_STATS_INC(icmp6.rterr);
366366
return;

features/lwipstack/lwip/src/core/ipv6/lwip_ip6.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
* @return the netif on which to send to reach dest
8484
*/
8585
struct netif *
86-
ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
86+
ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest, u8_t idx)
8787
{
8888
#if LWIP_SINGLE_NETIF
8989
LWIP_UNUSED_ARG(src);
@@ -94,10 +94,23 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
9494

9595
LWIP_ASSERT_CORE_LOCKED();
9696

97+
if(idx != NETIF_NO_INDEX) {
98+
/* iterate through netifs */
99+
NETIF_FOREACH(netif) {
100+
/* is the netif up, does it have a link and a valid address? */
101+
if (netif_is_up(netif) && netif_is_link_up(netif)) {
102+
/* interface name matches? */
103+
if (netif_get_index(netif) == idx) {
104+
/* return netif with matched name */
105+
return netif;
106+
}
107+
}
108+
}
109+
}
97110
/* If single netif configuration, fast return. */
98111
if ((netif_list != NULL) && (netif_list->next == NULL)) {
99-
if (!netif_is_up(netif_list) || !netif_is_link_up(netif_list)){//||
100-
// (ip6_addr_has_zone(dest) && !ip6_addr_test_zone(dest, netif_list))) {
112+
if (!netif_is_up(netif_list) || !netif_is_link_up(netif_list) ||
113+
(ip6_addr_has_zone(dest) && !ip6_addr_test_zone(dest, netif_list))) {
101114
return NULL;
102115
}
103116
return netif_list;
@@ -1298,13 +1311,13 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
12981311
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
12991312

13001313
if (dest != LWIP_IP_HDRINCL) {
1301-
netif = ip6_route(src, dest);
1314+
netif = ip6_route(src, dest, p->if_idx);
13021315
} else {
13031316
/* IP header included in p, read addresses. */
13041317
ip6hdr = (struct ip6_hdr *)p->payload;
13051318
ip6_addr_copy_from_packed(src_addr, ip6hdr->src);
13061319
ip6_addr_copy_from_packed(dest_addr, ip6hdr->dest);
1307-
netif = ip6_route(&src_addr, &dest_addr);
1320+
netif = ip6_route(&src_addr, &dest_addr, p->if_idx);
13081321
}
13091322

13101323
if (netif == NULL) {

features/lwipstack/lwip/src/core/ipv6/lwip_nd6.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,14 +776,14 @@ nd6_input(struct pbuf *p, struct netif *inp)
776776

777777
if (htonl(rdnss_opt->lifetime) > 0) {
778778
/* TODO implement Lifetime > 0 */
779-
dns_setserver(rdnss_server_idx++, &rdnss_address);
779+
dns_setserver(rdnss_server_idx++, &rdnss_address, inp);
780780
} else {
781781
/* TODO implement DNS removal in dns.c */
782782
u8_t s;
783783
for (s = 0; s < DNS_MAX_SERVERS; s++) {
784-
const ip_addr_t *addr = dns_getserver(s);
784+
const ip_addr_t *addr = dns_getserver(s,netif_get_name(inp));
785785
if(ip_addr_cmp(addr, &rdnss_address)) {
786-
dns_setserver(s, NULL);
786+
dns_setserver(s, NULL, inp);
787787
}
788788
}
789789
}

features/lwipstack/lwip/src/core/lwip_dns.c

Lines changed: 116 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
302302
static struct dns_req_entry dns_requests[DNS_MAX_REQUESTS];
303303
#endif
304304
static ip_addr_t dns_servers[DNS_MAX_SERVERS];
305+
struct dns_server_interface *multihoming_dns_servers;
305306

306307
#if LWIP_IPV4
307308
const ip_addr_t dns_mquery_v4group = DNS_MQUERY_IPV4_GROUP_INIT;
@@ -321,7 +322,7 @@ dns_init(void)
321322
/* initialize default DNS server address */
322323
ip_addr_t dnsserver;
323324
DNS_SERVER_ADDRESS(&dnsserver);
324-
dns_setserver(0, &dnsserver);
325+
dns_setserver(0, &dnsserver, NULL);
325326
#endif /* DNS_SERVER_ADDRESS */
326327

327328
#if LWIP_FULL_DNS
@@ -363,15 +364,114 @@ dns_init(void)
363364
* @param dnsserver IP address of the DNS server to set
364365
*/
365366
void
366-
dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
367+
dns_setserver(u8_t numdns, const ip_addr_t *dnsserver, struct netif *netif)
367368
{
368-
if (numdns < DNS_MAX_SERVERS) {
369-
if (dnsserver != NULL) {
370-
dns_servers[numdns] = (*dnsserver);
369+
370+
if (netif == NULL || netif_check_default(netif)) {
371+
if (numdns < DNS_MAX_SERVERS) {
372+
if (dnsserver != NULL) {
373+
dns_servers[numdns] = (*dnsserver);
374+
} else {
375+
dns_servers[numdns] = *IP_ADDR_ANY;
376+
}
377+
}
378+
} else {
379+
char name[INTERFACE_NAME_MAX_SIZE];
380+
sprintf(name, "%c%c%d", netif->name[0], netif->name[1], netif->num);
381+
dns_add_interface_server(numdns, name, dnsserver);
382+
}
383+
}
384+
385+
/**
386+
* @ingroup dns
387+
* Obtain one of the currently configured DNS server.
388+
*
389+
* @param numdns the index of the DNS server
390+
* @return IP address of the indexed DNS server or "ip_addr_any" if the DNS
391+
* server has not been configured.
392+
*/
393+
const ip_addr_t*
394+
dns_getserver(u8_t numdns, const char *interface_name)
395+
{
396+
if (interface_name == NULL) {
397+
if (numdns < DNS_MAX_SERVERS) {
398+
return &dns_servers[numdns];
371399
} else {
372-
dns_servers[numdns] = *IP_ADDR_ANY;
400+
return IP_ADDR_ANY;
401+
}
402+
} else {
403+
return dns_get_interface_server(numdns, interface_name);
404+
}
405+
}
406+
407+
/**
408+
* @ingroup dns
409+
* Initialize one of the DNS servers.
410+
*
411+
* @param numdns the index of the DNS server to set must be < DNS_MAX_SERVERS
412+
* @param dnsserver IP address of the DNS server to set
413+
*/
414+
void
415+
dns_add_interface_server(u8_t numdns, const char *interface_name, const ip_addr_t *dnsserver)
416+
{
417+
struct dns_server_interface *new_interface_server;
418+
419+
if (numdns >= DNS_MAX_SERVERS) {
420+
return;
421+
}
422+
423+
if (multihoming_dns_servers != NULL) {
424+
// if interface server already exists on the list just update it
425+
for (new_interface_server = multihoming_dns_servers; new_interface_server != NULL; new_interface_server = new_interface_server->next) {
426+
if (!strcmp(interface_name, new_interface_server->interface_name)) {
427+
new_interface_server->dns_servers[numdns] = (*dnsserver);
428+
return;
429+
}
373430
}
374431
}
432+
// add new dns server to the list tail
433+
new_interface_server = mem_malloc(sizeof(struct dns_server_interface));
434+
strncpy(new_interface_server->interface_name, interface_name, INTERFACE_NAME_MAX_SIZE);
435+
new_interface_server->dns_servers[numdns] = (*dnsserver);
436+
new_interface_server->next = NULL;
437+
438+
if (multihoming_dns_servers == NULL) {
439+
multihoming_dns_servers = new_interface_server;
440+
} else {
441+
struct dns_server_interface *tail;
442+
tail = multihoming_dns_servers;
443+
444+
while (tail->next != NULL) {
445+
tail = tail->next;
446+
}
447+
tail->next = new_interface_server;
448+
449+
}
450+
}
451+
452+
void
453+
dns_remove_interface_servers(const char *interface_name)
454+
{
455+
struct dns_server_interface *temp = multihoming_dns_servers;
456+
struct dns_server_interface *prev = NULL;
457+
458+
if (temp != NULL && !strcmp(interface_name, temp->interface_name)) {
459+
multihoming_dns_servers = temp->next;
460+
mem_free(temp);
461+
return;
462+
}
463+
464+
while (temp != NULL && strcmp(interface_name, temp->interface_name)) {
465+
prev = temp;
466+
temp = temp->next;
467+
}
468+
469+
if (temp == NULL) {
470+
return;
471+
}
472+
473+
prev->next = temp->next;
474+
mem_free(temp);
375475
}
376476

377477
/**
@@ -383,13 +483,20 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
383483
* server has not been configured.
384484
*/
385485
const ip_addr_t *
386-
dns_getserver(u8_t numdns)
486+
dns_get_interface_server(u8_t numdns, const char *interface_name)
387487
{
488+
struct dns_server_interface *interface_server;
489+
388490
if (numdns < DNS_MAX_SERVERS) {
389-
return &dns_servers[numdns];
390-
} else {
391491
return IP_ADDR_ANY;
392492
}
493+
494+
for (interface_server = multihoming_dns_servers; interface_server != NULL; interface_server = interface_server->next) {
495+
if (!strcmp(interface_name, interface_server->interface_name)) {
496+
return &interface_server->dns_servers[numdns];
497+
}
498+
}
499+
return IP_ADDR_ANY;
393500
}
394501

395502
/**

0 commit comments

Comments
 (0)