Skip to content
Snippets Groups Projects

Use the IPv6 address of bridges

Merged meskio requested to merge meskio/rdsys:ipv6 into main
1 unresolved thread
Files
16
+ 46
4
@@ -117,12 +117,17 @@ func calcTestedResources(metrics *Metrics, currentRatios map[core.Hashkey]flicke
if b, ok := getBridgeBase(r); ok {
running = b.Flags.Running
}
ipversion := strconv.Itoa(int(r.IPVersion()))
if r.IPVersion() == core.IPAny {
ipversion = "any"
}
metrics.Resources.With(
prometheus.Labels{
"type": rName,
"functional": core.StateToString(rTest.State),
"ratio": core.SpeedToString(rTest.Speed),
"running": strconv.FormatBool(running),
"ipversion": ipversion,
}).Inc()
}
@@ -250,6 +255,7 @@ func reloadBridgeDescriptors(cfg *Config, rcol *core.BackendResources, testFunc
for _, bridge := range bridges {
blockedIn := bl.blockedIn(bridge.Fingerprint)
foundIP := map[uint16]bool{}
for _, t := range bridge.Transports {
if !resources.ResourceMap[t.Type()].IsAddressDummy && t.Address.Invalid() {
log.Printf("Reject bridge %s transport %s as its IP is not valid: %s", t.Fingerprint, t.Type(), t.Address.String())
@@ -261,10 +267,37 @@ func reloadBridgeDescriptors(cfg *Config, rcol *core.BackendResources, testFunc
t.Distribution = bridge.Distribution
t.SetBlockedIn(blockedIn)
rcol.Add(t)
if resources.ResourceMap[t.Type()].IsAddressDummy {
foundIP[core.IPv4] = true
foundIP[core.IPv6] = true
} else {
foundIP[t.IPVer] = true
}
}
// only hand out vanilla flavour if there are no transports
if len(bridge.Transports) == 0 {
if len(bridge.Transports) != 0 {
// add IPv6/IPv4 transports from ORAddress if possible
for _, t := range bridge.Transports {
for _, ipVersion := range []uint16{core.IPv4, core.IPv6} {
if foundIP[ipVersion] {
continue
}
for _, addr := range bridge.ORAddresses {
if addr.Address.Invalid() {
continue
}
if addr.IPVersion == ipVersion {
newT := *t
newT.Address = addr.Address
newT.IPVer = addr.IPVersion
rcol.Add(&newT)
}
}
}
}
} else {
// only hand out vanilla flavour if there are no transports
if bridge.Address.Invalid() {
log.Printf("Reject vanilla bridge %s s as its IP is not valid: %s", bridge.Fingerprint, bridge.Address.String())
continue
@@ -299,9 +332,10 @@ func loadBridgesFromNetworkstatus(networkstatusFile string) (map[string]*resourc
if addr, err := net.ResolveIPAddr("", status.Address.IPv6Address.String()); err == nil {
b.Address = resources.IPAddr{IPAddr: *addr}
b.IPVer = core.IPv6
b.Port = status.Address.IPv6ORPort
oraddress := resources.ORAddress{
IPVersion: 6,
IPVersion: core.IPv6,
Port: b.Port,
Address: b.Address,
}
@@ -309,9 +343,10 @@ func loadBridgesFromNetworkstatus(networkstatusFile string) (map[string]*resourc
}
if addr, err := net.ResolveIPAddr("", status.Address.IPv4Address.String()); err == nil {
b.Address = resources.IPAddr{IPAddr: *addr}
b.IPVer = core.IPv4
b.Port = status.Address.IPv4ORPort
oraddress := resources.ORAddress{
IPVersion: 4,
IPVersion: core.IPv4,
Port: b.Port,
Address: b.Address,
}
@@ -453,6 +488,13 @@ func populateTransportInfo(transport string, t *resources.Transport) error {
return err
}
t.Address = resources.IPAddr{IPAddr: net.IPAddr{IP: addr.IP, Zone: addr.Zone}}
if resources.ResourceMap[t.Type()].IsAddressDummy {
t.IPVer = core.IPAny
} else if t.Address.IP.To4() == nil {
t.IPVer = core.IPv6
} else {
t.IPVer = core.IPv4
}
p, err := strconv.Atoi(port)
if err != nil {
return err
Loading