Skip to content

Commit

Permalink
add udp reachable check (#545)
Browse files Browse the repository at this point in the history
* add udp reachable check

add integration test for udp

* refactor for how variable creating
  • Loading branch information
weakiwi authored Feb 17, 2020
1 parent 09b559d commit 81d5f15
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions integration-tests/goss/alpine3/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: false
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/goss/alpine3/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: false
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/goss/centos7/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/goss/centos7/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/goss/generate_goss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ goss a "${args[@]}" package $package foobar vim-tiny

goss a "${args[@]}" addr --timeout 1s google.com:443 google.com:22

goss a "${args[@]}" addr --timeout 1s udp://8.8.8.8:53

goss a "${args[@]}" port tcp:80 tcp6:80 9999

goss a "${args[@]}" service $package foobar
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/goss/precise/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/goss/precise/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/goss/wheezy/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/goss/wheezy/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ addr:
tcp://google.com:443:
reachable: true
timeout: 1000
udp://8.8.8.8:53:
reachable: true
timeout: 1000
port:
tcp:80:
listening: true
Expand Down
8 changes: 5 additions & 3 deletions system/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ func (a *DefAddr) Exists() (bool, error) { return a.Reachable() }
func (a *DefAddr) Reachable() (bool, error) {
network, address := splitAddress(a.address)

localAddr := &net.TCPAddr{
IP: net.ParseIP(a.LocalAddress),
var localAddr net.Addr
if network == "udp" {
localAddr = &net.UDPAddr{IP: net.ParseIP(a.LocalAddress)}
} else {
localAddr = &net.TCPAddr{IP: net.ParseIP(a.LocalAddress)}
}

d := net.Dialer{LocalAddr: localAddr, Timeout: time.Duration(a.Timeout) * time.Millisecond}
conn, err := d.Dial(network, address)
if err != nil {
Expand Down

0 comments on commit 81d5f15

Please sign in to comment.