diff options
author | David Doan <daviddoan@Davids-MacBook-Pro-70.local> | 2023-10-11 16:39:56 -0400 |
---|---|---|
committer | David Doan <daviddoan@Davids-MacBook-Pro-70.local> | 2023-10-11 16:39:56 -0400 |
commit | db0a9f0a4605d85ba4e535ba0ab590776cc4ba0a (patch) | |
tree | 4cfc83ca904f33b7d052ce5a6784d5996e827c90 /pkg/routingTable.go | |
parent | ded5a362b43715497a6f887354dd1a20bc9a621b (diff) | |
parent | ce42396f99e1d99d7e3b3016acabd9380627a297 (diff) |
merge
Diffstat (limited to 'pkg/routingTable.go')
-rw-r--r-- | pkg/routingTable.go | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/pkg/routingTable.go b/pkg/routingTable.go deleted file mode 100644 index bda4524..0000000 --- a/pkg/routingTable.go +++ /dev/null @@ -1,71 +0,0 @@ -package routingTable - -import ( - "fmt" - "net" - "net/netip" - "os" - "bufio" -) - -type Address struct { - addr netip.Addr; - prefix netip.Prefix; -} - -type Routing struct { - dest Address; - cost uint16_t; - mask netip.Prefix; -} - -routingTable := make(map[Address]Routing) - -func Initialize(config IpConfig) (error) { - if len(os.Args) != 2 { - fmt.Printf("Usage: %s <configFile>\n", os.Args[0]) - os.Exit(1) - } - fileName := os.Args[1] - - lnxConfig, err := lnxconfig.ParseConfig(fileName) - if err != nil { - panic(err) - } - - // populate routing table - for _, iface := range lnxConfig.Interfaces { - routingTable[Address{iface.AssignedIP, iface.AssignedPrefix}] = Routing{Address{iface.AssignedIP, iface.AssignedPrefix}, 0, iface.AssignedPrefix} - } - -} - -func AddRoute(dest Address, cost uint16_t, mask netip.Prefix) (error) { - if _, ok := routingTable[dest]; ok { - return newErrString(ln, "Route already exists") - } - routingTable[dest] = Routing{dest, cost, mask} -} - -func RemoveRoute(dest Address) (error) { - if _, ok := routingTable[dest]; !ok { - return newErrString(ln, "Route does not exist") - } - delete(routingTable, dest) -} - -func GetRoute(dest Address) (Routing, error) { - // get the most specific route - for key, value := range routingTable { - if key.prefix.Contains(dest.addr) { - return value, nil - } - } - return nil, newErrString(ln, "Route does not exist") -} - -func PrintRoutingTable() { - for key, value := range routingTable { - fmt.Printf("%s/%d\t%d\n", key.addr, key.prefix.Bits(), value.cost) - } -}
\ No newline at end of file |