This adds an option to the config file to specify the TTL value. If 0 or not specified, in some cases it defaults to 64 and in other cases it defaults to whatever is configured in the operating system. This matches previous behavior.
Signed-off-by: Francis Tang <francis.tang@gmail.com>
# The size of the payload.
[ payload_size: <int> ]
+# TTL of outbound packets. Value must be in the range [0, 255]. Can be used
+# to test reachability of a target within a given number of hops, for example,
+# to determine when network routing has changed.
+[ ttl: <int> ]
+
```
### <grpc_probe>
- expect: "^:[^ ]+ 001"
icmp:
prober: icmp
+ icmp_ttl5:
+ prober: icmp
+ timeout: 5s
+ icmp:
+ ttl: 5
\ No newline at end of file
}
// DefaultICMPProbe set default value for ICMPProbe
+ DefaultICMPTTL = 64
DefaultICMPProbe = ICMPProbe{
IPProtocolFallback: true,
+ TTL: DefaultICMPTTL,
}
// DefaultDNSProbe set default value for DNSProbe
SourceIPAddress string `yaml:"source_ip_address,omitempty"`
PayloadSize int `yaml:"payload_size,omitempty"`
DontFragment bool `yaml:"dont_fragment,omitempty"`
+ TTL int `yaml:"ttl,omitempty"`
}
type DNSProbe struct {
if runtime.GOOS == "windows" && s.DontFragment {
return errors.New("\"dont_fragment\" is not supported on windows platforms")
}
+
+ if s.TTL < 0 {
+ return errors.New("\"ttl\" cannot be negative")
+ }
+ if s.TTL > 255 {
+ return errors.New("\"ttl\" cannot exceed 255")
+ }
return nil
}
input: "testdata/invalid-http-request-compression-reject-all-encodings.yml",
want: `error parsing config file: invalid configuration "Accept-Encoding: *;q=0.0", "compression: gzip"`,
},
+ {
+ input: "testdata/invalid-icmp-ttl.yml",
+ want: "error parsing config file: \"ttl\" cannot be negative",
+ },
+ {
+ input: "testdata/invalid-icmp-ttl-overflow.yml",
+ want: "error parsing config file: \"ttl\" cannot exceed 255",
+ },
{
input: "testdata/invalid-tcp-query-response-regexp.yml",
want: `error parsing config file: "Could not compile regular expression" regexp=":["`,
--- /dev/null
+modules:
+ icmp_test:
+ prober: icmp
+ icmp:
+ ttl: 256
--- /dev/null
+modules:
+ icmp_test:
+ prober: icmp
+ icmp:
+ ttl: -1
rttStart := time.Now()
if icmpConn != nil {
+ ttl := module.ICMP.TTL
+ if ttl > 0 {
+ if c4 := icmpConn.IPv4PacketConn(); c4 != nil {
+ level.Debug(logger).Log("msg", "Setting TTL (IPv4 unprivileged)", "ttl", ttl)
+ c4.SetTTL(ttl)
+ }
+ if c6 := icmpConn.IPv6PacketConn(); c6 != nil {
+ level.Debug(logger).Log("msg", "Setting TTL (IPv6 unprivileged)", "ttl", ttl)
+ c6.SetHopLimit(ttl)
+ }
+ }
_, err = icmpConn.WriteTo(wb, dst)
} else {
+ ttl := config.DefaultICMPTTL
+ if module.ICMP.TTL > 0 {
+ level.Debug(logger).Log("msg", "Overriding TTL (raw IPv4)", "ttl", ttl)
+ ttl = module.ICMP.TTL
+ }
// Only for IPv4 raw. Needed for setting DontFragment flag.
header := &ipv4.Header{
Version: ipv4.Version,
Len: ipv4.HeaderLen,
Protocol: 1,
TotalLen: ipv4.HeaderLen + len(wb),
- TTL: 64,
+ TTL: ttl,
Dst: dstIPAddr.IP,
Src: srcIP,
}