qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/6] linux-user: Add support for various missing netlink sockopt entries
@ 2025-01-19  4:41 deller
  2025-01-19  4:41 ` [PATCH v3 1/6] linux-user: netlink: Add missing IFA_PROTO to host_to_target_data_addr_rtattr() deller
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: deller @ 2025-01-19  4:41 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé, Laurent Vivier,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

From: Helge Deller <deller@gmx.de>

This patchset adds various missing sockopt calls, so that qemu linux-user
is able to successfully build the debian gupnp package in a chroot.

Tested with a 32-bit big-endian hppa linux-user chroot running on a phyiscal
x86-64 little-endian host.

This fixes debian's bug report:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1044651

Signed-off-by: Helge Deller <deller@gmx.de>

Please review patches #3, #4 and #5.

Changes in v3:
- Updated patches #3, #4 and #5 based on suggestions from
  Laurent Vivier

Changes in v2:
- Moved IFA_PROTO in patch 1 as suggested by Laurent Vivier
- Added Reviewed-by from Philippe Mathieu-Daudé and Laurent Vivier
  in patch 2

Helge Deller (6):
  linux-user: netlink: Add missing IFA_PROTO to
    host_to_target_data_addr_rtattr()
  linux-user: Use unique error messages for cmsg parsing
  linux-user: netlink: Add IP_PKTINFO cmsg parsing
  linux-user: netlink: Add emulation of IP_MULTICAST_IF
  linux-user: netlink: add netlink neighbour emulation
  linux-user: netlink: Add missing QEMU_IFLA entries

 linux-user/fd-trans.c     | 137 +++++++++++++++++++++++++++++++++++++-
 linux-user/syscall.c      |  34 +++++++---
 linux-user/syscall_defs.h |   6 ++
 3 files changed, 168 insertions(+), 9 deletions(-)

-- 
2.47.0



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/6] linux-user: netlink: Add missing IFA_PROTO to host_to_target_data_addr_rtattr()
  2025-01-19  4:41 [PATCH v3 0/6] linux-user: Add support for various missing netlink sockopt entries deller
@ 2025-01-19  4:41 ` deller
  2025-01-20 18:29   ` Laurent Vivier
  2025-01-19  4:41 ` [PATCH v3 2/6] linux-user: Use unique error messages for cmsg parsing deller
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: deller @ 2025-01-19  4:41 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé, Laurent Vivier,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

From: Helge Deller <deller@gmx.de>

Fixes this warning:
 Unknown host IFA type: 11

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/fd-trans.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c
index c04a97c73a..a86ed2f4b4 100644
--- a/linux-user/fd-trans.c
+++ b/linux-user/fd-trans.c
@@ -1140,6 +1140,7 @@ static abi_long host_to_target_data_addr_rtattr(struct rtattr *rtattr)
     /* binary: depends on family type */
     case IFA_ADDRESS:
     case IFA_LOCAL:
+    case IFA_PROTO:
         break;
     /* string */
     case IFA_LABEL:
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/6] linux-user: Use unique error messages for cmsg parsing
  2025-01-19  4:41 [PATCH v3 0/6] linux-user: Add support for various missing netlink sockopt entries deller
  2025-01-19  4:41 ` [PATCH v3 1/6] linux-user: netlink: Add missing IFA_PROTO to host_to_target_data_addr_rtattr() deller
@ 2025-01-19  4:41 ` deller
  2025-01-19  4:41 ` [PATCH v3 3/6] linux-user: netlink: Add IP_PKTINFO " deller
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: deller @ 2025-01-19  4:41 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé, Laurent Vivier,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

From: Helge Deller <deller@gmx.de>

Avoid using the same error message for two different code paths
as it complicates determining the one which actually triggered.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 78c7c0b34e..a157abc40c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1827,7 +1827,7 @@ static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
                 *dst = tswap32(*dst);
             }
         } else {
-            qemu_log_mask(LOG_UNIMP, "Unsupported ancillary data: %d/%d\n",
+            qemu_log_mask(LOG_UNIMP, "Unsupported target ancillary data: %d/%d\n",
                           cmsg->cmsg_level, cmsg->cmsg_type);
             memcpy(data, target_data, len);
         }
@@ -2049,7 +2049,7 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
 
         default:
         unimplemented:
-            qemu_log_mask(LOG_UNIMP, "Unsupported ancillary data: %d/%d\n",
+            qemu_log_mask(LOG_UNIMP, "Unsupported host ancillary data: %d/%d\n",
                           cmsg->cmsg_level, cmsg->cmsg_type);
             memcpy(target_data, data, MIN(len, tgt_len));
             if (tgt_len > len) {
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/6] linux-user: netlink: Add IP_PKTINFO cmsg parsing
  2025-01-19  4:41 [PATCH v3 0/6] linux-user: Add support for various missing netlink sockopt entries deller
  2025-01-19  4:41 ` [PATCH v3 1/6] linux-user: netlink: Add missing IFA_PROTO to host_to_target_data_addr_rtattr() deller
  2025-01-19  4:41 ` [PATCH v3 2/6] linux-user: Use unique error messages for cmsg parsing deller
@ 2025-01-19  4:41 ` deller
  2025-01-20 18:10   ` Laurent Vivier
  2025-01-19  4:41 ` [PATCH v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF deller
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: deller @ 2025-01-19  4:41 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé, Laurent Vivier,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

From: Helge Deller <deller@gmx.de>

Fixes those warnings:
 Unsupported host ancillary data: 0/8

Signed-off-by: Helge Deller <deller@gmx.de>

v2: (based on feedback by Laurent Vivier)
- add target_in_pktinfo struct and fix copying target_in_addr fields
---
 linux-user/syscall.c      | 10 ++++++++++
 linux-user/syscall_defs.h |  6 ++++++
 2 files changed, 16 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a157abc40c..df8609b4d8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1998,6 +1998,16 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
                     (void *) &errh->offender, sizeof(errh->offender));
                 break;
             }
