Skip to contentSkip to conversation

ipv4: make do_ip_setsockopt for IP_MULTICAST_IF support ip_mreq struct

PATCH Applied Xiaotian Feng 3 participants 4 messages Sep 17, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 ipv4: make do_ip_setsockopt for IP_MULTICAST_IF support ip_mreq struct

ip_mreq and ip_mreqn is almost the same, and do_ip_setsockopt for IP_MULTICAST_IF part supported ip_mreqn struct. This patch adds support for ip_mreq struct.

Cc Patrick McHardy <[email protected]>
Cc David S. Miller <[email protected]>
---
 net/ipv4/ip_sockglue.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
net/ipv4/ip_sockglue.c +6 -1
index 5a29dce..1e8d026 100644
@@ -612,11 +612,16 @@ static int do_ip_setsockopt(struct sock *sk, int level,
 		 */
 
 		err = -EFAULT;
+		memset(&mreq, 0, sizeof(mreq));
+
 		if (optlen >= sizeof(struct ip_mreqn)) {
 			if (copy_from_user(&mreq, optval, sizeof(mreq)))
 				break;
+		} else if (optlen >= sizeof(struct ip_mreq)) {
+			if (copy_from_user(&mreq, optval,
+					   sizeof(struct ip_mreq)))
+				break;
 		} else if (optlen >= sizeof(struct in_addr)) {
-			memset(&mreq, 0, sizeof(mreq));
 			if (copy_from_user(&mreq.imr_address, optval,
 					   sizeof(struct in_addr)))
 				break;
Signature · 1 line
1.6.2.5
#1 lore raw

Xiaotian Feng wrote, at 09/17/2009 01:20 PM:

Quoted 3 lines

ip_mreq and ip_mreqn is almost the same, and do_ip_setsockopt for IP_MULTICAST_IF part supported ip_mreqn struct. This patch adds support for ip_mreq struct.

It's not meaning to support the ip_mreq struct, the imr_multiaddr member never be used by the IP_MULTICAST_IF.

In addition, using the option normally like this:
struct in_addr interface_addr;
setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, sizeof(interface_addr));

Do your patch suggest using the option like this?
struct ip_mreq mreq;
setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, &mreq, sizeof(mreq));

Best Regards
-----
Shan Wei

author
#2 lore raw
Quoted 8 lines · Shan Wei

Xiaotian Feng wrote, at 09/17/2009 01:20 PM:

Quoted 3 lines

ip_mreq and ip_mreqn is almost the same, and do_ip_setsockopt for IP_MULTICAST_IF part supported ip_mreqn struct. This patch adds support for ip_mreq struct.

It's not meaning to support the ip_mreq struct, the imr_multiaddr member never be used by the IP_MULTICAST_IF.

Quoted 8 lines

In addition, using the option normally like this:

   struct in_addr interface_addr;
   setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF,&interface_addr, sizeof(interface_addr));

Do your patch suggest using the option like this?

   struct ip_mreq  mreq;
   setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF,&mreq, sizeof(mreq));

In fact, current implemetation supports:

struct ip_mreqn mreqn;
setsockopt(socket, IPPROTO_IP, IP_MULTICAST_IF, &mreqn, sizeof(mreqn));

Then why not support mreq?

Quoted 5 lines

Best Regards
-----
Shan Wei

#3 lore raw

Hello!

Quoted 6 lines · Danny Feng

In fact, current implemetation supports:

struct ip_mreqn mreqn;
setsockopt(socket, IPPROTO_IP, IP_MULTICAST_IF, &mreqn, sizeof(mreqn));

Then why not support mreq?

Because support of ip_mreqn makes sense (it user interface index) and support of ip_mreq, which does not contain interface index, does not. "Polymorphic" IP_MULTICAST_IF was a stupid mistake (mine), which should not grow like a tumor.

Ack to patch #1, nack to #2.

Alexey