mirror of
https://github.com/luscis/openlan.git
synced 2025-10-06 09:06:54 +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"),
|
Remote: c.String("remote"),
|
||||||
Segment: c.Int("segment"),
|
Segment: c.Int("segment"),
|
||||||
Protocol: c.String("protocol"),
|
Protocol: c.String("protocol"),
|
||||||
|
DstPort: c.Int("dstport"),
|
||||||
}
|
}
|
||||||
url := o.Url(c.String("url"), network)
|
url := o.Url(c.String("url"), network)
|
||||||
clt := o.NewHttp(c.String("token"))
|
clt := o.NewHttp(c.String("token"))
|
||||||
@@ -96,6 +97,7 @@ func (o Output) Commands(app *api.App) {
|
|||||||
&cli.StringFlag{Name: "remote"},
|
&cli.StringFlag{Name: "remote"},
|
||||||
&cli.IntFlag{Name: "segment"},
|
&cli.IntFlag{Name: "segment"},
|
||||||
&cli.StringFlag{Name: "protocol"},
|
&cli.StringFlag{Name: "protocol"},
|
||||||
|
&cli.StringFlag{Name: "dstport"},
|
||||||
//&cli.StringFlag{Name: "connection"},
|
//&cli.StringFlag{Name: "connection"},
|
||||||
//&cli.StringFlag{Name: "secret"},
|
//&cli.StringFlag{Name: "secret"},
|
||||||
//&cli.StringFlag{Name: "auth"},
|
//&cli.StringFlag{Name: "auth"},
|
||||||
|
@@ -56,7 +56,7 @@ type Qoser interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Outputer interface {
|
type Outputer interface {
|
||||||
AddOutput(segment int, protocol, Remote string)
|
AddOutput(data schema.Output)
|
||||||
DelOutput(device string)
|
DelOutput(device string)
|
||||||
SaveOutput()
|
SaveOutput()
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"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) {
|
func (h Output) Post(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
name := vars["id"]
|
||||||
|
|
||||||
output := &schema.Output{}
|
output := &schema.Output{}
|
||||||
if err := GetData(r, output); err != nil {
|
if err := GetData(r, output); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
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()
|
cs := h.Switcher.Config()
|
||||||
if cs.Network == nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
network := cs.GetNetwork(output.Network)
|
worker := GetWorker(name)
|
||||||
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)
|
|
||||||
if worker == nil {
|
if worker == nil {
|
||||||
http.Error(w, "Network not found", http.StatusBadRequest)
|
http.Error(w, "network not found", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
worker.AddOutput(output.Segment, output.Protocol, output.Remote)
|
worker.AddOutput(*output)
|
||||||
ResponseMsg(w, 0, "")
|
ResponseMsg(w, 0, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Output) Delete(w http.ResponseWriter, r *http.Request) {
|
func (h Output) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
name := vars["id"]
|
||||||
|
|
||||||
output := &schema.Output{}
|
output := &schema.Output{}
|
||||||
if err := GetData(r, output); err != nil {
|
if err := GetData(r, output); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
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()
|
cs := h.Switcher.Config()
|
||||||
if cs.Network == nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
network := cs.GetNetwork(output.Network)
|
worker := GetWorker(name)
|
||||||
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)
|
|
||||||
if worker == nil {
|
if worker == nil {
|
||||||
http.Error(w, "Network not found", http.StatusBadRequest)
|
http.Error(w, "network not found", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
worker.DelOutput(output.Device)
|
worker.DelOutput(output.Device)
|
||||||
|
@@ -3,7 +3,8 @@ package schema
|
|||||||
type Output struct {
|
type Output struct {
|
||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
Remote string `json:"Remote"`
|
Remote string `json:"remote"`
|
||||||
|
DstPort int `json:"dstPort"`
|
||||||
Segment int `json:"segment"`
|
Segment int `json:"segment"`
|
||||||
Device string `json:"device"`
|
Device string `json:"device"`
|
||||||
RxBytes uint64 `json:"rxBytes"`
|
RxBytes uint64 `json:"rxBytes"`
|
||||||
|
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/libol"
|
"github.com/luscis/openlan/pkg/libol"
|
||||||
"github.com/luscis/openlan/pkg/models"
|
"github.com/luscis/openlan/pkg/models"
|
||||||
cn "github.com/luscis/openlan/pkg/network"
|
cn "github.com/luscis/openlan/pkg/network"
|
||||||
|
"github.com/luscis/openlan/pkg/schema"
|
||||||
nl "github.com/vishvananda/netlink"
|
nl "github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -812,11 +813,12 @@ func (w *WorkerImpl) ACLer() api.ACLer {
|
|||||||
return w.acl
|
return w.acl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WorkerImpl) AddOutput(segment int, protocol, Remote string) {
|
func (w *WorkerImpl) AddOutput(data schema.Output) {
|
||||||
output := co.Output{
|
output := co.Output{
|
||||||
Segment: segment,
|
Segment: data.Segment,
|
||||||
Protocol: protocol,
|
Protocol: data.Protocol,
|
||||||
Remote: Remote,
|
Remote: data.Remote,
|
||||||
|
DstPort: data.DstPort,
|
||||||
}
|
}
|
||||||
w.cfg.Outputs = append(w.cfg.Outputs, output)
|
w.cfg.Outputs = append(w.cfg.Outputs, output)
|
||||||
port := &LinuxPort{
|
port := &LinuxPort{
|
||||||
|
Reference in New Issue
Block a user