tor  0.4.2.0-alpha-dev
Data Structures | Macros | Typedefs | Functions | Variables
control_getinfo.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/or/circuitlist.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
#include "core/or/policies.h"
#include "core/or/versions.h"
#include "feature/client/addressmap.h"
#include "feature/client/bridges.h"
#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
#include "feature/control/control_cmd.h"
#include "feature/control/control_events.h"
#include "feature/control/control_fmt.h"
#include "feature/control/control_getinfo.h"
#include "feature/control/control_proto.h"
#include "feature/control/fmt_serverstatus.h"
#include "feature/control/getinfo_geoip.h"
#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_cache.h"
#include "feature/hs_common/shared_random_client.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/rend/rendcache.h"
#include "feature/stats/geoip_stats.h"
#include "feature/stats/predict_ports.h"
#include "lib/version/torversion.h"
#include "core/or/entry_connection_st.h"
#include "core/or/or_connection_st.h"
#include "core/or/origin_circuit_st.h"
#include "core/or/socks_request_st.h"
#include "feature/control/control_connection_st.h"
#include "feature/control/control_cmd_args_st.h"
#include "feature/dircache/cached_dir_st.h"
#include "feature/nodelist/extrainfo_st.h"
#include "feature/nodelist/microdesc_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist_st.h"
#include <pwd.h>

Go to the source code of this file.

Data Structures

struct  getinfo_item_t
 

Macros

#define CONTROL_EVENTS_PRIVATE
 
#define CONTROL_MODULE_PRIVATE
 
#define CONTROL_GETINFO_PRIVATE
 
#define ITEM(name, fn, desc)   { name, getinfo_helper_##fn, desc, 0 }
 
#define PREFIX(name, fn, desc)   { name, getinfo_helper_##fn, desc, 1 }
 
#define DOC(name, desc)   { name, NULL, desc, 0 }
 

Typedefs

typedef int(* getinfo_helper_t) (control_connection_t *, const char *q, char **a, const char **error_out)
 
typedef struct getinfo_item_t getinfo_item_t
 

Functions

static char * list_getinfo_options (void)
 
static char * download_status_to_string (const download_status_t *dl)
 
static int getinfo_helper_misc (control_connection_t *conn, const char *question, char **answer, const char **errmsg)
 
static char * munge_extrainfo_into_routerinfo (const char *ri_body, const signed_descriptor_t *ri, const signed_descriptor_t *ei)
 
