sd-ndisc: rename ndisc-protocol.[ch] -> ndisc-option.[ch]
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 8 Mar 2024 15:08:27 +0000 (00:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Mar 2024 01:55:48 +0000 (10:55 +0900)
src/libsystemd-network/meson.build
src/libsystemd-network/ndisc-option.c [new file with mode: 0644]
src/libsystemd-network/ndisc-option.h [new file with mode: 0644]
src/libsystemd-network/ndisc-protocol.c [deleted file]
src/libsystemd-network/ndisc-protocol.h [deleted file]
src/libsystemd-network/radv-internal.h
src/libsystemd-network/sd-ndisc-router.c

index a2e5106b42d4c940a762a749f83b48ba838c1a3b..e4340f995794756f0a098b4afdf0c5b7000e8ad5 100644 (file)
@@ -12,7 +12,7 @@ sources = files(
         'icmp6-util.c',
         'lldp-neighbor.c',
         'lldp-network.c',
-        'ndisc-protocol.c',
+        'ndisc-option.c',
         'network-common.c',
         'network-internal.c',
         'sd-dhcp-client-id.c',
diff --git a/src/libsystemd-network/ndisc-option.c b/src/libsystemd-network/ndisc-option.c
new file mode 100644 (file)
index 0000000..ad32129
--- /dev/null
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <netinet/icmp6.h>
+
+#include "ndisc-option.h"
+
+int ndisc_option_parse(
+                ICMP6Packet *p,
+                size_t offset,
+                uint8_t *ret_type,
+                size_t *ret_len,
+                const uint8_t **ret_opt) {
+
+        assert(p);
+
+        if (offset == p->raw_size)
+                return -ESPIPE; /* end of the packet */
+
+        if (offset > p->raw_size)
+                return -EBADMSG;
+
+        if (p->raw_size - offset < sizeof(struct nd_opt_hdr))
+                return -EBADMSG;
+
+        assert_cc(alignof(struct nd_opt_hdr) == 1);
+        const struct nd_opt_hdr *hdr = (const struct nd_opt_hdr*) (p->raw_packet + offset);
+        if (hdr->nd_opt_len == 0)
+                return -EBADMSG;
+
+        size_t len = hdr->nd_opt_len * 8;
+        if (p->raw_size - offset < len)
+                return -EBADMSG;
+
+        if (ret_type)
+                *ret_type = hdr->nd_opt_type;
+        if (ret_len)
+                *ret_len = len;
+        if (ret_opt)
+                *ret_opt = p->raw_packet + offset;
+
+        return 0;
+}
+
+static const uint8_t prefix_length_code_to_prefix_length[_PREFIX_LENGTH_CODE_MAX] = {
+        [PREFIX_LENGTH_CODE_96] = 96,
+        [PREFIX_LENGTH_CODE_64] = 64,
+        [PREFIX_LENGTH_CODE_56] = 56,
+        [PREFIX_LENGTH_CODE_48] = 48,
+        [PREFIX_LENGTH_CODE_40] = 40,
+        [PREFIX_LENGTH_CODE_32] = 32,
+};
+
+int pref64_plc_to_prefix_length(uint16_t plc, uint8_t *ret) {
+        plc &= PREF64_PLC_MASK;
+        if (plc >= _PREFIX_LENGTH_CODE_MAX)
+                return -EINVAL;
+
+        if (ret)
+                *ret = prefix_length_code_to_prefix_length[plc];
+        return 0;
+}
+
+int pref64_prefix_length_to_plc(uint8_t prefixlen, uint8_t *ret) {
+        assert(ret);
+
+        for (size_t i = 0; i < ELEMENTSOF(prefix_length_code_to_prefix_length); i++)
+                if (prefix_length_code_to_prefix_length[i] == prefixlen) {
+                        *ret = i;
+                        return 0;
+                }
+
+        return -EINVAL;
+}
diff --git a/src/libsystemd-network/ndisc-option.h b/src/libsystemd-network/ndisc-option.h
new file mode 100644 (file)
index 0000000..dcb1b19
--- /dev/null
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "icmp6-packet.h"
+#include "time-util.h"
+
+/* RFC 8781: PREF64 or (NAT64 prefix) */
+#define PREF64_SCALED_LIFETIME_MASK      0xfff8
+#define PREF64_PLC_MASK                  0x0007
+#define PREF64_MAX_LIFETIME_USEC         (65528 * USEC_PER_SEC)
+
+typedef enum PrefixLengthCode {
+        PREFIX_LENGTH_CODE_96,
+        PREFIX_LENGTH_CODE_64,
+        PREFIX_LENGTH_CODE_56,
+        PREFIX_LENGTH_CODE_48,
+        PREFIX_LENGTH_CODE_40,
+        PREFIX_LENGTH_CODE_32,
+        _PREFIX_LENGTH_CODE_MAX,
+        _PREFIX_LENGTH_CODE_INVALID = -EINVAL,
+} PrefixLengthCode;
+
+/* rfc8781: section 4 - Scaled Lifetime: 13-bit unsigned integer. PREFIX_LEN (Prefix Length Code): 3-bit unsigned integer */
+struct nd_opt_prefix64_info {
+        uint8_t type;
+        uint8_t length;
+        uint16_t lifetime_and_plc;
+        uint8_t prefix[12];
+} _packed_;
+
+int pref64_plc_to_prefix_length(uint16_t plc, uint8_t *ret);
+int pref64_prefix_length_to_plc(uint8_t prefixlen, uint8_t *ret);
+
+int ndisc_option_parse(
+                ICMP6Packet *p,
+                size_t offset,
+                uint8_t *ret_type,
+                size_t *ret_len,
+                const uint8_t **ret_opt);
diff --git a/src/libsystemd-network/ndisc-protocol.c b/src/libsystemd-network/ndisc-protocol.c
deleted file mode 100644 (file)
index d1f0819..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
-#include <netinet/icmp6.h>
-
-#include "ndisc-protocol.h"
-
-int ndisc_option_parse(
-                ICMP6Packet *p,
-                size_t offset,
-                uint8_t *ret_type,
-                size_t *ret_len,
-                const uint8_t **ret_opt) {
-
-        assert(p);
-
-        if (offset == p->raw_size)
-                return -ESPIPE; /* end of the packet */
-
-        if (offset > p->raw_size)
-                return -EBADMSG;
-
-        if (p->raw_size - offset < sizeof(struct nd_opt_hdr))
-                return -EBADMSG;
-
-        assert_cc(alignof(struct nd_opt_hdr) == 1);
-        const struct nd_opt_hdr *hdr = (const struct nd_opt_hdr*) (p->raw_packet + offset);
-        if (hdr->nd_opt_len == 0)
-                return -EBADMSG;
-
-        size_t len = hdr->nd_opt_len * 8;
-        if (p->raw_size - offset < len)
-                return -EBADMSG;
-
-        if (ret_type)
-                *ret_type = hdr->nd_opt_type;
-        if (ret_len)
-                *ret_len = len;
-        if (ret_opt)
-                *ret_opt = p->raw_packet + offset;
-
-        return 0;
-}
-
-static const uint8_t prefix_length_code_to_prefix_length[_PREFIX_LENGTH_CODE_MAX] = {
-        [PREFIX_LENGTH_CODE_96] = 96,
-        [PREFIX_LENGTH_CODE_64] = 64,
-        [PREFIX_LENGTH_CODE_56] = 56,
-        [PREFIX_LENGTH_CODE_48] = 48,
-        [PREFIX_LENGTH_CODE_40] = 40,
-        [PREFIX_LENGTH_CODE_32] = 32,
-};
-
-int pref64_plc_to_prefix_length(uint16_t plc, uint8_t *ret) {
-        plc &= PREF64_PLC_MASK;
-        if (plc >= _PREFIX_LENGTH_CODE_MAX)
-                return -EINVAL;
-
-        if (ret)
-                *ret = prefix_length_code_to_prefix_length[plc];
-        return 0;
-}
-
-int pref64_prefix_length_to_plc(uint8_t prefixlen, uint8_t *ret) {
-        assert(ret);
-
-        for (size_t i = 0; i < ELEMENTSOF(prefix_length_code_to_prefix_length); i++)
-                if (prefix_length_code_to_prefix_length[i] == prefixlen) {
-                        *ret = i;
-                        return 0;
-                }
-
-        return -EINVAL;
-}
diff --git a/src/libsystemd-network/ndisc-protocol.h b/src/libsystemd-network/ndisc-protocol.h
deleted file mode 100644 (file)
index dcb1b19..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-#include "icmp6-packet.h"
-#include "time-util.h"
-
-/* RFC 8781: PREF64 or (NAT64 prefix) */
-#define PREF64_SCALED_LIFETIME_MASK      0xfff8
-#define PREF64_PLC_MASK                  0x0007
-#define PREF64_MAX_LIFETIME_USEC         (65528 * USEC_PER_SEC)
-
-typedef enum PrefixLengthCode {
-        PREFIX_LENGTH_CODE_96,
-        PREFIX_LENGTH_CODE_64,
-        PREFIX_LENGTH_CODE_56,
-        PREFIX_LENGTH_CODE_48,
-        PREFIX_LENGTH_CODE_40,
-        PREFIX_LENGTH_CODE_32,
-        _PREFIX_LENGTH_CODE_MAX,
-        _PREFIX_LENGTH_CODE_INVALID = -EINVAL,
-} PrefixLengthCode;
-
-/* rfc8781: section 4 - Scaled Lifetime: 13-bit unsigned integer. PREFIX_LEN (Prefix Length Code): 3-bit unsigned integer */
-struct nd_opt_prefix64_info {
-        uint8_t type;
-        uint8_t length;
-        uint16_t lifetime_and_plc;
-        uint8_t prefix[12];
-} _packed_;
-
-int pref64_plc_to_prefix_length(uint16_t plc, uint8_t *ret);
-int pref64_prefix_length_to_plc(uint8_t prefixlen, uint8_t *ret);
-
-int ndisc_option_parse(
-                ICMP6Packet *p,
-                size_t offset,
-                uint8_t *ret_type,
-                size_t *ret_len,
-                const uint8_t **ret_opt);
index d6cec904b032a753c697254269a51e39543f7667..8091a5d882b09fa9ef3ce671bf3e138470fd0668 100644 (file)
@@ -10,7 +10,7 @@
 #include "sd-radv.h"
 
 #include "list.h"
-#include "ndisc-protocol.h"
+#include "ndisc-option.h"
 #include "network-common.h"
 #include "sparse-endian.h"
 #include "time-util.h"
index 4a95d7dba7a970ec92444fb5b5faaaceb336759e..309ef10195ca488a61adea434251f0ae6a7c1495 100644 (file)
@@ -14,7 +14,7 @@
 #include "memory-util.h"
 #include "missing_network.h"
 #include "ndisc-internal.h"
-#include "ndisc-protocol.h"
+#include "ndisc-option.h"
 #include "ndisc-router-internal.h"
 #include "strv.h"