Skip to content

Commit

Permalink
Merge pull request #720 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
gh-718 Initial support for IP masquerading
  • Loading branch information
UltraInstinct14 committed Jul 5, 2024
2 parents a1abce6 + 79e024b commit 0076e3c
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 45 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/advanced-lb-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ jobs:
./validation.sh
./rmconfig.sh
cd -
- run: |
cd cicd/httpsproxy/
./config.sh
./validation.sh
./rmconfig.sh
cd -
#- run: |
# cd cicd/httpsproxy/
# ./config.sh
# ./validation.sh
# ./rmconfig.sh
# cd -
9 changes: 9 additions & 0 deletions api/models/firewall_option_entry.go

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

3 changes: 3 additions & 0 deletions api/models/loadbalance_entry.go

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

36 changes: 36 additions & 0 deletions api/restapi/embedded_spec.go

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

6 changes: 6 additions & 0 deletions api/restapi/handler/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func ConfigPostFW(params operations.PostConfigFirewallParams) middleware.Respond
Opts.Trap = params.Attr.Opts.Trap
Opts.Record = params.Attr.Opts.Record
Opts.Mark = uint32(params.Attr.Opts.FwMark)
Opts.DoSnat = params.Attr.Opts.DoSnat
Opts.ToIP = params.Attr.Opts.ToIP
Opts.ToPort = uint16(params.Attr.Opts.ToPort)

FW.Rule = Rules
FW.Opts = Opts
Expand Down Expand Up @@ -156,6 +159,9 @@ func ConfigGetFW(params operations.GetConfigFirewallAllParams) middleware.Respon
tmpOpts.Trap = FW.Opts.Trap
tmpOpts.Record = FW.Opts.Record
tmpOpts.FwMark = int64(FW.Opts.Mark)
tmpOpts.DoSnat = FW.Opts.DoSnat
tmpOpts.ToIP = FW.Opts.ToIP
tmpOpts.ToPort = int64(FW.Opts.ToPort)
tmpOpts.Counter = FW.Opts.Counter

tmpResult.RuleArguments = &tmpRule
Expand Down
1 change: 1 addition & 0 deletions api/restapi/handler/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid
tmpSvc.Probetype = lb.Serv.ProbeType
tmpSvc.Probeport = lb.Serv.ProbePort
tmpSvc.Name = lb.Serv.Name
tmpSvc.Snat = lb.Serv.Snat

tmpLB.ServiceArguments = &tmpSvc

Expand Down
13 changes: 12 additions & 1 deletion api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2894,6 +2894,9 @@ definitions:
name:
type: string
description: service name
snat:
type: boolean
description: snat rule
oper:
type: integer
format: int32
Expand Down Expand Up @@ -3614,6 +3617,15 @@ definitions:
fwMark:
type: integer
description: Set a fwmark for any matching rule
doSnat:
type: boolean
description: Do SNAT on matching rule
toIP:
type: string
description: Modify to given IP in CIDR notation
toPort:
type: integer
description: Modify to given Port (Zero if port is not to be modified)
counter:
type: string
description: traffic counters
Expand Down Expand Up @@ -3949,4 +3961,3 @@ definitions:
type: integer
format: uint8
description: Retry Count to detect failure

6 changes: 6 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ type FwOptArg struct {
Allow bool `json:"allow"`
// Mark - Mark the matching rule
Mark uint32 `json:"fwMark"`
// DoSnat - Do snat on matching rule
DoSnat bool `json:"doSnat"`
ToIP string `json:"toIP"`
ToPort uint16 `json:"toPort"`
// Counter - Traffic counter
Counter string `json:"counter"`
}
Expand Down Expand Up @@ -561,6 +565,8 @@ type LbServiceArg struct {
Name string `json:"name"`
// PersistTimeout - Persistence timeout in seconds
PersistTimeout uint32 `json:"persistTimeout"`
// Snat - Do SNAT
Snat bool `json:"snat"`
}

// LbEndPointArg - Information related to load-balancer end-point
Expand Down
2 changes: 1 addition & 1 deletion loxilb-ebpf
26 changes: 16 additions & 10 deletions pkg/loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,18 +922,24 @@ func DpNatLbRuleMod(w *NatDpWorkQ) int {

key := new(natKey)

key.daddr = [4]C.uint{0, 0, 0, 0}
if tk.IsNetIPv4(w.ServiceIP.String()) {
key.daddr[0] = C.uint(tk.IPtonl(w.ServiceIP))
key.v6 = 0
key.mark = C.ushort(w.BlockNum)

if w.NatType == DpSnat {
key.mark |= 0x1000
} else {
convNetIP2DPv6Addr(unsafe.Pointer(&key.daddr[0]), w.ServiceIP)
key.v6 = 1
key.daddr = [4]C.uint{0, 0, 0, 0}
if tk.IsNetIPv4(w.ServiceIP.String()) {
key.daddr[0] = C.uint(tk.IPtonl(w.ServiceIP))
key.v6 = 0
} else {
convNetIP2DPv6Addr(unsafe.Pointer(&key.daddr[0]), w.ServiceIP)
key.v6 = 1
}
key.mark = C.ushort(w.BlockNum)
key.dport = C.ushort(tk.Htons(w.L4Port))
key.l4proto = C.uchar(w.Proto)
key.zone = C.ushort(w.ZoneNum)
}
key.mark = C.ushort(w.BlockNum)
key.dport = C.ushort(tk.Htons(w.L4Port))
key.l4proto = C.uchar(w.Proto)
key.zone = C.ushort(w.ZoneNum)

if w.Work == DpCreate {
dat := new(natActs)
Expand Down
Loading

0 comments on commit 0076e3c

Please sign in to comment.