]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-ndisc: notify user on STOP
authorTom Gundersen <teg@jklm.no>
Thu, 22 Oct 2015 15:46:35 +0000 (17:46 +0200)
committerTom Gundersen <teg@jklm.no>
Wed, 11 Nov 2015 14:42:38 +0000 (15:42 +0100)
Also, stop the state machine when we get into a broken state, rather than just notify the user.

src/libsystemd-network/sd-ndisc.c
src/libsystemd-network/test-ndisc-rs.c
src/network/networkd-ndisc.c
src/systemd/sd-ndisc.h

index c494b9d6d8e5ade0e18ee84be67bbaa3f8f4e83a..b8bfc6c549cf5668a0cde9823be0cd5cf1bae1a0 100644 (file)
@@ -494,8 +494,8 @@ static int ndisc_router_advertisment_recv(sd_event_source *s, int fd, uint32_t r
                 event = SD_NDISC_EVENT_ROUTER_ADVERTISMENT_MANAGED;
 
         log_ndisc(nd, "Received Router Advertisement flags %s/%s",
-                     ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED? "MANAGED": "none",
-                     ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER? "OTHER": "none");
+                     ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED ? "MANAGED" : "none",
+                     ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER ? "OTHER" : "none");
 
         if (event != SD_NDISC_EVENT_ROUTER_ADVERTISMENT_NONE) {
                 r = ndisc_ra_parse(nd, ra, len);
@@ -549,7 +549,8 @@ static int ndisc_router_solicitation_timeout(sd_event_source *s, uint64_t usec,
                                       next_timeout, 0,
                                       ndisc_router_solicitation_timeout, nd);
                 if (r < 0) {
-                        ndisc_notify(nd, r);
+                        /* we cannot continue if we are unable to rearm the timer */
+                        sd_ndisc_stop(nd);
                         return 0;
                 }
 
@@ -575,6 +576,8 @@ int sd_ndisc_stop(sd_ndisc *nd) {
 
         nd->state = NDISC_STATE_IDLE;
 
+        ndisc_notify(nd, SD_NDISC_EVENT_STOP);
+
         return 0;
 }
 
index 44eab94e8be5cef0e425457fba2f5b0dd22ddf63..59c720d48dfbedad845b0ef1d61fe71038b208e9 100644 (file)
@@ -87,11 +87,13 @@ int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) {
 
 static void test_rs_done(sd_ndisc *nd, int event, void *userdata) {
         sd_event *e = userdata;
-        static int idx = 0;
+        static unsigned idx = 0;
         struct {
                 uint8_t flag;
                 int event;
         } flag_event[] = {
+                { 0, SD_NDISC_EVENT_STOP },
+                { 0, SD_NDISC_EVENT_STOP },
                 { 0, SD_NDISC_EVENT_ROUTER_ADVERTISMENT_NONE },
                 { ND_RA_FLAG_OTHER, SD_NDISC_EVENT_ROUTER_ADVERTISMENT_OTHER },
                 { ND_RA_FLAG_MANAGED, SD_NDISC_EVENT_ROUTER_ADVERTISMENT_MANAGED }
@@ -106,7 +108,7 @@ static void test_rs_done(sd_ndisc *nd, int event, void *userdata) {
         if (verbose)
                 printf("  got event %d\n", event);
 
-        if (idx < 3) {
+        if (idx < ELEMENTSOF(flag_event)) {
                 send_ra(flag_event[idx].flag);
                 return;
         }
index 33e692f97f736fd8bec2213548c0be8775c7aa7d..50661c65f72e44772d86f73f18265fcb985324b1 100644 (file)
@@ -37,6 +37,7 @@ static void ndisc_router_handler(sd_ndisc *nd, int event, void *userdata) {
                 return;
 
         switch(event) {
+        case SD_NDISC_EVENT_STOP:
         case SD_NDISC_EVENT_ROUTER_ADVERTISMENT_NONE:
                 return;
 
@@ -51,10 +52,7 @@ static void ndisc_router_handler(sd_ndisc *nd, int event, void *userdata) {
                 break;
 
         default:
-                if (event < 0)
-                        log_link_warning_errno(link, event, "IPv6 Neighbor Discover error: %m");
-                else
-                        log_link_warning(link, "IPv6 Neighbor Discovery unknown event: %d", event);
+                log_link_warning(link, "IPv6 Neighbor Discovery unknown event: %d", event);
 
                 break;
         }
index 570e1741d68e3927222b20afa4931a7227646afb..d0dd098560814c4b795158101a644bff2d2b58bb 100644 (file)
 _SD_BEGIN_DECLARATIONS;
 
 enum {
-        SD_NDISC_EVENT_ROUTER_ADVERTISMENT_NONE              = 0,
-        SD_NDISC_EVENT_ROUTER_ADVERTISMENT_TIMEOUT           = 1,
-        SD_NDISC_EVENT_ROUTER_ADVERTISMENT_OTHER             = 2,
-        SD_NDISC_EVENT_ROUTER_ADVERTISMENT_MANAGED           = 3,
+        SD_NDISC_EVENT_ROUTER_ADVERTISMENT_NONE         = 0,
+        SD_NDISC_EVENT_ROUTER_ADVERTISMENT_TIMEOUT      = 1,
+        SD_NDISC_EVENT_ROUTER_ADVERTISMENT_OTHER        = 2,
+        SD_NDISC_EVENT_ROUTER_ADVERTISMENT_MANAGED      = 3,
+        SD_NDISC_EVENT_STOP                             = 4,
 };
 
 typedef struct sd_ndisc sd_ndisc;