Skip to content
Commits on Source (3)
pylib/version.py
pylib/ntp_control.py
pylib/ntp_magic.py
pylib/control.py
pylib/magic.py
*/ntp
wafhelpers/.autorevision-cache
.lock-waf*
......
......@@ -43,7 +43,7 @@ import sys, socket, select, struct, time, getopt, datetime
try:
import ntp.packet
import ntp.util
import ntp.ntp_magic
import ntp.magic
except:
sys.stderr.write("ntpdig: can't find Python NTP library -- check PYTHONPATH.\n")
sys.exit(1)
......@@ -137,13 +137,13 @@ def clock_select(packets):
if response.stratum > NTP_INFIN:
drop("stratum too high")
continue
if response.version() < ntp.ntp_magic.NTP_OLDVERSION:
if response.version() < ntp.magic.NTP_OLDVERSION:
drop("response version %d is too old" % response.version())
continue
if response.mode() != ntp.ntp_magic.MODE_SERVER:
if response.mode() != ntp.magic.MODE_SERVER:
drop("unexpected response mode %d" % response.mode())
continue
if response.version() > ntp.ntp_magic.NTP_VERSION:
if response.version() > ntp.magic.NTP_VERSION:
drop("response version %d is too new" % response.version())
continue
if response.stratum == 0:
......
......@@ -167,7 +167,7 @@ class Ntpq(cmd.Cmd):
self.chosts = [] # Command-line hosts
self.peers = [] # Data from NTP peers.
self.debug = 0
self.pktversion = ntp.ntp_magic.NTP_OLDVERSION + 1
self.pktversion = ntp.magic.NTP_OLDVERSION + 1
self.uservars = collections.OrderedDict()
self.ai_family = socket.AF_UNSPEC
......@@ -272,41 +272,41 @@ usage: help [ command ]
self.say("\nind assid status conf reach auth condition last_event cnt\n")
self.say("===========================================================\n")
for (i, peer) in enumerate(self.peers):
statval = ntp.ntp_control.CTL_PEER_STATVAL(peer.status)
if not showall and (statval & (ntp.ntp_control.CTL_PST_CONFIG|ntp.ntp_control.CTL_PST_REACH)) == 0:
statval = ntp.control.CTL_PEER_STATVAL(peer.status)
if not showall and (statval & (ntp.control.CTL_PST_CONFIG|ntp.control.CTL_PST_REACH)) == 0:
continue
event = ntp.ntp_control.CTL_PEER_EVENT(peer.status)
event_count = ntp.ntp_control.CTL_PEER_NEVNT(peer.status)
if statval & ntp.ntp_control.CTL_PST_CONFIG:
event = ntp.control.CTL_PEER_EVENT(peer.status)
event_count = ntp.control.CTL_PEER_NEVNT(peer.status)
if statval & ntp.control.CTL_PST_CONFIG:
conf = "yes"
else:
conf = "no"
if statval & ntp.ntp_control.CTL_PST_BCAST:
if statval & ntp.control.CTL_PST_BCAST:
reach = "none"
if statval & ntp.ntp_control.CTL_PST_AUTHENABLE:
if statval & ntp.control.CTL_PST_AUTHENABLE:
auth = "yes"
else:
auth = "none"
elif statval & ntp.ntp_control.CTL_PST_REACH:
elif statval & ntp.control.CTL_PST_REACH:
reach = "yes"
else:
reach = "no"
if (statval & ntp.ntp_control.CTL_PST_AUTHENABLE) == 0:
if (statval & ntp.control.CTL_PST_AUTHENABLE) == 0:
auth = "none"
elif statval & ntp.ntp_control.CTL_PST_AUTHENTIC:
elif statval & ntp.control.CTL_PST_AUTHENTIC:
auth = "ok "
else:
auth = "bad"
if self.pktversion > ntp.ntp_magic.NTP_OLDVERSION:
if self.pktversion > ntp.magic.NTP_OLDVERSION:
seldict = {
ntp.ntp_control.CTL_PST_SEL_REJECT: "reject",
ntp.ntp_control.CTL_PST_SEL_SANE: "falsetick",
ntp.ntp_control.CTL_PST_SEL_CORRECT: "excess",
ntp.ntp_control.CTL_PST_SEL_SELCAND: "outlier",
ntp.ntp_control.CTL_PST_SEL_SYNCCAND: "candidate",
ntp.ntp_control.CTL_PST_SEL_EXCESS: "backup",
ntp.ntp_control.CTL_PST_SEL_SYSPEER: "sys.peer",
ntp.ntp_control.CTL_PST_SEL_PPS: "pps.peer",
ntp.control.CTL_PST_SEL_REJECT: "reject",
ntp.control.CTL_PST_SEL_SANE: "falsetick",
ntp.control.CTL_PST_SEL_CORRECT: "excess",
ntp.control.CTL_PST_SEL_SELCAND: "outlier",
ntp.control.CTL_PST_SEL_SYNCCAND: "candidate",
ntp.control.CTL_PST_SEL_EXCESS: "backup",
ntp.control.CTL_PST_SEL_SYSPEER: "sys.peer",
ntp.control.CTL_PST_SEL_PPS: "pps.peer",
}
condition = seldict[statval & 0x7]
else:
......@@ -324,19 +324,19 @@ usage: help [ command ]
elif (statval & 0x3) == OLD_CTL_PST_SEL_SYSPEER:
condition = "sys_peer"
event_dict = {
ntp.ntp_magic.PEVNT_MOBIL: "mobilize",
ntp.ntp_magic.PEVNT_DEMOBIL: "demobilize",
ntp.ntp_magic.PEVNT_REACH: "reachable",
ntp.ntp_magic.PEVNT_UNREACH: "unreachable",
ntp.ntp_magic.PEVNT_RESTART: "restart",
ntp.ntp_magic.PEVNT_REPLY: "no_reply",
ntp.ntp_magic.PEVNT_RATE: "rate_exceeded",
ntp.ntp_magic.PEVNT_DENY: "access_denied",
ntp.ntp_magic.PEVNT_ARMED: "leap_armed",
ntp.ntp_magic.PEVNT_NEWPEER: "sys_peer",
ntp.ntp_magic.PEVNT_CLOCK: "clock_alarm",
ntp.magic.PEVNT_MOBIL: "mobilize",
ntp.magic.PEVNT_DEMOBIL: "demobilize",
ntp.magic.PEVNT_REACH: "reachable",
ntp.magic.PEVNT_UNREACH: "unreachable",
ntp.magic.PEVNT_RESTART: "restart",
ntp.magic.PEVNT_REPLY: "no_reply",
ntp.magic.PEVNT_RATE: "rate_exceeded",
ntp.magic.PEVNT_DENY: "access_denied",
ntp.magic.PEVNT_ARMED: "leap_armed",
ntp.magic.PEVNT_NEWPEER: "sys_peer",
ntp.magic.PEVNT_CLOCK: "clock_alarm",
}
last_event = event_dict.get(ntp.ntp_magic.PEER_EVENT|event, "")
last_event = event_dict.get(ntp.magic.PEER_EVENT|event, "")
display = \
"%3d %5u %04x %3.3s %4s %4.4s %9.9s %11s %2lu" % \
(i + 1, peer.associd,
......@@ -372,8 +372,8 @@ usage: help [ command ]
self.say(("=" * report.width()) + "\n")
for peer in self.peers:
if not showall and \
not (ntp.ntp_control.CTL_PEER_STATVAL(peer.status)
& (ntp.ntp_control.CTL_PST_CONFIG|ntp.ntp_control.CTL_PST_REACH)):
not (ntp.control.CTL_PEER_STATVAL(peer.status)
& (ntp.control.CTL_PST_CONFIG|ntp.control.CTL_PST_REACH)):
if self.debug:
self.warn("eliding [%d]\n" % peer.associd)
continue
......@@ -439,7 +439,7 @@ usage: help [ command ]
return ()
lo = self.__assoc_valid(tokens[0])
hi = self.__assoc_valid(tokens[1])
if lo < 0 or hi < 0 or hi < 0:
if lo < 0 or hi < 0 or hi < lo:
return ()
return (lo, hi)
......@@ -840,11 +840,11 @@ usage: authenticate [ yes|no ]
else:
try:
newversion = int(line)
if newversion >= ntp.ntp_magic.NTP_OLDVERSION and newversion <= ntp.ntp_magic.NTP_VERSION:
if newversion >= ntp.magic.NTP_OLDVERSION and newversion <= ntp.magic.NTP_VERSION:
self.pktversion = newversion
else:
print("versions %d to %d, please"
% (ntp.ntp_magic.NTP_OLDVERSION, ntp.ntp_magic.NTP_VERSION))
% (ntp.magic.NTP_OLDVERSION, ntp.magic.NTP_VERSION))
except ValueError:
print("What?")
print("NTP version being claimed is %d" % self.pktversion)
......@@ -983,7 +983,7 @@ usage: showvars
associd = self.__assoc_valid(line)
if associd >= 0:
qtype = ntp.ntpc.TYPE_SYS if associd == 0 else ntp.ntpc.TYPE_PEER
self.__dolist(self.uservars.keys(), associd, ntp.ntp_control.CTL_OP_READVAR, qtype)
self.__dolist(self.uservars.keys(), associd, ntp.control.CTL_OP_READVAR, qtype)
def help_readlist(self):
self.say("""\
......@@ -1016,7 +1016,7 @@ usage: writelist [ assocID ]
associd = self.__assoc_valid(line)
if associd >= 0:
qtype = ntp.ntpc.TYPE_SYS if associd == 0 else ntp.ntpc.TYPE_PEER
self.__dolist(line.split()[1:], associd, ntp.ntp_control.CTL_OP_READVAR, qtype, quiet=True)
self.__dolist(line.split()[1:], associd, ntp.control.CTL_OP_READVAR, qtype, quiet=True)
def help_readvar(self):
self.say("""\
......@@ -1057,7 +1057,7 @@ usage: writevar assocID name=value,[...]
if (associd != idrange[0]):
self.say("\n")
if not self.__dolist(self.uservars,
associd, ntp.ntp_control.CTL_OP_READVAR, ntp.ntpc.TYPE_PEER):
associd, ntp.control.CTL_OP_READVAR, ntp.ntpc.TYPE_PEER):
return
def help_mreadlist(self):
......@@ -1091,7 +1091,7 @@ usage: mrl assocIDlow assocIDhigh
for associd in idrange:
if (associd != idrange[0]):
self.say("\n")
if not self.__dolist(varlist, associd, ntp.ntp_control.CTL_OP_READVAR, ntp.ntpc.TYPE_PEER):
if not self.__dolist(varlist, associd, ntp.control.CTL_OP_READVAR, ntp.ntpc.TYPE_PEER):
return
def help_mreadvar(self):
......@@ -1118,7 +1118,7 @@ usage: mrv assocIDlow assocIDhigh [ name=value[,...] ]
assoc = self.__assoc_valid(line)
if assoc >= 0:
self.__dolist(self.uservars.keys(),
assoc, ntp.ntp_control.CTL_OP_READCLOCK, ntp.ntpc.TYPE_CLOCK)
assoc, ntp.control.CTL_OP_READCLOCK, ntp.ntpc.TYPE_CLOCK)
def help_clocklist(self):
self.say("""\
......@@ -1142,7 +1142,7 @@ usage: cl [ assocID ]
if assoc == 0:
self.warn("This command requires the association ID of a clock.\n")
elif assoc > 0:
self.__dolist(line.split()[1:], assoc, ntp.ntp_control.CTL_OP_READCLOCK, ntp.ntpc.TYPE_CLOCK)
self.__dolist(line.split()[1:], assoc, ntp.control.CTL_OP_READCLOCK, ntp.ntpc.TYPE_CLOCK)
def help_clockvar(self):
self.say("""\
......
......@@ -18,7 +18,7 @@ from __future__ import print_function, division
import sys, getopt, re, time
import socket
import ntp.ntp_magic
import ntp.magic
import ntp.packet
# General notes on Python 2/3 compatibility:
......@@ -177,14 +177,14 @@ if __name__ == "__main__":
sys.stdout.write("\bLeap status not available\n")
sys.exit(1)
if leap == ntp.ntp_magic.LEAP_NOTINSYNC:
if leap == ntp.magic.LEAP_NOTINSYNC:
if verbose:
sys.stdout.write("\b" + "*+:."[i % 4])
if i < tries:
time.sleep(sleep)
continue
if leap in (ntp.ntp_magic.LEAP_NOWARNING, ntp.ntp_magic.LEAP_ADDSECOND, ntp.ntp_magic.LEAP_DELSECOND):
if leap in (ntp.magic.LEAP_NOWARNING, ntp.magic.LEAP_ADDSECOND, ntp.magic.LEAP_DELSECOND):
# We could check "sync" here to make sure we like the source...
if verbose:
sys.stdout.write("\bOK!\n")
......
......@@ -182,8 +182,8 @@ A Mode 6 packet cannot have extension fields.
from __future__ import print_function, division
import sys, socket, select, struct, collections, string
import getpass, hashlib, time
import ntp.ntp_control
import ntp.ntp_magic
import ntp.control
import ntp.magic
import ntp.ntpc
import ntp.util
......@@ -324,7 +324,7 @@ class Packet:
@staticmethod
def PKT_LI_VN_MODE(l, v, m): return ((((l) & 3) << 6) | Packet.VN_MODE((v), (m)))
def __init__(self, mode=ntp.ntp_magic.MODE_CLIENT, version=ntp.ntp_magic.NTP_VERSION, session=None):
def __init__(self, mode=ntp.magic.MODE_CLIENT, version=ntp.magic.NTP_VERSION, session=None):
self.session = session # Where to get session context
self.li_vn_mode = 0 # leap, version, mode (uint8_t)
# Subclasses have variable fields here
......@@ -340,7 +340,7 @@ class Packet:
self.__extension = polybytes(x)
def leap(self):
return ("no-leap", "add-leap", "del-leap", "unsync")[ntp.ntp_magic.PKT_LEAP(self.li_vn_mode)]
return ("no-leap", "add-leap", "del-leap", "unsync")[ntp.magic.PKT_LEAP(self.li_vn_mode)]
def version(self):
return (self.li_vn_mode >> 3) & 0x7
......@@ -530,7 +530,7 @@ class ControlPacket(Packet):
"Mode 6 request/response."
def __init__(self, session, opcode=0, associd=0, qdata=''):
Packet.__init__(self, mode=ntp.ntp_magic.MODE_CONTROL,
Packet.__init__(self, mode=ntp.magic.MODE_CONTROL,
version=session.pktversion,
session=session)
self.r_e_m_op = opcode # ntpq operation code
......@@ -689,14 +689,14 @@ class ControlSession:
"A session to a host"
MRU_ROW_LIMIT = 256
server_errors = {
ntp.ntp_control.CERR_UNSPEC: "UNSPEC",
ntp.ntp_control.CERR_PERMISSION: "PERMISSION",
ntp.ntp_control.CERR_BADFMT: "BADFMT",
ntp.ntp_control.CERR_BADOP: "BADOP",
ntp.ntp_control.CERR_BADASSOC: "BADASSOC",
ntp.ntp_control.CERR_UNKNOWNVAR: "UNKNOWNVAR",
ntp.ntp_control.CERR_BADVALUE: "BADVALUE",
ntp.ntp_control.CERR_RESTRICT: "RESTRICT",
ntp.control.CERR_UNSPEC: "UNSPEC",
ntp.control.CERR_PERMISSION: "PERMISSION",
ntp.control.CERR_BADFMT: "BADFMT",
ntp.control.CERR_BADOP: "BADOP",
ntp.control.CERR_BADASSOC: "BADASSOC",
ntp.control.CERR_UNKNOWNVAR: "UNKNOWNVAR",
ntp.control.CERR_BADVALUE: "BADVALUE",
ntp.control.CERR_RESTRICT: "RESTRICT",
}
def __init__(self):
......@@ -704,7 +704,7 @@ class ControlSession:
self.ai_family = socket.AF_UNSPEC
self.primary_timeout = DEFTIMEOUT # Timeout for first select
self.secondary_timeout = DEFSTIMEOUT # Timeout for later selects
self.pktversion = ntp.ntp_magic.NTP_OLDVERSION + 1 # Packet version number we use
self.pktversion = ntp.magic.NTP_OLDVERSION + 1 # Packet version number we use
self.always_auth = False # Always send authenticated requests
self.keytype = "MD5"
self.keyid = None
......@@ -733,7 +733,7 @@ class ControlSession:
if hname.startswith("["):
hname = hname[1:-1]
# First try to resolve it as an ip address and if that fails,
# do a fullblown (dns) lookup. That way we only use the dns
# do a fullblown (DNS) lookup. That way we only use the dns
# when it is needed and work around some implementations that
# will return an "IPv4-mapped IPv6 address" address if you
# give it an IPv4 address to lookup.
......@@ -750,26 +750,26 @@ class ControlSession:
sys.stderr.write("ntpq: numeric-mode lookup of %s failed, %s\n" % (hname, e.strerror))
try:
return hinted_lookup(port="ntp", hints=0)
except socket.gaierror as e:
sys.stderr.write("ntpq: standard-mode lookup of %s failed, %s\n" % (hname, e.strerror))
# EAI_NODATA and AI_CANONNAME should both exist - they're in the
# POSIX API. If this code throws AttributeErrors there is
# probably a very old and broken socket layer in your Python
# build. The C implementation had a second fallback mode that
# removed AI_ADDRCONFIG if the first fallback raised BADFLAGS.
fallback_hints = socket.AI_CANONNAME
try:
fallback_hints |= socket.AI_ADDRCONFIG
except AttributeError:
pass
try:
if e.errno in (socket.EAI_NONAME, socket.EAI_NODATA):
try:
return hinted_lookup(port="ndp", hints=0)
except socket.gaierror as e:
sys.stderr.write("ntpq: ndp lookup failed, %s\n" % e.strerror)
except AttributeError:
sys.stderr.write("ntpq: API error, missing socket attributes\n")
except socket.gaierror as e1:
sys.stderr.write("ntpq: standard-mode lookup of %s failed, %s\n" % (hname, e1.strerror))
# EAI_NODATA and AI_CANONNAME should both exist - they're in the
# POSIX API. If this code throws AttributeErrors there is
# probably a very old and broken socket layer in your Python
# build. The C implementation had a second fallback mode that
# removed AI_ADDRCONFIG if the first fallback raised BADFLAGS.
fallback_hints = socket.AI_CANONNAME
try:
fallback_hints |= socket.AI_ADDRCONFIG
except AttributeError:
pass
try:
if e1.errno in (socket.EAI_NONAME, socket.EAI_NODATA):
try:
return hinted_lookup(port="ndp", hints=0)
except socket.gaierror as e2:
sys.stderr.write("ntpq: ndp lookup failed, %s\n" % e2.strerror)
except AttributeError:
sys.stderr.write("ntpq: API error, missing socket attributes\n")
return None
def openhost(self, hname, fam=socket.AF_UNSPEC):
......@@ -853,7 +853,7 @@ class ControlSession:
sys.stderr.write("sendrequest(opcode=%d)\n" % opcode)
# Check to make sure the data will fit in one packet
if len(qdata) > ntp.ntp_control.CTL_MAX_DATA_LEN:
if len(qdata) > ntp.control.CTL_MAX_DATA_LEN:
sys.stderr.write("***Internal error! Data too large (%d)\n" %
len(qdata))
return -1
......@@ -957,11 +957,11 @@ class ControlSession:
except struct.error as reason:
raise ControlException(SERR_UNSPEC)
if rpkt.version() > ntp.ntp_magic.NTP_VERSION or rpkt.version() < ntp.ntp_magic.NTP_OLDVERSION:
if rpkt.version() > ntp.magic.NTP_VERSION or rpkt.version() < ntp.magic.NTP_OLDVERSION:
if self.debug:
warn("Fragment received with version %d\n" % rpkt.version())
continue
if rpkt.mode() != ntp.ntp_magic.MODE_CONTROL:
if rpkt.mode() != ntp.magic.MODE_CONTROL:
if self.debug:
warn("Fragment received with mode %d\n" % rpkt.mode())
continue
......@@ -1100,7 +1100,7 @@ class ControlSession:
def readstat(self, associd=0):
"Read peer status, or throw an exception."
self.doquery(opcode=ntp.ntp_control.CTL_OP_READSTAT, associd=associd)
self.doquery(opcode=ntp.control.CTL_OP_READSTAT, associd=associd)
if len(self.response) % 4:
raise ControlException(SERR_BADLENGTH)
idlist = []
......@@ -1151,7 +1151,7 @@ class ControlSession:
items.append((pair, ""))
return collections.OrderedDict(items)
def readvar(self, associd=0, varlist=None, opcode=ntp.ntp_control.CTL_OP_READVAR):
def readvar(self, associd=0, varlist=None, opcode=ntp.control.CTL_OP_READVAR):
"Read system vars from the host as a dict, or throw an exception."
if varlist == None:
qdata = ""
......@@ -1162,7 +1162,7 @@ class ControlSession:
def config(self, configtext):
"Send configuration text to the daemon. Return True if accepted."
self.doquery(opcode=ntp.ntp_control.CTL_OP_CONFIGURE, qdata=configtext, auth=True)
self.doquery(opcode=ntp.control.CTL_OP_CONFIGURE, qdata=configtext, auth=True)
# Copes with an implementation error - ntpd uses putdata without
# setting the size correctly.
if not self.response:
......@@ -1174,7 +1174,7 @@ class ControlSession:
def fetch_nonce(self):
"Receive a nonce that can be replayed - combats source address spoofing"
self.doquery(opcode=ntp.ntp_control.CTL_OP_REQ_NONCE)
self.doquery(opcode=ntp.control.CTL_OP_REQ_NONCE)
if not self.response.startswith(polybytes("nonce=")):
raise ControlException(SERR_BADNONCE)
return polystr(self.response.strip())
......@@ -1217,10 +1217,10 @@ class ControlSession:
else:
raise ControlException(SERR_BADPARAM % k)
if 'kod' in variables:
variables['resany'] = variables.get('resany', 0) | ntp.ntp_magic.RES_KOD
variables['resany'] = variables.get('resany', 0) | ntp.magic.RES_KOD
del variables['kod']
if 'limited' in variables:
variables['resany'] = variables.get('resany', 0) | ntp.ntp_magic.RES_LIMITED
variables['resany'] = variables.get('resany', 0) | ntp.magic.RES_LIMITED
del variables['limited']
nonce = self.fetch_nonce()
......@@ -1240,13 +1240,13 @@ class ControlSession:
while True:
# Request additions to the MRU list
try:
self.doquery(opcode=ntp.ntp_control.CTL_OP_READ_MRU, qdata=req_buf)
self.doquery(opcode=ntp.control.CTL_OP_READ_MRU, qdata=req_buf)
recoverable_read_errors = False
except ControlException as e:
recoverable_read_errors = True
if e.errorcode is None:
raise e
elif e.errorcode == ntp.ntp_control.CERR_UNKNOWNVAR:
elif e.errorcode == ntp.control.CERR_UNKNOWNVAR:
# None of the supplied prior entries match, so
# toss them from our list and try again.
if self.debug:
......@@ -1256,10 +1256,10 @@ class ControlSession:
raise ControlException(SERR_STALL)
if self.debug:
warn("---> Restarting from the beginning, retry #%u\n" % restarted_count)
elif e.errorcode == ntp.ntp_control.CERR_UNKNOWNVAR:
elif e.errorcode == ntp.control.CERR_UNKNOWNVAR:
e.message = "CERR_UNKNOWNVAR from ntpd but no priors given."
raise e
elif e.errorcode == ntp.ntp_control.CERR_BADVALUE:
elif e.errorcode == ntp.control.CERR_BADVALUE:
if cap_frags:
cap_frags = False
if self.debug:
......@@ -1357,7 +1357,7 @@ class ControlSession:
for i in range(len(span.entries)):
e = span.entries[len(span.entries) - i - 1]
incr = ", addr.%d=%s, last.%d=%s" % (i, e.addr, i, e.last)
if len(req_buf) + len(incr) >= ntp.ntp_control.CTL_MAX_DATA_LEN:
if len(req_buf) + len(incr) >= ntp.control.CTL_MAX_DATA_LEN:
break
else:
req_buf += incr
......@@ -1391,7 +1391,7 @@ class ControlSession:
def __ordlist(self, listtype):
"Retrieve ordered-list data."
self.doquery(opcode=ntp.ntp_control.CTL_OP_READ_ORDLIST_A, qdata=listtype, auth=True)
self.doquery(opcode=ntp.control.CTL_OP_READ_ORDLIST_A, qdata=listtype, auth=True)
stanzas = []
for (key, value) in self.__parse_varlist().items():
if key[-1].isdigit() and key[-2] == '.':
......@@ -1463,7 +1463,7 @@ class Authenticator:
# According to RFC 5909 7.5 the MAC is always present when an extension
# field is present. Note: this crude test will fail on Mode 6 packets.
# On those you have to go in and look at the count.
return len(packet) > ntp.ntp_magic.LEN_PKT_NOMAC
return len(packet) > ntp.magic.LEN_PKT_NOMAC
def verify_mac(self, packet):
"Does the MAC on this packet verify according to credentials we have?"
# FIXME: Someday, figure out how to handle SHA1?
......
......@@ -13,8 +13,8 @@ import collections
import ntp.ntpc
import ntp.version
import ntp.ntp_magic
import ntp.ntp_control
import ntp.magic
import ntp.control
def stdversion():
return "%s-%s-%s %s" % (ntp.version.VERSION, ntp.version.VCS_TICK,
......@@ -194,11 +194,11 @@ class PeerSummary:
elif name == "hpoll":
hpoll = value
if hpoll < 0:
hpoll = ntp.ntp_magic.NTP_MINPOLL
hpoll = ntp.magic.NTP_MINPOLL
elif name == "ppoll":
ppoll = value
if ppoll < 0:
ppoll = ntp.ntp_magic.NTP_MINPOLL
ppoll = ntp.magic.NTP_MINPOLL
elif name == "reach":
# Shipped as hex, displayed in octal
reach = value
......@@ -218,16 +218,16 @@ class PeerSummary:
srcport = value
elif name == "reftime":
reftime = value # l_fp timestamp
if hmode == ntp.ntp_magic.MODE_BCLIENT:
if hmode == ntp.magic.MODE_BCLIENT:
# broadcastclient or multicastclient
ptype = 'b'
elif hmode == ntp.ntp_magic.MODE_BROADCAST:
elif hmode == ntp.magic.MODE_BROADCAST:
# broadcast or multicast server
if srcadr.startswith("224."): # IANA multicast address prefix
ptype = 'M'
else:
ptype = 'B'
elif hmode == ntp.ntp_magic.MODE_CLIENT:
elif hmode == ntp.magic.MODE_CLIENT:
if srchost and '(' in srchost:
ptype = 'l' # local refclock
elif dstadr_refid == "POOL":
......@@ -236,9 +236,9 @@ class PeerSummary:
ptype = 'a' # manycastclient
else:
ptype = 'u' # unicast
elif hmode == ntp.ntp_magic.MODE_ACTIVE:
elif hmode == ntp.magic.MODE_ACTIVE:
ptype = 's' # symmetric active
elif hmode == ntp.ntp_magic.MODE_PASSIVE:
elif hmode == ntp.magic.MODE_PASSIVE:
ptype = 'S' # symmetric passive
#
......@@ -246,10 +246,10 @@ class PeerSummary:
#
line = ""
poll_sec = 1 << min(ppoll, hpoll)
if self.pktversion > ntp.ntp_magic.NTP_OLDVERSION:
c = " x.-+#*o"[ntp.ntp_control.CTL_PEER_STATVAL(rstatus) & 0x7]
if self.pktversion > ntp.magic.NTP_OLDVERSION:
c = " x.-+#*o"[ntp.control.CTL_PEER_STATVAL(rstatus) & 0x7]
else:
c = " .+*"[ntp.ntp_control.CTL_PEER_STATVAL(rstatus) & 0x3]
c = " .+*"[ntp.control.CTL_PEER_STATVAL(rstatus) & 0x3]
# Source host or clockname
if srchost != None:
clock_name = srchost
......@@ -322,9 +322,9 @@ class MRUSummary:
stats += " %6d" % avgint
else:
stats += " %6.2f" % favgint
if entry.rs & ntp.ntp_magic.RES_KOD:
if entry.rs & ntp.magic.RES_KOD:
rscode = 'K'
elif entry.rs & ntp.ntp_magic.RES_LIMITED:
elif entry.rs & ntp.magic.RES_LIMITED:
rscode = 'L'
else:
rscode = '.'
......@@ -334,8 +334,8 @@ class MRUSummary:
dns = canonicalize_dns(dns)
stats += " %4hx %c %d %d %6d %5s %s" % \
(entry.rs, rscode,
ntp.ntp_magic.PKT_MODE(entry.mv),
ntp.ntp_magic.PKT_VERSION(entry.mv),
ntp.magic.PKT_MODE(entry.mv),
ntp.magic.PKT_VERSION(entry.mv),
entry.ct, port[1:], dns)
return stats
except TypeError:
......
......@@ -9,8 +9,8 @@ def configure(conf):
def build(ctx):
srcnode = ctx.srcnode.make_node('pylib')
#bldnode = ctx.bldnode.make_node('pylib')
target1 = ctx.srcnode.make_node('pylib/ntp_control.py')
target2 = ctx.srcnode.make_node('pylib/ntp_magic.py')
target1 = ctx.srcnode.make_node('pylib/control.py')
target2 = ctx.srcnode.make_node('pylib/magic.py')
target3 = ctx.srcnode.make_node('pylib/version.py')
target4 = ctx.srcnode.make_node('wafhelpers/.autorevision-cache')
......