[ntp:questions] Is there something with greater detail on "interface" besides the manpage?

Rick Jones rick.jones2 at hp.com
Sat Feb 15 00:21:15 UTC 2014


Harlan Stenn <stenn at ntp.org> wrote:
> The ntp.conf file "interface" directive is the better choice.

> It may not do a "pattern match" but that shouldn't be that hard to
> fix, should a volunteer feel like doing that.

Not really knowing what I was doing, I have tried this against the dev
tarball.  It seems to work but I cannot say I've given it an
exhaustive testing regimen.  Mostly it was looking to see that if I
said:

interface listen eth*

that lsof would show several sockets.

raj at tardy:~/ntp-dev-4.2.7p421/ntpd$ diff -c ../orig/ntpd/ntp_io.c ntp_io.c
*** ../orig/ntpd/ntp_io.c	2014-02-09 02:02:39.000000000 -0800
--- ntp_io.c	2014-02-14 15:54:34.695364092 -0800
***************
*** 21,26 ****
--- 21,32 ----
  #ifdef HAVE_SYS_UIO_H
  # include <sys/uio.h>
  #endif
+ #ifdef HAVE_SYS_TYPES_H
+ # include <sys/types.h>
+ #endif
+ #ifdef HAVE_REGEX_H
+ # include <regex.h>
+ #endif
  
  #include "ntp_machine.h"
  #include "ntpd.h"
***************
*** 1289,1294 ****
--- 1295,1304 ----
  	nic_rule *	rule;
  	int		isloopback;
  	int		iswildcard;
+ #ifdef HAVE_REGEX_H
+ 	regex_t         preg;
+ 	int             need_free=0;
+ #endif
  
  	DPRINTF(4, ("interface_action: interface %s ",
  		    (if_name != NULL) ? if_name : "wildcard"));
***************
*** 1356,1367 ****
  
  		case MATCH_IFNAME:
  			if (if_name != NULL
  			    && !strcasecmp(if_name, rule->if_name)) {
! 
  				DPRINTF(4, ("interface name match - %s\n",
  				    action_text(rule->action)));
  				return rule->action;
  			}
  			break;
  		}
  	}
--- 1366,1390 ----
  
  		case MATCH_IFNAME:
  			if (if_name != NULL
+ #ifdef HAVE_REGEX_H
+ 			    && !regcomp(&preg, rule->if_name, REG_ICASE|REG_NOSUB)
+ 			    && (need_free=1)
+                             && !regexec(&preg, if_name, 0, NULL, 0)) {
+ #else
  			    && !strcasecmp(if_name, rule->if_name)) {
! #endif
  				DPRINTF(4, ("interface name match - %s\n",
  				    action_text(rule->action)));
+ #ifdef HAVE_REGEX_H
+ 				regfree(&preg);
+ #endif
  				return rule->action;
  			}
+ #ifdef HAVE_REGEX_H
+ 			if (need_free) {
+ 			    regfree(&preg);
+ 			}
+ #endif
  			break;
  		}
  	}


-- 
I don't interest myself in "why." I think more often in terms of
"when," sometimes "where;" always "how much."  - Joubert
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...



More information about the questions mailing list