PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/saltstack/salt/extras-3.10/pyroute2/netlink/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/saltstack/salt/extras-3.10/pyroute2/netlink/proxy.py

'''
Netlink proxy engine
'''

import errno
import logging
import struct
import threading
import traceback

from pyroute2.netlink.exceptions import NetlinkError

log = logging.getLogger(__name__)


class NetlinkProxy(object):
    '''
    Proxy schemes::

        User -> NetlinkProxy -> Kernel
                       |
             <---------+

        User <- NetlinkProxy <- Kernel

    '''

    def __init__(self, policy='forward', nl=None, lock=None):
        self.nl = nl
        self.lock = lock or threading.Lock()
        self.pmap = {}
        self.policy = policy

    def handle(self, msg):
        #
        # match the packet
        #
        ptype = msg['header']['type']
        plugin = self.pmap.get(ptype, None)
        if plugin is not None:
            with self.lock:
                try:
                    ret = plugin(msg, self.nl)
                    if ret is None:
                        #
                        # The packet is terminated in the plugin,
                        # return the NLMSG_ERR == 0
                        #
                        # FIXME: optimize
                        #
                        newmsg = struct.pack('IHH', 40, 2, 0)
                        newmsg += msg.data[8:16]
                        newmsg += struct.pack('I', 0)
                        # nlmsgerr struct alignment
                        newmsg += b'\0' * 20
                        return {'verdict': self.policy, 'data': newmsg}
                    else:
                        return ret

                except Exception as e:
                    log.error(''.join(traceback.format_stack()))
                    log.error(traceback.format_exc())
                    # errmsg
                    if isinstance(e, (OSError, IOError)):
                        code = e.errno
                    elif isinstance(e, NetlinkError):
                        code = e.code
                    else:
                        code = errno.ECOMM
                    newmsg = struct.pack('HH', 2, 0)
                    newmsg += msg.data[8:16]
                    newmsg += struct.pack('I', code)
                    newmsg += msg.data
                    newmsg = struct.pack('I', len(newmsg) + 4) + newmsg
                    return {'verdict': 'error', 'data': newmsg}
        return None