a couple of patches for Vyos 1.1.0-beta1


#1

hi, I’ve spent the last few hours switching from Vyatta to Vyos 1.10-beta1. I’ve had to re-work some of the vyatta patches that originated in UBNT circles (thanks!), but now I have identical functionality to before which is great.
There are two main patches I needed - and I’ve included my patch files below - I take no credit for this - I’ve only re-worked the patches into the latest Vyos. It would be great if these patches (or variants of them) could be incorporated into the next release of Vyos as it would make things easier if these features were out the box (it took me a while to understand Linux patch files!).

  1. set up freedns as a dynamic DNS provider (http://freedns.afraid.org/)
$ sudo su -
# cd /tmp
# curl -o ddclient.deb http://ftp.us.debian.org/debian/pool/main/d/ddclient/ddclient_3.8.1-1.1_all.deb
# dpkg -i ddclient.deb

# cat >/tmp/ddclient.patch <<'EOL'
--- /usr/sbin/ddclient.orig
+++ /usr/sbin/ddclient
@@ -1783,14 +1783,14 @@
 ## load_sha1_support
 ######################################################################
 sub load_sha1_support {
-    my $sha1_loaded = eval {require Digest::SHA1};
+    my $sha1_loaded = eval {require Digest::SHA};
     unless ($sha1_loaded) {
         fatal(<<"EOM");
-Error loading the Perl module Digest::SHA1 needed for freedns update.
+Error loading the Perl module Digest::SHA needed for freedns update.
 On Debian, the package libdigest-sha1-perl must be installed.
 EOM
     }
-    import  Digest::SHA1 (qw/sha1_hex/);
+    import  Digest::SHA (qw/sha1_hex/);
 }
 ######################################################################
 ## geturl
EOL

# patch -p0 < /tmp/ddclient.patch

# cat >/tmp/ddns-node.def.patch <<'EOL'
--- /opt/vyatta/share/vyatta-cfg/templates/service/dns/dynamic/interface/node.tag/service/node.def.orig
+++ /opt/vyatta/share/vyatta-cfg/templates/service/dns/dynamic/interface/node.tag/service/node.def
@@ -2,7 +2,7 @@
 help: Service being used for Dynamic DNS [REQUIRED]
 type: txt
 syntax:expression: exec "
-        service_array=(dnspark dslreports dyndns easydns namecheap sitelutions zoneedit)
+        service_array=(dnspark dslreports dyndns easydns freedns namecheap sitelutions zoneedit)
         service_array_len=${#service_array[*]}
         i=0
         while [ $i -lt $service_array_len ]; do
@@ -15,7 +15,7 @@
         exit 1 "

 allowed: local -a array ;
-         array=(dnspark dslreports dyndns easydns namecheap sitelutions zoneedit);
+         array=(dnspark dslreports dyndns easydns freedns namecheap sitelutions zoneedit);
          echo -n ${array[@]}

 commit:expression: $VAR(./@/login) != ""; "Set login for service $VAR(./@) to send DDNS updates for interface $VAR(../@)"
EOL

# patch -p0 < /tmp/ddns-node.def.patch

$ config
# set service dns dynamic interface pppoe0 service freedns
# set service dns dynamic interface pppoe0 service freedns host-name ???.????.???
# set service dns dynamic interface pppoe0 service freedns login ?????
# set service dns dynamic interface pppoe0 service freedns password ????
# commit
# save
[edit]
# exit

$ config
# show service dns dynamic
 interface pppoe0 {
     service freedns {
         host-name ??????
         login ??????
         password ?????
     }
 }
[edit]
# exit

$ sudo su -
# show dns dynamic status
interface    : pppoe0
ip address   : ?.?.?.?
host-name    : ????
last update  : Thu Jan  1 00:00:00 1970
update-status: good
  1. Conditional DNS forwarding support;
$ sudo su -
# cat >/tmp/dns_forwarding-node.patch <<'EOL'
--- /dev/null
+++ /opt/vyatta/share/vyatta-cfg/templates/service/dns/forwarding/options/node.def
@@ -0,0 +1,7 @@
+multi:
+type: txt
+# help formatted below to appear properly during tab completion
+help: Additional options for dns forwarding. You must 
+                use the syntax of dnsmasq.conf in this text-field. Using this 
+               without proper knowledge may result in a crashed dnsmaq daemon.
+               Check system log to look for errors.
EOL

# patch -p0 < /tmp/dns_forwarding-node.patch

# cat >/tmp/vyatta-dns-forwarding.pl.patch <<'EOL'
--- /opt/vyatta/sbin/vyatta-dns-forwarding.pl.orig
+++ /opt/vyatta/sbin/vyatta-dns-forwarding.pl
@@ -63,7 +63,7 @@
     my $output = '';
     my $config = new Vyatta::Config;
     my $use_dnsmasq_conf = 0;
-    my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers, @domain, $server, $ignore_hosts_file);
+    my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers, @options, @domain, $server, $ignore_hosts_file);

     $config->setLevel("service dns forwarding");

