Skip to contentSkip to conversation

linux-user: make do_setsockopt support SOL_RAW ICMP_FILTER socket option

PATCH Superseded Jing Huang 3 participants 4 messages Jul 16, 2012

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jing Huang

author
#0 lore raw

PATCH v2 2/3 linux-user: make do_setsockopt support SOL_RAW ICMP_FILTER socket option

This patch makes do_setsockopt() support SOL_RAW ICMP_FILTER socket option.

---
 linux-user/syscall.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
linux-user/syscall.c +20 -0
index 28c8ba5..fc8690d 100644
@@ -60,6 +60,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 #include <linux/wireless.h>
+#include <linux/icmp.h>
 #include "qemu-common.h"
 #ifdef TARGET_GPROF
 #include <sys/gmon.h>
@@ -1442,6 +1443,25 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             goto unimplemented;
         }
         break;
+    case SOL_RAW:
+        switch (optname) {
+        case ICMP_FILTER:
+            /*struct icmp_filter takes an u32 value*/
+            optname = ICMP_FILTER;
+            if (optlen < sizeof(uint32_t)) {
+                return -TARGET_EINVAL;
+            }
+
+            if (get_user_u32(val, optval_addr)) {
+                return -TARGET_EFAULT;
+            }
+            ret = get_errno(setsockopt(sockfd, level, optname,
+                                        (char *)&val, sizeof(val)));
+            break;
+        default:
+            goto unimplemented;
+        }
+        break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
             /* Options with 'int' argument.  */
Signature · 1 line
1.7.8.6
#1 lore raw

2012/7/16 Jing Huang <[email protected]>:

Quoted 20 lines

This patch makes do_setsockopt() support SOL_RAW ICMP_FILTER socket option.

---
 linux-user/syscall.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
linux-user/syscall.c +1 -0
index 28c8ba5..fc8690d 100644
@@ -60,6 +60,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 #include <linux/wireless.h>
+#include <linux/icmp.h>
 #include "qemu-common.h"
 #ifdef TARGET_GPROF
 #include <sys/gmon.h>

linux-user/syscall.c static abi_long do_setsockopt(int sockfd, int level, int optname, · line 1450

Quoted 8 lines
linux-user/syscall.c +5 -0
@@ -1442,6 +1443,25 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             goto unimplemented;
         }
         break;
