
    h                        d Z ddlmZmZmZmZmZmZ ddlm	Z	m
Z
mZ ddlmZmZ ddlmZ  G d de	          Z G d d	e	          Z G d
 de	          Z G d de	          Zd Z G d de	          Zd Z G d de	          Z G d de          Z eee           dD ]Z e
eee            e
ee            e
ee           dS )a  
    GARP - Generic Attribute Register Protocol
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :author:    Sergey Matsievskiy, matsievskiysv@gmail.com

    :description:

        This module provides Scapy layers for the GARP protocol and its
        two applications: GARP VLAN Registration Protocol (GVRP) and
        GARP Multicast Registration Protocol (GMRP)

        normative references:
            - IEEE 802.1D 2004 - Media Access Control (MAC) Bridges
            - IEEE 802.1Q 1998 - Virtual Bridged Local Area Networks

    )LenField	EnumField	ByteFieldPacketListField
ShortFieldMACField)Packetbind_layerssplit_layers)LLCDot3)warningc                   6    e Zd ZdZd Z edd          gZd ZdS )GVRPz
    GVRP
    vlan   c                 
    d|fS N     selfss     V/mounts/lovelace/software/anaconda3/lib/python3.11/site-packages/scapy/contrib/gxrp.pyextract_paddingzGVRP.extract_padding0       Avr   N)__name__
__module____qualname____doc__namer   fields_descr   r   r   r   r   r   &   sJ          D :fa(()K    r   r   c                   6    e Zd ZdZdZ edd          gZd ZdS )
GMRP_GROUPz
    GMRP Group
    z
GMRP GroupaddrNc                 
    d|fS r   r   r   s     r   r   zGMRP_GROUP.extract_padding>   r   r   )r   r   r   r    r!   r   r"   r   r   r   r   r$   r$   4   sJ          D 8FD))*K    r   r$   c                   B    e Zd ZdZdZ edddddd	          gZd
 ZdS )GMRP_SERVICEz
    GMRP Service
    zGMRP Serviceeventr   z
All GroupszAll Unregistered Groups)r   r   Bfmtc                 
    d|fS r   r   r   s     r   r   zGMRP_SERVICE.extract_paddingS   r   r   N)r   r   r   r    r!   r   r"   r   r   r   r   r(   r(   B   sf          D 		%>??		
 	
 	
K    r   r(   c                        e Zd ZdZdZ edddd            edd	d
ddddddd          gZ fdZd Z	 fdZ
 xZS )GARP_ATTRIBUTEz"
    GARP attribute container
    zGARP AttributelenNr*   c                     | dz   S N   r   )ls    r   <lambda>zGARP_ATTRIBUTE.<lambda>`   s
    A r   )r,   adjustr)   r   LeaveAll	JoinEmptyJoinIn
LeaveEmptyLeaveInEmpty)r   r   r3            r+   c                     t          t          |                               |          }| j        %| j        dk    r| j        dk    rt          d           |S )Nr   r3   z#Non-empty payload at LeaveAll event)superr/   
do_dissectr0   r)   r   )r   r   	__class__s     r   rB   zGARP_ATTRIBUTE.do_dissectp   sP    .$''221558DJ!OO19:::r   c                 >    | j         dz
  }|d |         ||d          fS r2   )r0   )r   r   boundarys      r   r   zGARP_ATTRIBUTE.extract_paddingv   s(    8a<(|Qxyy\))r   c                 2   	 | j         }|j         }|j        }|j        }|j        dk    rt          S |j        dk    r$|j        dk    rt
          S |j        dk    rt          S n# t          $ r Y nw xY wt          t          |           
                    |          S )N01:80:c2:00:00:2101:80:c2:00:00:20r   r3   )parent
underlayerdstr   typer$   r(   AttributeErrorrA   r/   guess_payload_class)r   payloadgarp_messagegarpllcdot3rC   s         r   rN   z"GARP_ATTRIBUTE.guess_payload_classz   s    	;L&D/C>D//////$))%%!&!++'' 	 	 	D	^T**>>wGGGs   -A! A! A! !
A.-A.)r   r   r   r    r!   r   r   r"   rB   r   rN   __classcell__)rC   s   @r   r/   r/   W   s          D 	#oo>>>	 !  	
 	
 	
K"    * * *H H H H H H H H Hr   r/   c                     |r!t          |          dk    s|dd         dk    rd S t          |dd                   dk    rt          S d S )Nr   r       r3   )r0   ordr/   pktlstcurremains       r   parse_next_attrr]      sW     S[[A%%!)?)?t	VAaC[		Q		tr   c                   f    e Zd ZdZdZ edd           edg e           edd          gZd	 Z	d
S )GARP_MESSAGEz 
    GARP message container
    zGARP MessagerL   r   attrsnext_cls_cbend_markr   c                 
    d|fS r   r   r   s     r   r   zGARP_MESSAGE.extract_padding   r   r   N)
r   r   r   r    r!   r   r   r]   r"   r   r   r   r   r_   r_      sm          D	&$AAA	*c""K    r   r_   c                 Z    |st          |          dk    s|dd         dk    rd S t          S )Nr   r   rV   )r0   r_   rX   s       r   parse_next_msgrf      s7     c&kkQ&&&1+*@*@tr   c                   `    e Zd ZdZd Z edd           edg e           edd          gZ	dS )	GARPz
    GARP packet
    proto_idr   msgsra   rc   r   N)
r   r   r   r    r!   r   r   rf   r   r"   r   r   r   rh   rh      sZ          D 	
:v&&???	*c""KKKr   rh   c                       e Zd ZdZg ZdS )LLC_GARPz'
    Dummy class for layer binding
    N)r   r   r   r    payload_guessr   r   r   rl   rl      s          MMMr   rl   )rH   rG   z01:80:c2:00:00:22z01:80:c2:00:00:23z01:80:c2:00:00:24z01:80:c2:00:00:25z01:80:c2:00:00:26z01:80:c2:00:00:27z01:80:c2:00:00:28z01:80:c2:00:00:29z01:80:c2:00:00:2az01:80:c2:00:00:2bz01:80:c2:00:00:2cz01:80:c2:00:00:2dz01:80:c2:00:00:2ez01:80:c2:00:00:2f)rK   N)r    scapy.fieldsr   r   r   r   r   r   scapy.packetr	   r
   r   scapy.layers.l2r   r   scapy.errorr   r   r$   r(   r/   r]   r_   rf   rh   rl   macr   r   r   <module>rs      sa   "                ; : : : : : : : : : % % % % % % % %          6              6   *6H 6H 6H 6H 6HV 6H 6H 6Hr      6          6       s    T3   ! ) )C  KhC((((( D#    Hd     r   