1
0
mirror of https://github.com/rancher/os.git synced 2025-08-01 15:08:47 +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

@ -24,10 +24,11 @@ const (
) )
var ( var (
defaultDhcpArgs = []string{"dhcpcd", "-MA4"} defaultDhcpArgs = []string{"dhcpcd", "-MA4"}
exitDhcpArgs = []string{"dhcpcd", "-x"} inactiveDhcpArgs = []string{"dhcpcd", "-MA4", "--inactive"}
exitWpaArgs = []string{"wpa_cli", "terminate"} exitDhcpArgs = []string{"dhcpcd", "-x"}
dhcpReleaseCmd = "dhcpcd --release" exitWpaArgs = []string{"wpa_cli", "terminate"}
dhcpReleaseCmd = "dhcpcd --release"
) )
func createInterfaces(netCfg *NetworkConfig) { func createInterfaces(netCfg *NetworkConfig) {
@ -178,7 +179,12 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool
wg := sync.WaitGroup{} 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 { 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 != "" {