+            case IP_PKTINFO:
+            {
+                struct in_pktinfo *pkti = data;
+                struct target_in_pktinfo *target_pi = target_data;
+
+                __put_user(pkti->ipi_ifindex, &target_pi->ipi_ifindex);
+                target_pi->ipi_spec_dst.s_addr = pkti->ipi_spec_dst.s_addr;
+                target_pi->ipi_addr.s_addr = pkti->ipi_addr.s_addr;
+                break;
+            }
             default:
                 goto unimplemented;
             }
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index faad9147c9..86d773add7 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2622,6 +2622,12 @@ struct target_ucred {
     abi_uint gid;
 };
 
+struct target_in_pktinfo {
+    abi_int               ipi_ifindex;
+    struct target_in_addr ipi_spec_dst;
+    struct target_in_addr ipi_addr;
+};
+
 typedef abi_int target_timer_t;
 
 #define TARGET_SIGEV_MAX_SIZE 64
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF
  2025-01-19  4:41 [PATCH v3 0/6] linux-user: Add support for various missing netlink sockopt entries deller
                   ` (2 preceding siblings ...)
  2025-01-19  4:41 ` [PATCH v3 3/6] linux-user: netlink: Add IP_PKTINFO " deller
@ 2025-01-19  4:41 ` deller
  2025-01-20 18:17   ` Laurent Vivier
  2025-01-19  4:41 ` [PATCH v3 5/6] linux-user: netlink: add netlink neighbour emulation deller
  2025-01-19  4:41 ` [PATCH v3 6/6] linux-user: netlink: Add missing QEMU_IFLA entries deller
  5 siblings, 1 reply; 12+ messages in thread
From: deller @ 2025-01-19  4:41 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé, Laurent Vivier,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

From: Helge Deller <deller@gmx.de>

Add IP_MULTICAST_IF and share the code with IP_ADD_MEMBERSHIP / IP_DROP_MEMBERSHIP.
Sharing the code makes sense, because the manpage of ip(7)  says:

IP_MULTICAST_IF (since Linux 1.2)
      Set the local device for a multicast socket.  The argument
      for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
      ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
      in_addr structure.  (The kernel determines which structure
      is being passed based on the size passed in optlen.)  For
      getsockopt(2), the argument is an in_addr structure.

Signed-off-by: Helge Deller <deller@gmx.de>

v2: (based on feedback by Laurent Vivier)
- refined commit message and restructure the copying of ip_mreqn fields

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bbe2560927..4360543e20 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             }
             ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
             break;
+        case IP_MULTICAST_IF:
         case IP_ADD_MEMBERSHIP:
         case IP_DROP_MEMBERSHIP:
         {
             struct ip_mreqn ip_mreq;
             struct target_ip_mreqn *target_smreqn;
+            int min_size;

             QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
                               sizeof(struct target_ip_mreq));

-            if (optlen < sizeof (struct target_ip_mreq) ||
+            if (optname == IP_MULTICAST_IF) {
+                min_size = sizeof(struct in_addr);
+            } else {
+                min_size = sizeof(struct target_ip_mreq);
+            }
+            if (optlen < min_size ||
                 optlen > sizeof (struct target_ip_mreqn)) {
                 return -TARGET_EINVAL;
             }
@@ -2149,7 +2156,9 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
                 return -TARGET_EFAULT;
             }
             ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
-            ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
+            if (optlen >= sizeof(struct target_ip_mreq)) {
+                ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
+            }
             if (optlen == sizeof(struct target_ip_mreqn)) {
                 ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
                 optlen = sizeof(struct ip_mreqn);
---
 linux-user/syscall.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index df8609b4d8..6ee02383da 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             }
             ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
             break;
+        case IP_MULTICAST_IF:
         case IP_ADD_MEMBERSHIP:
         case IP_DROP_MEMBERSHIP:
         {
             struct ip_mreqn ip_mreq;
             struct target_ip_mreqn *target_smreqn;
+            int min_size;
 
             QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
                               sizeof(struct target_ip_mreq));
 
-            if (optlen < sizeof (struct target_ip_mreq) ||
+            if (optname == IP_MULTICAST_IF) {
+                min_size = sizeof(struct in_addr);
+            } else {
+                min_size = sizeof(struct target_ip_mreq);
+            }
+            if (optlen < min_size ||
                 optlen > sizeof (struct target_ip_mreqn)) {
                 return -TARGET_EINVAL;
             }
@@ -2149,13 +2156,14 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
                 return -TARGET_EFAULT;
             }
             ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
