Linux Packet Interface and Ethernet chip multicast filters

From: Danahy, JM John (4673) (DanahyJM@gvl.esys.com)
Date: Fri Aug 25 2000 - 17:54:15 EST


LINUX-NET

I am trying to read 802.3 link level messages using the packet interface
on Linux 2.2.5-15. I can send and receive the messages, however, I am
having
trouble filtering them. I continue to receive all broadcasts and multicasts
on the interface regardless of adding the multicast hardware address of
interest to the Ethernet cards multicast list.

I am using an Intel 82558 Lan controller chip that is built into the
motherboard with the eepro100 driver (2.2.5-15 kernel release and latest
version off the net). Driver is working fine for networking.

I have tried all possible values within the structure "struct sockaddr_ll".
In particular, I tried using "serverAddr.sll_protocol = htons(ETH_P_802_3)",
however, I was unable to read any messages.

Is it possible to filter addresses like ff:ff:ff:ff:ff:f3 or BROADCAST
messages using the eepro100 driver with the 82558 chip or am I
incorrectly using the packet interface? I realize it could be something
to do with the built-in lan on the motherboard, but I wanted to be
assured that there was not something wrong on the linux side before I
started debugging the driver and chip or went to a new card.

I have used 3Com cards but learned that they pass the messages to the
kernel without filtering. Can the kernel protocol layer be used to filter
hardware MAC addresses?

The following is test code that I am using to read/write to the socket:

    /*---------------------------------------------------*/

    struct sockaddr_ll serverAddr; /* server's address */
    struct sockaddr_ll clientAddr; /* client's address */

    memset(&serverAddr, 0, sizeof (serverAddr));
    memset(&clientAddr, 0, sizeof (clientAddr));

    sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_802_2));

    if (sock < 0)
        {
        perror ("cannot open socket");
        exit (1);
        }

    /* Need interface index for bind call */
    sprintf(ifr.ifr_name,"%s","eth0");
    if (ioctl(sock, SIOCGIFINDEX, (char *)&ifr) < 0)
      {
      printf("Error 0x%x getting interface (%d) index\n",
                                                errno,ifr.ifr_ifindex);
      close(sock);
      exit(-errno);
      }

   /* Set up our internet address, and bind it so the client can connect. */
    serverAddr.sll_family = AF_PACKET;
    serverAddr.sll_protocol = htons(ETH_P_802_2);
    serverAddr.sll_ifindex = ifr.ifr_ifindex;
    serverAddr.sll_hatype = ARPHRD_ETHER;
    serverAddr.sll_pkttype = PACKET_HOST;
    serverAddr.sll_halen = 6;

    memcpy((char *)iHWAddress, (char *)serverAddr.sll_addr, 6);

    if (bind (sock, (struct sockaddr *) &serverAddr, sizeof (serverAddr)) <
0)
        {
        perror ("bind error");
        exit (1);
        }

    /* check for a multicast address */
    if (iHWAddress[0] & 0x1)
      {
      /* multicast, so enable address on interface */
      printf("Setting multicast address ");
      for (i = 0; i < 6; i++ )
        {
        printf("%02.2x%s",iHWAddress[i],((i<5)?":":"\n"));
        }

      packmreq.mr_ifindex = ifr.ifr_ifindex;
      packmreq.mr_type = PACKET_MR_MULTICAST;
      packmreq.mr_alen = 6;
      bzero((char *)&packmreq.mr_address, 8);
      bcopy((const char *)iHWAddress, (char *)&packmreq.mr_address, 6);

      if ((i=setsockopt(sock, SOL_SOCKET, PACKET_ADD_MEMBERSHIP,
                                       &packmreq, sizeof(packmreq))) < 0)
        {
        printf("Error %d - setsockopt for multicast addresses\n",errno);
        exit(1);
        }
      }

    for (;;)
        {
        int numRead;

        if ((numRead = recvfrom(sock, buffer, size, 0,
                         (struct sockaddr *)&clientAddr, &len)) < 0 )
          {

          printf("Error 0x%x on recvfrom socket\n",errno);
          }
        else
          {
          printf("Received %d bytes on socket:\n",numRead);
          printClientSock(clientAddr);
          hexdump(buffer,numRead);
          }
        }

    /*---------------------------------------------------*/

Any ideas or comments would be greatly appreciated. Thanks in advance !!!

John M. Danahy

Sr. Electrical Eng. II
Raytheon Systems Company
CBN 99
P.O. Box 6056
Greenville, TX 75403.6056

voice: 903.457.4673
fax: 903.457.4413
email: DanahyJM@gvl.esys.com

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Aug 31 2000 - 21:00:31 EST