[vbox-dev] [PATCH] Implement media state for host-only interface

Ed Maste emaste at freebsd.org
Thu Aug 30 21:23:08 GMT 2012


I have an application that issues SIOCGIFMEDIA to check interface media
status, and logs an error when that fails on a vboxnet interface.

This change is based on the same support added to FreeBSD's if_tap
interface in SVN r238183, which is in turn based on DragonFly BSD commit
70d9a675bf5441cc854a843ead702d08928c37f3.  Sponsored by ADARA Networks.

Ideally status would report 'active' only when a VM is attached to the
host-only interface, but I don't see a straightforward way to do so with
the decoupling between VBoxNetFlt and VBoxNetAdp -- so consider this a
query for further information on this point as well.  As it stands it
reports 'active' always.

Patch released under the MIT license.

diff --git a/src/VBox/HostDrivers/VBoxNetAdp/freebsd/VBoxNetAdp-freebsd.c b/src/VBox/HostDrivers/VBoxNetAdp/freebsd/VBoxNetAdp-freebsd.c
index 1b65cc4..42cdd3e 100644
--- a/src/VBox/HostDrivers/VBoxNetAdp/freebsd/VBoxNetAdp-freebsd.c
+++ b/src/VBox/HostDrivers/VBoxNetAdp/freebsd/VBoxNetAdp-freebsd.c
@@ -48,6 +48,7 @@
 #include <net/if_var.h>
 #include <net/route.h>
 #include <net/if_dl.h>
+#include <net/if_media.h>
 #include <net/if_types.h>
 #include <net/ethernet.h>
 #include <net/bpf.h>
@@ -246,6 +247,10 @@ static void VBoxNetAdpFreeBSDNetstart(struct ifnet *ifp)
  */
 static int VBoxNetAdpFreeBSDNetioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 {
+    struct ifmediareq *ifmr;
+    int count;
+    int error = 0;
+
     switch (cmd)
     {
         case SIOCSIFFLAGS:
@@ -260,10 +265,23 @@ static int VBoxNetAdpFreeBSDNetioctl(struct ifnet *ifp, u_long cmd, caddr_t data
                     ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
             }
             break;
+        case SIOCGIFMEDIA:
+            ifmr = (struct ifmediareq *)data;
+            count = ifmr->ifm_count;
+            ifmr->ifm_count = 1;
+            ifmr->ifm_status = IFM_AVALID;
+            ifmr->ifm_active = IFM_ETHER;
+            ifmr->ifm_status |= IFM_ACTIVE;
+            ifmr->ifm_current = ifmr->ifm_active;
+            if (count >= 1) {
+                int media = IFM_ETHER;
+                error = copyout(&media, ifmr->ifm_ulist, sizeof(int));
+            }
+            break;
         default:
             return ether_ioctl(ifp, cmd, data);
     }
-    return 0;
+    return error;
 }

 int vboxNetAdpOsInit(PVBOXNETADP pThis)





More information about the vbox-dev mailing list