Merge pull request #2986 from Lawlieta/develop

Fix dns server address set error and improve the default netdev set operations
This commit is contained in:
Bernard Xiong 2019-08-22 20:36:58 +08:00 committed by GitHub
commit 200f3d4480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 117 additions and 80 deletions

View File

@ -279,13 +279,14 @@ dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
dns_servers[numdns] = (*dnsserver); dns_servers[numdns] = (*dnsserver);
#ifdef RT_USING_NETDEV #ifdef RT_USING_NETDEV
extern struct netif *netif_default; extern struct netif *netif_list;
extern struct netdev *netdev_get_by_name(const char *name); extern struct netdev *netdev_get_by_name(const char *name);
extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server); extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
struct netif *netif = NULL;
/* set network interface device DNS server address */ /* set network interface device DNS server address */
if (netif_default) { for (netif = netif_list; netif != NULL; netif = netif->next) {
netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver); netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
} }
#endif /* RT_USING_NETDEV */ #endif /* RT_USING_NETDEV */
} }

View File

@ -253,6 +253,12 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ #endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */
static int lwip_netdev_set_default(struct netdev *netif)
{
netif_set_default((struct netif *)netif->user_data);
return ERR_OK;
}
const struct netdev_ops lwip_netdev_ops = const struct netdev_ops lwip_netdev_ops =
{ {
lwip_netdev_set_up, lwip_netdev_set_up,
@ -282,6 +288,8 @@ const struct netdev_ops lwip_netdev_ops =
lwip_netdev_netstat, lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ #endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */
lwip_netdev_set_default,
}; };
static int netdev_add(struct netif *lwip_netif) static int netdev_add(struct netif *lwip_netif)

View File

@ -370,13 +370,14 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
dns_servers[numdns] = (*dnsserver); dns_servers[numdns] = (*dnsserver);
#ifdef RT_USING_NETDEV #ifdef RT_USING_NETDEV
extern struct netif *netif_default; extern struct netif *netif_list;
extern struct netdev *netdev_get_by_name(const char *name); extern struct netdev *netdev_get_by_name(const char *name);
extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server); extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
struct netif *netif = NULL;
/* set network interface device DNS server address */ /* set network interface device DNS server address */
if (netif_default) { for (netif = netif_list; netif != NULL; netif = netif->next) {
netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver); netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
} }
#endif /* RT_USING_NETDEV */ #endif /* RT_USING_NETDEV */
} else { } else {

View File

@ -261,6 +261,12 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ #endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */
static int lwip_netdev_set_default(struct netdev *netif)
{
netif_set_default((struct netif *)netif->user_data);
return ERR_OK;
}
const struct netdev_ops lwip_netdev_ops = const struct netdev_ops lwip_netdev_ops =
{ {
lwip_netdev_set_up, lwip_netdev_set_up,
@ -290,6 +296,8 @@ const struct netdev_ops lwip_netdev_ops =
lwip_netdev_netstat, lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ #endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */
lwip_netdev_set_default,
}; };
static int netdev_add(struct netif *lwip_netif) static int netdev_add(struct netif *lwip_netif)

View File

@ -367,13 +367,14 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
dns_servers[numdns] = (*dnsserver); dns_servers[numdns] = (*dnsserver);
#ifdef RT_USING_NETDEV #ifdef RT_USING_NETDEV
extern struct netif *netif_default; extern struct netif *netif_list;
extern struct netdev *netdev_get_by_name(const char *name); extern struct netdev *netdev_get_by_name(const char *name);
extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server); extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
struct netif *netif = NULL;
/* set network interface device DNS server address */ /* set network interface device DNS server address */
if (netif_default) { for (netif = netif_list; netif != NULL; netif = netif->next) {
netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver); netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
} }
#endif /* RT_USING_NETDEV */ #endif /* RT_USING_NETDEV */
} else { } else {

View File

@ -262,6 +262,12 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ #endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */
static int lwip_netdev_set_default(struct netdev *netif)
{
netif_set_default((struct netif *)netif->user_data);
return ERR_OK;
}
const struct netdev_ops lwip_netdev_ops = const struct netdev_ops lwip_netdev_ops =
{ {
lwip_netdev_set_up, lwip_netdev_set_up,
@ -291,6 +297,8 @@ const struct netdev_ops lwip_netdev_ops =
lwip_netdev_netstat, lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */ #endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */
lwip_netdev_set_default,
}; };
static int netdev_add(struct netif *lwip_netif) static int netdev_add(struct netif *lwip_netif)

View File

@ -137,6 +137,9 @@ struct netdev_ops
int (*ping)(struct netdev *netdev, const char *host, size_t data_len, uint32_t timeout, struct netdev_ping_resp *ping_resp); int (*ping)(struct netdev *netdev, const char *host, size_t data_len, uint32_t timeout, struct netdev_ping_resp *ping_resp);
void (*netstat)(struct netdev *netdev); void (*netstat)(struct netdev *netdev);
#endif #endif
/* set default network interface device in current network stack*/
int (*set_default)(struct netdev *netdev);
}; };
/* The network interface device registered and unregistered*/ /* The network interface device registered and unregistered*/

View File

@ -349,6 +349,12 @@ void netdev_set_default(struct netdev *netdev)
if (netdev) if (netdev)
{ {
netdev_default = netdev; netdev_default = netdev;
if (netdev->ops->set_default)
{
/* set default network interface device in the current network stack */
netdev->ops->set_default(netdev);
}
LOG_D("Setting default network interface device name(%s) successfully.", netdev->name); LOG_D("Setting default network interface device name(%s) successfully.", netdev->name);
} }
} }
@ -1128,9 +1134,10 @@ static void netdev_set_dns(char *netdev_name, uint8_t dns_num, char *dns_server)
} }
inet_aton(dns_server, &dns_addr); inet_aton(dns_server, &dns_addr);
netdev_set_dns_server(netdev, dns_num, &dns_addr); if (netdev_set_dns_server(netdev, dns_num, &dns_addr) == RT_EOK)
{
rt_kprintf("set network interface device(%s) dns server #0: %s\n", netdev_name, dns_server); rt_kprintf("set network interface device(%s) dns server #%d: %s\n", netdev_name, dns_num, dns_server);
}
} }
int netdev_dns(int argc, char **argv) int netdev_dns(int argc, char **argv)