Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
NTPsec
ntpsec
Commits
d4c2a76b
Commit
d4c2a76b
authored
Jan 04, 2017
by
Eric S. Raymond
Browse files
Scalarize the l_fp type. Byte order magic is due to Hal Murray.
parent
c26d0602
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/ntp.h
View file @
d4c2a76b
...
...
@@ -494,10 +494,10 @@ struct pkt {
u_fp
rootdelay
;
/* roundtrip delay to primary source */
u_fp
rootdisp
;
/* dispersion to primary source*/
uint32_t
refid
;
/* reference id */
l_fp
reftime
;
/* last update time */
l_fp
org
;
/* originate time stamp */
l_fp
rec
;
/* receive time stamp */
l_fp
xmt
;
/* transmit time stamp */
l_fp
_w
reftime
;
/* last update time */
l_fp
_w
org
;
/* originate time stamp */
l_fp
_w
rec
;
/* receive time stamp */
l_fp
_w
xmt
;
/* transmit time stamp */
#define MIN_MAC_LEN (1 * sizeof(uint32_t))
/* crypto_NAK */
#define MAX_MD5_LEN (5 * sizeof(uint32_t))
/* MD5 */
...
...
include/ntp_fp.h
View file @
d4c2a76b
...
...
@@ -29,39 +29,30 @@
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
typedef
struct
{
union
{
uint32_t
Xl_ui
;
/* unsigned integral part */
int32_t
Xl_i
;
/* signed integral part */
}
Ul_i
;
uint32_t
l_uf
;
}
l_fp
;
#define lfpfrac(n) ((n).l_uf)
#define setlfpfrac(n, v) (n).l_uf = (v)
#define lfpsint(n) (n).Ul_i.Xl_i
#define setlfpsint(n, v) (n).Ul_i.Xl_i = (v)
#define bumplfpsint(n, i) (n).Ul_i.Xl_i += (i)
#define lfpuint(n) (n).Ul_i.Xl_ui
#define setlfpuint(n, v) (n).Ul_i.Xl_ui = (v)
#define bumplfpuint(n, i) (n).Ul_i.Xl_ui += (i)
static
inline
uint64_t
lfp_to_uint64
(
const
l_fp
lfp
)
{
return
(
uint64_t
)
lfpuint
(
lfp
)
<<
32
|
(
uint64_t
)
lfpfrac
(
lfp
);
typedef
uint64_t
l_fp
;
#define LOW32 0x00000000ffffffffUL
#define HIGH32 0xffffffff00000000UL
#define BUMP 0x0000000100000000UL
#define lfpfrac(n) ((uint32_t)((n) & LOW32))
#define setlfpfrac(n, v) (n) = (((n) & HIGH32) | ((v) & LOW32))
#define lfpsint(n) (int32_t)(((n) & HIGH32) >> 32)
#define setlfpsint(n, v) (n) = (int64_t)((((int64_t)(v)) << 32) | ((n) & LOW32))
#define bumplfpsint(n, i) (n) += (i)*BUMP
#define lfpuint(n) (uint32_t)(((n) & HIGH32) >> 32)
#define setlfpuint(n, v) (n) = (uint64_t)((((uint64_t)(v)) << 32) | ((n) & LOW32))
#define bumplfpuint(n, i) (n) += (i)*BUMP
static
inline
uint64_t
lfp_to_uint64
(
const
l_fp
lfp
)
{
return
lfp
;
}
static
inline
l_fp
uint64_to_lfp
(
uint64_t
x
)
{
l_fp
fp
;
setlfpuint
(
fp
,
x
>>
32
);
setlfpfrac
(
fp
,
x
&
0xFFFFFFFFUL
);
return
fp
;
static
inline
l_fp
uint64_to_lfp
(
uint64_t
x
)
{
return
x
;
}
static
inline
l_fp
lfpinit
(
int32_t
hi
,
uint32_t
lo
)
{
l_fp
tmp
;
l_fp
tmp
=
0
;
setlfpsint
(
tmp
,
hi
);
setlfpfrac
(
tmp
,
lo
);
return
tmp
;
...
...
@@ -103,12 +94,22 @@ typedef uint32_t u_fp;
#define HTONS_FP(x) (htonl(x))
#define NTOHS_FP(x) (ntohl(x))
static
inline
l_fp
htonl_fp
(
l_fp
lfp
)
{
return
lfpinit
(
htonl
(
lfpuint
(
lfp
)),
htonl
(
lfpfrac
(
lfp
)));
typedef
struct
{
uint32_t
l_ui
;
uint32_t
l_uf
;
}
l_fp_w
;
static
inline
l_fp_w
htonl_fp
(
l_fp
lfp
)
{
l_fp_w
lfpw
;
lfpw
.
l_ui
=
htonl
(
lfpuint
(
lfp
));
lfpw
.
l_uf
=
htonl
(
lfpfrac
(
lfp
));
return
lfpw
;
// return lfpinit(htonl(lfpuint(lfp)), htonl(lfpfrac(lfp)));
}
static
inline
l_fp
ntohl_fp
(
l_fp
lfp
)
{
return
lfpinit
(
ntohl
(
lfp
uint
(
lfp
)
),
ntohl
(
lfp
frac
(
lfp
)
));
static
inline
l_fp
ntohl_fp
(
l_fp
_w
lfp
w
)
{
return
lfpinit
(
ntohl
(
lfp
w
.
l_ui
),
ntohl
(
lfp
w
.
l_uf
));
}
/* Convert unsigned ts fraction to net order ts */
...
...
libntp/refidsmear.c
View file @
d4c2a76b
...
...
@@ -17,7 +17,7 @@
l_fp
convertRefIDToLFP
(
uint32_t
r
)
{
l_fp
temp
;
l_fp
temp
=
0
;
r
=
ntohl
(
r
);
...
...
ntpd/refclock_jupiter.c
View file @
d4c2a76b
...
...
@@ -613,7 +613,7 @@ jupiter_pps(struct instance *instance)
pps_info_t
pps_info
;
struct
timespec
timeout
,
ts
;
double
dtemp
;
l_fp
tstmp
;
l_fp
tstmp
=
0
;
/*
* Convert the timespec nanoseconds field to ntp l_fp units.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment