repo: ngircd
action: commit
revision: 
path_from: 
revision_from: 22fa782be7840dae825be43e9ac8d8476d80f08c:
path_to: 
revision_to: 
git.thebackupbox.net
ngircd
git clone git://git.thebackupbox.net/ngircd
commit 22fa782be7840dae825be43e9ac8d8476d80f08c
Author: Florian Westphal 
Date:   Mon Apr 21 00:45:19 2008 +0200

    IPv6: Add config options to disabe ipv4/ipv6 support.

    This also enables ipv6-only setups.

diff --git a/doc/sample-ngircd.conf b/doc/sample-ngircd.conf
index 13014d32a0fb6d8ee1afc1904ab8428db658a523..
index ..9f107a83f42e524da59a604d5879509d069a3e9f 100644
--- a/doc/sample-ngircd.conf
+++ b/doc/sample-ngircd.conf
@@ -103,6 +103,15 @@
 	# Don't do any DNS lookups when a client connects to the server.
 	;NoDNS = no

+	# allow both ipv4 and ipv6 clients to connect by opening both
+	# ipv4 and ipv6 sockets
+	;ListenIPv6 = yes
+	;ListenIPv4 = yes
+
+	# try to connect to other irc servers using ipv4 and ipv6, if possible
+	;ConnectIPv6 = yes
+	;ConnectIPv4 = yes
+
 	# Maximum number of simultaneous connection the server is allowed
 	# to accept (0: unlimited):
 	;MaxConnections = 0
diff --git a/man/ngircd.conf.5.tmpl b/man/ngircd.conf.5.tmpl
index 3a6b7d56176af3d1d46e826afb9942b3e7e242ef..
index ..cd5922afd9ab4071e8852c397eb4f0f6e1803d74 100644
--- a/man/ngircd.conf.5.tmpl
+++ b/man/ngircd.conf.5.tmpl
@@ -158,6 +158,24 @@ If you configure ngircd to connect to other servers, ngircd may still
 perform a DNS lookup if required.
 Default: No.
 .TP
+\fBListenIPv4\fR
+Set this to no if you do not want ngircd to accept clients using the standard internet protocol, ipv4.
+This allows use of ngircd in ipv6-only setups.
+Default: Yes.
+.TP
+\fBListenIPv6\fR
+Set this to no if you do not want ngircd to accept clients using the new internet protocol, ipv6.
+Default: Yes.
+.TP
+\fBConnectIPv4\fR
+Set this to no if you do not want ngircd to connect to other irc servers using ipv4.
+This allows use of ngircd in ipv6-only setups.
+Default: Yes.
+.TP
+\fBConnectIPv6\fR
+Set this to no if you do not want ngircd to connect to other irc servers using ipv6.
+Default: Yes.
+.TP
 \fBMaxConnections\fR
 Maximum number of simultaneous connection the server is allowed to accept
 (0: unlimited). Default: 0.
diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c
index 0f6686221696f463eccd11097aa488fd8121bcbc..
index ..ad2baa9ef2a73fe6b424b1832f871c94f38407b4 100644
--- a/src/ngircd/conf.c
+++ b/src/ngircd/conf.c
@@ -152,6 +152,15 @@ Conf_Rehash( void )
 } /* Config_Rehash */


