修正在ECMP网络下的表现

之前ECMP网络可能会导致一次trace的结果来自不同flow(按icmp id区分的策略下),目前id不再携带TTL信息,因此一次trace的id将保持一致。
 要提交的变更:
	修改:     trace/icmp_ipv4.go
	修改:     trace/icmp_ipv6.go
This commit is contained in:
tsosunchia
2024-04-06 20:00:24 +08:00
parent c6eb9bbd2e
commit 190111f6da
2 changed files with 18 additions and 6 deletions

View File

@@ -150,8 +150,9 @@ func (t *ICMPTracer) listenICMP() {
}
continue
}
ttl := int(msg.Msg[36])
packet_id := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[32:34])), 2)
if process_id, ttl, err := reverseID(packet_id); err == nil {
if process_id, _, err := reverseID(packet_id); err == nil {
if process_id == int64(os.Getpid()&0x7f) {
dstip := net.IP(msg.Msg[24:28])
if dstip.Equal(t.DestIP) || dstip.Equal(net.IPv4zero) {
@@ -266,15 +267,20 @@ func (t *ICMPTracer) send(ttl int) error {
return nil
}
id := gernerateID(ttl)
//id := gernerateID(ttl)
id := gernerateID(0)
// log.Println("发送的", id)
data := []byte{byte(ttl)}
data = append(data, bytes.Repeat([]byte{1}, t.Config.PktSize-5)...)
data = append(data, 0x00, 0x00, 0x4f, 0xff)
icmpHeader := icmp.Message{
Type: ipv4.ICMPTypeEcho, Code: 0,
Body: &icmp.Echo{
ID: id,
//Data: []byte("HELLO-R-U-THERE"),
Data: append(bytes.Repeat([]byte{1}, t.Config.PktSize-4), 0x00, 0x00, 0x4f, 0xff),
Data: data,
Seq: ttl,
},
}

View File

@@ -171,8 +171,9 @@ func (t *ICMPTracerv6) listenICMP() {
}
}
ttl := int(msg.Msg[56])
packet_id := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[52:54])), 2)
if process_id, ttl, err := reverseID(packet_id); err == nil {
if process_id, _, err := reverseID(packet_id); err == nil {
if process_id == int64(os.Getpid()&0x7f) {
dstip := net.IP(msg.Msg[32:48])
// 无效包本地环回包
@@ -260,14 +261,19 @@ func (t *ICMPTracerv6) send(ttl int) error {
if t.final != -1 && ttl > t.final {
return nil
}
id := gernerateID(ttl)
//id := gernerateID(ttl)
id := gernerateID(0)
data := []byte{byte(ttl)}
data = append(data, bytes.Repeat([]byte{1}, t.Config.PktSize-5)...)
data = append(data, 0x00, 0x00, 0x4f, 0xff)
icmpHeader := icmp.Message{
Type: ipv6.ICMPTypeEchoRequest, Code: 0,
Body: &icmp.Echo{
ID: id,
//Data: []byte("HELLO-R-U-THERE"),
Data: append(bytes.Repeat([]byte{1}, t.Config.PktSize-4), 0x00, 0x00, 0x4f, 0xff),
Data: data,
Seq: ttl,
},
}