Skip to content

Instantly share code, notes, and snippets.

@chenchun
Last active July 30, 2018 08:17
Show Gist options
  • Save chenchun/ffb29a945203b9ea943f0f7140c22bc2 to your computer and use it in GitHub Desktop.
Save chenchun/ffb29a945203b9ea943f0f7140c22bc2 to your computer and use it in GitHub Desktop.
#hairpin mode
ip link add br0 type bridge
ip link add br1 type bridge
ip link add dev v0 type veth peer name v1
ip link set v0 master br0
ip link set v1 master br1
ip link set br0 up
ip link set br1 up
ip link set v0 up
ip link set v1 up
ip ad add 192.168.0.1/24 dev br0
[root@10 vagrant]# arping -c 1 -A -I br0 192.168.0.1
ARPING 192.168.0.1 from 192.168.0.1 br0
Sent 1 probes (1 broadcast(s))
Received 0 response(s)
[root@10 vagrant]# tcpdump -vvnneSs 0 -i v1
tcpdump: WARNING: v1: no IPv4 address assigned
tcpdump: listening on v1, link-type EN10MB (Ethernet), capture size 65535 bytes
15:52:20.866169 66:83:79:e3:a5:6c > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.1 is-at 66:83:79:e3:a5:6c, length 28
bridge link set dev v0 hairpin on
bridge link set dev v1 hairpin on
[root@10 vagrant]# bridge -d link show
15: v1 state UP @v0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br1 state forwarding priority 32 cost 2
hairpin on guard off root_block off fastleave off
16: v0 state UP @v1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 2
hairpin on guard off root_block off fastleave off
[root@10 vagrant]# arping -c 1 -A -I br0 192.168.0.1
ARPING 192.168.0.1 from 192.168.0.1 br0
Sent 1 probes (1 broadcast(s))
Received 0 response(s)
[root@10 vagrant]# tcpdump -vvnneSs 0 -i v1
tcpdump: WARNING: v1: no IPv4 address assigned
tcpdump: listening on v1, link-type EN10MB (Ethernet), capture size 65535 bytes
15:53:53.586450 66:83:79:e3:a5:6c > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.1 is-at 66:83:79:e3:a5:6c, length 28
15:53:53.586479 66:83:79:e3:a5:6c > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.1 is-at 66:83:79:e3:a5:6c, length 28
15:53:53.586489 66:83:79:e3:a5:6c > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.1 is-at 66:83:79:e3:a5:6c, length 28
15:53:53.586491 66:83:79:e3:a5:6c > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.1 is-at 66:83:79:e3:a5:6c, length 28
15:53:53.586494 66:83:79:e3:a5:6c > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.1 is-at 66:83:79:e3:a5:6c, length 28
15:53:53.586495 66:83:79:e3:a5:6c > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.1 is-at 66:83:79:e3:a5:6c, length 28
...
# hairpin mode path: /sys/devices/virtual/net/vbr65665/brif/veth_C208CC94/hairpin_mode
ip link add br0 type bridge
ip link add br1 type bridge
ip link add dev v1 type veth peer name v2
ip link add dev v3 type veth peer name v4
ip link set v1 master br0
ip link set v3 master br0
ip link set br0 up
ip link set br1 up
ip link set v1 up
ip link set v2 up
ip link set v3 up
ip link set v4 up
ip netns add ctn
ip link set v2 netns ctn
ip netns exec ctn ip link set v2 up
ip netns exec ctn ip ad add 192.168.0.2/24 dev v2
ip ad add 192.168.0.1/24 dev br0
ip netns exec ctn ip route add default via 192.168.0.1 dev v2
ip link set v4 master br1
ip netns exec ctn arping -c 1 -A -I v2 192.168.0.2
[root@10 vagrant]# tcpdump -vvnneSs 0 -i v4
tcpdump: WARNING: v4: no IPv4 address assigned
tcpdump: listening on v4, link-type EN10MB (Ethernet), capture size 65535 bytes
15:46:01.037537 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
bridge link set dev v3 hairpin on
bridge link set dev v4 hairpin on
ip netns exec ctn arping -c 1 -A -I v2 192.168.0.2
[root@10 vagrant]# tcpdump -vvnneSs 0 -i v4
tcpdump: WARNING: v4: no IPv4 address assigned
tcpdump: listening on v4, link-type EN10MB (Ethernet), capture size 65535 bytes
15:46:01.037537 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:04.079981 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:12.944624 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:12.944632 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:12.944635 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:12.944637 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:12.944640 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:12.944641 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:12.944642 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
15:47:12.944643 fa:17:2a:ad:1c:74 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Reply 192.168.0.2 is-at fa:17:2a:ad:1c:74, length 28
...
bridge link set
mcast_flood on or mcast_flood off
Controls whether a given port will be flooded with multicast
traffic for which there is no MDB entry. By default this flag
is on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment