@@ -33,6 +33,7 @@ type Subnet struct {
3333 PodToNicList map [string ][]string
3434 V4Gw string
3535 V6Gw string
36+ GatewayMAC string
3637}
3738
3839func NewSubnet (name , cidrStr string , excludeIps []string ) (* Subnet , error ) {
@@ -72,6 +73,7 @@ func NewSubnet(name, cidrStr string, excludeIps []string) (*Subnet, error) {
7273 MacToPod : map [string ]string {},
7374 NicToMac : map [string ]string {},
7475 PodToNicList : map [string ][]string {},
76+ GatewayMAC : "" ,
7577 }
7678 subnet .joinFreeWithReserve ()
7779 } else if protocol == kubeovnv1 .ProtocolIPv6 {
@@ -93,6 +95,7 @@ func NewSubnet(name, cidrStr string, excludeIps []string) (*Subnet, error) {
9395 MacToPod : map [string ]string {},
9496 NicToMac : map [string ]string {},
9597 PodToNicList : map [string ][]string {},
98+ GatewayMAC : "" ,
9699 }
97100 subnet .joinFreeWithReserve ()
98101 } else {
@@ -121,6 +124,7 @@ func NewSubnet(name, cidrStr string, excludeIps []string) (*Subnet, error) {
121124 MacToPod : map [string ]string {},
122125 NicToMac : map [string ]string {},
123126 PodToNicList : map [string ][]string {},
127+ GatewayMAC : "" ,
124128 }
125129 subnet .joinFreeWithReserve ()
126130 }
@@ -132,7 +136,7 @@ func (subnet *Subnet) GetRandomMac(podName, nicName string) string {
132136 return mac
133137 }
134138 for {
135- mac := util .GenerateMac ( )
139+ mac := util .GenerateMacWithExclusion ([] string { subnet . GatewayMAC } )
136140 if _ , ok := subnet .MacToPod [mac ]; ! ok {
137141 subnet .MacToPod [mac ] = podName
138142 subnet .NicToMac [nicName ] = mac
@@ -142,6 +146,11 @@ func (subnet *Subnet) GetRandomMac(podName, nicName string) string {
142146}
143147
144148func (subnet * Subnet ) GetStaticMac (podName , nicName , mac string , checkConflict bool ) error {
149+ if subnet .GatewayMAC != "" && mac == subnet .GatewayMAC {
150+ klog .Errorf ("mac %s conflicts with gateway MAC %s" , mac , subnet .GatewayMAC )
151+ return ErrConflict
152+ }
153+
145154 if checkConflict {
146155 if p , ok := subnet .MacToPod [mac ]; ok && p != podName {
147156 klog .Errorf ("mac %s has been allocated to pod %s" , mac , p )
0 commit comments