Add ipfilter to exclude ip from candidates gather (#1052)
This commit is contained in:
@@ -227,6 +227,49 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
|
||||
})
|
||||
}
|
||||
|
||||
if len(rtcConf.IPs.Includes) != 0 || len(rtcConf.IPs.Excludes) != 0 {
|
||||
var ipnets [2][]*net.IPNet
|
||||
for i, ips := range [][]string{rtcConf.IPs.Includes, rtcConf.IPs.Excludes} {
|
||||
ipnets[i], err = func(fromIPs []string) ([]*net.IPNet, error) {
|
||||
var toNets []*net.IPNet
|
||||
for _, ip := range fromIPs {
|
||||
_, ipnet, err := net.ParseCIDR(ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
toNets = append(toNets, ipnet)
|
||||
}
|
||||
return toNets, nil
|
||||
}(ips)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
includes, excludes := ipnets[0], ipnets[1]
|
||||
|
||||
s.SetIPFilter(func(ip net.IP) bool {
|
||||
if len(includes) > 0 {
|
||||
for _, ipn := range includes {
|
||||
if ipn.Contains(ip) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if len(excludes) > 0 {
|
||||
for _, ipn := range excludes {
|
||||
if ipn.Contains(ip) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
return &WebRTCConfig{
|
||||
Configuration: c,
|
||||
SettingEngine: s,
|
||||
|
||||
Reference in New Issue
Block a user