Skip to content

BGP: Handle multiple capabilities in one Optional Parameter#480

Open
kbandla wants to merge 1 commit into
masterfrom
issue118
Open

BGP: Handle multiple capabilities in one Optional Parameter#480
kbandla wants to merge 1 commit into
masterfrom
issue118

Conversation

@kbandla

@kbandla kbandla commented Jul 13, 2020

Copy link
Copy Markdown
Owner
  • Fixes BGP (v4) Open typed packet failing to parse. #118 (please see issue for details)
  • Introduce capabilities property (for cases where there are >1 capablity)
  • Keep older capability property for backward compatibility
  • Added __bgp10 unittest, which broke the original parser

* Fixes #118 (please see issue for details)
* Introduce `capabilities` property (for cases where there are >1 capablity)
* Keep older `capability` property for backward compatibility
* Added `__bgp10` unittest, which broke the original parser
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 89.288% when pulling a7bdc52 on issue118 into bc0fc98 on master.

@amgadhanafy amgadhanafy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe this fix will be useful in multiple locations that have similar issues (single value instead of list), I believe making a generic way to apply it is useful

@obormot obormot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

minor comments.. looks good overall 👍

Comment thread dpkt/bgp.py

def __bytes__(self):
caps = b''.join(map(bytes, self.capabilities))
self.cap_len = len(caps)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unused?
also prob shouldn't create new fields inside this method

Comment thread dpkt/bgp.py
self.capability = self.capabilities[0]

def __len__(self):
return self.__hdr_len__ + sum(map(len, self.capabilities))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

calling len() on each instance of capability would cause serialization to bytes, then taking the resulting length. would something like sum(cap.len for cap in self.capabilities) achieve the same result?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Alternatively you could override the __len__ method to return that header element?

Comment thread dpkt/bgp.py
while self.data:
capability = self.Capability(self.data)
l.append(capability)
self.data = self.data[self.__hdr_len__+capability.len:]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe pep8 would want whitespace around +

@amgadhanafy

Copy link
Copy Markdown
Contributor

Hi @kbandla ,
Any chance to get this merged soon?

Comment thread dpkt/bgp.py
self.capability = self.capabilities[0]

def __len__(self):
return self.__hdr_len__ + sum(map(len, self.capabilities))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't cover the case where the type is AUTHENTICATION, as capabilities won't exist (and it doesn't count the length of the authentication data).

Comment thread dpkt/bgp.py
return self.__hdr_len__ + sum(map(len, self.capabilities))

def __bytes__(self):
caps = b''.join(map(bytes, self.capabilities))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will also fail if this is an authentication parameter. Perhaps some variant of caps = bytes(self.data) if not isinstance(self.data, list) else b''.join(map(bytes, self.data))?

@crocogorical crocogorical mentioned this pull request Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BGP (v4) Open typed packet failing to parse.

5 participants