[systemd-devel] [PATCH 2/8] sd-icmp6-nd: Add function to stop ongoing ICMPv6 discovery

Patrik Flykt patrik.flykt at linux.intel.com
Thu Jun 26 03:24:12 PDT 2014


In some use cases stopping an ongoing ICMPv6 discovery is more
useful than always unreferencing the whole structure.
---
 src/libsystemd-network/sd-icmp6-nd.c   | 13 +++++++++++++
 src/libsystemd-network/test-icmp6-rs.c |  4 ++++
 src/systemd/sd-icmp6-nd.h              |  1 +
 3 files changed, 18 insertions(+)

diff --git a/src/libsystemd-network/sd-icmp6-nd.c b/src/libsystemd-network/sd-icmp6-nd.c
index 10c5e5e..80915c3 100644
--- a/src/libsystemd-network/sd-icmp6-nd.c
+++ b/src/libsystemd-network/sd-icmp6-nd.c
@@ -282,6 +282,19 @@ static int icmp6_router_solicitation_timeout(sd_event_source *s, uint64_t usec,
         return 0;
 }
 
+int sd_icmp6_nd_stop(sd_icmp6_nd *nd) {
+        assert_return(nd, -EINVAL);
+        assert_return(nd->event, -EINVAL);
+
+        log_icmp6_nd(client, "Stop ICMPv6");
+
+        icmp6_nd_init(nd);
+
+        nd->state = ICMP6_NEIGHBOR_DISCOVERY_IDLE;
+
+        return 0;
+}
+
 int sd_icmp6_router_solicitation_start(sd_icmp6_nd *nd) {
         int r;
 
diff --git a/src/libsystemd-network/test-icmp6-rs.c b/src/libsystemd-network/test-icmp6-rs.c
index cd5c476..b81211f 100644
--- a/src/libsystemd-network/test-icmp6-rs.c
+++ b/src/libsystemd-network/test-icmp6-rs.c
@@ -127,6 +127,10 @@ static void test_rs(sd_event *e) {
                                  time_now + 2 *USEC_PER_SEC, 0,
                                  test_rs_hangcheck, NULL) >= 0);
 
+        assert(sd_icmp6_nd_stop(nd) >= 0);
+        assert(sd_icmp6_router_solicitation_start(nd) >= 0);
+        assert(sd_icmp6_nd_stop(nd) >= 0);
+
         assert(sd_icmp6_router_solicitation_start(nd) >= 0);
 
         sd_event_loop(e);
diff --git a/src/systemd/sd-icmp6-nd.h b/src/systemd/sd-icmp6-nd.h
index 5e9dc0a..73f91aa 100644
--- a/src/systemd/sd-icmp6-nd.h
+++ b/src/systemd/sd-icmp6-nd.h
@@ -51,6 +51,7 @@ sd_icmp6_nd *sd_icmp6_nd_ref(sd_icmp6_nd *nd);
 sd_icmp6_nd *sd_icmp6_nd_unref(sd_icmp6_nd *nd);
 int sd_icmp6_nd_new(sd_icmp6_nd **ret);
 
+int sd_icmp6_nd_stop(sd_icmp6_nd *nd);
 int sd_icmp6_router_solicitation_start(sd_icmp6_nd *nd);
 
 #endif
-- 
1.9.1



More information about the systemd-devel mailing list