logo       

[CVS] Module ircu2.10: Change committed: msg#00000

Subject: [CVS] Module ircu2.10: Change committed
Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Branch tags: u2_10_12_branch
Commit time: 2006-03-14 03:46:02 UTC

Modified files:
  Tag: u2_10_12_branch
     ircd/uping.c ircd/s_bsd.c ircd/s_auth.c ircd/os_generic.c
     ircd/listener.c ircd/ircd_res.c include/res.h
     include/ircd_osdep.h ChangeLog

Log message:

Fix /uping on IPv6-enabled FreeBSD builds (#1435373).

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.710.2.76 ircu2.10/ChangeLog:1.710.2.77
--- ircu2.10/ChangeLog:1.710.2.76       Wed Feb 22 13:35:39 2006
+++ ircu2.10/ChangeLog  Mon Mar 13 19:45:52 2006
@@ -1,3 +1,31 @@
+2006-03-02  Michael Poole <mdpoole@xxxxxxxxxxx>
+
+       * include/ircd_osdep.h (os_socket): New parameter.
+
+       * include/res.h (irc_in_addr_unspec): New macro.
+
+       * ircd/ircd_res.c (restart_resolver): Set family appropriately.
+
+       * ircd/listener.c (inetport): Let os_ library pick socket family.
+
+       * ircd/os_generic.c: Do not #define _XOPEN_SOURCE on FreeBSD 5+.
+       (sockaddr_from_irc): New parameter.
+       (os_sendto_nonb): Use new parameter to sockaddr_from_irc().
+       (os_socket): New parameter.  Try to turn off IPV6_V6ONLY on
+       sockets that listen on unspecified addresses.
+       (os_connect_nonb): Use new parameter to sockaddr_from_irc().
+
+       * ircd/s_auth.c (start_auth_query): Let os_ library pick socket
+       family.
+
+       * ircd/s_bsd.c (connect_inet): If we pick the IPv4 vhost, specify
+       family for os_socket() as AF_INET.
+
+       * ircd/uping.c (uping_init): Set socket family appropriately.
+       (uping_server): Likewise.
+       (uping_end): Fix format strings (the ms_* fields are int, not
+       long, and this causes bad results on LP64 machines).
+
 2006-02-22  Michael Poole <mdpoole@xxxxxxxxxxx>
 
        * ircd/m_silence.c (apply_silence): Refuse to apply silences for
Index: ircu2.10/include/ircd_osdep.h
diff -u ircu2.10/include/ircd_osdep.h:1.7.2.1 
ircu2.10/include/ircd_osdep.h:1.7.2.2
--- ircu2.10/include/ircd_osdep.h:1.7.2.1       Wed Feb 15 19:22:28 2006
+++ ircu2.10/include/ircd_osdep.h       Mon Mar 13 19:45:52 2006
@@ -1,6 +1,6 @@
 /** @file ircd_osdep.h
  * @brief Public definitions and APIs for OS-dependent operations.
- * @version $Id: ircd_osdep.h,v 1.7.2.1 2006/02/16 03:22:28 entrope Exp $
+ * @version $Id: ircd_osdep.h,v 1.7.2.2 2006/03/14 03:45:52 entrope Exp $
  */
 #ifndef INCLUDED_ircd_osdep_h
 #define INCLUDED_ircd_osdep_h
@@ -32,7 +32,7 @@
 extern int os_get_sockerr(int fd);
 extern int os_get_sockname(int fd, struct irc_sockaddr* sin_out);
 extern int os_get_peername(int fd, struct irc_sockaddr* sin_out);
-extern int os_socket(const struct irc_sockaddr* local, int type, const char* 
port_name);
+extern int os_socket(const struct irc_sockaddr* local, int type, const char* 
port_name, int family);
 extern int os_accept(int fd, struct irc_sockaddr* peer);
 extern IOResult os_sendto_nonb(int fd, const char* buf, unsigned int length,
                                unsigned int* length_out, unsigned int flags,
Index: ircu2.10/include/res.h
diff -u ircu2.10/include/res.h:1.17.2.1 ircu2.10/include/res.h:1.17.2.2
--- ircu2.10/include/res.h:1.17.2.1     Wed Feb 15 20:04:25 2006
+++ ircu2.10/include/res.h      Mon Mar 13 19:45:52 2006
@@ -1,6 +1,6 @@
 /** @file
  * @brief IRC resolver API.
- * @version $Id: res.h,v 1.17.2.1 2006/02/16 04:04:25 entrope Exp $
+ * @version $Id: res.h,v 1.17.2.2 2006/03/14 03:45:52 entrope Exp $
  */
 
 #ifndef INCLUDED_res_h
@@ -116,6 +116,16 @@
 extern void gethost_byname(const char *name, dns_callback_f callback, void 
*ctx);
 extern void gethost_byaddr(const struct irc_in_addr *addr, dns_callback_f 
callback, void *ctx);
 
+/** Evaluate to non-zero if \a ADDR is an unspecified (all zeros) address. */
+#define irc_in_addr_unspec(ADDR) (((ADDR)->in6_16[0] == 0) \
+                                  && ((ADDR)->in6_16[1] == 0) \
+                                  && ((ADDR)->in6_16[2] == 0) \
+                                  && ((ADDR)->in6_16[3] == 0) \
+                                  && ((ADDR)->in6_16[4] == 0) \
+                                  && ((ADDR)->in6_16[6] == 0) \
+                                  && ((ADDR)->in6_16[7] == 0) \
+                                  && ((ADDR)->in6_16[5] == 0 \
+                                      || (ADDR)->in6_16[5] == 65535))
 /** Evaluate to non-zero if \a ADDR is a valid address (not all 0s and not all 
1s). */
 #define irc_in_addr_valid(ADDR) (((ADDR)->in6_16[0] && ~(ADDR)->in6_16[0]) \
                                  || (ADDR)->in6_16[1] != (ADDR)->in6_16[0] \
Index: ircu2.10/ircd/ircd_res.c
diff -u ircu2.10/ircd/ircd_res.c:1.23.2.3 ircu2.10/ircd/ircd_res.c:1.23.2.4
--- ircu2.10/ircd/ircd_res.c:1.23.2.3   Wed Feb 15 20:04:25 2006
+++ ircu2.10/ircd/ircd_res.c    Mon Mar 13 19:45:52 2006
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief IRC resolver functions.
- * @version $Id: ircd_res.c,v 1.23.2.3 2006/02/16 04:04:25 entrope Exp $
+ * @version $Id: ircd_res.c,v 1.23.2.4 2006/03/14 03:45:52 entrope Exp $
  */
 
 #include "client.h"
@@ -173,19 +173,21 @@
 
   if (!s_active(&res_socket_v4))
   {
-    int fd = os_socket(&VirtualHost_v4, SOCK_DGRAM, "Resolver UDPv4 socket");
+    int fd = os_socket(&VirtualHost_v4, SOCK_DGRAM, "Resolver UDPv4 socket", 
AF_INET);
     if (fd >= 0)
       socket_add(&res_socket_v4, res_readreply, NULL,
                  SS_DATAGRAM, SOCK_EVENT_READABLE, fd);
   }
 
+#ifdef AF_INET6
   if (!s_active(&res_socket_v6))
   {
-    int fd = os_socket(&VirtualHost_v6, SOCK_DGRAM, "Resolver UDPv6 socket");
+    int fd = os_socket(&VirtualHost_v6, SOCK_DGRAM, "Resolver UDPv6 socket", 
AF_INET6);
     if (fd >= 0)
       socket_add(&res_socket_v6, res_readreply, NULL,
                  SS_DATAGRAM, SOCK_EVENT_READABLE, fd);
   }
+#endif
 
   if (s_active(&res_socket_v4) || s_active(&res_socket_v6))
     timer_init(&res_timeout);
Index: ircu2.10/ircd/listener.c
diff -u ircu2.10/ircd/listener.c:1.28 ircu2.10/ircd/listener.c:1.28.2.1
--- ircu2.10/ircd/listener.c:1.28       Mon Aug 15 16:22:50 2005
+++ ircu2.10/ircd/listener.c    Mon Mar 13 19:45:52 2006
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation for handling listening sockets.
- * @version $Id: listener.c,v 1.28 2005/08/15 23:22:50 entrope Exp $
+ * @version $Id: listener.c,v 1.28.2.1 2006/03/14 03:45:52 entrope Exp $
  */
 #include "config.h"
 
@@ -187,7 +187,7 @@
   /*
    * At first, open a new socket
    */
-  fd = os_socket(&listener->addr, SOCK_STREAM, get_listener_name(listener));
+  fd = os_socket(&listener->addr, SOCK_STREAM, get_listener_name(listener), 0);
   if (fd < 0)
     return 0;
   /*
Index: ircu2.10/ircd/os_generic.c
diff -u ircu2.10/ircd/os_generic.c:1.23.2.3 ircu2.10/ircd/os_generic.c:1.23.2.4
--- ircu2.10/ircd/os_generic.c:1.23.2.3 Wed Feb 15 19:22:28 2006
+++ ircu2.10/ircd/os_generic.c  Mon Mar 13 19:45:52 2006
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation of OS-dependent operations.
- * @version $Id: os_generic.c,v 1.23.2.3 2006/02/16 03:22:28 entrope Exp $
+ * @version $Id: os_generic.c,v 1.23.2.4 2006/03/14 03:45:52 entrope Exp $
  */
 #include "config.h"
 
@@ -29,11 +29,13 @@
  */
 #define _XOPEN_SOURCE   500
 #define __EXTENSIONS__  1
-#else
-/* FreeBSD 6.0 requires SUSv3 to support IPv6.  Apparently some other
- * OS requires SUSv3 to define IOV_MAX, but its identity is lost for
- * the time being.
+#elif defined(__FreeBSD__) && __FreeBSD__ >= 5
+/* FreeBSD 6.0 requires SUSv3 to support IPv6 -- but if you ask for
+ * that specifically (by defining _XOPEN_SOURCE to anything at all),
+ * they cleverly hide IPPROTO_IPV6.  If you don't ask for anything,
+ * they give you everything.
  */
+#else
 #define _XOPEN_SOURCE   600
 #endif
 
@@ -72,6 +74,10 @@
 #include <unistd.h>
 #endif
 
+#if defined(IPV6_BINDV6ONLY) &&!defined(IPV6_V6ONLY)
+# define IPV6_V6ONLY IPV6_BINDV6ONLY
+#endif
+
 #ifndef IOV_MAX
 #define IOV_MAX 16     /**< minimum required length of an iovec array */
 #endif
@@ -131,15 +137,16 @@
  * @param[in] compat_fd If non-negative, an FD specifying address family.
  * @return Length of address written to \a v6.
  */
-int sockaddr_from_irc(struct sockaddr_in6 *v6, const struct irc_sockaddr *irc, 
int compat_fd)
+int sockaddr_from_irc(struct sockaddr_in6 *v6, const struct irc_sockaddr *irc, 
int compat_fd, int family)
 {
     struct sockaddr_in6 sin6;
     socklen_t slen;
-    int family;
 
     assert(irc != 0);
     slen = sizeof(sin6);
-    if ((0 <= compat_fd)
+    if (family) {
+        /* accept whatever user specified */
+    } else if ((0 <= compat_fd)
         && (0 == getsockname(compat_fd, (struct sockaddr*)&sin6, &slen)))
         family = sin6.sin6_family;
     else if ((irc == &VirtualHost_v4) || irc_in_addr_is_ipv4(&irc->addr))
@@ -168,7 +175,7 @@
 #define sn_family sin_family
 #define sockaddr_to_irc sockaddr_in_to_irc
 
-int sockaddr_from_irc(struct sockaddr_in *v4, const struct irc_sockaddr *irc, 
int compat_fd)
+int sockaddr_from_irc(struct sockaddr_in *v4, const struct irc_sockaddr *irc, 
int compat_fd, int family)
 {
     assert(irc != 0);
     v4->sin_family = AF_INET;
@@ -179,7 +186,7 @@
     } else{
         memset(&v4, 0, sizeof(v4));
     }
-    (void)compat_fd;
+    (void)compat_fd; (void)family;
     return sizeof(*v4);
 }
 
@@ -496,7 +503,7 @@
   int res, size;
   assert(0 != buf);
 
-  size = sockaddr_from_irc(&addr, peer, fd);
+  size = sockaddr_from_irc(&addr, peer, fd, 0);
   assert((addr.sn_family == AF_INET) == irc_in_addr_is_ipv4(&peer->addr));
   if (-1 < (res = sendto(fd, buf, length, flags, (struct sockaddr*)&addr, 
size))) {
     if (count_out)
@@ -566,15 +573,16 @@
  * @param[in] local Local address to bind to.
  * @param[in] type SOCK_STREAM or SOCK_DGRAM.
  * @param[in] port_name Port name (used in error diagnostics).
+ * @param[in] family A specific address family to use, or 0 for automatic.
  * @return Bound descriptor, or -1 on error.
  */
-int os_socket(const struct irc_sockaddr* local, int type, const char* 
port_name)
+int os_socket(const struct irc_sockaddr* local, int type, const char* 
port_name, int family)
 {
   struct sockaddr_native addr;
   int size, fd;
 
   assert(local != 0);
-  size = sockaddr_from_irc(&addr, local, -1);
+  size = sockaddr_from_irc(&addr, local, -1, family);
   fd = socket(addr.sn_family, type, 0);
   if (fd < 0) {
     report_error(SOCKET_ERROR_MSG, port_name, errno);
@@ -596,6 +604,11 @@
     return -1;
   }
   if (local) {
+#if defined(IPV6_V6ONLY)
+    int on = 0;
+    if (family == 0 && irc_in_addr_unspec(&local->addr))
+      setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
+#endif
     if (bind(fd, (struct sockaddr*)&addr, size)) {
       report_error(BIND_ERROR_MSG, port_name, errno);
       close(fd);
@@ -635,7 +648,7 @@
   struct sockaddr_native addr;
   int size;
 
-  size = sockaddr_from_irc(&addr, sin, fd);
+  size = sockaddr_from_irc(&addr, sin, fd, 0);
   if (0 == connect(fd, (struct sockaddr*) &addr, size))
     return IO_SUCCESS;
   else if (errno == EINPROGRESS)
Index: ircu2.10/ircd/s_auth.c
diff -u ircu2.10/ircd/s_auth.c:1.37.2.4 ircu2.10/ircd/s_auth.c:1.37.2.5
--- ircu2.10/ircd/s_auth.c:1.37.2.4     Wed Feb 22 07:34:44 2006
+++ ircu2.10/ircd/s_auth.c      Mon Mar 13 19:45:52 2006
@@ -31,7 +31,7 @@
  */
 /** @file
  * @brief Implementation of DNS and ident lookups.
- * @version $Id: s_auth.c,v 1.37.2.4 2006/02/22 15:34:44 entrope Exp $
+ * @version $Id: s_auth.c,v 1.37.2.5 2006/03/14 03:45:52 entrope Exp $
  */
 #include "config.h"
 
@@ -826,7 +826,7 @@
   local_addr.port = 0;
   memcpy(&remote_addr.addr, &cli_ip(auth->client), sizeof(remote_addr.addr));
   remote_addr.port = 113;
-  fd = os_socket(&local_addr, SOCK_STREAM, "auth query");
+  fd = os_socket(&local_addr, SOCK_STREAM, "auth query", 0);
   if (fd < 0) {
     ++ServerStats->is_abad;
     if (IsUserPort(auth->client))
Index: ircu2.10/ircd/s_bsd.c
diff -u ircu2.10/ircd/s_bsd.c:1.80 ircu2.10/ircd/s_bsd.c:1.80.2.1
--- ircu2.10/ircd/s_bsd.c:1.80  Mon Jul 11 19:13:10 2005
+++ ircu2.10/ircd/s_bsd.c       Mon Mar 13 19:45:52 2006
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Functions that now (or in the past) relied on BSD APIs.
- * @version $Id: s_bsd.c,v 1.80 2005/07/12 02:13:10 entrope Exp $
+ * @version $Id: s_bsd.c,v 1.80.2.1 2006/03/14 03:45:52 entrope Exp $
  */
 #include "config.h"
 
@@ -207,6 +207,8 @@
 {
   const struct irc_sockaddr *local;
   IOResult result;
+  int family = 0;
+
   assert(0 != aconf);
   assert(0 != cptr);
   /*
@@ -215,11 +217,12 @@
    */
   if (irc_in_addr_valid(&aconf->origin.addr))
     local = &aconf->origin;
-  else if (irc_in_addr_is_ipv4(&aconf->address.addr))
+  else if (irc_in_addr_is_ipv4(&aconf->address.addr)) {
     local = &VirtualHost_v4;
-  else
+    family = AF_INET;
+  } else
     local = &VirtualHost_v6;
-  cli_fd(cptr) = os_socket(local, SOCK_STREAM, cli_name(cptr));
+  cli_fd(cptr) = os_socket(local, SOCK_STREAM, cli_name(cptr), family);
   if (cli_fd(cptr) < 0)
     return 0;
 
Index: ircu2.10/ircd/uping.c
diff -u ircu2.10/ircd/uping.c:1.23 ircu2.10/ircd/uping.c:1.23.2.1
--- ircu2.10/ircd/uping.c:1.23  Sun Mar 20 08:06:30 2005
+++ ircu2.10/ircd/uping.c       Mon Mar 13 19:45:52 2006
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief UDP ping implementation.
- * @version $Id: uping.c,v 1.23 2005/03/20 16:06:30 entrope Exp $
+ * @version $Id: uping.c,v 1.23.2.1 2006/03/14 03:45:52 entrope Exp $
  */
 #include "config.h"
 
@@ -135,7 +135,7 @@
   memcpy(&from, &VirtualHost_v4, sizeof(from));
   from.port = atoi(UDP_PORT);
 
-  fd = os_socket(&from, SOCK_DGRAM, "IPv4 uping listener");
+  fd = os_socket(&from, SOCK_DGRAM, "IPv4 uping listener", AF_INET);
   if (fd < 0)
     return -1;
   if (!socket_add(&upingSock_v4, uping_echo_callback, 0, SS_DATAGRAM,
@@ -145,10 +145,11 @@
     return -1;
   }
 
+#ifdef AF_INET6
   memcpy(&from, &VirtualHost_v6, sizeof(from));
   from.port = atoi(UDP_PORT);
 
-  fd = os_socket(&from, SOCK_DGRAM, "IPv6 uping listener");
+  fd = os_socket(&from, SOCK_DGRAM, "IPv6 uping listener", AF_INET6);
   if (fd < 0)
     return -1;
   if (!socket_add(&upingSock_v6, uping_echo_callback, 0, SS_DATAGRAM,
@@ -157,6 +158,7 @@
     close(fd);
     return -1;
   }
+#endif
 
   return 0;
 }
@@ -368,6 +370,7 @@
 int uping_server(struct Client* sptr, struct ConfItem* aconf, int port, int 
count)
 {
   int fd;
+  int family = 0;
   struct UPing* pptr;
   struct irc_sockaddr *local;
 
@@ -383,8 +386,13 @@
   if (IsUPing(sptr))
     uping_cancel(sptr, sptr);  /* Cancel previous ping request */
 
-  local = irc_in_addr_is_ipv4(&aconf->address.addr) ? &VirtualHost_v4 : 
&VirtualHost_v6;
-  fd = os_socket(local, SOCK_DGRAM, "Outbound uping socket");
+  if (irc_in_addr_is_ipv4(&aconf->address.addr)) {
+    local = &VirtualHost_v4;
+    family = AF_INET;
+  } else {
+    local = &VirtualHost_v6;
+  }
+  fd = os_socket(local, SOCK_DGRAM, "Outbound uping socket", family);
   if (fd < 0)
     return 0;
 
@@ -430,7 +438,7 @@
        sendcmdto_one(&me, CMD_NOTICE, pptr->client, "%C :UPING %s%s",
                      pptr->client, pptr->name, pptr->buf);
        sendcmdto_one(&me, CMD_NOTICE, pptr->client, "%C :UPING Stats: "
-                     "sent %d recvd %d ; min/avg/max = %1lu/%1lu/%1lu ms",
+                     "sent %d recvd %d ; min/avg/max = %u/%u/%u ms",
                      pptr->client, pptr->sent, pptr->received, pptr->ms_min,
                      (2 * pptr->ms_ave) / (2 * pptr->received), pptr->ms_max);
       } else
@@ -474,5 +482,3 @@
   }
   ClearUPing(sptr);
 }
-
-
----------------------- End of diff -----------------------


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe