linux-user: convert sockaddr_ll from host to target
PATCH 1/1 linux-user: convert sockaddr_ll from host to target
As we convert sockaddr for AF_PACKET family for sendto() (target to host) we need also to convert this for getsockname() (host to target).
arping uses getsockname() to get the the interface address and uses this address with sendto().
Tested with:
/sbin/arping -D -q -c2 -I eno1 192.168.122.88
...getsockname(3, {sa_family=AF_PACKET, proto=0x806, if2, pkttype=PACKET_HOST, addr(6)={1, 10c37b6b9a76}, [18]) = 0
...
sendto(3, "..." 28, 0,
{sa_family=AF_PACKET, proto=0x806, if2, pkttype=PACKET_HOST,
addr(6)={1, ffffffffffff}, 20) = 28...
--- linux-user/syscall.c | 5 +++++ 1 file changed, 5 insertions(+)
linux-user/syscall.c +5 -0
@@ -100,6 +100,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,#include <linux/route.h> #include <linux/filter.h> #include <linux/blkpg.h> +#include <netpacket/packet.h> #include <linux/netlink.h> #ifdef CONFIG_RTNETLINK #include <linux/rtnetlink.h>
@@ -1379,6 +1380,10 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr,struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; target_nl->nl_pid =tswap32 (target_nl->nl_pid); target_nl->nl_groups =tswap32 (target_nl->nl_groups); + }else if (addr->sa_family ==AF_PACKET ) { +struct sockaddr_ll *target_ll = (struct sockaddr_ll *)target_saddr; + target_ll->sll_ifindex =tswap32 (target_ll->sll_ifindex); + target_ll->sll_hatype =tswap16 (target_ll->sll_hatype); }unlock_user (target_saddr, target_addr, len);
Signature · 1 line
2.5.5
Quoted 29 lines · Laurent Vivier
As we convert sockaddr for
AF_PACKETfamily forsendto()(target to host) we need also to convert this forgetsockname()(host to target).arping uses
getsockname()to get the the interface address and uses this address withsendto().Tested with:
/sbin/arping -D -q -c2 -I eno1 192.168.122.88...
getsockname(3, {sa_family=AF_PACKET, proto=0x806, if2, pkttype=PACKET_HOST, addr(6)={1, 10c37b6b9a76}, [18])= 0
...
sendto(3, "..." 28, 0,{sa_family=AF_PACKET, proto=0x806, if2, pkttype=PACKET_HOST, addr(6)={1, ffffffffffff}, 20) = 28...
Signed-off-by Laurent Vivier <[email protected]>--- linux-user/syscall.c | 5 +++++ 1 file changed, 5 insertions(+)linux-user/syscall.c +0
-0
linux-user/syscall.c int __clone2(int (*fn)(void *), void *child_stack_base, · line 103
Quoted 4 lines
linux-user/syscall.c +1
-0@@ -100,6 +100,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,#include <linux/route.h> #include <linux/filter.h> #include <linux/blkpg.h> +#include <netpacket/packet.h>
Do we need the new include? We already use struct sockaddr_ll without it.
linux-user/syscall.c static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, · line 1388
Quoted 13 lines
linux-user/syscall.c +4
-0#include <linux/netlink.h> #ifdef CONFIG_RTNETLINK #include <linux/rtnetlink.h> @@ -1379,6 +1380,10 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr,struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; target_nl->nl_pid =tswap32 (target_nl->nl_pid); target_nl->nl_groups =tswap32 (target_nl->nl_groups); + }else if (addr->sa_family ==AF_PACKET ) { +struct sockaddr_ll *target_ll = (struct sockaddr_ll *)target_saddr; + target_ll->sll_ifindex =tswap32 (target_ll->sll_ifindex); + target_ll->sll_hatype =tswap16 (target_ll->sll_hatype); }unlock_user (target_saddr, target_addr, len);
Otherwise
thanks
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Laurent Vivier
As we convert sockaddr for
AF_PACKETfamily forsendto()(target to host) we need also to convert this forgetsockname()(host to target).arping uses
getsockname()to get the the interface address and uses this address withsendto().Tested with:
/sbin/arping -D -q -c2 -I eno1 192.168.122.88...
getsockname(3, {sa_family=AF_PACKET, proto=0x806, if2, pkttype=PACKET_HOST, addr(6)={1, 10c37b6b9a76}, [18])= 0
...
sendto(3, "..." 28, 0,{sa_family=AF_PACKET, proto=0x806, if2, pkttype=PACKET_HOST, addr(6)={1, ffffffffffff}, 20) = 28...
Signed-off-by Laurent Vivier <[email protected]>--- linux-user/syscall.c | 5 +++++ 1 file changed, 5 insertions(+)
Quoted 12 lines
linux-user/syscall.c int __clone2(int (*fn)(void *), void *child_stack_base, · line 103
Quoted 9 lines
linux-user/syscall.c +1
-0@@ -100,6 +100,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,#include <linux/route.h> #include <linux/filter.h> #include <linux/blkpg.h> +#include <netpacket/packet.h> Do we need the new include? We already use struct
sockaddr_llwithout it.
we already use target_sockaddr_ll, not sockaddr_ll.
Quoted 16 lines
Quoted 5 lines
linux-user/syscall.c +0
-0#include <linux/netlink.h> #ifdef CONFIG_RTNETLINK #include <linux/rtnetlink.h> linux-user/syscall.c static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, · line 1388
Quoted 9 lines
linux-user/syscall.c +4
-0@@ -1379,6 +1380,10 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr,struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; target_nl->nl_pid =tswap32 (target_nl->nl_pid); target_nl->nl_groups =tswap32 (target_nl->nl_groups); + }else if (addr->sa_family ==AF_PACKET ) { +struct sockaddr_ll *target_ll = (struct sockaddr_ll *)target_saddr; + target_ll->sll_ifindex =tswap32 (target_ll->sll_ifindex); + target_ll->sll_hatype =tswap16 (target_ll->sll_hatype); }unlock_user (target_saddr, target_addr, len);Otherwise
Quoted 1 line
Reviewed-by Peter Maydell <[email protected]>
Thanks,
Laurent
Quoted 7 lines · Laurent Vivier
Quoted 2 lines · Peter Maydell
Do we need the new include? We already use struct
sockaddr_llwithout it.we already use
target_sockaddr_ll, notsockaddr_ll.
Oh yes; I got confused with sockaddr_nl I think.
thanks
-- PMM
Quoted 38 lines · Laurent Vivier
As we convert sockaddr for
AF_PACKETfamily forsendto()(target to host) we need also to convert this forgetsockname()(host to target).arping uses
getsockname()to get the the interface address and uses this address withsendto().Tested with:
/sbin/arping -D -q -c2 -I eno1 192.168.122.88...
getsockname(3, {sa_family=AF_PACKET, proto=0x806, if2, pkttype=PACKET_HOST, addr(6)={1, 10c37b6b9a76}, [18])= 0
...
sendto(3, "..." 28, 0,{sa_family=AF_PACKET, proto=0x806, if2, pkttype=PACKET_HOST, addr(6)={1, ffffffffffff}, 20) = 28...
Signed-off-by Laurent Vivier <[email protected]>--- linux-user/syscall.c | 5 +++++ 1 file changed, 5 insertions(+)linux-user/syscall.c +1
-0@@ -100,6 +100,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,#include <linux/route.h> #include <linux/filter.h> #include <linux/blkpg.h> +#include <netpacket/packet.h> #include <linux/netlink.h> #ifdef CONFIG_RTNETLINK #include <linux/rtnetlink.h>
linux-user/syscall.c static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, · line 1389
Quoted 10 lines
linux-user/syscall.c +4
-0@@ -1379,6 +1380,10 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr,struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; target_nl->nl_pid =tswap32 (target_nl->nl_pid); target_nl->nl_groups =tswap32 (target_nl->nl_groups); + }else if (addr->sa_family ==AF_PACKET ) { +struct sockaddr_ll *target_ll = (struct sockaddr_ll *)target_saddr; + target_ll->sll_ifindex =tswap32 (target_ll->sll_ifindex); + target_ll->sll_hatype =tswap16 (target_ll->sll_hatype); }unlock_user (target_saddr, target_addr, len);
It would be good to have this patch in 2.7 as this bug breaks dhclient:
dhclient uses arping to check the IP address is not already in use and then hangs. I've seen that, at least, in a fedora21 + qemu-ppc64 container.
Thanks,
Laurent