K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
Loading...
Searching...
No Matches
Remote shell execution

Data Structures

struct  kfsw_remexec_entry
 
struct  kfsw_remexec_allowlist
 
struct  kfsw_remexec_reply
 
struct  kfsw_remexec_stats
 

Macros

#define KFSW_REMEXEC_PARAM_TABLE_ID   38U
 
#define KFSW_REMEXEC_PARAM_TABLE_NAME   "remexec"
 
#define KFSW_REMEXEC_COMMAND_MAX   64U
 
#define KFSW_REMEXEC_OUTPUT_MAX   ((size_t)CONFIG_KFSW_REMEXEC_OUTPUT_MAX)
 
#define KFSW_REMEXEC_REFUSAL_MAX   96U
 

Enumerations

enum  kfsw_remexec_status {
  KFSW_REMEXEC_OK = 0 , KFSW_REMEXEC_NOT_OFFERED = 1 , KFSW_REMEXEC_TOO_LONG = 2 , KFSW_REMEXEC_INVALID = 3 ,
  KFSW_REMEXEC_BUSY = 4 , KFSW_REMEXEC_TIMEOUT = 5 , KFSW_REMEXEC_FAILED = 6 , KFSW_REMEXEC_UNAVAILABLE = 7
}
 

Functions

int kfsw_remexec_init (const struct kfsw_remexec_allowlist *allowlist)
 
bool kfsw_remexec_is_initialized (void)
 
void kfsw_remexec_get_stats (struct kfsw_remexec_stats *stats)
 
const char * kfsw_remexec_last_refusal (void)
 
const char * kfsw_remexec_last_command (void)
 
const char * kfsw_remexec_status_name (enum kfsw_remexec_status status)
 
void kfsw_remexec_list_local (const char *prefix, struct kfsw_remexec_reply *reply)
 
void kfsw_remexec_run_local (const char *line, struct kfsw_remexec_reply *reply)
 
int kfsw_remexec_server_start (void)
 
int kfsw_remexec_list_remote (uint16_t node, const char *prefix, struct kfsw_remexec_reply *reply)
 
int kfsw_remexec_run_remote (uint16_t node, const char *line, struct kfsw_remexec_reply *reply)
 

Variables

const struct kfsw_param_definition_set kfsw_remexec_param_definitions
 

Description

Reads which shell commands a node offers for remote execution and runs one of them, returning what it printed to the node that asked.

The allowlist the composition hands to kfsw_remexec_init() is the security boundary. A command is not reachable until it is marked there, the listing reports exactly the marked commands, and anything else is refused with a reason naming the command. There is no wildcard, no debug mode and no PIN: discovery and permission are one list, so they cannot disagree. A node that never calls kfsw_remexec_init(), or marks nothing, answers the listing with an empty reply and refuses every execution.

Output is bounded. A reply carries at most KFSW_REMEXEC_OUTPUT_MAX bytes and says how many it dropped, so a chatty command cannot flood the link and an operator is never left guessing whether the output was complete. Whether the command succeeded is reported separately from whether its output fitted.

Macro Documentation

◆ KFSW_REMEXEC_COMMAND_MAX

#define KFSW_REMEXEC_COMMAND_MAX   64U

#include <remexec.h>

Longest command line accepted, excluding the terminator.

◆ KFSW_REMEXEC_OUTPUT_MAX

#define KFSW_REMEXEC_OUTPUT_MAX   ((size_t)CONFIG_KFSW_REMEXEC_OUTPUT_MAX)

#include <remexec.h>

Largest output one reply carries, excluding the terminator.

◆ KFSW_REMEXEC_PARAM_TABLE_ID

#define KFSW_REMEXEC_PARAM_TABLE_ID   38U

#include <remexec.h>

Table 38: what remote execution accepted, refused and truncated.

◆ KFSW_REMEXEC_PARAM_TABLE_NAME

#define KFSW_REMEXEC_PARAM_TABLE_NAME   "remexec"

#include <remexec.h>

Parameter table name.

◆ KFSW_REMEXEC_REFUSAL_MAX

#define KFSW_REMEXEC_REFUSAL_MAX   96U

#include <remexec.h>

Longest refusal text kept and published, including the terminator.

Enumeration Documentation

◆ kfsw_remexec_status

#include <remexec.h>

Outcome of one request.

Enumerator
KFSW_REMEXEC_OK 

The command ran and reported success.

KFSW_REMEXEC_NOT_OFFERED 

The command is not marked in the serving node's allowlist.