@@ -71,6 +71,7 @@
            @listen_interfaces = $config->returnOrigValues("listen-on");
            $cache_size = $config->returnOrigValue("cache-size");
            @use_nameservers = $config->returnOrigValues("name-server");
+           @options = $config->returnOrigValues("options");
            $use_system_nameservers = $config->existsOrig("system");
            @use_dhcp_nameservers = $config->returnOrigValues("dhcp");
            @domain = $config->listOrigNodes("domain");
@@ -80,6 +81,7 @@
            @listen_interfaces = $config->returnValues("listen-on");
            $cache_size = $config->returnValue("cache-size");
            @use_nameservers = $config->returnValues("name-server");
+           @options = $config->returnValues("options");
            $use_system_nameservers = $config->exists("system");
           @use_dhcp_nameservers = $config->returnValues("dhcp");
            @domain = $config->listNodes("domain");
@@ -148,6 +150,12 @@
         }
     }

+    if (@options != 0) {
+       foreach my $option (@options) {
+          $output .= "$option\n";
+       }
+    }
+
     if ($use_dnsmasq_conf == 1) {
         $output .= "resolv-file=/etc/dnsmasq.conf\n";
     }
EOL

# patch -p0 < /tmp/vyatta-dns-forwarding.pl.patch

$ config
# set service dns forwarding listen-on eth0
# set service dns forwarding listen-on eth1
# set service dns forwarding listen-on vtun0
# set service dns forwarding options "server=/netflix.com/103.6.212.24"
# set service dns forwarding options "server=/nflximg.com/103.6.212.24"
# set service dns forwarding options "server=/nflximg.net/103.6.212.24"
# set service dns forwarding options "server=/netflix.com.edgesuite.net/103.6.212.24"
# set service dns forwarding options "server=/nflxext.com/103.6.212.24"
# set service dns forwarding options "server=/bbc.co.uk/103.6.212.24"
# set service dns forwarding options "server=/cp143012-i.akamaihd.net/103.6.212.24"
# set service dns forwarding options "server=/a1638.g.akamai.net/103.6.212.24"
# set service dns forwarding options "server=/cp96472.live.edgefcs.net/103.6.212.24"
# set service dns forwarding options "server=/itv.com/103.6.212.24"
# set service dns forwarding options "server=/channel4.com/103.6.212.24"
[edit]

$ config
# show service dns forwarding
 cache-size 150
 listen-on eth1
 listen-on eth0
 listen-on vtun0
 options server=/netflix.com/103.6.212.24
 options server=/nflximg.com/103.6.212.24
 options server=/nflximg.net/103.6.212.24
 options server=/netflix.com.edgesuite.net/103.6.212.24
 options server=/nflxext.com/103.6.212.24
 options server=/bbc.co.uk/103.6.212.24
 options server=/cp143012-i.akamaihd.net/103.6.212.24
 options server=/a1638.g.akamai.net/103.6.212.24
 options server=/cp96472.live.edgefcs.net/103.6.212.24
 options server=/itv.com/103.6.212.24
 options server=/channel4.com/103.6.212.24
 system
[edit]