From b1c5892b87a5161014b40332ce019e78ee41ba0c Mon Sep 17 00:00:00 2001 From: Jason-ZW Date: Sat, 17 Nov 2018 00:29:41 +0800 Subject: [PATCH] Change dhcpcd master node startup function --- pkg/netconf/netconf_linux.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/netconf/netconf_linux.go b/pkg/netconf/netconf_linux.go index 1f4c4316..5bbe9ea4 100644 --- a/pkg/netconf/netconf_linux.go +++ b/pkg/netconf/netconf_linux.go @@ -24,10 +24,11 @@ const ( ) var ( - defaultDhcpArgs = []string{"dhcpcd", "-MA4"} - exitDhcpArgs = []string{"dhcpcd", "-x"} - exitWpaArgs = []string{"wpa_cli", "terminate"} - dhcpReleaseCmd = "dhcpcd --release" + defaultDhcpArgs = []string{"dhcpcd", "-MA4"} + inactiveDhcpArgs = []string{"dhcpcd", "-MA4", "--inactive"} + exitDhcpArgs = []string{"dhcpcd", "-x"} + exitWpaArgs = []string{"wpa_cli", "terminate"} + dhcpReleaseCmd = "dhcpcd --release" ) func createInterfaces(netCfg *NetworkConfig) { @@ -178,7 +179,12 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool wg := sync.WaitGroup{} - //apply network config + // Don't start any interfaces other than those specified on the command line. + // This allows dhcpcd to be started in Master mode. + // Then wait for subsequent dhcpcd commands to start each interface as required. + runInactiveDhcp() + + // apply network config for _, link := range links { applyOuter(link, netCfg, &wg, userSetHostname, userSetDNS) } @@ -282,6 +288,15 @@ func hasDhcp(iface string) bool { return len(out) > 0 } +func runInactiveDhcp() { + cmd := exec.Command(inactiveDhcpArgs[0], inactiveDhcpArgs[1:]...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + log.Errorf("Failed to run command [%v]: %v", cmd, err) + } +} + func runDhcp(netCfg *NetworkConfig, iface string, argstr string, setHostname, setDNS bool) { args := []string{} if argstr != "" {