package config import "fmt" type StaticRoute struct { // Provider is the routing provider/table this route belongs to. Provider string `yaml:"provider"` // Dest is the destination CIDR or host address. Dest string `yaml:"dest"` // Gateway is the next-hop IP address, or one of "blackhole", "prohibit", "unreachable". Gateway string `yaml:"gateway"` // Device is the outbound interface. Not allowed with blackhole/prohibit/unreachable gateways. Device string `yaml:"device,omitempty"` // Persistent survives firewall restarts. Persistent bool `yaml:"persistent,omitempty"` Comment string `yaml:"comment,omitempty"` } var specialGateways = map[string]bool{ "blackhole": true, "prohibit": true, "unreachable": true, } func (c *Config) validateRoutes() error { for i, r := range c.Routes { if r.Provider == "" { return fmt.Errorf("routes[%d]: provider required", i) } if r.Dest == "" { return fmt.Errorf("routes[%d]: dest required", i) } if r.Device != "" && specialGateways[r.Gateway] { return fmt.Errorf("routes[%d]: device not allowed with %s gateway", i, r.Gateway) } } return nil }