+static const char*
+yesno_to_str(int boolean_value)
+{
+	if (boolean_value)
+		return "yes";
+	return "no";
+}
+
+
 GLOBAL int
 Conf_Test( void )
 {
@@ -201,10 +210,17 @@ Conf_Test( void )
 	printf( "  PingTimeout = %d\n", Conf_PingTimeout );
 	printf( "  PongTimeout = %d\n", Conf_PongTimeout );
 	printf( "  ConnectRetry = %d\n", Conf_ConnectRetry );
-	printf( "  OperCanUseMode = %s\n", Conf_OperCanMode == true ? "yes" : "no" );
-	printf( "  OperServerMode = %s\n", Conf_OperServerMode == true? "yes" : "no" );
-	printf( "  PredefChannelsOnly = %s\n", Conf_PredefChannelsOnly == true ? "yes" : "no" );
-	printf( "  NoDNS = %s\n", Conf_NoDNS ? "yes" : "no");
+	printf( "  OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
+	printf( "  OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
+	printf( "  PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
+	printf( "  NoDNS = %s\n", yesno_to_str(Conf_NoDNS));
+
+#ifdef WANT_IPV6
+	printf("  ListenIPv6 = %s\n", yesno_to_str(Conf_ListenIPv6));
+	printf("  ListenIPv4 = %s\n", yesno_to_str(Conf_ListenIPv4));
+	printf("  ConnectIPv4= %s\n", yesno_to_str(Conf_ConnectIPv6));
+	printf("  ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
+#endif
 	printf( "  MaxConnections = %ld\n", Conf_MaxConnections);
 	printf( "  MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
 	printf( "  MaxJoins = %d\n", Conf_MaxJoins>0 ? Conf_MaxJoins : -1);
@@ -449,6 +465,11 @@ Set_Defaults( bool InitServers )
 	Conf_PredefChannelsOnly = false;
 	Conf_OperServerMode = false;

+	Conf_ConnectIPv4 = true;
+	Conf_ListenIPv4 = true;
+	Conf_ConnectIPv6 = true;
+	Conf_ListenIPv6 = true;
+
 	Conf_MaxConnections = 0;
 	Conf_MaxConnectionsIP = 5;
 	Conf_MaxJoins = 10;
@@ -817,6 +838,33 @@ Handle_GLOBAL( int Line, char *Var, char *Arg )
 		Conf_NoDNS = Check_ArgIsTrue( Arg );
 		return;
 	}
+#ifdef WANT_IPV6
+	/* the default setting for all the WANT_IPV6 special options is 'true' */
+	if( strcasecmp( Var, "ListenIPv6" ) == 0 ) {
+		/* listen on ipv6 sockets, if available? */
+		Conf_ListenIPv6 = Check_ArgIsTrue( Arg );
+		return;
+	}
+	if( strcasecmp( Var, "ListenIPv4" ) == 0 ) {
+		/*
+		 * listen on ipv4 sockets, if available?
+		 * this allows "ipv6-only" setups.
+		 */
+		Conf_ListenIPv4 = Check_ArgIsTrue( Arg );
+		return;
+	}
+	if( strcasecmp( Var, "ConnectIPv6" ) == 0 ) {
+		/* connect to other hosts using ipv6, if they have an AAAA record? */
+		Conf_ConnectIPv6 = Check_ArgIsTrue( Arg );
+		return;
+	}
+	if( strcasecmp( Var, "ConnectIPv4" ) == 0 ) {
+		/* connect to other hosts using ipv4.
+		 * again, this can be used for ipv6-only setups */
+		Conf_ConnectIPv4 = Check_ArgIsTrue( Arg );
+		return;
+	}
+#endif
 	if( strcasecmp( Var, "OperCanUseMode" ) == 0 ) {
 		/* Are IRC operators allowed to use MODE in channels they aren't Op in? */
 		Conf_OperCanMode = Check_ArgIsTrue( Arg );
@@ -1138,6 +1186,16 @@ Validate_Config(bool Configtest, bool Rehash)
 			     "No administrative information configured but required by RFC!");
 	}

+#ifdef WANT_IPV6
+	if (!Conf_ListenIPv4 && !Conf_ListenIPv6)
+		Config_Error(LOG_ALERT,
+			"Both \"ListenIPv4\" and \"ListenIPv6\" are set to 'no'; no network protocol available!");
+
+	if (!Conf_ConnectIPv4 && !Conf_ConnectIPv6)
+		Config_Error(LOG_ALERT,
+			"Both \"ConnectIPv4\" and \"ConnectIPv6\" are set to 'no'; ngircd will fail to connect to other irc servers");
+#endif
+
 #ifdef DEBUG
 	servers = servers_once = 0;
 	for (i = 0; i < MAX_SERVERS; i++) {
diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h
index d505f3390db01625f259d565bf7c9dffc4cc26dd..
index ..3bc206605e208d40b78cd02c1cab05fcb9eeb8cb 100644
--- a/src/ngircd/conf.h
+++ b/src/ngircd/conf.h
@@ -124,11 +124,20 @@ GLOBAL bool Conf_OperCanMode;
 /* Disable all DNS functions? */
 GLOBAL bool Conf_NoDNS;

-/* don't listen for incoming ipv6 connections, even if OS supports it? */
-GLOBAL bool Conf_NoListenIpv6;
+/* listen for incoming ipv6 connections if OS supports it (default: yes)? */
+GLOBAL bool Conf_ListenIPv6;

-/* don't connect to remote systems unsign ipv6? */
-GLOBAL bool Conf_NoConnectIpv6;
+/* listen for incoming ipv4 connections if OS supports it (default: yes)? */
+GLOBAL bool Conf_ListenIPv4;
+
+/*
+ * try to connect to remote systems using the ipv6 protocol,
+ * if they have an ipv6 address? (default yes)
+ */
+GLOBAL bool Conf_ConnectIPv6;
+
+/* same as above, but for ipv4 hosts, default: yes  */
+GLOBAL bool Conf_ConnectIPv4;

 /* If an IRC op gives chanop privileges without being a chanop,
  * ircd2 will ignore the command. This enables a workaround:
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
index 9e31e4eec576e7c3a747e0c97d65ed790911b5da..
index ..1696d5c5f62968d8d495576b4e1bc67947db66ee 100644
--- a/src/ngircd/conn.c
+++ b/src/ngircd/conn.c
@@ -315,10 +315,11 @@ Conn_InitListeners( void )
 	}

 #ifdef WANT_IPV6
-	if (!Conf_NoListenIpv6)
+	if (Conf_ListenIPv6)
 		created = ports_initlisteners(&Conf_ListenPorts, AF_INET6, cb_listen);
 #endif
-	created += ports_initlisteners(&Conf_ListenPorts, AF_INET, cb_listen);
+	if (Conf_ListenIPv4)
+		created += ports_initlisteners(&Conf_ListenPorts, AF_INET, cb_listen);

 	return created;
 } /* Conn_InitListeners */
diff --git a/src/ngircd/resolve.c b/src/ngircd/resolve.c
index a128694bab19f06033dff4da93737f32bb0094b6..
index ..041c15620b1585c56f84dd45c8fa7a17f55b0c1a 100644
--- a/src/ngircd/resolve.c
+++ b/src/ngircd/resolve.c
@@ -45,6 +45,10 @@ static void Do_ResolveAddr PARAMS(( const ng_ipaddr_t *Addr, int Sock, int w_fd
 static void Do_ResolveName PARAMS(( const char *Host, int w_fd ));
 static bool register_callback PARAMS((RES_STAT *s, void (*cbfunc)(int, short)));

+#ifdef WANT_IPV6
+extern bool Conf_ConnectIPv4;
+extern bool Conf_ConnectIPv6;
+#endif

 static pid_t
 Resolver_fork(int *pipefds)
@@ -270,7 +274,7 @@ ForwardLookup(const char *hostname, array *IpAddr)
 #ifdef HAVE_GETADDRINFO
 	int res;
 	struct addrinfo *a, *ai_results;
-	static const struct addrinfo hints = {
+	static struct addrinfo hints = {
 #ifndef WANT_IPV6
 		.ai_family = AF_INET,
 #endif
@@ -280,6 +284,14 @@ ForwardLookup(const char *hostname, array *IpAddr)
 		.ai_socktype = SOCK_STREAM,
 		.ai_protocol = IPPROTO_TCP
 	};
+#ifdef WANT_IPV6
+	assert(Conf_ConnectIPv6 || Conf_ConnectIPv4);
+
+	if (!Conf_ConnectIPv6)
+		hints.ai_family = AF_INET;
+	if (!Conf_ConnectIPv4)
+		hints.ai_family = AF_INET6;
+#endif
 	res = getaddrinfo(hostname, NULL, &hints, &ai_results);
 	switch (res) {
 	case 0:	break;

-----END OF PAGE-----