Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] u32: fix for negative offsets #656

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pyroute2/netlink/rtnl/tcmsg/cls_u32.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,20 @@ def cut_field(key, separator):
return (new_key, field)

# 'header' array to pack keys to
header = [(0, 0) for i in range(256)]
header = [(0, 0) for i in range(-256, 256)]

keys = []
# iterate keys and pack them to the 'header'
for key in self['keys']:
# TODO tags: filter
(key, nh) = cut_field(key, '@') # FIXME: do not ignore nh
(key, offset) = cut_field(key, '+')
if key.find('-') != -1:
(key, offset) = cut_field(key, '-')
use_minus = True
else:
(key, offset) = cut_field(key, '+')
use_minus = False

offset = int(offset, 0)
# a little trick: if you provide /00ff+8, that
# really means /ff+9, so we should take it into
Copy link

@reshmasreekumar reshmasreekumar Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vic063 you will probably have to change the logic of updating offset at line number 185 .i.e.

offset = offset + 1 if not use_minus else offset - 1

Expand All @@ -184,6 +190,8 @@ def cut_field(key, separator):
mask = int(mask, 0)
value = int(key, 0)
bits = 24
if use_minus:
offset *= -1
if mask == 0 and value == 0:
key = self.u32_key(data=self.data)
key['key_off'] = offset
Expand All @@ -201,7 +209,7 @@ def cut_field(key, separator):
key = None
value = 0
mask = 0
for offset in range(256):
for offset in range(-256, 256):
(bvalue, bmask) = header[offset]
if bmask > 0 and key is None:
key = self.u32_key(data=self.data)
Expand Down