[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/17] linux-user: manage bind with a socket of SOCK_
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL 08/17] linux-user: manage bind with a socket of SOCK_PACKET type. |
Date: |
Mon, 11 Jan 2016 16:16:10 +0200 |
From: Laurent Vivier <address@hidden>
This is obsolete, but if we want to use dhcp with an old distro (like debian
etch), we need it. Some users (like dhclient) use SOCK_PACKET with AF_PACKET
and the kernel allows that.
packet(7)
In Linux 2.0, the only way to get a packet socket was by calling
socket(AF_INET, SOCK_PACKET, protocol). This is still supported but
strongly deprecated. The main difference between the two methods is
that SOCK_PACKET uses the old struct sockaddr_pkt to specify an inter‐
face, which doesn't provide physical layer independence.
struct sockaddr_pkt {
unsigned short spkt_family;
unsigned char spkt_device[14];
unsigned short spkt_protocol;
};
spkt_family contains the device type, spkt_protocol is the IEEE 802.3
protocol type as defined in <sys/if_ether.h> and spkt_device is the
device name as a null-terminated string, for example, eth0.
Signed-off-by: Laurent Vivier <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3484132..94d64fa 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2090,6 +2090,30 @@ static int sock_flags_fixup(int fd, int target_type)
return fd;
}
+static abi_long packet_target_to_host_sockaddr(void *host_addr,
+ abi_ulong target_addr,
+ socklen_t len)
+{
+ struct sockaddr *addr = host_addr;
+ struct target_sockaddr *target_saddr;
+
+ target_saddr = lock_user(VERIFY_READ, target_addr, len, 1);
+ if (!target_saddr) {
+ return -TARGET_EFAULT;
+ }
+
+ memcpy(addr, target_saddr, len);
+ addr->sa_family = tswap16(target_saddr->sa_family);
+ /* spkt_protocol is big-endian */
+
+ unlock_user(target_saddr, target_addr, 0);
+ return 0;
+}
+
+static TargetFdTrans target_packet_trans = {
+ .target_to_host_addr = packet_target_to_host_sockaddr,
+};
+
/* do_socket() Must return target values and target errnos. */
static abi_long do_socket(int domain, int type, int protocol)
{
@@ -2112,6 +2136,12 @@ static abi_long do_socket(int domain, int type, int
protocol)
ret = get_errno(socket(domain, type, protocol));
if (ret >= 0) {
ret = sock_flags_fixup(ret, target_type);
+ if (type == SOCK_PACKET) {
+ /* Manage an obsolete case :
+ * if socket type is SOCK_PACKET, bind by name
+ */
+ fd_trans_register(ret, &target_packet_trans);
+ }
}
return ret;
}
--
2.6.4
- [Qemu-devel] [PULL 00/17] linux-user queque, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 01/17] linux-user: add signalfd/signalfd4 syscalls, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 06/17] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 04/17] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 05/17] linux-user: SOCK_PACKET uses network endian to encode protocol in socket(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 03/17] linux-user: in poll(), if nfds is 0, pfd can be NULL, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 02/17] linux-user: correctly align target_epoll_event, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 08/17] linux-user: manage bind with a socket of SOCK_PACKET type.,
riku . voipio <=
- [Qemu-devel] [PULL 17/17] linux-user/mmap.c: Use end instead of real_end in target_mmap, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 11/17] linux-user/mmap.c: Always zero MAP_ANONYMOUS memory in mmap_frag(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 07/17] linux-user: add a function hook to translate sockaddr, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 14/17] linux-user/syscall.c: Use SOL_SOCKET instead of level for setsockopt(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 15/17] linux-user: Update m68k syscall definitions to match Linux 4.4., riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 10/17] linux-user, sh4: fix signal retcode address, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 09/17] linux-user: check fd is >= 0 in fd_trans_host_to_target_data/fd_trans_host_to_target_addr, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 13/17] linux-user: enable sigaltstack for all architectures, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 12/17] unicore32: convert get_sp_from_cpustate from macro to inline, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 16/17] linux-user: Add SOCKOP_sendmmsg and SOCKOP_recvmmsg socket call, wire them up., riku . voipio, 2016/01/11