HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python311/lib/python3.11/site-packages/pyroute2/dhcp/__pycache__/__init__.cpython-311.pyc
�

�;f@'����dZddlZddlZddlmZddlmZddlmZdZdZ	dZ
dZdZd	Z
d
ZdZdZd
Zeed��sGd�de��ZGd�de��ZGd�de��ZdS)ao

DHCP protocol
=============

The DHCP implementation here is far from complete, but
already provides some basic functionality. Later it will
be extended with IPv6 support and more DHCP options
will be added.

Right now it can be interesting mostly to developers,
but not users and/or system administrators. So, the
development hints first.

The packet structure description is intentionally
implemented as for netlink packets. Later these two
parsers, netlink and generic, can be merged, so the
syntax is more or less compatible.

Packet fields
-------------

There are two big groups of items within any DHCP packet.
First, there are BOOTP/DHCP packet fields, they're defined
with the `fields` attribute::

    class dhcp4msg(msg):
        fields = ((name, format, policy),
                  (name, format, policy),
                  ...
                  (name, format, policy))

The `name` can be any literal. Format should be specified
as for the struct module, like `B` for `uint8`, or `i` for
`int32`, or `>Q` for big-endian uint64. There are also
aliases defined, so one can write `uint8` or `be16`, or
like that. Possible aliases can be seen in the
`pyroute2.protocols` module.

The `policy` is a bit complicated. It can be a number or
literal, and it will mean that it is a default value, that
should be encoded if no other value is given.

But when the `policy` is a dictionary, it can contain keys
as follows::

    'l2addr': {'format': '6B',
               'decode': ...,
               'encode': ...}

Keys `encode` and `decode` should contain filters to be used
in decoding and encoding procedures. The encoding filter
should accept the value from user's definition and should
return a value that can be packed using `format`. The decoding
filter should accept a value, decoded according to `format`,
and should return value that can be used by a user.

The `struct` module can not decode IP addresses etc, so they
should be decoded as `4s`, e.g. Further transformation from
4 bytes string to a string like '10.0.0.1' performs the filter.

DHCP options
------------

DHCP options are described in a similar way::

    options = ((code, name, format),
               (code, name, format),
               ...
               (code, name, format))

Code is a `uint8` value, name can be any string literal. Format
is a string, that must have a corresponding class, inherited from
`pyroute2.dhcp.option`. One can find these classes in
`pyroute2.dhcp` (more generic) or in `pyroute2.dhcp.dhcp4msg`
(IPv4-specific). The option class must reside within dhcp message
class.

Every option class can be decoded in two ways. If it has fixed
width fields, it can be decoded with ordinary `msg` routines, and
in this case it can look like that::

    class client_id(option):
        fields = (('type', 'uint8'),
                  ('key', 'l2addr'))

If it must be decoded by some custom rules, one can define the
policy just like for the fields above::

    class array8(option):
        policy = {'format': 'string',
                  'encode': lambda x: array('B', x).tobytes(),
                  'decode': lambda x: array('B', x).tolist()}

