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:
commit
200f3d4480
|
@ -279,13 +279,14 @@ dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
|
|||
dns_servers[numdns] = (*dnsserver);
|
||||
|
||||
#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 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 */
|
||||
if (netif_default) {
|
||||
netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver);
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
|
||||
}
|
||||
#endif /* RT_USING_NETDEV */
|
||||
}
|
||||
|
|
|
@ -253,6 +253,12 @@ void lwip_netdev_netstat(struct netdev *netif)
|
|||
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
|
||||
#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 =
|
||||
{
|
||||
lwip_netdev_set_up,
|
||||
|
@ -282,6 +288,8 @@ const struct netdev_ops lwip_netdev_ops =
|
|||
lwip_netdev_netstat,
|
||||
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
|
||||
#endif /* RT_USING_FINSH */
|
||||
|
||||
lwip_netdev_set_default,
|
||||
};
|
||||
|
||||
static int netdev_add(struct netif *lwip_netif)
|
||||
|
|
|
@ -370,13 +370,14 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
|
|||
dns_servers[numdns] = (*dnsserver);
|
||||
|
||||
#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 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 */
|
||||
if (netif_default) {
|
||||
netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver);
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
|
||||
}
|
||||
#endif /* RT_USING_NETDEV */
|
||||
} else {
|
||||
|
|
|
@ -261,6 +261,12 @@ void lwip_netdev_netstat(struct netdev *netif)
|
|||
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
|
||||
#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 =
|
||||
{
|
||||
lwip_netdev_set_up,
|
||||
|
@ -290,6 +296,8 @@ const struct netdev_ops lwip_netdev_ops =
|
|||
lwip_netdev_netstat,
|
||||
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
|
||||
#endif /* RT_USING_FINSH */
|
||||
|
||||
lwip_netdev_set_default,
|
||||
};
|
||||
|
||||
static int netdev_add(struct netif *lwip_netif)
|
||||
|
|
|
@ -367,13 +367,14 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
|
|||
dns_servers[numdns] = (*dnsserver);
|
||||
|
||||
#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 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 */
|
||||
if (netif_default) {
|
||||
netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver);
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
|
||||
}
|
||||
#endif /* RT_USING_NETDEV */
|
||||
} else {
|
||||
|
|
|
@ -262,6 +262,12 @@ void lwip_netdev_netstat(struct netdev *netif)
|
|||
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
|
||||
#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 =
|
||||
{
|
||||
lwip_netdev_set_up,
|
||||
|
@ -291,6 +297,8 @@ const struct netdev_ops lwip_netdev_ops =
|
|||
lwip_netdev_netstat,
|
||||
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
|
||||
#endif /* RT_USING_FINSH */
|
||||
|
||||
lwip_netdev_set_default,
|
||||
};
|
||||
|
||||
static int netdev_add(struct netif *lwip_netif)
|
||||
|
|
|
@ -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);
|
||||
void (*netstat)(struct netdev *netdev);
|
||||
#endif
|
||||
|
||||
/* set default network interface device in current network stack*/
|
||||
int (*set_default)(struct netdev *netdev);
|
||||
};
|
||||
|
||||
/* The network interface device registered and unregistered*/
|
||||
|
|
|
@ -349,6 +349,12 @@ void netdev_set_default(struct netdev *netdev)
|
|||
if (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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
netdev_set_dns_server(netdev, dns_num, &dns_addr);
|
||||
|
||||
rt_kprintf("set network interface device(%s) dns server #0: %s\n", netdev_name, dns_server);
|
||||
if (netdev_set_dns_server(netdev, dns_num, &dns_addr) == RT_EOK)
|
||||
{
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue