[distcc] Binding distccd to specific IP.

Neil Mansilla neil at whatUseek.com
Thu Oct 17 05:09:00 GMT 2002


On Thu, 17 Oct 2002, Martin Pool wrote:

> On 17 Oct 2002, Tim Potter <tpot at samba.org> wrote:
> > On Wed, Oct 16, 2002 at 12:18:13PM -0400, Neil Mansilla wrote:
> >
> > > I actually patched the code with a new option, --address.  If the group is
> > > interested let me know.  Also, what would be the preferred diff command
> > > line options?
> >
> > In general diff -u is the best option to use when submitting
> > patches.
>
> Yes, diff -u, or diff -pNurd.
>
> You'd make me really happy by including not just the option, but also
> --help entries, manual entries, and even a test case.  Good docs don't
> just happen.
>
> --
> Martin

Here's the daemon_address_bind.diff file -- I unpacked the unmodified
v0.12 into "distcc-0.12.orig" and my patched version to "distcc-0.12".
Then from the parent directory, ran the diff like this:

  diff -pNurd distcc-0.12.orig distcc-0.12 > daemon_address_bind.diff

If you have problems viewing this in your e-mail client, you can pull
the diff file from this URL:

  http://www.aol2.com/daemon_address_bind.diff

If you're interested, please take a look and make any suggestions or mods.
I have it running just swell on a couple batches of boxes.  Also, a little
doc file and the --help msg were added.

Regards,
Neil




diff -pNurd distcc-0.12.orig/doc/daemon-address-binding.txt distcc-0.12/doc/daemon-address-binding.txt
--- distcc-0.12.orig/doc/daemon-address-binding.txt	Wed Dec 31 19:00:00 1969
+++ distcc-0.12/doc/daemon-address-binding.txt	Thu Oct 17 00:25:47 2002
@@ -0,0 +1,41 @@
+2002-10-17 00:11 EST5
+Daemon Address Binding Patch
+
+If you're reading this, there's a good chance that you've
+decided to patch your distcc package with the daemon
+address binding patch.  It allows you to tell the distccd
+(the daemon process) to bind to a specific IP (like
+BindAddress x.x.x.x in Apache).
+
+On the default distribution of distcc, the distccd daemon
+would bind all available IP addresses, which means all
+addresses on all available network adapters would have the
+port open (the default port is 4200).
+
+The reason for using this patched version is to restrict
+it to a single IP address.  This is most useful if you have
+more than one network adapter in your machine, or you have
+more than one IP address configured on the machine, and
+you wish to keep it bound on a private network.  The main
+change was made in the src/srvnet.c source file.
+
+So, for example, if your eth0 is configured to the private
+IP 192.168.1.50 and your eth1 is configured to some public
+Internet address, and you only wish the private network IP
+to have port 4200 open for distcc use, you would execute
+the daemon like this:
+
+   distccd --address=192.168.1.50
+
+IMPORTANT NOTE: If you bind to a specific address, make
+sure that you use that explicit address in your DISTCC_HOSTS
+environment variable.  For example, if you have the distccd
+daemon running on three machines, 192.168.1.50 through .52,
+make sure to set the addresses in the export line
+explicitly:
+
+export DISTCC_HOSTS="192.168.1.50 192.168.1.51 192.168.1.52"
+
+Neil Mansilla
+neil at whatUseek.com
+whatUseek, Corp.
diff -pNurd distcc-0.12.orig/src/dopt.c distcc-0.12/src/dopt.c
--- distcc-0.12.orig/src/dopt.c	Sun Oct  6 22:51:20 2002
+++ distcc-0.12/src/dopt.c	Wed Oct 16 12:11:12 2002
@@ -58,6 +58,8 @@ int arg_nchildren = 2;          /**< Num
                                  * on this machine.  About ncpus+1 I
                                  * think. */
 int arg_port = 4200;
+const char *arg_address = NULL;
+

 /** If true, serve all requests directly from listening process
     without forking.  Better for debugging. **/
@@ -83,6 +85,7 @@ const struct poptOption options[] = {
     { "nice", 'N',       POPT_ARG_INT, &arg_nice_inc,  'N', 0, 0 },
     { "pid-file", 'P',   POPT_ARG_STRING, &arg_pid_file, 0, 0, 0 },
     { "port", 'p',       POPT_ARG_INT, &arg_port,      0, 0, 0 },
+    { "address", 'a',    POPT_ARG_STRING, &arg_address,      0, 0, 0 },
     { "help", 0,         POPT_ARG_NONE, 0, '?', 0, 0 },
     { "version", 0, POPT_ARG_NONE, 0, 'V', 0, 0 },
     { "no-fork", 0,      POPT_ARG_NONE, &arg_no_fork, 0, 0, 0 },
@@ -109,6 +112,7 @@ static void distccd_show_usage(void)
 "    -n, --tasks NUM            number of concurrent connections\n"
 #endif
 "    -p, --port PORT            TCP port to listen on\n"
+"    -a, --address ADDRESS	IP address to bind to\n"
 "    -P, --pid-file FILE        save daemon process id to file\n"
 "    -N, --nice LEVEL           lower priority, 20=most nice\n"
 "  Debug and trace:\n"
@@ -122,6 +126,8 @@ static void distccd_show_usage(void)
 "\n"
 "distccd runs either from inetd or as a standalone daemon to compile\n"
 "files submitted by the distcc client.  distccd runs on TCP port 4200.\n"
+"distccd will bind to all interfaces and available IP addresses unless\n"
+"a specific address is provided.\n"
 "\n"
 "distccd should only run on trusted networks.\n"
 );
diff -pNurd distcc-0.12.orig/src/dparent.c distcc-0.12/src/dparent.c
--- distcc-0.12.orig/src/dparent.c	Sun Oct  6 22:51:21 2002
+++ distcc-0.12/src/dparent.c	Wed Oct 16 12:05:00 2002
@@ -101,7 +101,7 @@ int dcc_standalone_server(void)
     if ((ret = dcc_refuse_root()) != 0)
         return ret;

-    if ((listen_fd = open_socket_in(arg_port)) == -1)
+    if ((listen_fd = open_socket_in(arg_port,arg_address)) == -1)
         return EXIT_BIND_FAILED;

     set_cloexec_flag(listen_fd, 1);
diff -pNurd distcc-0.12.orig/src/opt.h distcc-0.12/src/opt.h
--- distcc-0.12.orig/src/opt.h	Sun Oct  6 22:51:21 2002
+++ distcc-0.12/src/opt.h	Wed Oct 16 12:05:42 2002
@@ -29,3 +29,4 @@ extern int opt_daemon_mode, opt_inetd_mo
 extern const char *arg_log_file;
 extern int opt_no_fifo;
 extern int opt_log_stderr;
+extern const char *arg_address;
diff -pNurd distcc-0.12.orig/src/srvnet.c distcc-0.12/src/srvnet.c
--- distcc-0.12.orig/src/srvnet.c	Sun Oct  6 22:51:21 2002
+++ distcc-0.12/src/srvnet.c	Thu Oct 17 00:09:21 2002
@@ -69,7 +69,7 @@
 typedef int socklen_t;
 #endif

-int open_socket_in(int port)
+int open_socket_in(int port,char *address)
 {
     struct sockaddr_in sock;
     int res;
@@ -84,7 +84,15 @@ int open_socket_in(int port)
     memset((char *) &sock, 0, sizeof(sock));
     sock.sin_port = htons(port);
     sock.sin_family = PF_INET;
-    sock.sin_addr.s_addr = INADDR_ANY;
+
+    if (address) {
+	// Bind to specific address as set in command line options
+	sock.sin_addr.s_addr = inet_addr(address);
+    }
+    else {
+	// Bind to all available interfaces and addresses
+	sock.sin_addr.s_addr = INADDR_ANY;
+    }

     res = socket(PF_INET, SOCK_STREAM, 0);
     if (res == -1) {
diff -pNurd distcc-0.12.orig/src/util.h distcc-0.12/src/util.h
--- distcc-0.12.orig/src/util.h	Sun Oct  6 22:51:21 2002
+++ distcc-0.12/src/util.h	Wed Oct 16 12:03:53 2002
@@ -35,7 +35,7 @@ int dcc_remove_if_exists(const char *fna
 #define str_equal(a, b) (!strcmp((a), (b)))

 /* srvnet.c */
-int open_socket_in(int port);
+int open_socket_in(int port,char *address);
 int is_a_socket(int fd);





More information about the distcc mailing list