-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Roopa Prabhu says: ==================== fib rule selftest This series adds a new test to test fib rules. ip route get is used to test fib rule matches. This series also extends ip route get to match on sport and dport to test recent support of sport and dport fib rule match. v2 - address ido's commemt to make sport dport ip route get to work correctly for input route get. I don't support ip route get on ip-proto match yet. ip route get creates a udp packet and i have left it at that. We could extend ip route get to support a few ip proto matches in followup patches. v3 - Support ip_proto (only tcp and udp) match in getroute. dropped printing of new match attrs in ip route get, because ipv6 does not print it. And ipv6 currrently shares the dump api with ipv6 notify and its better to not add them to the notify api. dropped it to keep the api consistent between ipv4 and ipv6 (though uid is already printed in the ipv4 case). If we need it, both ipv4 and ipv6 can be enhanced to provide a separate get api. Moved skb creation for ipv4 to a separate func. v4 - drop separate skb for netlink and fix concerns around rcu and netlink reply (as pointed out by DaveM). I now try to reset the skb after the route lookup and before the netlink send (testing shows this is ok. More eyes and any feedback here will be helpful) v5 - dropped RTA_TABLE ipv4_rtm_policy update from this series and posted it separately for net (feedback from Eric) ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Showing
9 changed files
with
406 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <linux/netlink.h> | ||
#include <linux/rtnetlink.h> | ||
#include <linux/types.h> | ||
#include <net/net_namespace.h> | ||
#include <net/netlink.h> | ||
#include <net/ip.h> | ||
|
||
int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, | ||
struct netlink_ext_ack *extack) | ||
{ | ||
*ip_proto = nla_get_u8(attr); | ||
|
||
switch (*ip_proto) { | ||
case IPPROTO_TCP: | ||
case IPPROTO_UDP: | ||
case IPPROTO_ICMP: | ||
return 0; | ||
default: | ||
NL_SET_ERR_MSG(extack, "Unsupported ip proto"); | ||
return -EOPNOTSUPP; | ||
} | ||
} | ||
EXPORT_SYMBOL_GPL(rtm_getroute_parse_ip_proto); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
# This test is for checking IPv4 and IPv6 FIB rules API | ||
|
||
ret=0 | ||
|
||
PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} | ||
IP="ip -netns testns" | ||
|
||
RTABLE=100 | ||
GW_IP4=192.51.100.2 | ||
SRC_IP=192.51.100.3 | ||
GW_IP6=2001:db8:1::2 | ||
SRC_IP6=2001:db8:1::3 | ||
|
||
DEV_ADDR=192.51.100.1 | ||
DEV=dummy0 | ||
|
||
log_test() | ||
{ | ||
local rc=$1 | ||
local expected=$2 | ||
local msg="$3" | ||
|
||
if [ ${rc} -eq ${expected} ]; then | ||
nsuccess=$((nsuccess+1)) | ||
printf "\n TEST: %-50s [ OK ]\n" "${msg}" | ||
else | ||
nfail=$((nfail+1)) | ||
printf "\n TEST: %-50s [FAIL]\n" "${msg}" | ||
if [ "${PAUSE_ON_FAIL}" = "yes" ]; then | ||
echo | ||
echo "hit enter to continue, 'q' to quit" | ||
read a | ||
[ "$a" = "q" ] && exit 1 | ||
fi | ||
fi | ||
} | ||
|
||
log_section() | ||
{ | ||
echo | ||
echo "######################################################################" | ||
echo "TEST SECTION: $*" | ||
echo "######################################################################" | ||
} | ||
|
||
setup() | ||
{ | ||
set -e | ||
ip netns add testns | ||
$IP link set dev lo up | ||
|
||
$IP link add dummy0 type dummy | ||
$IP link set dev dummy0 up | ||
$IP address add 198.51.100.1/24 dev dummy0 | ||
$IP -6 address add 2001:db8:1::1/64 dev dummy0 | ||
|
||
set +e | ||
} | ||
|
||
cleanup() | ||
{ | ||
$IP link del dev dummy0 &> /dev/null | ||
ip netns del testns | ||
} | ||
|
||
fib_check_iproute_support() | ||
{ | ||
ip rule help 2>&1 | grep -q $1 | ||
if [ $? -ne 0 ]; then | ||
echo "SKIP: iproute2 iprule too old, missing $1 match" | ||
return 1 | ||
fi | ||
|
||
ip route get help 2>&1 | grep -q $2 | ||
if [ $? -ne 0 ]; then | ||
echo "SKIP: iproute2 get route too old, missing $2 match" | ||
return 1 | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
fib_rule6_del() | ||
{ | ||
$IP -6 rule del $1 | ||
log_test $? 0 "rule6 del $1" | ||
} | ||
|
||
fib_rule6_del_by_pref() | ||
{ | ||
pref=$($IP -6 rule show | grep "$1 lookup $TABLE" | cut -d ":" -f 1) | ||
$IP -6 rule del pref $pref | ||
} | ||
|
||
fib_rule6_test_match_n_redirect() | ||
{ | ||
local match="$1" | ||
local getmatch="$2" | ||
|
||
$IP -6 rule add $match table $RTABLE | ||
$IP -6 route get $GW_IP6 $getmatch | grep -q "table $RTABLE" | ||
log_test $? 0 "rule6 check: $1" | ||
|
||
fib_rule6_del_by_pref "$match" | ||
log_test $? 0 "rule6 del by pref: $match" | ||
} | ||
|
||
fib_rule6_test() | ||
{ | ||
# setup the fib rule redirect route | ||
$IP -6 route add table $RTABLE default via $GW_IP6 dev $DEV onlink | ||
|
||
match="oif $DEV" | ||
fib_rule6_test_match_n_redirect "$match" "$match" "oif redirect to table" | ||
|
||
match="from $SRC_IP6 iif $DEV" | ||
fib_rule6_test_match_n_redirect "$match" "$match" "iif redirect to table" | ||
|
||
match="tos 0x10" | ||
fib_rule6_test_match_n_redirect "$match" "$match" "tos redirect to table" | ||
|
||
match="fwmark 0x64" | ||
getmatch="mark 0x64" | ||
fib_rule6_test_match_n_redirect "$match" "$getmatch" "fwmark redirect to table" | ||
|
||
fib_check_iproute_support "uidrange" "uid" | ||
if [ $? -eq 0 ]; then | ||
match="uidrange 100-100" | ||
getmatch="uid 100" | ||
fib_rule6_test_match_n_redirect "$match" "$getmatch" "uid redirect to table" | ||
fi | ||
|
||
fib_check_iproute_support "sport" "sport" | ||
if [ $? -eq 0 ]; then | ||
match="sport 666 dport 777" | ||
fib_rule6_test_match_n_redirect "$match" "$match" "sport and dport redirect to table" | ||
fi | ||
|
||
fib_check_iproute_support "ipproto" "ipproto" | ||
if [ $? -eq 0 ]; then | ||
match="ipproto tcp" | ||
fib_rule6_test_match_n_redirect "$match" "$match" "ipproto match" | ||
fi | ||
|
||
fib_check_iproute_support "ipproto" "ipproto" | ||
if [ $? -eq 0 ]; then | ||
match="ipproto icmp" | ||
fib_rule6_test_match_n_redirect "$match" "$match" "ipproto icmp match" | ||
fi | ||
} | ||
|
||
fib_rule4_del() | ||
{ | ||
$IP rule del $1 | ||
log_test $? 0 "del $1" | ||
} | ||
|
||
fib_rule4_del_by_pref() | ||
{ | ||
pref=$($IP rule show | grep "$1 lookup $TABLE" | cut -d ":" -f 1) | ||
$IP rule del pref $pref | ||
} | ||
|
||
fib_rule4_test_match_n_redirect() | ||
{ | ||
local match="$1" | ||
local getmatch="$2" | ||
|
||
$IP rule add $match table $RTABLE | ||
$IP route get $GW_IP4 $getmatch | grep -q "table $RTABLE" | ||
log_test $? 0 "rule4 check: $1" | ||
|
||
fib_rule4_del_by_pref "$match" | ||
log_test $? 0 "rule4 del by pref: $match" | ||
} | ||
|
||
fib_rule4_test() | ||
{ | ||
# setup the fib rule redirect route | ||
$IP route add table $RTABLE default via $GW_IP4 dev $DEV onlink | ||
|
||
match="oif $DEV" | ||
fib_rule4_test_match_n_redirect "$match" "$match" "oif redirect to table" | ||
|
||
match="from $SRC_IP iif $DEV" | ||
fib_rule4_test_match_n_redirect "$match" "$match" "iif redirect to table" | ||
|
||
match="tos 0x10" | ||
fib_rule4_test_match_n_redirect "$match" "$match" "tos redirect to table" | ||
|
||
match="fwmark 0x64" | ||
getmatch="mark 0x64" | ||
fib_rule4_test_match_n_redirect "$match" "$getmatch" "fwmark redirect to table" | ||
|
||
fib_check_iproute_support "uidrange" "uid" | ||
if [ $? -eq 0 ]; then | ||
match="uidrange 100-100" | ||
getmatch="uid 100" | ||
fib_rule4_test_match_n_redirect "$match" "$getmatch" "uid redirect to table" | ||
fi | ||
|
||
fib_check_iproute_support "sport" "sport" | ||
if [ $? -eq 0 ]; then | ||
match="sport 666 dport 777" | ||
fib_rule4_test_match_n_redirect "$match" "$match" "sport and dport redirect to table" | ||
fi | ||
|
||
fib_check_iproute_support "ipproto" "ipproto" | ||
if [ $? -eq 0 ]; then | ||
match="ipproto tcp" | ||
fib_rule4_test_match_n_redirect "$match" "$match" "ipproto tcp match" | ||
fi | ||
|
||
fib_check_iproute_support "ipproto" "ipproto" | ||
if [ $? -eq 0 ]; then | ||
match="ipproto icmp" | ||
fib_rule4_test_match_n_redirect "$match" "$match" "ipproto icmp match" | ||
fi | ||
} | ||
|
||
run_fibrule_tests() | ||
{ | ||
log_section "IPv4 fib rule" | ||
fib_rule4_test | ||
log_section "IPv6 fib rule" | ||
fib_rule6_test | ||
} | ||
|
||
if [ "$(id -u)" -ne 0 ];then | ||
echo "SKIP: Need root privileges" | ||
exit 0 | ||
fi | ||
|
||
if [ ! -x "$(command -v ip)" ]; then | ||
echo "SKIP: Could not run test without ip tool" | ||
exit 0 | ||
fi | ||
|
||
# start clean | ||
cleanup &> /dev/null | ||
setup | ||
run_fibrule_tests | ||
cleanup | ||
|
||
exit $ret |