Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
since19861019 opened this issue Sep 5, 2014 · 0 comments
Open

Comments

@since19861019
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant