コード例 #1
0
    def session_create(self, tunnel_id, session_id, peer_session_id, name):
        """
        Creates a new ethernet session over the tunnel.

        :param tunnel_id: Local tunnel identifier
        :param session_id: Local session identifier
        :param peer_session_id: Remote peer session identifier
        :param name: Interface name
        """

        msg = self._create_message(
            L2TP_CMD_SESSION_CREATE,
            [
                netlink.U32Attr(L2TP_ATTR_CONN_ID, tunnel_id),
                netlink.U32Attr(L2TP_ATTR_SESSION_ID, session_id),
                netlink.U32Attr(L2TP_ATTR_PEER_SESSION_ID, peer_session_id),
                netlink.U16Attr(L2TP_ATTR_PW_TYPE, L2TP_PWTYPE_ETH),
                # TODO: Cookies.
                netlink.NulStrAttr(L2TP_ATTR_IFNAME, name),
            ])
        msg.send(self.connection)

        try:
            self.connection.recv()
        except OSError, e:
            if e.errno == errno.EEXIST:
                raise L2TPSessionExists(session_id)

            raise NetlinkError
コード例 #2
0
    def tunnel_create(self, tunnel_id, peer_tunnel_id, socket):
        """
        Creates a new L2TP tunnel.

        :param tunnel_id: Local tunnel identifier
        :param peer_tunnel_id: Remote peer tunnel identifier
        :param socket: UDP socket file descriptor
        """

        msg = self._create_message(L2TP_CMD_TUNNEL_CREATE, [
            netlink.U32Attr(L2TP_ATTR_CONN_ID, tunnel_id),
            netlink.U32Attr(L2TP_ATTR_PEER_CONN_ID, peer_tunnel_id),
            netlink.U8Attr(L2TP_ATTR_PROTO_VERSION, 3),
            netlink.U16Attr(L2TP_ATTR_ENCAP_TYPE, L2TP_ENCAPTYPE_UDP),
            netlink.U32Attr(L2TP_ATTR_FD, socket),
        ])
        msg.send(self.connection)

        try:
            self.connection.recv()
        except OSError, e:
            if e.errno == errno.EEXIST:
                # This tunnel identifier is already in use; make sure to remove it from
                # our pool of assignable tunnel identifiers.
                raise L2TPTunnelExists(tunnel_id)

            raise NetlinkError
コード例 #3
0
  def session_modify(self, tunnel_id, session_id, mtu):
    """
    Modifies an existing session.

    :param tunnel_id: Local tunnel identifier
    :param session_id: Local session identifier
    """
    msg = self._create_message(L2TP_CMD_SESSION_MODIFY, [
      netlink.U32Attr(L2TP_ATTR_CONN_ID, tunnel_id),
      netlink.U32Attr(L2TP_ATTR_SESSION_ID, session_id),
      netlink.U16Attr(L2TP_ATTR_MTU, mtu),
    ])
    msg.send(self.connection)

    try:
      reply = self.connection.recv()
    except OSError:
      logger.debug(traceback.format_exc())
      logger.warning("Unable to modify tunnel %d session %d!" % (tunnel_id, session_id))