+    case SOL_RAW:
+        switch (optname) {
+        case ICMP_FILTER:
+            /*struct icmp_filter takes an u32 value*/
+            optname = ICMP_FILTER;

Needless assignment statements. optname already has the value ICMP_FILTER

linux-user/syscall.c static abi_long do_setsockopt(int sockfd, int level, int optname, · line 1459

Quoted 9 lines
linux-user/syscall.c +9 -0
+            if (optlen < sizeof(uint32_t)) {
+                return -TARGET_EINVAL;
+            }
+
+            if (get_user_u32(val, optval_addr)) {
+                return -TARGET_EFAULT;
+            }
+            ret = get_errno(setsockopt(sockfd, level, optname,
+                                        (char *)&val, sizeof(val)));

Dont need casting &val to char *.

Quoted 12 lines
linux-user/syscall.c +5 -1
+            break;
+        default:
+            goto unimplemented;
+        }
+        break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
             /* Options with 'int' argument.  */
--

1.7.8.6

Signature · 3 lines
Best Regards,

Dunrong Huang
author
#2 lore raw
Quoted 22 lines · Dunrong Huang

2012/7/16 Jing Huang <[email protected]>:

Quoted 21 lines

This patch makes do_setsockopt() support SOL_RAW ICMP_FILTER socket option.

---
 linux-user/syscall.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
linux-user/syscall.c +1 -0
index 28c8ba5..fc8690d 100644
@@ -60,6 +60,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 #include <linux/wireless.h>
+#include <linux/icmp.h>
 #include "qemu-common.h"
 #ifdef TARGET_GPROF
 #include <sys/gmon.h>
@@ -1442,6 +1443,25 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             goto unimplemented;
Quoted 8 lines

linux-user/syscall.c static abi_long do_setsockopt(int sockfd, int level, int optname, · line 1450

Quoted 7 lines
linux-user/syscall.c +5 -0
         }
         break;
+    case SOL_RAW:
+        switch (optname) {
+        case ICMP_FILTER:
+            /*struct icmp_filter takes an u32 value*/
+            optname = ICMP_FILTER;

Needless assignment statements. optname already has the value ICMP_FILTER

do_setsockopt() lacks level=SOL_RAW and optname=ICMP_FILTER.

The ping in linux-user guest invokes:
setsockopt(icmp_sock, SOL_RAW, ICMP_FILTER, (char *)&filt, sizeof(filt)) in main() function.

Quoted 10 lines

linux-user/syscall.c static abi_long do_setsockopt(int sockfd, int level, int optname, · line 1459

Quoted 9 lines
linux-user/syscall.c +9 -0
+            if (optlen < sizeof(uint32_t)) {
+                return -TARGET_EINVAL;
+            }
+
+            if (get_user_u32(val, optval_addr)) {
+                return -TARGET_EFAULT;
+            }
+            ret = get_errno(setsockopt(sockfd, level, optname,
+                                        (char *)&val, sizeof(val)));

Dont need casting &val to char *.

I refer to the definition of setsockopt() in linux-kernel/net/tipc/socket.c

Quoted 19 lines
Quoted 9 lines
linux-user/syscall.c +5 -1
+            break;
+        default:
+            goto unimplemented;
+        }
+        break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
             /* Options with 'int' argument.  */
--
Quoted 3 lines

1.7.8.6

--
Best Regards,

Dunrong Huang

#3 lore raw
In reply to Jing Huang
Quoted 21 lines · Jing Huang

This patch makes do_setsockopt() support SOL_RAW ICMP_FILTER socket option.

---
 linux-user/syscall.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
linux-user/syscall.c +1 -0
index 28c8ba5..fc8690d 100644
@@ -60,6 +60,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 #include <linux/wireless.h>
+#include <linux/icmp.h>
 #include "qemu-common.h"
 #ifdef TARGET_GPROF

#include <sys/gmon.h>

linux-user/syscall.c static abi_long do_setsockopt(int sockfd, int level, int optname, · line 1449

Quoted 7 lines
linux-user/syscall.c +4 -0
@@ -1442,6 +1443,25 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             goto unimplemented;
         }
         break;
+    case SOL_RAW:
+        switch (optname) {
+        case ICMP_FILTER:
+            /*struct icmp_filter takes an u32 value*/

Please add spaces after the "/*" and before the "*/".

linux-user/syscall.c static abi_long do_setsockopt(int sockfd, int level, int optname, · line 1450

Quoted 1 line
linux-user/syscall.c +1 -0
+            optname = ICMP_FILTER;

Pointless assignment, as Dunrong says.

linux-user/syscall.c static abi_long do_setsockopt(int sockfd, int level, int optname, · line 1459

Quoted 9 lines
linux-user/syscall.c +9 -0
+            if (optlen < sizeof(uint32_t)) {
+                return -TARGET_EINVAL;
+            }
+
+            if (get_user_u32(val, optval_addr)) {
+                return -TARGET_EFAULT;
+            }
+            ret = get_errno(setsockopt(sockfd, level, optname,
+                                        (char *)&val, sizeof(val)));

Agreed with Dunrong, this is a pointless cast; setsockopt() takes a void* for the optval pointer.
(Compare posix spec and see the other calls to setsockopt in this function. The prototype of the internal kernel function implementing setsockopt is not relevant because that is not the API that the kernel exposes to userspace.)

Quoted 11 lines
linux-user/syscall.c +5 -1
+            break;
+        default:
+            goto unimplemented;
+        }
+        break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
             /* Options with 'int' argument.  */
--

1.7.8.6

-- PMM