Skip to content

Commit

Permalink
Merge pull request loxilb-io#884 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
loxilb-io#864 Initial support for lb source ranges
  • Loading branch information
UltraInstinct14 authored Nov 20, 2024
2 parents 1dfec09 + 9faac07 commit 41cc0af
Show file tree
Hide file tree
Showing 34 changed files with 646 additions and 137 deletions.
96 changes: 95 additions & 1 deletion api/models/loadbalance_entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 30 additions & 3 deletions api/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions api/restapi/handler/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
func ConfigGetCIState(params operations.GetConfigCistateAllParams) middleware.Responder {
var result []*models.CIStatusGetEntry
result = make([]*models.CIStatusGetEntry, 0)
tk.LogIt(tk.LogDebug, "api: Status %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: Status %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
hasMod, err := ApiHooks.NetCIStateGet()
if err != nil {
tk.LogIt(tk.LogDebug, "api: Error occur : %v\n", err)
Expand All @@ -46,7 +46,7 @@ func ConfigGetCIState(params operations.GetConfigCistateAllParams) middleware.Re
}

func ConfigPostCIState(params operations.PostConfigCistateParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: HA %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: HA %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)

var hasMod cmn.HASMod

Expand All @@ -67,7 +67,7 @@ func ConfigPostCIState(params operations.PostConfigCistateParams) middleware.Res
func ConfigGetBFDSession(params operations.GetConfigBfdAllParams) middleware.Responder {
var result []*models.BfdGetEntry
result = make([]*models.BfdGetEntry, 0)
tk.LogIt(tk.LogDebug, "api: Status %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: Status %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
bfdMod, err := ApiHooks.NetBFDGet()
if err != nil {
tk.LogIt(tk.LogDebug, "api: Error occur : %v\n", err)
Expand All @@ -90,7 +90,7 @@ func ConfigGetBFDSession(params operations.GetConfigBfdAllParams) middleware.Res
}

func ConfigPostBFDSession(params operations.PostConfigBfdParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: HA %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: HA %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)

var bfdMod cmn.BFDMod

Expand All @@ -112,7 +112,7 @@ func ConfigPostBFDSession(params operations.PostConfigBfdParams) middleware.Resp
}

func ConfigDeleteBFDSession(params operations.DeleteConfigBfdRemoteIPRemoteIPParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: HA %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: HA %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)

var bfdMod cmn.BFDMod

Expand Down
2 changes: 1 addition & 1 deletion api/restapi/handler/conntrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func ConfigGetConntrack(params operations.GetConfigConntrackAllParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: Conntrack %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: Conntrack %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
// Get Conntrack informations
res, err := ApiHooks.NetCtInfoGet()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions api/restapi/handler/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func ConfigGetEndPoint(params operations.GetConfigEndpointAllParams) middleware.Responder {
// Get endpoint rules
tk.LogIt(tk.LogDebug, "api: EndPoint %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: EndPoint %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)

res, err := ApiHooks.NetEpHostGet()
if err != nil {
Expand Down Expand Up @@ -58,7 +58,7 @@ func ConfigGetEndPoint(params operations.GetConfigEndpointAllParams) middleware.
}

func ConfigPostEndPoint(params operations.PostConfigEndpointParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: EndPoint %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: EndPoint %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)

EP := cmn.EndPointMod{}
EP.HostName = params.Attr.HostName
Expand All @@ -78,7 +78,7 @@ func ConfigPostEndPoint(params operations.PostConfigEndpointParams) middleware.R
}

func ConfigDeleteEndPoint(params operations.DeleteConfigEndpointEpipaddressIPAddressParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: EndPoint %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: EndPoint %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)

EP := cmn.EndPointMod{}
EP.HostName = params.IPAddress
Expand Down
6 changes: 3 additions & 3 deletions api/restapi/handler/fdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func ConfigPostFDB(params operations.PostConfigFdbParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: FDB %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: FDB %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
ret := loxinlp.AddFDBNoHook(params.Attr.MacAddress, params.Attr.Dev)
if ret != 0 {
return &ResultResponse{Result: "fail"}
Expand All @@ -33,7 +33,7 @@ func ConfigPostFDB(params operations.PostConfigFdbParams) middleware.Responder {
}

func ConfigDeleteFDB(params operations.DeleteConfigFdbMacAddressDevIfNameParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: FDB %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: FDB %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
ret := loxinlp.DelFDBNoHook(params.MacAddress, params.IfName)
if ret != 0 {
return &ResultResponse{Result: "fail"}
Expand All @@ -42,7 +42,7 @@ func ConfigDeleteFDB(params operations.DeleteConfigFdbMacAddressDevIfNameParams)
}

func ConfigGetFDB(params operations.GetConfigFdbAllParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: FDB %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: FDB %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
fdbs, _ := loxinlp.GetFDBNoHook()
var result []*models.FDBEntry
result = make([]*models.FDBEntry, 0)
Expand Down
16 changes: 10 additions & 6 deletions api/restapi/handler/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func ConfigPostFW(params operations.PostConfigFirewallParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: Firewall %s API called by IP: %s. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.RemoteAddr, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: Firewall %s API called by IP: %s. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.RemoteAddr, params.HTTPRequest.URL)
Opts := cmn.FwOptArg{}
Rules := cmn.FwRuleArg{}
FW := cmn.FwRuleMod{}
Expand All @@ -35,7 +35,7 @@ func ConfigPostFW(params operations.PostConfigFirewallParams) middleware.Respond
Rules.DstPortMax = uint16(params.Attr.RuleArguments.MaxDestinationPort)
Rules.DstPortMin = uint16(params.Attr.RuleArguments.MinDestinationPort)
Rules.InPort = params.Attr.RuleArguments.PortName
Rules.Pref = uint16(params.Attr.RuleArguments.Preference)
Rules.Pref = uint32(params.Attr.RuleArguments.Preference)
Rules.Proto = uint8(params.Attr.RuleArguments.Protocol)
Rules.SrcIP = params.Attr.RuleArguments.SourceIP
Rules.SrcPortMax = uint16(params.Attr.RuleArguments.MaxSourcePort)
Expand Down Expand Up @@ -80,7 +80,7 @@ func ConfigPostFW(params operations.PostConfigFirewallParams) middleware.Respond
}

func ConfigDeleteFW(params operations.DeleteConfigFirewallParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: Firewall %s API called by IP: %s. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.RemoteAddr, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: Firewall %s API called by IP: %s. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.RemoteAddr, params.HTTPRequest.URL)

Rules := cmn.FwRuleArg{}
FW := cmn.FwRuleMod{}
Expand All @@ -102,7 +102,7 @@ func ConfigDeleteFW(params operations.DeleteConfigFirewallParams) middleware.Res
Rules.InPort = *params.PortName
}
if params.Preference != nil {
Rules.Pref = uint16(*params.Preference)
Rules.Pref = uint32(*params.Preference)
}
if params.Protocol != nil {
Rules.Proto = uint8(*params.Protocol)
Expand Down Expand Up @@ -144,14 +144,19 @@ func ConfigDeleteFW(params operations.DeleteConfigFirewallParams) middleware.Res
}

func ConfigGetFW(params operations.GetConfigFirewallAllParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "api: Firewall %s API called by IP: %s. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.RemoteAddr, params.HTTPRequest.URL)
tk.LogIt(tk.LogTrace, "api: Firewall %s API called by IP: %s. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.RemoteAddr, params.HTTPRequest.URL)
res, _ := ApiHooks.NetFwRuleGet()
var result []*models.FirewallEntry
result = make([]*models.FirewallEntry, 0)
for _, FW := range res {
var tmpResult models.FirewallEntry
var tmpRule models.FirewallRuleEntry
var tmpOpts models.FirewallOptionEntry

if FW.Opts.Mark&0x40000000 != 0 {
continue
}

// Rule
tmpRule.DestinationIP = FW.Rule.DstIP
tmpRule.MaxDestinationPort = int64(FW.Rule.DstPortMax)
Expand All @@ -175,7 +180,6 @@ func ConfigGetFW(params operations.GetConfigFirewallAllParams) middleware.Respon
tmpOpts.ToIP = FW.Opts.ToIP
tmpOpts.ToPort = int64(FW.Opts.ToPort)
tmpOpts.Counter = FW.Opts.Counter

tmpResult.RuleArguments = &tmpRule
tmpResult.Opts = &tmpOpts

Expand Down
Loading

0 comments on commit 41cc0af

Please sign in to comment.