Skip to content

Commit

Permalink
Merge pull request #618 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
chore: utils go package added
  • Loading branch information
UltraInstinct14 committed Apr 2, 2024
2 parents 607d378 + e916e67 commit 9765c17
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 388 deletions.
6 changes: 3 additions & 3 deletions pkg/loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ import (
"time"
"unsafe"

cmn "github.com/loxilb-io/loxilb/common"
utils "github.com/loxilb-io/loxilb/pkg/utils"
tk "github.com/loxilb-io/loxilib"
nlp "github.com/vishvananda/netlink"

cmn "github.com/loxilb-io/loxilb/common"
)

// This file implements the interface DpHookInterface
Expand Down Expand Up @@ -2142,5 +2142,5 @@ func (e *DpEbpfH) DpTableGC() {
//export goLinuxArpResolver
func goLinuxArpResolver(dIP C.uint) {
goDest := uint32(dIP)
ArpResolver(goDest)
utils.ArpResolver(goDest)
}
6 changes: 3 additions & 3 deletions pkg/loxinet/gobgpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"time"

cmn "github.com/loxilb-io/loxilb/common"
utils "github.com/loxilb-io/loxilb/pkg/utils"
tk "github.com/loxilb-io/loxilib"

api "github.com/osrg/gobgp/v3/api"
"github.com/osrg/gobgp/v3/pkg/apiutil"
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
Expand Down Expand Up @@ -219,7 +219,7 @@ func (gbh *GoBgpH) syncRoute(p *goBgpRouteInfo, showIdentifier bgp.BGPAddPathMod
return err
}

if IsIPHostNetAddr(dstIP) {
if utils.IsIPHostNetAddr(dstIP) {
return nil
}

Expand Down Expand Up @@ -681,7 +681,7 @@ func (gbh *GoBgpH) AddCurrBgpRoutesToIPRoute() error {
return err
}

if IsIPHostNetAddr(dstIP) {
if utils.IsIPHostNetAddr(dstIP) {
continue
}

Expand Down
16 changes: 10 additions & 6 deletions pkg/loxinet/loxinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
prometheus "github.com/loxilb-io/loxilb/api/prometheus"
cmn "github.com/loxilb-io/loxilb/common"
opts "github.com/loxilb-io/loxilb/options"
utils "github.com/loxilb-io/loxilb/pkg/utils"
tk "github.com/loxilb-io/loxilib"
)

Expand All @@ -54,8 +55,6 @@ const (
const (
MkfsScript = "/usr/local/sbin/mkllb_bpffs"
BpfFsCheckFile = "/opt/loxilb/dp/bpf/intf_map"
ARPAcceptAll = "sysctl net.ipv4.conf.all.arp_accept=1"
ARPAcceptDfl = "sysctl net.ipv4.conf.default.arp_accept=1"
MkMountCG2 = "/usr/local/sbin/mkllb_cgroup 1"
)

Expand Down Expand Up @@ -181,6 +180,12 @@ func loxiNetTicker(bgpPeerMode bool) {

var mh loxiNetH

func sysctlInit() {
utils.WriteFile("/proc/sys/net/ipv4/conf/all/arp_accept", "1")
utils.WriteFile("/proc/sys/net/ipv4/conf/default/arp_accept", "1")
utils.WriteFile("/proc/sys/net/ipv4/ip_forward", "1")
}

func loxiNetInit() {
var rpcMode int

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

// It is important to make sure loxilb's eBPF filesystem
// is in place and mounted to make sure maps are pinned properly
if !FileExists(BpfFsCheckFile) {
if FileExists(MkfsScript) {
if !utils.FileExists(BpfFsCheckFile) {
if utils.FileExists(MkfsScript) {
RunCommand(MkfsScript, true)
}
}

RunCommand(ARPAcceptAll, false)
RunCommand(ARPAcceptDfl, false)
sysctlInit()

mh.self = opts.Opts.ClusterSelf
mh.rssEn = opts.Opts.RssEnable
Expand Down
26 changes: 13 additions & 13 deletions pkg/loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import (
"sync"
"time"

tk "github.com/loxilb-io/loxilib"
probing "github.com/prometheus-community/pro-bing"

"github.com/loxilb-io/loxilb/api/loxinlp"
cmn "github.com/loxilb-io/loxilb/common"
utils "github.com/loxilb-io/loxilb/pkg/utils"
tk "github.com/loxilb-io/loxilib"
probing "github.com/prometheus-community/pro-bing"
)

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

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

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

certExists := FileExists(certFile)
keyExists := FileExists(keyFile)
certExists := utils.FileExists(certFile)
keyExists := utils.FileExists(keyFile)

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

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

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

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

0 comments on commit 9765c17

Please sign in to comment.