sd-ndisc: do not print "(null)" in the log message
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 22 May 2024 15:38:38 +0000 (00:38 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 22 May 2024 20:07:58 +0000 (22:07 +0200)
If we received RA with no flags set, or with an invalid preference,
previously "(null)" was printed.

Follow-up for 238ed432c347ddf7dde7825feb2672b089583103.

Fixes https://github.com/systemd/systemd/pull/32308#discussion_r1600940289.

src/libsystemd-network/sd-ndisc-router.c
src/libsystemd-network/sd-ndisc.c

index b2ad41434e54b23fdcb954ed901a5e549ac19c11..9ca737d493970875e6cb9b6ff5f277fc0f2013ea 100644 (file)
@@ -203,9 +203,10 @@ int sd_ndisc_router_get_preference(sd_ndisc_router *rt, uint8_t *ret) {
 }
 
 static const char* const ndisc_router_preference_table[] = {
-        [SD_NDISC_PREFERENCE_LOW]    = "low",
-        [SD_NDISC_PREFERENCE_MEDIUM] = "medium",
-        [SD_NDISC_PREFERENCE_HIGH]   = "high",
+        [SD_NDISC_PREFERENCE_LOW]      = "low",
+        [SD_NDISC_PREFERENCE_MEDIUM]   = "medium",
+        [SD_NDISC_PREFERENCE_HIGH]     = "high",
+        [SD_NDISC_PREFERENCE_RESERVED] = "reserved",
 };
 
 DEFINE_STRING_TABLE_LOOKUP_TO_STRING(ndisc_router_preference, int);
index 2e303965f893492be005eb2572dc23faf837bdd7..ca15f942f5615c2f459f2317e45e93fa37933e04 100644 (file)
@@ -248,10 +248,10 @@ static int ndisc_handle_router(sd_ndisc *nd, ICMP6Packet *packet) {
                 if (r < 0)
                         return r;
 
-                log_ndisc(nd, "Received Router Advertisement from %s: flags=0x%0*"PRIx64"%s%s%s, preference=%s, lifetime=%s",
+                log_ndisc(nd, "Received Router Advertisement from %s: flags=0x%0*"PRIx64"(%s), preference=%s, lifetime=%s",
                           IN6_ADDR_TO_STRING(&a),
                           flags & UINT64_C(0x00ffffffffffff00) ? 14 : 2, flags, /* suppress too many zeros if no extension */
-                          s ? " (" : "", s, s ? ")" : "",
+                          s ?: "none",
                           ndisc_router_preference_to_string(pref),
                           FORMAT_TIMESPAN(lifetime, USEC_PER_SEC));
         }