-            ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
-            if (optlen == sizeof(struct target_ip_mreqn)) {
-                ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
-                optlen = sizeof(struct ip_mreqn);
+            if (optlen >= sizeof(struct target_ip_mreq)) {
+                ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
+                if (optlen >= sizeof(struct target_ip_mreqn)) {
+                    __put_user(target_smreqn->imr_ifindex, &ip_mreq.imr_ifindex);
+                    optlen = sizeof(struct ip_mreqn);
+                }
             }
             unlock_user(target_smreqn, optval_addr, 0);
-
             ret = get_errno(setsockopt(sockfd, level, optname, &ip_mreq, optlen));
             break;
         }
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 5/6] linux-user: netlink: add netlink neighbour emulation
  2025-01-19  4:41 [PATCH v3 0/6] linux-user: Add support for various missing netlink sockopt entries deller
                   ` (3 preceding siblings ...)
  2025-01-19  4:41 ` [PATCH v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF deller
@ 2025-01-19  4:41 ` deller
  2025-01-19  4:41 ` [PATCH v3 6/6] linux-user: netlink: Add missing QEMU_IFLA entries deller
  5 siblings, 0 replies; 12+ messages in thread
From: deller @ 2025-01-19  4:41 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé, Laurent Vivier,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

From: Helge Deller <deller@gmx.de>

Fixes various warnings in the testsuite while building gupnp:
 gssdp-net-DEBUG: Failed to send netlink message: Operation not supported
 gupnp-context-DEBUG: Mismatch between host header and host IP (example.com, expected: 127.0.0.1)
 gupnp-context-DEBUG: Mismatch between host header and host port (80, expected 4711)
 gupnp-context-DEBUG: Mismatch between host header and host IP (192.168.1.2, expected: 127.0.0.1)
 gupnp-context-DEBUG: Mismatch between host header and host IP (fe80::01, expected: 127.0.0.1)
 gupnp-context-DEBUG: Mismatch between host header and host port (80, expected 4711)
 gupnp-context-DEBUG: Failed to parse HOST header from request: Invalid IPv6 address ?[fe80::01%1]? in URI
 gupnp-context-DEBUG: Failed to parse HOST header from request: Invalid IPv6 address ?[fe80::01%eth0]? in URI
 gupnp-context-DEBUG: Failed to parse HOST header from request: Could not parse port ?:1? in URI
 gupnp-context-DEBUG: Mismatch between host header and host IP (example.com, expected: ::1)
 gupnp-context-DEBUG: Mismatch between host header and host port (80, expected 4711)
 gupnp-context-DEBUG: Mismatch between host header and host IP (example.com, expected: ::1)
 gupnp-context-DEBUG: Mismatch between host header and host port (80, expected 4711)
 gupnp-context-DEBUG: Mismatch between host header and host IP (example.com, expected: ::1)

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/fd-trans.c | 100 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)

diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c
index a86ed2f4b4..a5e6c6b6f2 100644
--- a/linux-user/fd-trans.c
+++ b/linux-user/fd-trans.c
@@ -25,12 +25,16 @@
 #ifdef CONFIG_RTNETLINK
 #include <linux/rtnetlink.h>
 #include <linux/if_bridge.h>
+#include <linux/neighbour.h>
 #endif
 #include "qemu.h"
 #include "user-internals.h"
 #include "fd-trans.h"
 #include "signal-common.h"
 
+#define NDM_RTA(r)  ((struct rtattr*)(((char*)(r)) + \
+                    NLMSG_ALIGN(sizeof(struct ndmsg))))
+
 enum {
     QEMU_IFLA_BR_UNSPEC,
     QEMU_IFLA_BR_FORWARD_DELAY,
@@ -1210,6 +1214,35 @@ static abi_long host_to_target_data_route_rtattr(struct rtattr *rtattr)
     return 0;
 }
 
+static abi_long host_to_target_data_neigh_rtattr(struct rtattr *rtattr)
+{
+    struct nda_cacheinfo *ndac;
+    uint32_t *u32;
+
+    switch (rtattr->rta_type) {
+    case NDA_UNSPEC:
+    case NDA_DST:
+    case NDA_LLADDR:
+        break;
+    case NDA_PROBES:
+        u32 = RTA_DATA(rtattr);
+        *u32 = tswap32(*u32);
+        break;
+    case NDA_CACHEINFO:
+        ndac = RTA_DATA(rtattr);
+        ndac->ndm_confirmed = tswap32(ndac->ndm_confirmed);
+        ndac->ndm_used      = tswap32(ndac->ndm_used);
+        ndac->ndm_updated   = tswap32(ndac->ndm_updated);
+        ndac->ndm_refcnt    = tswap32(ndac->ndm_refcnt);
+        break;
+    default:
+        qemu_log_mask(LOG_UNIMP, "Unknown host to target NEIGH type: %d\n",
+                      rtattr->rta_type);
+        break;
+    }
+    return 0;
+}
+
 static abi_long host_to_target_link_rtattr(struct rtattr *rtattr,
                                          uint32_t rtattr_len)
 {
@@ -1231,12 +1264,20 @@ static abi_long host_to_target_route_rtattr(struct rtattr *rtattr,
                                           host_to_target_data_route_rtattr);
 }
 
