function lookup_mac()
{
set +x if [ ! -z "$2" ]; then
MAC=$(ip netns exec $2 ip link show $1 | grep ether | awk '{print $2}') else
MAC=$(ip link show $1 | grep ether | awk '{print $2}') fi
MAC="${MAC//:/}" echo"0x${MAC:10:2}${MAC:8:2}${MAC:6:2}${MAC:4:2}${MAC:2:2}${MAC:0:2}"
set -x
}
function cleanup {
set +ex rm $BPF_PROG 2> /dev/null
ip link del $VETH0 2> /dev/null
ip link del $VETH1 2> /dev/null
ip link del $VETH2 2> /dev/null
ip link del $VETH3 2> /dev/null
ip netns exec $NS1 killall netserver
ip netns delete $NS1 2> /dev/null
ip netns delete $NS2 2> /dev/null
set -ex
}
function setup_one_veth {
ip netns add $1
ip link add $2 type veth peer name $3
ip link set dev $2 up
ip addr add $4/24 dev $2
ip link set $3 netns $1
ip netns exec $1 ip link set dev $3 up
ip netns exec $1 ip addr add $5/24 dev $3
if [ "$6" ]; then
ip netns exec $1 ip addr add $6/32 dev $3 fi
}
function get_trace {
set +x cat ${TRACE_ROOT}/trace | grep -v '^#'
set -x
}
function cleanup_routes {
ip route del ${IPVETH1}/32 dev $VETH0 2> /dev/null || true
ip route del table local local ${IP_LOCAL}/32 dev lo 2> /dev/null || true
}
function install_test {
cleanup_routes cp /dev/null ${TRACE_ROOT}/trace
function test_start {
set +x echo"----------------------------------------------------------------" echo"Starting test: $*" echo"----------------------------------------------------------------"
set -x
}
function failure {
get_trace echo"FAIL: $*"
exit 1
}
function test_drop_all_in {
test_start "test_drop_all on lwt in"
install_test in drop_all
ping -c 3 $IP_LOCAL && {
failure "test_drop_all in: Unexpected success of ping"
}
match_trace "$(get_trace)""
dropping with: 2
dropping with: 2
dropping with: 2" || exit 1
remove_prog in
}
function test_push_ll_and_redirect {
test_start "test_push_ll_and_redirect on lwt xmit"
install_test xmit push_ll_and_redirect
ping -c 3 $IPVETH1 || {
failure "Redirected packets appear to be dropped"
}
match_trace "$(get_trace)""
redirected to $DST_IFINDEX
redirected to $DST_IFINDEX
redirected to $DST_IFINDEX" || exit 1
remove_prog xmit
}
function test_no_l2_and_redirect {
test_start "test_no_l2_and_redirect on lwt xmit"
install_test xmit fill_garbage_and_redirect
ping -c 3 $IPVETH1 && {
failure "Unexpected success despite lack of L2 header"
}
match_trace "$(get_trace)""
redirected to $DST_IFINDEX
redirected to $DST_IFINDEX
redirected to $DST_IFINDEX" || exit 1
remove_prog xmit
}
function test_rewrite {
test_start "test_rewrite on lwt xmit"
install_test xmit test_rewrite
ping -c 3 $IPVETH1 || {
failure "Rewritten packets appear to be dropped"
}
match_trace "$(get_trace)""
out: rewriting from 2fea8c0 to 3fea8c0
out: rewriting from 2fea8c0 to 3fea8c0
out: rewriting from 2fea8c0 to 3fea8c0" || exit 1
remove_prog out
}
function test_fill_garbage {
test_start "test_fill_garbage on lwt xmit"
install_test xmit fill_garbage
ping -c 3 $IPVETH1 && {
failure "test_drop_all ${1}: Unexpected success of ping"
}
match_trace "$(get_trace)""
Set initial 96 bytes of header to FF
Set initial 96 bytes of header to FF
Set initial 96 bytes of header to FF" || exit 1
remove_prog xmit
}
function test_netperf_nop {
test_start "test_netperf_nop on lwt xmit"
install_test xmit nop
netperf -H $IPVETH1 -t TCP_STREAM || {
failure "packets appear to be dropped"
}
match_trace "$(get_trace)"""|| exit 1
remove_prog xmit
}
function test_netperf_redirect {
test_start "test_netperf_redirect on lwt xmit"
install_test xmit push_ll_and_redirect_silent
netperf -H $IPVETH1 -t TCP_STREAM || {
failure "Rewritten packets appear to be dropped"
}
match_trace "$(get_trace)"""|| exit 1
remove_prog xmit
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.