diff options
author | John Southworth <john.southworth@vyatta.com> | 2011-08-16 18:26:24 -0500 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2011-10-27 17:11:27 -0500 |
commit | b1c37ed9fe0e2cfac2ac46d757c6037c1c5436c2 (patch) | |
tree | 7b9b6d104a9f1feeceee34b6f05162cbc488a77e | |
parent | 489df817f907a5dab7e177412fee7da8a970a309 (diff) | |
download | vyatta-op-b1c37ed9fe0e2cfac2ac46d757c6037c1c5436c2.tar.gz vyatta-op-b1c37ed9fe0e2cfac2ac46d757c6037c1c5436c2.zip |
Create new ping command with the following semantics
1. ping <ipv4|ipv6|hostname> will use
* ping for a v4 address
* ping6 for a v6 address
* ping or ping6 for a hostname which ever resolves prefering ipv4
2. ping ipv4 <ipv4|hostname> will ping
3. ping ipv6 <ipv6|hostname> will ping6
4. ping <node> option <advanced ping options>
* allows for options to pass down to ping
* this is a stop gap while we add the most common options
* to the CLI
(cherry picked from commit 5145fd68da8f1c7f8289b99f58cb6eb96389fcef)
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | scripts/vyatta-ping | 28 | ||||
-rw-r--r-- | templates/ping/ipv4/node.def | 4 | ||||
-rw-r--r-- | templates/ping/ipv4/node.tag/node.def | 8 | ||||
-rw-r--r-- | templates/ping/ipv4/node.tag/options/node.def | 8 | ||||
-rw-r--r-- | templates/ping/ipv4/node.tag/options/node.tag/node.def | 8 | ||||
-rw-r--r-- | templates/ping/ipv6/node.def (renamed from templates/ping6/node.def) | 0 | ||||
-rw-r--r-- | templates/ping/ipv6/node.tag/node.def (renamed from templates/ping6/node.tag/node.def) | 2 | ||||
-rw-r--r-- | templates/ping/ipv6/node.tag/options/node.def | 8 | ||||
-rw-r--r-- | templates/ping/ipv6/node.tag/options/node.tag/node.def | 8 | ||||
-rw-r--r-- | templates/ping/node.def | 1 | ||||
-rw-r--r-- | templates/ping/node.tag/node.def | 6 | ||||
-rw-r--r-- | templates/ping/node.tag/options/node.def | 8 | ||||
-rw-r--r-- | templates/ping/node.tag/options/node.tag/node.def | 8 | ||||
-rw-r--r-- | templates/show/system/boot-messages/commit/node.def | 2 |
15 files changed, 96 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am index d1f98ff..ca03fb1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,6 +39,7 @@ bin_SCRIPTS += scripts/vyatta-remote-copy.pl 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 sbin_SCRIPTS = scripts/dhcpv6-client-show-leases.pl sbin_SCRIPTS += scripts/vyatta-image-tools.pl diff --git a/scripts/vyatta-ping b/scripts/vyatta-ping new file mode 100644 index 0000000..d454c19 --- /dev/null +++ b/scripts/vyatta-ping @@ -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 + /bin/ping ${@:2} $ADDR +elif [[ "$ADDR" =~ $ip6regex ]]; then + /bin/ping6 ${@: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 + /bin/ping ${@:2} $ADDR + elif host $ADDR | awk {' print $4 '} \ + | grep -m1 -E "$ip6regex">/dev/null; then + # if ipv6 resolution then ping6 + /bin/ping6 ${@:2} $ADDR + else + echo -e "\n Unknown address: [$ADDR]\n" + fi +fi + diff --git a/templates/ping/ipv4/node.def b/templates/ping/ipv4/node.def new file mode 100644 index 0000000..500ee3a --- /dev/null +++ b/templates/ping/ipv4/node.def @@ -0,0 +1,4 @@ +# +# Operational mode template for the "ping" command +# +help: Send IPv4 Internet Control Message Protocol (ICMP) echo request diff --git a/templates/ping/ipv4/node.tag/node.def b/templates/ping/ipv4/node.tag/node.def new file mode 100644 index 0000000..3b5d1a9 --- /dev/null +++ b/templates/ping/ipv4/node.tag/node.def @@ -0,0 +1,8 @@ +# +# Operational mode front-end for "ping" command +# + +help: Send IPv4 ICMP echo request to specified <hostname|IPv4 address> +allowed: echo -n '<hostname> <x:x:x:x:x>' + +run: /bin/ping $2 diff --git a/templates/ping/ipv4/node.tag/options/node.def b/templates/ping/ipv4/node.tag/options/node.def new file mode 100644 index 0000000..90b225d --- /dev/null +++ b/templates/ping/ipv4/node.tag/options/node.def @@ -0,0 +1,8 @@ +# +# Operational mode front-end for "ping" command +# + +help: Supply advanced options to ping +allowed: echo -n 'option text' + + diff --git a/templates/ping/ipv4/node.tag/options/node.tag/node.def b/templates/ping/ipv4/node.tag/options/node.tag/node.def new file mode 100644 index 0000000..9d4fdca --- /dev/null +++ b/templates/ping/ipv4/node.tag/options/node.tag/node.def @@ -0,0 +1,8 @@ +# +# Operational mode front-end for "ping" command +# + +help: Supply advanced options to ping +allowed: echo -n '<ping-options>' + +run: /bin/ping ${*:5} $3 diff --git a/templates/ping6/node.def b/templates/ping/ipv6/node.def index 20cc018..20cc018 100644 --- a/templates/ping6/node.def +++ b/templates/ping/ipv6/node.def diff --git a/templates/ping6/node.tag/node.def b/templates/ping/ipv6/node.tag/node.def index 9241a00..d5ec570 100644 --- a/templates/ping6/node.tag/node.def +++ b/templates/ping/ipv6/node.tag/node.def @@ -3,6 +3,6 @@ # help: Send IPv6 ICMP echo request 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: /bin/ping6 $2 diff --git a/templates/ping/ipv6/node.tag/options/node.def b/templates/ping/ipv6/node.tag/options/node.def new file mode 100644 index 0000000..90b225d --- /dev/null +++ b/templates/ping/ipv6/node.tag/options/node.def @@ -0,0 +1,8 @@ +# +# Operational mode front-end for "ping" command +# + +help: Supply advanced options to ping +allowed: echo -n 'option text' + + diff --git a/templates/ping/ipv6/node.tag/options/node.tag/node.def b/templates/ping/ipv6/node.tag/options/node.tag/node.def new file mode 100644 index 0000000..10c13a5 --- /dev/null +++ b/templates/ping/ipv6/node.tag/options/node.tag/node.def @@ -0,0 +1,8 @@ +# +# Operational mode front-end for "ping" command +# + +help: Supply advanced options to ping +allowed: echo -n '<ping-options>' + +run: /bin/ping6 ${*:5} $3 diff --git a/templates/ping/node.def b/templates/ping/node.def index 2639ddb..a1bac16 100644 --- a/templates/ping/node.def +++ b/templates/ping/node.def @@ -2,3 +2,4 @@ # Operational mode template for the "ping" command # help: Send Internet Control Message Protocol (ICMP) echo request +allowed: echo -n '<hostname> <x.x.x.x> <h:h:h:h:h:h:h:h>' diff --git a/templates/ping/node.tag/node.def b/templates/ping/node.tag/node.def index efd7127..fe6dbce 100644 --- a/templates/ping/node.tag/node.def +++ b/templates/ping/node.tag/node.def @@ -2,7 +2,7 @@ # Operational mode front-end for "ping" command # -help: Send ICMP echo request to specified <hostname|IPv4 address> -allowed: echo -n '<hostname> <x.x.x.x>' +help: Send ICMP echo request to specified node +allowed: echo -n '<hostname> <x.x.x.x> <h:h:h:h:h:h:h:h>' -run: /bin/ping $2 +run: /opt/vyatta/bin/vyatta-ping $2 diff --git a/templates/ping/node.tag/options/node.def b/templates/ping/node.tag/options/node.def new file mode 100644 index 0000000..90b225d --- /dev/null +++ b/templates/ping/node.tag/options/node.def @@ -0,0 +1,8 @@ +# +# Operational mode front-end for "ping" command +# + +help: Supply advanced options to ping +allowed: echo -n 'option text' + + diff --git a/templates/ping/node.tag/options/node.tag/node.def b/templates/ping/node.tag/options/node.tag/node.def new file mode 100644 index 0000000..cd1efa8 --- /dev/null +++ b/templates/ping/node.tag/options/node.tag/node.def @@ -0,0 +1,8 @@ +# +# Operational mode front-end for "ping" command +# + +help: Supply advanced options to ping +allowed: echo -n '<ping-options>' + +run: /opt/vyatta/bin/vyatta-ping $2 "${@:4}" diff --git a/templates/show/system/boot-messages/commit/node.def b/templates/show/system/boot-messages/commit/node.def new file mode 100644 index 0000000..60e1f67 --- /dev/null +++ b/templates/show/system/boot-messages/commit/node.def @@ -0,0 +1,2 @@ +help: Show the commit messages from this boot +run: cat /var/log/vyatta/vyatta-commit-this-boot.log |