static int getinfo_helper_listeners (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int getinfo_helper_current_time (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int getinfo_helper_dir (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static char * digest_list_to_string (const smartlist_t *sl)
 
STATIC void getinfo_helper_downloads_networkstatus (const char *flavor, download_status_t **dl_to_emit, const char **errmsg)
 
STATIC void getinfo_helper_downloads_cert (const char *fp_sk_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC void getinfo_helper_downloads_desc (const char *desc_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC void getinfo_helper_downloads_bridge (const char *bridge_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC int getinfo_helper_downloads (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static int getinfo_helper_events (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int getinfo_helper_onions (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static int getinfo_helper_liveness (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static int getinfo_helper_sr (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static int handle_getinfo_helper (control_connection_t *control_conn, const char *question, char **answer, const char **err_out)
 
int handle_control_getinfo (control_connection_t *conn, const control_cmd_args_t *args)
 

Variables

static const getinfo_item_t getinfo_items []
 
const control_cmd_syntax_t getinfo_syntax
 

Detailed Description

Implementation for miscellaneous controller getinfo commands.

Definition in file control_getinfo.c.

Typedef Documentation

◆ getinfo_helper_t

typedef int(* getinfo_helper_t) (control_connection_t *, const char *q, char **a, const char **error_out)

Callback function for GETINFO: on a given control connection, try to answer the question q and store the newly-allocated answer in *a. If an internal error occurs, return -1 and optionally set *error_out to point to an error message to be delivered to the controller. On success, or if the key is not recognized, return 0. Do not set a if the key is not recognized but you may set error_out to improve the error message.

Definition at line 1340 of file control_getinfo.c.

◆ getinfo_item_t

A single item for the GETINFO question-to-answer-function table.

Function Documentation

◆ digest_list_to_string()

static char* digest_list_to_string ( const smartlist_t sl)
static

Given a smartlist of 20-byte digests, return a newly allocated string containing each of those digests in order, formatted in HEX, and terminated with a newline.

Definition at line 641 of file control_getinfo.c.

Referenced by getinfo_helper_downloads().

◆ download_status_to_string()

static char * download_status_to_string ( const download_status_t dl)
static

Turn a download_status_t into a human-readable description in a newly allocated string. The format is specified in control-spec.txt, under the documentation for "GETINFO download/..." .

Definition at line 665 of file control_getinfo.c.

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_current_time()

STATIC int getinfo_helper_current_time ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: answers requests for information about the current time in both local and UTC forms.

Definition at line 306 of file control_getinfo.c.

◆ getinfo_helper_dir()

STATIC int getinfo_helper_dir ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: knows the answers for questions about directory information.

Definition at line 331 of file control_getinfo.c.

References node_get_by_hex_id(), signed_descriptor_get_body(), and strcmpstart().

◆ getinfo_helper_downloads()

STATIC int getinfo_helper_downloads ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

◆ getinfo_helper_downloads_bridge()

STATIC void getinfo_helper_downloads_bridge ( const char *  bridge_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the bridge download cases for getinfo_helper_downloads()

Definition at line 919 of file control_getinfo.c.

References base16_decode(), DIGEST_LEN, and HEX_DIGEST_LEN.

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_downloads_cert()

STATIC void getinfo_helper_downloads_cert ( const char *  fp_sk_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the cert download cases for getinfo_helper_downloads()

Definition at line 773 of file control_getinfo.c.

References base16_decode(), DIGEST_LEN, HEX_DIGEST_LEN, and strcmpstart().

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_downloads_desc()

STATIC void getinfo_helper_downloads_desc ( const char *  desc_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the routerdesc download cases for getinfo_helper_downloads()

Definition at line 873 of file control_getinfo.c.

References base16_decode(), DIGEST_LEN, and HEX_DIGEST_LEN.

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_downloads_networkstatus()

STATIC void getinfo_helper_downloads_networkstatus ( const char *  flavor,
download_status_t **  dl_to_emit,
const char **  errmsg 
)

Handle the consensus download cases for getinfo_helper_downloads()

Definition at line 744 of file control_getinfo.c.

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_events()

static int getinfo_helper_events ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)
static

Implementation helper for GETINFO: knows how to generate summaries of the current states of things we send events about.

Definition at line 1024 of file control_getinfo.c.

◆ getinfo_helper_listeners()

static int getinfo_helper_listeners ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)
static

Implementation helper for GETINFO: answers requests for information about which ports are bound.

Definition at line 247 of file control_getinfo.c.

◆ getinfo_helper_liveness()

static int getinfo_helper_liveness ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)
static

Implementation helper for GETINFO: answers queries about network liveness.

Definition at line 1295 of file control_getinfo.c.

◆ getinfo_helper_misc()

static int getinfo_helper_misc ( control_connection_t conn,
const char *  question,
char **  answer,
const char **  errmsg 
)
static

Implementation helper for GETINFO: knows the answers for various trivial-to-implement questions.

Definition at line 82 of file control_getinfo.c.

◆ getinfo_helper_onions()

STATIC int getinfo_helper_onions ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: knows how to enumerate hidden services created via the control port.

Definition at line 1265 of file control_getinfo.c.

References control_connection_t::ephemeral_onion_services, and get_detached_onion_services().

◆ getinfo_helper_sr()

static int getinfo_helper_sr ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)
static

Implementation helper for GETINFO: answers queries about shared random value.

Definition at line 1315 of file control_getinfo.c.

◆ handle_control_getinfo()

int handle_control_getinfo ( control_connection_t conn,
const control_cmd_args_t args 
)

Called when we receive a GETINFO command. Try to fetch all requested information, and reply with information or error message.

Definition at line 1596 of file control_getinfo.c.

References control_cmd_args_t::args, control_write_endreply(), handle_getinfo_helper(), smartlist_add(), smartlist_add_asprintf(), smartlist_add_strdup(), and SMARTLIST_FOREACH_BEGIN.

◆ handle_getinfo_helper()

static int handle_getinfo_helper ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  err_out 
)
static

Lookup the 'getinfo' entry question, and return the answer in *answer (or NULL if key not recognized). Return 0 if success or unrecognized, or -1 if recognized but internal error.

Definition at line 1567 of file control_getinfo.c.

References getinfo_item_t::fn, getinfo_items, strcmpstart(), tor_assert(), and getinfo_item_t::varname.

Referenced by handle_control_getinfo().

◆ list_getinfo_options()

static char * list_getinfo_options ( void  )
static

Allocate and return a list of recognized GETINFO options.

Definition at line 1539 of file control_getinfo.c.

References getinfo_items, smartlist_add_asprintf(), SMARTLIST_FOREACH, smartlist_join_strings(), smartlist_sort_strings(), tor_free, and getinfo_item_t::varname.

◆ munge_extrainfo_into_routerinfo()

static char* munge_extrainfo_into_routerinfo ( const char *  ri_body,
const signed_descriptor_t ri,
const signed_descriptor_t ei 
)
static

Awful hack: return a newly allocated string based on a routerinfo and (possibly) an extrainfo, sticking the read-history and write-history from ei into the resulting string. The thing you get back won't necessarily have a valid signature.

New code should never use this; it's for backward compatibility.

NOTE: ri_body is as returned by signed_descriptor_get_body: it might not be NUL-terminated.

Definition at line 203 of file control_getinfo.c.

References signed_descriptor_get_body(), and signed_descriptor_t::signed_descriptor_len.

Variable Documentation

◆ getinfo_items

const getinfo_item_t getinfo_items[]
static

Table mapping questions accepted by GETINFO to the functions that know how to answer them.

Definition at line 1359 of file control_getinfo.c.

Referenced by handle_getinfo_helper(), and list_getinfo_options().

◆ getinfo_syntax

const control_cmd_syntax_t getinfo_syntax
Initial value:
= {
.max_args = UINT_MAX,
}

Definition at line 1589 of file control_getinfo.c.