[network][netdev] Improve the default netdev operation and format code

Signed-off-by: chenyong <1521761801@qq.com>
This commit is contained in:
chenyong 2019-08-22 18:32:32 +08:00
parent d588940dac
commit 0d8a216260
5 changed files with 105 additions and 71 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

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);
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*/

View File

@ -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)