[IRC-Dev CVS] [CVS] Module ircd-ircdev: Change committed
Brought to you by:
zolty
From: Toni G. <zo...@us...> - 2005-01-05 11:58:59
|
CVSROOT : /cvsroot/irc-dev Module : ircd-ircdev Commit time: 2005-01-05 11:58:46 UTC Modified files: ChangeLog ChangeLog.es Makefile.in configure configure.in doc/ircd.sample-en.conf doc/ircd.sample-es.conf include/patchlevel.h include/res.h include/s_bsd.h include/sys.h include/uping.h ircd/.cvsignore ircd/IPcheck.c ircd/gline.c ircd/ircd.c ircd/ircd_auth.c ircd/ircd_lexer.l ircd/ircd_parser.y ircd/ircd_res.c ircd/ircd_string.c ircd/listener.c ircd/match.c ircd/os_generic.c ircd/s_auth.c ircd/s_bsd.c ircd/s_conf.c ircd/s_user.c ircd/uping.c ircd/whocmds.c Added files: ircd/test/.cvsignore ircd/test/Makefile.in ircd/test/ircd_in_addr_t.c ircd/test/test_stub.c Removed files: ircd/test/Makefile Log message: Author: zoltan <zo...@ir...> Log message: 2005-01-05 Toni García <zo...@ir...> 1.0.alpha15 * Parchear Soporte de IPv6 ---------------------- diff included ---------------------- Index: ircd-ircdev/ChangeLog diff -u ircd-ircdev/ChangeLog:1.15 ircd-ircdev/ChangeLog:1.16 --- ircd-ircdev/ChangeLog:1.15 Tue Dec 28 03:15:43 2004 +++ ircd-ircdev/ChangeLog Wed Jan 5 03:58:33 2005 @@ -1,10 +1,13 @@ # # ChangeLog for ircd-ircdev # -# $Id: ChangeLog,v 1.15 2004/12/28 11:15:43 zolty Exp $ +# $Id: ChangeLog,v 1.16 2005/01/05 11:58:33 zolty Exp $ # # Insert new changes at beginning of the change list. # +2005-01-05 Toni García <zo...@ir...> 1.0.alpha15 + * Fix IPv6 support + 2004-11-28 Toni García <zo...@ir...> 1.0.alpha14 * Implementation IRC capabilities draft * Undernet synchorinization Index: ircd-ircdev/ChangeLog.es diff -u ircd-ircdev/ChangeLog.es:1.15 ircd-ircdev/ChangeLog.es:1.16 --- ircd-ircdev/ChangeLog.es:1.15 Tue Dec 28 03:15:43 2004 +++ ircd-ircdev/ChangeLog.es Wed Jan 5 03:58:33 2005 @@ -1,10 +1,13 @@ # # Log de Cambios para ircd-ircdev # -# $Id: ChangeLog.es,v 1.15 2004/12/28 11:15:43 zolty Exp $ +# $Id: ChangeLog.es,v 1.16 2005/01/05 11:58:33 zolty Exp $ # # Insertar los nuevos cambios al principio de esta lista de cambios. # +2005-01-05 Toni García <zo...@ir...> 1.0.alpha15 + * Parchear Soporte de IPv6 + 2004-11-28 Toni García <zo...@ir...> 1.0.alpha14 * Implementacion del estándar "IRC Capabilities" * Sincronizacion Undernet Index: ircd-ircdev/Makefile.in diff -u ircd-ircdev/Makefile.in:1.5 ircd-ircdev/Makefile.in:1.6 --- ircd-ircdev/Makefile.in:1.5 Wed Nov 24 08:11:30 2004 +++ ircd-ircdev/Makefile.in Wed Jan 5 03:58:33 2005 @@ -29,8 +29,8 @@ @SET_MAKE@ #### End of system configuration section. #### -SUBDIRS = doc ircd -IRCD_MAKEFILES = Makefile doc/Makefile ircd/Makefile +SUBDIRS = doc ircd ircd/test +IRCD_MAKEFILES = Makefile doc/Makefile ircd/Makefile ircd/test/Makefile all: build @@ -140,6 +140,9 @@ ircd/Makefile: ircd/Makefile.in config.status ./config.status +ircd/test/Makefile: ircd/test/Makefile.in config.status + ./config.status + config.status: configure ./config.status --recheck Index: ircd-ircdev/configure diff -u ircd-ircdev/configure:1.9 ircd-ircdev/configure:1.10 --- ircd-ircdev/configure:1.9 Wed Nov 24 08:11:30 2004 +++ ircd-ircdev/configure Wed Jan 5 03:58:33 2005 @@ -10187,7 +10187,7 @@ _ACEOF - ac_config_files="$ac_config_files Makefile ircd/Makefile doc/Makefile" + ac_config_files="$ac_config_files Makefile ircd/Makefile ircd/test/Makefile doc/Makefile" ac_config_commands="$ac_config_commands default" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -10719,6 +10719,7 @@ # Handling of arguments. "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; "ircd/Makefile" ) CONFIG_FILES="$CONFIG_FILES ircd/Makefile" ;; + "ircd/test/Makefile" ) CONFIG_FILES="$CONFIG_FILES ircd/test/Makefile" ;; "doc/Makefile" ) CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;; "default" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;; "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; Index: ircd-ircdev/configure.in diff -u ircd-ircdev/configure.in:1.8 ircd-ircdev/configure.in:1.9 --- ircd-ircdev/configure.in:1.8 Wed Nov 24 08:11:31 2004 +++ ircd-ircdev/configure.in Wed Jan 5 03:58:34 2005 @@ -22,7 +22,7 @@ dnl along with this program; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl -dnl $Id: configure.in,v 1.8 2004/11/24 16:11:31 zolty Exp $ +dnl $Id: configure.in,v 1.9 2005/01/05 11:58:34 zolty Exp $ dnl dnl Make sure we are in the correct directory (someone could have run @@ -749,7 +749,7 @@ [Maximum number of network connections]) dnl Finally really generate all output files: -AC_OUTPUT(Makefile ircd/Makefile doc/Makefile, [echo timestamp > stamp-h]) +AC_OUTPUT(Makefile ircd/Makefile ircd/test/Makefile doc/Makefile, [echo timestamp > stamp-h]) dnl Report configuration echo "IRC-Dev ircd is now hopefully configured for your system." Index: ircd-ircdev/doc/ircd.sample-en.conf diff -u ircd-ircdev/doc/ircd.sample-en.conf:1.9 ircd-ircdev/doc/ircd.sample-en.conf:1.10 --- ircd-ircdev/doc/ircd.sample-en.conf:1.9 Mon Dec 27 03:25:29 2004 +++ ircd-ircdev/doc/ircd.sample-en.conf Wed Jan 5 03:58:34 2005 @@ -53,8 +53,8 @@ # First some information about the server. # General { # name = "servername"; -# vhost = "virtualhost"; -# resolver = "ipaddress"; +# vhost = "ipv4vhost"; +# vhost = "ipv6vhost"; # description = "description"; # numeric = numericnumber; # }; @@ -66,8 +66,9 @@ # it. See "Port" block for listener virtual hosting. If in doubt, # leave it out. # -# You may need to specify the "resolver" address if your compile -# defaults to using IPv6 but your resolvers are all IPv4 hosts. +# You may specify both an IPv4 virtual host and an IPv6 virtual host, +# to indicate which address should be used for outbound connections +# of the respective type. # # Note that "numeric" field has to be unique on the network your server # is running on, must be between 0 and 4095, and is not updated on a rehash. Index: ircd-ircdev/doc/ircd.sample-es.conf diff -u ircd-ircdev/doc/ircd.sample-es.conf:1.5 ircd-ircdev/doc/ircd.sample-es.conf:1.6 --- ircd-ircdev/doc/ircd.sample-es.conf:1.5 Tue Dec 28 03:15:44 2004 +++ ircd-ircdev/doc/ircd.sample-es.conf Wed Jan 5 03:58:34 2005 @@ -59,8 +59,8 @@ # Primero una información sobre el servidor. # General { # name = "nombreservidor"; -# vhost = "virtualhost"; -# resolver = "direccionip"; +# vhost = "ipv4vhost"; +# vhost = "ipv6vhost"; # description = "descripcion"; # numeric = númerodenúmerico; # }; @@ -72,8 +72,9 @@ # "Connect" no la elimina. Veáse el bloque "Port" para la escucha con # virtual hosting. En caso de duda no pongas nada. # -# Puede que necesites especificar la dirección del resolvedor DNS si tu -# has compilado con IPv6 pero tus resolvedores son hosts de IPv4. +# Puedes especificar un virtualhost de IPv4 y un virtualhost de IPv6, +# para indicar cuál de las direcciones se debe utilizar para las +# conexiones salientes del tipo respectivo. # # Observe que el campo "numeric" tiene que ser único en la red si tu # servidor esta funcionando, y debe estar entre 0 y 4095, y no se Index: ircd-ircdev/include/patchlevel.h diff -u ircd-ircdev/include/patchlevel.h:1.15 ircd-ircdev/include/patchlevel.h:1.16 --- ircd-ircdev/include/patchlevel.h:1.15 Tue Dec 28 03:15:44 2004 +++ ircd-ircdev/include/patchlevel.h Wed Jan 5 03:58:34 2005 @@ -17,10 +17,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: patchlevel.h,v 1.15 2004/12/28 11:15:44 zolty Exp $ + * $Id: patchlevel.h,v 1.16 2005/01/05 11:58:34 zolty Exp $ * */ -#define PATCHLEVEL ".alpha14" +#define PATCHLEVEL ".alpha15" #define RELEASE "1.0" Index: ircd-ircdev/include/res.h diff -u ircd-ircdev/include/res.h:1.5 ircd-ircdev/include/res.h:1.6 --- ircd-ircdev/include/res.h:1.5 Wed Nov 24 08:00:43 2004 +++ ircd-ircdev/include/res.h Wed Jan 5 03:58:35 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief IRC resolver API. - * @version $Id: res.h,v 1.5 2004/11/24 16:00:43 zolty Exp $ + * @version $Id: res.h,v 1.6 2005/01/05 11:58:35 zolty Exp $ */ #ifndef INCLUDED_res_h @@ -148,9 +148,30 @@ extern void gethost_byname(const char *name, const struct DNSQuery *query); extern void gethost_byaddr(const struct irc_in_addr *addr, const struct DNSQuery *query); -extern int irc_in_addr_valid(const struct irc_in_addr *addr); -extern int irc_in_addr_cmp(const struct irc_in_addr *a, const struct irc_in_addr *b); -extern int irc_in_addr_is_ipv4(const struct irc_in_addr *addr); -extern int irc_in_addr_is_loopback(const struct irc_in_addr *addr); +/** 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] \ + || (ADDR)->in6_16[2] != (ADDR)->in6_16[0] \ + || (ADDR)->in6_16[3] != (ADDR)->in6_16[0] \ + || (ADDR)->in6_16[4] != (ADDR)->in6_16[0] \ + || (ADDR)->in6_16[5] != (ADDR)->in6_16[0] \ + || (ADDR)->in6_16[6] != (ADDR)->in6_16[0] \ + || (ADDR)->in6_16[7] != (ADDR)->in6_16[0]) +/** Evaluate to non-zero if \a ADDR (of type struct irc_in_addr) is an IPv4 address. */ +#define irc_in_addr_is_ipv4(ADDR) (!(ADDR)->in6_16[0] && !(ADDR)->in6_16[1] && !(ADDR)->in6_16[2] \ + && !(ADDR)->in6_16[3] && !(ADDR)->in6_16[4] && (ADDR)->in6_16[6] \ + && (!(ADDR)->in6_16[5] || (ADDR)->in6_16[5] == 65535)) +/** Evaluate to non-zero if \a A is a different IP than \a B. */ +#define irc_in_addr_cmp(A,B) (irc_in_addr_is_ipv4(A) ? ((A)->in6_16[6] != (B)->in6_16[6] \ + || (A)->in6_16[7] != (B)->in6_16[7] || !irc_in_addr_is_ipv4(B)) \ + : memcmp((A), (B), sizeof(struct irc_in_addr))) +/** Evaluate to non-zero if \a ADDR is a loopback address. */ +#define irc_in_addr_is_loopback(ADDR) (!(ADDR)->in6_16[0] && !(ADDR)->in6_16[1] && !(ADDR)->in6_16[2] \ + && !(ADDR)->in6_16[3] && !(ADDR)->in6_16[4] \ + && ((!(ADDR)->in6_16[5] \ + && ((!(ADDR)->in6_16[6] && (ADDR)->in6_16[7] == htons(1)) \ + || (ntohs((ADDR)->in6_16[6]) & 0xff00) == 0x7f00)) \ + || (((ADDR)->in6_16[5] == 65535) \ + && (ntohs((ADDR)->in6_16[6]) & 0xff00) == 0x7f00))) #endif Index: ircd-ircdev/include/s_bsd.h diff -u ircd-ircdev/include/s_bsd.h:1.4 ircd-ircdev/include/s_bsd.h:1.5 --- ircd-ircdev/include/s_bsd.h:1.4 Wed Nov 24 08:00:43 2004 +++ ircd-ircdev/include/s_bsd.h Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file s_bsd.h * @brief Wrapper functions to avoid direct use of BSD APIs. - * @version $Id: s_bsd.h,v 1.4 2004/11/24 16:00:43 zolty Exp $ + * @version $Id: s_bsd.h,v 1.5 2005/01/05 11:58:35 zolty Exp $ */ #ifndef INCLUDED_s_bsd_h #define INCLUDED_s_bsd_h @@ -73,7 +73,8 @@ extern int HighestFd; extern struct Client* LocalClientArray[MAXCONNECTIONS]; -extern struct irc_sockaddr VirtualHost; +extern struct irc_sockaddr VirtualHost_v4; +extern struct irc_sockaddr VirtualHost_v6; /* * Proto types Index: ircd-ircdev/include/sys.h diff -u ircd-ircdev/include/sys.h:1.2 ircd-ircdev/include/sys.h:1.3 --- ircd-ircdev/include/sys.h:1.2 Sun Feb 22 08:13:21 2004 +++ ircd-ircdev/include/sys.h Wed Jan 5 03:58:35 2005 @@ -18,20 +18,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: sys.h,v 1.2 2004/02/22 16:13:21 zolty Exp $ + * $Id: sys.h,v 1.3 2005/01/05 11:58:35 zolty Exp $ * */ #ifndef INCLUDED_sys_h #define INCLUDED_sys_h -#if WORDS_BIGENDIAN -# define BIT_ZERO_ON_LEFT -#else -# define BIT_ZERO_ON_RIGHT -#endif - -#define HAVE_RELIABLE_SIGNALS - /* * safety margin so we can always have one spare fd, for motd/authd or * whatever else. -24 allows "safety" margin of 10 listen ports, 8 servers @@ -39,23 +31,6 @@ */ #define MAXCLIENTS (MAXCONNECTIONS-24) -#ifdef HAVECURSES -#define DOCURSES -#else -#undef DOCURSES -#endif - -#ifdef HAVETERMCAP -#define DOTERMCAP -#else -#undef DOTERMCAP -#endif - -#ifndef CONFIG_SETUGID -#undef IRC_UID -#undef IRC_GID -#endif - /* Define FD_SETSIZE to what we want before including sys/types.h on BSD */ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__) #if ((!defined(USE_POLL)) && (!defined(FD_SETSIZE))) @@ -63,16 +38,7 @@ #endif #endif -#define LIMIT_FMT "%d" - #define IRCD_MAX(a, b) ((a) > (b) ? (a) : (b)) #define IRCD_MIN(a, b) ((a) < (b) ? (a) : (b)) -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif - #endif /* INCLUDED_sys_h */ Index: ircd-ircdev/include/uping.h diff -u ircd-ircdev/include/uping.h:1.3 ircd-ircdev/include/uping.h:1.4 --- ircd-ircdev/include/uping.h:1.3 Wed Nov 24 08:00:44 2004 +++ ircd-ircdev/include/uping.h Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief UDP ping implementation. - * @version $Id: uping.h,v 1.3 2004/11/24 16:00:44 zolty Exp $ + * @version $Id: uping.h,v 1.4 2005/01/05 11:58:35 zolty Exp $ */ #ifndef INCLUDED_uping_h #define INCLUDED_uping_h @@ -79,7 +79,6 @@ extern void uping_read(struct UPing* pptr); extern void uping_end(struct UPing* pptr); extern void uping_cancel(struct Client *sptr, struct Client *acptr); -extern void uping_echo(void); extern struct UPing* uping_begin(void); extern int uping_server(struct Client* sptr, struct ConfItem* aconf, int port, int count); Index: ircd-ircdev/ircd/.cvsignore diff -u ircd-ircdev/ircd/.cvsignore:1.3 ircd-ircdev/ircd/.cvsignore:1.4 --- ircd-ircdev/ircd/.cvsignore:1.3 Sun Feb 22 08:11:42 2004 +++ ircd-ircdev/ircd/.cvsignore Wed Jan 5 03:58:35 2005 @@ -4,6 +4,7 @@ ircd chkconf table_gen +umkpasswd chattr.tab.c autom4te.cache lex.yy.c Index: ircd-ircdev/ircd/IPcheck.c diff -u ircd-ircdev/ircd/IPcheck.c:1.6 ircd-ircdev/ircd/IPcheck.c:1.7 --- ircd-ircdev/ircd/IPcheck.c:1.6 Tue Dec 28 03:15:45 2004 +++ ircd-ircdev/ircd/IPcheck.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Code to count users connected from particular IP addresses. - * @version $Id: IPcheck.c,v 1.6 2004/12/28 11:15:45 zolty Exp $ + * @version $Id: IPcheck.c,v 1.7 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -330,12 +330,15 @@ */ int ip_registry_check_remote(struct Client* cptr, int is_burst) { - struct IPRegistryEntry* entry = ip_registry_find(&cli_ip(cptr)); + struct IPRegistryEntry* entry; /* * Mark that we did add/update an IPregistry entry */ SetIPChecked(cptr); + if (!irc_in_addr_valid(&cli_ip(cptr))) + return 1; + entry = ip_registry_find(&cli_ip(cptr)); if (0 == entry) { entry = ip_registry_new_entry(); ip_registry_canonicalize(&entry->addr, &cli_ip(cptr)); Index: ircd-ircdev/ircd/gline.c diff -u ircd-ircdev/ircd/gline.c:1.9 ircd-ircdev/ircd/gline.c:1.10 --- ircd-ircdev/ircd/gline.c:1.9 Tue Dec 28 03:15:45 2004 +++ ircd-ircdev/ircd/gline.c Wed Jan 5 03:58:35 2005 @@ -23,7 +23,7 @@ */ /** @file * @brief Implementation of Gline manipulation functions. - * @version $Id: gline.c,v 1.9 2004/12/28 11:15:45 zolty Exp $ + * @version $Id: gline.c,v 1.10 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -47,14 +47,12 @@ #include "msg.h" #include "numnicks.h" #include "numeric.h" -#include "sys.h" /* FALSE bleah */ #include "whocmds.h" /* #include <assert.h> -- Now using assert in ircd_log.h */ #include <string.h> #include <stdio.h> #include <stdlib.h> -#include <arpa/inet.h> /* for inet_ntoa */ #define CHECK_APPROVED 0 /**< Mask is acceptable */ #define CHECK_OVERRIDABLE 1 /**< Mask is acceptable, but not by default */ @@ -250,7 +248,7 @@ /* let the ops know about it */ sendto_opmask_butone(0, SNO_GLINE, "G-line active for %s", - get_client_name(acptr, TRUE)); + get_client_name(acptr, SHOW_IP)); /* and get rid of him */ if ((tval = exit_client_msg(cptr, acptr, &me, "G-lined (%s)", Index: ircd-ircdev/ircd/ircd.c diff -u ircd-ircdev/ircd/ircd.c:1.9 ircd-ircdev/ircd/ircd.c:1.10 --- ircd-ircdev/ircd/ircd.c:1.9 Tue Dec 28 03:15:45 2004 +++ ircd-ircdev/ircd/ircd.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Entry point and other initialization functions for the daemon. - * @version $Id: ircd.c,v 1.9 2004/12/28 11:15:45 zolty Exp $ + * @version $Id: ircd.c,v 1.10 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -246,79 +246,64 @@ */ static void try_connections(struct Event* ev) { struct ConfItem* aconf; - struct Client* cptr; struct ConfItem** pconf; - int connecting; - int confrq; time_t next = 0; struct ConnectionClass* cltmp; - struct ConfItem* con_conf = 0; struct Jupe* ajupe; - const char* con_class = NULL; + int hold; assert(ET_EXPIRE == ev_type(ev)); assert(0 != ev_timer(ev)); - connecting = FALSE; Debug((DEBUG_NOTICE, "Connection check at : %s", myctime(CurrentTime))); for (aconf = GlobalConfList; aconf; aconf = aconf->next) { - /* Also when already connecting! (update holdtimes) --SRB */ - if (!(aconf->status & CONF_SERVER) || aconf->address.port == 0 || aconf->hold == 0) - continue; - - /* Also skip juped servers */ - if ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe)) - continue; - - /* Skip this entry if the use of it is still on hold until - * future. Otherwise handle this entry (and set it on hold until next - * time). Will reset only hold times, if already made one successfull - * connection... [this algorithm is a bit fuzzy... -- msa >;) ] + /* Only consider server items with non-zero port and non-zero + * connect times that are not actively juped. */ - if (aconf->hold > CurrentTime && (next > aconf->hold || next == 0)) { - next = aconf->hold; + if (!(aconf->status & CONF_SERVER) + || aconf->address.port == 0 + || aconf->hold == 0 + || ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe))) continue; - } + /* Update next possible connection check time. */ + if (next > aconf->hold || next == 0) + next = aconf->hold; + + /* Update the next time we can consider this entry. */ cltmp = aconf->conn_class; - confrq = get_con_freq(cltmp); - if(confrq == 0) - aconf->hold = next = 0; - else - aconf->hold = CurrentTime + confrq; + hold = aconf->hold > CurrentTime; /* before we update aconf->hold */ + aconf->hold = ConFreq(cltmp) ? CurrentTime + ConFreq(cltmp) : 0; - /* Found a CONNECT config with port specified, scan clients and see if - * this server is already connected? + /* Do not try to connect if its use is still on hold until future, + * too many links in its connection class, it is already linked, + * or if connect rules forbid a link now. */ - cptr = FindServer(aconf->name); - - if (!cptr && (Links(cltmp) < MaxLinks(cltmp)) && - (!connecting /*|| (ConClass(cltmp) > con_class)*/)) { - /* - * Check connect rules to see if we're allowed to try - */ - if (0 == conf_eval_crule(aconf->name, CRULE_MASK)) { - con_class = ConClass(cltmp); - con_conf = aconf; - /* We connect only one at time... */ - connecting = TRUE; - } + if (hold + || (Links(cltmp) >= MaxLinks(cltmp)) + || FindServer(aconf->name) + || conf_eval_crule(aconf->name, CRULE_MASK)) { + continue; } - if ((next > aconf->hold) || (next == 0)) - next = aconf->hold; - } - if (connecting) { - if (con_conf->next) { /* are we already last? */ - /* Put the current one at the end and make sure we try all connections */ - for (pconf = &GlobalConfList; (aconf = *pconf); pconf = &(aconf->next)) - if (aconf == con_conf) + + /* Ensure it is at the end of the list for future checks. */ + if (aconf->next) { + /* Find aconf's location in the list and splice it out. */ + for (pconf = &GlobalConfList; *pconf; pconf = &(*pconf)->next) + if (*pconf == aconf) *pconf = aconf->next; - (*pconf = con_conf)->next = 0; + /* Reinsert it at the end of the list (where pconf is now). */ + *pconf = aconf; + aconf->next = 0; } - if (connect_server(con_conf, 0)) + /* Activate the connection itself. */ + if (connect_server(aconf, 0)) sendto_opmask_butone(0, SNO_OLDSNO, "Connection to %s activated.", - con_conf->name); + aconf->name); + + /* And stop looking for further candidates. */ + break; } if (next == 0) Index: ircd-ircdev/ircd/ircd_auth.c diff -u ircd-ircdev/ircd/ircd_auth.c:1.2 ircd-ircdev/ircd/ircd_auth.c:1.3 --- ircd-ircdev/ircd/ircd_auth.c:1.2 Tue Dec 28 03:15:45 2004 +++ ircd-ircdev/ircd/ircd_auth.c Wed Jan 5 03:58:35 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief IAuth client implementation for an IRC server. - * @version $Id: ircd_auth.c,v 1.2 2004/12/28 11:15:45 zolty Exp $ + * @version $Id: ircd_auth.c,v 1.3 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" #include "client.h" @@ -51,7 +51,6 @@ #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> -#include <arpa/inet.h> #ifdef HAVE_STDINT_H #include <stdint.h> #endif @@ -448,6 +447,7 @@ */ static void iauth_reconnect(struct IAuth *iauth) { + struct irc_sockaddr *local; IOResult result; int fd; @@ -459,7 +459,8 @@ gethost_byname(i_host(iauth), &i_query(iauth)); return; } - fd = os_socket(&VirtualHost, SOCK_STREAM, "IAuth"); + local = irc_in_addr_is_ipv4(&i_addr(iauth).addr) ? &VirtualHost_v4 : &VirtualHost_v6; + fd = os_socket(local, SOCK_STREAM, "IAuth"); if (fd < 0) return; if (!os_set_sockbufs(fd, SERVER_TCP_WINDOW, SERVER_TCP_WINDOW)) { Index: ircd-ircdev/ircd/ircd_lexer.l diff -u ircd-ircdev/ircd/ircd_lexer.l:1.6 ircd-ircdev/ircd/ircd_lexer.l:1.7 --- ircd-ircdev/ircd/ircd_lexer.l:1.6 Tue Dec 28 03:15:45 2004 +++ ircd-ircdev/ircd/ircd_lexer.l Wed Jan 5 03:58:35 2005 @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: ircd_lexer.l,v 1.6 2004/12/28 11:15:45 zolty Exp $ + * $Id: ircd_lexer.l,v 1.7 2005/01/05 11:58:35 zolty Exp $ * */ @@ -78,7 +78,6 @@ TOKEN(OPER), TOKEN(LOCAL), TOKEN(VHOST), - TOKEN(RESOLVER), TOKEN(MASK), TOKEN(HIDDEN), TOKEN(MOTD), Index: ircd-ircdev/ircd/ircd_parser.y diff -u ircd-ircdev/ircd/ircd_parser.y:1.8 ircd-ircdev/ircd/ircd_parser.y:1.9 --- ircd-ircdev/ircd/ircd_parser.y:1.8 Tue Dec 28 03:15:45 2004 +++ ircd-ircdev/ircd/ircd_parser.y Wed Jan 5 03:58:35 2005 @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: ircd_parser.y,v 1.8 2004/12/28 11:15:45 zolty Exp $ + * $Id: ircd_parser.y,v 1.9 2005/01/05 11:58:35 zolty Exp $ * */ %{ @@ -67,7 +67,6 @@ extern struct ServerConf* serverConfList; extern struct s_map* GlobalServiceMapList; extern struct qline* GlobalQuarantineList; - extern struct irc_sockaddr ResolverAddr; int yylex(void); /* Now all the globals we need :/... */ @@ -138,7 +137,6 @@ %token NO %token OPER %token VHOST -%token RESOLVER %token HIDDEN %token MOTD %token JUPE @@ -275,7 +273,7 @@ parse_error("Your General block must contain a numeric (between 1 and 4095)."); } ';' ; generalitems: generalitem generalitems | generalitem; -generalitem: generalnumeric | generalname | generalvhost | generalresolver | generaldesc | error; +generalitem: generalnumeric | generalname | generalvhost | generaldesc | error; generalnumeric: NUMERIC '=' NUMBER ';' { if (localConf.numeric == 0) @@ -303,12 +301,13 @@ generalvhost: VHOST '=' QSTRING ';' { - ircd_aton(&VirtualHost.addr, $3); -}; - -generalresolver: RESOLVER '=' QSTRING ';' -{ - ircd_aton(&ResolverAddr.addr, $3); + struct irc_in_addr addr; + if (!ircd_aton(&addr, $3)) + parse_error("Invalid virtual host '%s'.", $3); + else if (irc_in_addr_is_ipv4(&addr)) + memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr)); + else + memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr)); }; adminblock: ADMIN '{' adminitems '}' Index: ircd-ircdev/ircd/ircd_res.c diff -u ircd-ircdev/ircd/ircd_res.c:1.2 ircd-ircdev/ircd/ircd_res.c:1.3 --- ircd-ircdev/ircd/ircd_res.c:1.2 Tue Dec 28 03:15:45 2004 +++ ircd-ircdev/ircd/ircd_res.c Wed Jan 5 03:58:35 2005 @@ -41,7 +41,7 @@ */ /** @file * @brief IRC resolver functions. - * @version $Id: ircd_res.c,v 1.2 2004/12/28 11:15:45 zolty Exp $ + * @version $Id: ircd_res.c,v 1.3 2005/01/05 11:58:35 zolty Exp $ */ #include "client.h" #include "ircd_alloc.h" @@ -72,8 +72,10 @@ #error this code needs to be able to address individual octets #endif -/** Resolver UDP socket. */ -static struct Socket res_socket; +/** IPv4 resolver UDP socket. */ +static struct Socket res_socket_v4; +/** IPv6 resolver UDP socket. */ +static struct Socket res_socket_v6; /** Next DNS lookup timeout. */ static struct Timer res_timeout; /** Check for whether the resolver has been initialized yet. */ @@ -162,8 +164,6 @@ extern int irc_nscount; extern char irc_domain[HOSTLEN]; -struct irc_sockaddr ResolverAddr; - /** Check whether \a inp is a nameserver we use. * @param[in] inp Nameserver address. * @return Non-zero if we trust \a inp; zero if not. @@ -193,17 +193,24 @@ if (!request_list.next) request_list.next = request_list.prev = &request_list; - if (!s_active(&res_socket)) + if (!s_active(&res_socket_v4)) { - struct irc_sockaddr *local; - int fd; - local = irc_in_addr_valid(&ResolverAddr.addr) ? &ResolverAddr : &VirtualHost; - fd = os_socket(local, SOCK_DGRAM, "Resolver UDP socket"); - if (fd < 0) return; - if (!socket_add(&res_socket, res_readreply, NULL, SS_DATAGRAM, - SOCK_EVENT_READABLE, fd)) return; - timer_init(&res_timeout); + int fd = os_socket(&VirtualHost_v4, SOCK_DGRAM, "Resolver UDPv4 socket"); + if (fd >= 0) + socket_add(&res_socket_v4, res_readreply, NULL, + SS_DATAGRAM, SOCK_EVENT_READABLE, fd); + } + + if (!s_active(&res_socket_v6)) + { + int fd = os_socket(&VirtualHost_v6, SOCK_DGRAM, "Resolver UDPv6 socket"); + if (fd >= 0) + socket_add(&res_socket_v6, res_readreply, NULL, + SS_DATAGRAM, SOCK_EVENT_READABLE, fd); } + + if (s_active(&res_socket_v4) || s_active(&res_socket_v6)) + timer_init(&res_timeout); } /** Append local domain to hostname if needed. @@ -387,9 +394,11 @@ if (max_queries == 0) max_queries = 1; - for (i = 0; i < max_queries; i++) - if (os_sendto_nonb(s_fd(&res_socket), msg, len, NULL, 0, &irc_nsaddr_list[i]) == IO_SUCCESS) + for (i = 0; i < max_queries; i++) { + int fd = irc_in_addr_is_ipv4(&irc_nsaddr_list[i].addr) ? s_fd(&res_socket_v4) : s_fd(&res_socket_v6); + if (os_sendto_nonb(fd, msg, len, NULL, 0, &irc_nsaddr_list[i]) == IO_SUCCESS) ++sent; + } return(sent); } @@ -755,7 +764,7 @@ unsigned int rc; int answer_count; - assert(ev_socket(ev) == &res_socket); + assert((ev_socket(ev) == &res_socket_v4) || (ev_socket(ev) == &res_socket_v6)); sock = ev_socket(ev); if (IO_SUCCESS != os_recvfrom_nonb(s_fd(sock), buf, sizeof(buf), &rc, &lsin) @@ -941,55 +950,3 @@ ":Resolver: requests %d(%d)", request_count, request_mem); return request_mem; } - -/** Check whether an address looks valid. - * This means not all 0s and not all 1s. - * @param[in] addr Address to check for validity. - * @return Non-zero if the address looks valid. - */ -int irc_in_addr_valid(const struct irc_in_addr *addr) -{ - unsigned int ii; - unsigned short val; - - val = addr->in6_16[0]; - if (val != 0 && val != 0xffff) - return 1; - for (ii = 1; ii < 8; ii++) - if (addr->in6_16[ii] != val) - return 1; - return 0; -} - -/** Compare two IP addresses. - * @param[in] a First address to compare. - * @param[in] b Second address to compare. - * @return Non-zero if the two addresses differ, zero if they are identical. - */ -int irc_in_addr_cmp(const struct irc_in_addr *a, const struct irc_in_addr *b) -{ - if (irc_in_addr_is_ipv4(a)) - return a->in6_16[6] != b->in6_16[6] - || a->in6_16[7] != b->in6_16[7] - || !irc_in_addr_is_ipv4(b); - else - return memcmp(a, b, sizeof(*a)); -} - -/** Indicate whether an IP address is a loopback address. - * @param[in] addr Address to check. - * @return Non-zero if the address is loopback; zero if not. - */ -int irc_in_addr_is_loopback(const struct irc_in_addr *addr) -{ - if (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) - return 0; - if ((addr->in6_16[5] == 0xffff) || (addr->in6_16[5] == 0 && addr->in6_16[6] != 0)) - return (ntohs(addr->in6_16[6]) & 0xff00) == 0x7f00; - else - return addr->in6_16[5] == 0 && addr->in6_16[6] == 0 && htons(addr->in6_16[7]) == 1; -} Index: ircd-ircdev/ircd/ircd_string.c diff -u ircd-ircdev/ircd/ircd_string.c:1.5 ircd-ircdev/ircd/ircd_string.c:1.6 --- ircd-ircdev/ircd/ircd_string.c:1.5 Tue Dec 28 03:15:46 2004 +++ ircd-ircdev/ircd/ircd_string.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Implementation of string operations. - * @version $Id: ircd_string.c,v 1.5 2004/12/28 11:15:46 zolty Exp $ + * @version $Id: ircd_string.c,v 1.6 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -453,22 +453,6 @@ return ircd_ntoa_r(buf, in); } -/* This doesn't really belong here, but otherwise umkpasswd breaks. */ -/** Check whether an IP address looks like an IPv4 address. - * @param[in] addr Address to check. - * @return Non-zero if the address is a valid IPv4 address, zero if not. - */ -int irc_in_addr_is_ipv4(const struct irc_in_addr *addr) -{ - return 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[5] == 0 || addr->in6_16[5] == 0xffff) - && addr->in6_16[6] != 0; -} - /** Convert an IP address to printable ASCII form. * @param[out] buf Output buffer to write to. * @param[in] in Address to format. @@ -539,8 +523,6 @@ if (ii < 7) APPEND(':'); } - if (max_zeros + max_start == 8) - APPEND(':'); #undef APPEND /* Nul terminate and return number of characters used. */ @@ -653,24 +635,31 @@ case '.': { uint32_t ip4; unsigned int len; - len = ircd_aton_ip4(input + pos, &ip4); + len = ircd_aton_ip4(part_start, &ip4); if (!len || (ii > 6)) return 0; ip->in6_16[ii++] = htons(ntohl(ip4) >> 16); ip->in6_16[ii++] = htons(ntohl(ip4) & 65535); - pos += len; - break; + if (colon < 8) { + unsigned int jj; + /* Shift stuff after "::" up and fill middle with zeros. */ + for (jj = 0; jj < ii - colon; jj++) + ip->in6_16[7 - jj] = ip->in6_16[ii - jj - 1]; + for (jj = 0; jj < 8 - ii; jj++) + ip->in6_16[colon + jj] = 0; + } + return part_start - input + len; } default: { - unsigned int jj; - if (colon >= 8) - return 0; - /* Shift stuff after "::" up and fill middle with zeros. */ ip->in6_16[ii++] = htons(part); - for (jj = 0; jj < ii - colon; jj++) - ip->in6_16[7 - jj] = ip->in6_16[ii - jj - 1]; - for (jj = 0; jj < 8 - ii; jj++) - ip->in6_16[colon + jj] = 0; + if (colon < 8) { + unsigned int jj; + /* Shift stuff after "::" up and fill middle with zeros. */ + for (jj = 0; jj < ii - colon; jj++) + ip->in6_16[7 - jj] = ip->in6_16[ii - jj - 1]; + for (jj = 0; jj < 8 - ii; jj++) + ip->in6_16[colon + jj] = 0; + } return pos; } } Index: ircd-ircdev/ircd/listener.c diff -u ircd-ircdev/ircd/listener.c:1.6 ircd-ircdev/ircd/listener.c:1.7 --- ircd-ircdev/ircd/listener.c:1.6 Tue Dec 28 03:15:46 2004 +++ ircd-ircdev/ircd/listener.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Implementation for handling listening sockets. - * @version $Id: listener.c,v 1.6 2004/12/28 11:15:46 zolty Exp $ + * @version $Id: listener.c,v 1.7 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -53,7 +53,6 @@ #include <unistd.h> #include <netdb.h> #include <sys/socket.h> -#include <arpa/inet.h> /** List of listening sockets. */ struct Listener* ListenerPollList = 0; Index: ircd-ircdev/ircd/match.c diff -u ircd-ircdev/ircd/match.c:1.4 ircd-ircdev/ircd/match.c:1.5 --- ircd-ircdev/ircd/match.c:1.4 Wed Nov 24 08:06:15 2004 +++ ircd-ircdev/ircd/match.c Wed Jan 5 03:58:35 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief Functions to match strings against IRC mask strings. - * @version $Id: match.c,v 1.4 2004/11/24 16:06:15 zolty Exp $ + * @version $Id: match.c,v 1.5 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -852,7 +852,6 @@ #include <string.h> #include <sys/socket.h> #include <netinet/in.h> -#include <arpa/inet.h> /** Parse an input string as an IPv4 address. * @param[in] in Text form of address. @@ -862,15 +861,13 @@ static int ipmask_parse_ipv4(const char *in, struct in_addr *out) { int class; - char ipname[16]; int ad[4] = { 0 }; int bits = 0; class = sscanf(in, "%d.%d.%d.%d/%d", &ad[0], &ad[1], &ad[2], &ad[3], &bits); if (class != 5) bits = class * 8; - ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1], ad[2], ad[3]); - out->s_addr = inet_addr(ipname); + out->s_addr = ntohl((ad[0] << 24) | (ad[1] << 16) | (ad[2] << 8) | ad[3]); return bits; } Index: ircd-ircdev/ircd/os_generic.c diff -u ircd-ircdev/ircd/os_generic.c:1.4 ircd-ircdev/ircd/os_generic.c:1.5 --- ircd-ircdev/ircd/os_generic.c:1.4 Tue Dec 28 03:15:46 2004 +++ ircd-ircdev/ircd/os_generic.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Implementation of OS-dependent operations. - * @version $Id: os_generic.c,v 1.4 2004/12/28 11:15:46 zolty Exp $ + * @version $Id: os_generic.c,v 1.5 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -110,28 +110,18 @@ socklen_t slen; int family; + assert(irc != 0); slen = sizeof(sin6); - if (0 <= compat_fd) { - if (0 == getsockname(compat_fd, (struct sockaddr*)&sin6, &slen)) - family = sin6.sin6_family; - else if (irc_in_addr_is_ipv4(&VirtualHost.addr)) - family = AF_INET; - else - family = AF_INET6; - } else { - if (irc_in_addr_is_ipv4(&irc->addr)) - family = AF_INET; - else - family = AF_INET6; - } + 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)) + family = AF_INET; + else + family = AF_INET6; - memset(v6, 0, sizeof(*v6)); - if (!irc) { - memset(v6, 0, sizeof(v6)); - v6->sin6_family = AF_INET6; - return sizeof(*v6); - } - else if ((family == AF_INET) && irc_in_addr_is_ipv4(&irc->addr)) { + memset(v6, 0, sizeof(*v6)); + if (family == AF_INET) { struct sockaddr_in *v4 = (struct sockaddr_in*)v6; v4->sin_family = AF_INET; memcpy(&v4->sin_addr, &irc->addr.in6_16[6], sizeof(v4->sin_addr)); @@ -160,6 +150,7 @@ int sockaddr_from_irc(struct sockaddr_in *v4, const struct irc_sockaddr *irc, int compat_fd) { + assert(irc != 0); v4->sin_family = AF_INET; if (irc) { assert(!irc->addr.in6_16[0] && !irc->addr.in6_16[1] && !irc->addr.in6_16[2] && !irc->addr.in6_16[3] && !irc->addr.in6_16[4] && (!irc->addr.in6_16[5] || irc->addr.in6_16[5] == 0xffff)); @@ -520,6 +511,7 @@ errno = 0; size = sockaddr_from_irc(&addr, peer, fd); + 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) *count_out = (unsigned) res; @@ -621,6 +613,7 @@ struct sockaddr_native addr; int size, fd; + assert(local != 0); size = sockaddr_from_irc(&addr, local, -1); fd = socket(addr.sn_family, type, 0); if (fd < 0) { Index: ircd-ircdev/ircd/s_auth.c diff -u ircd-ircdev/ircd/s_auth.c:1.6 ircd-ircdev/ircd/s_auth.c:1.7 --- ircd-ircdev/ircd/s_auth.c:1.6 Tue Dec 28 03:15:46 2004 +++ ircd-ircdev/ircd/s_auth.c Wed Jan 5 03:58:35 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief Implementation of DNS and ident lookups. - * @version $Id: s_auth.c,v 1.6 2004/12/28 11:15:46 zolty Exp $ + * @version $Id: s_auth.c,v 1.7 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -49,7 +49,6 @@ #include "struct.h" #include "sys.h" /* TRUE bleah */ -#include <arpa/inet.h> /* inet_netof */ #include <netdb.h> /* struct hostent */ #include <string.h> #include <stdlib.h> Index: ircd-ircdev/ircd/s_bsd.c diff -u ircd-ircdev/ircd/s_bsd.c:1.7 ircd-ircdev/ircd/s_bsd.c:1.8 --- ircd-ircdev/ircd/s_bsd.c:1.7 Tue Dec 28 03:15:46 2004 +++ ircd-ircdev/ircd/s_bsd.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Functions that now (or in the past) relied on BSD APIs. - * @version $Id: s_bsd.c,v 1.7 2004/12/28 11:15:46 zolty Exp $ + * @version $Id: s_bsd.c,v 1.8 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -60,7 +60,6 @@ #include "uping.h" #include "version.h" -#include <arpa/inet.h> /* #include <assert.h> -- Now using assert in ircd_log.h */ #include <errno.h> #include <fcntl.h> @@ -82,8 +81,10 @@ struct Client* LocalClientArray[MAXCONNECTIONS]; /** Maximum file descriptor in current use. */ int HighestFd = -1; -/** Default local address for outbound connections. */ -struct irc_sockaddr VirtualHost; +/** Default local address for outbound IPv4 connections. */ +struct irc_sockaddr VirtualHost_v4; +/** Default local address for outbound IPv6 connections. */ +struct irc_sockaddr VirtualHost_v6; /** Temporary buffer for reading data from a peer. */ static char readbuf[SERVER_TCP_WINDOW]; @@ -237,8 +238,10 @@ */ if (irc_in_addr_valid(&aconf->origin.addr)) local = &aconf->origin; + else if (irc_in_addr_is_ipv4(&aconf->address.addr)) + local = &VirtualHost_v4; else - local = &VirtualHost; + local = &VirtualHost_v6; cli_fd(cptr) = os_socket(local, SOCK_STREAM, cli_name(cptr)); if (cli_fd(cptr) < 0) return 0; Index: ircd-ircdev/ircd/s_conf.c diff -u ircd-ircdev/ircd/s_conf.c:1.8 ircd-ircdev/ircd/s_conf.c:1.9 --- ircd-ircdev/ircd/s_conf.c:1.8 Tue Dec 28 03:15:46 2004 +++ ircd-ircdev/ircd/s_conf.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief ircd configuration file driver - * @version $Id: s_conf.c,v 1.8 2004/12/28 11:15:46 zolty Exp $ + * @version $Id: s_conf.c,v 1.9 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -59,7 +59,6 @@ #include "sys.h" /* #include <assert.h> -- Now using assert in ircd_log.h */ -#include <arpa/inet.h> #include <errno.h> #include <fcntl.h> #include <netdb.h> Index: ircd-ircdev/ircd/s_user.c diff -u ircd-ircdev/ircd/s_user.c:1.9 ircd-ircdev/ircd/s_user.c:1.10 --- ircd-ircdev/ircd/s_user.c:1.9 Tue Dec 28 03:15:47 2004 +++ ircd-ircdev/ircd/s_user.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Miscellaneous user-related helper functions. - * @version $Id: s_user.c,v 1.9 2004/12/28 11:15:47 zolty Exp $ + * @version $Id: s_user.c,v 1.10 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -1706,7 +1706,7 @@ /** Check whether \a sptr is allowed to send a message to \a acptr. * If \a sptr is a remote user, it means some server has an outdated * SILENCE list for \a acptr, so send the missing SILENCE mask(s) back - * in the direction of \a sptr. + * in the direction of \a sptr. Skip the check if \a sptr is a server. * @param[in] sptr Client trying to send a message. * @param[in] acptr Destination of message. * @return Non-zero if \a sptr is SILENCEd by \a acptr, zero if not. @@ -1718,7 +1718,7 @@ size_t buf_used, slen; char buf[BUFSIZE]; - if (!(user = cli_user(acptr)) + if (IsServer(sptr) || !(user = cli_user(acptr)) || !(found = find_ban(sptr, user->silence))) return 0; assert(!(found->flags & BAN_EXCEPTION)); Index: ircd-ircdev/ircd/test/.cvsignore diff -u /dev/null ircd-ircdev/ircd/test/.cvsignore:1.1 --- /dev/null Wed Jan 5 03:58:51 2005 +++ ircd-ircdev/ircd/test/.cvsignore Wed Jan 5 03:58:36 2005 @@ -0,0 +1,4 @@ +Makefile +ircd_chattr_t +ircd_in_addr_t +ircd_string_t Index: ircd-ircdev/ircd/test/Makefile diff -u ircd-ircdev/ircd/test/Makefile:1.1.1.1 ircd-ircdev/ircd/test/Makefile:removed --- ircd-ircdev/ircd/test/Makefile:1.1.1.1 Mon Sep 8 03:34:31 2003 +++ ircd-ircdev/ircd/test/Makefile Wed Jan 5 03:58:51 2005 @@ -1,20 +0,0 @@ - -CPPFLAGS = -I../../include -I../../config -CFLAGS = -g -Wall - -TESTPROGS = \ - ircd_chattr_t \ - ircd_string_t - -all: ${TESTPROGS} - -ircd_chattr_t: ircd_chattr_t.o ../ircd_string.o - ${CC} -o $@ $^ - -ircd_string_t: ircd_string_t.o ../ircd_string.o - ${CC} -o $@ $^ - -.PHONY: clean - -clean: - rm -f core *.o ${TESTPROGS} Index: ircd-ircdev/ircd/test/Makefile.in diff -u /dev/null ircd-ircdev/ircd/test/Makefile.in:1.1 --- /dev/null Wed Jan 5 03:58:52 2005 +++ ircd-ircdev/ircd/test/Makefile.in Wed Jan 5 03:58:36 2005 @@ -0,0 +1,54 @@ +# IRC-Dev IRCD - An advanced and innovative IRC Daemon, ircd/test/Makefile + +# Copyright (C) 2002-2004 IRC-Dev Development Team <de...@ir...> +# Copyright (C) 1997 Carlo Wood +# Copyright (C) 1990 Jarkko Oikarinen + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA + +# $Id: Makefile.in,v 1.1 2005/01/05 11:58:36 zolty Exp $ + +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +CPPFLAGS = -I${top_srcdir}/include -I../.. +CFLAGS = -g -Wall + +TESTPROGS = \ + ircd_chattr_t \ + ircd_string_t \ + ircd_in_addr_t + +all: ${TESTPROGS} + +build: ${TESTPROGS} + +depend: + +ircd_chattr_t: ircd_chattr_t.o test_stub.o ../ircd_string.o + ${CC} -o $@ $^ + +ircd_string_t: ircd_string_t.o test_stub.o ../ircd_string.o + ${CC} -o $@ $^ + +ircd_in_addr_t: ircd_in_addr_t.o test_stub.o ../ircd_alloc.o ../ircd_string.o ../match.o ../numnicks.o + ${CC} -o $@ $^ + +.PHONY: distclean clean + +distclean: clean + rm -f Makefile + +clean: + rm -f core *.o ${TESTPROGS} Index: ircd-ircdev/ircd/test/ircd_in_addr_t.c diff -u /dev/null ircd-ircdev/ircd/test/ircd_in_addr_t.c:1.1 --- /dev/null Wed Jan 5 03:58:52 2005 +++ ircd-ircdev/ircd/test/ircd_in_addr_t.c Wed Jan 5 03:58:36 2005 @@ -0,0 +1,92 @@ +/* ircd_in_addr_t.c - Test file for IP address manipulation */ + +#include "ircd_log.h" +#include "ircd_string.h" +#include "numnicks.h" +#include "res.h" +#include <stdio.h> +#include <string.h> +#include <netinet/in.h> + +/** Structure to describe a test for IP address parsing and unparsing. */ +struct address_test { + const char *text; /**< Textual address to parse. */ + const char *canonical; /**< Canonical form of address. */ + struct irc_in_addr expected; /**< Parsed address. */ + const char *base64_v4; /**< v4-only compatible base64 encoding. */ + const char *base64_v6; /**< v6-compatible base64 encoding. */ + unsigned int is_valid : 1; /**< is address valid? */ + unsigned int is_ipv4 : 1; /**< is address ipv4? */ + unsigned int is_loopback : 1; /**< is address loopback? */ +}; + +/** Array of addresses to test with. */ +static struct address_test test_addrs[] = { + { "::", "0::", + {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, + "AAAAAA", "_", 0, 0, 0 }, + { "::1", "0::1", + {{ 0, 0, 0, 0, 0, 0, 0, 1 }}, + "AAAAAA", "_AAB", 1, 0, 1 }, + { "127.0.0.1", "127.0.0.1", + {{ 0, 0, 0, 0, 0, 0, 0x7f00, 1 }}, + "B]AAAB", "B]AAAB", 1, 1, 1 }, + { "::ffff:127.0.0.3", "127.0.0.3", + {{ 0, 0, 0, 0, 0, 0xffff, 0x7f00, 3 }}, + "B]AAAD", "B]AAAD", 1, 1, 1 }, + { "2002:7f00:3::1", "2002:7f00:3::1", + {{ 0x2002, 0x7f00, 3, 0, 0, 0, 0, 1 }}, + "B]AAAD", "CACH8AAAD_AAB", 1, 0, 0 }, + { "8352:0344:0:0:0:0:2001:1204", "8352:344::2001:1204", + {{ 0x8352, 0x344, 0, 0, 0, 0, 0x2001, 0x1204 }}, + "AAAAAA", "INSANE_CABBIE", 1, 0, 0 }, + { 0 }, +}; + +/** Perform tests for a single IP address. + * @param[in] addr Address test structure. + */ +static void +test_address(struct address_test *addr) +{ + struct irc_in_addr parsed; + unsigned int ii, len, val; + char unparsed[64], base64_v4[64], base64_v6[64]; + + /* Convert expected address to network order. */ + for (ii = 0; ii < 8; ++ii) + addr->expected.in6_16[ii] = htons(addr->expected.in6_16[ii]); + /* Make sure the text form is parsed as expected. */ + len = ircd_aton(&parsed, addr->text); + assert(len == strlen(addr->text)); + assert(!irc_in_addr_cmp(&parsed, &addr->expected)); + /* Make sure it converts back to ASCII. */ + ircd_ntoa_r(unparsed, &parsed); + assert(!strcmp(unparsed, addr->canonical)); + /* Check IP-to-base64 conversion. */ + iptobase64(base64_v4, &parsed, sizeof(base64_v4), 0); + iptobase64(base64_v6, &parsed, sizeof(base64_v6), 1); + if (addr->base64_v4) + assert(!strcmp(base64_v4, addr->base64_v4)); + if (addr->base64_v6) + assert(!strcmp(base64_v6, addr->base64_v6)); + /* Check testable attributes. */ + val = irc_in_addr_valid(&parsed); + assert(!!val == addr->is_valid); + val = irc_in_addr_is_ipv4(&parsed); + assert(!!val == addr->is_ipv4); + val = irc_in_addr_is_loopback(&parsed); + assert(!!val == addr->is_loopback); + printf("Passed: %s (%s/%s)\n", addr->text, base64_v4, base64_v6); +} + +int +main(int argc, char *argv[]) +{ + unsigned int ii; + + for (ii = 0; test_addrs[ii].text; ++ii) + test_address(&test_addrs[ii]); + + return 0; +} Index: ircd-ircdev/ircd/test/test_stub.c diff -u /dev/null ircd-ircdev/ircd/test/test_stub.c:1.1 --- /dev/null Wed Jan 5 03:58:52 2005 +++ ircd-ircdev/ircd/test/test_stub.c Wed Jan 5 03:58:36 2005 @@ -0,0 +1,39 @@ +/* test_stub.c - support stubs for test programs */ + +#include "client.h" +#include "ircd_log.h" +#include "s_debug.h" +#include <stdarg.h> +#include <stdio.h> + +struct Client me; +int log_inassert; + +void +log_write(enum LogSys subsys, enum LogLevel severity, unsigned int flags, + const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); +} + +void +debug(int level, const char *form, ...) +{ + va_list args; + + va_start(args, form); + vfprintf(stdout, form, args); + va_end(args); +} + +int +exit_client(struct Client *cptr, struct Client *bcptr, struct Client *sptr, + const char *comment) +{ + Debug((DEBUG_LIST, "exit_client(%p, %p, %p, \"%s\")\n", cptr, bcptr, sptr, comment)); + return 0; +} Index: ircd-ircdev/ircd/uping.c diff -u ircd-ircdev/ircd/uping.c:1.5 ircd-ircdev/ircd/uping.c:1.6 --- ircd-ircdev/ircd/uping.c:1.5 Tue Dec 28 03:15:47 2004 +++ ircd-ircdev/ircd/uping.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief UDP ping implementation. - * @version $Id: uping.c,v 1.5 2004/12/28 11:15:47 zolty Exp $ + * @version $Id: uping.c,v 1.6 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -45,7 +45,6 @@ #include "send.h" #include "sys.h" -#include <arpa/inet.h> /* #include <assert.h> -- Now using assert in ircd_log.h */ #include <errno.h> #include <netdb.h> @@ -59,8 +58,8 @@ #define UPINGTIMEOUT 60 /**< Timeout waiting for ping responses */ static struct UPing* pingList = 0; /**< Linked list of UPing structs */ -static int UPingFileDescriptor = -1; /**< UDP listener socket for upings */ -static struct Socket upingSock; /**< Socket struct for upings */ +static struct Socket upingSock_v4; /**< Socket struct for IPv4 upings */ +static struct Socket upingSock_v6; /**< Socket struct for IPv6 upings */ /** Start iteration of uping list. * @return Start of uping list. @@ -92,71 +91,77 @@ } /** Callback for uping listener socket. + * Reads a uping from the socket and respond, but not more than 10 + * times per second. * @param[in] ev I/O event for uping socket. */ static void uping_echo_callback(struct Event* ev) { + struct Socket *sock; + struct irc_sockaddr from; + unsigned int len = 0; + static time_t last = 0; + static int counter = 0; + char buf[BUFSIZE + 1]; + assert(ev_type(ev) == ET_READ || ev_type(ev) == ET_ERROR); + sock = ev_socket(ev); + assert(sock == &upingSock_v4 || sock == &upingSock_v6); - uping_echo(); + Debug((DEBUG_DEBUG, "UPING: uping_echo")); + + if (IO_SUCCESS != os_recvfrom_nonb(s_fd(sock), buf, BUFSIZE, &len, &from)) + return; + /* + * count em even if we're getting flooded so we can tell we're getting + * flooded. + */ + ++ServerStats->uping_recv; + if (len < 19) + return; + else if (CurrentTime != last) { + counter = 0; + last = CurrentTime; + } else if (++counter > 10) + return; + os_sendto_nonb(s_fd(sock), buf, len, NULL, 0, &from); } /** Initialize a UDP socket for upings. - * @returns File descriptor of UDP socket (-1 on error). + * @returns 0 on success, -1 on error. */ int uping_init(void) { struct irc_sockaddr from; int fd; - memcpy(&from, &VirtualHost, sizeof(from)); + memcpy(&from, &VirtualHost_v4, sizeof(from)); from.port = atoi(UDP_PORT); - fd = os_socket(&from, SOCK_DGRAM, "UDP listener socket"); + fd = os_socket(&from, SOCK_DGRAM, "IPv4 uping listener"); if (fd < 0) return -1; - if (!socket_add(&upingSock, uping_echo_callback, 0, SS_DATAGRAM, - SOCK_EVENT_READABLE, fd)) { + if (!socket_add(&upingSock_v4, uping_echo_callback, 0, SS_DATAGRAM, + SOCK_EVENT_READABLE, fd)) { Debug((DEBUG_ERROR, "UPING: Unable to queue fd to event system")); close(fd); return -1; } - UPingFileDescriptor = fd; - return fd; -} - -/** Read a uping from the socket and respond (but not more than 10 - * times per second). - */ -void uping_echo() -{ - struct irc_sockaddr from; - unsigned int len = 0; - static time_t last = 0; - static int counter = 0; - char buf[BUFSIZE + 1]; - - Debug((DEBUG_DEBUG, "UPING: uping_echo")); + memcpy(&from, &VirtualHost_v6, sizeof(from)); + from.port = atoi(UDP_PORT); - if (IO_SUCCESS != os_recvfrom_nonb(UPingFileDescriptor, buf, BUFSIZE, &len, &from)) - return; - /* - * count em even if we're getting flooded so we can tell we're getting - * flooded. - */ - ++ServerStats->uping_recv; - if (CurrentTime == last) { - if (++counter > 10) - return; - } - else { - counter = 0; - last = CurrentTime; + fd = os_socket(&from, SOCK_DGRAM, "IPv6 uping listener"); + if (fd < 0) + return -1; + if (!socket_add(&upingSock_v6, uping_echo_callback, 0, SS_DATAGRAM, + SOCK_EVENT_READABLE, fd)) { + Debug((DEBUG_ERROR, "UPING: Unable to queue fd to event system")); + close(fd); + return -1; } - if (len < 19) - return; - os_sendto_nonb(UPingFileDescriptor, buf, len, NULL, 0, &from); + + return 0; } @@ -367,6 +372,7 @@ { int fd; struct UPing* pptr; + struct irc_sockaddr *local; assert(0 != sptr); assert(0 != aconf); @@ -380,7 +386,8 @@ if (IsUPing(sptr)) uping_cancel(sptr, sptr); /* Cancel previous ping request */ - fd = os_socket(NULL, SOCK_DGRAM, "UDP ping socket"); + local = irc_in_addr_is_ipv4(&aconf->address.addr) ? &VirtualHost_v4 : &VirtualHost_v6; + fd = os_socket(local, SOCK_DGRAM, "Outbound uping socket"); if (fd < 0) return 0; Index: ircd-ircdev/ircd/whocmds.c diff -u ircd-ircdev/ircd/whocmds.c:1.5 ircd-ircdev/ircd/whocmds.c:1.6 --- ircd-ircdev/ircd/whocmds.c:1.5 Wed Nov 24 08:06:16 2004 +++ ircd-ircdev/ircd/whocmds.c Wed Jan 5 03:58:35 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Support functions for /WHO-like commands. - * @version $Id: whocmds.c,v 1.5 2004/11/24 16:06:16 zolty Exp $ + * @version $Id: whocmds.c,v 1.6 2005/01/05 11:58:35 zolty Exp $ */ #include "config.h" @@ -53,7 +53,6 @@ #include "whowas.h" #include "msg.h" -#include <arpa/inet.h> /* inet_ntoa */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> ----------------------- End of diff ----------------------- |