diff options
author | John Southworth <john.southworth@vyatta.com> | 2011-08-17 19:36:11 -0500 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2011-10-27 17:11:28 -0500 |
commit | 1f8755e7fa091ae705eda151882424d4e95e1832 (patch) | |
tree | 9ef2a6ad90123d9e1ffda62b9eed1944a291a5f1 | |
parent | 909267c0ba0bf6c92e14150313e3e3f6958753ea (diff) | |
download | vyatta-op-1f8755e7fa091ae705eda151882424d4e95e1832.tar.gz vyatta-op-1f8755e7fa091ae705eda151882424d4e95e1832.zip |
Initial traceroute rework checkin
(cherry picked from commit ce64904840bea3e716a7de3eca2618e63bcd87d1)
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | scripts/vyatta-traceroute | 28 | ||||
-rw-r--r-- | templates/traceroute/ipv4/node.def | 4 | ||||
-rw-r--r-- | templates/traceroute/ipv4/node.tag/node.def | 25 | ||||
-rw-r--r-- | templates/traceroute/ipv6/node.def (renamed from templates/traceroute6/node.def) | 0 | ||||
-rw-r--r-- | templates/traceroute/ipv6/node.tag/node.def (renamed from templates/traceroute6/node.tag/node.def) | 12 | ||||
-rw-r--r-- | templates/traceroute/node.def | 2 | ||||
-rw-r--r-- | templates/traceroute/node.tag/node.def | 23 |
8 files changed, 68 insertions, 27 deletions
diff --git a/Makefile.am b/Makefile.am index ca03fb1..6ad0386 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,6 +40,7 @@ bin_SCRIPTS += scripts/vyatta-show-current-user bin_SCRIPTS += scripts/tech-support-archive bin_SCRIPTS += scripts/vyatta-op-cmd-wrapper bin_SCRIPTS += scripts/vyatta-ping +bin_SCRIPTS += scripts/vyatta-traceroute sbin_SCRIPTS = scripts/dhcpv6-client-show-leases.pl sbin_SCRIPTS += scripts/vyatta-image-tools.pl diff --git a/scripts/vyatta-traceroute b/scripts/vyatta-traceroute new file mode 100644 index 0000000..f6dff6b --- /dev/null +++ b/scripts/vyatta-traceroute @@ -0,0 +1,28 @@ +#!/bin/bash +ADDR=$1 +# Regular expressions for matching an ipv4 and ipv6 address +# simple ipv4 matcher +ip4regex="^(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$" +# based on IPv6 regex from here: http://forums.dartware.com/viewtopic.php?t=452 +ip6regex="^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?\s*$" + +# Main logic +if [[ "$ADDR" =~ $ip4regex ]]; then + /usr/bin/traceroute ${@:2} $ADDR +elif [[ "$ADDR" =~ $ip6regex ]]; then + /usr/bin/traceroute6 ${@:2} $ADDR +else + echo "Resolving Address: $ADDR" + if host $ADDR | awk {' print $4 '} \ + | grep -m1 -E "$ip4regex">/dev/null; then + # resolve address and check if it is ipv4 or other + /usr/bin/traceroute ${@:2} $ADDR + elif host $ADDR | awk {' print $4 '} \ + | grep -m1 -E "$ip6regex">/dev/null; then + # if ipv6 resolution then ping6 + /usr/bin/traceroute6 ${@:2} $ADDR + else + echo -e "\n Unknown address: [$ADDR]\n" + fi +fi + diff --git a/templates/traceroute/ipv4/node.def b/templates/traceroute/ipv4/node.def new file mode 100644 index 0000000..2f618b1 --- /dev/null +++ b/templates/traceroute/ipv4/node.def @@ -0,0 +1,4 @@ +# +# Operational mode template for the "traceroute" command +# +help: Track network path to <hostname|IPv4 address> diff --git a/templates/traceroute/ipv4/node.tag/node.def b/templates/traceroute/ipv4/node.tag/node.def new file mode 100644 index 0000000..a37ae5b --- /dev/null +++ b/templates/traceroute/ipv4/node.tag/node.def @@ -0,0 +1,25 @@ +# +# Operational mode template for the "traceroute" command +# + +help: Track network path to specified <hostname|IPv4 address> +allowed: echo -n '<hostname> <x:x:x:x>' + +run: + if /opt/vyatta/sbin/vyatta-validate-type.pl -q ipv4 $3 + then + /usr/bin/traceroute $3 + echo + else + if cat /etc/resolv.conf 2> /dev/null | grep -q nameserver + then + if /usr/bin/host $3 &> /dev/null + then + /usr/bin/traceroute $3 + else + echo "Invalid IPv4 address or host name '$3'" + fi + else + echo "Either enter a valid IPv4 address or configure Domain Name Server to resolve host names" + fi + fi diff --git a/templates/traceroute6/node.def b/templates/traceroute/ipv6/node.def index 1075c44..1075c44 100644 --- a/templates/traceroute6/node.def +++ b/templates/traceroute/ipv6/node.def diff --git a/templates/traceroute6/node.tag/node.def b/templates/traceroute/ipv6/node.tag/node.def index 59d5367..b746c3e 100644 --- a/templates/traceroute6/node.tag/node.def +++ b/templates/traceroute/ipv6/node.tag/node.def @@ -3,21 +3,21 @@ # help: Track network path to specified <hostname|IPv6 address> -allowed: echo -n '<hostname> <x:x:x:x:x>' +allowed: echo -n '<hostname> <h:h:h:h:h:h:h:h>' run: - if /opt/vyatta/sbin/vyatta-validate-type.pl -q ipv6 $2 + if /opt/vyatta/sbin/vyatta-validate-type.pl -q ipv6 $3 then - /usr/bin/traceroute6 $2 + /usr/bin/traceroute6 $3 echo else if cat /etc/resolv.conf 2> /dev/null | grep -q nameserver then - if /usr/bin/host $2 &> /dev/null + if /usr/bin/host $3 &> /dev/null then - /usr/bin/traceroute6 $2 + /usr/bin/traceroute6 $3 else - echo "Invalid IPv6 address or host name '$2'" + echo "Invalid IPv6 address or host name '$3'" fi else echo "Either enter a valid IPv6 address or configure Domain Name Server to resolve host names" diff --git a/templates/traceroute/node.def b/templates/traceroute/node.def index 2f618b1..28e695c 100644 --- a/templates/traceroute/node.def +++ b/templates/traceroute/node.def @@ -1,4 +1,4 @@ # # Operational mode template for the "traceroute" command # -help: Track network path to <hostname|IPv4 address> +help: Track network path to node diff --git a/templates/traceroute/node.tag/node.def b/templates/traceroute/node.tag/node.def index 7309798..7b90221 100644 --- a/templates/traceroute/node.tag/node.def +++ b/templates/traceroute/node.tag/node.def @@ -2,24 +2,7 @@ # Operational mode template for the "traceroute" command # -help: Track network path to specified <hostname|IPv4 address> -allowed: echo -n '<hostname> <x.x.x.x>' +help: Track network path to specified node +allowed: echo -n '<hostname> <x.x.x.x> <h:h:h:h:h:h:h:h>' -run: - if /opt/vyatta/sbin/vyatta-validate-type.pl -q ipv4 $2 - then - /usr/bin/traceroute $2 - echo - else - if cat /etc/resolv.conf 2> /dev/null | grep -q nameserver - then - if /usr/bin/host $2 &> /dev/null - then - /usr/bin/traceroute $2 - else - echo "Invalid IP address or host name '$2'" - fi - else - echo "Either enter a valid IPv4 address or configure Domain Name Server to resolve host names" - fi - fi +run: /opt/vyatta/bin/vyatta-traceroute $2 |