From 27a07827c4a56b65744c061fff78f7ca76cd934e Mon Sep 17 00:00:00 2001 From: Joakim Tjernlund Date: Fri, 11 Jul 2014 03:02:02 +0200 Subject: SIOCGIFINDEX: fix typo Wrong type was used in ioctl definition. Signed-off-by: Joakim Tjernlund Reviewed-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/ioctls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 07a00da727..609b27cf0b 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -118,7 +118,7 @@ IOCTL(SIOCSIFMEM, IOC_W, MK_PTR(MK_STRUCT(STRUCT_ptr_ifreq))) IOCTL(SIOCADDMULTI, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) IOCTL(SIOCDELMULTI, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) - IOCTL(SIOCGIFINDEX, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq))) + IOCTL(SIOCGIFINDEX, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_int_ifreq))) IOCTL(SIOCSIFLINK, 0, TYPE_NULL) IOCTL_SPECIAL(SIOCGIFCONF, IOC_W | IOC_R, do_ioctl_ifconf, MK_PTR(MK_STRUCT(STRUCT_ifconf))) -- cgit v1.2.3 From 451aaf688c709c91a0d511c24624104677cc754e Mon Sep 17 00:00:00 2001 From: Joakim Tjernlund Date: Sat, 12 Jul 2014 15:47:06 +0200 Subject: qemu-user: Impl. setsockopt(SO_BINDTODEVICE) Signed-off-by: Joakim Tjernlund Reviewed-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5a272d3d08..dcf13238e5 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; + + if (optlen > IFNAMSIZ - 1) { + optlen = IFNAMSIZ - 1; + } + dev_ifname = lock_user(VERIFY_READ, optval_addr, optlen, 1); + if (!dev_ifname) { + return -TARGET_EFAULT; + } + optname = SO_BINDTODEVICE; + addr_ifname = alloca(IFNAMSIZ); + memcpy(addr_ifname, dev_ifname, optlen); + addr_ifname[optlen] = 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; -- cgit v1.2.3 From 33a29b51c9fb56abd94d751dd3a51b84b82c8379 Mon Sep 17 00:00:00 2001 From: Joakim Tjernlund Date: Sat, 12 Jul 2014 15:47:07 +0200 Subject: linux-user: handle AF_PACKET sockaddrs in target_to_host_sockaddr Implement conversion of the AF_PACKET sockaddr subtype in target_to_host_sockaddr. Signed-off-by: Joakim Tjernlund Reviewed-by: Peter Maydell Signed-off-by: Riku Voipio --- 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 dcf13238e5..7163ade3f3 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 856302780f..c9e6323905 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; -- cgit v1.2.3 From 2dd08dfd9a553af3d53c6508e436b0c2aa5a469b Mon Sep 17 00:00:00 2001 From: Joakim Tjernlund Date: Fri, 11 Jul 2014 17:18:03 +0200 Subject: alloca one extra byte sockets target_to_host_sockaddr() may increase the lenth with 1 byte for AF_UNIX sockets so allocate 1 extra byte. Signed-off-by: Joakim Tjernlund Reviewed-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7163ade3f3..a50229d0d7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1984,7 +1984,7 @@ static abi_long do_connect(int sockfd, abi_ulong target_addr, return -TARGET_EINVAL; } - addr = alloca(addrlen); + addr = alloca(addrlen+1); ret = target_to_host_sockaddr(addr, target_addr, addrlen); if (ret) @@ -2005,7 +2005,7 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, if (msgp->msg_name) { msg.msg_namelen = tswap32(msgp->msg_namelen); - msg.msg_name = alloca(msg.msg_namelen); + msg.msg_name = alloca(msg.msg_namelen+1); ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name), msg.msg_namelen); if (ret) { @@ -2268,7 +2268,7 @@ static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, if (!host_msg) return -TARGET_EFAULT; if (target_addr) { - addr = alloca(addrlen); + addr = alloca(addrlen+1); ret = target_to_host_sockaddr(addr, target_addr, addrlen); if (ret) { unlock_user(host_msg, msg, 0); -- cgit v1.2.3 From b545f63fa974ebffd55d70ca615572d497e543dc Mon Sep 17 00:00:00 2001 From: Riku Voipio Date: Tue, 15 Jul 2014 17:01:55 +0300 Subject: linux-user: use TARGET_SA_ONSTACK in get_sigframe As reported by Laurent, which should use TARGET_SA_ONSTACK on arm, microblaze and openrisc targets like we do on all others. Practical matter is minimal as for almost all archs SA_ONSTACK is 0x08000000: http://lxr.free-electrons.com/ident?i=SA_ONSTACK Reported-by: Laurent Desnogues Signed-off-by: Riku Voipio --- linux-user/signal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index f3b43787fd..1141054be2 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -1305,7 +1305,7 @@ static abi_ulong get_sigframe(struct target_sigaction *ka, CPUARMState *env) /* * This is the X/Open sanctioned signal stack switching. */ - if ((ka->sa_flags & SA_ONSTACK) && !sas_ss_flags(sp)) { + if ((ka->sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp)) { sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; } @@ -3509,8 +3509,9 @@ static abi_ulong get_sigframe(struct target_sigaction *ka, { abi_ulong sp = env->regs[1]; - if ((ka->sa_flags & SA_ONSTACK) != 0 && !on_sig_stack(sp)) + if ((ka->sa_flags & TARGET_SA_ONSTACK) != 0 && !on_sig_stack(sp)) { sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; + } return ((sp - frame_size) & -8UL); } @@ -3891,7 +3892,7 @@ static inline abi_ulong get_sigframe(struct target_sigaction *ka, /* redzone */ /* This is the X/Open sanctioned signal stack switching. */ - if ((ka->sa_flags & SA_ONSTACK) != 0 && !onsigstack) { + if ((ka->sa_flags & TARGET_SA_ONSTACK) != 0 && !onsigstack) { sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; } -- cgit v1.2.3