aboutsummaryrefslogtreecommitdiffstats
path: root/package/libs/libnl-tiny/src/include/linux/netlink.h
diff options
context:
space:
mode:
authorFlorian Fainelli <florian@openwrt.org>2015-01-10 18:10:04 +0000
committerFlorian Fainelli <florian@openwrt.org>2015-01-10 18:10:04 +0000
commit1f07007293c2a98abd721bf6bbe112c5cae71525 (patch)
tree24e08ec57941d3a93d99d153f86458ae7e026f69 /package/libs/libnl-tiny/src/include/linux/netlink.h
parent57a3eb31a2a14cd25099c0e1e3569b2c75a9e38e (diff)
downloadupstream-1f07007293c2a98abd721bf6bbe112c5cae71525.tar.gz
upstream-1f07007293c2a98abd721bf6bbe112c5cae71525.tar.bz2
upstream-1f07007293c2a98abd721bf6bbe112c5cae71525.zip
adm5120: add experimental 3.14 kernel support
Signed-off-by: Florian Fainelli <florian@openwrt.org> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@43915 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/libs/libnl-tiny/src/include/linux/netlink.h')
0 files changed, 0 insertions, 0 deletions
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
from __future__ import (absolute_import, print_function, division)
import sys

import six

from netlib import tcp
from ..models import ServerConnection
from ..exceptions import ProtocolException
from netlib.exceptions import TcpException


class _LayerCodeCompletion(object):
    """
    Dummy class that provides type hinting in PyCharm, which simplifies development a lot.
    """

    def __init__(self, **mixin_args):  # pragma: nocover
        super(_LayerCodeCompletion, self).__init__(**mixin_args)
        if True:
            return
        self.config = None
        """@type: libmproxy.proxy.ProxyConfig"""
        self.client_conn = None
        """@type: libmproxy.models.ClientConnection"""
        self.server_conn = None
        """@type: libmproxy.models.ServerConnection"""
        self.channel = None
        """@type: libmproxy.controller.Channel"""
        self.ctx = None
        """@type: libmproxy.protocol.Layer"""


class Layer(_LayerCodeCompletion):
    """
    Base class for all layers. All other protocol layers should inherit from this class.
    """

    def __init__(self, ctx, **mixin_args):
        """
        Each layer usually passes itself to its child layers as a context. Properties of the
        context are transparently mapped to the layer, so that the following works:

        .. code-block:: python

            root_layer = Layer(None)
            root_layer.client_conn = 42
            sub_layer = Layer(root_layer)
            print(sub_layer.client_conn) # 42

        The root layer is passed a :py:class:`libmproxy.proxy.RootContext` object,
        which provides access to :py:attr:`.client_conn <libmproxy.proxy.RootContext.client_conn>`,
        :py:attr:`.next_layer <libmproxy.proxy.RootContext.next_layer>` and other basic attributes.

        Args:
            ctx: The (read-only) parent layer / context.
        """
        self.ctx = ctx
        """
        The parent layer.

        :type: :py:class:`Layer`
        """
        super(Layer, self).__init__(**mixin_args)

    def __call__(self):
        """Logic of the layer.

        Returns:
            Once the protocol has finished without exceptions.

        Raises:
            ~libmproxy.exceptions.ProtocolException: if an exception occurs. No other exceptions must be raised.
        """
        raise NotImplementedError()

    def __getattr__(self, name):
        """
        Attributes not present on the current layer are looked up on the context.
        """
        return getattr(self.ctx, name)

    @property
    def layers(self):
        """
        List of all layers, including the current layer (``[self, self.ctx, self.ctx.ctx, ...]``)
        """
        return [self] + self.ctx.layers

    def __repr__(self):
        return type(self).__name__


class ServerConnectionMixin(object):
    """
    Mixin that provides a layer with the capabilities to manage a server connection.
    The server address can be passed in the constructor or set by calling :py:meth:`set_server`.
    Subclasses are responsible for calling :py:meth:`disconnect` before returning.

    Recommended Usage:

    .. code-block:: python

        class MyLayer(Layer, ServerConnectionMixin):
            def __call__(self):
                try:
                    # Do something.
                finally:
                    if self.server_conn:
                        self.disconnect()
    """

    def __init__(self, server_address=None, source_address=None):
        super(ServerConnectionMixin, self).__init__()
        self.server_conn = ServerConnection(server_address, source_address)
        self.__check_self_connect()

    def __check_self_connect(self):
        """
        We try to protect the proxy from _accidentally_ connecting to itself,
        e.g. because of a failed transparent lookup or an invalid configuration.
        """
        address = self.server_conn.address
        if address:
            self_connect = (
                address.port == self.config.port and