[PATCH] Implement ExternalIp config directive for silcd so that silc servers behind a NAT with a static IP can join a silcnet

Skywing <[email protected]> Thu, 26 Jun 2008 20:41:36 -0500
Newsgroups gmane.network.silc.devel
Message-ID <982D8D05B6407A49AD506E6C3AC8E7D66147930B16@caralain.haven.nynaeve.net>
This patch implements a new config directive in silcd.conf:

ExternalIp = "external-ip-address";

This lives under the ServerInfo tag in the config file.

The purpose of this option is to allow the scenario where one has a silcd behind a NAT, with a static external IP, to successfully join a silcnet.  Previously, or at least as far as I could tell, one had to have the primary listener IP match the external IP exactly, or the server would not be able to join the silcnet as a client connecting out to a silc router (the connection would fail with server ID is incorrect (51)).

One could not specify the actual external IP as the primary listener IP, as this would cause the bind to fail and the server would refuse to start.

With the patch, it is now possible to override the primary listener IP for purposes of creating the silc server's local server ID, thus enabling the server to work in the NAT scenario.  The primary listener  IP is still used for binding the socket, but the external IP overrides it (if the option is set) for purposes of calculating the server ID, which allows a NAT'd server to join the silc network properly.

(Please let me know if there was any supported way to do this previously; I could not find any, so I added this option to enable that case.)

Diff against silc-server-1.1.4.

 -S

_______________________________________________________________________
Info:    https://lists.silcnet.org/mailman/listinfo/silc-announce
Archive: https://lists.silcnet.org/pipermail/silc-announce
FAQ:     http://silcnet.org/support/faq/
silc-server-externalip.patch (application/octet-stream, 2.7 KB)
--- silc-server-1.1.4-dist-old/apps/silcd/server.c	2008-05-07 16:21:11.000000000 -0500
+++ silc-server-1.1.4-dist/apps/silcd/server.c	2008-06-26 13:56:06.000000000 -0500
@@ -758,6 +758,7 @@
   SilcNetListener listener;
   SilcUInt16 *port;
   char **ip;
+  char *external_ip;
 
   SILC_LOG_DEBUG(("Initializing server"));
 
@@ -861,8 +862,11 @@
   /* Create a Server ID for the server. */
   port = silc_net_listener_get_port(listener, NULL);
   ip = silc_net_listener_get_ip(listener, NULL);
-  silc_id_create_server_id(server->config->server_info->primary->public_ip ?
-			   server->config->server_info->primary->public_ip :
+  external_ip = server->config->server_info->external_ip ?
+  		server->config->server_info->external_ip :
+		server->config->server_info->primary->public_ip;
+  silc_id_create_server_id(external_ip ?
+			   external_ip :
 			   ip[0], port[0], server->rng, &id);
   if (!id)
     goto err;
--- silc-server-1.1.4-dist-old/apps/silcd/serverconfig.c	2008-05-07 16:21:11.000000000 -0500
+++ silc-server-1.1.4-dist/apps/silcd/serverconfig.c	2008-06-26 13:47:37.000000000 -0500
@@ -595,6 +595,10 @@
     CONFIG_IS_DOUBLE(server_info->server_type);
     server_info->server_type = strdup((char *) val);
   }
+  else if (!strcmp(name, "externalip")) {
+    CONFIG_IS_DOUBLE(server_info->external_ip);
+    server_info->external_ip = strdup((char *) val);
+  }
   else if (!strcmp(name, "admin")) {
     CONFIG_IS_DOUBLE(server_info->admin);
     server_info->admin = strdup((char *) val);
@@ -1256,6 +1260,7 @@
   { "primary",		SILC_CONFIG_ARG_BLOCK,	fetch_serverinfo, table_serverinfo_c},
   { "secondary",	SILC_CONFIG_ARG_BLOCK,	fetch_serverinfo, table_serverinfo_c},
   { "servertype",	SILC_CONFIG_ARG_STR,	fetch_serverinfo, NULL},
+  { "externalip",	SILC_CONFIG_ARG_STR,	fetch_serverinfo, NULL},
   { "location",		SILC_CONFIG_ARG_STR,	fetch_serverinfo, NULL},
   { "admin",		SILC_CONFIG_ARG_STR,	fetch_serverinfo, NULL},
   { "adminemail",	SILC_CONFIG_ARG_STR,	fetch_serverinfo, NULL},
@@ -1639,6 +1644,7 @@
       silc_free(di);
     }
     silc_free(si->server_type);
+    silc_free(si->external_ip);
     silc_free(si->location);
     silc_free(si->admin);
     silc_free(si->email);
--- silc-server-1.1.4-dist-old/apps/silcd/serverconfig.h	2008-05-07 16:21:11.000000000 -0500
+++ silc-server-1.1.4-dist/apps/silcd/serverconfig.h	2008-06-26 13:39:16.000000000 -0500
@@ -59,6 +59,7 @@
   char *server_name;
   SilcServerConfigServerInfoInterface *primary;
   SilcServerConfigServerInfoInterface *secondary;
+  char *external_ip;    /* E.g. public IP if we're in a NAT */
   char *server_type;	/* E.g. "Test Server" */
   char *location;	/* geographic location */
   char *admin;		/* admin full name */