qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE)
@ 2014-07-12  9:46 Joakim Tjernlund
  2014-07-12  9:46 ` [Qemu-devel] [PATCH 2/2 v2] linux-user: impl. sockaddr_ll Joakim Tjernlund
  2014-07-12 10:53 ` [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE) Peter Maydell
  0 siblings, 2 replies; 4+ messages in thread
From: Joakim Tjernlund @ 2014-07-12  9:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Joakim Tjernlund

---
 linux-user/syscall.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 57c1664..5a07d9c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1497,6 +1497,25 @@ set_timeout:
                 unlock_user_struct(tfprog, optval_addr, 1);
                 return ret;
         }
+	case TARGET_SO_BINDTODEVICE:
+	{
+		char *dev_ifname, *addr_ifname;
+
+		dev_ifname = lock_user(VERIFY_READ, optval_addr, optlen, 1);
+		if (!dev_ifname) {
+			return -TARGET_EFAULT;
+		}
+		if (optlen > IFNAMSIZ - 1) {
+			optlen = IFNAMSIZ - 1;
+		}
+		optname = SO_BINDTODEVICE;
+		addr_ifname = alloca(IFNAMSIZ);
+		memcpy(addr_ifname, dev_ifname, IFNAMSIZ);
+		addr_ifname[IFNAMSIZ - 1] = 0;
+		ret = get_errno(setsockopt(sockfd, level, optname, addr_ifname, optlen));
+		unlock_user (dev_ifname, optval_addr, 0);
+		return ret;
+	}
             /* Options with 'int' argument.  */
         case TARGET_SO_DEBUG:
 		optname = SO_DEBUG;
-- 
1.8.5.5

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

* [Qemu-devel] [PATCH 2/2 v2] linux-user: impl. sockaddr_ll
  2014-07-12  9:46 [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE) Joakim Tjernlund
@ 2014-07-12  9:46 ` Joakim Tjernlund
  2014-07-12 10:56   ` Peter Maydell
  2014-07-12 10:53 ` [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE) Peter Maydell
  1 sibling, 1 reply; 4+ messages in thread
From: Joakim Tjernlund @ 2014-07-12  9:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Joakim Tjernlund

Used by AF_PACKET sockets
---
 linux-user/syscall.c      |  7 +++++++
 linux-user/syscall_defs.h | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5a07d9c..a87fe74 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1140,6 +1140,13 @@ static inline abi_long target_to_host_sockaddr(struct sockaddr *addr,
 
     memcpy(addr, target_saddr, len);
     addr->sa_family = sa_family;
+    if (sa_family == AF_PACKET) {
+	    struct target_sockaddr_ll *lladdr;
+
+	    lladdr = (struct target_sockaddr_ll *)addr;
+	    lladdr->sll_ifindex = tswap32(lladdr->sll_ifindex);
+	    lladdr->sll_hatype = tswap16(lladdr->sll_hatype);
+    }
     unlock_user(target_saddr, target_addr, 0);
 
     return 0;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 8563027..329c9c5 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -121,6 +121,16 @@ struct target_sockaddr {
     uint8_t sa_data[14];
 };
 
+struct target_sockaddr_ll {
+	uint16_t sll_family;   /* Always AF_PACKET */
+	uint16_t sll_protocol; /* Physical layer protocol */
+	int      sll_ifindex;  /* Interface number */
+	uint16_t sll_hatype;   /* ARP hardware type */
+	uint8_t  sll_pkttype;  /* Packet type */
+	uint8_t  sll_halen;    /* Length of address */
+	uint8_t  sll_addr[8];  /* Physical layer address */
+};
+
 struct target_sock_filter {
     abi_ushort code;
     uint8_t jt;
-- 
1.8.5.5

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

* Re: [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE)
  2014-07-12  9:46 [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE) Joakim Tjernlund
  2014-07-12  9:46 ` [Qemu-devel] [PATCH 2/2 v2] linux-user: impl. sockaddr_ll Joakim Tjernlund
