package rtable import ( "errors" "fmt" "os/exec" "github.com/crip/ripv2" ) func Add(r *ripv2.Routes) { r.Lock() for _, r := range r.Routes { if !r.FIB { command(ADD, &r) r.FIB = true } } r.Unlock() } func command(command COMMAND, r *ripv2.Route) error { var cmd *exec.Cmd switch command { case ADD, REMOVE: cmd = exec.Command("route", string(command), "-net", r.Addr.String(), r.Subnet.String(), r.Nexthop.String(), "-hopcount", fmt.Sprint(r.Metric)) default: return errors.New("command not supported") } return cmd.Run() } func Remove(r *ripv2.Routes) { for _, r := range r.Routes { command(REMOVE, &r) } }