Subject: Fw: [Bug 207097] New: recvmsg returning buffer filled with zeros

From: Stephen Hemminger <[email-masked]>
Date: Mon, 6 Apr 2020 08:03:43 -0700

This is most likely just a programming error in the sample application.
Someone want to investigate it?

Begin forwarded message:

Date: Sat, 04 Apr 2020 11:00:23 +0000
From: [email-masked]
To: [email-masked]
Subject: [Bug 207097] New: recvmsg returning buffer filled with zeros

https://bugzilla.kernel.org/show_bug.cgi?id=207097

            Bug ID: 207097
           Summary: recvmsg returning buffer filled with zeros
           Product: Networking
           Version: 2.5
    Kernel Version: 5.3.0-46-generic
          Hardware: All
                OS: Linux
              Tree: Mainline
            Status: NEW
          Severity: blocking
          Priority: P1
         Component: Other
          Assignee: [email-masked]
          Reporter: [email-masked]
        Regression: No

I am creating socket as follows:

=============================

static void create_new_read_socket( const uint64_t card_pos )
{
     const int read_sock = available_cards[card_pos].read_socket = socket(
PF_PACKET, SOCK_RAW|SOCK_NONBLOCK, htons( ETH_P_ALL ) );

     if( read_sock < 0 ) 
     {
          fprintf( stderr, "%s %d Unable to create read_sock", __func__,
__LINE__ );
          return;
     }

     struct ifreq ifr;
     strncpy( ifr.ifr_name, available_cards[card_pos].card_name, IFNAMSIZ );
     if( ioctl( read_sock, SIOCGIFFLAGS, &ifr ) == -1 )
     {
          fprintf( stderr, "%s %d Unable to get flag", __func__, __LINE__ );
          return;
     }
     available_cards[card_pos].ifr_flags_backup = ifr.ifr_flags;
     ifr.ifr_flags |= ( IFF_PROMISC | IFF_UP );
     if( ioctl( read_sock, SIOCSIFFLAGS, &ifr ) == -1 )
     {
          fprintf( stderr, "%s %d Unable to set promiscious flag", __func__,
__LINE__ );
          return;
     }

     struct sockaddr_ll ll =
     {   
          .sll_family = PF_PACKET,
          .sll_protocol = htons(ETH_P_ALL),
          .sll_ifindex = (int)available_cards[card_pos].index
     };            
     if( bind( read_sock, (struct sockaddr *) &ll, sizeof(ll) ) < 0 ) 
     {
          fprintf( stderr, "%s %d Unable to bind", __func__, __LINE__ );
          return;
     }
     const int one = 1;         
     if( setsockopt( read_sock, SOL_PACKET, PACKET_AUXDATA, &one, sizeof(one))
< 0 ) 
     {        
          fprintf( stderr, "%s %d Unable to setsockopt PACKET_AUXDATA",
__func__, __LINE__ );
          return;
     }        
}

=============================

reading the packet as follows:

=============================

read_return = recvmsg( read_socket, &msg, MSG_DONTWAIT );

=============================

I am seeing recvmsg is returning buffer filled with zeros but returning size is
accurate.

-- 
You are receiving this mail because:
You are the assignee for the bug.