1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

fix json parser for IPv6 routing

This commit is contained in:
Darien Raymond 2016-10-18 11:36:45 +02:00
parent 4e80ed05d9
commit b3bbd80674
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -60,25 +60,45 @@ func parseIP(s string) *router.IP {
mask = s[i+1:]
}
ip := v2net.ParseAddress(addr)
if !ip.Family().Either(v2net.AddressFamilyIPv4, v2net.AddressFamilyIPv6) {
return nil
}
bits := uint32(32)
if len(mask) > 0 {
bits64, err := strconv.ParseUint(mask, 10, 32)
if err != nil {
switch ip.Family() {
case v2net.AddressFamilyIPv4:
bits := uint32(32)
if len(mask) > 0 {
bits64, err := strconv.ParseUint(mask, 10, 32)
if err != nil {
return nil
}
bits = uint32(bits64)
}
if bits > 32 {
log.Warning("Router: invalid network mask: ", bits)
return nil
}
bits = uint32(bits64)
}
if bits > 32 {
log.Warning("Router: invalid network mask: ", bits)
return &router.IP{
Ip: []byte(ip.IP()),
UnmatchingBits: 32 - bits,
}
case v2net.AddressFamilyIPv6:
bits := uint32(128)
if len(mask) > 0 {
bits64, err := strconv.ParseUint(mask, 10, 32)
if err != nil {
return nil
}
bits = uint32(bits64)
}
if bits > 128 {
log.Warning("Router: invalid network mask: ", bits)
return nil
}
return &router.IP{
Ip: []byte(ip.IP()),
UnmatchingBits: 128 - bits,
}
default:
log.Warning("Router: unsupported address: ", s)
return nil
}
return &router.IP{
Ip: []byte(ip.IP()),
UnmatchingBits: 32 - bits,
}
}
func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {