2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-03-29 11:38:16 +00:00

Correctly align rtattr and nlmsg

When advancing through messages,
must pad to nearest multiple of
4.  This resolves erroneously landing on incorrect offsets.
This commit is contained in:
Jarrod Johnson 2022-01-19 13:21:59 -05:00
parent 2d13921d54
commit 456b43eeb7
3 changed files with 17 additions and 7 deletions

View File

@ -18,6 +18,9 @@ import time
class InvalidApiKey(Exception):
pass
def msg_align(len):
return (len + 3) & ~3
cryptname = ctypes.util.find_library('crypt')
if not cryptname:
if os.path.exists('/usr/lib64/libcrypt.so.1'):
@ -59,8 +62,8 @@ def get_my_addresses():
break
if rtatyp == 1:
addrs.append((fam, rta[4:rtalen], plen, ridx))
rta = rta[rtalen:]
v = v[length:]
rta = rta[msg_align(rtalen):]
v = v[msg_align(length):]
return addrs

View File

@ -22,6 +22,11 @@ import eventlet.semaphore as semaphore
import eventlet.green.socket as socket
import struct
def msg_align(len):
return (len + 3) & ~3
neightable = {}
neightime = 0
@ -65,12 +70,12 @@ def _update_neigh():
curraddr = curraddr[12:]
elif rtatyp == 1: # ip address
currip = rta[4:rtalen].tobytes()
rta = rta[rtalen:]
rta = rta[msg_align(rtalen):]
if not rtalen:
break
if curraddr and currip:
neightable[currip] = curraddr
v = v[length:]
v = v[msg_align(length):]
finally:
s.close()

View File

@ -25,6 +25,8 @@ import eventlet.support.greendns
import os
getaddrinfo = eventlet.support.greendns.getaddrinfo
def msg_align(len):
return (len + 3) & ~3
def mask_to_cidr(mask):
maskn = socket.inet_pton(socket.AF_INET, mask)
@ -571,7 +573,7 @@ def get_my_addresses(idx=0, family=0, matchlla=None):
break
if rta[4:rtalen].tobytes() == matchlla:
return get_my_addresses(idx=ridx)
rta = rta[rtalen:]
rta = rta[msg_align(rtalen):]
elif (ridx == idx or not idx) and scope == 0:
rta = v[nlhdrsz+ifaddrsz:length]
while len(rta):
@ -580,8 +582,8 @@ def get_my_addresses(idx=0, family=0, matchlla=None):
break
if rtatyp == 1:
addrs.append((fam, rta[4:rtalen].tobytes(), plen, ridx))
rta = rta[rtalen:]
v = v[length:]
rta = rta[msg_align(rtalen):]
v = v[msg_align(length):]
return addrs