In the corresponding modules, like in `pyroute2.dhcp.dhcp4msg`,
one can define as many custom DHCP options, as one need. Just
be sure, that they are compatible with the DHCP server and all
fit into 1..254 (`uint8`) -- the 0 code is used for padding and
the code 255 is the end of options code.
�N)�array)�
basestring)�msg���������tobytesc��eZdZejZdS)rN)�__name__�
__module__�__qualname__r�tostringr���I/opt/alt/python311/lib/python3.11/site-packages/pyroute2/dhcp/__init__.pyrr|s�������.���rrc�H�eZdZdZdZdZdZdd�Zed���Z	d�Z
d�ZdS)	�optionrNrc�F�tj|||||���||_dS)N)�content�buf�offset�value)r�__init__�code)�selfrrrrrs      rrzoption.__init__�s3�����'�s�6��	
�	
�	
�	
���	�	�	rc�B�|j�dS|jdkrdS|jdzS)Nrrr)�data_length)r s r�lengthz
option.length�s1����#��4���q� � ��1��#�a�'�'rc���|xjtjd|j��z
c_|jdvr|S|j}d|_|j��|j�dd���|j��}|jddkrdt|��z}n
|jd}tj	d	d
kr*t|t��r|�d��}tj||��|_ntj|��|j}||_|xjtjdt|����z
c_|xj|z
c_|S)N�B)r�r�encodec��|S�Nr��xs r�<lambda>zoption.encode.<locals>.<lambda>�����r�format�string�%isrrzutf-8)r�struct�packr�policy�getr�len�sys�version_info�
isinstance�strr'r)r �saver�fmt�datas     rr'z
option.encode�s8�����F�K��T�Y�/�/�/����9�� � ��K��x������;�"�:�D�K�O�O�H�k�k�:�:�4�:�F�F�E��{�8�$��0�0��c�%�j�j�(����k�(�+�����"�a�'�'�J�u�c�,B�,B�'����W�-�-���{�3��.�.�D�H�H��J�t�����x��������F�K��S��Y�Y�/�/�/������D�����rc���tjd|j|jdz|jdz���d|_|j��|jddkrd|jz}n
|jd}tj||j|jdz|jdz|jz���}t
|��dkr|d}|j�dd	���|��}t|t��r.|jddkr|d|�
d
���}||_n2|j}|xjdz
c_tj
|��||_|S)Nr%rrrr.r/r0�decodec��|Sr)rr*s rr,zoption.decode.<locals>.<lambda>�r-r�)r1�unpackrrr"r3r5r4r8r�findrrr>)r r;rrs    rr>z
option.decode�sd��!�=����$�+��/�D�K�!�O�;�<�
�
�
�
����;�"��{�8�$��0�0��d�.�.����k�(�+���M������q��4�;��?�T�=M�+M�M�N���E��5�z�z�Q����a���:�D�K�O�O�H�k�k�:�:�5�A�A�E��5�*�-�-�
5��K��)�X�5�5��3��
�
�7� 3� 3�3�4���D�J�J��[�F�
�K�K�1��K�K��J�t���� �D�K��r)NrrNr)rrrrr"r3rr�propertyr#r'r>rrrrr�su�������D��K�
�F��E������(�(��X�(����8 � � � � rrc���eZdZdZdZiZiZd�Zd�Zd�Z	Gd�de
��ZGd�d	e
��ZGd
�de
��Z
Gd�d
e
��ZGd�de
��ZGd�de
��ZGd�de
��ZdS)�dhcpmsgrNc�f�|jD](}|dd�\}}}|||d�x|j|<|j|<�)dS)Nr)�namerr.)�options�_decode_map�_encode_map)r rrrGr;s     r�_register_optionszdhcpmsg._register_options�s_���l�	�	�F�$�R�a�R�j�O�D�$�����?�?�
�D��T�"�T�%5�d�%;�%;�	�	rc�F�tj|��|���i|d<|jt	|j��k�rUt
jd|j|j|jdz���d}|dkr|xjdz
c_�j|dkr|S||jvrLt
jd|j|jdz|jdz���d}|xj|dzz
c_��t||j|d��}||j|j���}|���|xj|j
z
c_|j�|j}n|}||d|j|d	<|jt	|j��k��U|S)
NrHr%rrr&rr.)rrrG)rr>rKrr5rr1rArI�getattrr#r)r rr#�option_classrrs      rr>zdhcpmsg.decode�s����
�4������� � � ���Y���k�C���M�M�)�)��=��d�h�t�{�T�[�1�_�/L�&M�N�N���D��q�y�y����q� �����s�{�{����4�+�+�+������$�+��/�D�K�!�O�"C�D���������v��z�)����#�4��)9�$�)?��)I�J�J�L�!�\�d�h�t�{�C�C�C�F��M�M�O�O�O��K�K�6�=�(�K�K��|�'�������>C�D��O�D�,�T�2�6�:�;�5�k�C���M�M�)�)�6�rc�0�tj|��|���|�d��ptgd�d�}|xj|�d|d������jz
c_|xj|�d|dd	�d
������jz
c_|xj|�dd
������jz
c_|�	��D]�\}}|dvr�
|j
�|ddi��d}|��0t||��}t|t��r|||j
|d���}n||j
|d|���}|xj|���jz
c_��|xj|�d������jz
c_|S)NrH)rrr���)�message_type�parameter_list�5rS)rrr�chaddr)�type�key�=)r�<�pyroute2)rS�	client_id�	vendor_idr.rr&)rr'rKr4�DHCPDISCOVERr�uint8r\r/�itemsrJrMr8�dict�none)r rHrGrr;rNrs       rr'zdhcpmsg.encodes���
�4������� � � ��(�(�9�%�%�
�(�3�3�3�*
�*
��
	
����J�J�B�g�n�&=�J�>�>�E�E�G�G�K�	
���	
����N�N�A�d�8�n�=�=�B�N�G�G�
�V�X�X�
�	
���
	
���D�K�K�R�z�K�:�:�A�A�C�C�G�G���"�=�=�?�?�	,�	,�K�D�%��A�A�A���"�&�&�t�h��-=�>�>�x�H�C��{��"�4��-�-�L��%��&�&�
�%���� 0�� 6�v� >������&���)�$�/��7�u�����
�H�H��
�
���+�+�H�H�H����D�I�I�3�I�'�'�.�.�0�0�4�4����rc��eZdZdS)�dhcpmsg.noneN)rrrrrrrbrd,s�������rrbc��eZdZddiZdS)�dhcpmsg.be16r.z>HN�rrrr3rrr�be16rf/��������D�!���rrhc��eZdZddiZdS)�dhcpmsg.be32r.z>INrgrrr�be32rk2rirrlc��eZdZddiZdS)�
dhcpmsg.uint8r.r%Nrgrrrr_rn5s�������C����rr_c��eZdZddiZdS)�dhcpmsg.stringr.r/Nrgrrrr/rp8s�������H�%���rr/c��eZdZdd�d�d�ZdS)�dhcpmsg.array8r/c�F�td|�����S�Nr%)rrr*s rr,zdhcpmsg.array8.<lambda>>s���c�1�
�
� 5� 5� 7� 7�rc�F�td|�����Srt)r�tolistr*s rr,zdhcpmsg.array8.<lambda>?s���c�1�
�
� 4� 4� 6� 6�r)r.r'r>Nrgrrr�array8rr;s)�������7�7�6�6�
�
���rrwc��eZdZdZdS)�dhcpmsg.client_id))rWr_)rX�l2addrN)rrr�fieldsrrrr\ryBs������7���rr\)rrrrHrzrJrIrKr>r'rrbrhrlr_r/rwr\rrrrErE�s}�������G�
�F��K��K�������B&�&�&�P
�
�
�
�
�v�
�
�
�"�"�"�"�"�v�"�"�"�"�"�"�"�"�v�"�"�"�!�!�!�!�!��!�!�!�&�&�&�&�&��&�&�&�
�
�
�
�
��
�
�
�8�8�8�8�8�F�8�8�8�8�8rrE)�__doc__r1r6r�pyroute2.commonr�pyroute2.protocolsr�BOOTREQUEST�	BOOTREPLYr^�	DHCPOFFER�DHCPREQUEST�DHCPDECLINE�DHCPACK�DHCPNAK�DHCPRELEASE�
DHCPINFORM�hasattrrrErrr�<module>r�s?��b�b�H�
�
�
�
�
�
�
�������&�&�&�&�&�&�"�"�"�"�"�"���
�	���
�	�����
��
����
�
��w�u�i� � �!�!�!�!�!�!��!�!�!�Q�Q�Q�Q�Q�S�Q�Q�Q�ho8�o8�o8�o8�o8�c�o8�o8�o8�o8�o8r