Skip to content

Commit 9765c17

Browse files
Merge pull request #618 from TrekkieCoder/main
chore: utils go package added
2 parents 607d378 + e916e67 commit 9765c17

File tree

7 files changed

+454
-388
lines changed

7 files changed

+454
-388
lines changed

pkg/loxinet/dpebpf_linux.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ import (
5454
"time"
5555
"unsafe"
5656

57+
cmn "github.com/loxilb-io/loxilb/common"
58+
utils "github.com/loxilb-io/loxilb/pkg/utils"
5759
tk "github.com/loxilb-io/loxilib"
5860
nlp "github.com/vishvananda/netlink"
59-
60-
cmn "github.com/loxilb-io/loxilb/common"
6161
)
6262

6363
// This file implements the interface DpHookInterface
@@ -2142,5 +2142,5 @@ func (e *DpEbpfH) DpTableGC() {
21422142
//export goLinuxArpResolver
21432143
func goLinuxArpResolver(dIP C.uint) {
21442144
goDest := uint32(dIP)
2145-
ArpResolver(goDest)
2145+
utils.ArpResolver(goDest)
21462146
}

pkg/loxinet/gobgpclient.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"time"
3030

3131
cmn "github.com/loxilb-io/loxilb/common"
32+
utils "github.com/loxilb-io/loxilb/pkg/utils"
3233
tk "github.com/loxilb-io/loxilib"
33-
3434
api "github.com/osrg/gobgp/v3/api"
3535
"github.com/osrg/gobgp/v3/pkg/apiutil"
3636
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
@@ -219,7 +219,7 @@ func (gbh *GoBgpH) syncRoute(p *goBgpRouteInfo, showIdentifier bgp.BGPAddPathMod
219219
return err
220220
}
221221

222-
if IsIPHostNetAddr(dstIP) {
222+
if utils.IsIPHostNetAddr(dstIP) {
223223
return nil
224224
}
225225

@@ -681,7 +681,7 @@ func (gbh *GoBgpH) AddCurrBgpRoutesToIPRoute() error {
681681
return err
682682
}
683683

684-
if IsIPHostNetAddr(dstIP) {
684+
if utils.IsIPHostNetAddr(dstIP) {
685685
continue
686686
}
687687

pkg/loxinet/loxinet.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
prometheus "github.com/loxilb-io/loxilb/api/prometheus"
3636
cmn "github.com/loxilb-io/loxilb/common"
3737
opts "github.com/loxilb-io/loxilb/options"
38+
utils "github.com/loxilb-io/loxilb/pkg/utils"
3839
tk "github.com/loxilb-io/loxilib"
3940
)
4041

@@ -54,8 +55,6 @@ const (
5455
const (
5556
MkfsScript = "/usr/local/sbin/mkllb_bpffs"
5657
BpfFsCheckFile = "/opt/loxilb/dp/bpf/intf_map"
57-
ARPAcceptAll = "sysctl net.ipv4.conf.all.arp_accept=1"
58-
ARPAcceptDfl = "sysctl net.ipv4.conf.default.arp_accept=1"
5958
MkMountCG2 = "/usr/local/sbin/mkllb_cgroup 1"
6059
)
6160

@@ -181,6 +180,12 @@ func loxiNetTicker(bgpPeerMode bool) {
181180

182181
var mh loxiNetH
183182

183+
func sysctlInit() {
184+
utils.WriteFile("/proc/sys/net/ipv4/conf/all/arp_accept", "1")
185+
utils.WriteFile("/proc/sys/net/ipv4/conf/default/arp_accept", "1")
186+
utils.WriteFile("/proc/sys/net/ipv4/ip_forward", "1")
187+
}
188+
184189
func loxiNetInit() {
185190
var rpcMode int
186191

@@ -197,14 +202,13 @@ func loxiNetInit() {
197202

198203
// It is important to make sure loxilb's eBPF filesystem
199204
// is in place and mounted to make sure maps are pinned properly
200-
if !FileExists(BpfFsCheckFile) {
201-
if FileExists(MkfsScript) {
205+
if !utils.FileExists(BpfFsCheckFile) {
206+
if utils.FileExists(MkfsScript) {
202207
RunCommand(MkfsScript, true)
203208
}
204209
}
205210

206-
RunCommand(ARPAcceptAll, false)
207-
RunCommand(ARPAcceptDfl, false)
211+
sysctlInit()
208212

209213
mh.self = opts.Opts.ClusterSelf
210214
mh.rssEn = opts.Opts.RssEnable

pkg/loxinet/rules.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import (
3232
"sync"
3333
"time"
3434

35-
tk "github.com/loxilb-io/loxilib"
36-
probing "github.com/prometheus-community/pro-bing"
37-
3835
"github.com/loxilb-io/loxilb/api/loxinlp"
3936
cmn "github.com/loxilb-io/loxilb/common"
37+
utils "github.com/loxilb-io/loxilb/pkg/utils"
38+
tk "github.com/loxilb-io/loxilib"
39+
probing "github.com/prometheus-community/pro-bing"
4040
)
4141

4242
// error codes
@@ -360,7 +360,7 @@ func RulesInit(zone *Zone) *RuleH {
360360
rootCACertile := cmn.CertPath + cmn.CACertFileName
361361

362362
// Check if there exist a common CA certificate
363-
if exists := FileExists(rootCACertile); exists {
363+
if exists := utils.FileExists(rootCACertile); exists {
364364

365365
rootCA, err := os.ReadFile(rootCACertile)
366366
if err != nil {
@@ -374,8 +374,8 @@ func RulesInit(zone *Zone) *RuleH {
374374
certFile := cmn.CertPath + cmn.PrivateCertName
375375
keyFile := cmn.CertPath + cmn.PrivateKeyName
376376

377-
certExists := FileExists(certFile)
378-
keyExists := FileExists(keyFile)
377+
certExists := utils.FileExists(certFile)
378+
keyExists := utils.FileExists(keyFile)
379379

380380
if certExists == true && keyExists == true {
381381
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
@@ -993,7 +993,7 @@ func (R *RuleH) electEPSrc(r *ruleEnt) bool {
993993
sip = r.tuples.l3Dst.addr.IP.Mask(r.tuples.l3Dst.addr.Mask)
994994
if np.xIP.Equal(sip) {
995995
sip = net.IPv4(0, 0, 0, 0)
996-
} else if IsIPHostAddr(np.xIP.String()) {
996+
} else if utils.IsIPHostAddr(np.xIP.String()) {
997997
sip = net.IPv4(0, 0, 0, 0)
998998
}
999999
} else {
@@ -1528,7 +1528,7 @@ func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) {
15281528
R.vipMap[sNetAddr.IP.String()]--
15291529

15301530
if R.vipMap[sNetAddr.IP.String()] == 0 {
1531-
if IsIPHostAddr(sNetAddr.IP.String()) {
1531+
if utils.IsIPHostAddr(sNetAddr.IP.String()) {
15321532
loxinlp.DelAddrNoHook(sNetAddr.IP.String()+"/32", "lo")
15331533
}
15341534
dev := fmt.Sprintf("llb-rule-%s", sNetAddr.IP.String())
@@ -1866,7 +1866,7 @@ func (R *RuleH) AddEPHost(apiCall bool, hostName string, name string, args epHos
18661866
if args.probeType == HostProbeHTTPS {
18671867
// Check if there exist a CA certificate particularly for this EP
18681868
rootCACertile := cmn.CertPath + hostName + "/" + cmn.CACertFileName
1869-
if exists := FileExists(rootCACertile); exists {
1869+
if exists := utils.FileExists(rootCACertile); exists {
18701870
rootCA, err := os.ReadFile(rootCACertile)
18711871
if err != nil {
18721872
tk.LogIt(tk.LogError, "RootCA cert load failed : %v", err)
@@ -2084,7 +2084,7 @@ func (R *RuleH) epCheckNow(ep *epHost) {
20842084
}
20852085

20862086
urlStr := fmt.Sprintf("https://%s:%d/%s", addr.String(), ep.opts.probePort, ep.opts.probeReq)
2087-
sOk := HTTPSProber(urlStr, R.tlsCert, R.rootCAPool, ep.opts.probeResp)
2087+
sOk := utils.HTTPSProber(urlStr, R.tlsCert, R.rootCAPool, ep.opts.probeResp)
20882088
//tk.LogIt(tk.LogDebug, "[PROBE] https ep - URL[%s:%s] Resp[%s] %v\n", ep.hostName, urlStr, ep.opts.probeResp, sOk)
20892089
ep.transitionEPState(sOk, inActTryThr)
20902090
} else {
@@ -2624,7 +2624,7 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP) error {
26242624
}
26252625
ev, _, iface := R.zone.L3.IfaSelectAny(IP, false)
26262626
if ev == 0 {
2627-
if !IsIPHostAddr(IP.String()) {
2627+
if !utils.IsIPHostAddr(IP.String()) {
26282628
if loxinlp.AddAddrNoHook(IP.String()+"/32", "lo") != 0 {
26292629
tk.LogIt(tk.LogError, "nat lb-rule vip %s:%s add failed\n", IP.String(), "lo")
26302630
} else {
@@ -2635,7 +2635,7 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP) error {
26352635
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
26362636
defer cancel()
26372637
rCh := make(chan int)
2638-
go GratArpReqWithCtx(ctx, rCh, IP, iface)
2638+
go utils.GratArpReqWithCtx(ctx, rCh, IP, iface)
26392639
select {
26402640
case <-rCh:
26412641
break
@@ -2645,7 +2645,7 @@ func (R *RuleH) AdvRuleVIPIfL2(IP net.IP) error {
26452645
}
26462646

26472647
} else if ciState != "NOT_DEFINED" {
2648-
if IsIPHostAddr(IP.String()) {
2648+
if utils.IsIPHostAddr(IP.String()) {
26492649
if loxinlp.DelAddrNoHook(IP.String()+"/32", "lo") != 0 {
26502650
tk.LogIt(tk.LogError, "nat lb-rule vip %s:%s delete failed\n", IP.String(), "lo")
26512651
} else {

0 commit comments

Comments
 (0)