about summary refs log tree commit diff
path: root/shared/nm-utils/unaligned.h
diff options
context:
space:
mode:
authorSebastien Bacher <seb128@ubuntu.com>2018-08-24 11:00:09 +0200
committerSebastien Bacher <seb128@ubuntu.com>2018-08-24 11:06:47 +0200
commitb7db94545968c37886b7111d8c85f62eb063fbb4 (patch)
tree7c2aedd497b1fdcb26bf9d49f98cc63a530baf2e /shared/nm-utils/unaligned.h
parent9d5cdc3adde9e7e57bf5a0e754e563b6a9e8e513 (diff)
parentcaf1db9d6fbc056cc6c76a24574890f6c7895f3d (diff)
Import Debian changes 1.12.2-0ubuntu3
network-manager (1.12.2-0ubuntu3) cosmic; urgency=medium

  * debian/rules:
    - use --with-libnm-glib, the default reversed since that's a legacy
      library but we still need it for unity-control-center

network-manager (1.12.2-0ubuntu2) cosmic; urgency=medium

  * debian/patches/git-newglib-test.patch:
    - backport upstream commit to fix the tests with the new glib 

network-manager (1.12.2-0ubuntu1) cosmic; urgency=medium

  * New upstream version
  * d/p/libnm-register-empty-NMClient-and-NetworkManager-when-loa.patch,
    d/p/e91f1a7d2a6b8400b6b331d5b72287dcb5164a39.patch,
    d/p/git_thunderbolt_connect.patch:
    - removed, those changes are in the new version
  * Backport Debian changes
  * Update symbols file for libnm0
  * Enable iwd support
  * Drop version requirements when oldstable ships a newer version
  * Drop dh_strip override, the dbgsym migration is done
  * Rebase patches
  * Make sure the example server.conf is actually installed
  * Update install path for plugins, it now includes a version number
  * Drop libnl3 build dependency.
    Upstream has copied the code directly from libnl3 for the few functions it
    needs with a few small modifications.
  * Drop libiw build dependency.
    Hasn't been needed for a long time and was simply a left over from older
    releases.
  * Bump Standards-Version to 4.1.5
  * Fix compile error due to NM_AVAILABLE_IN_1_12_2 macro (Closes: #905372)
Diffstat (limited to 'shared/nm-utils/unaligned.h')
-rw-r--r--shared/nm-utils/unaligned.h78
1 files changed, 26 insertions, 52 deletions
diff --git a/shared/nm-utils/unaligned.h b/shared/nm-utils/unaligned.h
index 7c847a3c..965a5fe9 100644
--- a/shared/nm-utils/unaligned.h
+++ b/shared/nm-utils/unaligned.h
@@ -1,22 +1,8 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 #pragma once
 
 /***
-  This file is part of systemd.
-
-  Copyright 2014 Tom Gundersen
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd 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
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+  Copyright © 2014 Tom Gundersen
 ***/
 
 #include <endian.h>
@@ -25,89 +11,77 @@
 /* BE */
 
 static inline uint16_t unaligned_read_be16(const void *_u) {
-        const uint8_t *u = _u;
+        const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
 
-        return (((uint16_t) u[0]) << 8) |
-                ((uint16_t) u[1]);
+        return be16toh(u->x);
 }
 
 static inline uint32_t unaligned_read_be32(const void *_u) {
-        const uint8_t *u = _u;
+        const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
 
-        return (((uint32_t) unaligned_read_be16(u)) << 16) |
-                ((uint32_t) unaligned_read_be16(u + 2));
+        return be32toh(u->x);
 }
 
 static inline uint64_t unaligned_read_be64(const void *_u) {
-        const uint8_t *u = _u;
+        const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
 
-        return (((uint64_t) unaligned_read_be32(u)) << 32) |
-                ((uint64_t) unaligned_read_be32(u + 4));
+        return be64toh(u->x);
 }
 
 static inline void unaligned_write_be16(void *_u, uint16_t a) {
-        uint8_t *u = _u;
+        struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
 
-        u[0] = (uint8_t) (a >> 8);
-        u[1] = (uint8_t) a;
+        u->x = be16toh(a);
 }
 
 static inline void unaligned_write_be32(void *_u, uint32_t a) {
-        uint8_t *u = _u;
+        struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
 
-        unaligned_write_be16(u, (uint16_t) (a >> 16));
-        unaligned_write_be16(u + 2, (uint16_t) a);
+        u->x = be32toh(a);
 }
 
 static inline void unaligned_write_be64(void *_u, uint64_t a) {
-        uint8_t *u = _u;
+        struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
 
-        unaligned_write_be32(u, (uint32_t) (a >> 32));
-        unaligned_write_be32(u + 4, (uint32_t) a);
+        u->x = be64toh(a);
 }
 
 /* LE */
 
 static inline uint16_t unaligned_read_le16(const void *_u) {
-        const uint8_t *u = _u;
+        const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
 
-        return (((uint16_t) u[1]) << 8) |
-                ((uint16_t) u[0]);
+        return le16toh(u->x);
 }
 
 static inline uint32_t unaligned_read_le32(const void *_u) {
-        const uint8_t *u = _u;
+        const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
 
-        return (((uint32_t) unaligned_read_le16(u + 2)) << 16) |
-                ((uint32_t) unaligned_read_le16(u));
+        return le32toh(u->x);
 }
 
 static inline uint64_t unaligned_read_le64(const void *_u) {
-        const uint8_t *u = _u;
+        const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
 
-        return (((uint64_t) unaligned_read_le32(u + 4)) << 32) |
-                ((uint64_t) unaligned_read_le32(u));
+        return le64toh(u->x);
 }
 
 static inline void unaligned_write_le16(void *_u, uint16_t a) {
-        uint8_t *u = _u;
+        struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
 
-        u[0] = (uint8_t) a;
-        u[1] = (uint8_t) (a >> 8);
+        u->x = le16toh(a);
 }
 
 static inline void unaligned_write_le32(void *_u, uint32_t a) {
-        uint8_t *u = _u;
+        struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
 
-        unaligned_write_le16(u, (uint16_t) a);
-        unaligned_write_le16(u + 2, (uint16_t) (a >> 16));
+        u->x = le32toh(a);
 }
 
 static inline void unaligned_write_le64(void *_u, uint64_t a) {
-        uint8_t *u = _u;
+        struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
 
-        unaligned_write_le32(u, (uint32_t) a);
-        unaligned_write_le32(u + 4, (uint32_t) (a >> 32));
+        u->x = le64toh(a);
 }
 
 #if __BYTE_ORDER == __BIG_ENDIAN