Skip to content

Commit

Permalink
capricious flag/config file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcoles committed Oct 7, 2024
1 parent f621b94 commit 1abae6d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ If you think that this may be useful and have any
questions/suggestions, feel free to contact me at vc5lb@proton.me or
raise a GitHub issue.

There has been a bt of an overhaul on the elasticsearch logging
schema> I can't imagine that this is being used much yet, but
something to be aware of if you are using it.
## NB:

In a hopefully final bout of capriciousness I have put the primary
IPv4 address back as the mandatory first command line argument. Other
parameters which cannot be changed after initialisation have been
removed from the config file and are now flags.

## Quickstart

Expand Down
32 changes: 15 additions & 17 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ func main() {

const FACILITY = "vc5"

// mandatory - will likely make this the 1st argument again
addr := flag.String("a", "", "Primary IPv4 address (used for BGP router ID probe source address if VLANs not used)")

// commonly used flags
bgp := flag.Bool("b", false, "Enable BGP listener on port 179")
learn := flag.Uint("l", 0, "Learn; wait for this many seconds before advertising VIPs (for multicast flow state adverts)")
listen := flag.Bool("b", false, "Enable BGP listener on port 179")
native := flag.Bool("n", false, "Use native mode XDP; better performance on network cards that support it")
hostid := flag.String("i", "", "Host ID for logging")
webroot := flag.String("r", "", "Webserver root directory to override built-in documents")
Expand All @@ -54,9 +52,9 @@ func main() {
// somewhat more esoteric options
asn := flag.Uint("A", 0, "Autonomous System Number to enable loopback BGP")
delay := flag.Uint("D", 0, "Delay between initialisaton of interfaces (to prevent bond from flapping)")
flows := flag.Uint("F", 0, "Set maximum number of flows") // experimental - may change
cmd_path := flag.String("C", "", "Command channel path") // experimental - may change
hardfail := flag.Bool("H", false, "Hard fail on balancer configuration error") // experimental - may change
flows := flag.Uint("F", 0, "Set maximum number of flows")
cmd_path := flag.String("C", "", "Command channel path")
hardfail := flag.Bool("H", false, "Hard fail on balancer configuration error")

// Best not to mess with these
socket := flag.String("S", "/var/run/vc5ns", "Socket for communication with proxy in network namespace")
Expand All @@ -77,8 +75,9 @@ func main() {
return
}

file := args[0]
nics := args[1:]
addr := args[0]
file := args[1]
nics := args[2:]

config, err := vc5.Load(file)

Expand All @@ -87,11 +86,7 @@ func main() {
}

if *hostid == "" {
*hostid = *addr
}

if *hostid == "" {
*hostid = "vc5"
*hostid = addr
}

logs := vc5.NewLogger(*hostid, config.LoggingConfig())
Expand All @@ -100,7 +95,7 @@ func main() {
logs.Fatal(FACILITY, "args", KV{"error.message": "No interfaces defined"})
}

address := netip.MustParseAddr(*addr)
address := netip.MustParseAddr(addr)

if !address.Is4() {
logs.Fatal(FACILITY, "args", KV{"error.message": "Address is not IPv4: " + address.String()})
Expand All @@ -126,8 +121,7 @@ func main() {
// getting into an error state - the manager will accept the
// connection but then quietly drop it after ten seconds or
// so. This seems to keep the peer happy.
//err = bgpListener(logs.Sub("bgp"))
if *bgp {
if *listen {
err = bgpListener(logs)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -169,6 +163,9 @@ func main() {
// Short delay to let interfaces quiesce after loading XDP
time.Sleep(5 * time.Second)

// Add a short delay on return to allow BGP, etc to cleanly exit
defer time.Sleep(5 * time.Second)

// Create a balancer instance - this implements interface methods
// (configuration changes, stats requests, etc). which are called
// by the manager object (which handles the main event loop)
Expand All @@ -194,6 +191,7 @@ func main() {
manager := vc5.Manager{
Balancer: balancer,
Logs: logs,
Learn: *learn,
NAT: nat(client), // We use a NAT method and a custom probe function
Prober: prober(client, *socket), // to run checks from the inside network namespace
RouterID: routerID, // BGP router ID to use to speak to peers
Expand Down
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"os"
"regexp"
"strconv"
"time"
//"time"

"github.com/davidcoles/cue"
"github.com/davidcoles/cue/bgp"
Expand Down Expand Up @@ -85,8 +85,8 @@ type Config struct {
Services services `json:"services,omitempty"`
VLANs map[uint16]Prefix `json:"vlans,omitempty"` // VLAN ID to subnet mappings
BGP map[string]bgp.Parameters `json:"bgp,omitempty"` // BGP peers
Learn time.Duration `json:"learn,omitempty"`
Logging Logging_ `json:"logging,omitempty"`
//Learn time.Duration `json:"learn,omitempty"`
Logging Logging_ `json:"logging,omitempty"`
}

func (c *Config) LoggingConfig() Logging {
Expand Down
8 changes: 7 additions & 1 deletion manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Manager struct {
RouterID [4]byte
WebListener net.Listener
Interval uint8
Learn uint

Address netip.Addr
SNI bool
Expand Down Expand Up @@ -84,6 +85,11 @@ func (m *Manager) Manage(ctx context.Context, cfg *Config) error {

m.config = cfg

learn := time.Duration(m.Learn)
if learn == 0 {
learn = 1
}

start := time.Now()
F := "vc5"

Expand Down Expand Up @@ -146,7 +152,7 @@ func (m *Manager) Manage(ctx context.Context, cfg *Config) error {

// advertise VIPs via BGP
go func() {
timer := time.NewTimer(m.config.Learn * time.Second)
timer := time.NewTimer(learn * time.Second)
ticker := time.NewTicker(5 * time.Second)
services := m.Director.Status()

Expand Down

0 comments on commit 1abae6d

Please sign in to comment.