[Git][NTPsec/ntpsec][master] 2 commits: Boolification.
Eric S. Raymond
gitlab at mg.gitlab.com
Wed Dec 16 01:33:58 UTC 2015
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
e5cf9208 by Eric S. Raymond at 2015-12-15T18:56:13Z
Boolification.
- - - - -
d363c605 by Eric S. Raymond at 2015-12-15T20:31:13Z
In replay, implement full packet parsing.
- - - - -
3 changed files:
- include/ntp_io.h
- ntpd/ntp_intercept.c
- ntpd/ntp_io.c
Changes:
=====================================
include/ntp_io.h
=====================================
--- a/include/ntp_io.h
+++ b/include/ntp_io.h
@@ -47,7 +47,7 @@ typedef enum {
extern int qos;
SOCKET move_fd(SOCKET fd);
bool get_broadcastclient_flag(void);
-extern int is_ip_address(const char *, u_short, sockaddr_u *);
+extern bool is_ip_address(const char *, u_short, sockaddr_u *);
extern void sau_from_netaddr(sockaddr_u *, const isc_netaddr_t *);
extern void add_nic_rule(nic_rule_match match_type,
const char *if_name, int prefixlen,
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -433,15 +433,20 @@ int intercept_adjtime(const struct timeval *ntv, struct timeval *otv)
{
if (mode == replay) {
struct timeval rntv, rotv;
+ long nsec, nusec, osec, ousec;
get_operation("adjtime ");
/* bletch - likely to foo up on 32-bit machines */
if (sscanf(linebuf, "adjtime %ld %ld %ld %ld",
- &rntv.tv_sec, &rntv.tv_usec,
- &rotv.tv_sec, &rotv.tv_usec) != 4)
+ &nsec, &nusec, &osec, &ousec) != 4)
{
fprintf(stderr, "ntpd: garbled adjtime format, line %d\n", lineno);
exit(1);
}
+ /* avoid compiler warnings due to time_t having an unexpected length */
+ rntv.tv_sec = nsec;
+ rntv.tv_usec = nusec;
+ rntv.tv_sec = osec;
+ rntv.tv_usec = ousec;
if (ntv->tv_sec != rntv.tv_sec
|| ntv->tv_usec != rntv.tv_usec
|| otv->tv_sec != rotv.tv_sec
@@ -622,7 +627,6 @@ static void packet_dump(char *buf, size_t buflen,
snprintf(buf, buflen, "%s %d:%d:%d:%d:%u:%u:%u:%s:%s:%s:%s ",
socktoa(dest),
pkt->li_vn_mode, pkt->stratum, pkt->ppoll, pkt->precision,
- /* FIXME: might be better to dump these in fixed-point */
pkt->rootdelay, pkt->rootdisp,
pkt->refid,
lfpdump(&pkt->reftime), lfpdump(&pkt->org),
@@ -703,7 +707,10 @@ void intercept_replay(void)
else if (strncmp(linebuf, "receive ", 8) == 0)
{
struct recvbuf rbuf;
+ struct pkt *pkt;
+ int li_vn_mode = 0, stratum = 0, ppoll = 0, precision = 0;
char recvbuf[BUFSIZ], srcbuf[BUFSIZ], pktbuf[BUFSIZ], macbuf[BUFSIZ];
+ char refbuf[32], orgbuf[32], recbuf[32], xmtbuf[32];
if (sscanf(linebuf, "receive %x %s %s %s %s",
&rbuf.cast_flags, recvbuf, srcbuf, pktbuf, macbuf) != 5)
@@ -713,8 +720,42 @@ void intercept_replay(void)
}
atolfp(recvbuf, &rbuf.recv_time);
- /* FIXME: parse source address */
- /* FIXME: parse packet and MAC */
+ if (!is_ip_address(srcbuf, AF_UNSPEC, &rbuf.recv_srcadr)) {
+ fprintf(stderr, "ntpd: invalid IP address in receive at line %d\n", lineno);
+ exit(1);
+ }
+
+ pkt = &rbuf.recv_pkt;
+ if (sscanf(pktbuf, "%d:%d:%d:%d:%u:%u:%u:%s:%s:%s:%s",
+ &li_vn_mode, &stratum,
+ &ppoll, &precision,
+ &pkt->rootdelay, &pkt->rootdisp,
+ &pkt->refid,
+ refbuf, orgbuf, recbuf, xmtbuf) != 7)
+ {
+ fprintf(stderr, "ntpd: malformed packet dump at line %d\n",
+ lineno);
+ exit(1);
+ }
+ /* extra transfers required because the struct members are int8_t */
+ pkt->li_vn_mode = li_vn_mode;
+ pkt->stratum = stratum;
+ pkt->ppoll = ppoll;
+ pkt->precision = precision;
+ atolfp(refbuf, &pkt->reftime);
+ atolfp(orgbuf, &pkt->org);
+ atolfp(recbuf, &pkt->rec);
+ atolfp(xmtbuf, &pkt->xmt);
+
+ memset(pkt->exten, '\0', sizeof(pkt->exten));
+ if (strcmp(macbuf, "nomac") != 0) {
+ size_t i;
+ for (i = 0; i < strlen(macbuf)/2; i++) {
+ int hexval;
+ sscanf(macbuf + 2*i, "%02x", &hexval);
+ pkt->exten[i] = hexval & 0xff;
+ }
+ }
/*
* If the packet doesn't dump identically to how it came in,
=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -716,7 +716,7 @@ addr_samesubnet(
* and set the return value
* see the bind9/getaddresses.c for details
*/
-int
+bool
is_ip_address(
const char * host,
u_short af,
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f0a57d5e59c8dda9f3a9ec789bd79ab7fde791cc...d363c6050c73a86405b17d68e55299710ee9c7d3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151216/d29e3165/attachment.html>
More information about the vc
mailing list