You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/04/10 14:18:23 UTC
[incubator-nuttx] 06/08: netlink: Remove netlink_route_recvfrom
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 70012bc4a276fd2e2e5c1eedf53d9da9fe19887b
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Apr 8 18:30:28 2020 +0800
netlink: Remove netlink_route_recvfrom
The same functionality could be implemented in the common place(netlink_recvfrom)
Change-Id: I8aedb29c4f0572f020ca5c0775f06c5e1e17ae4a
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
net/netlink/netlink.h | 15 ----
net/netlink/netlink_route.c | 175 -------------------------------------------
net/netlink/netlink_sockif.c | 54 +++++++------
3 files changed, 33 insertions(+), 211 deletions(-)
diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index f1f204c..fc58cf8 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -279,21 +279,6 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
socklen_t tolen);
#endif
-/****************************************************************************
- * Name: netlink_route_recvfrom()
- *
- * Description:
- * Perform the recvfrom() operation for the NETLINK_ROUTE protocol.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_NETLINK_ROUTE
-ssize_t netlink_route_recvfrom(FAR struct socket *psock,
- FAR struct nlmsghdr *nlmsg,
- size_t len, int flags,
- FAR struct sockaddr_nl *from);
-#endif
-
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index 6c51ea7..e5873e7 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -1015,179 +1015,4 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
return ret;
}
-/****************************************************************************
- * Name: netlink_route_recvfrom()
- *
- * Description:
- * Perform the recvfrom() operation for the NETLINK_ROUTE protocol.
- *
- ****************************************************************************/
-
-ssize_t netlink_route_recvfrom(FAR struct socket *psock,
- FAR struct nlmsghdr *nlmsg,
- size_t len, int flags,
- FAR struct sockaddr_nl *from)
-{
- FAR struct netlink_response_s *entry;
- ssize_t ret;
-
- DEBUGASSERT(psock != NULL && nlmsg != NULL &&
- len >= sizeof(struct nlmsghdr));
-
- /* Find the response to this message. The return value */
-
- entry = (FAR struct netlink_response_s *)netlink_tryget_response(psock);
- if (entry == NULL)
- {
- /* No response is variable, but presumably, one is expected. Check
- * if the socket has been configured for non-blocking operation.
- * REVISIT: I think there needs to be some higher level logic to
- * select Netlink non-blocking sockets.
- */
-
- if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
- {
- return -EAGAIN;
- }
-
- /* Wait for the response. This should always succeed. */
-
- entry = (FAR struct netlink_response_s *)netlink_get_response(psock);
- DEBUGASSERT(entry != NULL);
- if (entry == NULL)
- {
- return -EPIPE;
- }
- }
-
- if (len < entry->msg.nlmsg_len)
- {
- kmm_free(entry);
- return -EMSGSIZE;
- }
-
- /* Handle the response according to the message type */
-
- switch (entry->msg.nlmsg_type)
- {
-#ifndef CONFIG_NETLINK_DISABLE_GETLINK
- case RTM_NEWLINK:
- {
- FAR struct getlink_recvfrom_rsplist_s *resp =
- (FAR struct getlink_recvfrom_rsplist_s *)entry;
-
- /* Copy the payload to the user buffer */
-
- memcpy(nlmsg, &resp->payload, resp->payload.hdr.nlmsg_len);
-
- /* Return address. REVISIT... this is just a guess. */
-
- if (from != NULL)
- {
- from->nl_family = resp->payload.iface.ifi_family;
- from->nl_pad = 0;
- from->nl_pid = resp->payload.hdr.nlmsg_pid;
- from->nl_groups = resp->payload.hdr.nlmsg_type;
- }
-
- /* The return value is the payload size */
-
- ret = resp->payload.hdr.nlmsg_len;
- }
- break;
-#endif
-
-#ifndef CONFIG_NETLINK_DISABLE_GETNEIGH
- case RTM_GETNEIGH:
- {
- FAR struct getneigh_recvfrom_rsplist_s *resp =
- (FAR struct getneigh_recvfrom_rsplist_s *)entry;
-
- /* Copy the payload to the user buffer */
-
- memcpy(nlmsg, &resp->payload, resp->payload.hdr.nlmsg_len);
-
- /* Return address. REVISIT... this is just a guess. */
-
- if (from != NULL)
- {
- from->nl_family = resp->payload.msg.ndm_family;
- from->nl_pad = 0;
- from->nl_pid = resp->payload.hdr.nlmsg_pid;
- from->nl_groups = resp->payload.hdr.nlmsg_type;
- }
-
- /* The return value is the payload size */
-
- ret = resp->payload.hdr.nlmsg_len;
- }
- break;
-#endif
-
-#ifndef CONFIG_NETLINK_DISABLE_GETROUTE
- case RTM_NEWROUTE:
- {
- FAR struct getroute_recvfrom_resplist_s *resp =
- (FAR struct getroute_recvfrom_resplist_s *)entry;
-
- /* Copy the payload to the user buffer */
-
- memcpy(nlmsg, &resp->payload, resp->payload.hdr.nlmsg_len);
-
- /* Return address. REVISIT... this is just a guess. */
-
- if (from != NULL)
- {
- from->nl_family = resp->payload.rte.rtm_family;
- from->nl_pad = 0;
- from->nl_pid = resp->payload.hdr.nlmsg_pid;
- from->nl_groups = resp->payload.hdr.nlmsg_type;
- }
-
- /* The return value is the payload size */
-
- ret = resp->payload.hdr.nlmsg_len;
- }
- break;
-#endif
-
-#ifndef NETLINK_DISABLE_NLMSGDONE
- case NLMSG_DONE:
- {
- FAR struct nlroute_msgdone_rsplist_s *resp =
- (FAR struct nlroute_msgdone_rsplist_s *)entry;
-
- /* Copy the payload to the user buffer */
-
- resp->payload.hdr.nlmsg_len = sizeof(struct nlmsghdr);
- memcpy(nlmsg, &resp->payload, sizeof(struct nlmsghdr));
-
- /* Return address. REVISIT... this is just a guess. */
-
- if (from != NULL)
- {
- from->nl_family = resp->payload.gen.rtgen_family;
- from->nl_pad = 0;
- from->nl_pid = resp->payload.hdr.nlmsg_pid;
- from->nl_groups = 0;
- }
-
- /* The return value is the payload size */
-
- ret = sizeof(struct nlmsghdr);
- }
- break;
-#endif
-
- default:
- nerr("ERROR: Unrecognized message type: %u\n",
- entry->msg.nlmsg_type);
- ret = -EIO;
- break;
- }
-
- kmm_free(entry);
- return ret;
-}
-
#endif /* CONFIG_NETLINK_ROUTE */
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index 63c9bd5..8d981c4 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -799,40 +799,52 @@ static ssize_t netlink_recvfrom(FAR struct socket *psock, FAR void *buf,
FAR struct sockaddr *from,
FAR socklen_t *fromlen)
{
- FAR struct netlink_conn_s *conn;
- FAR struct nlmsghdr *nlmsg;
- int ret;
+ FAR struct netlink_response_s *entry;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
DEBUGASSERT(from == NULL ||
(fromlen != NULL && *fromlen >= sizeof(struct sockaddr_nl)));
- conn = (FAR struct netlink_conn_s *)psock->s_conn;
+ /* Find the response to this message. The return value */
- /* Get a reference to the NetLink message */
+ entry = (FAR struct netlink_response_s *)netlink_tryget_response(psock);
+ if (entry == NULL)
+ {
+ /* No response is variable, but presumably, one is expected. Check
+ * if the socket has been configured for non-blocking operation.
+ */
- nlmsg = (FAR struct nlmsghdr *)buf;
+ if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
+ {
+ return -EAGAIN;
+ }
- switch (conn->protocol)
+ /* Wait for the response. This should always succeed. */
+
+ entry = (FAR struct netlink_response_s *)netlink_get_response(psock);
+ DEBUGASSERT(entry != NULL);
+ if (entry == NULL)
+ {
+ return -EPIPE;
+ }
+ }
+
+ if (len > entry->msg.nlmsg_len)
{
-#ifdef CONFIG_NETLINK_ROUTE
- case NETLINK_ROUTE:
- ret = netlink_route_recvfrom(psock, nlmsg, len, flags,
- (FAR struct sockaddr_nl *)from);
- if (ret >= 0 && fromlen != NULL)
- {
- *fromlen = sizeof(struct sockaddr_nl);
- }
+ len = entry->msg.nlmsg_len;
+ }
- break;
-#endif
+ /* Copy the payload to the user buffer */
- default:
- ret = -EOPNOTSUPP;
- break;
+ memcpy(buf, &entry->msg, len);
+ kmm_free(entry);
+
+ if (from != NULL)
+ {
+ netlink_getpeername(psock, from, fromlen);
}
- return ret;
+ return len;
}
/****************************************************************************