]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Bug #214: Allow option on command line to specify specific interface only to be used
authorDanny Mayer <mayer@ntp.org>
Mon, 14 Feb 2005 05:26:43 +0000 (00:26 -0500)
committerDanny Mayer <mayer@ntp.org>
Mon, 14 Feb 2005 05:26:43 +0000 (00:26 -0500)
bk: 421036935gCq3PHNT1cnGF-ZPudJuQ

ntpd/cmd_args.c
ntpd/ntp_io.c

index d5ad2f4f6e08b334a2f2a3840aa81b98951cb1eb..82f9e5820abeb34b773712e7e8098b6bc8e3ea86 100644 (file)
@@ -18,8 +18,9 @@
  */
 extern char const *progname;
 int    listen_to_virtual_ips = 1;
+char   *specific_interface = NULL;        /* interface name or IP address to bind to */
 
-static const char *ntp_options = "aAbB:c:C:dD:f:gi:k:l:LnNO:p:P:qr:s:S:t:T:W:u:v:V:xY:Z:-:";
+static const char *ntp_options = "aAbB:c:C:dD:f:gi:k:l:L:nNO:p:P:qr:s:S:t:T:W:u:v:V:xY:Z:-:";
 
 #ifdef HAVE_NETINFO
 extern int     check_netinfo;
@@ -81,6 +82,8 @@ getstartup(
 #endif
                case 'L':
                    listen_to_virtual_ips = 0;
+                   if(ntp_optarg)
+                       specific_interface = ntp_optarg; 
                    break;
                case 'l':
                        {
@@ -150,6 +153,7 @@ getstartup(
                (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
                (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
                (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
+               (void) fprintf(stderr, "\t\t[ -L interface ]\n");
 #if defined(HAVE_SCHED_SETSCHEDULER)
                (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
 #endif
@@ -397,6 +401,7 @@ getCmdOpts(
                (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
                (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
                (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
+               (void) fprintf(stderr, "\t\t[ -L interface ]\n");
 #if defined(HAVE_SCHED_SETSCHEDULER)
                (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
 #endif
index 0f2342e25ed346f799161661565b6d3d21dba69d..c1f0fff5fdd140ea8a44f90f713b1c974f000898 100644 (file)
@@ -44,6 +44,7 @@
 */
 
 extern int listen_to_virtual_ips;
+extern const char *specific_interface;
 
 #if defined(SYS_WINNT)
 #include <transmitbuff.h>
@@ -404,9 +405,24 @@ address_okay(isc_interface_t *isc_if) {
            printf("address_okay: listen Virtual: %d, IF name: %s, Up Flag: %d\n", 
                    listen_to_virtual_ips, isc_if->name, (isc_if->flags & INTERFACE_F_UP));
 #endif
+       /*
+        * Always allow the loopback
+        */
+       if((isc_if->flags & INTERFACE_F_LOOPBACK) != 0)
+               return (ISC_TRUE);
 
-       if (listen_to_virtual_ips == 0  && (strchr(isc_if->name, (int)':') != NULL))
-               return (ISC_FALSE);
+       /*
+        * Check if the interface is specified
+        */
+       if (specific_interface != NULL) {
+               if (stricmp(isc_if->name, specific_interface) == 0)
+                       return (ISC_TRUE);
+       }
+       else {
+               if (listen_to_virtual_ips == 0  && 
+                  (strchr(isc_if->name, (int)':') != NULL))
+                       return (ISC_FALSE);
+       }
 
        /* XXXPDM This should be fixed later, but since we may not have set
         * the UP flag, we at least get to use the interface.
@@ -536,8 +552,10 @@ create_sockets(
                        netsyslog(LOG_ERR, "no IPv4 interfaces found");
 #endif
 #ifdef UDP_WILDCARD_DELIVERY
-       nwilds = create_wildcards(port);
-       idx = nwilds; 
+       if (specific_interface == NULL) {
+               nwilds = create_wildcards(port);
+               idx = nwilds;
+       }
 #endif
 
        result = isc_interfaceiter_create(mctx, &iter);