Skip to content

Commit

Permalink
configurate interfaces for mac, addresses and traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Jan 7, 2020
1 parent 0b22130 commit 220e8bf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion config-respondd_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion respond/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion respond/daemon/nodeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion respond/daemon/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 220e8bf

Please sign in to comment.