netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Socket receives packet to multicast group to which it was not joined since kernel 3.13.10-1
@ 2014-05-12 16:38 Yurij M. Plotnikov
  2014-05-12 17:18 ` Eric Dumazet
  0 siblings, 1 reply; 12+ messages in thread
From: Yurij M. Plotnikov @ 2014-05-12 16:38 UTC (permalink / raw)
  To: netdev; +Cc: Alexandra N. Kossovsky

[-- Attachment #1: Type: text/plain, Size: 810 bytes --]

On kernel 3.13.10-1 I see that socket joined to one multicast group 
receives packets to another multicast address. That can be reproduced by 
the following example:

1. socket(DGRAM) -> 3
2. bind(3, 0.0.0.0:12345) -> 0
3. setsockopt(3, IP_MULTICAST_IF, {224.168.2.9, 7}) -> 0
// "7" is correct interface index

4. Send packet from peer host to 224.168.2.9:12345
5. poll({3, POLLIN}) -> 1
6. recv(3) -> <data_length>

5. Send packet from peer host to 225.168.2.9:12345
// Note that the address is not the same!
6. poll({3, POLLIN}) -> 1
7. recv(3) -> <data_length>

I checked kernel 3.12.6-2, there is no such problem. I have placed 
simple C-program in attachment to reproduce the behaviour. It should be 
called:
./mult_recv <mcast_address> <interface index> i.e. in example above:
./mult_recv 224.168.2.9 7

[-- Attachment #2: mult_recv.c --]
[-- Type: text/x-csrc, Size: 1785 bytes --]

#include <stdio.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
#include <poll.h>

int
main(int argc, char *argv[])
{
    int sock;
    int rc;
    struct sockaddr_in addr;
    struct ip_mreqn req;
    char buf[256];
    struct pollfd fds;

    if (argc < 2)
    {
        printf("\nToo few arguments\n");
        return 1;
    }

    sock = socket(PF_INET, SOCK_DGRAM, 0);
    printf("socket() -> %d(%d)\n", sock, errno);

    addr.sin_family = AF_INET;
    addr.sin_port = htons(12345);
    addr.sin_addr.s_addr = INADDR_ANY;
    rc = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
    printf("bind() -> %d(%d)\n", rc, errno);

    memset((void *)&req, 0, sizeof(req));
    rc = inet_aton(argv[1], &req.imr_multiaddr);
    printf("inet_aton() -> %d(%d)\n", rc, errno);
    req.imr_ifindex = atoi(argv[2]);

    rc = setsockopt(sock, SOL_IP, IP_ADD_MEMBERSHIP, &req, sizeof(req));
    printf("setsockopt() -> %d(%d)\n", rc, errno);

    printf("Send packet to %s:12345 address...", argv[1]);
    getchar();

    fds.fd = sock;
    fds.events = POLLIN;
    rc = poll(&fds, 1, 1000);
    printf("poll() -> %d(%d)\n", rc, errno);

    if (rc != 1)
    {
        printf("The packet was not received.\n");
        return 1;
    }

    rc = recv(sock, buf, sizeof(buf), 0);
    printf("recv() -> %d(%d)\n", rc, errno);

    printf("Send packet to different multicast address(with 12345 port)...");
    getchar();

    rc = poll(&fds, 1, 1000);
    printf("poll() -> %d(%d)\n", rc, errno);

    if (rc != 0)
    {
        printf("The packet to different multicast address was received.\n");
        rc = recv(sock, buf, sizeof(buf), 0);
        printf("recv() -> %d(%d)\n", rc, errno);
        return 1;
    }
    printf("The behaviour is correct\n");

    return 0;
}

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-06-04  7:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-12 16:38 Socket receives packet to multicast group to which it was not joined since kernel 3.13.10-1 Yurij M. Plotnikov
2014-05-12 17:18 ` Eric Dumazet
2014-05-13  6:25   ` Yurij M. Plotnikov
2014-05-13 21:36     ` Shawn Bohrer
2014-05-14 20:40       ` Shawn Bohrer
2015-05-24  4:55         ` Oliver Graff
2015-05-26 17:41           ` Shawn Bohrer
2015-05-26 17:59             ` Eric Dumazet
2015-06-01 16:34               ` [PATCH] ipv4/udp: Verify multicast group is ours in upd_v4_early_demux() Shawn Bohrer
2015-06-01 20:11                 ` Sergei Shtylyov
2015-06-03 21:27                   ` [PATCH v2] " Shawn Bohrer
2015-06-04  7:46                     ` David Miller

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).