Commit Graph

38 Commits

Author SHA1 Message Date
Ben Kochie
671c40f29a Fix return on deadlock fix
Fix the return value bug introduced by #85

Signed-off-by: Ben Kochie <superq@gmail.com>
2020-10-01 22:41:34 +01:00
Alexandr Stelnykovych
70ede2ab32
Deadlock fix (#85)
Deadlock observed when starting multiple ping routines.
It happens when writting to `recv` channel (which is full) and no active
readers for this channel.

*Example to reproduce the issue* :

	var waiter sync.WaitGroup
	pingFunc := func() {
		defer waiter.Done()

		pinger, err := ping.NewPinger("8.8.8.8")
		if err != nil {
			return
		}

		pinger.SetPrivileged(true)
		pinger.Count = 5
		pinger.Interval = time.Second
		pinger.Timeout = time.Second * 4

		pinger.Run()
	}

	for i := 0; i < 1000; i++ {
		waiter.Add(1)
		go pingFunc()
	}

	waiter.Wait() // deadlock here! (reproducible almost every time)
2020-10-01 17:29:13 +02:00
Lifei Chen
e8ae07c3ce
Return an error when addr is empty 2020-09-18 13:04:29 +01:00
maddie
e9da6dae98
Return error from Run() (#81)
* Return error to caller and let them handle it
* Use explicit return in Run()
* Silence linter for not handling recvICMP error
2020-09-17 15:08:15 +01:00
Ben Kochie
83991da571
Fix build (#102)
* Fix go fmt issue.
* Run golangci-lint in CI.

Signed-off-by: Ben Kochie <superq@gmail.com>
2020-09-15 18:48:24 +02:00
Ben Kochie
54d38cd396
Add Makefile (#99)
Add a Makefile to simplify build and test.

Signed-off-by: Ben Kochie <superq@gmail.com>
2020-09-14 23:26:21 +02:00
Ben Kochie
e11dda7fa5
Add golangci-lint configuration (#100)
* Add a configuration for golangci-lint.
* Fix some linter issues.

Signed-off-by: Ben Kochie <superq@gmail.com>
2020-09-14 20:23:32 +02:00
Ben Kochie
800dd84e47
Add goreleaser build (#98)
* Add goreleaser config.
* Update .gitignore to skip build output.
* Update CircleCI to Go 1.15 with new optimized image[0].
* Add release workflow step.

[0]: https://circleci.com/docs/2.0/circleci-images/#next-gen-circleci-images

Signed-off-by: Ben Kochie <superq@gmail.com>
2020-09-14 08:20:13 +02:00
Ben Kochie
8e89829cd5
Don't resolve when creating Pinger (#65)
Move the DNS resolver out of the NewPinger() function in order to allow
adjusting of IPv4 vs IPv6 DNS resolution before running. This also
allows the user to verify resolution.
* Create new `New()` method that returns a bare default struct.
* Create new `Resolve()` method.
* Call `Resolve()` from `SetAddr()`.
* Call `Resolve()` automatically from `Run()`.
* Remove unecessary private `run()` method.

Update ping command for simplifed return values of `NewPinger()`.

Signed-off-by: Ben Kochie <superq@gmail.com>
2020-09-14 07:41:27 +02:00
Prasanna Kumar
805de73348
Initialize go module (#93)
* Initialize go module

* Update go.mod

* Update go.sum
2020-09-13 12:04:30 +02:00
Cam
41725b6c24 Update readme and sample command to go-ping organization
closes #90
2020-09-12 12:11:16 -07:00
Cam
4e5b655249 Don't separate ping response header from received bytes 2019-06-13 10:43:26 -07:00
Cam
e33cfb8ae7 Add processPacket unit tests
Add vet and unit test to circleci job
2019-06-04 11:15:55 -07:00
Greg
56df11e077 Make processPacket more performant (#59)
* Make processPacket more performant

* Add more info for debugging to returned error

* remove old benchmark

* change print statement to error return
2019-06-03 16:11:21 -07:00
Alirie Gray
d596e7045d Fix runtime panic 2019-05-30 15:36:06 -07:00
Alirie Gray
3eec4c7c0d Add ability to specifiy source IP address 2019-05-29 16:33:37 -07:00
Maximiliano Churichi
5cc5e2921d Fix TTL comment 2019-05-28 15:33:38 -07:00
Clint Armstrong
3745d7b591 expose ttl on returned ping 2019-05-28 15:33:38 -07:00
Cameron Sparr
ef3ab45e41
Don't oversend packets
fixes part of #6
2018-11-06 16:54:34 +00:00
Ben Kochie
3a0b5a7d8e Fix CPU use (#40)
* Move default case out of select block.
* Add defers to close resources.
* `go fmt` cleanup.
2018-11-06 16:04:36 +00:00
Cameron Sparr
9db3df4bca
Set a random source seed to avoid ID conflicts
closes #14
closes #33
2018-11-06 14:30:27 +00:00
Lincoln Thurlow
28a88d0810 patch: compare identifier for non-root access icmp (#32)
Commit d046b245 introduces a bug which causes ping to always fail.
The source of this bug is:

```
	// Check if reply from same ID
	body := m.Body.(*icmp.Echo)
	if body.ID != p.id {
		return nil
	}
```

Which due to the selection of p.id requires that SetPrivileged is
set to true.  In the case where Privileged (i.e p.network == udp)
it is left to the kernel to set the ICMP id.

https://lwn.net/Articles/443051/  Discusses the introduction of
non-setuid-less ping.  The kernel implementation for this
interface dictates using the local port, which gets mapped into
the ping_table struct.  There is no current implementation in the
go icmp library to address this problem directly.

To address this issue, I've added a `Tracker` field for `Pinger`
as well as `IcmpData` datastructure to allow for uniquely tracking
icmp requests.  The id (as with the `id` field) is not unique,
but will statistically rare for duplicates.
2018-11-06 14:10:49 +00:00
Ben Kochie
687023bdc7 Include adddress in Packet (#38)
Include the original address in the Packet type for use in
`pinger.OnRecv()`.
2018-11-06 12:47:14 +00:00
Cameron Sparr
74b9e0e9f9
Update sample code, README, and circle v2 (#42)
Update sample code, README, and circle v2
2018-11-06 12:45:58 +00:00
Xie Zhenye
667d0a66f2 remove signal handler, add Stop method (#10)
* remove signal handler, add Stop method

* Added ICMP Packet ID to distinguish ICMP replies
2018-11-06 10:48:48 +00:00
Maciek Szczesniak
ad2f544f6b Removed duplicated fields in struct (#27) 2018-08-30 17:03:48 +01:00
webfrank
d046b24518 Added ICMP Packet ID to distinguish ICMP replies in multithreading environment (#15) 2018-08-29 18:21:50 +01:00
keeZey
5740bb1ff1 Change size to Size to make it exportable (#18)
I have made Size exportable as i require the ability to change the
packetsize on a per host basis
2018-08-29 18:14:37 +01:00
mapl
68a45b48a0 Update README.md (#21)
update doc on windows support
2018-08-29 18:10:52 +01:00
Cameron Sparr
416e72114c Add integration tests in circle 2016-02-08 09:29:08 -07:00
Cameron Sparr
dae25ab260 Write unit tests 2016-02-07 14:15:39 -07:00
Cameron Sparr
f1680c8931 put setcap command in README 2016-02-03 11:39:07 -07:00
Cameron Sparr
8ee98d82c4 fix sysctl command 2016-02-01 16:50:38 -07:00
Cameron Sparr
88cc1ad8dd uncommit ping binary 2016-02-01 15:52:45 -07:00
Cameron Sparr
3d295adf56 README typos 2016-02-01 15:49:19 -07:00
Cameron Sparr
3535a0e9a0 Update doc on privileged ping and install 2016-02-01 15:28:30 -07:00
Cameron Sparr
77403bd6ed First commit of go-ping library 2016-02-01 15:21:12 -07:00
Cameron Sparr
5b436d0265 Initial commit 2016-02-01 15:06:45 -07:00