Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save goldmann/8520622 to your computer and use it in GitHub Desktop.
Save goldmann/8520622 to your computer and use it in GitHub Desktop.
From c4e29cd30fb6b23e5589a7e08dcf2fe3f7041c61 Mon Sep 17 00:00:00 2001
From: Marek Goldmann <marek.goldmann@gmail.com>
Date: Sat, 18 Jan 2014 18:48:53 +0100
Subject: [PATCH] Find if the IP is already used
---
network.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/network.go b/network.go
index 22ea8ba..d4cbabd 100644
--- a/network.go
+++ b/network.go
@@ -10,6 +10,7 @@ import (
"github.com/dotcloud/docker/utils"
"log"
"net"
+ "os/exec"
"strconv"
"sync"
"syscall"
@@ -466,8 +467,14 @@ func (alloc *IPAllocator) run() {
}
if _, inUse = alloc.inUse[newNum]; !inUse {
- // We found an unused IP
- break
+ _, err := exec.Command("arping", "-f", "-c", "1", "-q", "-I", "docker0", intToIP(newNum).String()).Output()
+ if err != nil {
+ // We found an unused IP
+ break
+ } else {
+ // Address is already used by some other host on network
+ continue
+ }
}
}
--
1.8.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment