* [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type
@ 2015-10-28 19:12 Laurent Vivier
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 1/4] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Laurent Vivier @ 2015-10-28 19:12 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio, Laurent Vivier
This is obsolete, but if we want to use dhcp with some distros (like debian
ppc 8.2 jessie), we need it.
At the bind level, we are not able to know the socket type so we try to
guess it by analyzing the name. We manage only the case "ethX",
"ethX" in spk_device is similar to set htons(0x6574) in sll_protocol in the
normal case, and as this protocol does not exist, it's ok.
SOCK_PACKET uses network endian to encode protocol in socket()
in PACKET(7) :
protocol is the IEEE 802.3 protocol
number in network order. See the <linux/if_ether.h> include file for a
list of allowed protocols. When protocol is set to htons(ETH_P_ALL)
then all protocols are received. All incoming packets of that protocol
type will be passed to the packet socket before they are passed to the
protocols implemented in the kernel.
v2: Split the patch in 4 parts to manage protocol endianness (socket()) and
interface name (bind()) in different patches.
Use TargetFdTrans array to manage the SOCK_PACKET type special case in
bind().
The two others patches are here to introduce a new function in TargetFdTrans
to translate sockaddr data structure (rename previous functions to be
clear).
Laurent Vivier (4):
linux-user: SOCK_PACKET uses network endian to encode protocol in
socket()
linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure
fields accordingly
linux-user: add a function hook to translate sockaddr
linux-user: manage bind with a socket of SOCK_PACKET type.
linux-user/syscall.c | 95 ++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 81 insertions(+), 14 deletions(-)
--
2.4.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v2 1/4] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()
2015-10-28 19:12 [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type Laurent Vivier
@ 2015-10-28 19:13 ` Laurent Vivier
2015-10-28 19:14 ` Peter Maydell
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 2/4] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly Laurent Vivier
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Laurent Vivier @ 2015-10-28 19:13 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio, Laurent Vivier
in PACKET(7) :
packet_socket = socket(AF_PACKET, int socket_type, int protocol);
[...]
protocol is the IEEE 802.3 protocol
number in network order. See the <linux/if_ether.h> include file for a
list of allowed protocols. When protocol is set to htons(ETH_P_ALL)
then all protocols are received. All incoming packets of that protocol
type will be passed to the packet socket before they are passed to the
protocols implemented in the kernel.
[...]
Compatibility
In Linux 2.0, the only way to get a packet socket was by calling
socket(AF_INET, SOCK_PACKET, protocol).
We need to tswap16() the protocol because on big-endian, the ABI is
waiting for, for instance for ETH_P_ALL, 0x0003 (big endian ==
network order), whereas on little-endian it is waiting for 0x0300.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 4b4159d..7c724ab 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2089,6 +2089,12 @@ static abi_long do_socket(int domain, int type, int protocol)
if (domain == PF_NETLINK)
return -TARGET_EAFNOSUPPORT;
+
+ if (domain == AF_PACKET ||
+ (domain == AF_INET && type == SOCK_PACKET)) {
+ protocol = tswap16(protocol);
+ }
+
ret = get_errno(socket(domain, type, protocol));
if (ret >= 0) {
ret = sock_flags_fixup(ret, target_type);
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v2 2/4] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly
2015-10-28 19:12 [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type Laurent Vivier
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 1/4] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
@ 2015-10-28 19:13 ` Laurent Vivier
2015-10-28 19:15 ` Peter Maydell
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 3/4] linux-user: add a function hook to translate sockaddr Laurent Vivier
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Laurent Vivier @ 2015-10-28 19:13 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio, Laurent Vivier
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7c724ab..41b85b4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -295,20 +295,20 @@ static bitmask_transtbl fcntl_flags_tbl[] = {
{ 0, 0, 0, 0 }
};
-typedef abi_long (*TargetFdFunc)(void *, size_t);
+typedef abi_long (*TargetFdDataFunc)(void *, size_t);
typedef struct TargetFdTrans {
- TargetFdFunc host_to_target;
- TargetFdFunc target_to_host;
+ TargetFdDataFunc host_to_target_data;
+ TargetFdDataFunc target_to_host_data;
} TargetFdTrans;
static TargetFdTrans **target_fd_trans;
static unsigned int target_fd_max;
-static TargetFdFunc fd_trans_host_to_target(int fd)
+static TargetFdDataFunc fd_trans_host_to_target_data(int fd)
{
if (fd < target_fd_max && target_fd_trans[fd]) {
- return target_fd_trans[fd]->host_to_target;
+ return target_fd_trans[fd]->host_to_target_data;
}
return NULL;
}
@@ -5438,7 +5438,7 @@ host_to_target_signalfd_siginfo(struct signalfd_siginfo *tinfo,
tinfo->ssi_addr = tswap64(info->ssi_addr);
}
-static abi_long host_to_target_signalfd(void *buf, size_t len)
+static abi_long host_to_target_data_signalfd(void *buf, size_t len)
{
int i;
@@ -5450,7 +5450,7 @@ static abi_long host_to_target_signalfd(void *buf, size_t len)
}
static TargetFdTrans target_signalfd_trans = {
- .host_to_target = host_to_target_signalfd,
+ .host_to_target_data = host_to_target_data_signalfd,
};
static abi_long do_signalfd4(int fd, abi_long mask, int flags)
@@ -5867,8 +5867,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
goto efault;
ret = get_errno(read(arg1, p, arg3));
if (ret >= 0 &&
- fd_trans_host_to_target(arg1)) {
- ret = fd_trans_host_to_target(arg1)(p, ret);
+ fd_trans_host_to_target_data(arg1)) {
+ ret = fd_trans_host_to_target_data(arg1)(p, ret);
}
unlock_user(p, arg2, ret);
}
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v2 3/4] linux-user: add a function hook to translate sockaddr
2015-10-28 19:12 [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type Laurent Vivier
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 1/4] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 2/4] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly Laurent Vivier
@ 2015-10-28 19:13 ` Laurent Vivier
2015-10-28 19:18 ` Peter Maydell
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type Laurent Vivier
2015-10-28 19:21 ` [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type Peter Maydell
4 siblings, 1 reply; 12+ messages in thread
From: Laurent Vivier @ 2015-10-28 19:13 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio, Laurent Vivier
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 41 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 41b85b4..31b5c2c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -296,9 +296,11 @@ static bitmask_transtbl fcntl_flags_tbl[] = {
};
typedef abi_long (*TargetFdDataFunc)(void *, size_t);
+typedef abi_long (*TargetFdAddrFunc)(void *, abi_ulong, socklen_t);
typedef struct TargetFdTrans {
TargetFdDataFunc host_to_target_data;
TargetFdDataFunc target_to_host_data;
+ TargetFdAddrFunc target_to_host_addr;
} TargetFdTrans;
static TargetFdTrans **target_fd_trans;
@@ -313,6 +315,14 @@ static TargetFdDataFunc fd_trans_host_to_target_data(int fd)
return NULL;
}
+static TargetFdAddrFunc fd_trans_target_to_host_addr(int fd)
+{
+ if (fd < target_fd_max && target_fd_trans[fd]) {
+ return target_fd_trans[fd]->target_to_host_addr;
+ }
+ return NULL;
+}
+
static void fd_trans_register(int fd, TargetFdTrans *trans)
{
unsigned int oldmax;
@@ -2115,7 +2125,12 @@ static abi_long do_bind(int sockfd, abi_ulong target_addr,
addr = alloca(addrlen+1);
- ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ if (fd_trans_target_to_host_addr(sockfd)) {
+ ret = fd_trans_target_to_host_addr(sockfd)(addr, target_addr,
+ addrlen);
+ } else {
+ ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ }
if (ret)
return ret;
@@ -2135,7 +2150,12 @@ static abi_long do_connect(int sockfd, abi_ulong target_addr,
addr = alloca(addrlen+1);
- ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ if (fd_trans_target_to_host_addr(sockfd)) {
+ ret = fd_trans_target_to_host_addr(sockfd)(addr, target_addr,
+ addrlen);
+ } else {
+ ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ }
if (ret)
return ret;
@@ -2155,8 +2175,14 @@ 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+1);
- ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name),
- msg.msg_namelen);
+ if (fd_trans_target_to_host_addr(fd)) {
+ ret = fd_trans_target_to_host_addr(fd)(msg.msg_name,
+ tswapal(msgp->msg_name),
+ msg.msg_namelen);
+ } else {
+ ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name),
+ msg.msg_namelen);
+ }
if (ret) {
goto out2;
}
@@ -2418,7 +2444,12 @@ static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags,
return -TARGET_EFAULT;
if (target_addr) {
addr = alloca(addrlen+1);
- ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ if (fd_trans_target_to_host_addr(fd)) {
+ ret = fd_trans_target_to_host_addr(fd)(addr, target_addr,
+ addrlen);
+ } else {
+ ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ }
if (ret) {
unlock_user(host_msg, msg, 0);
return ret;
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type.
2015-10-28 19:12 [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type Laurent Vivier
` (2 preceding siblings ...)
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 3/4] linux-user: add a function hook to translate sockaddr Laurent Vivier
@ 2015-10-28 19:13 ` Laurent Vivier
2015-10-28 19:20 ` Peter Maydell
2015-10-28 19:21 ` [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type Peter Maydell
4 siblings, 1 reply; 12+ messages in thread
From: Laurent Vivier @ 2015-10-28 19:13 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, riku.voipio, Laurent Vivier
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 <laurent@vivier.eu>
---
linux-user/syscall.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 31b5c2c..f048437 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2086,6 +2086,30 @@ static int sock_flags_fixup(int fd, int target_type)
return fd;
}
+static abi_long packet_target_to_host_addr(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_addr,
+};
+
/* do_socket() Must return target values and target errnos. */
static abi_long do_socket(int domain, int type, int protocol)
{
@@ -2108,6 +2132,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.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 1/4] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 1/4] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
@ 2015-10-28 19:14 ` Peter Maydell
0 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2015-10-28 19:14 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers
On 28 October 2015 at 19:13, Laurent Vivier <laurent@vivier.eu> wrote:
> in PACKET(7) :
>
> packet_socket = socket(AF_PACKET, int socket_type, int protocol);
> [...]
> protocol is the IEEE 802.3 protocol
> number in network order. See the <linux/if_ether.h> include file for a
> list of allowed protocols. When protocol is set to htons(ETH_P_ALL)
> then all protocols are received. All incoming packets of that protocol
> type will be passed to the packet socket before they are passed to the
> protocols implemented in the kernel.
> [...]
> Compatibility
>
> In Linux 2.0, the only way to get a packet socket was by calling
> socket(AF_INET, SOCK_PACKET, protocol).
>
> We need to tswap16() the protocol because on big-endian, the ABI is
> waiting for, for instance for ETH_P_ALL, 0x0003 (big endian ==
> network order), whereas on little-endian it is waiting for 0x0300.
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 2/4] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 2/4] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly Laurent Vivier
@ 2015-10-28 19:15 ` Peter Maydell
0 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2015-10-28 19:15 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers
On 28 October 2015 at 19:13, Laurent Vivier <laurent@vivier.eu> wrote:
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> linux-user/syscall.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/4] linux-user: add a function hook to translate sockaddr
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 3/4] linux-user: add a function hook to translate sockaddr Laurent Vivier
@ 2015-10-28 19:18 ` Peter Maydell
0 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2015-10-28 19:18 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers
On 28 October 2015 at 19:13, Laurent Vivier <laurent@vivier.eu> wrote:
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> linux-user/syscall.c | 41 ++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 36 insertions(+), 5 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 41b85b4..31b5c2c 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -296,9 +296,11 @@ static bitmask_transtbl fcntl_flags_tbl[] = {
> };
>
> typedef abi_long (*TargetFdDataFunc)(void *, size_t);
> +typedef abi_long (*TargetFdAddrFunc)(void *, abi_ulong, socklen_t);
> typedef struct TargetFdTrans {
> TargetFdDataFunc host_to_target_data;
> TargetFdDataFunc target_to_host_data;
> + TargetFdAddrFunc target_to_host_addr;
> } TargetFdTrans;
>
> static TargetFdTrans **target_fd_trans;
> @@ -313,6 +315,14 @@ static TargetFdDataFunc fd_trans_host_to_target_data(int fd)
> return NULL;
> }
>
> +static TargetFdAddrFunc fd_trans_target_to_host_addr(int fd)
> +{
> + if (fd < target_fd_max && target_fd_trans[fd]) {
> + return target_fd_trans[fd]->target_to_host_addr;
> + }
> + return NULL;
This should probably do something sensible with a negative
input (either assert, or return NULL, I guess).
> +}
> +
> static void fd_trans_register(int fd, TargetFdTrans *trans)
> {
> unsigned int oldmax;
> @@ -2115,7 +2125,12 @@ static abi_long do_bind(int sockfd, abi_ulong target_addr,
>
> addr = alloca(addrlen+1);
>
> - ret = target_to_host_sockaddr(addr, target_addr, addrlen);
> + if (fd_trans_target_to_host_addr(sockfd)) {
> + ret = fd_trans_target_to_host_addr(sockfd)(addr, target_addr,
> + addrlen);
> + } else {
> + ret = target_to_host_sockaddr(addr, target_addr, addrlen);
> + }
> if (ret)
> return ret;
>
> @@ -2135,7 +2150,12 @@ static abi_long do_connect(int sockfd, abi_ulong target_addr,
>
> addr = alloca(addrlen+1);
>
> - ret = target_to_host_sockaddr(addr, target_addr, addrlen);
> + if (fd_trans_target_to_host_addr(sockfd)) {
> + ret = fd_trans_target_to_host_addr(sockfd)(addr, target_addr,
> + addrlen);
> + } else {
> + ret = target_to_host_sockaddr(addr, target_addr, addrlen);
> + }
> if (ret)
> return ret;
>
> @@ -2155,8 +2175,14 @@ 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+1);
> - ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name),
> - msg.msg_namelen);
> + if (fd_trans_target_to_host_addr(fd)) {
> + ret = fd_trans_target_to_host_addr(fd)(msg.msg_name,
> + tswapal(msgp->msg_name),
> + msg.msg_namelen);
> + } else {
> + ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name),
> + msg.msg_namelen);
> + }
> if (ret) {
> goto out2;
> }
> @@ -2418,7 +2444,12 @@ static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags,
> return -TARGET_EFAULT;
> if (target_addr) {
> addr = alloca(addrlen+1);
> - ret = target_to_host_sockaddr(addr, target_addr, addrlen);
> + if (fd_trans_target_to_host_addr(fd)) {
> + ret = fd_trans_target_to_host_addr(fd)(addr, target_addr,
> + addrlen);
> + } else {
> + ret = target_to_host_sockaddr(addr, target_addr, addrlen);
> + }
> if (ret) {
> unlock_user(host_msg, msg, 0);
> return ret;
The repetition here suggests we should pass the fd into
target_to_host_sockaddr and do the handling of
fd_trans_target_to_host_addr there.
thanks
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type.
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type Laurent Vivier
@ 2015-10-28 19:20 ` Peter Maydell
2015-10-28 19:25 ` Laurent Vivier
0 siblings, 1 reply; 12+ messages in thread
From: Peter Maydell @ 2015-10-28 19:20 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers
On 28 October 2015 at 19:13, Laurent Vivier <laurent@vivier.eu> wrote:
> 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 <laurent@vivier.eu>
> ---
> linux-user/syscall.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 31b5c2c..f048437 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2086,6 +2086,30 @@ static int sock_flags_fixup(int fd, int target_type)
> return fd;
> }
>
> +static abi_long packet_target_to_host_addr(void *host_addr,
> + abi_ulong target_addr,
> + socklen_t len)
Should the function name be ..._to_host_sockaddr ?
Otherwise,
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type
2015-10-28 19:12 [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type Laurent Vivier
` (3 preceding siblings ...)
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type Laurent Vivier
@ 2015-10-28 19:21 ` Peter Maydell
4 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2015-10-28 19:21 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers
On 28 October 2015 at 19:12, Laurent Vivier <laurent@vivier.eu> wrote:
> This is obsolete, but if we want to use dhcp with some distros (like debian
> ppc 8.2 jessie), we need it.
>
> At the bind level, we are not able to know the socket type so we try to
> guess it by analyzing the name. We manage only the case "ethX",
> "ethX" in spk_device is similar to set htons(0x6574) in sll_protocol in the
> normal case, and as this protocol does not exist, it's ok.
This cover letter is underselling the patchset, which now handles
more than just "ethX" :-)
I had a couple of minor comments but it looks pretty good overall.
thanks
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type.
2015-10-28 19:20 ` Peter Maydell
@ 2015-10-28 19:25 ` Laurent Vivier
2015-10-28 20:09 ` Peter Maydell
0 siblings, 1 reply; 12+ messages in thread
From: Laurent Vivier @ 2015-10-28 19:25 UTC (permalink / raw)
To: Peter Maydell; +Cc: Riku Voipio, QEMU Developers
Le 28/10/2015 20:20, Peter Maydell a écrit :
> On 28 October 2015 at 19:13, Laurent Vivier <laurent@vivier.eu> wrote:
>> 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 <laurent@vivier.eu>
>> ---
>> linux-user/syscall.c | 30 ++++++++++++++++++++++++++++++
>> 1 file changed, 30 insertions(+)
>>
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> index 31b5c2c..f048437 100644
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -2086,6 +2086,30 @@ static int sock_flags_fixup(int fd, int target_type)
>> return fd;
>> }
>>
>> +static abi_long packet_target_to_host_addr(void *host_addr,
>> + abi_ulong target_addr,
>> + socklen_t len)
>
> Should the function name be ..._to_host_sockaddr ?
It was what I did in my first draft, but as I have called the type
TargetFdDataFunc and TargetFdAddrFunc, I have chosen to call the
function _addr.
If you think it is better, I can change that.
>
> Otherwise,
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type.
2015-10-28 19:25 ` Laurent Vivier
@ 2015-10-28 20:09 ` Peter Maydell
0 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2015-10-28 20:09 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, QEMU Developers
On 28 October 2015 at 19:25, Laurent Vivier <laurent@vivier.eu> wrote:
>
>
> Le 28/10/2015 20:20, Peter Maydell a écrit :
>> On 28 October 2015 at 19:13, Laurent Vivier <laurent@vivier.eu> wrote:
>>> +static abi_long packet_target_to_host_addr(void *host_addr,
>>> + abi_ulong target_addr,
>>> + socklen_t len)
>>
>> Should the function name be ..._to_host_sockaddr ?
>
> It was what I did in my first draft, but as I have called the type
> TargetFdDataFunc and TargetFdAddrFunc, I have chosen to call the
> function _addr.
>
> If you think it is better, I can change that.
Well, it is sockaddr types we're handling, so it seems
a bit clearer to use that in the name.
thanks
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-10-28 20:09 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-28 19:12 [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type Laurent Vivier
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 1/4] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
2015-10-28 19:14 ` Peter Maydell
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 2/4] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly Laurent Vivier
2015-10-28 19:15 ` Peter Maydell
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 3/4] linux-user: add a function hook to translate sockaddr Laurent Vivier
2015-10-28 19:18 ` Peter Maydell
2015-10-28 19:13 ` [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type Laurent Vivier
2015-10-28 19:20 ` Peter Maydell
2015-10-28 19:25 ` Laurent Vivier
2015-10-28 20:09 ` Peter Maydell
2015-10-28 19:21 ` [Qemu-devel] [PATCH v2 0/4] linux-user: manage SOCK_PACKET socket type 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).