Multihoming fixed according to new LWIP implementation.

pull/10353/head
Tymoteusz Bloch 2019-03-29 18:40:42 +01:00 committed by Cruz Monrreal II
parent 1632cc9ee4
commit 42b5680697
16 changed files with 216 additions and 55 deletions

View File

@ -194,10 +194,10 @@ static void test_failure_handler(const failure_t failure)
Case cases[] = {
Case("TCPSOCKET_OPEN_LIMIT", TCPSOCKET_OPEN_LIMIT),
Case("TCPSOCKET_ECHOTEST", TCPSOCKET_ECHOTEST),
Case("TCPSOCKET_ECHOTEST_NONBLOCK", TCPSOCKET_ECHOTEST_NONBLOCK),
Case("TCPSOCKET_OPEN_CLOSE_REPEAT", TCPSOCKET_OPEN_CLOSE_REPEAT),
Case("TCPSOCKET_OPEN_LIMIT", TCPSOCKET_OPEN_LIMIT),
Case("TCPSOCKET_THREAD_PER_SOCKET_SAFETY", TCPSOCKET_THREAD_PER_SOCKET_SAFETY),
Case("TCPSOCKET_CONNECT_INVALID", TCPSOCKET_CONNECT_INVALID),
Case("TCPSOCKET_ECHOTEST_BURST", TCPSOCKET_ECHOTEST_BURST),

View File

@ -29,6 +29,8 @@
#error [NOT_SUPPORTED] Both Wifi and Ethernet devices are required for multihoming tests.
#endif
#define STRING_VERIFY(str) (str != NULL ? str : "not supported")
#include "greentea-client/test_env.h"
#include "unity/unity.h"
@ -95,13 +97,12 @@ static void _ifup()
TEST_FAIL_MESSAGE("Wifi connection error!");
return;
}
wifi->get_interface_name(interface_name[interface_num]);
printf("MAC: %s\n", wifi->get_mac_address());
printf("IP: %s\n", wifi->get_ip_address());
printf("Netmask: %s\n", wifi->get_netmask());
printf("Gateway: %s\n", wifi->get_gateway());
printf("Wifi interface name: %s\n\n", STRING_VERIFY(wifi->get_interface_name(interface_name[interface_num])));
printf("MAC: %s\n", STRING_VERIFY(wifi->get_mac_address()));
printf("IP: %s\n", STRING_VERIFY(wifi->get_ip_address()));
printf("Netmask: %s\n", STRING_VERIFY(wifi->get_netmask()));
printf("Gateway: %s\n", STRING_VERIFY(wifi->get_gateway()));
printf("RSSI: %d\n\n", wifi->get_rssi());
printf("Wifi interface name: %s\n\n", interface_name[interface_num]);
interface_num++;
} else {
TEST_FAIL_MESSAGE("ERROR: No WiFiInterface found!");

View File

@ -3,5 +3,5 @@ lwip/test/*
lwip/src/apps/*
lwip/src/netif/lwip_slipif.c
lwip/src/include/lwip/apps/*
lwip/src/include/posix/*
lwip/src/include/compat/stdc/*
lwip-eth/*

View File

@ -514,19 +514,9 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
if (optlen > NSAPI_INTERFACE_NAME_MAX_SIZE) {
return NSAPI_ERROR_UNSUPPORTED;
}
#if LWIP_TCP
if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_TCP) {
s->conn->pcb.tcp->interface_name = (const char *)optval;
}
#endif
if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_UDP) {
s->conn->pcb.udp->interface_name = (const char *)optval;
}
#if LWIP_RAW
if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_RAW) {
s->conn->pcb.raw->interface_name = (const char *)optval;
}
#endif
netconn_bind_if(s->conn, netif_name_to_index((const char *)optval));
return 0;
#if LWIP_TCP
case NSAPI_KEEPALIVE:

View File

@ -673,7 +673,7 @@ dhcp_handle_ack(struct netif *netif, struct dhcp_msg *msg_in)
for (n = 0; (n < LWIP_DHCP_PROVIDE_DNS_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) {
ip_addr_t dns_addr;
ip_addr_set_ip4_u32_val(dns_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n)));
dns_setserver(n, &dns_addr);
dns_setserver(n, &dns_addr,netif);
}
#endif /* LWIP_DHCP_PROVIDE_DNS_SERVERS */
}

View File

