]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Split out network byte order functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 19 Apr 2022 00:49:20 +0000 (19:49 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 19 Apr 2022 01:48:02 +0000 (20:48 -0500)
21 files changed:
src/lib/util/dbuff.h
src/lib/util/dbuff_tests.c
src/lib/util/dict_ext.h
src/lib/util/dict_wasm.mk [new file with mode: 0644]
src/lib/util/nbo.h [new file with mode: 0644]
src/lib/util/net.h
src/lib/util/value.c
src/listen/dns/proto_dns_udp.c
src/modules/rlm_eap/types/rlm_eap_fast/eap_fast.c
src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c
src/modules/rlm_icmp/rlm_icmp.c
src/protocols/arp/arp.h
src/protocols/dhcpv4/decode.c
src/protocols/dhcpv6/base.c
src/protocols/dhcpv6/decode.c
src/protocols/dhcpv6/dhcpv6.h
src/protocols/dns/base.c
src/protocols/dns/decode.c
src/protocols/dns/encode.c
src/protocols/internal/encode.c
src/protocols/tftp/decode.c

index bd2950d52b8f07a104469e9a195b93f6e4f03465..d64366346a2dd9fbc19ce21dcdc7b17442307b37 100644 (file)
@@ -32,7 +32,7 @@ extern "C" {
 #include <errno.h>
 #include <freeradius-devel/missing.h>
 #include <freeradius-devel/util/debug.h>
-#include <freeradius-devel/util/net.h>
+#include <freeradius-devel/util/nbo.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -1472,7 +1472,7 @@ static inline ssize_t _fr_dbuff_in_##_type(uint8_t **pos_p, fr_dbuff_t *out, _ty
 { \
        fr_assert(!out->is_const); \
        _FR_DBUFF_EXTEND_LOWAT_POS_OR_RETURN(pos_p, out, sizeof(_type##_t)); \
-       fr_net_from_##_type((*pos_p), num); \
+       fr_nbo_from_##_type((*pos_p), num); \
        return _fr_dbuff_set(pos_p, out, (*pos_p) + sizeof(_type##_t)); \
 }
 FR_DBUFF_PARSE_INT_DEF(uint16)
@@ -1546,11 +1546,12 @@ static inline ssize_t _fr_dbuff_in_double(uint8_t **pos_p, fr_dbuff_t *out, doub
 static inline ssize_t _fr_dbuff_in_uint64v(uint8_t **pos_p, fr_dbuff_t *dbuff, uint64_t num)
 {
        size_t  ret;
+       uint8_t swapped[sizeof(uint64_t)];
 
        ret = ROUND_UP_DIV((size_t)fr_high_bit_pos(num | 0x08), 8);
-       num = ntohll(num);
+       fr_nbo_from_uint64(swapped, num);
 
-       return _fr_dbuff_in_memcpy(pos_p, dbuff, ((uint8_t *)&num) + (sizeof(uint64_t) - ret), ret);
+       return _fr_dbuff_in_memcpy(pos_p, dbuff, (swapped + (sizeof(uint64_t) - ret)), ret);
 }
 
 /** Copy an integer value into a dbuff or marker using our internal variable length encoding
@@ -1712,7 +1713,7 @@ static inline ssize_t _fr_dbuff_out_##_type(_type##_t *out, uint8_t **pos_p, fr_
 { \
        fr_assert(out); \
        FR_DBUFF_EXTEND_LOWAT_OR_RETURN(in, sizeof(_type##_t)); \
-       *out = fr_net_to_##_type((*pos_p)); \
+       *out = fr_nbo_to_##_type((*pos_p)); \
        return _fr_dbuff_set(pos_p, in, (*pos_p) + sizeof(_type##_t)); \
 }
 
@@ -1769,7 +1770,7 @@ static inline ssize_t _fr_dbuff_out_uint64v(uint64_t *num, uint8_t **pos_p, fr_d
        slen = _fr_dbuff_out_memcpy(((uint8_t *) num) + (8 - length), pos_p, dbuff, length);
        if (slen <= 0) return slen;
 
-       *num = fr_net_to_uint64((uint8_t const *)num);
+       *num = fr_nbo_to_uint64((uint8_t const *)num);
        return length;
 }
 
@@ -1808,7 +1809,7 @@ static inline ssize_t _fr_dbuff_out_int64v(int64_t *num, uint8_t **pos_p, fr_dbu
        if (slen <= 0) return slen;
 
        if (msb & 0x80) memset(((uint8_t *)num), 0xff, sizeof(*num) - length);
-       *num = fr_net_to_int64((uint8_t const *)num);
+       *num = fr_nbo_to_int64((uint8_t const *)num);
 
        return length;
 }
index 1d52876ba8f041a4b59e7042b1dcca5e4c8b5b46..2be5da8a028ce5869791d324ab08c3b7bf005b08 100644 (file)
@@ -93,7 +93,7 @@ static void test_dbuff_max(void)
  *
  * @note Passing constants to fr_dbuff_in() as it is written results in
  *      warnings about narrowing casts on the constants--but those casts are in
- *      the underlying inlined fr_net_from*() functions. They have to be there;
+ *      the underlying inlined fr_nbo_from*() functions. They have to be there;
  *      that's how those functions work. (The tests worked despite the warnings.)
  *      Using variables avoids the warnings, at least with the compile options
  *      the build system uses by default.
index 1535e2effcb1f6791470fb06f953341ce833d402..7ab2e4e7e3bc8020de1e9603b7d265d563b639cf 100644 (file)
@@ -26,6 +26,7 @@ RCSIDH(dict_ext_h, "$Id$")
 
 #include <freeradius-devel/util/dict.h>
 #include <freeradius-devel/util/ext.h>
+#include <freeradius-devel/util/hash.h>
 
 #include <limits.h>
 
diff --git a/src/lib/util/dict_wasm.mk b/src/lib/util/dict_wasm.mk
new file mode 100644 (file)
index 0000000..48f8336
--- /dev/null
@@ -0,0 +1,11 @@
+TARGET         := dict.wasm
+
+SRC_CC          := emcc
+SRC_CFLAGS      := ''
+
+SOURCES                := dict_ext.c \
+                  dict_fixup.c \
+                  dict_print.c \
+                  dict_tokenize.c \
+                  dict_unknown.c \
+                  dict_util.c \
diff --git a/src/lib/util/nbo.h b/src/lib/util/nbo.h
new file mode 100644 (file)
index 0000000..83de015
--- /dev/null
@@ -0,0 +1,233 @@
+#pragma once
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/** Structures and functions for converting integers to/from network byte order
+ *
+ * @file src/lib/util/nbo.h
+ *
+ * @author Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ * @copyright 2022 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ */
+RCSIDH(nbo_h, "$Id$")
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <freeradius-devel/util/misc.h>
+
+/** Write out an unsigned 16bit integer in wire format (big endian)
+ *
+ * @param[out] out     Where to write the integer.
+ * @param[in] num      to encode.
+ */
+static inline void fr_nbo_from_uint16(uint8_t out[static sizeof(uint16_t)], uint16_t num)
+{
+       out[0] = (num >> 8) & 0xff;
+       out[1] = num & 0xff;
+}
+
+/** Write out an unsigned 24bit integer in wire format (big endian)
+ *
+ * @param[out] out     Where to write the integer.
+ * @param[in] num      to encode.
+ */
+static inline void fr_nbo_from_uint24(uint8_t out[static 3], uint32_t num)
+{
+       out[0] = (num >> 16) & 0xff;
+       out[1] = (num >> 8) & 0xff;
+       out[2] = num & 0xff;
+}
+
+/** Write out an unsigned 32bit integer in wire format (big endian)
+ *
+ * @param[out] out     Where to write the integer.
+ * @param[in] num      to encode.
+ */
+static inline void fr_nbo_from_uint32(uint8_t out[static sizeof(uint32_t)], uint32_t num)
+{
+       fr_nbo_from_uint16(out, (uint16_t) (num >> 16));
+       fr_nbo_from_uint16(out + sizeof(uint16_t), (uint16_t) num);
+}
+
+/** Write out an unsigned 64bit integer in wire format (big endian)
+ *
+ * @param[out] out     Where to write the integer.
+ * @param[in] num      to encode.
+ */
+static inline void fr_nbo_from_uint64(uint8_t out[static sizeof(uint64_t)], uint64_t num)
+{
+       fr_nbo_from_uint32(out, (uint32_t)(num >> 32));
+       fr_nbo_from_uint32(out + sizeof(uint32_t), (uint32_t)num);
+}
+
+/** Write out an signed 16bit integer in wire format (big endian)
+ *
+ * @param[out] out     Where to write the integer.
+ * @param[in] num      to encode.
+ */
+static inline void fr_nbo_from_int16(uint8_t out[static sizeof(int16_t)], int16_t num)
+{
+       out[0] = (num >> 8) & 0xff;
+       out[1] = num & 0xff;
+}
+
+/** Write out an signed 32bit integer in wire format (big endian)
+ *
+ * @param[out] out     Where to write the integer.
+ * @param[in] num      to encode.
+ */
+static inline void fr_nbo_from_int32(uint8_t out[static sizeof(int32_t)], int32_t num)
+{
+       fr_nbo_from_uint16(out, (int16_t) (num >> 16));
+       fr_nbo_from_uint16(out + sizeof(int16_t), (int16_t) num);
+}
+
+/** Write out an signed 64bit integer in wire format (big endian)
+ *
+ * @param[out] out     Where to write the integer.
+ * @param[in] num      to encode.
+ */
+static inline void fr_nbo_from_int64(uint8_t out[static sizeof(uint64_t)], uint64_t num)
+{
+       fr_nbo_from_uint32(out, (int32_t)(num >> 32));
+       fr_nbo_from_uint32(out + sizeof(int32_t), (int32_t)num);
+}
+
+/** Write out an unsigned 64bit integer in wire format using the fewest bytes possible
+ *
+ * @param[out] out     Where to write big endian encoding of num.
+ *                     Should be at least 8 bytes.
+ * @param[in] num      Number to encode.
+ * @return the number of bytes written to out.
+ */
+static inline size_t fr_nbo_from_uint64v(uint8_t out[static sizeof(uint64_t)], uint64_t num)
+{
+       size_t ret;
+       uint8_t swapped[sizeof(uint64_t)];
+
+       ret = ROUND_UP_DIV((size_t)fr_high_bit_pos(num | 0x80), 8);
+
+       fr_nbo_from_uint64(swapped, num);
+       memcpy(out, (swapped + (sizeof(uint64_t) - ret)), ret); /* aligned */
+
+       return ret;
+}
+
+/** Read an unsigned 16bit integer from wire format (big endian)
+ *
+ * @param[in] data     To convert to a 16bit unsigned integer of native endianness.
+ * @return a 16 bit unsigned integer of native endianness.
+ */
+static inline uint16_t fr_nbo_to_uint16(uint8_t const data[static sizeof(uint16_t)])
+{
+       return (((uint16_t)data[0]) << 8) | data[1];
+}
+
+/** Read an unsigned 24bit integer from wire format (big endian)
+ *
+ * @param[in] data     To convert to a 24bit unsigned integer of native endianness.
+ * @return a 24 bit unsigned integer of native endianness.
+ */
+static inline uint32_t fr_nbo_to_uint24(uint8_t const data[static 3])
+{
+       return (((uint32_t)data[0]) << 16) | (((uint32_t)data[1]) << 8) | data[2];
+}
+
+/** Read an unsigned 32bit integer from wire format (big endian)
+ *
+ * @param[in] data     To convert to a 32bit unsigned integer of native endianness.
+ * @return a 32 bit unsigned integer of native endianness.
+ */
+static inline uint32_t fr_nbo_to_uint32(uint8_t const data[static sizeof(uint32_t)])
+{
+       return ((uint32_t)fr_nbo_to_uint16(data) << 16) | fr_nbo_to_uint16(data + sizeof(uint16_t));
+}
+
+/** Read an unsigned 64bit integer from wire format (big endian)
+ *
+ * @param[in] data     To convert to a 64bit unsigned integer of native endianness.
+ * @return a 64 bit unsigned integer of native endianness.
+ */
+static inline uint64_t fr_nbo_to_uint64(uint8_t const data[static sizeof(uint64_t)])
+{
+       return ((uint64_t)fr_nbo_to_uint32(data) << 32) | fr_nbo_to_uint32(data + sizeof(uint32_t));
+}
+
+/*
+ * To get signed integers, simply cast.
+ */
+#define fr_nbo_to_int16(_x)    ((int16_t) fr_nbo_to_uint16(_x))
+#define fr_nbo_to_int32(_x)    ((int32_t) fr_nbo_to_uint32(_x))
+#define fr_nbo_to_int64(_x)    ((int64_t) fr_nbo_to_uint64(_x))
+
+
+/** Read an unsigned 64bit integer from wire format (big endian) with a variable length encoding
+ *
+ * @param[in] data     Buffer containing the number.
+ * @param[in] data_len Length of number.
+ * @return a 64 bit unsigned integer of native endianness.
+ */
+static inline uint64_t fr_nbo_to_uint64v(uint8_t const *data, size_t data_len)
+{
+       uint64_t num = 0;
+       uint64_t nbo;
+
+       if (unlikely(data_len > sizeof(uint64_t))) return 0;
+
+       /*
+        *      Copy at an offset into memory
+        *      allocated for the uin64_t
+        */
+       memcpy(((uint8_t *)&num) + (sizeof(uint64_t) - data_len), data, data_len);      /* aligned */
+       fr_nbo_from_uint64((uint8_t *)&nbo, num);
+
+       return nbo;
+}
+
+static inline uint64_t fr_nbo_to_int64v(uint8_t const *data, size_t data_len)
+{
+       int64_t num = 0;
+       uint64_t nbo;
+
+       if (unlikely(data_len > sizeof(uint64_t))) return 0;
+
+       /*
+        *      Copy at an offset into memory
+        *      allocated for the uin64_t
+        */
+       memcpy(((uint8_t *)&num) + (sizeof(uint64_t) - data_len), data, data_len);      /* aligned */
+       if (*data & 0x80) memset(((uint8_t *)&num) + data_len, 0xff, sizeof(num) - data_len);
+
+       fr_nbo_from_uint64((uint8_t *)&nbo, num);
+
+       return nbo;
+}
+
+/** Convert bits (as in prefix length) to bytes, rounding up.
+ *
+ * @param bits number of bits in the prefix
+ * @return number of bytes taken to store the prefix
+ */
+static inline unsigned int fr_bytes_from_bits(unsigned int bits)
+{
+       return (bits + 7) >> 3;
+}
+
+#ifdef __cplusplus
+}
+#endif
index 5de3433507f55d697ec853864c2dc8336be0ec8f..899696e4002696895ff825487cfd97a2d5fd7d67 100644 (file)
@@ -155,197 +155,6 @@ int               fr_udp_header_check(uint8_t const *data, uint16_t remaining, ip_header_t co
 uint16_t       fr_ip_header_checksum(uint8_t const *data, uint8_t ihl);
 uint16_t       fr_ip6_pesudo_header_checksum(struct in6_addr const *src, struct in6_addr const *dst, uint16_t ip_len, uint8_t ip_next);
 
-/** Write out an unsigned 16bit integer in wire format (big endian)
- *
- * @param[out] out     Where to write the integer.
- * @param[in] num      to encode.
- */
-static inline void fr_net_from_uint16(uint8_t out[static sizeof(uint16_t)], uint16_t num)
-{
-       out[0] = (num >> 8) & 0xff;
-       out[1] = num & 0xff;
-}
-
-/** Write out an unsigned 24bit integer in wire format (big endian)
- *
- * @param[out] out     Where to write the integer.
- * @param[in] num      to encode.
- */
-static inline void fr_net_from_uint24(uint8_t out[static 3], uint32_t num)
-{
-       out[0] = (num >> 16) & 0xff;
-       out[1] = (num >> 8) & 0xff;
-       out[2] = num & 0xff;
-}
-
-/** Write out an unsigned 32bit integer in wire format (big endian)
- *
- * @param[out] out     Where to write the integer.
- * @param[in] num      to encode.
- */
-static inline void fr_net_from_uint32(uint8_t out[static sizeof(uint32_t)], uint32_t num)
-{
-       fr_net_from_uint16(out, (uint16_t) (num >> 16));
-       fr_net_from_uint16(out + sizeof(uint16_t), (uint16_t) num);
-}
-
-/** Write out an unsigned 64bit integer in wire format (big endian)
- *
- * @param[out] out     Where to write the integer.
- * @param[in] num      to encode.
- */
-static inline void fr_net_from_uint64(uint8_t out[static sizeof(uint64_t)], uint64_t num)
-{
-       fr_net_from_uint32(out, (uint32_t)(num >> 32));
-       fr_net_from_uint32(out + sizeof(uint32_t), (uint32_t)num);
-}
-
-/** Write out an signed 16bit integer in wire format (big endian)
- *
- * @param[out] out     Where to write the integer.
- * @param[in] num      to encode.
- */
-static inline void fr_net_from_int16(uint8_t out[static sizeof(int16_t)], int16_t num)
-{
-       out[0] = (num >> 8) & 0xff;
-       out[1] = num & 0xff;
-}
-
-/** Write out an signed 32bit integer in wire format (big endian)
- *
- * @param[out] out     Where to write the integer.
- * @param[in] num      to encode.
- */
-static inline void fr_net_from_int32(uint8_t out[static sizeof(int32_t)], int32_t num)
-{
-       fr_net_from_uint16(out, (int16_t) (num >> 16));
-       fr_net_from_uint16(out + sizeof(int16_t), (int16_t) num);
-}
-
-/** Write out an signed 64bit integer in wire format (big endian)
- *
- * @param[out] out     Where to write the integer.
- * @param[in] num      to encode.
- */
-static inline void fr_net_from_int64(uint8_t out[static sizeof(uint64_t)], uint64_t num)
-{
-       fr_net_from_uint32(out, (int32_t)(num >> 32));
-       fr_net_from_uint32(out + sizeof(int32_t), (int32_t)num);
-}
-
-/** Write out an unsigned 64bit integer in wire format using the fewest bytes possible
- *
- * @param[out] out     Where to write big endian encoding of num.
- *                     Should be at least 8 bytes.
- * @param[in] num      Number to encode.
- * @return the number of bytes written to out.
- */
-static inline size_t fr_net_from_uint64v(uint8_t out[static sizeof(uint64_t)], uint64_t num)
-{
-       size_t ret;
-
-       ret = ROUND_UP_DIV((size_t)fr_high_bit_pos(num | 0x80), 8);
-       num = ntohll(num);
-       memcpy(out, ((uint8_t *)&num) + (sizeof(uint64_t) - ret), ret); /* aligned */
-
-       return ret;
-}
-
-/** Read an unsigned 16bit integer from wire format (big endian)
- *
- * @param[in] data     To convert to a 16bit unsigned integer of native endianness.
- * @return a 16 bit unsigned integer of native endianness.
- */
-static inline uint16_t fr_net_to_uint16(uint8_t const data[static sizeof(uint16_t)])
-{
-       return (((uint16_t)data[0]) << 8) | data[1];
-}
-
-/** Read an unsigned 24bit integer from wire format (big endian)
- *
- * @param[in] data     To convert to a 24bit unsigned integer of native endianness.
- * @return a 24 bit unsigned integer of native endianness.
- */
-static inline uint32_t fr_net_to_uint24(uint8_t const data[static 3])
-{
-       return (((uint32_t)data[0]) << 16) | (((uint32_t)data[1]) << 8) | data[2];
-}
-
-/** Read an unsigned 32bit integer from wire format (big endian)
- *
- * @param[in] data     To convert to a 32bit unsigned integer of native endianness.
- * @return a 32 bit unsigned integer of native endianness.
- */
-static inline uint32_t fr_net_to_uint32(uint8_t const data[static sizeof(uint32_t)])
-{
-       return ((uint32_t)fr_net_to_uint16(data) << 16) | fr_net_to_uint16(data + sizeof(uint16_t));
-}
-
-/** Read an unsigned 64bit integer from wire format (big endian)
- *
- * @param[in] data     To convert to a 64bit unsigned integer of native endianness.
- * @return a 64 bit unsigned integer of native endianness.
- */
-static inline uint64_t fr_net_to_uint64(uint8_t const data[static sizeof(uint64_t)])
-{
-       return ((uint64_t)fr_net_to_uint32(data) << 32) | fr_net_to_uint32(data + sizeof(uint32_t));
-}
-
-/*
- * To get signed integers, simply cast.
- */
-#define fr_net_to_int16(_x)    ((int16_t) fr_net_to_uint16(_x))
-#define fr_net_to_int32(_x)    ((int32_t) fr_net_to_uint32(_x))
-#define fr_net_to_int64(_x)    ((int64_t) fr_net_to_uint64(_x))
-
-
-/** Read an unsigned 64bit integer from wire format (big endian) with a variable length encoding
- *
- * @param[in] data     Buffer containing the number.
- * @param[in] data_len Length of number.
- * @return a 64 bit unsigned integer of native endianness.
- */
-static inline uint64_t fr_net_to_uint64v(uint8_t const *data, size_t data_len)
-{
-       uint64_t num = 0;
-
-       if (unlikely(data_len > sizeof(uint64_t))) return 0;
-
-       /*
-        *      Copy at an offset into memory
-        *      allocated for the uin64_t
-        */
-       memcpy(((uint8_t *)&num) + (sizeof(uint64_t) - data_len), data, data_len);      /* aligned */
-       return ntohll(num);
-}
-
-static inline uint64_t fr_net_to_int64v(uint8_t const *data, size_t data_len)
-{
-       int64_t num = 0;
-
-       if (unlikely(data_len > sizeof(uint64_t))) return 0;
-
-       /*
-        *      Copy at an offset into memory
-        *      allocated for the uin64_t
-        */
-       memcpy(((uint8_t *)&num) + (sizeof(uint64_t) - data_len), data, data_len);      /* aligned */
-
-       if (*data & 0x80) memset(((uint8_t *)&num) + data_len, 0xff, sizeof(num) - data_len);
-
-       return ntohll(num);
-}
-
-/** Convert bits (as in prefix length) to bytes, rounding up.
- *
- * @param bits number of bits in the prefix
- * @return number of bytes taken to store the prefix
- */
-static inline unsigned int fr_bytes_from_bits(unsigned int bits)
-{
-       return (bits + 7) >> 3;
-}
-
 #ifdef __cplusplus
 }
 #endif
index c567c6396506c0fe08b569bfcc8aed99d171f66e..988b7be3d59840f30732c05675a57a33eaa87c2c 100644 (file)
@@ -2575,7 +2575,7 @@ static inline int fr_value_box_cast_to_ethernet(TALLOC_CTX *ctx, fr_value_box_t
        case FR_TYPE_UINT64: {
                uint8_t array[8];
 
-               fr_net_from_uint64(array, src->vb_uint64);
+               fr_nbo_from_uint64(array, src->vb_uint64);
 
                /*
                 *      For OUIs in the DB.
@@ -2929,7 +2929,7 @@ static inline int fr_value_box_cast_to_integer(TALLOC_CTX *ctx, fr_value_box_t *
                }
 
                fr_value_box_init(dst, dst_type, dst_enumv, src->tainted);
-               dst->vb_uint64 = fr_net_to_uint64(&src->vb_ifid[0]);
+               dst->vb_uint64 = fr_nbo_to_uint64(&src->vb_ifid[0]);
                return 0;
        }
 
index 13c75758e136469e24d9aebf68206d47847623ee..f5ed51c65663789b2d1e7ca3cacba66ba9a909de 100644 (file)
@@ -172,7 +172,7 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
         *      proto_dns sets the priority
         */
 
-       xid = fr_net_to_uint16(buffer);
+       xid = fr_nbo_to_uint16(buffer);
 
        /*
         *      Print out what we received.
index 1f9b3d2aa0aa62684877068d3165bea88a1268f0..3c33cb4b1984308d7bf47edd3eff8bb0e5975d0a 100644 (file)
@@ -441,9 +441,9 @@ ssize_t eap_fast_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_
                uint16_t        len;
                fr_pair_t       *vp;
 
-               attr = fr_net_to_uint16(p) & EAP_FAST_TLV_TYPE;
+               attr = fr_nbo_to_uint16(p) & EAP_FAST_TLV_TYPE;
                p += 2;
-               len = fr_net_to_uint16(p);
+               len = fr_nbo_to_uint16(p);
                p += 2;
 
                da = fr_dict_attr_child_by_num(parent, attr);
index 3a4eba536010a93c8b6649ff450f24b619000c79..cf5e9ed1742ca5917a3022d1acbda975d15a087d 100644 (file)
@@ -175,13 +175,13 @@ static ssize_t eap_ttls_decode_pair(request_t *request, TALLOC_CTX *ctx, fr_dcur
                RDEBUG3("%04zu %02x%02x%02x%02x %02x%02x%02x%02x ...", p - data,
                        p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
 
-               attr = fr_net_to_uint32(p);
+               attr = fr_nbo_to_uint32(p);
                p += 4;
 
                flags = p[0];
                p++;
 
-               value_len = fr_net_to_uint64v(p, 3);    /* Yes, that is a 24 bit length field */
+               value_len = fr_nbo_to_uint64v(p, 3);    /* Yes, that is a 24 bit length field */
                p += 3;
 
                if (value_len < 8) {
@@ -207,7 +207,7 @@ static ssize_t eap_ttls_decode_pair(request_t *request, TALLOC_CTX *ctx, fr_dcur
                 *      Do we have a vendor field?
                 */
                if (flags & FR_DIAMETER_AVP_FLAG_VENDOR) {
-                       vendor = fr_net_to_uint32(p);
+                       vendor = fr_nbo_to_uint32(p);
                        p += 4;
                        value_len -= 4; /* -= 4 for the vendor ID field */
 
index 16e6cbece6757ccdffeaa122870c516f5644449e..f293a52a7c7c92bb4155fb6a6f8aec790b32611e 100644 (file)
@@ -93,7 +93,7 @@ static uint16_t icmp_checksum(uint8_t *data, size_t data_len, uint16_t checksum)
        p = data;
        end = data + data_len;
        while (p < end) {
-               sum += fr_net_to_uint16(p);      /* type / code */
+               sum += fr_nbo_to_uint16(p);      /* type / code */
                p += 2;
        }
 
index 7651dffbd54473f9161d2bb2857363bb57e661c5..0f92d81d01697f855af9266fe68f787bf00c4c69 100644 (file)
@@ -26,6 +26,7 @@
 #include <freeradius-devel/util/packet.h>
 #include <freeradius-devel/util/rand.h>
 #include <freeradius-devel/util/log.h>
+#include <freeradius-devel/util/net.h>
 
 #include <freeradius-devel/protocol/arp/dictionary.h>
 #include <freeradius-devel/protocol/arp/rfc826.h>
index 2de6cccb275d9be4ac2793024f610da66e2b4b20..04dee0b150763f483b145a6ccec31e781ce8a946 100644 (file)
@@ -181,8 +181,8 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t
 
                        if (data_len != 8) goto raw;
 
-                       ipaddr = fr_net_to_uint32(p);
-                       mask = fr_net_to_uint32(p + 4);
+                       ipaddr = fr_nbo_to_uint32(p);
+                       mask = fr_nbo_to_uint32(p + 4);
                        p += 8;
 
                        /*
@@ -236,14 +236,14 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t
                                mask <<= (32 - vp->vp_ip.prefix);
 
                                if (*p > 24) {
-                                       ipaddr = fr_net_to_uint32(p + 1);
+                                       ipaddr = fr_nbo_to_uint32(p + 1);
 
                                } else if (*p > 16) {
-                                       ipaddr = fr_net_to_uint24(p + 1);
+                                       ipaddr = fr_nbo_to_uint24(p + 1);
                                        ipaddr <<= 8;
 
                                } else if (*p > 8) {
-                                       ipaddr = fr_net_to_uint16(p + 1);
+                                       ipaddr = fr_nbo_to_uint16(p + 1);
                                        ipaddr <<= 16;
 
                                } else { /* 1..8 */
@@ -668,7 +668,7 @@ next:
                return data_len + 2; /* decoded the whole thing */
        }
 
-       pen = fr_net_to_uint32(p);
+       pen = fr_nbo_to_uint32(p);
 
        /*
         *      Verify that the parent (which should be a VSA)
index 4a9fe6b9e28b8a5856404ef0f5a32da34b069404..1d9f7fcb739d1a9d4e1527571e5768ec4b5f0308 100644 (file)
@@ -352,7 +352,7 @@ static bool verify_to_client(uint8_t const *packet, size_t packet_len, fr_dhcpv6
 
        switch (packet[0]) {
        case FR_PACKET_TYPE_VALUE_ADVERTISE:
-               transaction_id = fr_net_to_uint24(&packet[1]);
+               transaction_id = fr_nbo_to_uint24(&packet[1]);
                if (transaction_id != packet_ctx->transaction_id) {
                fail_tid:
                        fr_strerror_const("Transaction ID does not match");
@@ -390,7 +390,7 @@ static bool verify_to_client(uint8_t const *packet, size_t packet_len, fr_dhcpv6
                return true;
 
        case FR_PACKET_TYPE_VALUE_REPLY:
-               transaction_id = fr_net_to_uint24(&packet[1]);
+               transaction_id = fr_nbo_to_uint24(&packet[1]);
                if (transaction_id != packet_ctx->transaction_id) goto fail_tid;
 
                if (!fr_dhcpv6_option_find(options, end, FR_SERVER_ID)) goto fail_sid;
@@ -449,7 +449,7 @@ static bool verify_to_client(uint8_t const *packet, size_t packet_len, fr_dhcpv6
                return verify_to_client(option + 4, DHCPV6_GET_OPTION_LEN(option), packet_ctx);
 
        case FR_DHCPV6_LEASE_QUERY_REPLY:
-               transaction_id = fr_net_to_uint24(&packet[1]);
+               transaction_id = fr_nbo_to_uint24(&packet[1]);
                if (transaction_id != packet_ctx->transaction_id) goto fail_tid;
 
                if (!fr_dhcpv6_option_find(options, end, FR_SERVER_ID)) goto fail_sid;
@@ -840,7 +840,7 @@ ssize_t     fr_dhcpv6_encode(fr_dbuff_t *dbuff, uint8_t const *original, size_t leng
                        FR_DBUFF_IN_MEMCPY_RETURN(&frame_dbuff, vp->vp_octets, DHCPV6_TRANSACTION_ID_LEN);
                } else {
                        uint8_t id[DHCPV6_TRANSACTION_ID_LEN];
-                       fr_net_from_uint24(id, fr_rand());
+                       fr_nbo_from_uint24(id, fr_rand());
                        FR_DBUFF_IN_MEMCPY_RETURN(&frame_dbuff, id, sizeof(id)); /* Need 24 bits of the 32bit integer */
                }
                break;
@@ -945,9 +945,9 @@ static void dhcpv6_print_hex(FILE *fp, uint8_t const *packet, size_t packet_len,
                        break;
                }
 
-               length = fr_net_to_uint16(option + 2);
+               length = fr_nbo_to_uint16(option + 2);
                fprintf(fp, "%.*s", depth + 1, tabs);
-               fprintf(fp, "%04x %04x\t", fr_net_to_uint16(option), length);
+               fprintf(fp, "%04x %04x\t", fr_nbo_to_uint16(option), length);
 
                if ((option + 4 + length) > end) {
                        print_hex_data(fp, option + 4, end - (option + 4), depth + 3);
index 6c8e96fb0c89bdb5ead54d329f7f199114ecc695..5308bdd201f70004d9998c1c4c43795a30efeeef 100644 (file)
@@ -332,7 +332,7 @@ static ssize_t decode_array(TALLOC_CTX *ctx, fr_pair_list_t *out,
        while (p < end) {
                if ((end - p) < 2) goto raw;
 
-               element_len = fr_net_to_uint16(p);
+               element_len = fr_nbo_to_uint16(p);
 
                if ((size_t) (end - p) < (((size_t) element_len) + 2)) goto raw;
 
index 3d500ced124e24b5ce6f4727276069282f9d4b30..a85fbb19d2de314a6c4d73d8ac111ef6e41f6f5f 100644 (file)
@@ -46,8 +46,8 @@ extern size_t const fr_dhcpv6_attr_sizes[FR_TYPE_MAX + 1][2];
 #define DHCPV6_RELAY_HDR_LEN           (DHCPV6_MSG_TYPE_LEN + DHCPV6_HOP_COUNT_LEN + DHCPV6_LINK_ADDRESS_LEN + DHCPV6_PEER_ADDRESS_LEN)
 #define DHCPV6_OPT_HDR_LEN             (sizeof(uint16_t) * 2)
 
-#define DHCPV6_GET_OPTION_NUM(_x)      fr_net_to_uint16(_x)
-#define DHCPV6_GET_OPTION_LEN(_x)      fr_net_to_uint16((_x) + 2)
+#define DHCPV6_GET_OPTION_NUM(_x)      fr_nbo_to_uint16(_x)
+#define DHCPV6_GET_OPTION_LEN(_x)      fr_nbo_to_uint16((_x) + 2)
 
 #define DHCPV6_MAX_RELAY_NESTING       10
 
index ee1d54767afa6c3801bb201f8a907dedb376cb11..b25722d2084fd8e2ddd0b4a7c41b4d67e52e6ea1 100644 (file)
@@ -85,7 +85,7 @@ static bool fr_dns_tlv_ok(uint8_t const *p, uint8_t const *end, fr_dns_decode_fa
                        return false;
                }
 
-               len = fr_net_to_uint16(p + 2);
+               len = fr_nbo_to_uint16(p + 2);
                if ((p + 4 + len) > end) {
                        DECODE_FAIL(TLV_OVERFLOWS_RR);
                        return false;
@@ -120,7 +120,7 @@ bool fr_dns_packet_ok(uint8_t const *packet, size_t packet_len, bool query, fr_d
                return false;
        }
 
-       qdcount = fr_net_to_uint16(packet + 4);
+       qdcount = fr_nbo_to_uint16(packet + 4);
 
        if (query) {
                /*
@@ -135,11 +135,11 @@ bool fr_dns_packet_ok(uint8_t const *packet, size_t packet_len, bool query, fr_d
                        DECODE_FAIL(NO_QUESTIONS);
                        return false;
                }
-               if (fr_net_to_uint16(packet + 6) != 0) {
+               if (fr_nbo_to_uint16(packet + 6) != 0) {
                        DECODE_FAIL(NS_IN_QUESTION);
                        return false;
                }
-               if (fr_net_to_uint16(packet + 8) != 0) {
+               if (fr_nbo_to_uint16(packet + 8) != 0) {
                        DECODE_FAIL(ANSWERS_IN_QUESTION);
                        return false;
                }
@@ -152,7 +152,7 @@ bool fr_dns_packet_ok(uint8_t const *packet, size_t packet_len, bool query, fr_d
                 */
        }
 
-       expected = fr_net_to_uint16(packet + 4) + fr_net_to_uint16(packet + 6) + fr_net_to_uint16(packet + 8) + fr_net_to_uint16(packet + 10);
+       expected = fr_nbo_to_uint16(packet + 4) + fr_nbo_to_uint16(packet + 6) + fr_nbo_to_uint16(packet + 8) + fr_nbo_to_uint16(packet + 10);
        count = 0;
 
        p = packet + DNS_HDR_LEN;
@@ -329,7 +329,7 @@ bool fr_dns_packet_ok(uint8_t const *packet, size_t packet_len, bool query, fr_d
                        return false;
                }
 
-               len = fr_net_to_uint16(p);
+               len = fr_nbo_to_uint16(p);
                if (len == 0) {
                        DECODE_FAIL(ZERO_RR_LEN);
                        return false;
index 45d55d4c42d68db1e34dcf747beeb4a0fed6a1d3..f69b1135cefbfbe205bd40e874f477767560facd 100644 (file)
@@ -274,7 +274,7 @@ static ssize_t decode_array(TALLOC_CTX *ctx, fr_pair_list_t *out,
                        break;
                }
 
-               element_len = fr_net_to_uint16(p);
+               element_len = fr_nbo_to_uint16(p);
                if ((p + 2 + element_len) > end) {
                        goto raw;
                }
@@ -365,8 +365,8 @@ static ssize_t decode_dns_labels(TALLOC_CTX *ctx, fr_pair_list_t *out,
 }
 
 
-#define DNS_GET_OPTION_NUM(_x) fr_net_to_uint16(_x)
-#define DNS_GET_OPTION_LEN(_x) fr_net_to_uint16((_x) + 2)
+#define DNS_GET_OPTION_NUM(_x) fr_nbo_to_uint16(_x)
+#define DNS_GET_OPTION_LEN(_x) fr_nbo_to_uint16((_x) + 2)
 
 static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out,
                              fr_dict_attr_t const *parent,
@@ -483,7 +483,7 @@ static ssize_t decode_record(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_
        int i, count;
        uint8_t const *p = rr;
 
-       count = fr_net_to_uint16(counter);
+       count = fr_nbo_to_uint16(counter);
        FR_PROTO_TRACE("Decoding %u of %s", count, attr->name);
        for (i = 0; i < count; i++) {
                ssize_t slen;
index 7f97b01841b474cdf590fb21b9c60469ba33000a..2e5c962163cf9d238d35fa2b20472d1a3d4d6e17 100644 (file)
@@ -597,7 +597,7 @@ static ssize_t encode_record(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, fr_pair
                if (!vp) break;
        }
 
-       fr_net_from_uint16(counter, count);
+       fr_nbo_from_uint16(counter, count);
        FR_PROTO_TRACE("      %s encoded %d records", attr->name, count);
 
        return fr_dbuff_set(dbuff, &work_dbuff);
index a17041493c87197103fe76220e37298fb77cecfa..e42e502007fc815efac5322203ff0aff86bd41e5 100644 (file)
@@ -231,7 +231,7 @@ static ssize_t internal_encode(fr_dbuff_t *dbuff,
         *      the function.
         */
        vlen = fr_dbuff_used(&value_dbuff);
-       flen = (ssize_t) fr_net_from_uint64v(buff, vlen);
+       flen = (ssize_t) fr_nbo_from_uint64v(buff, vlen);
 
        /*
         *      Ugh, it's a long one, need to move the data.
index 5987bb6aa8d84ef6730e86ecb0addd5467974d15..40be8293b6a5b52d06544d366e0994d579e354ad 100644 (file)
@@ -89,7 +89,7 @@ int fr_tftp_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, si
        end = (data + data_len);
 
        /* Opcode */
-       opcode = fr_net_to_uint16(p);
+       opcode = fr_nbo_to_uint16(p);
        vp = fr_pair_afrom_da(ctx, attr_tftp_opcode);
        if (!vp) goto error;
 
@@ -202,7 +202,7 @@ int fr_tftp_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, si
                vp = fr_pair_afrom_da(ctx, attr_tftp_block);
                if (!vp) goto error;
 
-               vp->vp_uint16 = fr_net_to_uint16(p);
+               vp->vp_uint16 = fr_nbo_to_uint16(p);
 
                fr_pair_append(out, vp);
 
@@ -244,7 +244,7 @@ int fr_tftp_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, si
                vp = fr_pair_afrom_da(ctx, attr_tftp_error_code);
                if (!vp) goto error;
 
-               vp->vp_uint16 = fr_net_to_uint16(p);
+               vp->vp_uint16 = fr_nbo_to_uint16(p);
 
                fr_pair_append(out, vp);