net: ipv6: added test to expose racey clock check in route cache aging logic

Introduces a KUnit test which exposes a racey clock check in route cache
aging logic.

This test creates a rt6_exception which is set to expire after the now
time passed into rt6_age_exceptions and asserts that the exception will
not be removed.

This test fails because with certain settings, specified by this test,
the aging logic does not use the time passed in as the current time, but
instead directly checks jiffies. Because jiffies is greater than the
expiration time on the exception, it is removed; however, it should not
be because the now parameter can be and usually is early than the
current value of jiffies.

This test may be run using a .config with the following options:

CONFIG_TEST=y
CONFIG_TEST_TEST=y
CONFIG_EXAMPLE_TEST=y
CONFIG_NET=y
CONFIG_INET=y
CONFIG_IPV6_TEST=y

and with the following command:

./tools/testing/kunit/kunit.py

Change-Id: I9acda2ca4e04b4cf60e5addd5a4ee989cb0efca0
Kunitconfig-Revision: c4ad34242571a1883bdd1db0dae32bb6cc69559d
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
diff --git a/net/ipv6/route-test.c b/net/ipv6/route-test.c
index 627fe55..9245261 100644
--- a/net/ipv6/route-test.c
+++ b/net/ipv6/route-test.c
@@ -72,6 +72,28 @@
 }
 
 static void
+rt6_age_exceptions_test_rtf_expires_not_before_expiration(struct test *test)
+{
+	struct rt6_test *ctx = test->priv;
+	struct fib6_info *rt_info = ctx->rt_info;
+	struct rt6_info *rt6_ex_info;
+	struct mock_expectation *handle;
+	struct fib6_gc_args gc_args;
+
+	rt6_ex_info = ip6_rt_pcpu_alloc(rt_info);
+	rt6_ex_info->rt6i_flags |= RTF_EXPIRES;
+	rt6_ex_info->dst.expires = 1;
+	rt6_add_exception(test, rt_info, rt6_ex_info);
+
+	handle = EXPECT_CALL(rt6_remove_exception(any(test), any(test)));
+	handle->min_calls_expected = 0;
+	handle->max_calls_expected = 0;
+	handle->action = int_return(test, 0);
+
+	rt6_age_exceptions(rt_info, &gc_args, 0);
+}
+
+static void
 rt6_age_exceptions_test_rtf_expires_after_expiration(struct test *test)
 {
 	struct rt6_test *ctx = test->priv;
@@ -334,6 +356,7 @@
 }
 
 static struct test_case rt6_test_cases[] = {
+	TEST_CASE(rt6_age_exceptions_test_rtf_expires_not_before_expiration),
 	TEST_CASE(rt6_age_exceptions_test_rtf_expires_after_expiration),
 	TEST_CASE(rt6_age_exceptions_test_pmtu_expires_not_before_timeout),
 	TEST_CASE(rt6_age_exceptions_test_pmtu_expires_after_timeout),