6 Commits

Author SHA1 Message Date
Mayuresh Gaitonde
b0dbda04c9 Add a fix for gw ip 2019-09-12 14:44:21 -07:00
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 40 additions and 9 deletions

View File

@@ -18,22 +18,23 @@ type Controller struct {
localIP, peerIP net.IP localIP, peerIP net.IP
communities []string communities []string
origin uint32 origin uint32
multiHop bool
s *gobgp.BgpServer s *gobgp.BgpServer
} }
func NewController(config *c.Config) (*Controller, error) { func NewController(config *c.Config) (*Controller, error) {
c := &Controller{} c := &Controller{}
var gw net.IP
var err error
if config.Bgp.PeerIP == "" { if config.Bgp.PeerIP == "" {
gw, err := gateway() gw, err = gateway()
if err != nil {
return nil, err
}
c.peerIP = gw c.peerIP = gw
} else { } else {
c.peerIP = net.ParseIP(config.Bgp.PeerIP) c.peerIP = net.ParseIP(config.Bgp.PeerIP)
gw, err = via(c.peerIP)
} }
if c.peerIP == nil { if err != nil || c.peerIP == nil {
return nil, fmt.Errorf("Unable to get peer IP") return nil, fmt.Errorf("Unable to get peer IP : %v", err)
} }
c.communities = config.Bgp.Communities c.communities = config.Bgp.Communities
switch config.Bgp.Origin { switch config.Bgp.Origin {
@@ -46,7 +47,7 @@ func NewController(config *c.Config) (*Controller, error) {
} }
s := gobgp.NewBgpServer() s := gobgp.NewBgpServer()
go s.Serve() go s.Serve()
localAddr, err := localAddress(c.peerIP) localAddr, err := localAddress(gw)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -62,6 +63,10 @@ func NewController(config *c.Config) (*Controller, error) {
} }
c.s = s c.s = s
c.peerAS = config.Bgp.PeerAS 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 return c, nil
} }
@@ -72,6 +77,9 @@ func (c *Controller) AddPeer(peer string) error {
PeerAs: uint32(c.peerAS), 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}) 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 { for _, nodeInfo := range data {
n := nodeInfo.(map[string]interface{}) n := nodeInfo.(map[string]interface{})
if n["Node"] == c.node && n["Status"].(string) == "passing" { if n["Node"] == c.node {
if n["Status"].(string) == "passing" {
return true, nil 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) return false, fmt.Errorf("No healcheck info found for node %s in consul", c.node)

View File

@@ -16,6 +16,19 @@ func gateway() (net.IP, error) {
return net.ParseIP(strings.TrimSpace(string(out))), nil 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)
}
if string(out) == "" {
// assume the provided dest is the next hop
return dest, nil
}
return net.ParseIP(strings.TrimSpace(string(out))), nil
}
func localAddress(gw net.IP) (net.IP, error) { func localAddress(gw net.IP) (net.IP, error) {
addrs, err := net.InterfaceAddrs() addrs, err := net.InterfaceAddrs()
if err != nil { if err != nil {

View File

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