All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 0/2][NETNS49][IPV4][IGMP] activate multicast per namespace
@ 2007-10-12 17:10 Daniel Lezcano
  2007-10-12 17:10 ` [patch 1/2][NETNS49][IPV4][IGMP] make igmp proc " Daniel Lezcano
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Daniel Lezcano @ 2007-10-12 17:10 UTC (permalink / raw)
  To: ebiederm-aS9lmoZGLiVWk0Htik3J/w; +Cc: containers-qjLDD68F18O7TbgM5vRIOg

The following patches activate the multicast sockets for
the namespaces. The results is a traffic going through 
differents namespaces. So if there are several applications
listenning to the same multicast group/port, running in
different namespaces, they will receive multicast packets.

The following program helps to test that.

Note that the TTL field is set to 2 to avoid to packets to
be dropped while going through the network namespace.

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int run(int server, int daddr, int dport, int saddr, int nbmsg, int delay, int timeout)
{
        int fd,i;
        struct ip_mreq mreq;
        struct sockaddr_in addr;

        socklen_t len = sizeof(addr);
        int val;

        memset(&addr,0,len);
        memset(&mreq, 0, sizeof(mreq));

        mreq.imr_multiaddr.s_addr  = daddr;
        mreq.imr_interface.s_addr  = saddr;

        addr.sin_family       = AF_INET;
        addr.sin_port         = dport;
        addr.sin_addr.s_addr  = INADDR_ANY;

        if ((fd = socket(AF_INET,SOCK_DGRAM,0)) == -1) {
                perror("socket");
                return 1;
        }

        if (server)
                if (bind(fd, (struct sockaddr*)&addr, sizeof(addr))) {
                        perror("bind");
                        return 1;
                }

        if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq))) {
                perror("setsockopt ADD_MEMBER_SHIP");
                return 1;
        }

        val = 2;
        if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &val, sizeof(val))) {
                perror("setsockopt MULTICAST_TTL");
                return 1;
        }

        /* val = 0; */
        val = 1;
        if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &val, sizeof(val))) {
                perror("setsockopt MULTICAST_LOOP");
                return 1;
        }

        addr.sin_addr.s_addr  = daddr;

        if (server) {
                for (i = 0; i < nbmsg; i++) {
                        alarm(timeout);
                        if (recv(fd,&i,sizeof(i),0) == -1) {
                                perror("recv");
                                return 1;
                        }
                        fprintf(stderr, ".");
                }
        } else {
                for (i = 0; i < nbmsg; i++) {
                        if (sendto(fd, &i, sizeof(i), MSG_CONFIRM,
                                   (const struct sockaddr*)&addr, len) == -1) {
                                perror("sendto");
                                return 1;
                        }
                        usleep(delay);
                }
        }

        fprintf(stderr," - done.\n");
        return 0;
}

int main(int argc, char* argv[])
{
        in_addr_t dest = inet_addr("234.5.6.7");
        int port = htons(10000);

        return run(argc > 1, dest, port, 0, 1000, 50000, 60);
}

-- 

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

end of thread, other threads:[~2007-10-15 18:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-12 17:10 [patch 0/2][NETNS49][IPV4][IGMP] activate multicast per namespace Daniel Lezcano
2007-10-12 17:10 ` [patch 1/2][NETNS49][IPV4][IGMP] make igmp proc " Daniel Lezcano
2007-10-12 17:10 ` [patch 2/2][NETNS49][IPV4][IGMP] make igmp " Daniel Lezcano
     [not found] ` <20071012171013.105324992-WECHFHqYCmGD/CxQmPlnQ0FT0OZdM7KVQQ4Iyu8u01E@public.gmane.org>
2007-10-12 18:50   ` [patch 0/2][NETNS49][IPV4][IGMP] activate multicast " Eric W. Biederman
     [not found]     ` <m17ils9ngz.fsf-T1Yj925okcoyDheHMi7gv2pdwda3JcWeAL8bYrjMMd8@public.gmane.org>
2007-10-12 21:03       ` Daniel Lezcano
     [not found]         ` <470FE130.8040403-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2007-10-12 21:37           ` Eric W. Biederman
2007-10-15  8:31           ` [Devel] " Denis V. Lunev
     [not found]             ` <47132576.6020508-3ImXcnM4P+0@public.gmane.org>
2007-10-15 16:14               ` Daniel Lezcano
     [not found]                 ` <471391F1.4090804-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2007-10-15 18:03                   ` Eric W. Biederman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.