Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] The Probability of Duplicate MAC Addresses #4001

Closed
wolgod opened this issue May 10, 2024 · 7 comments · Fixed by #4095
Closed

[BUG] The Probability of Duplicate MAC Addresses #4001

wolgod opened this issue May 10, 2024 · 7 comments · Fixed by #4095
Labels
bug Something isn't working

Comments

@wolgod
Copy link

wolgod commented May 10, 2024

Kube-OVN Version

1.11.9

Kubernetes Version

1.20.1

Operation-system/Kernel Version

"CentOS Linux 7 (Core)"
5.4.231-1.el7.elrepo.x86_64

Description

func GenerateMac() string {
	prefix := "00:00:00"
	b := make([]byte, 3)
	_, err := rand.Read(b)
	if err != nil {
		klog.Errorf("generate mac error: %v", err)
	}

	mac := fmt.Sprintf("%s:%02X:%02X:%02X", prefix, b[0], b[1], b[2])
	return mac
} 

如果集群里频繁创建pod,mac地址存在重复的可能,在underlay网络下会存在问题

Steps To Reproduce

在集群中发现不同的pod的mac地址出现重复

Current Behavior

mac地址出现重复

Expected Behavior

mac地址不重复

@wolgod wolgod added the bug Something isn't working label May 10, 2024
@wolgod wolgod changed the title [BUG] mac may gennic [BUG] The Probability of Duplicate MAC Addresses May 10, 2024
@oilbeater
Copy link
Collaborator

理论上冲突的概率是 1/(256256256) 实在大概什么样的规模下发现冲突的

@wolgod
Copy link
Author

wolgod commented May 28, 2024

理论上冲突的概率是 1/(256_256_256) 实在大概什么样的规模下发现冲突的

500台node节点,有10台机器作为jenkins的salve起动态pod,发现好几次其他业务的pod已经申请了该mac,但是jenkins起的pod也申请了该mac,交换机处理就有问题然后就会影响其他业务正在运行的pod

@wolgod
Copy link
Author

wolgod commented May 28, 2024

从概率上来看出现重复概率还挺高’
企业微信截图_9fbc9f40-dc60-4d27-90c5-18d3827d296a

企业微信截图_78cd7c33-c3c8-448e-beb6-054484343a6d

这个如果改成除了第一个00,后面的都随机应该可行吧

@oilbeater
Copy link
Collaborator

如果是这样我倾向于直接在 mac 里嵌入 IP 这样在 IPv4 的情况下至少可以保证绝对的不冲突

@oilbeater
Copy link
Collaborator

参考了下 cilium 的实现 https://github.com/cilium/cilium/blob/8c7e442ccd48b9011a10f34a128ec98751d9a80e/pkg/mac/mac.go#L106 这应该是最大随机化的做法了

@oilbeater oilbeater mentioned this issue May 28, 2024
1 task
@wolgod
Copy link
Author

wolgod commented May 28, 2024

参考了下 cilium 的实现 https://github.com/cilium/cilium/blob/8c7e442ccd48b9011a10f34a128ec98751d9a80e/pkg/mac/mac.go#L106 这应该是最大随机化的做法了

看代码这个实现和已有的实现里把6字节改成全随机没啥大的区别吧

@oilbeater
Copy link
Collaborator

主要是第一个字节最后两位需要特殊设置,不然可能变成组播的 mac 地址。这个实现应该可以指数级下降冲突概率了,ipv6 的地址范围可能会比 mac 地址还大,也不能直接用 ip 来生成 mac 还是先只能用这种随机算法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants