mirror of
https://github.com/luscis/openlan.git
synced 2025-09-27 04:46:02 +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 && \
|
||||
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)
|
||||
|
@@ -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)
|
||||
|
@@ -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"`
|
||||
|
@@ -111,6 +111,7 @@ func NewNetworkSchema(n *Network) schema.Network {
|
||||
Prefix: route.Prefix,
|
||||
Metric: route.Metric,
|
||||
Mode: route.Mode,
|
||||
Origin: route.Origin,
|
||||
})
|
||||
}
|
||||
return sn
|
||||
|
@@ -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 {
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user