Skip to content

Network Utilities does not show input/output packet count. #2

Open
@since19861019

Description

@since19861019

I use your driver with VirtualBox (thanks!) and noticed network status is not updated.
I made small modification and it seems working.
Though link speed is not accurate ( always 1G), but prettier than 0.

diff --git a/virtio-net/virtio_net.cpp b/virtio-net/virtio_net.cpp
index 3332930..eeeb8f4 100644
--- a/virtio-net/virtio_net.cpp
+++ b/virtio-net/virtio_net.cpp
@@ -608,7 +608,11 @@ bool PJVirtioNet::updateLinkStatus()
    IONetworkMedium* medium = dict ? IONetworkMedium::getMediumWithType(dict, kIOMediumEthernetAuto) : 0;
    if (!medium)
        VIOLog("virtio-net updateLinkStatus: Warning, no medium found!\n");
-   setLinkStatus((link_is_up ? kIONetworkLinkActive : 0) | kIONetworkLinkValid, medium);
+    if(link_is_up)
+        setLinkStatus(kIONetworkLinkValid | kIONetworkLinkActive,
+                      medium,1000000000ul);
+    else
+       setLinkStatus(kIONetworkLinkValid, 0);
    return link_is_up;
 }

@@ -941,7 +945,11 @@ void PJVirtioNet::detectLinkStatusFeature(uint16_t device_specific_offset)
            status, (status & VIRTIO_NET_S_LINK_UP) ? "up" : "down");
        link_is_up = (status & VIRTIO_NET_S_LINK_UP) != 0;
    }
-   setLinkStatus((link_is_up ? kIONetworkLinkActive : 0) | kIONetworkLinkValid);
+    if(link_is_up)
+        setLinkStatus(kIONetworkLinkValid | kIONetworkLinkActive,
+                      getCurrentMedium(),1000000000ul);
+    else
+       setLinkStatus(kIONetworkLinkValid, 0);
 }

 bool PJVirtioNet::beginHandlingInterrupts()
@@ -1026,6 +1034,12 @@ bool PJVirtioNet::configureInterface(IONetworkInterface *netif)
        VIOLog("virtio-net configureInterface(): super failed\n");
        return false;
    }
+   // Get the generic network statistics structure.
+   IONetworkData * data = netif->getParameter(kIONetworkStatsKey);
+   if (!data || !(netStats = (IONetworkStats *) data->getBuffer())) {
+       VIOLog("virtio-net configureInterface(): getParameter(kIONetworkStatsKey) failed."); 
+       return false;
+   }
    return true;
 }

@@ -2198,6 +2212,7 @@ void PJVirtioNet::releaseSentPackets(bool from_debugger)
            virtio_net_packet* next = cur->next_free;

            freePacket(cur->mbuf);
+            netStats->outputPackets++;
            if (cur->mem)
            {
                packet_bufdesc_pool->setObject(cur->mem);
@@ -2254,6 +2269,7 @@ void PJVirtioNet::releaseSentPackets(bool from_debugger)
                    continue;
                }
                freePacket(packet->mbuf);
+                netStats->outputPackets++;
            }
            else
            {
@@ -2408,7 +2424,7 @@ void PJVirtioNet::handleReceivedPackets()
    }
    if (packets_submitted > 0)
    {
-       interface->flushInputQueue();
+       netStats->inputPackets += interface->flushInputQueue();
        //IOLog("virtio-net handleReceivedPackets(): %u received\n", packets_submitted);
    }
 }
diff --git a/virtio-net/virtio_net.h b/virtio-net/virtio_net.h
index 9c545b8..03b1aa8 100644
--- a/virtio-net/virtio_net.h
+++ b/virtio-net/virtio_net.h
@@ -320,6 +320,8 @@ protected:

    /// Low bit is atomically toggled on if the configuration change bit was detected in the interrupt handler
    volatile UInt8 received_config_change __attribute__((aligned(32)));
+private:
+   IONetworkStats * netStats;
 };

 #endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions