fea: fallback for output.
Some checks failed
Coverage CI / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
Ubuntu CI / build (push) Has been cancelled

This commit is contained in:
Daniel Ding
2025-08-29 10:43:14 +08:00
parent 1202289a32
commit 80ea5c26b4
10 changed files with 27 additions and 20 deletions

View File

@@ -27,6 +27,7 @@ func (o Output) Add(c *cli.Context) error {
DstPort: c.Int("dstport"),
Secret: c.String("secret"),
Crypt: c.String("crypt"),
Fallback: c.String("fallback"),
}
url := o.Url(c.String("url"), network)
clt := o.NewHttp(c.String("token"))
@@ -94,6 +95,7 @@ func (o Output) Commands() *cli.Command {
Usage: "Add an output for the network",
Flags: []cli.Flag{
&cli.StringFlag{Name: "remote", Required: true},
&cli.StringFlag{Name: "fallback"},
&cli.IntFlag{Name: "segment"},
&cli.StringFlag{Name: "protocol"},
&cli.StringFlag{Name: "dstport"},

View File

@@ -10,6 +10,7 @@ type Output struct {
Segment int `json:"segment" yaml:"segment"`
Protocol string `json:"protocol,omitempty" yaml:"protocol,omitempty"` // gre, vxlan, tcp/tls/wss etc.
Remote string `json:"remote" yaml:"remote"`
Fallback string `json:"fallback,omitempty" yaml:"fallback,omitempty"`
DstPort int `json:"dstport,omitempty" yaml:"dstport,omitempty"`
Link string `json:"link,omitempty" yaml:"link,omitempty"` // link name
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`

View File

@@ -13,6 +13,7 @@ type Output struct {
TxBytes uint64
ErrPkt uint64
NewTime int64
Fallback string
}
func (o *Output) UpTime() int64 {

View File

@@ -10,5 +10,4 @@ func (l *Output) Update() {
l.RxBytes = sts.RxBytes
l.TxBytes = sts.TxBytes
}
return
}

View File

@@ -106,6 +106,7 @@ func NewOutputSchema(o *Output) schema.Output {
Network: o.Network,
Protocol: o.Protocol,
Remote: o.Remote,
Fallback: o.Fallback,
Segment: o.Segment,
Device: o.Device,
RxBytes: o.RxBytes,

View File

@@ -17,5 +17,5 @@ type Access struct {
System string `json:"system"`
Address string `json:"address"`
Names map[string]string `json:"names"`
Fallback string `json:"fallback"`
Fallback string `json:"fallback,omitempty"`
}

View File

@@ -2,11 +2,11 @@ package schema
type IPSecTunnel struct {
Left string `json:"local"`
LeftId string `json:"localid"`
LeftPort int `json:"localport"`
LeftId string `json:"localid,omitempty"`
LeftPort int `json:"localport,omitempty"`
Right string `json:"remote"`
RightId string `json:"remoteid"`
RightPort int `json:"remoteport"`
RightId string `json:"remoteid,omitempty"`
RightPort int `json:"remoteport,omitempty"`
Transport string `json:"protocol"`
Secret string `json:"secret"`
State string `json:"state"`

View File

@@ -5,7 +5,7 @@ type Link struct {
UUID string `json:"uuid"`
Alias string `json:"alias"`
Network string `json:"network"`
User string `json:"user"`
User string `json:"user,omitempty"`
Protocol string `json:"protocol"`
Server string `json:"server"`
Device string `json:"device"`

View File

@@ -4,13 +4,14 @@ type Output struct {
Network string `json:"network"`
Protocol string `json:"protocol"`
Remote string `json:"remote"`
DstPort int `json:"dstPort"`
Segment int `json:"segment"`
Secret string `json:"secret"`
Crypt string `json:"crypt"`
DstPort int `json:"dstPort,omitempty"`
Segment int `json:"segment,omitempty"`
Secret string `json:"secret,omitempty"`
Crypt string `json:"crypt,omitempty"`
Device string `json:"device"`
RxBytes uint64 `json:"rxBytes"`
TxBytes uint64 `json:"txBytes"`
ErrPkt uint64 `json:"errors"`
RxBytes uint64 `json:"rxBytes,omitempty"`
TxBytes uint64 `json:"txBytes,omitempty"`
ErrPkt uint64 `json:"errors,omitempty"`
AliveTime int64 `json:"aliveTime"`
Fallback string `json:"fallback,omitempty"`
}

View File

@@ -138,7 +138,8 @@ func (w *WorkerImpl) AddPhysical(bridge string, output string) {
func (w *WorkerImpl) addOutput(bridge string, port *co.Output) {
mtu := 0
if port.Protocol == "gre" {
switch port.Protocol {
case "gre":
mtu = 1450
link := &LinuxLink{
link: &nl.Gretap{
@@ -158,7 +159,7 @@ func (w *WorkerImpl) addOutput(bridge string, port *co.Output) {
return
}
port.Linker = link
} else if port.Protocol == "vxlan" {
case "vxlan":
dport := 8472
if port.DstPort > 0 {
dport = port.DstPort
@@ -183,8 +184,7 @@ func (w *WorkerImpl) addOutput(bridge string, port *co.Output) {
}
cn.LinkSet(port.Link, "mtu", strconv.Itoa(mtu))
port.Linker = link
} else if port.Protocol == "tcp" || port.Protocol == "tls" ||
port.Protocol == "wss" {
case "tcp", "tls", "wss":
port.Link = cn.Taps.GenName()
name, pass := SplitCombined(port.Secret)
algo, secret := SplitCombined(port.Crypt)
@@ -200,6 +200,7 @@ func (w *WorkerImpl) addOutput(bridge string, port *co.Output) {
File: "/dev/null",
},
Connection: port.Remote,
Fallback: port.Fallback,
Protocol: port.Protocol,
Username: name,
Password: pass,
@@ -214,7 +215,7 @@ func (w *WorkerImpl) addOutput(bridge string, port *co.Output) {
link.Initialize()
link.Start()
port.Linker = link
} else {
default:
link, err := nl.LinkByName(port.Remote)
if link == nil {
w.out.Error("WorkerImpl.addOutput %s %s", port.Remote, err)
@@ -256,6 +257,7 @@ func (w *WorkerImpl) addOutput(bridge string, port *co.Output) {
Segment: port.Segment,
Device: port.Link,
Secret: port.Secret,
Fallback: port.Fallback,
}
cache.Output.Add(port.Link, out)
@@ -921,7 +923,6 @@ func (w *WorkerImpl) delIpSet(rt co.PrefixRoute) {
return
}
w.setR.Del(rt.Prefix)
return
}
func (w *WorkerImpl) forwardSubnet() {
@@ -1087,6 +1088,7 @@ func (w *WorkerImpl) AddOutput(data schema.Output) {
DstPort: data.DstPort,
Secret: data.Secret,
Crypt: data.Crypt,
Fallback: data.Fallback,
}
if !w.cfg.AddOutput(output) {
w.out.Info("WorkerImple.AddOutput %s already existed", output.Id())