commit-inetutils
[Top][All Lists]
Advanced

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

[SCM] GNU Inetutils branch, master, updated. inetutils-1_8-115-g17d6784


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_8-115-g17d6784
Date: Thu, 01 Sep 2011 17:42:32 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  17d6784e33ccd6a7427e79846dfe44d86d4eaa8c (commit)
      from  8cd0ff9e38fd76117028a983322be0e0d037d1d5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=17d6784e33ccd6a7427e79846dfe44d86d4eaa8c


commit 17d6784e33ccd6a7427e79846dfe44d86d4eaa8c
Author: Mats Erik Andersson <address@hidden>
Date:   Thu Sep 1 19:35:05 2011 +0200

    syslogd: Full support for IPv6.
    
    New options are "ipv4", "ipv6", "ipany", and "bind".
    The latter restricts binding to a single address,
    if numeric, and one resolvable IPv4/IPv6 pair if
    given a sympolic host name.

diff --git a/ChangeLog b/ChangeLog
index 758c000..76d4f03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2011-09-01  Mats Erik Andersson <address@hidden>
+
+       * src/syslogd.c (BindAddress): New variable.
+       (finet): Replace by two-element vector of same name.
+       (argp_options): New options: "ipv4", "ipv6", "ipany", "bind".
+       (parse_opt): Likewise.
+       (main): Adaptions to the vector `finet[2]'.
+       (create_inet_socket): New prototype `void c_i_s (int, int [2])'.
+       Separate address families. Use BINDADDRESS at resolve time.
+       (fprintlog): Temporary socket by family; use descriptor pointer.
+       (die): Close both internet sockets.
+       * doc/inetutils.texi (syslogd): Update capabilities and options
+       for the server `syslogd'.
+       * tests/syslogd.sh: Adapt server options for IPv6.
+
 2011-08-20  Mats Erik Andersson <address@hidden>
 
        * src/logger.c (send_to_syslog, parse_opt) [LOG_PERROR]: Enclose every
diff --git a/doc/inetutils.texi b/doc/inetutils.texi
index c01ea61..ac1d2aa 100644
--- a/doc/inetutils.texi
+++ b/doc/inetutils.texi
@@ -2409,7 +2409,7 @@ Do not enter daemon mode.
 Print debug information (implies @option{-n}).
 
 @item -p @var{file}
address@hidden address@hidden
address@hidden address@hidden
 @opindex -p
 @opindex --socket
 Override default UNIX domain socket @file{/dev/log}.
@@ -2422,6 +2422,20 @@ Add UNIX socket to listen.  An unlimited number of 
sockets is allowed.
 @opindex -r
 @opindex --inet
 Receive remote messages via Internet domain socket.
+Without this option no remote massages are received,
+since there is no listening socket. Yet sockets for
+forwarding are created on the fly as needed,
+which might cause performance issues on busy systems.
+
address@hidden -b @var{address}
address@hidden address@hidden
address@hidden -b
address@hidden --bind
+Restrict the listening Internet domain socket to a single address.
+The default (given the use of @option{-r}) is a wildcard address,
+implying that the server listens at every available address.
+Any name will be resolved, and the lookup result will depend
+on the options @option{-4}, @option{-6}, and @option{--ipany}.
 
 @item --no-unixaf
 @opindex --no-unixaf
@@ -2432,18 +2446,37 @@ Do not listen on UNIX domain sockets (overrides 
@option{-a} and
 @opindex --no-klog
 Do not listen to the kernel log device @file{/dev/klog}.
 
address@hidden --ipany
address@hidden --ipany
+Allow both address families: IPv4 and IPv6.
+
address@hidden -4
address@hidden --ipv4
address@hidden -4
address@hidden --ipv4
+Use only IPv4 for Internet domain sockets.
+
address@hidden -6
address@hidden --ipv6
address@hidden -6
address@hidden --ipv6
+Use only IPv6 for Internet domain sockets.
+
 @item --no-forward
 @opindex --no-forward
 Do not forward any messages (overrides @option{-h}).
+This disables even temporary creation of forwarding
+sockets, an ability which is otherwise active when
+the option @option{-r} is left out.
 
 @item -h
address@hidden --hop
address@hidden --hop
 @opindex -h
 @opindex --hop
 Forward messages from remote hosts.
 
 @item -m @var{interval}
address@hidden address@hidden
address@hidden address@hidden
 @opindex -m
 @opindex --mark
 Specify timestamp interval in logs (0 for no timestamps).
diff --git a/src/syslogd.c b/src/syslogd.c
index f8758c2..ed82012 100644
--- a/src/syslogd.c
+++ b/src/syslogd.c
@@ -263,16 +263,20 @@ static void dbg_printf (const char *, ...);
 void trigger_restart (int);
 static void add_funix (const char *path);
 static int create_unix_socket (const char *path);
-static int create_inet_socket (int af);
+static void create_inet_socket (int af, int fd46[2]);
 
 char *LocalHostName;           /* Our hostname.  */
 char *LocalDomain;             /* Our local domain name.  */
+char *BindAddress = NULL;      /* Binding address for INET listeners.
+                                * The default is a wildcard address.  */
 char addrstr[INET6_ADDRSTRLEN];        /* Common address presentation.  */
 char addrname[NI_MAXHOST];     /* Common name lookup.  */
 int usefamily = AF_INET;       /* Address family for INET services.
                                 * Each of the values `AF_INET' and `AF_INET6'
                                 * produces a single-stacked server.  */
