aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-10-23 12:09:14 -0400
committersotech117 <michael_foiani@brown.edu>2023-10-23 12:09:14 -0400
commit0d68d5aa82a980b10b8afd00e054f6c126e50d93 (patch)
treef5005fc386f4162329324725a4d807084c34e566
parent0cada533358361e760958bae7e9d6fd3f60963b2 (diff)
try to fix infinite trigger update loop
-rw-r--r--pkg/ipstack/ipstack.go32
-rwxr-xr-xvhostbin3095666 -> 3105448 bytes
-rwxr-xr-xvrouterbin3095666 -> 3105440 bytes
3 files changed, 17 insertions, 15 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go
index ddb5b91..959e5ff 100644
--- a/pkg/ipstack/ipstack.go
+++ b/pkg/ipstack/ipstack.go
@@ -596,12 +596,14 @@ func makeRipMessage(command uint16, entries []RIPEntry) []byte {
binary.BigEndian.PutUint16(buf[0:2], command)
binary.BigEndian.PutUint16(buf[2:4], uint16(len(entries)))
- mask := netip.MustParseAddr("255.255.255.0")
for i, entry := range entries {
offset := 2*2 + i*SIZE_OF_RIP_ENTRY
binary.BigEndian.PutUint32(buf[offset:offset+4], entry.cost) // 0-3 = 4 bytes
copy(buf[offset+4:offset+8], entry.prefix.Addr().AsSlice()) // 4-7 = 4 bytes
- copy(buf[offset+8:offset+12], mask.AsSlice()) // 8-11 = 4 bytes
+
+ ipv4Netmask := uint32(0xffffffff)
+ ipv4Netmask <<= 32 - entry.prefix.Bits()
+ binary.BigEndian.PutUint32(buf[offset+8:offset+12], ipv4Netmask)
}
return buf
@@ -816,16 +818,13 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I
// each field is 4 bytes
cost := binary.BigEndian.Uint32(message[offset : offset+4])
address, _ := netip.AddrFromSlice(message[offset+4 : offset+8])
- mask, _ := netip.AddrFromSlice(message[offset+8 : offset+12])
- // TODO: fix the mask with the correct calculation
- if mask != netip.MustParseAddr("255.255.255.0") {
- fmt.Println("mask error")
- }
- // add to entries
- prefix := netip.PrefixFrom(address, 24)
- entries = append(entries, RIPEntry{prefix, cost})
+ mask := net.IPv4Mask(message[offset+8], message[offset+9], message[offset+10], message[offset+11])
+
+ // make the prefix
+ bits, _ := mask.Size()
+ prefix := netip.PrefixFrom(address, bits)
- // fmt.Println("Received RIP update: ", prefix.String(), cost)
+ entries = append(entries, RIPEntry{prefix, cost})
}
// add to routing table
@@ -851,10 +850,10 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I
if hop.VIP == hdr.Src &&
entry.cost > hop.Cost {
// fmt.Println("Updating route to ", destination.String(), "with cost", entry.cost)
- if entry.cost == INFINITY {
+ if entry.cost >= INFINITY {
// if we receive infinity from the same neighbor, then delete the route
delete(routingTable, destination)
- triggeredEntries = append(triggeredEntries, RIPEntry{destination, INFINITY})
+ triggeredEntries = append(triggeredEntries, RIPEntry{destination, entry.cost + 1})
} else {
routingTable[destination] = Hop{entry.cost + 1, "R", src, hdr.Src}
triggeredEntries = append(triggeredEntries, RIPEntry{destination, entry.cost + 1})
@@ -880,8 +879,11 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I
mu.Unlock()
}
} else {
- routingTable[destination] = Hop{entry.cost + 1, "R", src, hdr.Src}
- triggeredEntries = append(triggeredEntries, RIPEntry{destination, entry.cost + 1})
+ if entry.cost < INFINITY {
+ // if we receive infinity from the same neighbor, then delete the route
+ routingTable[destination] = Hop{entry.cost + 1, "R", src, hdr.Src}
+ // triggeredEntries = append(triggeredEntries, RIPEntry{destination, entry.cost + 1})
+ }
}
// send out triggered updates
diff --git a/vhost b/vhost
index f641013..ac23975 100755
--- a/vhost
+++ b/vhost
Binary files differ
diff --git a/vrouter b/vrouter
index 6708802..5455b09 100755
--- a/vrouter
+++ b/vrouter
Binary files differ