فهرست منبع

resolv.conf proper handling

Reinhard Russinger 3 سال پیش
والد
کامیت
7610cab4b4

+ 1 - 1
board/PSG/iot2050/BUILD

@@ -1 +1 @@
-137
+138

+ 13 - 0
board/PSG/iot2050/rootfs/etc/network/if-post-down.d/psg-dns

@@ -0,0 +1,13 @@
+#!/bin/bash
+WRKPATH=/etc/network
+DESTFILE=/etc/resolv.conf
+
+/bin/sed --follow-symlinks -i "/\# $IFACE/d" $DESTFILE
+
+readarray -t DNSSERVERS < <(/usr/bin/awk -f $WRKPATH/readInterfaces.awk $WRKPATH/interfaces device=$IFACE output=dns-nameservers)
+for a in "${DNSSERVERS[@]}"; do
+    if [[ ! -z $(/bin/grep "$a" "$DESTFILE") ]]; then
+        /bin/sed --follow-symlinks -i "/$a/d" $DESTFILE
+    fi
+done    
+

+ 13 - 0
board/PSG/iot2050/rootfs/etc/network/if-up.d/psg-dns

@@ -0,0 +1,13 @@
+#!/bin/bash
+WRKPATH=/etc/network
+DESTFILE=/etc/resolv.conf
+
+readarray -t DNSSERVERS < <(/usr/bin/awk -f $WRKPATH/readInterfaces.awk $WRKPATH/interfaces device=$IFACE output=dns-nameservers)
+
+for DNS in "${DNSSERVERS[@]}"; do
+    if [[ -z $(/bin/grep "$DNS" "$DESTFILE") ]]; then
+#        /bin/sed --follow-symlinks -i "1 s/^/$a\n/" $DESTFILE
+        echo "$DNS # $IFACE" >> $DESTFILE
+    fi         
+done    
+

+ 113 - 0
board/PSG/iot2050/rootfs/etc/network/readInterfaces.awk

@@ -0,0 +1,113 @@
+BEGIN {
+
+    start = 0;
+
+    if (ARGC < 3 || ARGC > 5) {
+        print "awk -f readInterfaces.awk <interfaces file> device=<eth device> [output=all|dns-nameservers] [debug=1]"
+        exit 1;
+    }
+
+    outAll = 0
+    outDNSNameservers = 0 
+
+    for (i = 2; i < ARGC; i++) {
+        split(ARGV[i], arg, "=");
+        if (arg[1] == "device")
+            device = arg[2];
+        else if (arg[1] == "output" && arg[2] == "all")
+            outAll = 1;
+        else if (arg[1] == "output" && arg[2] == "dns-nameservers")
+            outDNSNameservers = 1;
+        else if (arg[1] == "debug" && arg[2] == "1")
+            debug = 1;
+    }
+
+    if (!length(device)) {
+        print "awk -f readInterfaces.awk <interfaces file> device=<eth device> [output=all|dns-nameservers] [debug=1]"
+        exit 1;
+    }
+}
+
+{
+    # Look for iface line and if the interface comes with the device name
+    # scan whether it is dhcp or static or manual
+    # e.g. iface eth0 inet [static | dhcp | manual]
+    if ($1 == "iface")  {
+        # Ethernet name matches - switch the line scanning on
+        if ($2 == device) {
+            if (debug)
+                print $0;
+            # It's a DHCP interface
+            if (match($0, / dhcp/)) {
+                print "dhcp";
+                gotTypeNoAddr = 1;
+                exit 0;
+                # It's a static network interface. We want to scan the
+                # addresses after the static line
+            }
+            else if (match ($0, / static/)) {
+                static = 1;
+                next;
+            }
+            else if (match ($0, / manual/)) {
+                print "manual";
+                gotTypeNoAddr = 1;
+                exit 0;
+            }
+            # If it is other inteface line, switch it off
+            # Go to the next line
+        }
+        else {
+            static = 0;
+            next;
+        }
+    }
+    else if ($1 == "auto") {
+        static = 0;
+        next;
+    }
+
+    # At here, it means we are after the iface static line of
+    # after the device we are searching for
+    # Scan for the static content
+    if (static) {
+        # 2nd field to end of the line
+        if (length($1)) {
+            interface[$1] = interface[$1] " " substr($0, index($0, $2));
+            gotAddr = 1;
+        }
+    }
+}
+
+END {
+    if (gotAddr) {
+        if(!outDNSNameservers)
+            printf("%s %s %s\n", interface["address"], interface["netmask"], interface["gateway"]);
+        if (outAll) {
+            delete interface["address"];
+            delete interface["netmask"];
+            delete interface["gateway"];
+            for (field in interface) {
+                printf("%s %s\n", field, interface[field]);
+            }
+        }
+
+        if (outDNSNameservers) {
+            for (field in interface) {
+                if (field == "dns-nameservers") {
+                    split(interface[field], dnsnames);
+                    for (dns in dnsnames) {
+                        printf("nameserver %s\n", dnsnames[dns]);
+                        }
+                    }
+            }
+        }        
+        exit 0;
+    }
+    else {
+        if (gotTypeNoAddr)
+            exit 0;
+        else
+            exit 1;
+    }
+}