KFSW_REMEXEC_TOO_LONG 

The command line is longer than KFSW_REMEXEC_COMMAND_MAX.

KFSW_REMEXEC_INVALID 

The command line is empty or holds a byte that is not printable.

KFSW_REMEXEC_BUSY 

An execution is already running; requests are refused, never queued.

KFSW_REMEXEC_TIMEOUT 

The command overran the configured budget.

KFSW_REMEXEC_FAILED 

The command ran and reported a failure.

KFSW_REMEXEC_UNAVAILABLE 

The service is not initialised on the serving node.

Function Documentation

◆ kfsw_remexec_get_stats()

void kfsw_remexec_get_stats ( struct kfsw_remexec_stats *  stats)

#include <remexec.h>

Read the lifetime totals.

◆ kfsw_remexec_init()

int kfsw_remexec_init ( const struct kfsw_remexec_allowlist *  allowlist)

#include <remexec.h>

Adopt the allowlist and prepare the capture shell.

Call once, before the server starts. The entries are referenced, not copied, so they must have static lifetime.

Parameters
allowlistCommands this node offers. NULL, or a count of zero, offers nothing and is a valid composition.
Return values
0Adopted.
-E2BIGMore entries than CONFIG_KFSW_REMEXEC_MAX_ENTRIES.
-EINVALAn entry has no command or no help text, or a command is empty, holds a byte that is not printable, or repeats another.
-ENAMETOOLONGA command is longer than KFSW_REMEXEC_COMMAND_MAX.
-EALREADYAlready initialised.
-EAGAINThe capture shell did not become ready, so a command's output could not be read back. Nothing is offered.

◆ kfsw_remexec_is_initialized()

bool kfsw_remexec_is_initialized ( void  )

#include <remexec.h>

Whether an allowlist was adopted.

◆ kfsw_remexec_last_command()

const char * kfsw_remexec_last_command ( void  )

#include <remexec.h>

The last command line that was run, with its arguments.

Empty before the first one. It is what the node was asked to run, not what the command printed.

◆ kfsw_remexec_last_refusal()

const char * kfsw_remexec_last_refusal ( void  )

#include <remexec.h>

The most recent refusal, as the operator was told it.

Empty before any.

◆ kfsw_remexec_list_local()

void kfsw_remexec_list_local ( const char *  prefix,
struct kfsw_remexec_reply *  reply 
)

#include <remexec.h>

Fill reply with the commands this node offers.

With an empty or NULL prefix the listing is one command name a line. With a prefix it is the matching command and its subcommands, each as name<TAB>help. A listing longer than the output cap is truncated and reports the bytes it dropped.

◆ kfsw_remexec_list_remote()

int kfsw_remexec_list_remote ( uint16_t  node,
const char *  prefix,
struct kfsw_remexec_reply *  reply 
)

#include <remexec.h>

Ask node which commands it offers.

Return values
0The node answered; the outcome is in reply.
-EINVALNode 0, the broadcast address or above, or the local node.
-EACCESCSP is not running.
-ETIMEDOUTNo reply inside CONFIG_KFSW_REMEXEC_TIMEOUT_MS.
-EBADMSGThe reply did not match the request.

◆ kfsw_remexec_run_local()

void kfsw_remexec_run_local ( const char *  line,
struct kfsw_remexec_reply *  reply 
)

#include <remexec.h>

Run line on this node if the allowlist offers it.

Refuses rather than queues when an execution is already running. Must not be called from a shell command handler: the capture shell cannot execute from within an execution.

◆ kfsw_remexec_run_remote()

int kfsw_remexec_run_remote ( uint16_t  node,
const char *  line,
struct kfsw_remexec_reply *  reply 
)

#include <remexec.h>

Ask node to run line and return what it printed.

Errors are those of kfsw_remexec_list_remote(). A timeout leaves the outcome unknown: the serving node runs the command to completion whether or not the requester is still there, and discards a reply it cannot deliver.

◆ kfsw_remexec_server_start()

int kfsw_remexec_server_start ( void  )

#include <remexec.h>

Bind the remote execution port and start serving requests.

◆ kfsw_remexec_status_name()

const char * kfsw_remexec_status_name ( enum kfsw_remexec_status  status)

#include <remexec.h>

Human-readable name for a status, for shell output and logs.

Variable Documentation

◆ kfsw_remexec_param_definitions

const struct kfsw_param_definition_set kfsw_remexec_param_definitions
extern

#include <remexec.h>

Parameter table 38.