[Git][NTPsec/ntpsec][master] 2 commits: Added comments.
Ian Bruene
gitlab at mg.gitlab.com
Tue Jan 9 14:59:13 UTC 2018
Ian Bruene pushed to branch master at NTPsec / ntpsec
Commits:
bbd59975 by Ian Bruene at 2018-01-09T08:58:35-06:00
Added comments.
- - - - -
d761d774 by Ian Bruene at 2018-01-09T08:58:35-06:00
Removed redundant error checking from packetEater.
- - - - -
1 changed file:
- ntpclients/ntpsnmpd.py
Changes:
=====================================
ntpclients/ntpsnmpd.py
=====================================
--- a/ntpclients/ntpsnmpd.py
+++ b/ntpclients/ntpsnmpd.py
@@ -593,9 +593,16 @@ class DataSource: # This will be broken up in future to be less NTP-specific
elif action == "cleanup":
pass
- # =====================================
+ # ========================================================================
# Dynamic tree generator callbacks
- # =====================================
+ #
+ # The structure of these callbacks is somewhat complicated because they
+ # share code that is potentially finicky.
+ #
+ # The dynamicCallbackSkeleton() method handles the construction of the
+ # MIB tree, and the placement of the handler() within it. It also provides
+ # some useful data to the handler() via the readCallback() layer.
+ # ========================================================================
def sub_assocID(self):
def handler(oid, associd):
@@ -678,6 +685,8 @@ class DataSource: # This will be broken up in future to be less NTP-specific
for piece in pieces:
srcadr.append(ntp.util.hexstr2octets(piece))
srcadr = "".join(srcadr) # feed it an octet string
+ # The octet string encoder can handle either chars or 0-255
+ # ints. We use both of those options.
return ax.Varbind(ax.VALUE_OCTET_STR, oid, srcadr)
return self.dynamicCallbackSkeleton(handler)
@@ -1035,7 +1044,10 @@ class DataSource: # This will be broken up in future to be less NTP-specific
return None
def dynamicCallbackSkeleton(self, handler):
+ # Build a dynamic MIB tree, installing the provided handler in it
def readCallback(oid):
+ # This function assumes that it is a leaf node and that the
+ # last number in the OID is the index.
index = oid.subids[-1] # if called properly this works (Ha!)
associd = self.misc_getPeerIDs()[index]
return handler(oid, associd)
@@ -1125,6 +1137,7 @@ class PacketControl:
0, ax.REPERR_NOT_OPEN, 0)
self.sendPacket(resp, False)
continue
+ # TODO: Need to check for expected responses
ptype = packet.pduType
if ptype in self.pduHandlers:
self.pduHandlers[ptype](packet)
@@ -1174,15 +1187,6 @@ class PacketControl:
try:
pkt, extraData = ntp.agentx.decode_packet(self.recievedData)
self.recievedData = extraData
- if (self.sessionID is not None) and \
- (pkt.sessionID != self.sessionID):
- # sessionID does not match
- header = {"session_id": pkt.sessionID,
- "transaction_id": pkt.transactionID,
- "packet_id": pkt.packetID,
- "flags": {"bigEndian": pkt.bigEndian}}
- self.sendErrorResponse(header, ax.RSPERR_NOT_OPEN, 0)
- continue
self.recievedPackets.append(pkt)
dolog("\npacketEater got a full packet: %s\n" % repr(pkt), 3)
except ax.ParseDataLengthError:
@@ -1252,7 +1256,7 @@ class PacketControl:
binds.append(reader(oid))
# There should also be a situation that leads to noSuchInstance
# but I do not understand the requirements for that
- # Need to implement genError
+ # TODO: Need to implement genError
resp = ax.ResponsePDU(True, self.sessionID, packet.transactionID,
packet.packetID, 0, ax.ERR_NOERROR, 0, binds)
self.sendPacket(resp, False)
@@ -1266,7 +1270,7 @@ class PacketControl:
else:
oid, reader, _ = oids[0]
binds.append(reader(oid))
- # Need to implement genError
+ # TODO: Need to implement genError
resp = ax.ResponsePDU(True, self.sessionID, packet.transactionID,
packet.packetID, 0, ax.ERR_NOERROR, 0, binds)
self.sendPacket(resp, False)
@@ -1295,7 +1299,7 @@ class PacketControl:
packet.packetID, 0, ax.ERR_NOERROR, 0, binds)
self.sendPacket(resp, False)
- def handle_TestSetPDU(self, packet): # WIP
+ def handle_TestSetPDU(self, packet): # WIP / TODO
# Be advised: MOST OF THE VALIDATION IS DUMMY CODE OR DOESN'T EXIST
# According to the RFC this is one of the most demanding parts and
# *has* to be gotten right
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/3a7e76dc3dda4a92adbf7ed69abb92211ddbc114...d761d7748bec8bb2af14d7a48f790360fc30b64f
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/3a7e76dc3dda4a92adbf7ed69abb92211ddbc114...d761d7748bec8bb2af14d7a48f790360fc30b64f
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180109/b8b43e0e/attachment.html>
More information about the vc
mailing list