diff --git a/Makefile b/Makefile index 407689c..e066a25 100755 --- a/Makefile +++ b/Makefile @@ -106,7 +106,8 @@ linux-bin: linux-gz ## build linux install binary @cat $(SD)/dist/rootfs/var/openlan/script/install.sh > $(BD)/$(LINUX_DIR).bin && \ echo "__ARCHIVE_BELOW__:" >> $(BD)/$(LINUX_DIR).bin && \ cat $(BD)/$(LINUX_DIR).tar.gz >> $(BD)/$(LINUX_DIR).bin && \ - chmod +x $(BD)/$(LINUX_DIR).bin + chmod +x $(BD)/$(LINUX_DIR).bin && \ + echo "Save to $(BD)/$(LINUX_DIR).bin" install: env linux ## install packages @mkdir -p $(LINUX_DIR) diff --git a/pkg/access/worker.go b/pkg/access/worker.go index 44ddef2..f0cdb89 100755 --- a/pkg/access/worker.go +++ b/pkg/access/worker.go @@ -3,16 +3,17 @@ package access import ( "crypto/tls" "fmt" - "github.com/luscis/openlan/pkg/config" - "github.com/luscis/openlan/pkg/libol" - "github.com/luscis/openlan/pkg/models" - "github.com/luscis/openlan/pkg/network" - "github.com/luscis/openlan/pkg/schema" "net" "os" "runtime" "strings" "time" + + "github.com/luscis/openlan/pkg/config" + "github.com/luscis/openlan/pkg/libol" + "github.com/luscis/openlan/pkg/models" + "github.com/luscis/openlan/pkg/network" + "github.com/luscis/openlan/pkg/schema" ) type jobTimer struct { @@ -327,8 +328,11 @@ func (w *Worker) OnIpAddr(s *SocketWorker, n *models.Network) error { // Filter routes. var routes []*models.Route for _, rt := range n.Routes { - _, _, err := net.ParseCIDR(rt.Prefix) - if err != nil || rt.NextHop == n.IfAddr { + if _, _, err := net.ParseCIDR(rt.Prefix); err != nil { + w.out.Warn("Worker.OnIpAddr: parse %s failed.", rt.Prefix) + continue + } + if rt.NextHop == n.IfAddr || rt.Origin == n.IfAddr { continue } routes = append(routes, rt) diff --git a/pkg/models/network.go b/pkg/models/network.go index cd8d514..bae9c85 100755 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -12,6 +12,7 @@ type Route struct { NextHop string `json:"nexthop"` Metric int `json:"metric"` Mode string `json:"mode"` + Origin string `json:"origin"` } func NewRoute(prefix string, nexthop, mode string) (this *Route) { @@ -32,6 +33,10 @@ func (u *Route) SetMetric(value int) { u.Metric = value } +func (u *Route) SetOrigin(value string) { + u.Origin = value +} + type Network struct { Name string `json:"name"` Tenant string `json:"tenant,omitempty"` diff --git a/pkg/models/schema.go b/pkg/models/schema.go index 3dfb1fb..c37b1f3 100755 --- a/pkg/models/schema.go +++ b/pkg/models/schema.go @@ -111,6 +111,7 @@ func NewNetworkSchema(n *Network) schema.Network { Prefix: route.Prefix, Metric: route.Metric, Mode: route.Mode, + Origin: route.Origin, }) } return sn diff --git a/pkg/schema/network.go b/pkg/schema/network.go index f26ff24..cb28434 100755 --- a/pkg/schema/network.go +++ b/pkg/schema/network.go @@ -13,6 +13,7 @@ type PrefixRoute struct { NextHop string `json:"nexthop"` Metric int `json:"metric"` Mode string `json:"mode"` + Origin string `json:"origin"` } type Subnet struct { diff --git a/pkg/switch/openlan.go b/pkg/switch/openlan.go index 7d16916..d11f72a 100755 --- a/pkg/switch/openlan.go +++ b/pkg/switch/openlan.go @@ -2,6 +2,10 @@ package _switch import ( "fmt" + "net" + "strings" + "time" + "github.com/luscis/openlan/pkg/api" "github.com/luscis/openlan/pkg/cache" co "github.com/luscis/openlan/pkg/config" @@ -9,9 +13,6 @@ import ( "github.com/luscis/openlan/pkg/models" "github.com/luscis/openlan/pkg/network" "github.com/vishvananda/netlink" - "net" - "strings" - "time" ) func PeerName(name, prefix string) (string, string) { @@ -57,6 +58,9 @@ func (w *OpenLANWorker) Initialize() { if rt.Metric > 0 { rte.Metric = rt.Metric } + if rt.NextHop != "" { + rte.Origin = rt.NextHop + } n.Routes = append(n.Routes, rte) } cache.Network.Add(&n)