Skip to content

Commit f65464c

Browse files
committed
linux-user: netlink: Add emulation of IP_MULTICAST_IF
Add IP_MULTICAST_IF and share the code with IP_ADD_MEMBERSHIP / IP_DROP_MEMBERSHIP. Sharing the code makes sense, because the manpage of ip(7) says: IP_MULTICAST_IF (since Linux 1.2) Set the local device for a multicast socket. The argument for setsockopt(2) is an ip_mreqn or (since Linux 3.5) ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an in_addr structure. (The kernel determines which structure is being passed based on the size passed in optlen.) For getsockopt(2), the argument is an in_addr structure. Signed-off-by: Helge Deller <deller@gmx.de> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
1 parent 017fc66 commit f65464c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

linux-user/syscall.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,16 +2130,23 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
21302130
}
21312131
ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
21322132
break;
2133+
case IP_MULTICAST_IF:
21332134
case IP_ADD_MEMBERSHIP:
21342135
case IP_DROP_MEMBERSHIP:
21352136
{
21362137
struct ip_mreqn ip_mreq;
21372138
struct target_ip_mreqn *target_smreqn;
2139+
int min_size;
21382140

21392141
QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
21402142
sizeof(struct target_ip_mreq));
21412143

2142-
if (optlen < sizeof (struct target_ip_mreq) ||
2144+
if (optname == IP_MULTICAST_IF) {
2145+
min_size = sizeof(struct in_addr);
2146+
} else {
2147+
min_size = sizeof(struct target_ip_mreq);
2148+
}
2149+
if (optlen < min_size ||
21432150
optlen > sizeof (struct target_ip_mreqn)) {
21442151
return -TARGET_EINVAL;
21452152
}
@@ -2149,13 +2156,14 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
21492156
return -TARGET_EFAULT;
21502157
}
21512158
ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
2152-
ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
2153-
if (optlen == sizeof(struct target_ip_mreqn)) {
2154-
ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
2155-
optlen = sizeof(struct ip_mreqn);
2159+
if (optlen >= sizeof(struct target_ip_mreq)) {
2160+
ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
2161+
if (optlen >= sizeof(struct target_ip_mreqn)) {
2162+
__put_user(target_smreqn->imr_ifindex, &ip_mreq.imr_ifindex);
2163+
optlen = sizeof(struct ip_mreqn);
2164+
}
21562165
}
21572166
unlock_user(target_smreqn, optval_addr, 0);
2158-
21592167
ret = get_errno(setsockopt(sockfd, level, optname, &ip_mreq, optlen));
21602168
break;
21612169
}

0 commit comments

Comments
 (0)