I'm trying to program a simplified version of a eBGP speaker. For the import policy, I want to make sure that any new route that I import doesn't have any loops. The routing table that I build looks something like this.
10.0.0.0/8 3 8 11
10.8.0.0/8 4
192.168.0.0/16 3 5 6
192.168.43.0/24 (local)
My question is, how do you check for a routing loop?
Now I've tried multiple things and I think the right way to see if there would be any loops would be to construct a DAG using all the routes in the routing table. Then checking if the new route creates a cycle in the graph. But I can't understand if I should only look at certain prefixes when creating the DAG.