2019-04-10 13:18:05 +02:00
|
|
|
package respondd
|
|
|
|
|
|
|
|
import (
|
2019-05-18 23:33:13 +02:00
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/Vivena/babelweb2/parser"
|
|
|
|
|
2019-04-10 13:18:05 +02:00
|
|
|
"github.com/FreifunkBremen/yanic/data"
|
|
|
|
)
|
|
|
|
|
2019-04-10 21:57:31 +02:00
|
|
|
func (d *Daemon) updateNeighbours(iface string, resp *data.ResponseData) {
|
2019-04-10 13:18:05 +02:00
|
|
|
_, nodeID := d.getAnswer(iface)
|
2019-04-10 21:57:31 +02:00
|
|
|
resp.Neighbours.NodeID = nodeID
|
|
|
|
resp.Neighbours.Batadv = make(map[string]data.BatadvNeighbours)
|
2019-05-03 17:51:30 +02:00
|
|
|
|
2019-04-10 21:57:31 +02:00
|
|
|
for _, bface := range d.Batman {
|
2019-05-03 17:51:30 +02:00
|
|
|
|
2019-04-10 21:57:31 +02:00
|
|
|
b := NewBatman(bface)
|
2019-05-03 17:51:30 +02:00
|
|
|
if b == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-04-10 21:57:31 +02:00
|
|
|
for bfaceAddr, n := range b.Neighbours() {
|
|
|
|
resp.Neighbours.Batadv[bfaceAddr] = n
|
|
|
|
}
|
|
|
|
}
|
2019-05-18 23:33:13 +02:00
|
|
|
|
|
|
|
if d.babelData == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.Neighbours.Babel = make(map[string]data.BabelNeighbours)
|
|
|
|
d.babelData.Iter(func(bu parser.BabelUpdate) error {
|
|
|
|
sbu := bu.ToSUpdate()
|
|
|
|
if sbu.TableId != "interface" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if sbu.EntryData["up"].(bool) {
|
|
|
|
addr := sbu.EntryData["ipv6"].(string)
|
|
|
|
resp.Neighbours.Babel[string(sbu.EntryId)] = data.BabelNeighbours{
|
|
|
|
Protocol: "babel",
|
|
|
|
LinkLocalAddress: addr,
|
|
|
|
Neighbours: make(map[string]data.BabelLink),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
d.babelData.Iter(func(bu parser.BabelUpdate) error {
|
|
|
|
sbu := bu.ToSUpdate()
|
|
|
|
if sbu.TableId != "neighbour" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ifname, ok := sbu.EntryData["if"].(string)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("neighbour without if")
|
|
|
|
}
|
|
|
|
addr := sbu.EntryData["address"].(string)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("neighbour without address")
|
|
|
|
}
|
|
|
|
if bIfname, ok := resp.Neighbours.Babel[ifname]; ok {
|
|
|
|
link := data.BabelLink{
|
|
|
|
RXCost: int(sbu.EntryData["rxcost"].(uint64)),
|
|
|
|
TXCost: int(sbu.EntryData["txcost"].(uint64)),
|
|
|
|
Cost: int(sbu.EntryData["cost"].(uint64)),
|
|
|
|
}
|
|
|
|
bIfname.Neighbours[addr] = link
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return errors.New("ifname not found during parsing")
|
|
|
|
})
|
2019-04-10 13:18:05 +02:00
|
|
|
}
|