]> xenbits.xensource.com Git - unikraft/libs/click.git/commitdiff
click.cc: Probe the network devices at init time
authorStefan Jumarea <stefanjumarea02@gmail.com>
Fri, 8 Sep 2023 12:37:04 +0000 (15:37 +0300)
committerUnikraft <monkey@unikraft.io>
Sat, 9 Sep 2023 12:15:03 +0000 (12:15 +0000)
In the early init step, probe the network device if it was not already
probed or configured.

Whithout this step, the `uk_netdev_configure` call will fail, since it
expects the device state to be `UK_NETDEV_UNCONFIGURED`, not
`UK_NETDEV_UNPROBED`.

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #7

click.cc

index 1ab0076db15f17dfee726ab5c3259a953e3a3ff1..f72a32e944d8a88ba89866271ac3d7dfae77e6bd 100644 (file)
--- a/click.cc
+++ b/click.cc
@@ -236,11 +236,28 @@ uk_netdev_early_init(ErrorHandler *errh)
 {
        struct uk_netdev *netdev;
        struct uk_netdev_conf netdev_conf;
+       int ret;
 
        netdev_conf.nb_rx_queues = 1;
        netdev_conf.nb_tx_queues = 1;
        for (unsigned int i = 0; i < uk_netdev_count(); ++i) {
                netdev = uk_netdev_get(i);
+
+               if (!netdev)
+                       continue;
+               if (uk_netdev_state_get(netdev) != UK_NETDEV_UNCONFIGURED &&
+                               uk_netdev_state_get(netdev) != UK_NETDEV_UNPROBED) {
+                       uk_pr_info("Skipping to add network device %u to lwIP: Not in unconfigured state\n", i);
+                       continue;
+               }
+
+               if (uk_netdev_state_get(netdev) == UK_NETDEV_UNPROBED) {
+                       ret = uk_netdev_probe(netdev);
+                       if (ret < 0) {
+                               uk_pr_err("Failed to probe network device %u %d", i, ret);
+                               continue;
+                       }
+               }
                uk_pr_info("netdev %d early init\n", i);
                if (uk_netdev_configure(netdev, &netdev_conf) < 0)
                        return errh->error("Failed to configure device %d\n", i);