-int finet = -1;                        /* Internet datagram socket fd.  */
+int finet[2] = {-1, -1};       /* Internet datagram socket fd.  */
+#define IU_FD_IP4      0       /* Indices for the address families.  */
+#define IU_FD_IP6      1
 int fklog = -1;                        /* Kernel log device fd.  */
 char *LogPortText = "syslog";  /* Service/port for INET connections.  */
 int Initialized;               /* True when we are initialized. */
@@ -301,7 +305,8 @@ enum {
   OPT_NO_FORWARD = 256,
   OPT_NO_KLOG,
   OPT_NO_UNIXAF,
-  OPT_PIDFILE
+  OPT_PIDFILE,
+  OPT_IPANY
 };
 
 static struct argp_option argp_options[] = {
@@ -316,6 +321,10 @@ static struct argp_option argp_options[] = {
   {"hop", 'h', NULL, 0, "forward messages from remote hosts", GRP+1},
   {"inet", 'r', NULL, 0, "receive remote messages via internet domain socket",
    GRP+1},
+  {"ipv4", '4', NULL, 0, "restrict to IPv4 transport (default)", GRP+1},
+  {"ipv6", '6', NULL, 0, "restrict to IPv6 transport", GRP+1},
+  {"ipany", OPT_IPANY, NULL, 0, "allow transport with IPv4 and IPv6", GRP+1},
+  {"bind", 'b', "ADDR", 0, "bind listener to this address/name", GRP+1},
   {"mark", 'm', "INTVL", 0, "specify timestamp interval in logs (0 for no "
    "timestamps)", GRP+1},
   {"no-detach", 'n', NULL, 0, "do not enter daemon mode", GRP+1},
@@ -372,6 +381,22 @@ parse_opt (int key, char *arg, struct argp_state *state)
       AcceptRemote = 1;
       break;
 
+    case '4':
+      usefamily = AF_INET;
+      break;
+
+    case '6':
+      usefamily = AF_INET6;
+      break;
+
+    case OPT_IPANY:
+      usefamily = AF_UNSPEC;
+      break;
+
+    case 'b':
+      BindAddress = arg;
+      break;
+
     case 'm':
       v = strtol (arg, &endptr, 10);
       if (*endptr)
@@ -515,8 +540,8 @@ main (int argc, char *argv[])
   signal (SIGUSR1, Debug ? dbg_toggle : SIG_IGN);
   alarm (TIMERINTVL);
 
-  /* We add  2 = 1(klog) + 1(inet), even if they may be not use.  */
-  fdarray = (struct pollfd *) malloc ((nfunix + 2) * sizeof (*fdarray));
+  /* We add  3 = 1(klog) + 2(inet,inet6), even if they may stay unused.  */
+  fdarray = (struct pollfd *) malloc ((nfunix + 3) * sizeof (*fdarray));
   if (fdarray == NULL)
     error (EXIT_FAILURE, errno, "can't allocate fd table");
 
@@ -562,15 +587,24 @@ main (int argc, char *argv[])
   /* Initialize inet socket and add it to the list.  */
   if (AcceptRemote)
     {
-      finet = create_inet_socket (usefamily);
-      if (finet >= 0)
+      create_inet_socket (usefamily, finet);
+      if (finet[IU_FD_IP4] >= 0)
        {
-         fdarray[nfds].fd = finet;
+         /* IPv4 socket is present.  */
+         fdarray[nfds].fd = finet[IU_FD_IP4];
          fdarray[nfds].events = POLLIN | POLLPRI;
          nfds++;
-         dbg_printf ("Opened syslog UDP port.\n");
+         dbg_printf ("Opened syslog UDP/IPv4 port.\n");
        }
-      else
+      if (finet[IU_FD_IP6] >= 0)
+       {
+         /* IPv6 socket is present.  */
+         fdarray[nfds].fd = finet[IU_FD_IP6];
+         fdarray[nfds].events = POLLIN | POLLPRI;
+         nfds++;
+         dbg_printf ("Opened syslog UDP/IPv6 port.\n");
+       }
+      if (finet[IU_FD_IP4] < 0 && finet[IU_FD_IP6] < 0)
        dbg_printf ("Can't open UDP port: %s\n", strerror (errno));
     }
 
@@ -707,7 +741,8 @@ main (int argc, char *argv[])
                      }
                  }
              }
-           else if (fdarray[i].fd == finet)
+           else if (fdarray[i].fd == finet[IU_FD_IP4]
+                    || fdarray[i].fd == finet[IU_FD_IP6])
              {
                struct sockaddr_storage frominet;
                /*dbg_printf ("inet message\n"); */
@@ -794,22 +829,25 @@ create_unix_socket (const char *path)
   return fd;
 }
 
