Commit c8eded0b authored by Guido Trotter's avatar Guido Trotter
Browse files

AsyncUDPSocket: Move to a well defined UDP size



Currently we read maximum 4K packets, and don't check packets when
sending them. With this patch we move to a well defined maximum size of
60K.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent fe759e4c
...@@ -681,3 +681,10 @@ CONFD_CONFIG_RELOAD_TIMEOUT = 60 ...@@ -681,3 +681,10 @@ CONFD_CONFIG_RELOAD_TIMEOUT = 60
# polling every RATELIMIT seconds, rather than relying on inotify, to be able # polling every RATELIMIT seconds, rather than relying on inotify, to be able
# to serve more requests. # to serve more requests.
CONFD_CONFIG_RELOAD_RATELIMIT = 2 CONFD_CONFIG_RELOAD_RATELIMIT = 2
# Maximum UDP datagram size.
# On IPv4: 64K - 20 (ip header size) - 8 (udp header size) = 65507
# On IPv6: 64K - 40 (ip6 header size) - 8 (udp header size) = 65487
# (assuming we can't use jumbo frames)
# We just set this to 60K, which should be enough
MAX_UDP_DATA_SIZE = 61440
...@@ -95,7 +95,7 @@ class AsyncUDPSocket(asyncore.dispatcher): ...@@ -95,7 +95,7 @@ class AsyncUDPSocket(asyncore.dispatcher):
def handle_read(self): def handle_read(self):
try: try:
try: try:
payload, address = self.recvfrom(4096) payload, address = self.recvfrom(constants.MAX_UDP_DATA_SIZE)
except socket.error, err: except socket.error, err:
if err.errno == errno.EINTR: if err.errno == errno.EINTR:
# we got a signal while trying to read. no need to do anything, # we got a signal while trying to read. no need to do anything,
...@@ -148,6 +148,9 @@ class AsyncUDPSocket(asyncore.dispatcher): ...@@ -148,6 +148,9 @@ class AsyncUDPSocket(asyncore.dispatcher):
"""Enqueue a datagram to be sent when possible """Enqueue a datagram to be sent when possible
""" """
if len(payload) > constants.MAX_UDP_DATA_SIZE:
raise errors.UdpDataSizeError('Packet too big: %s > %s' % (len(payload),
constants.MAX_UDP_DATA_SIZE))
self._out_queue.append((ip, port, payload)) self._out_queue.append((ip, port, payload))
......
...@@ -297,6 +297,12 @@ class ConfdRequestError(GenericError): ...@@ -297,6 +297,12 @@ class ConfdRequestError(GenericError):
""" """
class UdpDataSizeError(GenericError):
"""UDP payload too big.
"""
# errors should be added above # errors should be added above
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment