Skip to content
Snippets Groups Projects
Commit 0e965c83 authored by Malte Bauch's avatar Malte Bauch
Browse files

Switch to route replace in case the default route has to be adjusted

parent 96dd557d
No related branches found
No related tags found
4 merge requests!17Build basic ci,!10Add simple modem support on linux through modemmanager,!8General refactoring,!5Draft: Add basic set support for ip/routing via gnmi
......@@ -104,6 +104,7 @@ func walkThroughConfig(config ygot.ValidatedGoStruct) error {
}
}
}
if networkInstances := conf.NetworkInstances; networkInstances != nil {
if networkInstanceMap := networkInstances.NetworkInstance; networkInstanceMap != nil {
for _, networkInstance := range networkInstanceMap {
......@@ -117,6 +118,7 @@ func walkThroughConfig(config ygot.ValidatedGoStruct) error {
}
}
}
return nil
}
......@@ -153,6 +155,7 @@ func generateSubinterface(subintf *gnmitargetygot.OpenconfigInterfaces_Interface
if len(errs) != 0 {
return fmt.Errorf("encountered %v errors during address adding \n%v", len(errs), errs)
}
return nil
}
......@@ -175,12 +178,43 @@ func generateProtocol(protocol *gnmitargetygot.OpenconfigNetworkInstance_Network
return err
}
nextHop := net.ParseIP(hop.GetConfig().GetIndex())
_ = ipnet
nextHop, ok := hop.GetConfig().GetNextHop().(*gnmitargetygot.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_StaticRoutes_Static_NextHops_NextHop_Config_NextHop_Union_String)
if !ok {
return fmt.Errorf("only string union is supported for nextHop")
}
nextHopParsed := net.ParseIP(nextHop.String)
if nextHop == nil {
return fmt.Errorf("failed parsing ip")
}
route := &netlink.Route{
LinkIndex: link.Attrs().Index,
Dst: ipnet,
Gw: nextHopParsed,
}
//if route.Dst != nil {
// fmt.Println("Route GW: ", route.Gw.String())
// fmt.Println("Route Src: ", route.Src.String())
// fmt.Println("Route Dst: ", route.Dst.String())
// err != netlink.RouteAdd(route)
route := netlink.Route{LinkIndex: link.Attrs().Index, Dst: ipnet, Src: nextHop}
netlink.RouteAdd(&route)
//}
fmt.Println("Route GW: ", route.Gw.String())
fmt.Println("Route Src: ", route.Src.String())
fmt.Println("Route Dst: ", route.Dst.String())
if err := netlink.RouteReplace(route); err != nil {
return err
}
}
}
return nil
}
......@@ -190,8 +224,8 @@ func CIDRToIPNet(s string) (*net.IPNet, error) {
return nil, err
}
ipnet.IP = ip
return ipnet, nil
return ipnet, nil
}
func filterKeys(path *gnmi.Path) []map[string]string {
......@@ -201,5 +235,6 @@ func filterKeys(path *gnmi.Path) []map[string]string {
keyMap = append(keyMap, key)
}
}
return keyMap
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment