Tor 0.4.9.0-alpha-dev
Data Structures | Macros | Typedefs | Functions | Variables
control_getinfo.c File Reference

Implementation for miscellaneous controller getinfo commands. More...

#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/getinfo_geoip.h"
#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/dircommon/directory.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/relay_find_addr.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/stats/geoip_stats.h"
#include "feature/stats/predict_ports.h"
#include "feature/stats/rephist.h"
#include "lib/version/torversion.h"
#include "lib/encoding/kvline.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)
 

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_current_consensus (consensus_flavor_t flavor, char **answer, const char **errmsg)
 
static int controller_get_routerdescs (smartlist_t *descs_out, const char *key, const char **msg)
 
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_rephist (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.

Macro Definition Documentation

◆ CONTROL_EVENTS_PRIVATE

#define CONTROL_EVENTS_PRIVATE

Definition at line 10 of file control_getinfo.c.

◆ CONTROL_GETINFO_PRIVATE

#define CONTROL_GETINFO_PRIVATE

Definition at line 12 of file control_getinfo.c.

◆ CONTROL_MODULE_PRIVATE

#define CONTROL_MODULE_PRIVATE

Definition at line 11 of file control_getinfo.c.

◆ DOC

#define DOC (   name,
  desc 
)    { name, NULL, desc, 0 }

Definition at line 1494 of file control_getinfo.c.

◆ ITEM

#define ITEM (   name,
  fn,
  desc 
)    { name, getinfo_helper_##fn, desc, 0 }

Definition at line 1492 of file control_getinfo.c.

◆ PREFIX

#define PREFIX (   name,
  fn,
  desc 
)    { name, getinfo_helper_##fn, desc, 1 }

Definition at line 1493 of 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 1479 of file control_getinfo.c.

Function Documentation

◆ controller_get_routerdescs()

static int controller_get_routerdescs ( smartlist_t descs_out,
const char *  key,
const char **  msg 
)
static

Helper for getinfo_helper_dir.

Add a signed_descriptor_t to descs_out for each router matching key. The key should be either

  • "/tor/server/authority" for our own routerinfo;
  • "/tor/server/all" for all the routerinfos we have, concatenated;
  • "/tor/server/fp/FP" where FP is a plus-separated sequence of hex identity digests; or
  • "/tor/server/d/D" where D is a plus-separated sequence of server descriptor digests, in hex.

Return 0 if we found some matching descriptors, or -1 if we do not have any descriptors, no matching descriptors, or if we did not recognize the key (URL). If -1 is returned *msg will be set to an appropriate error message.

Definition at line 394 of file control_getinfo.c.

◆ 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 730 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 754 of file control_getinfo.c.

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_current_consensus()

STATIC int getinfo_helper_current_consensus ( consensus_flavor_t  flavor,
char **  answer,
const char **  errmsg 
)

GETINFO helper for dumping different consensus flavors returns: 0 on success -1 on error.

Definition at line 346 of file control_getinfo.c.

◆ 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 321 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 459 of file control_getinfo.c.

◆ getinfo_helper_downloads()

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

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

Definition at line 1051 of file control_getinfo.c.

◆ 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 1008 of file control_getinfo.c.

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 862 of file control_getinfo.c.

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 962 of file control_getinfo.c.

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 833 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 1113 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 260 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 1401 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 84 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 1371 of file control_getinfo.c.

◆ getinfo_helper_rephist()

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

Implementation helper for GETINFO: answers queries about circuit onion handshake rephist values

Definition at line 1421 of file control_getinfo.c.

◆ 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 1454 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 1751 of file control_getinfo.c.

◆ 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 1722 of file control_getinfo.c.

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 1694 of file control_getinfo.c.

◆ 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 216 of file control_getinfo.c.

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 1498 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 1744 of file control_getinfo.c.