Commit 4734c0db authored by Yang Bo's avatar Yang Bo Committed by GitHub

weight for SRV records should be at least 1 (#3931)

Automatically submitted.
parent 86df1282
...@@ -185,6 +185,10 @@ func SRV(ctx context.Context, b ServiceBackend, zone string, state request.Reque ...@@ -185,6 +185,10 @@ func SRV(ctx context.Context, b ServiceBackend, zone string, state request.Reque
w1 *= float64(serv.Weight) w1 *= float64(serv.Weight)
} }
weight := uint16(math.Floor(w1)) weight := uint16(math.Floor(w1))
// weight should be at least 1
if weight == 0 {
weight = 1
}
what, ip := serv.HostType() what, ip := serv.HostType()
......
...@@ -103,6 +103,10 @@ func (e *External) srv(services []msg.Service, state request.Request) (records, ...@@ -103,6 +103,10 @@ func (e *External) srv(services []msg.Service, state request.Request) (records,
w1 *= float64(s.Weight) w1 *= float64(s.Weight)
} }
weight := uint16(math.Floor(w1)) weight := uint16(math.Floor(w1))
// weight should be at least 1
if weight == 0 {
weight = 1
}
what, ip := s.HostType() what, ip := s.HostType()
......
...@@ -228,6 +228,11 @@ func calcSRVWeight(numservices int) uint16 { ...@@ -228,6 +228,11 @@ func calcSRVWeight(numservices int) uint16 {
} }
w[serv.Priority] += weight w[serv.Priority] += weight
} }
weight := uint16(math.Floor((100.0 / float64(w[0])) * 100))
// weight should be at least 1
if weight == 0 {
weight = 1
}
return uint16(math.Floor((100.0 / float64(w[0])) * 100)) return weight
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment