summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Nemec <bnemec@redhat.com>2019-01-08 23:59:10 +0000
committerBen Nemec <bnemec@redhat.com>2019-01-09 16:26:40 +0000
commitc6d358d4c6926638fe9d5194e3da112c2750c6a4 (patch)
treec8dbb473985d62a067e079d593d85006fcb1a1dc
parent15c782b5a12ea2f09750bdf061a25f81d2c9f135 (diff)
Define types for C calls in netlink_lib
Previously this was not done, which meant all arguments were assumed to be ints. As long as we didn't get any large pointer addresses this worked fine, but for some reason the addition of threading to oslo.privsep triggered larger addresses that were then truncated. This caused segfaults in the underlying C library because we were passing it invalid pointers. This change sets argument and return types for all of the calls that are used in the module. Change-Id: I9dbbb01eac8cf7cded7794f8ba69797d6357eeec Closes-Bug: 1810518
Notes
Notes (review): Code-Review+1: Sean McGinnis <sean.mcginnis@gmail.com> Code-Review+1: Bernard Cafarelli <bcafarel@redhat.com> Code-Review+2: Slawek Kaplonski <skaplons@redhat.com> Code-Review+2: Brian Haley <haleyb.dev@gmail.com> Workflow+1: Brian Haley <haleyb.dev@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 10 Jan 2019 07:24:00 +0000 Reviewed-on: https://review.openstack.org/629335 Project: openstack/neutron Branch: refs/heads/master
-rw-r--r--neutron/privileged/agent/linux/netlink_lib.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/neutron/privileged/agent/linux/netlink_lib.py b/neutron/privileged/agent/linux/netlink_lib.py
index 8a10a0c..71ce3b0 100644
--- a/neutron/privileged/agent/linux/netlink_lib.py
+++ b/neutron/privileged/agent/linux/netlink_lib.py
@@ -49,9 +49,44 @@ from neutron.privileged.agent.linux import netlink_constants as nl_constants
49 49
50LOG = logging.getLogger(__name__) 50LOG = logging.getLogger(__name__)
51 51
52nfct = ctypes.CDLL(util.find_library('netfilter_conntrack')) 52nfct_lib = util.find_library('netfilter_conntrack')
53nfct = ctypes.CDLL(nfct_lib)
53libc = ctypes.CDLL(util.find_library('libc.so.6')) 54libc = ctypes.CDLL(util.find_library('libc.so.6'))
54 55
56# In unit tests the actual nfct library may not be installed, and since we
57# don't make actual calls to it we don't want to add a hard dependency.
58if nfct_lib:
59 # It's important that the types be defined properly on all of the functions
60 # we call from nfct, otherwise pointers can be truncated and cause
61 # segfaults.
62 nfct.nfct_set_attr.argtypes = [ctypes.c_void_p,
63 ctypes.c_int,
64 ctypes.c_void_p]
65 nfct.nfct_set_attr_u8.argtypes = [ctypes.c_void_p,
66 ctypes.c_int,
67 ctypes.c_uint8]
68 nfct.nfct_set_attr_u16.argtypes = [ctypes.c_void_p,
69 ctypes.c_int,
70 ctypes.c_uint16]
71 nfct.nfct_snprintf.argtypes = [ctypes.c_char_p,
72 ctypes.c_uint,
73 ctypes.c_void_p,
74 ctypes.c_uint,
75 ctypes.c_uint,
76 ctypes.c_uint]
77 nfct.nfct_new.restype = ctypes.c_void_p
78 nfct.nfct_destroy.argtypes = [ctypes.c_void_p]
79 nfct.nfct_query.argtypes = [ctypes.c_void_p,
80 ctypes.c_int,
81 ctypes.c_void_p]
82 nfct.nfct_callback_register.argtypes = [ctypes.c_void_p,
83 ctypes.c_int,
84 ctypes.c_void_p,
85 ctypes.c_void_p]
86 nfct.nfct_open.restype = ctypes.c_void_p
87 nfct.nfct_close.argtypes = [ctypes.c_void_p]
88
89
55IP_VERSIONS = [constants.IP_VERSION_4, constants.IP_VERSION_6] 90IP_VERSIONS = [constants.IP_VERSION_4, constants.IP_VERSION_6]
56DATA_CALLBACK = None 91DATA_CALLBACK = None
57 92