mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
Merge pull request #2368 from zacheryph/qemu-save-mac
save mac address within state for qemu
This commit is contained in:
commit
cb254bf8be
@ -86,6 +86,25 @@ func envOverrideBool(env string, b *bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func retrieveMAC(statePath string) net.HardwareAddr {
|
||||
var mac net.HardwareAddr
|
||||
fileName := filepath.Join(statePath, "mac-addr")
|
||||
|
||||
if macString, err := ioutil.ReadFile(fileName); err == nil {
|
||||
if mac, err = net.ParseMAC(string(macString)); err != nil {
|
||||
log.Fatal("failed to parse mac-addr file: %s\n", macString)
|
||||
}
|
||||
} else {
|
||||
// we did not generate a mac yet. generate one
|
||||
mac = generateMAC()
|
||||
if err = ioutil.WriteFile(fileName, []byte(mac.String()), 0640); err != nil {
|
||||
log.Fatalln("failed to write mac-addr file:", err)
|
||||
}
|
||||
}
|
||||
|
||||
return mac
|
||||
}
|
||||
|
||||
func generateMAC() net.HardwareAddr {
|
||||
mac := make([]byte, 6)
|
||||
n, err := rand.Read(mac)
|
||||
@ -538,7 +557,7 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
|
||||
if config.NetdevConfig == "" {
|
||||
qemuArgs = append(qemuArgs, "-net", "none")
|
||||
} else {
|
||||
mac := generateMAC()
|
||||
mac := retrieveMAC(config.StatePath)
|
||||
qemuArgs = append(qemuArgs, "-net", "nic,model=virtio,macaddr="+mac.String())
|
||||
forwardings, err := buildQemuForwardings(config.PublishedPorts, config.Containerized)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user