Jill Kaminski | 22 Jun 2011 19:13

show2() and self.__class__ question


Hello,

I have created a new file named mpls.py under the layers/ directory to 
define two new layers: MPLS and MPLS_MULTI.
They are working properly, except when I have an MPLS_MULTI() after an 
MPLS(), as in a = MPLS() / MPLS_MULTI().
If I call a.show2(), the MPLS_MULTI layer is displayed as an MPLS.

Here is my class:
"""
MPLS (Multi-Protocol Label Switching)

[RFC 3032]
"""

from scapy.packet import *
from scapy.fields import *
from scapy.layers.l2 import Ether, Dot1Q
from scapy.layers.ppp import PPP
from scapy.layers.inet import IP
from scapy.layers.inet6 import IPv6

class MPLS(Packet):
  name = "MPLS-Unicast"
  fields_desc = [
     BitField("label", 3, 20),
     BitField("experimental", 0, 3),
     BitField("bottom_of_stack", 1, 1),
     ByteField("ttl", 32)
(Continue reading)

Philippe Biondi | 22 Jun 2011 21:51

Re: show2() and self.__class__ question

Hi,

On Wed, 22 Jun 2011, Jill Kaminski wrote:

> I have created a new file named mpls.py under the layers/ directory to define 
> two new layers: MPLS and MPLS_MULTI.

First, be aware that there already exist the begining of a mpls extension 
in latest versions in contrib/mpls.py. However, I guess your work could 
enrich the existing implementation. Also, you'd better create new 
protocols in contrib/ so that I can easily distribute them in new 
releases.

> They are working properly, except when I have an MPLS_MULTI() after an 
> MPLS(), as in a = MPLS() / MPLS_MULTI().
> If I call a.show2(), the MPLS_MULTI layer is displayed as an MPLS.

You have an ambiguity here:

> bind_layers( MPLS,          MPLS,          bottom_of_stack=0 )
> bind_layers( MPLS,          MPLS_MULTI,    bottom_of_stack=0 )
> bind_layers( MPLS_MULTI,    MPLS,          bottom_of_stack=0 )
> bind_layers( MPLS_MULTI,    MPLS_MULTI,    bottom_of_stack=0 )

when bottom_of_stack=0, which should be the next header ? There is no way 
to choose. Scapy takes first one: MPLS.

---------------------------------------------------------------------
To unsubscribe, send a mail to scapy.ml-unsubscribe <at> secdev.org

(Continue reading)

Jill Kaminski | 22 Jun 2011 22:08

Re: show2() and self.__class__ question

Hi, and thank you for your reply!
If I create things that might be worth contributing, I will certainly 
add them to contrib.
> You have an ambiguity here:
>
>> bind_layers( MPLS,          MPLS,          bottom_of_stack=0 )
>> bind_layers( MPLS,          MPLS_MULTI,    bottom_of_stack=0 )
>> bind_layers( MPLS_MULTI,    MPLS,          bottom_of_stack=0 )
>> bind_layers( MPLS_MULTI,    MPLS_MULTI,    bottom_of_stack=0 )
>
> when bottom_of_stack=0, which should be the next header ? There is no 
> way to choose. Scapy takes first one: MPLS.
>
>
I guess I have a misunderstanding of bind_layers. I was assuming that 
the first bind_layers statement shown above does (essentially) the 
following:
- if an MPLS follows another MPLS, then set the bottom_of_stack field in 
the first MPLS to 0.

I was not thinking that a decision would be made based on 
bottom_of_stack, or that scapy would care what these fields are at all. 
In other words, I didn't think scapy would be deciding which should be 
the next header based on bottom_of_stack. Can you please explain this 
for me?

With much gratitude,
Jill

PS -- this should probably go in a new thread, but here you go anyway! I 
(Continue reading)


Gmane