5 Commits

Author SHA1 Message Date
Mayuresh Gaitonde
e15172111e fix non local peer and add multihop 2018-11-26 16:44:39 -08:00
Mayuresh Gaitonde
b641eb979e fix 2018-11-21 11:25:34 -08:00
Mayuresh Gaitonde
6e923a84fa bugfix 2018-11-21 10:57:46 -08:00
Mayuresh Gaitonde
2a3593aade add debug logs for bgp 2018-11-21 10:37:11 -08:00
Mayuresh Gaitonde
6a184933d1 Fix consul helthcheck 2018-11-20 18:16:44 -08:00
4 changed files with 36 additions and 9 deletions

View File

@@ -18,22 +18,23 @@ type Controller struct {
localIP, peerIP net.IP
communities []string
origin uint32
multiHop bool
s *gobgp.BgpServer
}
func NewController(config *c.Config) (*Controller, error) {
c := &Controller{}
var gw net.IP
var err error
if config.Bgp.PeerIP == "" {
gw, err := gateway()
if err != nil {
return nil, err
}
gw, err = gateway()
c.peerIP = gw
} else {
c.peerIP = net.ParseIP(config.Bgp.PeerIP)
gw, err = via(c.peerIP)
}
if c.peerIP == nil {
return nil, fmt.Errorf("Unable to get peer IP")
if err != nil || c.peerIP == nil {
return nil, fmt.Errorf("Unable to get peer IP : %v", err)
}
c.communities = config.Bgp.Communities
switch config.Bgp.Origin {
@@ -46,7 +47,7 @@ func NewController(config *c.Config) (*Controller, error) {
}
s := gobgp.NewBgpServer()
go s.Serve()
localAddr, err := localAddress(c.peerIP)
localAddr, err := localAddress(gw)
if err != nil {
return nil, err
}
@@ -62,6 +63,10 @@ func NewController(config *c.Config) (*Controller, error) {
}
c.s = s
c.peerAS = config.Bgp.PeerAS
// set mh by default for all ebgp peers
if c.peerAS != config.Bgp.LocalAS {
c.multiHop = true
}
return c, nil
}
@@ -72,6 +77,9 @@ func (c *Controller) AddPeer(peer string) error {
PeerAs: uint32(c.peerAS),
},
}
if c.multiHop {
n.EbgpMultihop = &api.EbgpMultihop{Enabled: true, MultihopTtl: uint32(255)}
}
return c.s.AddPeer(context.Background(), &api.AddPeerRequest{Peer: n})
}

View File

@@ -110,8 +110,13 @@ func (c *ConsulMon) healthCheck(service string) (bool, error) {
}
for _, nodeInfo := range data {
n := nodeInfo.(map[string]interface{})
if n["Node"] == c.node && n["Status"].(string) == "passing" {
return true, nil
if n["Node"] == c.node {
if n["Status"].(string) == "passing" {
return true, nil
} else {
glog.V(2).Infof("Consul Healthcheck returned %s status", n["Status"].(string))
return false, nil
}
}
}
return false, fmt.Errorf("No healcheck info found for node %s in consul", c.node)

View File

@@ -16,6 +16,15 @@ func gateway() (net.IP, error) {
return net.ParseIP(strings.TrimSpace(string(out))), nil
}
func via(dest net.IP) (net.IP, error) {
cmd := fmt.Sprintf(`ip route get %s | grep via | cut -d" " -f3`, dest.String())
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
return nil, fmt.Errorf("Failed to execute command: %s", cmd)
}
return net.ParseIP(strings.TrimSpace(string(out))), nil
}
func localAddress(gw net.IP) (net.IP, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {

View File

@@ -3,9 +3,11 @@ package main
import (
"context"
"flag"
"github.com/golang/glog"
c "github.com/mayuresh82/gocast/config"
"github.com/mayuresh82/gocast/controller"
"github.com/mayuresh82/gocast/server"
log "github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
@@ -17,6 +19,9 @@ var (
func main() {
flag.Parse()
if glog.V(4) {
log.SetLevel(log.DebugLevel)
}
conf := c.GetConfig(*config)
mon := controller.NewMonitor(conf)
srv := server.NewServer(conf.Agent.ListenAddr, mon)