mirror of
https://github.com/luscis/openlan.git
synced 2025-10-06 00:57:03 +08:00
fix: add vxlan output with dstport
This commit is contained in:
@@ -25,6 +25,7 @@ func (o Output) Add(c *cli.Context) error {
|
||||
Remote: c.String("remote"),
|
||||
Segment: c.Int("segment"),
|
||||
Protocol: c.String("protocol"),
|
||||
DstPort: c.Int("dstport"),
|
||||
}
|
||||
url := o.Url(c.String("url"), network)
|
||||
clt := o.NewHttp(c.String("token"))
|
||||
@@ -96,6 +97,7 @@ func (o Output) Commands(app *api.App) {
|
||||
&cli.StringFlag{Name: "remote"},
|
||||
&cli.IntFlag{Name: "segment"},
|
||||
&cli.StringFlag{Name: "protocol"},
|
||||
&cli.StringFlag{Name: "dstport"},
|
||||
//&cli.StringFlag{Name: "connection"},
|
||||
//&cli.StringFlag{Name: "secret"},
|
||||
//&cli.StringFlag{Name: "auth"},
|
||||
|
@@ -56,7 +56,7 @@ type Qoser interface {
|
||||
}
|
||||
|
||||
type Outputer interface {
|
||||
AddOutput(segment int, protocol, Remote string)
|
||||
AddOutput(data schema.Output)
|
||||
DelOutput(device string)
|
||||
SaveOutput()
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@@ -38,6 +37,9 @@ func (h Output) Get(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h Output) Post(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
name := vars["id"]
|
||||
|
||||
output := &schema.Output{}
|
||||
if err := GetData(r, output); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -45,24 +47,22 @@ func (h Output) Post(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
cs := h.Switcher.Config()
|
||||
if cs.Network == nil {
|
||||
http.Error(w, "switch has no network can not add output", http.StatusBadRequest)
|
||||
http.Error(w, "network is nil", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
network := cs.GetNetwork(output.Network)
|
||||
if network == nil {
|
||||
http.Error(w, fmt.Sprintf("switch has no network with %s can not add output", output.Network), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
worker := GetWorker(output.Network)
|
||||
worker := GetWorker(name)
|
||||
if worker == nil {
|
||||
http.Error(w, "Network not found", http.StatusBadRequest)
|
||||
http.Error(w, "network not found", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
worker.AddOutput(output.Segment, output.Protocol, output.Remote)
|
||||
worker.AddOutput(*output)
|
||||
ResponseMsg(w, 0, "")
|
||||
}
|
||||
|
||||
func (h Output) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
name := vars["id"]
|
||||
|
||||
output := &schema.Output{}
|
||||
if err := GetData(r, output); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -70,17 +70,12 @@ func (h Output) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
cs := h.Switcher.Config()
|
||||
if cs.Network == nil {
|
||||
http.Error(w, "switch has no network can not del output", http.StatusBadRequest)
|
||||
http.Error(w, "network is nil", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
network := cs.GetNetwork(output.Network)
|
||||
if network == nil {
|
||||
http.Error(w, fmt.Sprintf("switch has no network with %s can not del output", output.Network), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
worker := GetWorker(output.Network)
|
||||
worker := GetWorker(name)
|
||||
if worker == nil {
|
||||
http.Error(w, "Network not found", http.StatusBadRequest)
|
||||
http.Error(w, "network not found", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
worker.DelOutput(output.Device)
|
||||
|
@@ -3,7 +3,8 @@ package schema
|
||||
type Output struct {
|
||||
Network string `json:"network"`
|
||||
Protocol string `json:"protocol"`
|
||||
Remote string `json:"Remote"`
|
||||
Remote string `json:"remote"`
|
||||
DstPort int `json:"dstPort"`
|
||||
Segment int `json:"segment"`
|
||||
Device string `json:"device"`
|
||||
RxBytes uint64 `json:"rxBytes"`
|
||||
|
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/luscis/openlan/pkg/libol"
|
||||
"github.com/luscis/openlan/pkg/models"
|
||||
cn "github.com/luscis/openlan/pkg/network"
|
||||
"github.com/luscis/openlan/pkg/schema"
|
||||
nl "github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
@@ -812,11 +813,12 @@ func (w *WorkerImpl) ACLer() api.ACLer {
|
||||
return w.acl
|
||||
}
|
||||
|
||||
func (w *WorkerImpl) AddOutput(segment int, protocol, Remote string) {
|
||||
func (w *WorkerImpl) AddOutput(data schema.Output) {
|
||||
output := co.Output{
|
||||
Segment: segment,
|
||||
Protocol: protocol,
|
||||
Remote: Remote,
|
||||
Segment: data.Segment,
|
||||
Protocol: data.Protocol,
|
||||
Remote: data.Remote,
|
||||
DstPort: data.DstPort,
|
||||
}
|
||||
w.cfg.Outputs = append(w.cfg.Outputs, output)
|
||||
port := &LinuxPort{
|
||||
|
Reference in New Issue
Block a user