Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Use be32enc, rather than possibly unaligned uint32_t...



details:   https://anonhg.NetBSD.org/src/rev/2729bc8e1a39
branches:  trunk
changeset: 942839:2729bc8e1a39
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Aug 20 21:35:13 2020 +0000

description:
Use be32enc, rather than possibly unaligned uint32_t cast and htonl.

diffstat:

 sys/net/if_wg.c |  13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diffs (42 lines):

diff -r 9fd5cca60311 -r 2729bc8e1a39 sys/net/if_wg.c
--- a/sys/net/if_wg.c   Thu Aug 20 21:35:01 2020 +0000
+++ b/sys/net/if_wg.c   Thu Aug 20 21:35:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wg.c,v 1.14 2020/08/20 21:35:01 riastradh Exp $     */
+/*     $NetBSD: if_wg.c,v 1.15 2020/08/20 21:35:13 riastradh Exp $     */
 
 /*
  * Copyright (C) Ryota Ozaki <ozaki.ryota%gmail.com@localhost>
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.14 2020/08/20 21:35:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.15 2020/08/20 21:35:13 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1073,19 +1073,18 @@
 }
 
 static void
-wg_algo_tai64n(wg_timestamp_t _timestamp)
+wg_algo_tai64n(wg_timestamp_t timestamp)
 {
        struct timespec ts;
-       uint32_t *timestamp = (uint32_t *)_timestamp;
 
        /* FIXME strict TAI64N (https://cr.yp.to/libtai/tai64.html) */
        getnanotime(&ts);
        /* TAI64 label in external TAI64 format */
-       timestamp[0] = htonl(0x40000000L + (ts.tv_sec >> 32));
+       be32enc(timestamp, 0x40000000UL + (ts.tv_sec >> 32));
        /* second beginning from 1970 TAI */
-       timestamp[1] = htonl((long)ts.tv_sec);
+       be32enc(timestamp + 4, ts.tv_sec & 0xffffffffU);
        /* nanosecond in big-endian format */
-       timestamp[2] = htonl(ts.tv_nsec);
+       be32enc(timestamp + 8, ts.tv_nsec);
 }
 
 static struct wg_session *



Home | Main Index | Thread Index | Old Index