mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
feat: add CIDR support for ip setting (#43223)
issue: #26538 --------- Signed-off-by: yusheng.ma <yusheng.ma@zilliz.com> Signed-off-by: yusheng.ma <yushengma@bytedance.com> Co-authored-by: yusheng.ma <yushengma@bytedance.com>
This commit is contained in:
parent
77f2fb562f
commit
ebd517c514
@ -59,6 +59,22 @@ func GetIP(ip string) string {
|
|||||||
if len(ip) == 0 {
|
if len(ip) == 0 {
|
||||||
return GetLocalIP()
|
return GetLocalIP()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Support setting CIDR in the IP field to match interfaces based on CIDR. For example: 192.168.0.0/16
|
||||||
|
_, ipnet, err := net.ParseCIDR(ip)
|
||||||
|
if err == nil {
|
||||||
|
addrs, err := net.InterfaceAddrs()
|
||||||
|
if err == nil {
|
||||||
|
for _, addr := range addrs {
|
||||||
|
addrip, ok := addr.(*net.IPNet)
|
||||||
|
if ok && ipnet.Contains(addrip.IP) {
|
||||||
|
return addrip.IP.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic(errors.New(`Network port does not have an IP address that falls within the given CIDR range`))
|
||||||
|
}
|
||||||
|
|
||||||
netIP := net.ParseIP(ip)
|
netIP := net.ParseIP(ip)
|
||||||
// not a valid ip addr
|
// not a valid ip addr
|
||||||
if netIP == nil {
|
if netIP == nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user