+static abi_long host_to_target_neigh_rtattr(struct rtattr *rtattr,
+                                         uint32_t rtattr_len)
+{
+    return host_to_target_for_each_rtattr(rtattr, rtattr_len,
+                                          host_to_target_data_neigh_rtattr);
+}
+
 static abi_long host_to_target_data_route(struct nlmsghdr *nlh)
 {
     uint32_t nlmsg_len;
     struct ifinfomsg *ifi;
     struct ifaddrmsg *ifa;
     struct rtmsg *rtm;
+    struct ndmsg *ndm;
 
     nlmsg_len = nlh->nlmsg_len;
     switch (nlh->nlmsg_type) {
@@ -1263,6 +1304,17 @@ static abi_long host_to_target_data_route(struct nlmsghdr *nlh)
                                        nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
         }
         break;
+    case RTM_NEWNEIGH:
+    case RTM_DELNEIGH:
+    case RTM_GETNEIGH:
+        if (nlh->nlmsg_len >= NLMSG_LENGTH(sizeof(*ndm))) {
+            ndm = NLMSG_DATA(nlh);
+            ndm->ndm_ifindex = tswap32(ndm->ndm_ifindex);
+            ndm->ndm_state = tswap16(ndm->ndm_state);
+            host_to_target_neigh_rtattr(NDM_RTA(ndm),
+                                    nlmsg_len - NLMSG_LENGTH(sizeof(*ndm)));
+        }
+        break;
     case RTM_NEWROUTE:
     case RTM_DELROUTE:
     case RTM_GETROUTE:
@@ -1410,6 +1462,35 @@ static abi_long target_to_host_data_addr_rtattr(struct rtattr *rtattr)
     return 0;
 }
 
+static abi_long target_to_host_data_neigh_rtattr(struct rtattr *rtattr)
+{
+    struct nda_cacheinfo *ndac;
+    uint32_t *u32;
+
+    switch (rtattr->rta_type) {
+    case NDA_UNSPEC:
+    case NDA_DST:
+    case NDA_LLADDR:
+        break;
+    case NDA_PROBES:
+        u32 = RTA_DATA(rtattr);
+        *u32 = tswap32(*u32);
+        break;
+    case NDA_CACHEINFO:
+        ndac = RTA_DATA(rtattr);
+        ndac->ndm_confirmed = tswap32(ndac->ndm_confirmed);
+        ndac->ndm_used      = tswap32(ndac->ndm_used);
+        ndac->ndm_updated   = tswap32(ndac->ndm_updated);
+        ndac->ndm_refcnt    = tswap32(ndac->ndm_refcnt);
+        break;
+    default:
+        qemu_log_mask(LOG_UNIMP, "Unknown target NEIGH type: %d\n",
+                      rtattr->rta_type);
+        break;
+    }
+    return 0;
+}
+
 static abi_long target_to_host_data_route_rtattr(struct rtattr *rtattr)
 {
     uint32_t *u32;
@@ -1448,6 +1529,13 @@ static void target_to_host_addr_rtattr(struct rtattr *rtattr,
                                    target_to_host_data_addr_rtattr);
 }
 
+static void target_to_host_neigh_rtattr(struct rtattr *rtattr,
+                                     uint32_t rtattr_len)
+{
+    target_to_host_for_each_rtattr(rtattr, rtattr_len,
+                                   target_to_host_data_neigh_rtattr);
+}
+
 static void target_to_host_route_rtattr(struct rtattr *rtattr,
                                      uint32_t rtattr_len)
 {
@@ -1460,6 +1548,7 @@ static abi_long target_to_host_data_route(struct nlmsghdr *nlh)
     struct ifinfomsg *ifi;
     struct ifaddrmsg *ifa;
     struct rtmsg *rtm;
+    struct ndmsg *ndm;
 
     switch (nlh->nlmsg_type) {
     case RTM_NEWLINK:
@@ -1486,6 +1575,17 @@ static abi_long target_to_host_data_route(struct nlmsghdr *nlh)
                                        NLMSG_LENGTH(sizeof(*ifa)));
         }
         break;
+    case RTM_NEWNEIGH:
+    case RTM_DELNEIGH:
+    case RTM_GETNEIGH:
+        if (nlh->nlmsg_len >= NLMSG_LENGTH(sizeof(*ndm))) {
+            ndm = NLMSG_DATA(nlh);
+            ndm->ndm_ifindex = tswap32(ndm->ndm_ifindex);
+            ndm->ndm_state = tswap16(ndm->ndm_state);
+            target_to_host_neigh_rtattr(NDM_RTA(ndm), nlh->nlmsg_len -
+                                       NLMSG_LENGTH(sizeof(*ndm)));
+        }
+        break;
     case RTM_NEWROUTE:
     case RTM_DELROUTE:
     case RTM_GETROUTE:
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 6/6] linux-user: netlink: Add missing QEMU_IFLA entries
  2025-01-19  4:41 [PATCH v3 0/6] linux-user: Add support for various missing netlink sockopt entries deller
                   ` (4 preceding siblings ...)
  2025-01-19  4:41 ` [PATCH v3 5/6] linux-user: netlink: add netlink neighbour emulation deller
@ 2025-01-19  4:41 ` deller
  5 siblings, 0 replies; 12+ messages in thread
From: deller @ 2025-01-19  4:41 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé, Laurent Vivier,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

From: Helge Deller <deller@gmx.de>

This fixes the following qemu warnings when building debian gupnp package:
 Unknown host QEMU_IFLA type: 61
 Unknown host QEMU_IFLA type: 58
 Unknown host QEMU_IFLA type: 59
 Unknown host QEMU_IFLA type: 60
 Unknown host QEMU_IFLA type: 32820

QEMU_IFLA type 32820 is actually NLA_NESTED | QEMU_IFLA_PROP_LIST (a nested
entry), which is why rta_type needs to be masked with NLA_TYPE_MASK.

Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/fd-trans.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c
index a5e6c6b6f2..6a8775bb55 100644
--- a/linux-user/fd-trans.c
+++ b/linux-user/fd-trans.c
@@ -145,6 +145,14 @@ enum {
     QEMU_IFLA_PROTO_DOWN_REASON,
     QEMU_IFLA_PARENT_DEV_NAME,
     QEMU_IFLA_PARENT_DEV_BUS_NAME,
+    QEMU_IFLA_GRO_MAX_SIZE,
+    QEMU_IFLA_TSO_MAX_SIZE,
+    QEMU_IFLA_TSO_MAX_SEGS,
+    QEMU_IFLA_ALLMULTI,
+    QEMU_IFLA_DEVLINK_PORT,
+    QEMU_IFLA_GSO_IPV4_MAX_SIZE,
+    QEMU_IFLA_GRO_IPV4_MAX_SIZE,
+    QEMU_IFLA_DPLL_PIN,
     QEMU___IFLA_MAX
 };
 
@@ -986,6 +994,22 @@ static abi_long host_to_target_data_vfinfo_nlattr(struct nlattr *nlattr,
     return 0;
 }
 
+static abi_long host_to_target_data_prop_nlattr(struct nlattr *nlattr,
+                                                void *context)
+{
+    switch (nlattr->nla_type) {
+    /* string */
+    case QEMU_IFLA_ALT_IFNAME:
+        break;
+    default:
+        qemu_log_mask(LOG_UNIMP, "Unknown host PROP type: %d\n",
+                      nlattr->nla_type);
+        break;
+    }
+    return 0;
+}
+
+
 static abi_long host_to_target_data_link_rtattr(struct rtattr *rtattr)
 {
     uint32_t *u32;
@@ -994,7 +1018,7 @@ static abi_long host_to_target_data_link_rtattr(struct rtattr *rtattr)
     struct rtnl_link_ifmap *map;
     struct linkinfo_context li_context;
 
-    switch (rtattr->rta_type) {
+    switch (rtattr->rta_type & NLA_TYPE_MASK) {
     /* binary stream */
     case QEMU_IFLA_ADDRESS:
     case QEMU_IFLA_BROADCAST:
@@ -1032,6 +1056,12 @@ static abi_long host_to_target_data_link_rtattr(struct rtattr *rtattr)
     case QEMU_IFLA_CARRIER_DOWN_COUNT:
     case QEMU_IFLA_MIN_MTU:
     case QEMU_IFLA_MAX_MTU:
+    case QEMU_IFLA_GRO_MAX_SIZE:
+    case QEMU_IFLA_TSO_MAX_SIZE:
+    case QEMU_IFLA_TSO_MAX_SEGS:
+    case QEMU_IFLA_ALLMULTI:
+    case QEMU_IFLA_GSO_IPV4_MAX_SIZE:
+    case QEMU_IFLA_GRO_IPV4_MAX_SIZE:
         u32 = RTA_DATA(rtattr);
         *u32 = tswap32(*u32);
         break;
@@ -1127,6 +1157,10 @@ static abi_long host_to_target_data_link_rtattr(struct rtattr *rtattr)
         return host_to_target_for_each_nlattr(RTA_DATA(rtattr), rtattr->rta_len,
                                               NULL,
                                              host_to_target_data_vfinfo_nlattr);
+    case QEMU_IFLA_PROP_LIST:
+        return host_to_target_for_each_nlattr(RTA_DATA(rtattr), rtattr->rta_len,
+                                              NULL,
+                                             host_to_target_data_prop_nlattr);
     default:
         qemu_log_mask(LOG_UNIMP, "Unknown host QEMU_IFLA type: %d\n",
                       rtattr->rta_type);
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/6] linux-user: netlink: Add IP_PKTINFO cmsg parsing
  2025-01-19  4:41 ` [PATCH v3 3/6] linux-user: netlink: Add IP_PKTINFO " deller
@ 2025-01-20 18:10   ` Laurent Vivier
  0 siblings, 0 replies; 12+ messages in thread
From: Laurent Vivier @ 2025-01-20 18:10 UTC (permalink / raw)
  To: deller, Richard Henderson, Philippe Mathieu-Daudé,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

Le 19/01/2025 à 05:41, deller@kernel.org a écrit :
> From: Helge Deller <deller@gmx.de>
> 
> Fixes those warnings:
>   Unsupported host ancillary data: 0/8
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> 
> v2: (based on feedback by Laurent Vivier)
> - add target_in_pktinfo struct and fix copying target_in_addr fields
> ---
>   linux-user/syscall.c      | 10 ++++++++++
>   linux-user/syscall_defs.h |  6 ++++++
>   2 files changed, 16 insertions(+)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index a157abc40c..df8609b4d8 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1998,6 +1998,16 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
>                       (void *) &errh->offender, sizeof(errh->offender));
>                   break;
>               }
> +            case IP_PKTINFO:
> +            {
> +                struct in_pktinfo *pkti = data;
> +                struct target_in_pktinfo *target_pi = target_data;
> +
> +                __put_user(pkti->ipi_ifindex, &target_pi->ipi_ifindex);
> +                target_pi->ipi_spec_dst.s_addr = pkti->ipi_spec_dst.s_addr;
> +                target_pi->ipi_addr.s_addr = pkti->ipi_addr.s_addr;
> +                break;
> +            }
>               default:
>                   goto unimplemented;
>               }
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index faad9147c9..86d773add7 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -2622,6 +2622,12 @@ struct target_ucred {
>       abi_uint gid;
>   };
>   
> +struct target_in_pktinfo {
> +    abi_int               ipi_ifindex;
> +    struct target_in_addr ipi_spec_dst;
> +    struct target_in_addr ipi_addr;
> +};
> +
>   typedef abi_int target_timer_t;
>   
>   #define TARGET_SIGEV_MAX_SIZE 64

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF
  2025-01-19  4:41 ` [PATCH v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF deller
@ 2025-01-20 18:17   ` Laurent Vivier
  2025-01-20 20:42     ` Helge Deller
  0 siblings, 1 reply; 12+ messages in thread
From: Laurent Vivier @ 2025-01-20 18:17 UTC (permalink / raw)
  To: deller, Richard Henderson, Philippe Mathieu-Daudé,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

Le 19/01/2025 à 05:41, deller@kernel.org a écrit :
> From: Helge Deller <deller@gmx.de>
> 
> Add IP_MULTICAST_IF and share the code with IP_ADD_MEMBERSHIP / IP_DROP_MEMBERSHIP.
> Sharing the code makes sense, because the manpage of ip(7)  says:
> 
> IP_MULTICAST_IF (since Linux 1.2)
>        Set the local device for a multicast socket.  The argument
>        for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
>        ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
>        in_addr structure.  (The kernel determines which structure
>        is being passed based on the size passed in optlen.)  For
>        getsockopt(2), the argument is an in_addr structure.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> 
> v2: (based on feedback by Laurent Vivier)
> - refined commit message and restructure the copying of ip_mreqn fields
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index bbe2560927..4360543e20 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>               }
>               ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
>               break;
> +        case IP_MULTICAST_IF:
>           case IP_ADD_MEMBERSHIP:
>           case IP_DROP_MEMBERSHIP:
>           {
>               struct ip_mreqn ip_mreq;
>               struct target_ip_mreqn *target_smreqn;
> +            int min_size;
> 
>               QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
>                                 sizeof(struct target_ip_mreq));
> 
> -            if (optlen < sizeof (struct target_ip_mreq) ||
> +            if (optname == IP_MULTICAST_IF) {
> +                min_size = sizeof(struct in_addr);
> +            } else {
> +                min_size = sizeof(struct target_ip_mreq);
> +            }
> +            if (optlen < min_size ||
>                   optlen > sizeof (struct target_ip_mreqn)) {
>                   return -TARGET_EINVAL;
>               }
> @@ -2149,7 +2156,9 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>                   return -TARGET_EFAULT;
>               }
>               ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
> -            ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
> +            if (optlen >= sizeof(struct target_ip_mreq)) {
> +                ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
> +            }
>               if (optlen == sizeof(struct target_ip_mreqn)) {
>                   ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
>                   optlen = sizeof(struct ip_mreqn);

This part above seems to be in the commit message... and is the version 2, is this what you want?

> ---
>   linux-user/syscall.c | 20 ++++++++++++++------
>   1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index df8609b4d8..6ee02383da 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>               }
>               ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
>               break;
> +        case IP_MULTICAST_IF:
>           case IP_ADD_MEMBERSHIP:
>           case IP_DROP_MEMBERSHIP:
>           {
>               struct ip_mreqn ip_mreq;
>               struct target_ip_mreqn *target_smreqn;
> +            int min_size;
>   
>               QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
>                                 sizeof(struct target_ip_mreq));
>   
> -            if (optlen < sizeof (struct target_ip_mreq) ||
> +            if (optname == IP_MULTICAST_IF) {
> +                min_size = sizeof(struct in_addr);
> +            } else {
> +                min_size = sizeof(struct target_ip_mreq);
> +            }
> +            if (optlen < min_size ||
>                   optlen > sizeof (struct target_ip_mreqn)) {
>                   return -TARGET_EINVAL;
>               }
> @@ -2149,13 +2156,14 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>                   return -TARGET_EFAULT;
>               }
>               ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
> -            ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
> -            if (optlen == sizeof(struct target_ip_mreqn)) {
> -                ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
> -                optlen = sizeof(struct ip_mreqn);
> +            if (optlen >= sizeof(struct target_ip_mreq)) {
> +                ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
> +                if (optlen >= sizeof(struct target_ip_mreqn)) {
> +                    __put_user(target_smreqn->imr_ifindex, &ip_mreq.imr_ifindex);
> +                    optlen = sizeof(struct ip_mreqn);
> +                }
>               }
>               unlock_user(target_smreqn, optval_addr, 0);
> -
>               ret = get_errno(setsockopt(sockfd, level, optname, &ip_mreq, optlen));
>               break;
>           }

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/6] linux-user: netlink: Add missing IFA_PROTO to host_to_target_data_addr_rtattr()
  2025-01-19  4:41 ` [PATCH v3 1/6] linux-user: netlink: Add missing IFA_PROTO to host_to_target_data_addr_rtattr() deller
@ 2025-01-20 18:29   ` Laurent Vivier
  0 siblings, 0 replies; 12+ messages in thread
From: Laurent Vivier @ 2025-01-20 18:29 UTC (permalink / raw)
  To: deller, Richard Henderson, Philippe Mathieu-Daudé,
	qemu-devel, Stefan Hajnoczi
  Cc: deller

Le 19/01/2025 à 05:41, deller@kernel.org a écrit :
> From: Helge Deller <deller@gmx.de>
> 
> Fixes this warning:
>   Unknown host IFA type: 11
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
> ---
>   linux-user/fd-trans.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c
> index c04a97c73a..a86ed2f4b4 100644
> --- a/linux-user/fd-trans.c
> +++ b/linux-user/fd-trans.c
> @@ -1140,6 +1140,7 @@ static abi_long host_to_target_data_addr_rtattr(struct rtattr *rtattr)
>       /* binary: depends on family type */
>       case IFA_ADDRESS:
>       case IFA_LOCAL:
> +    case IFA_PROTO:
>           break;
>       /* string */
>       case IFA_LABEL:

Stefan has reported that it breaks build on ubuntu 22.04.
IFA_PROTO has been introduced in kernel v5.18.

I think you should define QEMU_IFA_XXXX enum as it was done for QEMU_IFLA_XXX, QEMU_RTA_XXX,...

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF
  2025-01-20 18:17   ` Laurent Vivier
@ 2025-01-20 20:42     ` Helge Deller
  2025-01-20 20:47       ` Helge Deller
  0 siblings, 1 reply; 12+ messages in thread
From: Helge Deller @ 2025-01-20 20:42 UTC (permalink / raw)
  To: Laurent Vivier, deller, Richard Henderson,
	Philippe Mathieu-Daudé, qemu-devel, Stefan Hajnoczi

On 1/20/25 19:17, Laurent Vivier wrote:
> Le 19/01/2025 à 05:41, deller@kernel.org a écrit :
>> From: Helge Deller <deller@gmx.de>
>>
>> Add IP_MULTICAST_IF and share the code with IP_ADD_MEMBERSHIP / IP_DROP_MEMBERSHIP.
>> Sharing the code makes sense, because the manpage of ip(7)  says:
>>
>> IP_MULTICAST_IF (since Linux 1.2)
>>        Set the local device for a multicast socket.  The argument
>>        for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
>>        ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
>>        in_addr structure.  (The kernel determines which structure
>>        is being passed based on the size passed in optlen.)  For
>>        getsockopt(2), the argument is an in_addr structure.
>>
>> Signed-off-by: Helge Deller <deller@gmx.de>
>>
>> v2: (based on feedback by Laurent Vivier)
>> - refined commit message and restructure the copying of ip_mreqn fields
>>
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> index bbe2560927..4360543e20 100644
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>>               }
>>               ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
>>               break;
>> +        case IP_MULTICAST_IF:
>>           case IP_ADD_MEMBERSHIP:
>>           case IP_DROP_MEMBERSHIP:
>>           {
>>               struct ip_mreqn ip_mreq;
>>               struct target_ip_mreqn *target_smreqn;
>> +            int min_size;
>>
>>               QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
>>                                 sizeof(struct target_ip_mreq));
>>
>> -            if (optlen < sizeof (struct target_ip_mreq) ||
>> +            if (optname == IP_MULTICAST_IF) {
>> +                min_size = sizeof(struct in_addr);
>> +            } else {
>> +                min_size = sizeof(struct target_ip_mreq);
>> +            }
>> +            if (optlen < min_size ||
>>                   optlen > sizeof (struct target_ip_mreqn)) {
>>                   return -TARGET_EINVAL;
>>               }
>> @@ -2149,7 +2156,9 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>>                   return -TARGET_EFAULT;
>>               }
>>               ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
>> -            ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
>> +            if (optlen >= sizeof(struct target_ip_mreq)) {
>> +                ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
>> +            }
>>               if (optlen == sizeof(struct target_ip_mreqn)) {
>>                   ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
>>                   optlen = sizeof(struct ip_mreqn);
> 
> This part above seems to be in the commit message... and is the version 2, is this what you want?

Ah... right.
I'll drop that patch version info, so it will be ok.


>> ---
>>   linux-user/syscall.c | 20 ++++++++++++++------
>>   1 file changed, 14 insertions(+), 6 deletions(-)
>>
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> index df8609b4d8..6ee02383da 100644
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>>               }
>>               ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
>>               break;
>> +        case IP_MULTICAST_IF:
>>           case IP_ADD_MEMBERSHIP:
>>           case IP_DROP_MEMBERSHIP:
>>           {
>>               struct ip_mreqn ip_mreq;
>>               struct target_ip_mreqn *target_smreqn;
>> +            int min_size;
>>               QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
>>                                 sizeof(struct target_ip_mreq));
>> -            if (optlen < sizeof (struct target_ip_mreq) ||
>> +            if (optname == IP_MULTICAST_IF) {
>> +                min_size = sizeof(struct in_addr);
>> +            } else {
>> +                min_size = sizeof(struct target_ip_mreq);
>> +            }
>> +            if (optlen < min_size ||
>>                   optlen > sizeof (struct target_ip_mreqn)) {
>>                   return -TARGET_EINVAL;
>>               }
>> @@ -2149,13 +2156,14 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>>                   return -TARGET_EFAULT;
>>               }
>>               ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
>> -            ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
>> -            if (optlen == sizeof(struct target_ip_mreqn)) {
>> -                ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
>> -                optlen = sizeof(struct ip_mreqn);
>> +            if (optlen >= sizeof(struct target_ip_mreq)) {
>> +                ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
>> +                if (optlen >= sizeof(struct target_ip_mreqn)) {
>> +                    __put_user(target_smreqn->imr_ifindex, &ip_mreq.imr_ifindex);
>> +                    optlen = sizeof(struct ip_mreqn);
>> +                }
>>               }
>>               unlock_user(target_smreqn, optval_addr, 0);
>> -
>>               ret = get_errno(setsockopt(sockfd, level, optname, &ip_mreq, optlen));
>>               break;
>>           }
> 
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>

Thanks!

Helge

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF
  2025-01-20 20:42     ` Helge Deller
