check and set promiscuous mode with netlink because vishvananda/netlink already supports it
This commit is contained in:
		@@ -334,20 +334,18 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Put the container bridge into promiscuous mode to force it to accept hairpin packets.
 | 
						// Put the container bridge into promiscuous mode to force it to accept hairpin packets.
 | 
				
			||||||
	// TODO: Remove this once the kernel bug (#20096) is fixed.
 | 
						// TODO: Remove this once the kernel bug (#20096) is fixed.
 | 
				
			||||||
	// TODO: check and set promiscuous mode with netlink once vishvananda/netlink supports it
 | 
					 | 
				
			||||||
	if plugin.hairpinMode == kubeletconfig.PromiscuousBridge {
 | 
						if plugin.hairpinMode == kubeletconfig.PromiscuousBridge {
 | 
				
			||||||
		output, err := plugin.execer.Command("ip", "link", "show", "dev", BridgeName).CombinedOutput()
 | 
					 | 
				
			||||||
		if err != nil || strings.Index(string(output), "PROMISC") < 0 {
 | 
					 | 
				
			||||||
			_, err := plugin.execer.Command("ip", "link", "set", BridgeName, "promisc", "on").CombinedOutput()
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return fmt.Errorf("Error setting promiscuous mode on %s: %v", BridgeName, err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		link, err := netlink.LinkByName(BridgeName)
 | 
							link, err := netlink.LinkByName(BridgeName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return fmt.Errorf("failed to lookup %q: %v", BridgeName, err)
 | 
								return fmt.Errorf("failed to lookup %q: %v", BridgeName, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if link.Attrs().Promisc != 1 {
 | 
				
			||||||
 | 
								// promiscuous mode is not on, then turn it on.
 | 
				
			||||||
 | 
								err := netlink.SetPromiscOn(link)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return fmt.Errorf("Error setting promiscuous mode on %s: %v", BridgeName, err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// configure the ebtables rules to eliminate duplicate packets by best effort
 | 
							// configure the ebtables rules to eliminate duplicate packets by best effort
 | 
				
			||||||
		plugin.syncEbtablesDedupRules(link.Attrs().HardwareAddr)
 | 
							plugin.syncEbtablesDedupRules(link.Attrs().HardwareAddr)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user