-static int
-create_inet_socket (int af)
+static void
+create_inet_socket (int af, int fd46[2])
 {
   int err, fd = -1;
   struct addrinfo hints, *rp, *ai;
 
+  /* Invalidate old descriptors.  */
+  fd46[IU_FD_IP4] = fd46[IU_FD_IP6] = -1;
+
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = af;
   hints.ai_socktype = SOCK_DGRAM;
   hints.ai_flags = AI_PASSIVE;
 
-  err = getaddrinfo (NULL, LogPortText, &hints, &rp);
+  err = getaddrinfo (BindAddress, LogPortText, &hints, &rp);
   if (err)
     {
       logerror ("lookup error, suspending inet service");
-      return fd;
+      return;
     }
 
   for (ai = rp; ai; ai = ai->ai_next)
@@ -829,17 +867,20 @@ create_inet_socket (int af)
          fd = -1;
          continue;
        }
-      /* Success.  Only one socket at this time.  */
-      break;
+      /* Register any success.  */
+      if (ai->ai_family == AF_INET && fd46[IU_FD_IP4] < 0)
+       fd46[IU_FD_IP4] = fd;
+      else if (ai->ai_family == AF_INET6 && fd46[IU_FD_IP6] < 0)
+       fd46[IU_FD_IP6] = fd;
     }
   freeaddrinfo (rp);
 
-  if (ai == NULL)
+  if (fd46[IU_FD_IP4] < 0 && fd46[IU_FD_IP6] < 0)
     {
       logerror ("inet service, failed lookup.");
-      return fd;
+      return;
     }
-  return fd;
+  return;
 }
 
 char **
@@ -1287,7 +1328,14 @@ fprintlog (struct filed *f, const char *from, int flags, 
const char *msg)
        dbg_printf ("Not forwarding because forwarding is disabled.\n");
       else
        {
-         int temp_finet = finet;
+         int temp_finet, *pfinet;      /* PFINET points to active fd.  */
+
+         if (f->f_un.f_forw.f_addr.ss_family == AF_INET)
+           pfinet = &finet[IU_FD_IP4];
+         else  /* AF_INET6 */
+           pfinet = &finet[IU_FD_IP6];
+
+         temp_finet = *pfinet;
 
          if (temp_finet < 0)
            {
@@ -1345,7 +1393,7 @@ fprintlog (struct filed *f, const char *from, int flags, 
const char *msg)
              logerror ("sendto");
            }
 
-         if (finet < 0)
+         if (*pfinet < 0)
            close (temp_finet); /* Only temporary socket may be closed.  */
        }
       break;
@@ -1631,8 +1679,10 @@ die (int signo)
          unlink (funix[i].name);
       }
 
-  if (finet >= 0)
-    close (finet);
+  if (finet[IU_FD_IP4] >= 0)
+    close (finet[IU_FD_IP4]);
+  if (finet[IU_FD_IP6] >= 0)
+    close (finet[IU_FD_IP6]);
 
   exit (EXIT_SUCCESS);
 }
diff --git a/tests/syslogd.sh b/tests/syslogd.sh
index 05848b7..3d3f7b6 100755
--- a/tests/syslogd.sh
+++ b/tests/syslogd.sh
@@ -94,7 +94,7 @@ fi
 IU_OPTIONS="--rcfile=$CONF --pidfile=$PID --socket=$SOCKET"
 ## Enable INET service when running as root.
 if [ "$USER" = "root" ]; then
-       IU_OPTIONS="$IU_OPTIONS --inet --hop"
+       IU_OPTIONS="$IU_OPTIONS --ipany --inet --hop"
 fi
 ## Bring in additional options from command line.
 ## Disable kernel messages otherwise.
@@ -125,11 +125,12 @@ EXITCODE=1
 # Send messages on two sockets: IPv4 and UNIX.
 #
 TESTCASES=$((TESTCASES + 1))
-$IU_LOGGER -h $SOCKET -p user -t $TAG "Sending BSD message."
+$IU_LOGGER -h $SOCKET -p user.info -t $TAG "Sending BSD message. (pid $$)"
 
 if [ "$USER" = "root" ]; then
-       TESTCASES=$((TESTCASES + 1))
-       $IU_LOGGER -4 -h localhost -p user -t $TAG "Sending IPv4 message."
+       TESTCASES=$((TESTCASES + 2))
+       $IU_LOGGER -4 -h localhost -p user.info -t $TAG "Sending IPv4 message. 
(pid $$)"
+       $IU_LOGGER -6 -h localhost -p user.info -t $TAG "Sending IPv6 message. 
(pid $$)"
 fi
 
 # Detection of registered messages.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog          |   15 ++++++++
 doc/inetutils.texi |   39 +++++++++++++++++++--
 src/syslogd.c      |   98 +++++++++++++++++++++++++++++++++++++++-------------
 tests/syslogd.sh   |    9 +++--
 4 files changed, 130 insertions(+), 31 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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