@ 2025-01-20 20:47       ` Helge Deller
  0 siblings, 0 replies; 12+ messages in thread
From: Helge Deller @ 2025-01-20 20:47 UTC (permalink / raw)
  To: Laurent Vivier, deller, Richard Henderson,
	Philippe Mathieu-Daudé, qemu-devel, Stefan Hajnoczi

On 1/20/25 21:42, Helge Deller wrote:
> On 1/20/25 19:17, Laurent Vivier wrote:
>> Le 19/01/2025 à 05:41, deller@kernel.org a écrit :
>>> From: Helge Deller <deller@gmx.de>
>>>
>>> Add IP_MULTICAST_IF and share the code with IP_ADD_MEMBERSHIP / IP_DROP_MEMBERSHIP.
>>> Sharing the code makes sense, because the manpage of ip(7)  says:
>>>
>>> IP_MULTICAST_IF (since Linux 1.2)
>>>        Set the local device for a multicast socket.  The argument
>>>        for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
>>>        ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
>>>        in_addr structure.  (The kernel determines which structure
>>>        is being passed based on the size passed in optlen.)  For
>>>        getsockopt(2), the argument is an in_addr structure.
>>>
>>> Signed-off-by: Helge Deller <deller@gmx.de>
>>>
>>> v2: (based on feedback by Laurent Vivier)
>>> - refined commit message and restructure the copying of ip_mreqn fields
>>>
>>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>>> index bbe2560927..4360543e20 100644
>>> --- a/linux-user/syscall.c
>>> +++ b/linux-user/syscall.c
>>> @@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>>>               }
>>>               ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
>>>               break;
>>> +        case IP_MULTICAST_IF:
>>>           case IP_ADD_MEMBERSHIP:
>>>           case IP_DROP_MEMBERSHIP:
>>>           {
>>>               struct ip_mreqn ip_mreq;
>>>               struct target_ip_mreqn *target_smreqn;
>>> +            int min_size;
>>>
>>>               QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
>>>                                 sizeof(struct target_ip_mreq));
>>>
>>> -            if (optlen < sizeof (struct target_ip_mreq) ||
>>> +            if (optname == IP_MULTICAST_IF) {
>>> +                min_size = sizeof(struct in_addr);
>>> +            } else {
>>> +                min_size = sizeof(struct target_ip_mreq);
>>> +            }
>>> +            if (optlen < min_size ||
>>>                   optlen > sizeof (struct target_ip_mreqn)) {
>>>                   return -TARGET_EINVAL;
>>>               }
>>> @@ -2149,7 +2156,9 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
>>>                   return -TARGET_EFAULT;
>>>               }
>>>               ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
>>> -            ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
>>> +            if (optlen >= sizeof(struct target_ip_mreq)) {
>>> +                ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
>>> +            }
>>>               if (optlen == sizeof(struct target_ip_mreqn)) {
>>>                   ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
>>>                   optlen = sizeof(struct ip_mreqn);
>>
>> This part above seems to be in the commit message... and is the version 2, is this what you want?
> 
> Ah... right.
> I'll drop that patch version info, so it will be ok.

Oh.. NOW I see the real problem :-(
No, of course it's not what I wanted.
Will fix it.

Helge

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-01-20 20:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-19  4:41 [PATCH v3 0/6] linux-user: Add support for various missing netlink sockopt entries deller
2025-01-19  4:41 ` [PATCH v3 1/6] linux-user: netlink: Add missing IFA_PROTO to host_to_target_data_addr_rtattr() deller
2025-01-20 18:29   ` Laurent Vivier
2025-01-19  4:41 ` [PATCH v3 2/6] linux-user: Use unique error messages for cmsg parsing deller
2025-01-19  4:41 ` [PATCH v3 3/6] linux-user: netlink: Add IP_PKTINFO " deller
2025-01-20 18:10   ` Laurent Vivier
2025-01-19  4:41 ` [PATCH v3 4/6] linux-user: netlink: Add emulation of IP_MULTICAST_IF deller
2025-01-20 18:17   ` Laurent Vivier
2025-01-20 20:42     ` Helge Deller
2025-01-20 20:47       ` Helge Deller
2025-01-19  4:41 ` [PATCH v3 5/6] linux-user: netlink: add netlink neighbour emulation deller
2025-01-19  4:41 ` [PATCH v3 6/6] linux-user: netlink: Add missing QEMU_IFLA entries deller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).