a
    kÄ#d¶  ã                   @   s  d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlmZ ddlmZ ddd	d
ddœZdddddddddddœ
ZG dd„ deƒZG dd„ deƒZddddd œZG d!d"„ d"eƒZG d#d$„ d$eƒZeeed%d&� ed'k�rdd(lmZ ee ƒ d$d)� d*S )+aa  
    VTP Scapy Extension
    ~~~~~~~~~~~~~~~~~~~~~

    :version:   2009-02-15
    :copyright: 2009 by Jochen Bartl
    :e-mail:    lobo@c3a.de / jochen.bartl@gmail.com
    :license:   GPL v2

        This program is free software; you can redistribute it and/or
        modify it under the terms of the GNU General Public License
        as published by the Free Software Foundation; either version 2
        of the License, or (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

    :TODO:

        - Join messages
        - RE MD5 hash calculation
        - Have a closer look at 8 byte padding in summary adv:

            "debug sw-vlan vtp packets" says the TLV length is invalid,
            when I change the values:

            ``b'\x00\x00\x00\x01\x06\x01\x00\x02'``

            * \x00\x00 ?
            * \x00\x01 tlvtype?
            * \x06 length?
            * \x00\x02 value?

        - h2i function for VTPTimeStampField

    :References:

        - | Understanding VLAN Trunk Protocol (VTP)
          | http://www.cisco.com/en/US/tech/tk389/tk689/technologies_tech_note09186a0080094c52.shtml  # noqa: E501
é    )ÚPacketÚbind_layers)ÚByteEnumFieldÚ	ByteFieldÚConditionalFieldÚFieldLenFieldÚIPFieldÚPacketListFieldÚ
ShortFieldÚSignedIntFieldÚStrFixedLenFieldÚStrLenFieldÚ	XIntField)ÚSNAP)Úchb)ÚconfZEthernetZFDDIZTrCRFzFDDI-netZTrBRF)é   é   é   é   é   zSource-Routing Ring NumberzSource-Routing Bridge NumberzSpanning-Tree Protocol TypezParent VLANzTranslationally Bridged VLANsZPruningzBridge TypezMax ARE Hop CountzMax STE Hop CountzBackup CRF Mode)
r   r   r   r   r   é   é   é   é	   é
   c                   @   s>   e Zd ZdZeddeƒeddƒedddd„ d	�gZd
d„ Z	dS )ÚVTPVlanInfoTlvzVTP VLAN Info TLVÚtyper   ÚlengthÚvalueNc                 C   s
   | j d S ©Nr   )r   ©Úpkt© r#   úH/var/www/html/gsl.tools/lib/python3.9/site-packages/scapy/contrib/vtp.pyÚ<lambda>V   ó    zVTPVlanInfoTlv.<lambda>©Zlength_fromc                 C   s   t jS ©N©r   Zpadding_layer©ÚselfÚpr#   r#   r$   Úguess_payload_classY   s    z"VTPVlanInfoTlv.guess_payload_class)
Ú__name__Ú
__module__Ú__qualname__Únamer   Ú_VTP_VLANINFO_TLV_TYPEr   r   Úfields_descr-   r#   r#   r#   r$   r   Q   s   
ýr   c                   @   s–   e Zd ZdZeddƒedddddœƒed	d
eƒeddddƒedd
ƒeddƒe	ddƒe
dddd„ d�eedg edd„ d�dd„ ƒg	Zdd„ Zdd„ ZdS )ÚVTPVlanInfozVTP VLAN InfoÚlenNÚstatusr   ÚactiveZ	suspended)r   r   r   r   ÚvlannamelenÚvlannameÚBZvlanidZmtuiÜ  Z
dot10indexÚdefaultc                 C   s   d| j d d  S )Nr   r   )r8   r!   r#   r#   r$   r%   h   r&   zVTPVlanInfo.<lambda>r'   Ztlvlistc                 C   s   | j d d| jd d   S )Né   r   r   )r5   r8   r!   r#   r#   r$   r%   l   r&   c                 C   s
   | j dvS )N)r   r   )r   r!   r#   r#   r$   r%   n   r&   c                 C   sn   dt | jƒd d  }| j d u r@|d }t|d@ ƒ|dd …  }|t | jƒ }|dkrb|d| 7 }||7 }|S )Nr   r   r<   éÿ   r   r   ó    )r5   r9   r   )r+   r,   Úpayr8   Ztmp_lenr#   r#   r$   Ú
post_buildr   s    
zVTPVlanInfo.post_buildc                 C   s   t jS r(   r)   r*   r#   r#   r$   r-   ‚   s    zVTPVlanInfo.guess_payload_class)r.   r/   r0   r1   r   r   Ú_VTP_VLAN_TYPEr   r
   r   r   r   r	   r   r3   r@   r-   r#   r#   r#   r$   r4   ]   s*   
ÿþûör4   zSummary AdvertisementzSubset AdvertisementszAdvertisement RequestZJoin)r   r   r   r   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚVTPTimeStampFieldc                 C   s   t  | ||d¡ d S )Nr<   )r   Ú__init__)r+   r1   r;   r#   r#   r$   rC   �   s    zVTPTimeStampField.__init__c              	   C   sD   d|d d… |dd… |dd… |dd… |dd… |dd… f S )Nz%s-%s-%s %s:%s:%sr   r   r   r   r   r<   r#   )r+   r"   Úxr#   r#   r$   Úi2repr’   s    zVTPTimeStampField.i2reprN)r.   r/   r0   rC   rE   r#   r#   r#   r$   rB   Ž   s   rB   c                   @   sæ   e Zd Zd Zeddƒeddeƒeeddƒdd„ ƒeeddƒd	d„ ƒeed
dƒdd„ ƒeddƒedddƒee	ddƒdd„ ƒee
ddƒdd„ ƒeeddƒdd„ ƒeedddƒdd„ ƒeedg eƒdd„ ƒeed dƒd!d„ ƒgZd"d#„ ZdS )$ÚVTPÚverr   Úcoder   Z	followersc                 C   s
   | j dkS r    ©rH   r!   r#   r#   r$   r%   œ   r&   zVTP.<lambda>Úseqc                 C   s
   | j dkS ©Nr   rI   r!   r#   r#   r$   r%   ž   r&   Úreservedr   c                 C   s
   | j dkS ©Nr   rI   r!   r#   r#   r$   r%       r&   Ú
domnamelenNÚdomnameZ
manbearpigé    Úrevc                 C   s   | j dkp| j dkS )Nr   r   rI   r!   r#   r#   r$   r%   ¤   s   
Úuidz192.168.0.1c                 C   s
   | j dkS r    rI   r!   r#   r#   r$   r%   ¨   r&   Ú	timestampZ930301000000c                 C   s
   | j dkS r    rI   r!   r#   r#   r$   r%   ª   r&   Úmd5s                   é   c                 C   s
   | j dkS r    rI   r!   r#   r#   r$   r%   ¬   r&   Zvlaninfoc                 C   s
   | j dkS rK   rI   r!   r#   r#   r$   r%   ¯   r&   Z
startvaluec                 C   s
   | j dkS rM   rI   r!   r#   r#   r$   r%   ±   r&   c                 C   sJ   | j d u r>t| j d¡ƒ}|d d… t|d@ ƒ |dd …  }||7 }|S )Nr>   r   r=   r   )rN   r5   rO   Ústripr   )r+   r,   r?   rN   r#   r#   r$   r@   ´   s
    
$zVTP.post_build)r.   r/   r0   r1   r   r   Ú
_VTP_Typesr   r   r   r   rB   r	   r4   r
   r3   r@   r#   r#   r#   r$   rF   –   sF   

ÿ
ÿ
ÿ

ÿ
ÿ
ÿÿ
þ
ÿèrF   i   rI   Ú__main__)Úinteract)ZmydictZmybannerN)!Ú__doc__Zscapy.packetr   r   Zscapy.fieldsr   r   r   r   r   r	   r
   r   r   r   r   Zscapy.layers.l2r   Zscapy.compatr   Zscapy.configr   rA   r2   r   r4   rW   rB   rF   r.   Z
scapy.mainrY   Úglobalsr#   r#   r#   r$   Ú<module>   sF   +4û	ö*ü(
