Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Detect enabling of hairpin mode on vethwe-bridge
Browse files Browse the repository at this point in the history
Enabled hairpin mode on vethwe-bridge was one of the root causes
for installing looping flows in the fastdp mode.

Also, it confused the weave custom L2 bridge, as the bridge treats
a bounced back packet, e.g. ARP brodcast request, as a local one
(the case for "Captured a packet associated with remote host").
  • Loading branch information
brb committed Dec 5, 2016
1 parent 2984e08 commit e5cf022
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
29 changes: 29 additions & 0 deletions net/bridge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net

import (
"github.com/Sirupsen/logrus"
"github.com/vishvananda/netlink"
)

Expand Down Expand Up @@ -51,3 +52,31 @@ func isDatapath(link netlink.Link) bool {
return false
}
}

func DetectHairpin(portIfName string, log *logrus.Logger) {
link, err := netlink.LinkByName(portIfName)
if err != nil {
log.Errorf("Unable to find link %q: %s", portIfName, err)
}

ch := make(chan netlink.LinkUpdate)
// See EnsureInterface for why done channel is not passed
if err := netlink.LinkSubscribe(ch, nil); err != nil {
log.Errorf("Unable to subscribe to netlink updates: %s", err)
}

pi, err := netlink.LinkGetProtinfo(link)
if err != nil {
log.Errorf("Unable to get link protinfo %q: %s", portIfName, err)
}
if pi.Hairpin {
log.Errorf("Hairpin mode enabled on %q", portIfName)
}

for up := range ch {
if up.Attrs().Name == portIfName && up.Attrs().Protinfo != nil &&
up.Attrs().Protinfo.Hairpin {
log.Errorf("Hairpin mode enabled on %q", portIfName)
}
}
}
4 changes: 4 additions & 0 deletions prog/weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ func main() {
overlay, bridge := createOverlay(datapathName, ifaceName, isAWSVPC, config.Host, config.Port, bufSzMB)
networkConfig.Bridge = bridge

if bridge != nil {
go weavenet.DetectHairpin("vethwe-bridge", Log)
}

name := peerName(routerName, bridge.Interface())

if nickName == "" {
Expand Down
12 changes: 12 additions & 0 deletions test/705_detect_hairpin_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash

. ./config.sh

start_suite "Detect hairpin mode"

weave_on $HOST1 launch

assert_raises "run_on $HOST1 sudo ip link set vethwe-bridge type bridge_slave hairpin on"
assert_raises "docker_on $HOST1 logs weave 2>&1 | grep -q 'Hairpin mode enabled on \"vethwe-bridge\"'"

end_suite

0 comments on commit e5cf022

Please sign in to comment.