register_netdev() race with ip addr












1















I am developing a proof of concept for a networking application that uses a generic stack interface driver that connects the stack to a userspace application rather than a physical device. This driver works fine and is in production.



The problem I have encountered is this: after I register the device in the kernel module for that driver via register_netdev(), I must sleep between 3ms and 6ms before I can successfully call "ip addr add". It would obviously be better to query something to see if I can set the IP address than to wait for a fixed time (or repeatedly attempt to set it until it sticks).



I am running 4.19.19 with Centos 7.6.



Does anyone know how to check (in a C application, via a system call, via sysfs, etc) if a network device is ready to receive an IP address? Here are some things I have tried without success (they return before I can successfully set the IP without sleeping):



1) Waiting for net_device.flags & IFF_UP



2) Waiting for net_device.reg_state == NETREG_REGISTERED



3) Waiting for netif_running(net_device)



I have also waited to see that I have an index reported by ioctl(fd, SIOCGIFINDEX...), and I seem to right after registering the device.



It feels like something in the network registration notify chain is taking its sweet time to finish up, but I have no idea what it is or how to tell when it is done.










share|improve this question













migrated from stackoverflow.com 13 mins ago


This question came from our site for professional and enthusiast programmers.























    1















    I am developing a proof of concept for a networking application that uses a generic stack interface driver that connects the stack to a userspace application rather than a physical device. This driver works fine and is in production.



    The problem I have encountered is this: after I register the device in the kernel module for that driver via register_netdev(), I must sleep between 3ms and 6ms before I can successfully call "ip addr add". It would obviously be better to query something to see if I can set the IP address than to wait for a fixed time (or repeatedly attempt to set it until it sticks).



    I am running 4.19.19 with Centos 7.6.



    Does anyone know how to check (in a C application, via a system call, via sysfs, etc) if a network device is ready to receive an IP address? Here are some things I have tried without success (they return before I can successfully set the IP without sleeping):



    1) Waiting for net_device.flags & IFF_UP



    2) Waiting for net_device.reg_state == NETREG_REGISTERED



    3) Waiting for netif_running(net_device)



    I have also waited to see that I have an index reported by ioctl(fd, SIOCGIFINDEX...), and I seem to right after registering the device.



    It feels like something in the network registration notify chain is taking its sweet time to finish up, but I have no idea what it is or how to tell when it is done.










    share|improve this question













    migrated from stackoverflow.com 13 mins ago


    This question came from our site for professional and enthusiast programmers.





















      1












      1








      1








      I am developing a proof of concept for a networking application that uses a generic stack interface driver that connects the stack to a userspace application rather than a physical device. This driver works fine and is in production.



      The problem I have encountered is this: after I register the device in the kernel module for that driver via register_netdev(), I must sleep between 3ms and 6ms before I can successfully call "ip addr add". It would obviously be better to query something to see if I can set the IP address than to wait for a fixed time (or repeatedly attempt to set it until it sticks).



      I am running 4.19.19 with Centos 7.6.



      Does anyone know how to check (in a C application, via a system call, via sysfs, etc) if a network device is ready to receive an IP address? Here are some things I have tried without success (they return before I can successfully set the IP without sleeping):



      1) Waiting for net_device.flags & IFF_UP



      2) Waiting for net_device.reg_state == NETREG_REGISTERED



      3) Waiting for netif_running(net_device)



      I have also waited to see that I have an index reported by ioctl(fd, SIOCGIFINDEX...), and I seem to right after registering the device.



      It feels like something in the network registration notify chain is taking its sweet time to finish up, but I have no idea what it is or how to tell when it is done.










      share|improve this question














      I am developing a proof of concept for a networking application that uses a generic stack interface driver that connects the stack to a userspace application rather than a physical device. This driver works fine and is in production.



      The problem I have encountered is this: after I register the device in the kernel module for that driver via register_netdev(), I must sleep between 3ms and 6ms before I can successfully call "ip addr add". It would obviously be better to query something to see if I can set the IP address than to wait for a fixed time (or repeatedly attempt to set it until it sticks).



      I am running 4.19.19 with Centos 7.6.



      Does anyone know how to check (in a C application, via a system call, via sysfs, etc) if a network device is ready to receive an IP address? Here are some things I have tried without success (they return before I can successfully set the IP without sleeping):



      1) Waiting for net_device.flags & IFF_UP



      2) Waiting for net_device.reg_state == NETREG_REGISTERED



      3) Waiting for netif_running(net_device)



      I have also waited to see that I have an index reported by ioctl(fd, SIOCGIFINDEX...), and I seem to right after registering the device.



      It feels like something in the network registration notify chain is taking its sweet time to finish up, but I have no idea what it is or how to tell when it is done.







      linux kernel






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 22:55







      Jeremy Whatley











      migrated from stackoverflow.com 13 mins ago


      This question came from our site for professional and enthusiast programmers.









      migrated from stackoverflow.com 13 mins ago


      This question came from our site for professional and enthusiast programmers.
























          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2funix.stackexchange.com%2fquestions%2f506640%2fregister-netdev-race-with-ip-addr%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 Unix & Linux Stack Exchange!


          • 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%2funix.stackexchange.com%2fquestions%2f506640%2fregister-netdev-race-with-ip-addr%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

          CARDNET

          Boot-repair Failure: Unable to locate package grub-common:i386

          濃尾地震