@ -96,8 +96,8 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
/* If single netif configuration, fast return. */
if ((netif_list != NULL) && (netif_list->next == NULL)) {
if (!netif_is_up(netif_list) || !netif_is_link_up(netif_list)){//||
// (ip6_addr_has_zone(dest) && !ip6_addr_test_zone(dest, netif_list))) {
if (!netif_is_up(netif_list) || !netif_is_link_up(netif_list) ||
(ip6_addr_has_zone(dest) && !ip6_addr_test_zone(dest, netif_list))) {
return NULL;
}
return netif_list;

View File

@ -776,14 +776,14 @@ nd6_input(struct pbuf *p, struct netif *inp)
if (htonl(rdnss_opt->lifetime) > 0) {
/* TODO implement Lifetime > 0 */
dns_setserver(rdnss_server_idx++, &rdnss_address);
dns_setserver(rdnss_server_idx++, &rdnss_address, inp);
} else {
/* TODO implement DNS removal in dns.c */
u8_t s;
for (s = 0; s < DNS_MAX_SERVERS; s++) {
const ip_addr_t *addr = dns_getserver(s);
const ip_addr_t *addr = dns_getserver(s,netif_get_name(inp));
if(ip_addr_cmp(addr, &rdnss_address)) {
dns_setserver(s, NULL);
dns_setserver(s, NULL, inp);
}
}
}

View File

@ -302,6 +302,7 @@ static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
static struct dns_req_entry dns_requests[DNS_MAX_REQUESTS];
#endif
static ip_addr_t dns_servers[DNS_MAX_SERVERS];
struct dns_server_interface *multihoming_dns_servers;
#if LWIP_IPV4
const ip_addr_t dns_mquery_v4group = DNS_MQUERY_IPV4_GROUP_INIT;
@ -321,7 +322,7 @@ dns_init(void)
/* initialize default DNS server address */
ip_addr_t dnsserver;
DNS_SERVER_ADDRESS(&dnsserver);
dns_setserver(0, &dnsserver);
dns_setserver(0, &dnsserver, NULL);
#endif /* DNS_SERVER_ADDRESS */
#if LWIP_FULL_DNS
@ -363,14 +364,21 @@ dns_init(void)
* @param dnsserver IP address of the DNS server to set
*/
void
dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
dns_setserver(u8_t numdns, const ip_addr_t *dnsserver, struct netif *netif)
{
if (numdns < DNS_MAX_SERVERS) {
if (dnsserver != NULL) {
dns_servers[numdns] = (*dnsserver);
} else {
dns_servers[numdns] = *IP_ADDR_ANY;
if (netif == NULL || netif_check_default(netif)) {
if (numdns < DNS_MAX_SERVERS) {
if (dnsserver != NULL) {
dns_servers[numdns] = (*dnsserver);
} else {
dns_servers[numdns] = *IP_ADDR_ANY;
}
}
} else {
char name[INTERFACE_NAME_MAX_SIZE];
sprintf(name, "%c%c%d", netif->name[0], netif->name[1], netif->num);
dns_add_interface_server(numdns, name, dnsserver);
}
}
@ -382,14 +390,113 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
* @return IP address of the indexed DNS server or "ip_addr_any" if the DNS
* server has not been configured.
*/
const ip_addr_t *
dns_getserver(u8_t numdns)
const ip_addr_t*
dns_getserver(u8_t numdns, const char *interface_name)
{
if (numdns < DNS_MAX_SERVERS) {
return &dns_servers[numdns];
if (interface_name == NULL) {
if (numdns < DNS_MAX_SERVERS) {
return &dns_servers[numdns];
} else {
return IP_ADDR_ANY;
}
} else {
return dns_get_interface_server(numdns, interface_name);
}
}
/**
* @ingroup dns
* Initialize one of the DNS servers.
*
* @param numdns the index of the DNS server to set must be < DNS_MAX_SERVERS
* @param dnsserver IP address of the DNS server to set
*/
void
dns_add_interface_server(u8_t numdns, const char *interface_name, const ip_addr_t *dnsserver)
{
struct dns_server_interface *new_interface_server;
if (numdns >= DNS_MAX_SERVERS) {
return;
}
if (multihoming_dns_servers != NULL) {
// if interface server already exists on the list just update it
for (new_interface_server = multihoming_dns_servers; new_interface_server != NULL; new_interface_server = new_interface_server->next) {
if (!strcmp(interface_name, new_interface_server->interface_name)) {
new_interface_server->dns_servers[numdns] = (*dnsserver);
return;
}
}
}
// add new dns server to the list tail
new_interface_server = mem_malloc(sizeof(struct dns_server_interface));
strncpy(new_interface_server->interface_name, interface_name, INTERFACE_NAME_MAX_SIZE);
new_interface_server->dns_servers[numdns] = (*dnsserver);
new_interface_server->next = NULL;
if (multihoming_dns_servers == NULL) {
multihoming_dns_servers = new_interface_server;
} else {
struct dns_server_interface *tail;
tail = multihoming_dns_servers;
while (tail->next != NULL) {
tail = tail->next;
}
tail->next = new_interface_server;
}
}
void
dns_remove_interface_servers(const char *interface_name)
{
struct dns_server_interface *temp = multihoming_dns_servers;
struct dns_server_interface *prev = NULL;
if (temp != NULL && !strcmp(interface_name, temp->interface_name)) {
multihoming_dns_servers = temp->next;
mem_free(temp);
return;
}
while (temp != NULL && strcmp(interface_name, temp->interface_name)) {
prev = temp;
temp = temp->next;
}
if (temp == NULL) {
return;
}
prev->next = temp->next;
mem_free(temp);
}
/**
* @ingroup dns
* Obtain one of the currently configured DNS server.
*
* @param numdns the index of the DNS server
* @return IP address of the indexed DNS server or "ip_addr_any" if the DNS
* server has not been configured.
*/
const ip_addr_t *
dns_get_interface_server(u8_t numdns, const char *interface_name)
{
struct dns_server_interface *interface_server;
if (numdns < DNS_MAX_SERVERS) {
return IP_ADDR_ANY;
}
for (interface_server = multihoming_dns_servers; interface_server != NULL; interface_server = interface_server->next) {
if (!strcmp(interface_name, interface_server->interface_name)) {
return &interface_server->dns_servers[numdns];
}
}
return IP_ADDR_ANY;
}
/**

View File

@ -113,6 +113,7 @@ struct netif *netif_default;
#define netif_index_to_num(index) ((index) - 1)
static u8_t netif_num;
static char netif_name [INTERFACE_NAME_MAX_SIZE];
#if LWIP_NUM_NETIF_CLIENT_DATA > 0
static u8_t netif_client_id;
@ -835,6 +836,26 @@ netif_set_default(struct netif *netif)
netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
}
/**
* @ingroup netif
* Checks if network interface is the default network interface
* @param netif the default network interface
* @return true if netif is set to default one
* otherwise return false
*/
bool
netif_check_default(struct netif *netif)
{
if (netif == NULL) {
return false;
}
if (netif_default == netif) {
return true;
} else {
return false;
}
}
/**
* @ingroup netif
* Bring an interface up, available for processing
@ -1722,6 +1743,23 @@ netif_find(const char *name)
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
return NULL;
}
/**
* @ingroup netif
* Get a network interface name
* @param netif
* @return name the name of the netif (like netif->name) plus concatenated number
* in ascii representation (e.g. 'en0')
*/
const char *
netif_get_name(struct netif *netif)
{
if (netif == NULL) {
return NULL;
}
sprintf(netif_name, "%c%c%d", netif->name[0], netif->name[1], netif->num);
return netif_name;
}
#if LWIP_NETIF_EXT_STATUS_CALLBACK
/**

View File

@ -1723,7 +1723,7 @@ tcp_kill_prio(u8_t prio)
* We want to find the connections with the lowest possible prio, and among
* these the one with the longest inactivity time.
*/
//mprio--; temporary commented
mprio--;
inactivity = 0;
inactive = NULL;

View File

@ -703,7 +703,12 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
npcb->snd_wnd_max = npcb->snd_wnd;
#if TCP_CALCULATE_EFF_SEND_MSS
npcb->mss = tcp_eff_send_mss(npcb->mss, &npcb->local_ip, &npcb->remote_ip);
struct netif *netif;
netif = netif_get_by_index(npcb->netif_idx);
if(netif == NULL) {
netif = ip_route(&npcb->local_ip, &npcb->remote_ip);
}
npcb->mss = tcp_eff_send_mss_netif(npcb->mss, netif, &npcb->remote_ip);
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
MIB2_STATS_INC(mib2.tcppassiveopens);
@ -866,7 +871,12 @@ tcp_process(struct tcp_pcb *pcb)
pcb->state = ESTABLISHED;
#if TCP_CALCULATE_EFF_SEND_MSS
pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip);
struct netif *netif;
netif = netif_get_by_index(pcb->netif_idx);
if(netif == NULL) {
netif = ip_route(&pcb->local_ip, &pcb->remote_ip);
}
pcb->mss = tcp_eff_send_mss_netif(pcb->mss, netif, &pcb->remote_ip);
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
pcb->cwnd = LWIP_TCP_CALC_INITIAL_CWND(pcb->mss);

View File

@ -50,6 +50,12 @@
extern "C" {
#endif
struct dns_server_interface {
char interface_name [INTERFACE_NAME_MAX_SIZE];
ip_addr_t dns_servers[DNS_MAX_SERVERS];
struct dns_server_interface *next;
};
/** DNS timer period */
#define DNS_TMR_INTERVAL 1000
@ -104,8 +110,11 @@ typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, vo
void dns_init(void);
void dns_tmr(void);
void dns_setserver(u8_t numdns, const ip_addr_t *dnsserver);
const ip_addr_t* dns_getserver(u8_t numdns);
void dns_setserver(u8_t numdns, const ip_addr_t *dnsserver, struct netif *netif);
const ip_addr_t* dns_getserver(u8_t numdns, const char *interface_name);
void dns_add_interface_server(u8_t numdns, const char *interface_name, const ip_addr_t *dnsserver);
void dns_remove_interface_servers(const char *interface_name);
const ip_addr_t* dns_get_interface_server(u8_t numdns, const char *interface_name);
err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr,
dns_found_callback found, void *callback_arg);
err_t dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr,

View File

@ -177,10 +177,8 @@ typedef struct ip6_addr ip6_addr_t;
* @param addr2 IPv6 address 2
* @return 1 if the addresses are considered equal, 0 if not
*/
//#define ip6_addr_cmp(addr1, addr2) (ip6_addr_cmp_zoneless((addr1), (addr2)) && \
// ip6_addr_cmp_zone((addr1), (addr2)))
#define ip6_addr_cmp(addr1, addr2) (ip6_addr_cmp_zoneless((addr1), (addr2)))
#define ip6_addr_cmp(addr1, addr2) (ip6_addr_cmp_zoneless((addr1), (addr2)) && \
ip6_addr_cmp_zone((addr1), (addr2)))
/** Compare IPv6 address to packed address and zone */
#define ip6_addr_cmp_packed(ip6addr, paddr, zone_idx) (((ip6addr)->addr[0] == (paddr)->addr[0]) && \

View File

@ -37,6 +37,7 @@
#ifndef LWIP_HDR_NETIF_H
#define LWIP_HDR_NETIF_H
#include <stdbool.h>
#include "lwip/opt.h"
#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
@ -429,7 +430,15 @@ void netif_remove(struct netif * netif);
structure. */
struct netif *netif_find(const char *name);
/* Returns a network interface name in the form
"et0", where the first two letters are the "name" field in the
netif structure, and the digit is in the num field in the same
structure. */
const char *netif_get_name(struct netif *netif);
void netif_set_default(struct netif *netif);
bool netif_check_default(struct netif *netif);
#if LWIP_IPV4
void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);

View File

@ -2400,8 +2400,7 @@
* initialization.
*/
#if !defined LWIP_IPV6_SCOPES || defined __DOXYGEN__
//#define LWIP_IPV6_SCOPES (LWIP_IPV6 && !LWIP_SINGLE_NETIF)
#define LWIP_IPV6_SCOPES 0
#define LWIP_IPV6_SCOPES 0 /*(LWIP_IPV6 && !LWIP_SINGLE_NETIF)*/
#endif
/**

View File

@ -1109,9 +1109,9 @@ int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) {
LWIP_UNUSED_ARG(pcb);
ip_addr_set_ip4_u32_val(ns, ns1);
dns_setserver(0, &ns);
dns_setserver(0, &ns, NULL);
ip_addr_set_ip4_u32_val(ns, ns2);
dns_setserver(1, &ns);
dns_setserver(1, &ns, NULL);
return 1;
}
@ -1124,15 +1124,15 @@ int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) {
ip_addr_t nsb;
LWIP_UNUSED_ARG(pcb);
nsa = dns_getserver(0);
nsa = dns_getserver(0, NULL);
ip_addr_set_ip4_u32_val(nsb, ns1);
if (ip_addr_cmp(nsa, &nsb)) {
dns_setserver(0, IP_ADDR_ANY);
dns_setserver(0, IP_ADDR_ANY, NULL);
}
nsa = dns_getserver(1);
nsa = dns_getserver(1, NULL);
ip_addr_set_ip4_u32_val(nsb, ns2);
if (ip_addr_cmp(nsa, &nsb)) {
dns_setserver(1, IP_ADDR_ANY);
dns_setserver(1, IP_ADDR_ANY, NULL);
}
return 1;
}