mirror of
https://github.com/luscis/openlan.git
synced 2025-10-05 16:47:11 +08:00
fix: add origin for routes.
This commit is contained in:
3
Makefile
3
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 && \
|
@cat $(SD)/dist/rootfs/var/openlan/script/install.sh > $(BD)/$(LINUX_DIR).bin && \
|
||||||
echo "__ARCHIVE_BELOW__:" >> $(BD)/$(LINUX_DIR).bin && \
|
echo "__ARCHIVE_BELOW__:" >> $(BD)/$(LINUX_DIR).bin && \
|
||||||
cat $(BD)/$(LINUX_DIR).tar.gz >> $(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
|
install: env linux ## install packages
|
||||||
@mkdir -p $(LINUX_DIR)
|
@mkdir -p $(LINUX_DIR)
|
||||||
|
@@ -3,16 +3,17 @@ package access
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"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"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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 {
|
type jobTimer struct {
|
||||||
@@ -327,8 +328,11 @@ func (w *Worker) OnIpAddr(s *SocketWorker, n *models.Network) error {
|
|||||||
// Filter routes.
|
// Filter routes.
|
||||||
var routes []*models.Route
|
var routes []*models.Route
|
||||||
for _, rt := range n.Routes {
|
for _, rt := range n.Routes {
|
||||||
_, _, err := net.ParseCIDR(rt.Prefix)
|
if _, _, err := net.ParseCIDR(rt.Prefix); err != nil {
|
||||||
if err != nil || rt.NextHop == n.IfAddr {
|
w.out.Warn("Worker.OnIpAddr: parse %s failed.", rt.Prefix)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if rt.NextHop == n.IfAddr || rt.Origin == n.IfAddr {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
routes = append(routes, rt)
|
routes = append(routes, rt)
|
||||||
|
@@ -12,6 +12,7 @@ type Route struct {
|
|||||||
NextHop string `json:"nexthop"`
|
NextHop string `json:"nexthop"`
|
||||||
Metric int `json:"metric"`
|
Metric int `json:"metric"`
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
|
Origin string `json:"origin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRoute(prefix string, nexthop, mode string) (this *Route) {
|
func NewRoute(prefix string, nexthop, mode string) (this *Route) {
|
||||||
@@ -32,6 +33,10 @@ func (u *Route) SetMetric(value int) {
|
|||||||
u.Metric = value
|
u.Metric = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *Route) SetOrigin(value string) {
|
||||||
|
u.Origin = value
|
||||||
|
}
|
||||||
|
|
||||||
type Network struct {
|
type Network struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Tenant string `json:"tenant,omitempty"`
|
Tenant string `json:"tenant,omitempty"`
|
||||||
|
@@ -111,6 +111,7 @@ func NewNetworkSchema(n *Network) schema.Network {
|
|||||||
Prefix: route.Prefix,
|
Prefix: route.Prefix,
|
||||||
Metric: route.Metric,
|
Metric: route.Metric,
|
||||||
Mode: route.Mode,
|
Mode: route.Mode,
|
||||||
|
Origin: route.Origin,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return sn
|
return sn
|
||||||
|
@@ -13,6 +13,7 @@ type PrefixRoute struct {
|
|||||||
NextHop string `json:"nexthop"`
|
NextHop string `json:"nexthop"`
|
||||||
Metric int `json:"metric"`
|
Metric int `json:"metric"`
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
|
Origin string `json:"origin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Subnet struct {
|
type Subnet struct {
|
||||||
|
@@ -2,6 +2,10 @@ package _switch
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/luscis/openlan/pkg/api"
|
"github.com/luscis/openlan/pkg/api"
|
||||||
"github.com/luscis/openlan/pkg/cache"
|
"github.com/luscis/openlan/pkg/cache"
|
||||||
co "github.com/luscis/openlan/pkg/config"
|
co "github.com/luscis/openlan/pkg/config"
|
||||||
@@ -9,9 +13,6 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/models"
|
"github.com/luscis/openlan/pkg/models"
|
||||||
"github.com/luscis/openlan/pkg/network"
|
"github.com/luscis/openlan/pkg/network"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
"net"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func PeerName(name, prefix string) (string, string) {
|
func PeerName(name, prefix string) (string, string) {
|
||||||
@@ -57,6 +58,9 @@ func (w *OpenLANWorker) Initialize() {
|
|||||||
if rt.Metric > 0 {
|
if rt.Metric > 0 {
|
||||||
rte.Metric = rt.Metric
|
rte.Metric = rt.Metric
|
||||||
}
|
}
|
||||||
|
if rt.NextHop != "" {
|
||||||
|
rte.Origin = rt.NextHop
|
||||||
|
}
|
||||||
n.Routes = append(n.Routes, rte)
|
n.Routes = append(n.Routes, rte)
|
||||||
}
|
}
|
||||||
cache.Network.Add(&n)
|
cache.Network.Add(&n)
|
||||||
|
Reference in New Issue
Block a user