Problem with SO_PRIORITY when sending broadcast packets










0














I'm having some issues with SO_PRIORITY, when used with setsockopt().



My doubt is about the WME MAC layer queues and socket priority when sending packets (defing, among other things, the AIFS times, in place of DIFS). I'm able to set a certain priority with:
setsockopt(sFd,SOL_SOCKET,SO_PRIORITY,&up,sizeof(up))
where "up" is the desired user priority (for instance, up=4 to use the AC_VO queue).
This seems to work both with raw and IP datagram sockets.



The problem is that the MAC queues are correctly used only when sending unicast packets (which are actually acknowledged); when sending broadcast (or multicast) data, as I'm required to do, only the "AC_BE" (up=0) queue is used, no matter what I set with SO_PRIORITY.



Do you know why? I actually want to properly use these queues also for broadcast transmissions, as it may be very useful for a research work I'm doing.



This is part of the code I'm using to send the packets out (here a raw socket is used, but the same happens with non-raw sockets, as AF_INET datagram ones):



// Open socket
sFd=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
if(sFd==-1)
perror("socket() error");
exit(EXIT_FAILURE);


// Getting WLAN interface index using a custom library (wlanLookup() and macAddrTypeGet() functions
ret_wlanl_val=wlanLookup(devname,&ifindex,srcmacaddr,0);
if(ret_wlanl_val<=0)
fprintf(stderr,"wlanLookup() error.n");
rs_printerror(stderr,ret_wlanl_val);
close(sFd);
exit(EXIT_FAILURE);


if(macAddrTypeGet(srcmacaddr)==MAC_BROADCAST)
fprintf(stderr,"Could not retrieve source MAC address.n");
close(sFd);
exit(EXIT_FAILURE);


// Prepare sockaddr_ll structure
bzero(&addrll,sizeof(addrll));
addrll.sll_ifindex=ifindex;
addrll.sll_family=AF_PACKET;
addrll.sll_protocol=htons(ETH_P_ALL);

// Bind to the wireless interface
if(bind(sFd,(struct sockaddr *) &addrll,sizeof(addrll))<0)
perror("Cannot bind to interface: bind() error");
close(sFd);
exit(EXIT_FAILURE);


// Print AC corresponding to selected UP (and handle possible wrong UP)
up=atoi(argv[3]);
switch(up)
case 0:
case 3:
fprintf(stdout,"AC_BE is selected, with UP: %d.n",up);
break;

case 1:
case 2:
fprintf(stdout,"AC_BK is selected, with UP: %d.n",up);
break;

case 4:
case 5:
fprintf(stdout,"AC_VI is selected, with UP: %d.n",up);
break;

case 6:
case 7:
fprintf(stdout,"AC_VO is selected, with UP: %d.n",up);
break;

default:
fprintf(stderr,"Wrong UP specified. AC_BE will be used.n");
up=0;
break;


// Set user priority using socket layer options (does not work with broadcast?)
if(setsockopt(sFd,SOL_SOCKET,SO_PRIORITY,&up,sizeof(up))!=0)
perror("setsockopt() for SO_PRIORITY error");
close(sFd);
exit(EXIT_FAILURE);


// Set broadcast permission using socket layer options (is this really required?)
if(setsockopt(sFd,SOL_SOCKET,SO_BROADCAST,(void *) &broadPerm,sizeof(broadPerm))!=0)
perror("setsockopt() for SO_BROADCAST error");
close(sFd);
exit(EXIT_FAILURE);


//... Prepare payload, headers and timer to periodically send data...

while(1)
// poll waiting for events happening on the timer descriptor (i.e. wait for timer expiration)
if(poll(&timerMon,1,INDEFINITE_BLOCK)>0)
// "Clear the event" by performing a read() on a junk variable
read(clockFd,&junk,sizeof(junk));
// Send brodcast data (if verbose==1, print '.' for each sent datagram)
// Prepare datagram

// ... Prepare datagram to be sent (contained in "ethernetpacket", with size "finalpktsize")

if(sendto(sFd,ethernetpacket,finalpktsize,0,(struct sockaddr *)&addrll,sizeof(struct sockaddr_ll))!=finalpktsize)
perror("sendto() for sending broadcasted data failed");
fprintf(stderr,"The program will be terminated now");
break;


if(verbose)
fprintf(stdout,".");
fflush(stdout);




//... free variables, close socket, ...


Thank you very much in advance.










share|improve this question


























    0














    I'm having some issues with SO_PRIORITY, when used with setsockopt().



    My doubt is about the WME MAC layer queues and socket priority when sending packets (defing, among other things, the AIFS times, in place of DIFS). I'm able to set a certain priority with:
    setsockopt(sFd,SOL_SOCKET,SO_PRIORITY,&up,sizeof(up))
    where "up" is the desired user priority (for instance, up=4 to use the AC_VO queue).
    This seems to work both with raw and IP datagram sockets.



    The problem is that the MAC queues are correctly used only when sending unicast packets (which are actually acknowledged); when sending broadcast (or multicast) data, as I'm required to do, only the "AC_BE" (up=0) queue is used, no matter what I set with SO_PRIORITY.



    Do you know why? I actually want to properly use these queues also for broadcast transmissions, as it may be very useful for a research work I'm doing.



    This is part of the code I'm using to send the packets out (here a raw socket is used, but the same happens with non-raw sockets, as AF_INET datagram ones):



    // Open socket
    sFd=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
    if(sFd==-1)
    perror("socket() error");
    exit(EXIT_FAILURE);


    // Getting WLAN interface index using a custom library (wlanLookup() and macAddrTypeGet() functions
    ret_wlanl_val=wlanLookup(devname,&ifindex,srcmacaddr,0);
    if(ret_wlanl_val<=0)
    fprintf(stderr,"wlanLookup() error.n");
    rs_printerror(stderr,ret_wlanl_val);
    close(sFd);
    exit(EXIT_FAILURE);


    if(macAddrTypeGet(srcmacaddr)==MAC_BROADCAST)
    fprintf(stderr,"Could not retrieve source MAC address.n");
    close(sFd);
    exit(EXIT_FAILURE);


    // Prepare sockaddr_ll structure
    bzero(&addrll,sizeof(addrll));
    addrll.sll_ifindex=ifindex;
    addrll.sll_family=AF_PACKET;
    addrll.sll_protocol=htons(ETH_P_ALL);

    // Bind to the wireless interface
    if(bind(sFd,(struct sockaddr *) &addrll,sizeof(addrll))<0)
    perror("Cannot bind to interface: bind() error");
    close(sFd);
    exit(EXIT_FAILURE);


    // Print AC corresponding to selected UP (and handle possible wrong UP)
    up=atoi(argv[3]);
    switch(up)
    case 0:
    case 3:
    fprintf(stdout,"AC_BE is selected, with UP: %d.n",up);
    break;

    case 1:
    case 2:
    fprintf(stdout,"AC_BK is selected, with UP: %d.n",up);
    break;

    case 4:
    case 5:
    fprintf(stdout,"AC_VI is selected, with UP: %d.n",up);
    break;

    case 6:
    case 7:
    fprintf(stdout,"AC_VO is selected, with UP: %d.n",up);
    break;

    default:
    fprintf(stderr,"Wrong UP specified. AC_BE will be used.n");
    up=0;
    break;


    // Set user priority using socket layer options (does not work with broadcast?)
    if(setsockopt(sFd,SOL_SOCKET,SO_PRIORITY,&up,sizeof(up))!=0)
    perror("setsockopt() for SO_PRIORITY error");
    close(sFd);
    exit(EXIT_FAILURE);


    // Set broadcast permission using socket layer options (is this really required?)
    if(setsockopt(sFd,SOL_SOCKET,SO_BROADCAST,(void *) &broadPerm,sizeof(broadPerm))!=0)
    perror("setsockopt() for SO_BROADCAST error");
    close(sFd);
    exit(EXIT_FAILURE);


    //... Prepare payload, headers and timer to periodically send data...

    while(1)
    // poll waiting for events happening on the timer descriptor (i.e. wait for timer expiration)
    if(poll(&timerMon,1,INDEFINITE_BLOCK)>0)
    // "Clear the event" by performing a read() on a junk variable
    read(clockFd,&junk,sizeof(junk));
    // Send brodcast data (if verbose==1, print '.' for each sent datagram)
    // Prepare datagram

    // ... Prepare datagram to be sent (contained in "ethernetpacket", with size "finalpktsize")

    if(sendto(sFd,ethernetpacket,finalpktsize,0,(struct sockaddr *)&addrll,sizeof(struct sockaddr_ll))!=finalpktsize)
    perror("sendto() for sending broadcasted data failed");
    fprintf(stderr,"The program will be terminated now");
    break;


    if(verbose)
    fprintf(stdout,".");
    fflush(stdout);




    //... free variables, close socket, ...


    Thank you very much in advance.










    share|improve this question
























      0












      0








      0







      I'm having some issues with SO_PRIORITY, when used with setsockopt().



      My doubt is about the WME MAC layer queues and socket priority when sending packets (defing, among other things, the AIFS times, in place of DIFS). I'm able to set a certain priority with:
      setsockopt(sFd,SOL_SOCKET,SO_PRIORITY,&up,sizeof(up))
      where "up" is the desired user priority (for instance, up=4 to use the AC_VO queue).
      This seems to work both with raw and IP datagram sockets.



      The problem is that the MAC queues are correctly used only when sending unicast packets (which are actually acknowledged); when sending broadcast (or multicast) data, as I'm required to do, only the "AC_BE" (up=0) queue is used, no matter what I set with SO_PRIORITY.



      Do you know why? I actually want to properly use these queues also for broadcast transmissions, as it may be very useful for a research work I'm doing.



      This is part of the code I'm using to send the packets out (here a raw socket is used, but the same happens with non-raw sockets, as AF_INET datagram ones):



      // Open socket
      sFd=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
      if(sFd==-1)
      perror("socket() error");
      exit(EXIT_FAILURE);


      // Getting WLAN interface index using a custom library (wlanLookup() and macAddrTypeGet() functions
      ret_wlanl_val=wlanLookup(devname,&ifindex,srcmacaddr,0);
      if(ret_wlanl_val<=0)
      fprintf(stderr,"wlanLookup() error.n");
      rs_printerror(stderr,ret_wlanl_val);
      close(sFd);
      exit(EXIT_FAILURE);


      if(macAddrTypeGet(srcmacaddr)==MAC_BROADCAST)
      fprintf(stderr,"Could not retrieve source MAC address.n");
      close(sFd);
      exit(EXIT_FAILURE);


      // Prepare sockaddr_ll structure
      bzero(&addrll,sizeof(addrll));
      addrll.sll_ifindex=ifindex;
      addrll.sll_family=AF_PACKET;
      addrll.sll_protocol=htons(ETH_P_ALL);

      // Bind to the wireless interface
      if(bind(sFd,(struct sockaddr *) &addrll,sizeof(addrll))<0)
      perror("Cannot bind to interface: bind() error");
      close(sFd);
      exit(EXIT_FAILURE);


      // Print AC corresponding to selected UP (and handle possible wrong UP)
      up=atoi(argv[3]);
      switch(up)
      case 0:
      case 3:
      fprintf(stdout,"AC_BE is selected, with UP: %d.n",up);
      break;

      case 1:
      case 2:
      fprintf(stdout,"AC_BK is selected, with UP: %d.n",up);
      break;

      case 4:
      case 5:
      fprintf(stdout,"AC_VI is selected, with UP: %d.n",up);
      break;

      case 6:
      case 7:
      fprintf(stdout,"AC_VO is selected, with UP: %d.n",up);
      break;

      default:
      fprintf(stderr,"Wrong UP specified. AC_BE will be used.n");
      up=0;
      break;


      // Set user priority using socket layer options (does not work with broadcast?)
      if(setsockopt(sFd,SOL_SOCKET,SO_PRIORITY,&up,sizeof(up))!=0)
      perror("setsockopt() for SO_PRIORITY error");
      close(sFd);
      exit(EXIT_FAILURE);


      // Set broadcast permission using socket layer options (is this really required?)
      if(setsockopt(sFd,SOL_SOCKET,SO_BROADCAST,(void *) &broadPerm,sizeof(broadPerm))!=0)
      perror("setsockopt() for SO_BROADCAST error");
      close(sFd);
      exit(EXIT_FAILURE);


      //... Prepare payload, headers and timer to periodically send data...

      while(1)
      // poll waiting for events happening on the timer descriptor (i.e. wait for timer expiration)
      if(poll(&timerMon,1,INDEFINITE_BLOCK)>0)
      // "Clear the event" by performing a read() on a junk variable
      read(clockFd,&junk,sizeof(junk));
      // Send brodcast data (if verbose==1, print '.' for each sent datagram)
      // Prepare datagram

      // ... Prepare datagram to be sent (contained in "ethernetpacket", with size "finalpktsize")

      if(sendto(sFd,ethernetpacket,finalpktsize,0,(struct sockaddr *)&addrll,sizeof(struct sockaddr_ll))!=finalpktsize)
      perror("sendto() for sending broadcasted data failed");
      fprintf(stderr,"The program will be terminated now");
      break;


      if(verbose)
      fprintf(stdout,".");
      fflush(stdout);




      //... free variables, close socket, ...


      Thank you very much in advance.










      share|improve this question













      I'm having some issues with SO_PRIORITY, when used with setsockopt().



      My doubt is about the WME MAC layer queues and socket priority when sending packets (defing, among other things, the AIFS times, in place of DIFS). I'm able to set a certain priority with:
      setsockopt(sFd,SOL_SOCKET,SO_PRIORITY,&up,sizeof(up))
      where "up" is the desired user priority (for instance, up=4 to use the AC_VO queue).
      This seems to work both with raw and IP datagram sockets.



      The problem is that the MAC queues are correctly used only when sending unicast packets (which are actually acknowledged); when sending broadcast (or multicast) data, as I'm required to do, only the "AC_BE" (up=0) queue is used, no matter what I set with SO_PRIORITY.



      Do you know why? I actually want to properly use these queues also for broadcast transmissions, as it may be very useful for a research work I'm doing.



      This is part of the code I'm using to send the packets out (here a raw socket is used, but the same happens with non-raw sockets, as AF_INET datagram ones):



      // Open socket
      sFd=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
      if(sFd==-1)
      perror("socket() error");
      exit(EXIT_FAILURE);


      // Getting WLAN interface index using a custom library (wlanLookup() and macAddrTypeGet() functions
      ret_wlanl_val=wlanLookup(devname,&ifindex,srcmacaddr,0);
      if(ret_wlanl_val<=0)
      fprintf(stderr,"wlanLookup() error.n");
      rs_printerror(stderr,ret_wlanl_val);
      close(sFd);
      exit(EXIT_FAILURE);


      if(macAddrTypeGet(srcmacaddr)==MAC_BROADCAST)
      fprintf(stderr,"Could not retrieve source MAC address.n");
      close(sFd);
      exit(EXIT_FAILURE);


      // Prepare sockaddr_ll structure
      bzero(&addrll,sizeof(addrll));
      addrll.sll_ifindex=ifindex;
      addrll.sll_family=AF_PACKET;
      addrll.sll_protocol=htons(ETH_P_ALL);

      // Bind to the wireless interface
      if(bind(sFd,(struct sockaddr *) &addrll,sizeof(addrll))<0)
      perror("Cannot bind to interface: bind() error");
      close(sFd);
      exit(EXIT_FAILURE);


      // Print AC corresponding to selected UP (and handle possible wrong UP)
      up=atoi(argv[3]);
      switch(up)
      case 0:
      case 3:
      fprintf(stdout,"AC_BE is selected, with UP: %d.n",up);
      break;

      case 1:
      case 2:
      fprintf(stdout,"AC_BK is selected, with UP: %d.n",up);
      break;

      case 4:
      case 5:
      fprintf(stdout,"AC_VI is selected, with UP: %d.n",up);
      break;

      case 6:
      case 7:
      fprintf(stdout,"AC_VO is selected, with UP: %d.n",up);
      break;

      default:
      fprintf(stderr,"Wrong UP specified. AC_BE will be used.n");
      up=0;
      break;


      // Set user priority using socket layer options (does not work with broadcast?)
      if(setsockopt(sFd,SOL_SOCKET,SO_PRIORITY,&up,sizeof(up))!=0)
      perror("setsockopt() for SO_PRIORITY error");
      close(sFd);
      exit(EXIT_FAILURE);


      // Set broadcast permission using socket layer options (is this really required?)
      if(setsockopt(sFd,SOL_SOCKET,SO_BROADCAST,(void *) &broadPerm,sizeof(broadPerm))!=0)
      perror("setsockopt() for SO_BROADCAST error");
      close(sFd);
      exit(EXIT_FAILURE);


      //... Prepare payload, headers and timer to periodically send data...

      while(1)
      // poll waiting for events happening on the timer descriptor (i.e. wait for timer expiration)
      if(poll(&timerMon,1,INDEFINITE_BLOCK)>0)
      // "Clear the event" by performing a read() on a junk variable
      read(clockFd,&junk,sizeof(junk));
      // Send brodcast data (if verbose==1, print '.' for each sent datagram)
      // Prepare datagram

      // ... Prepare datagram to be sent (contained in "ethernetpacket", with size "finalpktsize")

      if(sendto(sFd,ethernetpacket,finalpktsize,0,(struct sockaddr *)&addrll,sizeof(struct sockaddr_ll))!=finalpktsize)
      perror("sendto() for sending broadcasted data failed");
      fprintf(stderr,"The program will be terminated now");
      break;


      if(verbose)
      fprintf(stdout,".");
      fflush(stdout);




      //... free variables, close socket, ...


      Thank you very much in advance.







      c sockets queue broadcast wireless






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 '18 at 15:11









      es483es483

      426




      426






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240274%2fproblem-with-so-priority-when-sending-broadcast-packets%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240274%2fproblem-with-so-priority-when-sending-broadcast-packets%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Edmonton

          Crossroads (UK TV series)