Signed-off-by: Charles Myers <[email protected]>
---
 bsd/sys/compat/linux/linux_ioctl.cc | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/bsd/sys/compat/linux/linux_ioctl.cc 
b/bsd/sys/compat/linux/linux_ioctl.cc
index 43a50bb..d49386d 100644
--- a/bsd/sys/compat/linux/linux_ioctl.cc
+++ b/bsd/sys/compat/linux/linux_ioctl.cc
@@ -43,8 +43,8 @@
 #include <bsd/sys/net/if_dl.h>
 #include <bsd/sys/net/if_types.h>
 
-#include <bsd/sys/compat/linux/linux_socket.h>
 #include <bsd/sys/compat/linux/linux.h>
+#include <bsd/sys/compat/linux/linux_socket.h>
 
 #include <osv/file.h>
 #include <osv/socket.hh>
@@ -199,6 +199,17 @@ linux_gifhwaddr(struct ifnet *ifp, struct l_ifreq *ifr)
     return (ENOENT);
 }
 
+static int
+linux_sifname(socket_file *fp, struct l_ifreq *data)
+{
+    struct bsd_ifreq ifreq;
+
+    // FreeBSD ifreq uses a pointer to the new name string instead of 
including it in the struct
+    memcpy((char *)&ifreq, data->ifr_name, IFNAMSIZ);
+    ifreq.ifr_ifru.ifru_data = (caddr_t)(data->ifr_ifru.ifru_newname);
+
+    return fp->bsd_ioctl(SIOCSIFNAME, &ifreq);
+}
 
 /*
  * Fix the interface address field in bsd_ifreq. The bsd stack expects a
@@ -223,6 +234,16 @@ linux_to_bsd_ifreq(struct bsd_ifreq *ifr_p)
 }
 
 /*
+ * FreeBSD ifru_index is short but Linux is an int so need to clear extra bits.
+ */
+static inline void 
+bsd_to_linux_ifreq_ifindex(struct bsd_ifreq *ifr_p)
+{
+    void *ptr = &ifr_p->ifr_index;
+    *(int *)(ptr) = ifr_p->ifr_index;
+}
+
+/*
  * Socket related ioctls
  */
 
@@ -241,8 +262,8 @@ linux_ioctl_socket(socket_file *fp, u_long cmd, void *data)
     switch (cmd) {
     case SIOCSIFADDR:
     case SIOCSIFNETMASK:
-    case SIOCSIFDSTADDR: 
-    case SIOCSIFBRDADDR: 
+    case SIOCSIFDSTADDR:
+    case SIOCSIFBRDADDR:
         if ((ifp = ifunit_ref((char *)data)) == NULL)
             return (EINVAL);
         linux_to_bsd_ifreq((struct bsd_ifreq *)data) ;
@@ -251,10 +272,16 @@ linux_ioctl_socket(socket_file *fp, u_long cmd, void 
*data)
 
     case SIOCGIFMTU:
     case SIOCSIFMTU:
+        if ((ifp = ifunit_ref((char *)data)) == NULL)
+            return (EINVAL);
+        error = fp->bsd_ioctl(cmd, data);
+        break;
+
     case SIOCGIFINDEX:
         if ((ifp = ifunit_ref((char *)data)) == NULL)
             return (EINVAL);
         error = fp->bsd_ioctl(cmd, data);
+       bsd_to_linux_ifreq_ifindex((struct bsd_ifreq *)data);
         break;
 
     case SIOCGIFADDR:
@@ -278,7 +305,9 @@ linux_ioctl_socket(socket_file *fp, u_long cmd, void *data)
         break;
 
     case SIOCSIFNAME:
-        error = ENOIOCTL;
+        if ((ifp = ifunit_ref((char *)data)) == NULL)
+            return (EINVAL);
+        error = linux_sifname(fp, (struct l_ifreq *)data);
         break;
 
     case SIOCGIFHWADDR:
-- 
2.7.4

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to