bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] ifconfig hurd: Notify pfinet of interfaces


From: Samuel Thibault
Subject: [PATCH] ifconfig hurd: Notify pfinet of interfaces
Date: Tue, 27 Sep 2022 02:48:55 +0200
User-agent: NeoMutt/20170609 (1.8.3)

When the pfinet translator is configured without any initial interface,
ifconfig has to explicitly tell it the interfaces to be configured.
This needs to be done before any SIOC ioctl with that interface name,
thus introducing a system_preconfigure that is called before any other
configuration.

* ifconfig/system.h (system_preconfigure): New prototype.
* ifconfig/system/hurd.c: Include hurd.h, hurd/paths.h, hurd/fsys.h,
argz.h.
(check_driving): New function.
(system_preconfigure): New function.
* ifconfig/system/bsd.c (system_preconfigure): New functions.
* ifconfig/system/generic.c (system_preconfigure): Likewise.
* ifconfig/system/linux.c (system_preconfigure): Likewise.
* ifconfig/system/qnx.c (system_preconfigure): Likewise.
* ifconfig/system/solaris.c (system_preconfigure): Likewise.
* ifconfig/changeif.c (configure_if): Call system_preconfigure before
other "set" functions.

Index: inetutils-2.3/ifconfig/system/hurd.c
===================================================================
--- inetutils-2.3.orig/ifconfig/system/hurd.c
+++ inetutils-2.3/ifconfig/system/hurd.c
@@ -24,6 +24,10 @@
 #include <stdlib.h>
 #include <sys/ioctl.h>
 #include <net/if_arp.h>
+#include <hurd.h>
+#include <hurd/paths.h>
+#include <hurd/fsys.h>
+#include <argz.h>
 #include "../ifconfig.h"
 
 #include <attribute.h>
@@ -34,6 +38,107 @@
 const char *system_default_format = "gnu";
 
 
+/* Check that pfinet is driving the given interface name.  */
+static int
+check_driving (const char *name)
+{
+  file_t node;
+  fsys_t fsys;
+  error_t err;
+
+  char *argz = 0, *new_argz = 0;
+  size_t argz_len = 0;
+  char *entry = 0;
+  const char *socket = _SERVERS_SOCKET "/2";
+
+  int ret = 0;
+
+  if (strcmp (name, "lo") == 0)
+    /* Always configured.  */
+    return 1;
+
+  node = file_name_lookup (socket, 0, 0666);
+  if (node == MACH_PORT_NULL)
+    {
+      error (0, 0, "Interface name %s does not exist", name);
+      return 0;
+    }
+
+  file_get_fs_options (node, &argz, &argz_len);
+
+  for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
+    {
+      if (strcmp (entry, "-i") == 0)
+       {
+         char *ifname = argz_next (argz, argz_len, entry);
+
+         if (strcmp (ifname, name) == 0)
+           {
+             /* Already there.  */
+             ret = 1;
+             goto out;
+           }
+       }
+
+      else if (strncmp (entry, "--interface=", 12) == 0)
+       {
+         if (strcmp (entry + 12, name) == 0)
+           {
+             /* Already there.  */
+             ret = 1;
+             goto out;
+           }
+       }
+    }
+
+  /* Not already there.  */
+
+  err = file_getcontrol (node, &fsys);
+  if (err)
+    {
+      if (err == EPERM)
+       error (0, err, "Could not make pfinet %s drive %s", socket, name);
+      else
+       error (0, err, "Could not get control of %s", socket);
+      goto out;
+    }
+
+  new_argz = malloc (argz_len);
+  memcpy (new_argz, argz, argz_len);
+
+  err = argz_insert (&new_argz, &argz_len, new_argz, name);
+  if (err)
+    {
+      error (0, err, "Could not prepend name %s to '%s' for %s", name, 
new_argz, socket);
+      goto out;
+    }
+
+  err = argz_insert (&new_argz, &argz_len, new_argz, "-i");
+  if (err)
+    {
+      argz_stringify (new_argz, argz_len, ' ');
+      error (0, err, "Could not prepend -i to '%s' for %s", new_argz, socket);
+      goto out;
+    }
+
+  err = fsys_set_options (fsys, new_argz, argz_len, 1);
+  if (err)
+    {
+      argz_stringify (new_argz, argz_len, ' ');
+      error (0, err, "Could not make pfinet %s drive %s with '%s'", socket, 
name, new_argz);
+      goto out;
+    }
+
+  ret = 1;
+
+out:
+  free (new_argz);
+  vm_deallocate (mach_task_self (), (vm_offset_t) argz, argz_len);
+  mach_port_deallocate (mach_task_self (), node);
+
+  return ret;
+}
+
 /* Argument parsing stuff.  */
 
 const char *system_help = "NAME [ADDR]\
@@ -156,6 +261,15 @@ system_parse_opt_rest (struct ifconfig *
   return 0;
 }
 
