From d3bca3c2cfbe8abd714e9ddd4ce6c4b923c59bd9 Mon Sep 17 00:00:00 2001 From: Zhe Weng Date: Wed, 2 Aug 2023 16:58:46 +0800 Subject: [PATCH] net: Add FIOC_FILEPATH ioctl support for ICMP(v6)/RPMsg/Usrsock sockets Example of /proc/PID/group/fd in this case: FD OFLAGS TYPE POS PATH 3 3 9 0 icmp:[dev eth0, id 1, flg 1] 4 3 9 0 icmp6:[dev eth0, id 2, flg 1] 5 3 9 0 rpmsg:[ap:[test:0]<->remote] # server side 5 3 9 0 rpmsg:[remote<->ap:[test:0]] # client side Signed-off-by: Zhe Weng --- net/icmp/icmp_ioctl.c | 7 +++++++ net/icmpv6/icmpv6_ioctl.c | 7 +++++++ net/local/local_sockif.c | 1 - net/netdev/netdev_ioctl.c | 3 +++ net/rpmsg/rpmsg_sockif.c | 23 +++++++++++++++++++++++ net/tcp/tcp_ioctl.c | 1 - net/udp/udp_ioctl.c | 1 - 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/net/icmp/icmp_ioctl.c b/net/icmp/icmp_ioctl.c index 7c38638d63..8f1364b24e 100644 --- a/net/icmp/icmp_ioctl.c +++ b/net/icmp/icmp_ioctl.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -77,6 +78,12 @@ int icmp_ioctl(FAR struct socket *psock, int cmd, unsigned long arg) case FIONSPACE: *(FAR int *)((uintptr_t)arg) = MIN_UDP_MSS; break; + case FIOC_FILEPATH: + snprintf((FAR char *)(uintptr_t)arg, PATH_MAX, + "icmp:[dev %s, id %" PRIu16 ", flg %" PRIx8 "]", + conn->dev ? conn->dev->d_ifname : "NULL", + NTOHS(conn->id), conn->sconn.s_flags); + break; default: ret = -ENOTTY; break; diff --git a/net/icmpv6/icmpv6_ioctl.c b/net/icmpv6/icmpv6_ioctl.c index 6e97bd3f9b..16ad642800 100644 --- a/net/icmpv6/icmpv6_ioctl.c +++ b/net/icmpv6/icmpv6_ioctl.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -77,6 +78,12 @@ int icmpv6_ioctl(FAR struct socket *psock, int cmd, unsigned long arg) case FIONSPACE: *(FAR int *)((uintptr_t)arg) = MIN_UDP_MSS; break; + case FIOC_FILEPATH: + snprintf((FAR char *)(uintptr_t)arg, PATH_MAX, + "icmp6:[dev %s, id %" PRIu16 ", flg %" PRIx8 "]", + conn->dev ? conn->dev->d_ifname : "NULL", + NTOHS(conn->id), conn->sconn.s_flags); + break; default: ret = -ENOTTY; break; diff --git a/net/local/local_sockif.c b/net/local/local_sockif.c index d7827a6943..cc6c21a71f 100644 --- a/net/local/local_sockif.c +++ b/net/local/local_sockif.c @@ -885,7 +885,6 @@ static int local_ioctl(FAR struct socket *psock, int cmd, unsigned long arg) case FIOC_FILEPATH: snprintf((FAR char *)(uintptr_t)arg, PATH_MAX, "local:[%s]", conn->lc_path); - ret = OK; break; case BIOC_FLUSH: ret = -EINVAL; diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index e0443a62b3..f906f6af9c 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -1591,6 +1591,9 @@ ssize_t net_ioctl_arglen(int cmd) case FIONREAD: return sizeof(int); + case FIOC_FILEPATH: + return PATH_MAX; + case SIOCGIFCONF: return sizeof(struct ifconf); diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c index 6aa5bdd7b3..5f662d07ca 100644 --- a/net/rpmsg/rpmsg_sockif.c +++ b/net/rpmsg/rpmsg_sockif.c @@ -1346,6 +1346,25 @@ static int rpmsg_socket_close(FAR struct socket *psock) return 0; } +static void rpmsg_socket_path(FAR struct rpmsg_socket_conn_s *conn, + FAR char *buf, size_t len) +{ + if (conn->backlog) /* Server */ + { + snprintf(buf, len, + "rpmsg:[%s:[%s%s]<->%s]", + CONFIG_RPTUN_LOCAL_CPUNAME, conn->rpaddr.rp_name, + conn->nameid, conn->rpaddr.rp_cpu); + } + else /* Client */ + { + snprintf(buf, len, + "rpmsg:[%s<->%s:[%s%s]]", + CONFIG_RPTUN_LOCAL_CPUNAME, conn->rpaddr.rp_cpu, + conn->rpaddr.rp_name, conn->nameid); + } +} + static int rpmsg_socket_ioctl(FAR struct socket *psock, int cmd, unsigned long arg) { @@ -1362,6 +1381,10 @@ static int rpmsg_socket_ioctl(FAR struct socket *psock, *(FAR int *)((uintptr_t)arg) = rpmsg_socket_get_space(conn); break; + case FIOC_FILEPATH: + rpmsg_socket_path(conn, (FAR char *)(uintptr_t)arg, PATH_MAX); + break; + default: ret = -ENOTTY; break; diff --git a/net/tcp/tcp_ioctl.c b/net/tcp/tcp_ioctl.c index 3bf5905ce6..83754efa34 100644 --- a/net/tcp/tcp_ioctl.c +++ b/net/tcp/tcp_ioctl.c @@ -154,7 +154,6 @@ int tcp_ioctl(FAR struct tcp_conn_s *conn, int cmd, unsigned long arg) break; case FIOC_FILEPATH: tcp_path(conn, (FAR char *)(uintptr_t)arg, PATH_MAX); - ret = OK; break; default: ret = -ENOTTY; diff --git a/net/udp/udp_ioctl.c b/net/udp/udp_ioctl.c index 1262ef5245..79ce573c20 100644 --- a/net/udp/udp_ioctl.c +++ b/net/udp/udp_ioctl.c @@ -149,7 +149,6 @@ int udp_ioctl(FAR struct udp_conn_s *conn, int cmd, unsigned long arg) break; case FIOC_FILEPATH: udp_path(conn, (FAR char *)(uintptr_t)arg, PATH_MAX); - ret = OK; break; default: ret = -ENOTTY;