+ 27 - 0
board/PSG/iot2050/rootfs/etc/ppp/ip-down.d/psg-dns

@@ -0,0 +1,27 @@
+#!/bin/bash
+# This script is called with the following arguments:
+#    Arg  Name                          Example
+#    $1   Interface name                ppp0
+#    $2   The tty                       ttyO1
+#    $3   The link speed                38400
+#    $4   Local IP number               12.34.56.78
+#    $5   Peer  IP number               12.34.56.99
+#    $6   Optional ``ipparam'' value    foo
+
+WRKPATH=/etc/ppp
+DESTFILE=/etc/resolv.conf
+
+if [ -e "$WRKPATH/resolv.conf" ]; then
+    
+    /bin/sed --follow-symlinks -i "/\# $1/d" $DESTFILE
+    
+    readarray -t DNSSERVERS < <(cat $WRKPATH/resolv.conf)
+
+    for DNS in "${DNSSERVERS[@]}"; do
+        if [[ ! -z $(/bin/grep "$DNS" "$DESTFILE") ]]; then
+            /bin/sed --follow-symlinks -i "/$DNS/d" $DESTFILE
+        fi
+    done
+
+    rm $WRKPATH/resolv.conf
+fi    

+ 26 - 0
board/PSG/iot2050/rootfs/etc/ppp/ip-up.d/psg-dns

@@ -0,0 +1,26 @@
+#!/bin/bash
+# This script is called with the following arguments:
+#    Arg  Name                          Example
+#    $1   Interface name                ppp0
+#    $2   The tty                       ttyO1
+#    $3   The link speed                38400
+#    $4   Local IP number               12.34.56.78
+#    $5   Peer  IP number               12.34.56.99
+#    $6   Optional ``ipparam'' value    foo
+
+WRKPATH=/etc/ppp
+DESTFILE=/etc/resolv.conf
+
+if [ -e "$WRKPATH/resolv.conf" ]; then
+
+    /bin/sed --follow-symlinks -i "/\# $1/d" $DESTFILE
+    
+    readarray -t DNSSERVERS < <(cat $WRKPATH/resolv.conf)
+
+    for DNS in "${DNSSERVERS[@]}"; do
+        if [[ -z $(/bin/grep "$DNS" "$DESTFILE") ]]; then
+            /bin/sed --follow-symlinks -i "1 s/^/$DNS \# $1\n/" $DESTFILE
+    #        echo "$DNS" #>> $DESTFILE
+        fi
+    done
+fi    

+ 1 - 0
board/PSG/iot2050/rootfs/etc/ppp/resolv.conf

@@ -0,0 +1 @@
+/tmp/resolv_pppd.conf

+ 1 - 0
board/PSG/iot2050/rootfs/etc/resolv.conf

@@ -0,0 +1 @@
+/tmp/resolv.conf

+ 1 - 1
board/PSG/iot2050/rootfs/var/psg/pppd.sh

@@ -11,7 +11,7 @@ PPPD_RETVAL=$?
 echo "PPPD: Retval = $PPPD_RETVAL"
 echo `date`"--PPPD: Retval = $PPPD_RETVAL" >> $VENDOR_PATH/pppd_retval.log
 
-if [ $PPPD_RETVAL != 0 ] && [ $PPPD_RETVAL != 1 ] && [ $PPPD_RETVAL != 6 ]; then
+if [ $PPPD_RETVAL != 0 ] && [ $PPPD_RETVAL != 1 ] && [ $PPPD_RETVAL != 5 ] && [ $PPPD_RETVAL != 6 ]; then
         echo "Modem Err $PPPD_RETVAL"
         $VENDOR_PATH/gsm_MSQ "*AT+cfun=1,1"
 fi

+ 19 - 0
patches/0006-pppd-change-reslov-conf-path.patch

@@ -0,0 +1,19 @@
+diff --git a/package/pppd/0001-change-resolv-conf-path.patch b/package/pppd/0001-change-resolv-conf-path.patch
+new file mode 100644
+index 0000000..6373c0d
+--- /dev/null
++++ b/package/pppd/0001-change-resolv-conf-path.patch
+@@ -0,0 +1,13 @@
++diff --git a/pppd/pathnames.h b/pppd/pathnames.h
++index b0a1cd9..a33f046 100644
++--- a/pppd/pathnames.h
+++++ b/pppd/pathnames.h
++@@ -30,7 +30,7 @@
++ #define _PATH_TTYOPT	 _ROOT_PATH "/etc/ppp/options."
++ #define _PATH_CONNERRS	 _ROOT_PATH "/etc/ppp/connect-errors"
++ #define _PATH_PEERFILES	 _ROOT_PATH "/etc/ppp/peers/"
++-#define _PATH_RESOLV	 _ROOT_PATH "/etc/resolv.conf"
+++#define _PATH_RESOLV	 _ROOT_PATH "/etc/ppp/resolv.conf"
++ 
++ #define _PATH_USEROPT	 ".ppprc"
++ #define	_PATH_PSEUDONYM	 ".ppp_pseudonym"