@ 2014-07-12 10:53 ` Peter Maydell
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2014-07-12 10:53 UTC (permalink / raw)
  To: Joakim Tjernlund; +Cc: QEMU Developers

On 12 July 2014 10:46, Joakim Tjernlund <Joakim.Tjernlund@transmode.se> wrote:
> ---
>  linux-user/syscall.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 57c1664..5a07d9c 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1497,6 +1497,25 @@ set_timeout:
>                  unlock_user_struct(tfprog, optval_addr, 1);
>                  return ret;
>          }
> +       case TARGET_SO_BINDTODEVICE:
> +       {
> +               char *dev_ifname, *addr_ifname;
> +
> +               dev_ifname = lock_user(VERIFY_READ, optval_addr, optlen, 1);
> +               if (!dev_ifname) {
> +                       return -TARGET_EFAULT;
> +               }
> +               if (optlen > IFNAMSIZ - 1) {
> +                       optlen = IFNAMSIZ - 1;
> +               }

This needs to go before the lock_user, not after.

> +               optname = SO_BINDTODEVICE;
> +               addr_ifname = alloca(IFNAMSIZ);
> +               memcpy(addr_ifname, dev_ifname, IFNAMSIZ);

You can't memcpy IFNAMSIZ bytes here because your source
might be shorter than that. memcpy() optlen bytes and set
addr_ifname[optlen] to 0.

> +               addr_ifname[IFNAMSIZ - 1] = 0;
> +               ret = get_errno(setsockopt(sockfd, level, optname, addr_ifname, optlen));
> +               unlock_user (dev_ifname, optval_addr, 0);
> +               return ret;
> +       }
>              /* Options with 'int' argument.  */
>          case TARGET_SO_DEBUG:
>                 optname = SO_DEBUG;
> --
> 1.8.5.5

Otherwise looks good; thanks.

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH 2/2 v2] linux-user: impl. sockaddr_ll
  2014-07-12  9:46 ` [Qemu-devel] [PATCH 2/2 v2] linux-user: impl. sockaddr_ll Joakim Tjernlund
@ 2014-07-12 10:56   ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2014-07-12 10:56 UTC (permalink / raw)
  To: Joakim Tjernlund; +Cc: QEMU Developers

On 12 July 2014 10:46, Joakim Tjernlund <Joakim.Tjernlund@transmode.se> wrote:
> Used by AF_PACKET sockets
> ---
>  linux-user/syscall.c      |  7 +++++++
>  linux-user/syscall_defs.h | 10 ++++++++++
>  2 files changed, 17 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 5a07d9c..a87fe74 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1140,6 +1140,13 @@ static inline abi_long target_to_host_sockaddr(struct sockaddr *addr,
>
>      memcpy(addr, target_saddr, len);
>      addr->sa_family = sa_family;
> +    if (sa_family == AF_PACKET) {
> +           struct target_sockaddr_ll *lladdr;
> +
> +           lladdr = (struct target_sockaddr_ll *)addr;
> +           lladdr->sll_ifindex = tswap32(lladdr->sll_ifindex);
> +           lladdr->sll_hatype = tswap16(lladdr->sll_hatype);
> +    }
>      unlock_user(target_saddr, target_addr, 0);

Your indentation here and in the struct definition below
looks wrong -- should be four-spaces. Otherwise

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

PS: your commit message is a little terse. I would suggest:

===
linux-user: handle AF_PACKET sockaddrs in target_to_host_sockaddr

Implement conversion of the AF_PACKET sockaddr subtype
in target_to_host_sockaddr.
===

thanks
-- PMM

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

end of thread, other threads:[~2014-07-12 10:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-12  9:46 [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE) Joakim Tjernlund
2014-07-12  9:46 ` [Qemu-devel] [PATCH 2/2 v2] linux-user: impl. sockaddr_ll Joakim Tjernlund
2014-07-12 10:56   ` Peter Maydell
2014-07-12 10:53 ` [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE) Peter Maydell

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).