+int
+system_preconfigure (int sfd MAYBE_UNUSED,
+                    struct ifreq *ifr MAYBE_UNUSED)
+{
+  if (!check_driving (ifr->ifr_name))
+    return -1;
+  return 0;
+}
+
 int
 system_configure (int sfd MAYBE_UNUSED,
                  struct ifreq *ifr MAYBE_UNUSED,
Index: inetutils-2.3/ifconfig/changeif.c
===================================================================
--- inetutils-2.3.orig/ifconfig/changeif.c
+++ inetutils-2.3/ifconfig/changeif.c
@@ -404,7 +404,8 @@ configure_if (int sfd, struct ifconfig *
   strncpy (ifr.ifr_name, ifp->name, IFNAMSIZ);
   ifr.ifr_name[IFNAMSIZ - 1] = '\0';
 
-  if (ifp->valid & IF_VALID_ADDR)
+  err = system_preconfigure (sfd, &ifr);
+  if (!err && ifp->valid & IF_VALID_ADDR)
     err = set_address (sfd, &ifr, ifp->address);
   if (!err && ifp->valid & IF_VALID_NETMASK)
     err = set_netmask (sfd, &ifr, ifp->netmask);
Index: inetutils-2.3/ifconfig/system.h
===================================================================
--- inetutils-2.3.orig/ifconfig/system.h
+++ inetutils-2.3/ifconfig/system.h
@@ -64,6 +64,7 @@ extern const char *system_default_format
 # undef SYSTEM_FORMAT_HANDLER
 
 
+int system_preconfigure (int sfd, struct ifreq *ifr);
 int system_configure (int sfd, struct ifreq *ifr,
                      struct system_ifconfig *__ifs);
 
Index: inetutils-2.3/ifconfig/system/bsd.c
===================================================================
--- inetutils-2.3.orig/ifconfig/system/bsd.c
+++ inetutils-2.3/ifconfig/system/bsd.c
@@ -178,6 +178,13 @@ system_parse_opt_rest (struct ifconfig *
 }
 
 int
+system_preconfigure (int sfd MAYBE_UNUSED,
+                    struct ifreq *ifr MAYBE_UNUSED)
+{
+  return 0;
+}
+
+int
 system_configure (int sfd MAYBE_UNUSED,
                  struct ifreq *ifr MAYBE_UNUSED,
                  struct system_ifconfig *ifs MAYBE_UNUSED)
Index: inetutils-2.3/ifconfig/system/generic.c
===================================================================
--- inetutils-2.3.orig/ifconfig/system/generic.c
+++ inetutils-2.3/ifconfig/system/generic.c
@@ -53,6 +53,13 @@ system_parse_opt_rest (struct ifconfig *
 }
 
 int
+system_preconfigure (int sfd MAYBE_UNUSED,
+                    struct ifreq *ifr MAYBE_UNUSED)
+{
+  return 0;
+}
+
+int
 system_configure (int sfd MAYBE_UNUSED,
                  struct ifreq *ifr MAYBE_UNUSED,
                  struct system_ifconfig *ifs MAYBE_UNUSED)
Index: inetutils-2.3/ifconfig/system/linux.c
===================================================================
--- inetutils-2.3.orig/ifconfig/system/linux.c
+++ inetutils-2.3/ifconfig/system/linux.c
@@ -895,6 +895,13 @@ system_parse_opt_rest (struct ifconfig *
 
 
 int
+system_preconfigure (int sfd MAYBE_UNUSED,
+                    struct ifreq *ifr MAYBE_UNUSED)
+{
+  return 0;
+}
+
+int
 system_configure (int sfd, struct ifreq *ifr, struct system_ifconfig *ifs)
 {
   if (ifs->valid & IF_VALID_TXQLEN)
Index: inetutils-2.3/ifconfig/system/qnx.c
===================================================================
--- inetutils-2.3.orig/ifconfig/system/qnx.c
+++ inetutils-2.3/ifconfig/system/qnx.c
@@ -58,6 +58,13 @@ system_parse_opt_rest (struct ifconfig *
 }
 
 int
+system_preconfigure (int sfd MAYBE_UNUSED,
+                    struct ifreq *ifr MAYBE_UNUSED)
+{
+  return 0;
+}
+
+int
 system_configure (int sfd, struct ifreq *ifr, struct system_ifconfig *ifs)
 {
   return 0;
Index: inetutils-2.3/ifconfig/system/solaris.c
===================================================================
--- inetutils-2.3.orig/ifconfig/system/solaris.c
+++ inetutils-2.3/ifconfig/system/solaris.c
@@ -174,6 +174,13 @@ system_parse_opt_rest (struct ifconfig *
 }
 
 int
+system_preconfigure (int sfd MAYBE_UNUSED,
+                    struct ifreq *ifr MAYBE_UNUSED)
+{
+  return 0;
+}
+
+int
 system_configure (int sfd, struct ifreq *ifr, struct system_ifconfig *ifs)
 {
 #ifdef IF_VALID_TXQLEN



reply via email to

[Prev in Thread] Current Thread [Next in Thread]