Closed ChenMiaoQiu closed 1 month ago
看了下 2 这种写法确实会存在溢出问题,修改后写法可以解决溢出问题,不过有会出现 ip 超过网段的问题。 感觉最好还是在 1 上处理,直接初始化时把 0 和 255 位置设置为 1,根本上解决问题。
ipCount := 1 << uint8(size-one)
ipalloc := strings.Repeat("0", ipCount-2) // 减去 0和 255这俩个不可分配地址,所有可分配的 IP 地址
// 初始化分配配置,标记 .0 和 .255 位置为不可分配,直接置为 1
(*ipam.Subnets)[subnet.String()] = fmt.Sprintf("1%s1", ipalloc)
network/ipam.go
1
此处可用ip数是否需要变更为
自动扣除网关和广播地址
2
此处代码是否要修改为
不应该直接在ip[3]处+1,如果计算出的ip[3]为255,+1的话ip[3]会变为0 例:172.16.0.0/12 数组序号为255
输出为
修改后
输出为