OpenWrt Forum Archive

Topic: multicast problem

The content of this topic has been archived on 19 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I am trying to run a small SSDP multicaster on the router itself (Openwrt trunk snapshot, r35673, TP-Link WR842ND), but it seems the router does not deliver the packets, at least Wireshark does not recive it in on my PC, firewall is turned off. OpenWRT's firewall is default, but I also tried to accept/flush it.

This is the source code, it works fine on a Linux box on the same subnet:

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

#define LOCAL_IF_ADDR "192.168.1.1"
#define MCAST_ADDR "239.255.255.250"
#define MCAST_PORT 1900

static const char* DATA1 =
  "NOTIFY * HTTP/1.1\r\n"
  "HOST: 239.255.255.250:1900\r\n"
  "LOCATION: http://192.168.1.1/upnp/device.xmlrn"
  "SERVER: Razor\r\n"
  "CACHE-CONTROL: max-age=1800\r\n"
  "NT: urn:schemas-upnp-org:device:MediaServer:1\r\n"
  "NTS: ssdp:alive\r\n"
  "USN: uuid:7B00805E-8000-11E2-9B8F-62BA6188709B::urn:schemas-upnp-org:device:MediaServer:1\r\n\r\n";

static const char* DATA2 =
  "NOTIFY * HTTP/1.1\r\n"
  "HOST: 239.255.255.250:1900\r\n"
  "LOCATION: http://192.168.1.1/upnp/device.xmlrn"
  "SERVER: Razor\r\n"
  "CACHE-CONTROL: max-age=1800\r\n"
  "NT: uuid:7B00805E-8000-11E2-9B8F-62BA6188709B\r\n"
  "NTS: ssdp:alive\r\n"
  "USN: uuid:7B00805E-8000-11E2-9B8F-62BA6188709B\r\n\r\n";



    struct in_addr localInterface;

    struct sockaddr_in groupSock;

    int sd;





    int main (int argc, char *argv[ ])

    {
     unsigned char ttl = 3;


    sd = socket(AF_INET, SOCK_DGRAM, 0);
    if(sd < 0)
    {
      perror("Opening datagram socket error");
      exit(1);
    }
    else
      printf("Opening the datagram socket...OK.\n");


    memset((char *) &groupSock, 0, sizeof(groupSock));
    groupSock.sin_family = AF_INET;
    groupSock.sin_addr.s_addr = inet_addr(MCAST_ADDR);
    groupSock.sin_port = htons(MCAST_PORT);


    memset((char *) &localInterface, 0, sizeof(localInterface));
    localInterface.s_addr = inet_addr(LOCAL_IF_ADDR);
    if(setsockopt(sd, IPPROTO_IP, IP_MULTICAST_IF, (char *)&localInterface, sizeof(localInterface)) < 0)
    {
      perror("Setting local interface error");
      exit(1);
    }
    else
      printf("Setting the local interface...OK\n");

    if(setsockopt(sd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
    {
      perror("Setting TTL failed");
      exit(1);
    }
    else
      printf("Setting TTL...OK\n");


/*
  struct ip_mreq group;
  memset((char *) &group, 0, sizeof(group));
  group.imr_multiaddr.s_addr = inet_addr(MCAST_ADDR);
  group.imr_interface.s_addr = inet_addr(LOCAL_IF_ADDR);

  if(setsockopt(sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&group, sizeof(group)) < 0)
  {
    perror("Adding multicast group error");
    close(sd);
    exit(1);
  }
  else
    printf("Adding multicast group...OK.\n");
*/

  while(1) {


    if(sendto(sd, DATA1, strlen(DATA1), 0, (struct sockaddr*)&groupSock, sizeof(groupSock)) < 0)

    {perror("Sending datagram message error");}

    else

      printf("Sending datagram message...OK\n");

    if(sendto(sd, DATA2, strlen(DATA2), 0, (struct sockaddr*)&groupSock, sizeof(groupSock)) < 0)

    {perror("Sending datagram message error");}

    else

      printf("Sending datagram message...OK\n");

  sleep(60);
  }



    return 0;

    }


tcpdump output on the router:

# tcpdump -vvv -i br-lan -n -X udp
tcpdump: listening on br-lan, link-type EN10MB (Ethernet), capture size 65535 bytes
15:22:53.560237 IP (tos 0x0, ttl 3, id 0, offset 0, flags [DF], proto UDP (17), length 322)
    192.168.1.1.55474 > 239.255.255.250.1900: [bad udp cksum 0xb2e3 -> 0xf57b!] UDP, length 294
        0x0000:  4500 0142 0000 4000 0311 c507 c0a8 0101  E..B..@.........
        0x0010:  efff fffa d8b2 076c 012e b2e3 4e4f 5449  .......l....NOTI
        0x0020:  4659 202a 2048 5454 502f 312e 310d 0a48  FY.*.HTTP/1.1..H
        0x0030:  4f53 543a 2032 3339 2e32 3535 2e32 3535  OST:.239.255.255
        0x0040:  2e32 3530 3a31 3930 300d 0a4c 4f43 4154  .250:1900..LOCAT
        0x0050:  494f 4e3a 2068 7474 703a 2f2f 3139 322e  ION:.http://192.
        0x0060:  3136 382e 312e 312f 7570 6e70 2f64 6576  168.1.1/upnp/dev
        0x0070:  6963 652e 786d 6c0d 0a53 4552 5645 523a  ice.xml..SERVER:
        0x0080:  2052 617a 6f72 0d0a 4341 4348 452d 434f  .Razor..CACHE-CO
        0x0090:  4e54 524f 4c3a 206d 6178 2d61 6765 3d31  NTROL:.max-age=1
        0x00a0:  3830 300d 0a4e 543a 2075 726e 3a73 6368  800..NT:.urn:sch
        0x00b0:  656d 6173 2d75 706e 702d 6f72 673a 6465  emas-upnp-org:de
        0x00c0:  7669 6365 3a4d 6564 6961 5365 7276 6572  vice:MediaServer
        0x00d0:  3a31 0d0a 4e54 533a 2073 7364 703a 616c  :1..NTS:.ssdp:al
        0x00e0:  6976 650d 0a55 534e 3a20 7575 6964 3a37  ive..USN:.uuid:7
        0x00f0:  4230 3038 3035 452d 3830 3030 2d31 3145  B00805E-8000-11E
        0x0100:  322d 3942 3846 2d36 3242 4136 3138 3837  2-9B8F-62BA61887
        0x0110:  3039 423a 3a75 726e 3a73 6368 656d 6173  09B::urn:schemas
        0x0120:  2d75 706e 702d 6f72 673a 6465 7669 6365  -upnp-org:device
        0x0130:  3a4d 6564 6961 5365 7276 6572 3a31 0d0a  :MediaServer:1..
        0x0140:  0d0a                                     ..
15:22:53.560384 IP (tos 0x0, ttl 3, id 0, offset 0, flags [DF], proto UDP (17), length 279)
    192.168.1.1.55474 > 239.255.255.250.1900: [bad udp cksum 0xb2b8 -> 0x4867!] UDP, length 251
        0x0000:  4500 0117 0000 4000 0311 c532 c0a8 0101  E.....@....2....
        0x0010:  efff fffa d8b2 076c 0103 b2b8 4e4f 5449  .......l....NOTI
        0x0020:  4659 202a 2048 5454 502f 312e 310d 0a48  FY.*.HTTP/1.1..H
        0x0030:  4f53 543a 2032 3339 2e32 3535 2e32 3535  OST:.239.255.255
        0x0040:  2e32 3530 3a31 3930 300d 0a4c 4f43 4154  .250:1900..LOCAT
        0x0050:  494f 4e3a 2068 7474 703a 2f2f 3139 322e  ION:.http://192.
        0x0060:  3136 382e 312e 312f 7570 6e70 2f64 6576  168.1.1/upnp/dev
        0x0070:  6963 652e 786d 6c0d 0a53 4552 5645 523a  ice.xml..SERVER:
        0x0080:  2052 617a 6f72 0d0a 4341 4348 452d 434f  .Razor..CACHE-CO
        0x0090:  4e54 524f 4c3a 206d 6178 2d61 6765 3d31  NTROL:.max-age=1
        0x00a0:  3830 300d 0a4e 543a 2075 7569 643a 3742  800..NT:.uuid:7B
        0x00b0:  3030 3830 3545 2d38 3030 302d 3131 4532  00805E-8000-11E2
        0x00c0:  2d39 4238 462d 3632 4241 3631 3838 3730  -9B8F-62BA618870
        0x00d0:  3942 0d0a 4e54 533a 2073 7364 703a 616c  9B..NTS:.ssdp:al
        0x00e0:  6976 650d 0a55 534e 3a20 7575 6964 3a37  ive..USN:.uuid:7
        0x00f0:  4230 3038 3035 452d 3830 3030 2d31 3145  B00805E-8000-11E
        0x0100:  322d 3942 3846 2d36 3242 4136 3138 3837  2-9B8F-62BA61887
        0x0110:  3039 420d 0a0d 0a                        09B....



# ifconfig
br-lan    Link encap:Ethernet  HWaddr 64:70:02:3D:D8:D1
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5934366 errors:0 dropped:315 overruns:0 frame:0
          TX packets:11882007 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:603833549 (575.8 MiB)  TX bytes:15967947259 (14.8 GiB)

eth0      Link encap:Ethernet  HWaddr 64:70:02:3D:D8:D1
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4519239 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9483585 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:542846161 (517.6 MiB)  TX bytes:4158062116 (3.8 GiB)
          Interrupt:5

eth1      Link encap:Ethernet  HWaddr 64:70:02:3D:D8:D3
          inet addr:178.48.84.61  Bcast:178.48.87.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28436446 errors:0 dropped:0 overruns:2 frame:0
          TX packets:25924817 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3368624931 (3.1 GiB)  TX bytes:882241550 (841.3 MiB)
          Interrupt:4

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:51778 errors:0 dropped:0 overruns:0 frame:0
          TX packets:51778 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:58270773 (55.5 MiB)  TX bytes:58270773 (55.5 MiB)

wlan0     Link encap:Ethernet  HWaddr 64:70:02:3D:D8:D2
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1565250 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2591171 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:240275575 (229.1 MiB)  TX bytes:3356872224 (3.1 GiB)



Have you got any hints?

Additional info: if i reboot the router then the app "works" for a few rounds (I can see the packet pairs in wireshark ~3 times) and then without touching anyhing, its over, no more packets arrive. Restart the process doesnt change anything.
I assume the source/tool itself is correct and I have some Openwrt/kernel related issue here.

Solution:

ip route add 239.255.255.250 dev eth0

(after setting up this route, sending out multicast packets work fine, no source address binding neither setting IP_MULTICAST_IF is neccessary)

A notice could be added to the MiniDLNA wiki page, as it might help others too.

Ticket #13151 is still unsolved...

However: the ip address of the external interface is set as source ip for these multicast packets instead of ip of br-lan, which i dont like at all, and binding the source ip of the multicast packets results that they are dropped again.
Currently I set up an ip alias in the same subnet to the internal interface (eth0), have no ip route and bind my multicast sockets to this alias address. Its ugly but still better than having the public ip.

I dont think this should work this way.

rsctm wrote:

However: the ip address of the external interface is set as source ip for these multicast packets instead of ip of br-lan, which i dont like at all, and binding the source ip of the multicast packets results that they are dropped again.
Currently I set up an ip alias in the same subnet to the internal interface (eth0), have no ip route and bind my multicast sockets to this alias address. Its ugly but still better than having the public ip.

I dont think this should work this way.

hi, can you explain how to do this step by step ? i have that same problem and same router that you... now i use AA RC1 to use minidlna without any problems ;/

So this means AA is not affected by this bug? I think the problem itself should be find and fixed instead of using my ugly workarounds.

yes, on AA rc1 this problem dosn't appear... i use dlna server for couple weaks and everything works fine... but i like to have newest firmware in every device tongue thats why i search how to get it work on newest trunk

ticket still unsolved sad

someone told me that minidlna multicast works ok on trunk from 10 April and dont disappear from network...

So please test and confirm it smile

The discussion might have continued from here.