Commit Graph

88 Commits

Author SHA1 Message Date
TheRushingWookie
a5e239147e Fix datarace in testPacketConnOK by adding a mutex when accessing testPacketConnOK's member variables
Signed-off-by: TheRushingWookie <3181551+TheRushingWookie@users.noreply.github.com>
2023-08-16 12:32:56 +00:00
Jeremiah Millay
31b1b44067 Fix packet loss stat zero division (#51)
Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
2023-08-16 12:28:30 +00:00
Kaj J. Niemi
17096581d8 Merge pull request #8 from basen/dependabot/go_modules/golang.org/x/sync-0.3.0 2023-07-13 17:12:56 +03:00
dependabot[bot]
2f4eedb1d6 Bump golang.org/x/sync from 0.2.0 to 0.3.0
Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.2.0 to 0.3.0.
- [Commits](https://github.com/golang/sync/compare/v0.2.0...v0.3.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sync
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-13 14:12:21 +00:00
Kaj J. Niemi
0b3e2694f6 Merge pull request #9 from basen/dependabot/go_modules/golang.org/x/net-0.12.0 2023-07-13 17:11:36 +03:00
dependabot[bot]
136126a27b Bump golang.org/x/net from 0.10.0 to 0.12.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.10.0 to 0.12.0.
- [Commits](https://github.com/golang/net/compare/v0.10.0...v0.12.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-10 23:20:55 +00:00
Kaj J. Niemi
442eb100c5 Merge pull request #4 from basen/dependabot/go_modules/golang.org/x/sync-0.2.0
Bump golang.org/x/sync from 0.1.0 to 0.2.0
2023-05-17 20:03:03 +03:00
dependabot[bot]
b702988fa6 Bump golang.org/x/sync from 0.1.0 to 0.2.0
Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.1.0 to 0.2.0.
- [Commits](https://github.com/golang/sync/compare/v0.1.0...v0.2.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sync
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-17 16:57:13 +00:00
Kaj J. Niemi
c2457fc90d Merge pull request #5 from basen/dependabot/go_modules/golang.org/x/net-0.10.0
Bump golang.org/x/net from 0.7.0 to 0.10.0
2023-05-17 19:56:34 +03:00
Kaj J. Niemi
ececdc59cf Merge pull request #6 from go-ping/master
Add deprecation notice to README
2023-05-17 19:56:12 +03:00
dependabot[bot]
76dcbcc416 Bump golang.org/x/net from 0.7.0 to 0.10.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.7.0 to 0.10.0.
- [Commits](https://github.com/golang/net/compare/v0.7.0...v0.10.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-09 00:01:59 +00:00
Kaj Niemi
c486a21ad5 get up to date 2023-02-21 15:38:27 +02:00
Kaj Niemi
51f8079108 add dependabot to keep us somewhat up to date 2023-02-21 15:34:46 +02:00
Thomas Casteleyn
caaf2b72ea Add deprecation notice to README 2023-01-21 22:33:18 +00:00
Mika Savela
c939a03fb2 fix tests 2023-01-12 11:34:15 +00:00
Kaj J. Niemi
1c7ace28c4 Merge pull request #1 from basen/tos-support
Add TOS support
2022-09-19 13:08:12 +03:00
Mika Savela
63b43a38b6 Add TOS support 2022-09-19 09:57:36 +00:00
Marcelo Magallon
b89bb75386 Report whether or not the TTL value was read (#205)
In IPv6 a hop limit of 0 is valid, so the TTL the code is reporting is
actually a valid value in that case.

Initialize ttl to -1, so that in the case of not getting a TTL value
from the control message, we can let the rest of the code whether the
reported value was actually 0 or whether it couldn't be read.

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
v1.1.0
2022-05-23 16:54:11 +02:00
chenlujjj
6d40342032 Delete redundant pinger.Stop() call (#197) 2022-04-28 15:36:15 +02:00
Marcelo E. Magallon
64d100b308 Goreleaser can no longer be installed using goreleaser.sh
This installation method was deprecated because the associated tool has
been deprecated.

Download "by hand" and run checks before trying to use binary.

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
2022-04-27 09:11:44 +01:00
Charlie Jonas
779d1e9195 Set Packet.ID when sending ICMP requests 2021-11-30 11:55:50 +00:00
Nate Sales
27679364c9 feat: add configurable ICMP identifier 2021-11-30 11:55:50 +00:00
Cemre Mengu
6e2b003bff Add ability to set TTL (#186) 2021-10-14 19:03:14 +01:00
Ben Kochie
3818264768 Use a UUID for packet tracking
Replace the random 8 byte tracker with a 16 byte UUID.
* Implement as a slice so that it can be extended later.
* Deprecate the exported `Pinger.Tracker` value.

https://github.com/go-ping/ping/issues/142

Signed-off-by: Ben Kochie <superq@gmail.com>
2021-09-11 16:15:12 +01:00
Marcelo Magallon
ff8be33200 Provide an abstraction over icmp.PacketConn (#166)
The differences between IPv4 and IPv6 APIs can be moved to a single type so that we don't need to keep track of them all over the code. We can also split Run() into two parts: the top one sets up the listener and the bottom one sends and receives packets. In this way, the bottom part can be tested using a mock packet connection.
2021-05-07 00:38:00 +01:00
Marcelo Magallon
e4e642a957 Use exponential backoff for read deadline (#162)
Before this change, pinging any target once takes ~ 100 ms (the time it takes for Run() to return, not the RTT). After this change, it takes a time comparable to the RTT. The change comes from ReadFrom blocking for the specified delay if the done signal hasn't fired yet. It also improves a little the time it takes to ping a single target multiple times.

Since this is exponential backoff in the way Ethernet does it (random delay, with an increasing maximum value, only changing in case of a timeout), the delay neither necessarily doubles nor increases each time the operation has to be retried, but it does eventually settle on the higher end of the possibilities if there are many timeouts.

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
Committed-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
Committed-by: Charlie Jonas <charlie@charliejonas.co.uk>
2021-04-07 22:46:46 +01:00
Marcelo Magallon
1726e5ede5 Add Logger interface to avoid logging directly (#161)
This commit adds a simple level-based log interface that allows users of the library to control and customize the output, for example by providing a standard Go logger with different settings (timestamps, prefixes, etc).

Closes #16. Closes #103.

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
2021-04-03 00:25:49 +01:00
Charlie Jonas
80a5113803 Reorder channel selection order and make Stop() idempotent (#159)
This fixes #94, closes #116 and also closes #157.
v1.0.0
2021-03-27 00:20:15 +00:00
Charlie Jonas
01e0869fb9 Wrap errors when using fmt.Errorf 2021-03-26 23:37:49 +00:00
Charlie Jonas
54fa5d1e4a Add size flag to demo pinger
Adds a command line flag to the demo pinger which lets the user set the
the size of the ICMP payload. This is useful for testing. The default is
set at 16 which is the default for an unconfigured pinger.

Signed-off-by: Charlie Jonas <charlie@charliejonas.co.uk>
2021-03-26 23:36:52 +00:00
Marcelo Magallon
df22d52de1 Add OnSetup callback (#155)
Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
Merged-by: Charlie Jonas <charlie@charliejonas.co.uk>
2021-03-25 23:48:16 +00:00
Jean Raby
d90f3778a8 Protect stats with RWMutex (#151)
* Protect stats with RWMutex

updateStats() now also updates rtts so it is protected by the
lock.
Statistics() should now be callable from other goroutines.

PacketsSent and PacketsRecvDuplicates can still be updated while
Statistics() is running, and thus could yield strange results
(sent<recv)

To fix this, atomics could be used, but it would require changing the
types of the fields from int to int64, thus changing the public api.

Signed-off-by: Jean Raby <jean@raby.sh>
2021-03-12 09:51:07 +01:00
Jean Raby
5f9dd908cc Fix packet matching; compute statistics as packets are received (#150)
* Fix unprivileged packet matching on Linux
* Compute statistics on-the-fly as packets are received

Signed-off-by: Jean Raby <jean@raby.sh>
Signed-off-by: Charlie Jonas <charlie@charliejonas.co.uk>
Co-authored-by: Charlie Jonas <charlie@charliejonas.co.uk>
2021-03-11 22:01:31 +00:00
Charlie Jonas
25d1413fb7 Fix size issue when deserialising on Windows (#144) 2021-02-16 21:04:19 +00:00
paulc
ab39f29b51 add trackerLength to p.Size in New() 2021-02-07 15:00:27 -08:00
Charlie Jonas
62f79f1f4f Make Tracker uint64 and check for both UDP and ICMP (#134) 2021-02-07 22:15:49 +00:00
Charlie Jonas
38783b05ce Fix size of array into which ICMP messages are deserialised 2021-02-07 22:14:39 +00:00
Lee
ad0b2d22f9 fix doc name
Signed-off-by: Lee <lee10202013@gmail.com>
2021-02-05 21:39:47 +00:00
Lee Wei
42a6788a51 Update CONTRIBUTING.md (#128)
* init contributing guide
* update README

Signed-off-by: Lee <lee10202013@gmail.com>
Co-authored-by: Charlie Jonas <charlie@charliejonas.co.uk>
2021-02-05 09:25:45 +01:00
Ben Kochie
b6486c6f1f Make default Timeout "forever"
Make the default Timeout setting the maximum Go Duration, which is
290 years. Effectively forever.

Signed-off-by: Ben Kochie <superq@gmail.com>
2021-02-01 19:22:33 +00:00
Steven Soroka
52eed920f9 Use MaxUint16 for IDs (#132) 2021-02-01 09:55:49 +00:00
Steven Soroka
30a8f08ad2 Process duplicate packets and make seeds goroutine-safe (#130)
Duplicate ICMP packets are now detected and processed using a separate callback and field in the statistics struct.

Co-authored-by: Charlie Jonas <charlie@charliejonas.co.uk>
Co-authored-by: Ben Kochie <superq@gmail.com>
2021-01-31 13:15:27 +00:00
Charlie Jonas
3300c582a6 Document that Run() returns errors (#112)
* Update example code in README
* Update example code in godoc
* Add missing full stops

Co-authored-by: Ben Kochie <superq@gmail.com>
2020-11-15 14:19:31 +01:00
Rob Collier
acac328aae Update the test to use an always invalid hostname (under the .invalid tld) 2020-11-14 14:44:32 -08:00
Rob Collier
145e7e44ad TLD 'wtf' now exists, use 'wtfh' instead in TestNewPingerInvalid 2020-11-14 14:44:32 -08:00
rrcollier
3977ed7266 Add an OnSend handler (#114)
This commit adds an OnSend handler, similar to the OnReceive handler but called when a packet is sent. It reuses the Packet type, but does not set the TTL or RTT.
2020-10-22 13:20:18 +01:00
rrcollier
265e7c64b3 Add option not to store all received RTTs (#115)
This prevents memory bloat from a process that wants to do very long-running ping tests.
2020-10-20 23:19:59 +01:00
Charlie Jonas
5f9dc3248b Ignore control message errors on Windows
The x/net/ipv4 and x/net/ipv6 packages do not implement the necessary
control message functionality on Microsoft Windows. This commit ignores
any control message errors that are returned by the SetControlMessage
function if the Go runtime is compiled for Windows. This fixes #105.

Signed-off-by: Charlie Jonas <charlie@charliejonas.co.uk>
2020-10-08 17:15:48 +01:00
Charlie Jonas
4db5733515 Update LICENSE and README
This commit extensively copyedits the README and adds a nod to our contributors in the LICENSE file.
2020-10-08 17:15:17 +01:00
Charlie Jonas
fe82a40fcd Add EditorConfig file
EditorConfig (https://editorconfig.org) is a dotfile which stores
configuration that is supported by a wide variety of text editors and
IDEs both natively and with plugins. This allows us to enforce project
standards such as line endings and indentation style.

Signed-off-by: Charlie Jonas <charlie@charliejonas.co.uk>
2020-10-08 17:12:42 +01:00