Merge pull request #2626 from Lawlieta/develop
[net][netdev] Fix netdev link_down status, socket create failed issue
This commit is contained in:
commit
b57e075867
|
@ -130,7 +130,7 @@ int lwip_ping_recv(int s, int *ttl)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef RT_USING_SAL
|
#ifndef RT_USING_NETDEV
|
||||||
|
|
||||||
/* using the lwIP custom ping */
|
/* using the lwIP custom ping */
|
||||||
rt_err_t ping(char* target_name, rt_uint32_t times, rt_size_t size)
|
rt_err_t ping(char* target_name, rt_uint32_t times, rt_size_t size)
|
||||||
|
@ -239,7 +239,7 @@ int cmd_ping(int argc, char **argv)
|
||||||
FINSH_FUNCTION_EXPORT_ALIAS(cmd_ping, __cmd_ping, ping network host);
|
FINSH_FUNCTION_EXPORT_ALIAS(cmd_ping, __cmd_ping, ping network host);
|
||||||
#endif /* RT_USING_FINSH */
|
#endif /* RT_USING_FINSH */
|
||||||
|
|
||||||
#endif /* RT_USING_SAL */
|
#endif /* RT_USING_NETDEV */
|
||||||
|
|
||||||
#endif /* RT_LWIP_ICMP */
|
#endif /* RT_LWIP_ICMP */
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ int lwip_ping_recv(int s, int *ttl)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef RT_USING_SAL
|
#ifndef RT_USING_NETDEV
|
||||||
|
|
||||||
/* using the lwIP custom ping */
|
/* using the lwIP custom ping */
|
||||||
rt_err_t ping(char* target_name, rt_uint32_t times, rt_size_t size)
|
rt_err_t ping(char* target_name, rt_uint32_t times, rt_size_t size)
|
||||||
|
@ -239,7 +239,7 @@ int cmd_ping(int argc, char **argv)
|
||||||
FINSH_FUNCTION_EXPORT_ALIAS(cmd_ping, __cmd_ping, ping network host);
|
FINSH_FUNCTION_EXPORT_ALIAS(cmd_ping, __cmd_ping, ping network host);
|
||||||
#endif /* RT_USING_FINSH */
|
#endif /* RT_USING_FINSH */
|
||||||
|
|
||||||
#endif /* RT_USING_SAL */
|
#endif /* RT_USING_NETDEV */
|
||||||
|
|
||||||
#endif /* RT_LWIP_ICMP */
|
#endif /* RT_LWIP_ICMP */
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ int lwip_ping_recv(int s, int *ttl)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef RT_USING_SAL
|
#ifndef RT_USING_NETDEV
|
||||||
|
|
||||||
/* using the lwIP custom ping */
|
/* using the lwIP custom ping */
|
||||||
rt_err_t ping(char* target_name, rt_uint32_t times, rt_size_t size)
|
rt_err_t ping(char* target_name, rt_uint32_t times, rt_size_t size)
|
||||||
|
@ -239,7 +239,7 @@ int cmd_ping(int argc, char **argv)
|
||||||
FINSH_FUNCTION_EXPORT_ALIAS(cmd_ping, __cmd_ping, ping network host);
|
FINSH_FUNCTION_EXPORT_ALIAS(cmd_ping, __cmd_ping, ping network host);
|
||||||
#endif /* RT_USING_FINSH */
|
#endif /* RT_USING_FINSH */
|
||||||
|
|
||||||
#endif /* RT_USING_SAL */
|
#endif /* RT_USING_NETDEV */
|
||||||
|
|
||||||
#endif /* RT_LWIP_ICMP */
|
#endif /* RT_LWIP_ICMP */
|
||||||
|
|
||||||
|
|
|
@ -269,8 +269,7 @@ struct netdev *netdev_get_by_family(int family)
|
||||||
{
|
{
|
||||||
netdev = rt_slist_entry(node, struct netdev, list);
|
netdev = rt_slist_entry(node, struct netdev, list);
|
||||||
pf = (struct sal_proto_family *) netdev->sal_user_data;
|
pf = (struct sal_proto_family *) netdev->sal_user_data;
|
||||||
if (pf && pf->skt_ops && pf->family == family &&
|
if (pf && pf->skt_ops && pf->family == family && netdev_is_up(netdev))
|
||||||
netdev_is_up(netdev) && netdev_is_link_up(netdev))
|
|
||||||
{
|
{
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
return netdev;
|
return netdev;
|
||||||
|
@ -281,8 +280,7 @@ struct netdev *netdev_get_by_family(int family)
|
||||||
{
|
{
|
||||||
netdev = rt_slist_entry(node, struct netdev, list);
|
netdev = rt_slist_entry(node, struct netdev, list);
|
||||||
pf = (struct sal_proto_family *) netdev->sal_user_data;
|
pf = (struct sal_proto_family *) netdev->sal_user_data;
|
||||||
if (pf && pf->skt_ops && pf->sec_family == family &&
|
if (pf && pf->skt_ops && pf->sec_family == family && netdev_is_up(netdev))
|
||||||
netdev_is_up(netdev) && netdev_is_link_up(netdev))
|
|
||||||
{
|
{
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
return netdev;
|
return netdev;
|
||||||
|
|
|
@ -370,7 +370,7 @@ static int socket_init(int family, int type, int protocol, struct sal_socket **r
|
||||||
struct sal_proto_family *pf;
|
struct sal_proto_family *pf;
|
||||||
struct netdev *netdv_def = netdev_default;
|
struct netdev *netdv_def = netdev_default;
|
||||||
struct netdev *netdev = RT_NULL;
|
struct netdev *netdev = RT_NULL;
|
||||||
rt_bool_t falgs = RT_FALSE;
|
rt_bool_t flag = RT_FALSE;
|
||||||
|
|
||||||
if (family < 0 || family > AF_MAX)
|
if (family < 0 || family > AF_MAX)
|
||||||
{
|
{
|
||||||
|
@ -388,26 +388,24 @@ static int socket_init(int family, int type, int protocol, struct sal_socket **r
|
||||||
sock->protocol = protocol;
|
sock->protocol = protocol;
|
||||||
|
|
||||||
/* get socket operations from network interface device */
|
/* get socket operations from network interface device */
|
||||||
if (netdv_def)
|
if (netdv_def == RT_NULL)
|
||||||
{
|
|
||||||
if (netdev_is_up(netdv_def) && netdev_is_link_up(netdv_def))
|
|
||||||
{
|
|
||||||
/* check default network interface device protocol family */
|
|
||||||
pf = (struct sal_proto_family *) netdv_def->sal_user_data;
|
|
||||||
if (pf != RT_NULL && pf->skt_ops && (pf->family == family || pf->sec_family == family))
|
|
||||||
{
|
|
||||||
sock->netdev = netdv_def;
|
|
||||||
falgs = RT_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
LOG_E("not find default network interface device for socket create.");
|
LOG_E("not find default network interface device for socket create.");
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (falgs == RT_FALSE)
|
if (netdev_is_up(netdv_def))
|
||||||
|
{
|
||||||
|
/* check default network interface device protocol family */
|
||||||
|
pf = (struct sal_proto_family *) netdv_def->sal_user_data;
|
||||||
|
if (pf != RT_NULL && pf->skt_ops && (pf->family == family || pf->sec_family == family))
|
||||||
|
{
|
||||||
|
sock->netdev = netdv_def;
|
||||||
|
flag = RT_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag == RT_FALSE)
|
||||||
{
|
{
|
||||||
/* get network interface device by protocol family */
|
/* get network interface device by protocol family */
|
||||||
netdev = netdev_get_by_family(family);
|
netdev = netdev_get_by_family(family);
|
||||||
|
@ -516,8 +514,6 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
|
||||||
/* get the socket object by socket descriptor */
|
/* get the socket object by socket descriptor */
|
||||||
SAL_SOCKET_OBJ_GET(sock, socket);
|
SAL_SOCKET_OBJ_GET(sock, socket);
|
||||||
|
|
||||||
/* check the network interface is commonicable */
|
|
||||||
SAL_NETDEV_IS_COMMONICABLE(sock->netdev);
|
|
||||||
/* check the network interface socket operations */
|
/* check the network interface socket operations */
|
||||||
SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, accept);
|
SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, accept);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue