1
0
mirror of https://github.com/rancher/os.git synced 2025-08-05 08:50:09 +00:00

Change dhcpcd master node startup function

This commit is contained in:
Jason-ZW 2018-11-17 00:29:41 +08:00 committed by niusmallnan
parent 200cf7111a
commit b1c5892b87

View File

@ -25,6 +25,7 @@ const (
var ( var (
defaultDhcpArgs = []string{"dhcpcd", "-MA4"} defaultDhcpArgs = []string{"dhcpcd", "-MA4"}
inactiveDhcpArgs = []string{"dhcpcd", "-MA4", "--inactive"}
exitDhcpArgs = []string{"dhcpcd", "-x"} exitDhcpArgs = []string{"dhcpcd", "-x"}
exitWpaArgs = []string{"wpa_cli", "terminate"} exitWpaArgs = []string{"wpa_cli", "terminate"}
dhcpReleaseCmd = "dhcpcd --release" dhcpReleaseCmd = "dhcpcd --release"
@ -178,6 +179,11 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
// 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 // apply network config
for _, link := range links { for _, link := range links {
applyOuter(link, netCfg, &wg, userSetHostname, userSetDNS) applyOuter(link, netCfg, &wg, userSetHostname, userSetDNS)
@ -282,6 +288,15 @@ func hasDhcp(iface string) bool {
return len(out) > 0 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) { func runDhcp(netCfg *NetworkConfig, iface string, argstr string, setHostname, setDNS bool) {
args := []string{} args := []string{}
if argstr != "" { if argstr != "" {