@@ -23,7 +23,6 @@ import (
23
23
"io/ioutil"
24
24
"net"
25
25
"path/filepath"
26
- "strconv"
27
26
"strings"
28
27
"sync"
29
28
"syscall"
@@ -58,12 +57,6 @@ const (
58
57
// fallbackMTU is used if an MTU is not specified, and we cannot determine the MTU
59
58
fallbackMTU = 1460
60
59
61
- // private mac prefix safe to use
62
- // Universally administered and locally administered addresses are distinguished by setting the second-least-significant
63
- // bit of the first octet of the address. If it is 1, the address is locally administered. For example, for address 0a:00:00:00:00:00,
64
- // the first cotet is 0a(hex), the binary form of which is 00001010, where the second-least-significant bit is 1.
65
- privateMACPrefix = "0a:58"
66
-
67
60
// ebtables Chain to store dedup rules
68
61
dedupChain = utilebtables .Chain ("KUBE-DEDUP" )
69
62
@@ -326,22 +319,6 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
326
319
return fmt .Errorf ("CNI plugin reported an invalid IPv4 address for container %v: %+v." , id , res .IP4 )
327
320
}
328
321
329
- // Explicitly assign mac address to cbr0. If bridge mac address is not explicitly set will adopt the lowest MAC address of the attached veths.
330
- // TODO: Remove this once upstream cni bridge plugin handles this
331
- link , err := netlink .LinkByName (BridgeName )
332
- if err != nil {
333
- return fmt .Errorf ("failed to lookup %q: %v" , BridgeName , err )
334
- }
335
- macAddr , err := generateHardwareAddr (plugin .gateway )
336
- if err != nil {
337
- return err
338
- }
339
- glog .V (3 ).Infof ("Configure %q mac address to %v" , BridgeName , macAddr )
340
- err = netlink .LinkSetHardwareAddr (link , macAddr )
341
- if err != nil {
342
- return fmt .Errorf ("Failed to configure %q mac address to %q: %v" , BridgeName , macAddr , err )
343
- }
344
-
345
322
// Put the container bridge into promiscuous mode to force it to accept hairpin packets.
346
323
// TODO: Remove this once the kernel bug (#20096) is fixed.
347
324
// TODO: check and set promiscuous mode with netlink once vishvananda/netlink supports it
@@ -353,8 +330,14 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
353
330
return fmt .Errorf ("Error setting promiscuous mode on %s: %v" , BridgeName , err )
354
331
}
355
332
}
333
+
334
+ link , err := netlink .LinkByName (BridgeName )
335
+ if err != nil {
336
+ return fmt .Errorf ("failed to lookup %q: %v" , BridgeName , err )
337
+ }
338
+
356
339
// configure the ebtables rules to eliminate duplicate packets by best effort
357
- plugin .syncEbtablesDedupRules (macAddr )
340
+ plugin .syncEbtablesDedupRules (link . Attrs (). HardwareAddr )
358
341
}
359
342
360
343
plugin .podIPs [id ] = ip4 .String ()
@@ -845,21 +828,3 @@ func (plugin *kubenetNetworkPlugin) syncEbtablesDedupRules(macAddr net.HardwareA
845
828
return
846
829
}
847
830
}
848
-
849
- // generateHardwareAddr generates 48 bit virtual mac addresses based on the IP input.
850
- func generateHardwareAddr (ip net.IP ) (net.HardwareAddr , error ) {
851
- if ip .To4 () == nil {
852
- return nil , fmt .Errorf ("generateHardwareAddr only support valid ipv4 address as input" )
853
- }
854
- mac := privateMACPrefix
855
- sections := strings .Split (ip .String (), "." )
856
- for _ , s := range sections {
857
- i , _ := strconv .Atoi (s )
858
- mac = mac + ":" + fmt .Sprintf ("%02x" , i )
859
- }
860
- hwAddr , err := net .ParseMAC (mac )
861
- if err != nil {
862
- return nil , fmt .Errorf ("Failed to parse mac address %s generated based on ip %s due to: %v" , mac , ip , err )
863
- }
864
- return hwAddr , nil
865
- }
0 commit comments