summary refs log tree commit diff
path: root/src/core/ndisc/tests
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2022-02-14 19:23:28 +0100
committerMichael Biebl <biebl@debian.org>2022-02-14 19:23:28 +0100
commit2f94dba7385fd0e0ef19a06eb4a2fcf6c43d7946 (patch)
treee2222f5577115985dd52044d2991253403cdd952 /src/core/ndisc/tests
parent88c227d90a6b7b388c5c85d72802a0ca8f05ed5c (diff)
New upstream version 1.35.91 upstream/1.35.91
Diffstat (limited to 'src/core/ndisc/tests')
-rw-r--r--src/core/ndisc/tests/test-ndisc-fake.c138
-rw-r--r--src/core/ndisc/tests/test-ndisc-linux.c55
2 files changed, 111 insertions, 82 deletions
diff --git a/src/core/ndisc/tests/test-ndisc-fake.c b/src/core/ndisc/tests/test-ndisc-fake.c
index f201bc56..0763b64e 100644
--- a/src/core/ndisc/tests/test-ndisc-fake.c
+++ b/src/core/ndisc/tests/test-ndisc-fake.c
@@ -11,24 +11,29 @@
 #include "ndisc/nm-fake-ndisc.h"
 
 #include "platform/nm-fake-platform.h"
+#include "nm-netns.h"
 
-#include "nm-test-utils-core.h"
+#include "platform/tests/test-common.h"
 
 /*****************************************************************************/
 
 static NMFakeNDisc *
 ndisc_new(void)
 {
-    NMNDisc *          ndisc;
-    const int          ifindex = 1;
-    const char *       ifname  = nm_platform_link_get_name(NM_PLATFORM_GET, ifindex);
-    NMUtilsIPv6IfaceId iid     = {};
+    gs_unref_object NML3Cfg *l3cfg = NULL;
+    NMNDisc                 *ndisc;
+    const int                ifindex = 1;
+    NMUtilsIPv6IfaceId       iid;
 
-    ndisc        = nm_fake_ndisc_new(ifindex, ifname);
-    iid.id_u8[7] = 1;
-    nm_ndisc_set_iid(ndisc, iid);
+    l3cfg = nm_netns_l3cfg_acquire(NM_NETNS_GET, ifindex);
+
+    ndisc = nm_fake_ndisc_new(l3cfg);
     g_assert(ndisc);
 
+    memset(&iid, 0, sizeof(iid));
+    iid.id_u8[7] = 1;
+    nm_ndisc_set_iid(ndisc, iid, FALSE);
+
     return NM_FAKE_NDISC(ndisc);
 }
 
@@ -37,7 +42,7 @@ ndisc_new(void)
 static void
 match_gateway(const NMNDiscData *rdata,
               guint              idx,
-              const char *       addr,
+              const char        *addr,
               gint64             expiry_msec,
               NMIcmpv6RouterPref pref)
 {
@@ -57,7 +62,7 @@ match_gateway(const NMNDiscData *rdata,
 #define match_address(rdata, idx, addr, _expiry_msec, _expiry_preferred_msec)     \
     G_STMT_START                                                                  \
     {                                                                             \
-        const NMNDiscData *   _rdata = (rdata);                                   \
+        const NMNDiscData    *_rdata = (rdata);                                   \
         guint                 _idx   = (idx);                                     \
         const NMNDiscAddress *_a;                                                 \
                                                                                   \
@@ -76,7 +81,7 @@ match_gateway(const NMNDiscData *rdata,
 #define match_route(rdata, idx, nw, pl, gw, _expiry_msec, pref) \
     G_STMT_START                                                \
     {                                                           \
-        const NMNDiscData * _rdata = (rdata);                   \
+        const NMNDiscData  *_rdata = (rdata);                   \
         guint               _idx   = (idx);                     \
         const NMNDiscRoute *_r;                                 \
         int                 _plen = (pl);                       \
@@ -140,9 +145,15 @@ typedef struct {
 /*****************************************************************************/
 
 static void
-test_simple_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, TestData *data)
+test_simple_changed(NMNDisc              *ndisc,
+                    const NMNDiscData    *rdata,
+                    guint                 changed_i,
+                    const NML3ConfigData *l3cd,
+                    TestData             *data)
 {
-    NMNDiscConfigMap changed = changed_int;
+    NMNDiscConfigMap changed = changed_i;
+
+    _LOGT("test_simple: callback (counter=%u)", data->counter);
 
     switch (data->counter++) {
     case 0:
@@ -180,12 +191,12 @@ test_simple_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int,
 static void
 test_simple(void)
 {
-    nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE);
-    gs_unref_object NMFakeNDisc *ndisc      = ndisc_new();
-    const gint64                 now_msec   = nm_utils_get_monotonic_timestamp_msec();
-    TestData                     data       = {
-        .loop             = loop,
-        .timestamp_msec_1 = now_msec,
+    nm_auto_unref_gmainloop GMainLoop *loop     = g_main_loop_new(NULL, FALSE);
+    gs_unref_object NMFakeNDisc       *ndisc    = ndisc_new();
+    const gint64                       now_msec = nm_utils_get_monotonic_timestamp_msec();
+    TestData                           data     = {
+                                      .loop             = loop,
+                                      .timestamp_msec_1 = now_msec,
     };
     guint id;
 
@@ -206,9 +217,11 @@ test_simple(void)
 
     g_signal_connect(ndisc, NM_NDISC_CONFIG_RECEIVED, G_CALLBACK(test_simple_changed), &data);
 
+    _LOGT("test_simple: start");
     nm_ndisc_start(NM_NDISC(ndisc));
     nmtst_main_loop_run_assert(data.loop, 15000);
     g_assert_cmpint(data.counter, ==, 2);
+    _LOGT("test_simple: done");
 }
 
 /*****************************************************************************/
@@ -221,9 +234,13 @@ test_everything_rs_sent(NMNDisc *ndisc, TestData *data)
 }
 
 static void
-test_everything_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, TestData *data)
+test_everything_changed(NMNDisc              *ndisc,
+                        const NMNDiscData    *rdata,
+                        guint                 changed_i,
+                        const NML3ConfigData *l3cd,
+                        TestData             *data)
 {
-    NMNDiscConfigMap changed = changed_int;
+    NMNDiscConfigMap changed = changed_i;
 
     if (data->counter == 0) {
         g_assert_cmpint(data->rs_counter, ==, 1);
@@ -288,12 +305,12 @@ test_everything_changed(NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_
 static void
 test_everything(void)
 {
-    nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE);
-    gs_unref_object NMFakeNDisc *ndisc      = ndisc_new();
-    const gint64                 now_msec   = nm_utils_get_monotonic_timestamp_msec();
-    TestData                     data       = {
-        .loop             = loop,
-        .timestamp_msec_1 = now_msec,
+    nm_auto_unref_gmainloop GMainLoop *loop     = g_main_loop_new(NULL, FALSE);
+    gs_unref_object NMFakeNDisc       *ndisc    = ndisc_new();
+    const gint64                       now_msec = nm_utils_get_monotonic_timestamp_msec();
+    TestData                           data     = {
+                                      .loop             = loop,
+                                      .timestamp_msec_1 = now_msec,
     };
     guint id;
 
@@ -342,12 +359,13 @@ test_everything(void)
 }
 
 static void
-test_preference_order_cb(NMNDisc *          ndisc,
-                         const NMNDiscData *rdata,
-                         guint              changed_int,
-                         TestData *         data)
+test_preference_order_cb(NMNDisc              *ndisc,
+                         const NMNDiscData    *rdata,
+                         guint                 changed_i,
+                         const NML3ConfigData *l3cd,
+                         TestData             *data)
 {
-    NMNDiscConfigMap changed = changed_int;
+    NMNDiscConfigMap changed = changed_i;
 
     if (data->counter == 1) {
         g_assert_cmpint(changed,
@@ -391,12 +409,12 @@ test_preference_order_cb(NMNDisc *          ndisc,
 static void
 test_preference_order(void)
 {
-    nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE);
-    gs_unref_object NMFakeNDisc *ndisc      = ndisc_new();
-    const gint64                 now_msec   = nm_utils_get_monotonic_timestamp_msec();
-    TestData                     data       = {
-        .loop             = loop,
-        .timestamp_msec_1 = now_msec,
+    nm_auto_unref_gmainloop GMainLoop *loop     = g_main_loop_new(NULL, FALSE);
+    gs_unref_object NMFakeNDisc       *ndisc    = ndisc_new();
+    const gint64                       now_msec = nm_utils_get_monotonic_timestamp_msec();
+    TestData                           data     = {
+                                      .loop             = loop,
+                                      .timestamp_msec_1 = now_msec,
     };
     guint id;
 
@@ -434,12 +452,13 @@ test_preference_order(void)
 }
 
 static void
-test_preference_changed_cb(NMNDisc *          ndisc,
-                           const NMNDiscData *rdata,
-                           guint              changed_int,
-                           TestData *         data)
+test_preference_changed_cb(NMNDisc              *ndisc,
+                           const NMNDiscData    *rdata,
+                           guint                 changed_i,
+                           const NML3ConfigData *l3cd,
+                           TestData             *data)
 {
-    NMNDiscConfigMap changed = changed_int;
+    NMNDiscConfigMap changed = changed_i;
 
     if (data->counter == 1) {
         g_assert_cmpint(changed,
@@ -513,12 +532,12 @@ test_preference_changed_cb(NMNDisc *          ndisc,
 static void
 test_preference_changed(void)
 {
-    nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE);
-    gs_unref_object NMFakeNDisc *ndisc      = ndisc_new();
-    const gint64                 now_msec   = nm_utils_get_monotonic_timestamp_msec();
-    TestData                     data       = {
-        .loop             = loop,
-        .timestamp_msec_1 = now_msec,
+    nm_auto_unref_gmainloop GMainLoop *loop     = g_main_loop_new(NULL, FALSE);
+    gs_unref_object NMFakeNDisc       *ndisc    = ndisc_new();
+    const gint64                       now_msec = nm_utils_get_monotonic_timestamp_msec();
+    TestData                           data     = {
+                                      .loop             = loop,
+                                      .timestamp_msec_1 = now_msec,
     };
     guint id;
 
@@ -576,10 +595,11 @@ test_preference_changed(void)
 /*****************************************************************************/
 
 static void
-_test_dns_solicit_loop_changed(NMNDisc *          ndisc,
-                               const NMNDiscData *rdata,
-                               guint              changed_int,
-                               TestData *         data)
+_test_dns_solicit_loop_changed(NMNDisc              *ndisc,
+                               const NMNDiscData    *rdata,
+                               guint                 changed_i,
+                               const NML3ConfigData *l3cd,
+                               TestData             *data)
 {
     data->counter++;
 }
@@ -593,12 +613,12 @@ _test_dns_solicit_loop_rs_sent(NMFakeNDisc *ndisc, TestData *data)
 static void
 test_dns_solicit_loop(void)
 {
-    nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(NULL, FALSE);
-    gs_unref_object NMFakeNDisc *ndisc      = ndisc_new();
-    const gint64                 now_msec   = nm_utils_get_monotonic_timestamp_msec();
-    TestData                     data       = {
-        .loop             = loop,
-        .timestamp_msec_1 = now_msec,
+    nm_auto_unref_gmainloop GMainLoop *loop     = g_main_loop_new(NULL, FALSE);
+    gs_unref_object NMFakeNDisc       *ndisc    = ndisc_new();
+    const gint64                       now_msec = nm_utils_get_monotonic_timestamp_msec();
+    TestData                           data     = {
+                                      .loop             = loop,
+                                      .timestamp_msec_1 = now_msec,
     };
     guint id;
 
diff --git a/src/core/ndisc/tests/test-ndisc-linux.c b/src/core/ndisc/tests/test-ndisc-linux.c
index 57021606..66c7e157 100644
--- a/src/core/ndisc/tests/test-ndisc-linux.c
+++ b/src/core/ndisc/tests/test-ndisc-linux.c
@@ -11,6 +11,8 @@
 #include "ndisc/nm-lndp-ndisc.h"
 
 #include "libnm-platform/nm-linux-platform.h"
+#include "nm-netns.h"
+#include "nm-l3cfg.h"
 
 #include "nm-test-utils-core.h"
 
@@ -19,16 +21,18 @@ NMTST_DEFINE();
 int
 main(int argc, char **argv)
 {
-    GMainLoop *        loop;
-    NMNDisc *          ndisc;
-    int                ifindex = 1;
-    const char *       ifname;
-    NMUtilsIPv6IfaceId iid   = {};
-    GError *           error = NULL;
-    int                max_addresses;
-    int                router_solicitations;
-    int                router_solicitation_interval;
-    guint32            ra_timeout;
+    gs_unref_object NML3Cfg *l3cfg = NULL;
+    NMNDiscConfig            config;
+    GMainLoop               *loop;
+    NMNDisc                 *ndisc;
+    int                      ifindex = 1;
+    const char              *ifname;
+    NMUtilsIPv6IfaceId       iid   = {};
+    GError                  *error = NULL;
+    int                      max_addresses;
+    int                      router_solicitations;
+    int                      router_solicitation_interval;
+    guint32                  ra_timeout;
 
     nmtst_init_with_logging(&argc, &argv, NULL, "DEFAULT");
 
@@ -56,18 +60,23 @@ main(int argc, char **argv)
                         &router_solicitation_interval,
                         &ra_timeout);
 
-    ndisc = nm_lndp_ndisc_new(NM_PLATFORM_GET,
-                              ifindex,
-                              ifname,
-                              NM_UTILS_STABLE_TYPE_UUID,
-                              "8ce666e8-d34d-4fb1-b858-f15a7al28086",
-                              NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64,
-                              NM_NDISC_NODE_TYPE_HOST,
-                              max_addresses,
-                              router_solicitations,
-                              router_solicitation_interval,
-                              ra_timeout,
-                              &error);
+    l3cfg = nm_netns_l3cfg_acquire(NM_NETNS_GET, ifindex);
+
+    config = (NMNDiscConfig){
+        .l3cfg                        = l3cfg,
+        .ifname                       = nm_l3cfg_get_ifname(l3cfg, TRUE),
+        .stable_type                  = NM_UTILS_STABLE_TYPE_UUID,
+        .network_id                   = "8ce666e8-d34d-4fb1-b858-f15a7al28086",
+        .addr_gen_mode                = NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64,
+        .node_type                    = NM_NDISC_NODE_TYPE_HOST,
+        .max_addresses                = max_addresses,
+        .router_solicitations         = router_solicitations,
+        .router_solicitation_interval = router_solicitation_interval,
+        .ra_timeout                   = ra_timeout,
+        .ip6_privacy                  = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR,
+    };
+
+    ndisc = nm_lndp_ndisc_new(&config);
     if (!ndisc) {
         g_print("Failed to create NMNDisc instance: %s\n", error->message);
         g_error_free(error);
@@ -75,7 +84,7 @@ main(int argc, char **argv)
     }
 
     iid.id_u8[7] = 1;
-    nm_ndisc_set_iid(ndisc, iid);
+    nm_ndisc_set_iid(ndisc, iid, FALSE);
     nm_ndisc_start(ndisc);
     g_main_loop_run(loop);