zoneconf.in (local-addresses-p): Set fake addresses in env var.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 23 Jan 2013 20:56:59 +0000 (20:56 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 23 Jan 2013 20:56:59 +0000 (20:56 +0000)
It's useful to be able to test configurations away from the production
environment, but the `local-addresses-p' check causes the results to be
different.  To allow this kind of testing, set the environment variable
`ZONECONF_LOCAL_ADDRESSES' to a `:'-separated list of IP addresses, in
dotted-quad format: then these addresses and no others will be
considered local.

zoneconf.in

index 43892db..d16e74a 100755 (executable)
@@ -942,12 +942,21 @@ proc host-canonify {host} {
 
 proc local-address-p {addr} {
   ## Answer whether the ADDR is one of the host's addresses.
+  global env
 
-  if {[catch { set sk [socket -server {} -myaddr $addr 0] }]} {
-    return false
+  if {[info exists env(ZONECONF_LOCAL_ADDRESSES)]} {
+    if {[string match "*:$addr:*" ":$env(ZONECONF_LOCAL_ADDRESSES):"]} {
+      return true
+    } else {
+      return false
+    }
   } else {
-    close $sk
-    return true
+    if {[catch { set sk [socket -server {} -myaddr $addr 0] }]} {
+      return false
+    } else {
+      close $sk
+      return true
+    }
   }
 }