Wait for ethwe via netlink, not via polling or signals
('docker kill' breaks restart policy)
This commit is contained in:
1 parent
42b64f826b
commit
6e89b036e2
5 files changed
+47
-39
No files matched your search
@@ -74,7 +74,8 @@ $(NETCHECK_EXE): prog/netcheck/netcheck.go
|
|||||||
# Sigproxy and weavewait need separate rules as they fail the netgo check in
|
# Sigproxy and weavewait need separate rules as they fail the netgo check in
|
||||||
# the main build stanza due to not importing net package
|
# the main build stanza due to not importing net package
|
||||||
$(SIGPROXY_EXE): prog/sigproxy/main.go
|
$(SIGPROXY_EXE): prog/sigproxy/main.go
|
||||||
$(WEAVEWAIT_EXE): prog/weavewait/main.go
|
$(WEAVEWAIT_EXE): prog/weavewait/main.go net/*.go
|
||||||
|
$(WEAVEHOSTS_EXE): prog/weavehosts/weavehosts.go
|
||||||
$(COVER_EXE): testing/cover/cover.go
|
$(COVER_EXE): testing/cover/cover.go
|
||||||
$(RUNNER_EXE): testing/runner/runner.go
|
$(RUNNER_EXE): testing/runner/runner.go
|
||||||
|
|
||||||
|
|||||||
@@ -2,30 +2,24 @@ package net
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/vishvananda/netlink/nl"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// Wait for an interface to come up.
|
||||||
sleepTime = 100 * time.Millisecond
|
func EnsureInterface(ifaceName string) (*net.Interface, error) {
|
||||||
)
|
s, err := nl.Subscribe(syscall.NETLINK_ROUTE, syscall.RTNLGRP_LINK)
|
||||||
|
if err != nil {
|
||||||
// Wait `wait` seconds for an interface to come up. Pass zero to check once
|
return nil, err
|
||||||
// and return immediately, or a negative value to wait indefinitely.
|
|
||||||
func EnsureInterface(ifaceName string, wait int) (iface *net.Interface, err error) {
|
|
||||||
if iface, err = findInterface(ifaceName); err == nil || wait == 0 {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
i := int64(math.MaxInt64)
|
defer s.Close()
|
||||||
if wait > 0 {
|
if iface, err := findInterface(ifaceName); err == nil {
|
||||||
i = int64(time.Duration(wait) * time.Second / sleepTime)
|
return iface, nil
|
||||||
}
|
}
|
||||||
for ; err != nil && i > 0; i-- {
|
waitForIfUp(s, ifaceName)
|
||||||
time.Sleep(sleepTime)
|
return findInterface(ifaceName)
|
||||||
iface, err = findInterface(ifaceName)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findInterface(ifaceName string) (iface *net.Interface, err error) {
|
func findInterface(ifaceName string) (iface *net.Interface, err error) {
|
||||||
@@ -37,3 +31,31 @@ func findInterface(ifaceName string) (iface *net.Interface, err error) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func waitForIfUp(s *nl.NetlinkSocket, ifaceName string) error {
|
||||||
|
for {
|
||||||
|
msgs, err := s.Receive()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, m := range msgs {
|
||||||
|
switch m.Header.Type {
|
||||||
|
case syscall.RTM_NEWLINK: // receive this type for link 'up'
|
||||||
|
ifmsg := nl.DeserializeIfInfomsg(m.Data)
|
||||||
|
attrs, err := syscall.ParseNetlinkRouteAttr(&m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
name := ""
|
||||||
|
for _, attr := range attrs {
|
||||||
|
if attr.Attr.Type == syscall.IFA_LABEL {
|
||||||
|
name = string(attr.Value[:len(attr.Value)-1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ifaceName == name && ifmsg.Flags&syscall.IFF_UP != 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-3
@@ -43,7 +43,6 @@ func main() {
|
|||||||
routerName string
|
routerName string
|
||||||
nickName string
|
nickName string
|
||||||
password string
|
password string
|
||||||
wait int
|
|
||||||
pktdebug bool
|
pktdebug bool
|
||||||
logLevel string
|
logLevel string
|
||||||
prof string
|
prof string
|
||||||
@@ -71,7 +70,6 @@ func main() {
|
|||||||
mflag.StringVar(&routerName, []string{"#name", "-name"}, "", "name of router (defaults to MAC of interface)")
|
mflag.StringVar(&routerName, []string{"#name", "-name"}, "", "name of router (defaults to MAC of interface)")
|
||||||
mflag.StringVar(&nickName, []string{"#nickname", "-nickname"}, "", "nickname of peer (defaults to hostname)")
|
mflag.StringVar(&nickName, []string{"#nickname", "-nickname"}, "", "nickname of peer (defaults to hostname)")
|
||||||
mflag.StringVar(&password, []string{"#password", "-password"}, "", "network password")
|
mflag.StringVar(&password, []string{"#password", "-password"}, "", "network password")
|
||||||
mflag.IntVar(&wait, []string{"#wait", "-wait"}, -1, "number of seconds to wait for interface to come up (0=don't wait, -1=wait forever)")
|
|
||||||
mflag.StringVar(&logLevel, []string{"-log-level"}, "info", "logging level (debug, info, warning, error)")
|
mflag.StringVar(&logLevel, []string{"-log-level"}, "info", "logging level (debug, info, warning, error)")
|
||||||
mflag.BoolVar(&pktdebug, []string{"#pktdebug", "#-pktdebug", "-pkt-debug"}, false, "enable per-packet debug logging")
|
mflag.BoolVar(&pktdebug, []string{"#pktdebug", "#-pktdebug", "-pkt-debug"}, false, "enable per-packet debug logging")
|
||||||
mflag.StringVar(&prof, []string{"#profile", "-profile"}, "", "enable profiling and write profiles to given path")
|
mflag.StringVar(&prof, []string{"#profile", "-profile"}, "", "enable profiling and write profiles to given path")
|
||||||
@@ -118,7 +116,7 @@ func main() {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
if ifaceName != "" {
|
if ifaceName != "" {
|
||||||
config.Iface, err = weavenet.EnsureInterface(ifaceName, wait)
|
config.Iface, err = weavenet.EnsureInterface(ifaceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Fatal(err)
|
Log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-15
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
weavenet "github.com/weaveworks/weave/net"
|
weavenet "github.com/weaveworks/weave/net"
|
||||||
@@ -17,22 +16,10 @@ var (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
args = os.Args[1:]
|
args = os.Args[1:]
|
||||||
notInExec = true
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(args) > 0 && args[0] == "-s" {
|
_, err := weavenet.EnsureInterface("ethwe")
|
||||||
notInExec = false
|
|
||||||
args = args[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
if notInExec {
|
|
||||||
usr2 := make(chan os.Signal)
|
|
||||||
signal.Notify(usr2, syscall.SIGUSR2)
|
|
||||||
<-usr2
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := weavenet.EnsureInterface("ethwe", -1)
|
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error {
|
|||||||
Log.Infof("Leaving container %s alone because %s", container.ID, err)
|
Log.Infof("Leaving container %s alone because %s", container.ID, err)
|
||||||
} else if hasWeaveWait {
|
} else if hasWeaveWait {
|
||||||
Log.Infof("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " "))
|
Log.Infof("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " "))
|
||||||
cmd := append(weaveWaitEntrypoint, "-s")
|
cmd := weaveWaitEntrypoint
|
||||||
options.Cmd = append(cmd, options.Cmd...)
|
options.Cmd = append(cmd, options.Cmd...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user