-
Notifications
You must be signed in to change notification settings - Fork 13
/
common-br.sh
99 lines (81 loc) · 2.41 KB
/
common-br.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
function no_output() {
local a=`$@ 2>&1`
[ -n "$a" ] && err $a && return 1
return 0
}
function create_bridge_with_interfaces() {
local bridge_name=$1
local i
shift
ip link del name $bridge_name type bridge 2>/dev/null
ip link add name $bridge_name type bridge
iptables -A FORWARD -i $bridge_name -j ACCEPT
for i in $@; do
no_output ip link set $i master $bridge_name
done
ip link set $bridge_name up
ip link set name $bridge_name type bridge ageing_time 400
}
function create_bridge_with_mcast() {
sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=0 >/dev/null
create_bridge_with_interfaces "$@"
ip link set name $1 type bridge mcast_querier 1 mcast_startup_query_count 10
local i
shift
for i in $@; do
bridge link set dev $i mcast_flood off
done
}
function flush_bridge() {
local bridge_name=$1
ip link set $bridge_name type bridge fdb_flush
}
function verify_ping_ns() {
local ns=$1
local from_dev=$2
local dump_dev=$3
local dst_ip=$4
local t=$5
local npackets=$6
local filter=${7:-icmp}
echo "sniff packets on $dump_dev"
timeout $((t+1)) tcpdump -qnnei $dump_dev -c $npackets ${filter} &
local tpid=$!
sleep 0.5
echo "run ping for $t seconds"
ip netns exec $ns ping -I $from_dev $dst_ip -c $t -w $t -q && success || err "Ping failed"
verify_no_traffic $tpid
}
function verify_ping_ns_mcast() {
local ns=$1
local from_dev=$2
local dump_dev=$3
local dst_ip=$4
local t=$5
local ndupes=$6
local npackets=$7
local filter=${8:-icmp}
echo "sniff packets on $dump_dev"
timeout $((t+1)) tcpdump -qnnei $dump_dev -c $npackets ${filter} &
local tpid=$!
sleep 0.5
echo "run ping for $t seconds"
ip netns exec $ns ping -I $from_dev $dst_ip -c $t -w $t | grep "+$ndupes duplicates" && success || err "Multicast ping failed"
verify_no_traffic $tpid
}
function verify_ping_remote_mcast() {
local from_dev=$1
local dump_dev=$2
local dst_ip=$3
local t=$4
local ndupes=$5
local npackets=$6
local filter=${7:-icmp}
echo "sniff packets on $dump_dev"
timeout $((t+1)) tcpdump -qnnei $dump_dev -c $npackets ${filter} &
local tpid=$!
sleep 0.5
on_remote "ping -I $from_dev $dst_ip -c $t -w $t" | grep "+$ndupes duplicates" && success || err "Multicast ping failed"
verify_no_traffic $tpid
}