From 220e8bf97e5daa7f6fd3a6f8cf31e521a58ed74c Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Sun, 23 Jun 2019 04:06:01 +0200 Subject: [PATCH] configurate interfaces for mac, addresses and traffic --- config-respondd_example.toml | 4 +++- respond/daemon/config.go | 4 +++- respond/daemon/nodeinfo.go | 11 ++++++++++- respond/daemon/statistics.go | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config-respondd_example.toml b/config-respondd_example.toml index 497f2b7..17f9738 100644 --- a/config-respondd_example.toml +++ b/config-respondd_example.toml @@ -15,7 +15,9 @@ hostname = "" site_code = "ffhb" domain_code = "" vpn = false -traffic_interfaces = [ "eth0" ] +interface_mac = "eth0" +interfaces_traffic = [ "eth0" ] +interfaces_address = [ "br-ffhb", "eth0" ] [defaults.location] latitude = 53.112446246 diff --git a/respond/daemon/config.go b/respond/daemon/config.go index ebfd0e8..e6d0407 100644 --- a/respond/daemon/config.go +++ b/respond/daemon/config.go @@ -41,7 +41,9 @@ type AnswerConfig struct { DomainCode string `toml:"domain_code"` Location *data.Location `json:"location,omitempty"` VPN bool `toml:"vpn"` - TrafficInterfaces []string `toml:"traffic_interfaces"` + InterfaceMAC string `toml:"interface_mac"` + InterfacesTraffic []string `toml:"interfaces_traffic"` + InterfacesAddress []string `toml:"interfaces_address"` } func (d *Daemon) getAnswer(iface string) (*AnswerConfig, string) { diff --git a/respond/daemon/nodeinfo.go b/respond/daemon/nodeinfo.go index 283b980..5cdee57 100644 --- a/respond/daemon/nodeinfo.go +++ b/respond/daemon/nodeinfo.go @@ -60,14 +60,23 @@ func (d *Daemon) updateNodeinfo(iface string, resp *data.ResponseData) { resp.Nodeinfo.Software.Babeld.Version = babel.Version() } + if config.InterfaceMAC != "" { + i, err := net.InterfaceByName(config.InterfaceMAC) + if err == nil { + resp.Nodeinfo.Network.Mac = i.HardwareAddr.String() + } + } if resp.Nodeinfo.Network.Mac == "" { resp.Nodeinfo.Network.Mac = fmt.Sprintf("%s:%s:%s:%s:%s:%s", nodeID[0:2], nodeID[2:4], nodeID[4:6], nodeID[6:8], nodeID[8:10], nodeID[10:12]) } - if iface != "" { + if iface != "" && len(config.InterfacesAddress) == 0 { resp.Nodeinfo.Network.Addresses = getAddresses(iface) } else { resp.Nodeinfo.Network.Addresses = []string{} + for _, ifname := range config.InterfacesAddress { + resp.Nodeinfo.Network.Addresses = append(resp.Nodeinfo.Network.Addresses, getAddresses(ifname)...) + } } resp.Nodeinfo.Network.Mesh = make(map[string]*data.NetworkInterface) for _, bface := range d.Batman { diff --git a/respond/daemon/statistics.go b/respond/daemon/statistics.go index 4b23530..c4fa07a 100644 --- a/respond/daemon/statistics.go +++ b/respond/daemon/statistics.go @@ -37,7 +37,7 @@ func (d *Daemon) updateStatistics(iface string, resp *data.ResponseData) { allowedInterfaces := make(map[string]bool) - for _, iface := range config.TrafficInterfaces { + for _, iface := range config.InterfacesTraffic { allowedInterfaces[iface] = true }