diff options
Diffstat (limited to 'pkg/ipstack')
-rw-r--r-- | pkg/ipstack/ipstack.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go index c8a4fe8..4556f0f 100644 --- a/pkg/ipstack/ipstack.go +++ b/pkg/ipstack/ipstack.go @@ -843,6 +843,7 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I destination := entry.prefix.Masked() // fmt.Println(prefix.String()) + triggeredEntries := make([]RIPEntry, 0) // check if the entry is already in the routing table and update if need be if hop, ok := routingTable[destination]; ok { // if the hop is the same as the incoming neighbor, @@ -853,8 +854,10 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I 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}) } else { routingTable[destination] = Hop{entry.cost + 1, "R", src, hdr.Src} + triggeredEntries = append(triggeredEntries, RIPEntry{destination, entry.cost + 1}) } } @@ -863,8 +866,10 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I if entry.cost < hop.Cost { if entry.cost == INFINITY { routingTable[destination] = Hop{entry.cost, "R", src, hdr.Src} + triggeredEntries = append(triggeredEntries, RIPEntry{destination, entry.cost}) } else { routingTable[destination] = Hop{entry.cost + 1, "R", src, hdr.Src} + triggeredEntries = append(triggeredEntries, RIPEntry{destination, entry.cost + 1}) } } @@ -883,7 +888,13 @@ func handleRIP(src *Interface, dest *Neighbor, message []byte, hdr *ipv4header.I // routingTable[destination] = Hop{0, "R", src, hdr.Src} //} else { routingTable[destination] = Hop{entry.cost + 1, "R", src, hdr.Src} + triggeredEntries = append(triggeredEntries, RIPEntry{destination, entry.cost + 1}) // } + + // send out triggered updates + if len(triggeredEntries) > 0 { + sendTriggeredUpdates(triggeredEntries) + } } } |