parent
58c9527f19
commit
6c4f09f4cb
22
interface.go
22
interface.go
|
@ -60,21 +60,17 @@ func (b *AbstractBridge) configureIpAndBridgeUp() {
|
||||||
// other server
|
// other server
|
||||||
brIp, brIpNet, err := net.ParseCIDR(b.BridgeIpCIDR)
|
brIp, brIpNet, err := net.ParseCIDR(b.BridgeIpCIDR)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println("Error parsing CIDR: ", err.Error())
|
||||||
}
|
|
||||||
|
|
||||||
if doesIpExists(brIp.String()) {
|
|
||||||
log.Println("Cannot take this IP, it exists already: " + brIp.String())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
br, err := tenus.NewLinkFrom(b.ExistingInterface)
|
br, err := tenus.NewLinkFrom(b.ExistingInterface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println("Error creating Ethernet Alias: ", err.Error())
|
||||||
|
log.Println("Problematic interface: ", b.ExistingInterface)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := br.SetLinkIp(brIp, brIpNet); err != nil {
|
if err := br.SetLinkIp(brIp, brIpNet); err != nil {
|
||||||
log.Println(err.Error())
|
log.Println("Error setting UP the IP: ", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -92,20 +88,22 @@ func (b *AbstractBridge) removeIPandBridgeInt() {
|
||||||
|
|
||||||
br, err := tenus.NewLinkFrom(b.ExistingInterface)
|
br, err := tenus.NewLinkFrom(b.ExistingInterface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println("Error creating Ethernet Handle: ", err.Error())
|
||||||
|
log.Println("Problematic interface: ", b.ExistingInterface)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
brIp, brIpNet, err := net.ParseCIDR(b.BridgeIpCIDR)
|
brIp, brIpNet, err := net.ParseCIDR(b.BridgeIpCIDR)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println("Error parsing CIDR: ", err.Error())
|
||||||
}
|
}
|
||||||
if err := br.UnsetLinkIp(brIp, brIpNet); err != nil {
|
if err := br.UnsetLinkIp(brIp, brIpNet); err != nil {
|
||||||
log.Println(err.Error())
|
log.Println("Error setting DOWN the IP: ", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func doesIpExists(bridgeip string) bool {
|
func isActive(bridgeip string) bool {
|
||||||
|
|
||||||
pinger, err := ping.NewPinger(bridgeip)
|
pinger, err := ping.NewPinger(bridgeip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -84,22 +85,26 @@ func (b *AbstractBridge) HierarchyReLocator(entity AbstractMulticast) {
|
||||||
entity.AddUniqueAndSort(brdNumber)
|
entity.AddUniqueAndSort(brdNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
brIp, _, err := net.ParseCIDR(b.BridgeIpCIDR)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// finished feeding the new number
|
// finished feeding the new number
|
||||||
// if Alpha:
|
// if Alpha:
|
||||||
if entity.IsAlpha(b.hIerarchyNumber) {
|
if entity.IsAlpha(b.hIerarchyNumber) {
|
||||||
if b.IsActive {
|
if isActive(brIp.String()) {
|
||||||
log.Println("Still ALPHA. This is ok.")
|
log.Println("Still ALPHA. This is ok.")
|
||||||
b.IsActive = true // you never know. Better to reiterate.
|
|
||||||
} else {
|
} else {
|
||||||
log.Println("I'm the new ALPHA! Get out my path, losers!")
|
log.Println("I'm the new ALPHA! Get out my path, losers!")
|
||||||
b.configureIpAndBridgeUp()
|
b.configureIpAndBridgeUp()
|
||||||
b.IsActive = true
|
log.Println("Ip is active: ", isActive(brIp.String()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println("GULP! There is a bigger one, better descalating")
|
log.Println("GULP! There is a bigger one, better descalating")
|
||||||
if b.IsActive {
|
if isActive(brIp.String()) {
|
||||||
b.removeIPandBridgeInt()
|
b.removeIPandBridgeInt()
|
||||||
b.IsActive = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue