From: Danny Mayer Date: Mon, 14 Feb 2005 05:26:43 +0000 (-0500) Subject: Bug #214: Allow option on command line to specify specific interface only to be used X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0500d085e9d38df472ec55ea9ac240f79beb32f;p=thirdparty%2Fntp.git Bug #214: Allow option on command line to specify specific interface only to be used bk: 421036935gCq3PHNT1cnGF-ZPudJuQ --- diff --git a/ntpd/cmd_args.c b/ntpd/cmd_args.c index d5ad2f4f6e..82f9e5820a 100644 --- a/ntpd/cmd_args.c +++ b/ntpd/cmd_args.c @@ -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 diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 0f2342e25e..c1f0fff5fd 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -44,6 +44,7 @@ */ extern int listen_to_virtual_ips; +extern const char *specific_interface; #if defined(SYS_WINNT) #include @@ -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);