Skip to content

eBPF-based security platform

util: drop the dead code and the needless exports

Daniel Borkmannef5b42c9298c
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index 764818bd..515164b7 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -1051,7 +1051,7 @@ static void build_usage(void)
"is available only in shirudo-operator and requires signing keys.\n");
}
-int shirudo_build_bpm_build(int argc, char **argv)
+static int shirudo_build_bpm_build(int argc, char **argv)
{
const char *context = ".", *file_arg = NULL, *version = NULL, *keys_arg = NULL;
char build_file[PATH_MAX], resolved_file[PATH_MAX], keys_dir[PATH_MAX];
diff --git a/tools/shirudo-build/bpm.h b/tools/shirudo-build/bpm.h
index 969c49a6..8e961ef0 100644
--- a/tools/shirudo-build/bpm.h
+++ b/tools/shirudo-build/bpm.h
@@ -70,7 +70,6 @@ int bpm_build_parse_beefile(const unsigned char *body, size_t len,
void bpm_build_spec_free(struct bpm_build_spec *spec);
int shirudo_build_bpm(int argc, char **argv);
-int shirudo_build_bpm_build(int argc, char **argv);
int shirudo_build_bpm_push(int argc, char **argv);
int shirudo_build_bpm_tree(int argc, char **argv);
bool shirudo_build_is_help(const char *arg);
diff --git a/util/bpm_oci.c b/util/bpm_oci.c
index e1ff63b2..32afb8b6 100644
--- a/util/bpm_oci.c
+++ b/util/bpm_oci.c
@@ -666,9 +666,10 @@ int bpm_oci_get_file(struct bpm_oci_client *c, const char *url,
* preserves the response headers (notably Location) and supports a request
* body while still retrying once after a registry authentication challenge.
*/
-int bpm_oci_request(struct bpm_oci_client *c, const char *method,
- const char *url, const char *accept, const char *content_type,
- const void *body, size_t body_len, struct bpm_http_response *r)
+static int bpm_oci_request(struct bpm_oci_client *c, const char *method,
+ const char *url, const char *accept,
+ const char *content_type, const void *body,
+ size_t body_len, struct bpm_http_response *r)
{
char auth[8192] = {};
int rc;
diff --git a/util/bpm_oci.h b/util/bpm_oci.h
index 13435ee0..eb56d5f6 100644
--- a/util/bpm_oci.h
+++ b/util/bpm_oci.h
@@ -24,7 +24,6 @@ struct shirudo_json_emit;
#define BPM_MAX_DIGEST 128
#define BPM_MAX_MEDIA 192
#define BPM_MAX_ENTRIES 512
-#define BPM_MAX_SOURCES 64
#define BPM_MAX_STATE 256
#define BPM_MAX_HTTP_BODY (256u * 1024u * 1024u)
#define BPM_INDEX_REPOSITORY "shirudo/bpm-index"
@@ -100,10 +99,6 @@ int bpm_oci_parse_push_repo(const char *raw, struct bpm_oci_client *c,
char *repository, size_t repository_sz);
int bpm_oci_url(const struct bpm_oci_client *c, const char *repo,
const char *kind, const char *ref, char *out, size_t sz);
-int bpm_oci_request(struct bpm_oci_client *c, const char *method,
- const char *url, const char *accept,
- const char *content_type, const void *body,
- size_t body_len, struct bpm_http_response *r);
/* 2xx fills out; 404 is -ENOENT, other failures -EACCES. */
int bpm_oci_get_memory(struct bpm_oci_client *c, const char *url,
const char *accept, struct bpm_buffer *out);
diff --git a/util/crypto.h b/util/crypto.h
index bef5866c..54d11fb6 100644
--- a/util/crypto.h
+++ b/util/crypto.h
@@ -67,9 +67,6 @@ struct shirudo_tls_ca {
void shirudo_tls_ca_cleanup(struct shirudo_tls_ca *ca);
-/* CURLOPT_SSL_CTX_FUNCTION callback. userptr points to shirudo_tls_ca. */
-CURLcode shirudo_sslctx_callback(CURL *curl, void *sslctx, void *userptr);
-
/*
* shirudo's TLS policy for every libcurl handle it opens: TLS 1.3 only
* and hybrid ML-KEM key exchange only (X25519MLKEM768, with the P-256
diff --git a/util/harden.c b/util/harden.c
index f61c76d9..192879d8 100644
--- a/util/harden.c
+++ b/util/harden.c
@@ -6,11 +6,8 @@
* sensitive buffers.
*/
-#include <sys/mman.h>
#include <sys/prctl.h>
#include <sys/resource.h>
-#include <string.h>
-#include <errno.h>
#include "harden.h"
@@ -23,16 +20,3 @@ void shirudo_harden_self(void)
prctl(PR_SET_PTRACER, 0, 0, 0, 0);
setrlimit(RLIMIT_CORE, &no_core);
}
-
-int shirudo_mlock_buffer(void *buf, size_t len)
-{
- if (mlock(buf, len) != 0)
- return -errno;
- madvise(buf, len, MADV_DONTDUMP);
- return 0;
-}
-
-void shirudo_zero_buffer(void *buf, size_t len)
-{
- explicit_bzero(buf, len);
-}
diff --git a/util/harden.h b/util/harden.h
index 59bd8c68..354967e2 100644
--- a/util/harden.h
+++ b/util/harden.h
@@ -12,7 +12,4 @@
void shirudo_harden_self(void);
-int shirudo_mlock_buffer(void *buf, size_t len);
-void shirudo_zero_buffer(void *buf, size_t len);
-
#endif /* SHIRUDO_HARDEN_H */
diff --git a/util/help.c b/util/help.c
index 26bc2fa8..508a7f89 100644
--- a/util/help.c
+++ b/util/help.c
@@ -118,9 +118,10 @@ void shirudo_print_help(const struct shirudo_help *h)
fprintf(stderr, "\n%s\n", h->footer);
}
-void shirudo_help_unknown_subcommand(const char *cmd_label, const char *bad,
- const struct shirudo_help_item *subcmds,
- size_t n_subcmds)
+static void
+shirudo_help_unknown_subcommand(const char *cmd_label, const char *bad,
+ const struct shirudo_help_item *subcmds,
+ size_t n_subcmds)
{
struct shirudo_suggestion sugg[4];
const char *names[SHIRUDO_SUBCMD_MAX];
diff --git a/util/help.h b/util/help.h
index 801da762..e6c9c796 100644
--- a/util/help.h
+++ b/util/help.h
@@ -39,11 +39,6 @@ void shirudo_print_help(const struct shirudo_help *h);
void shirudo_print_subcmd_list(const struct shirudo_help_item *items,
size_t n_items);
-void shirudo_help_unknown_subcommand(const char *cmd_label,
- const char *bad,
- const struct shirudo_help_item *subcmds,
- size_t n_subcmds);
-
/*
* NULL on failure with stderr already written: a did-you-mean block,
* or the ambiguous matches.
diff --git a/util/json.c b/util/json.c
index e8e480e7..1126d4a1 100644
--- a/util/json.c
+++ b/util/json.c
@@ -14,39 +14,13 @@
#include "json.h"
-static int flush_sink(struct shirudo_json_emit *e)
-{
- int rc;
-
- if (e->err)
- return e->err;
- if (!e->sink || e->len == 0)
- return 0;
- rc = e->sink(e->sink_ctx, e->buf, e->len);
- if (rc) {
- e->err = rc < 0 ? rc : -EIO;
- return e->err;
- }
- e->len = 0;
- if (e->cap)
- e->buf[0] = '\0';
- return 0;
-}
-
static void put(struct shirudo_json_emit *e, char c)
{
if (e->err)
return;
if (e->len + 1 >= e->cap) {
- if (!e->sink || flush_sink(e)) {
- if (!e->err)
- e->err = -ENOSPC;
- return;
- }
- if (e->len + 1 >= e->cap) {
- e->err = -ENOSPC;
- return;
- }
+ e->err = -ENOSPC;
+ return;
}
e->buf[e->len++] = c;
e->buf[e->len] = '\0';
@@ -249,13 +223,6 @@ void shirudo_json_raw(struct shirudo_json_emit *e, const char *value,
put(e, value[i]);
}
-int shirudo_json_emit_flush(struct shirudo_json_emit *e)
-{
- if (!e)
- return -EINVAL;
- return flush_sink(e);
-}
-
struct pctx {
const char *p;
const char *end;
diff --git a/util/json.h b/util/json.h
index 623a794b..7e9b9578 100644
--- a/util/json.h
+++ b/util/json.h
@@ -28,12 +28,6 @@ struct shirudo_json_emit {
int err; /* sticky; -ENOSPC, -EILSEQ, -E2BIG */
unsigned depth; /* open-container nesting */
uint32_t nonempty; /* bit d set: container at depth d has a member */
- /*
- * Buffer-only callers leave the sink NULL; a sink is flushed when the
- * buffer fills and by shirudo_json_emit_flush().
- */
- int (*sink)(void *ctx, const char *data, size_t len);
- void *sink_ctx;
};
/*
@@ -60,8 +54,6 @@ void shirudo_json_str(struct shirudo_json_emit *e, const char *val);
void shirudo_json_raw(struct shirudo_json_emit *e, const char *value,
size_t value_len);
-int shirudo_json_emit_flush(struct shirudo_json_emit *e);
-
/*
* Not a generic deserialiser: declared keys are dispatched, everything
* else is parsed and discarded, within bounds so hostile input cannot
diff --git a/util/keys.c b/util/keys.c
index f84ae716..74d853de 100644
--- a/util/keys.c
+++ b/util/keys.c
@@ -89,8 +89,8 @@ int shirudo_keys_digest_der(const unsigned char *der, size_t der_sz,
return rc;
}
-int shirudo_keys_digest_file(const char *path, uint8_t sha256[32],
- uint8_t fingerprint[32])
+static int shirudo_keys_digest_file(const char *path, uint8_t sha256[32],
+ uint8_t fingerprint[32])
{
unsigned char *der = NULL;
size_t der_sz = 0;
diff --git a/util/keys.h b/util/keys.h
index 69e87d1e..26eaa934 100644
--- a/util/keys.h
+++ b/util/keys.h
@@ -60,8 +60,6 @@ int shirudo_keys_read_der(const char *path, unsigned char **out,
int shirudo_keys_digest_der(const unsigned char *der, size_t der_sz,
uint8_t sha256[32], uint8_t fingerprint[32]);
-int shirudo_keys_digest_file(const char *path, uint8_t sha256[32],
- uint8_t fingerprint[32]);
/*
* The digest the init event covers: the one certificate's digest, or
diff --git a/util/paths.h b/util/paths.h
index d9fd68c8..8f479317 100644
--- a/util/paths.h
+++ b/util/paths.h
@@ -19,7 +19,6 @@
#define SHIRUDO_CERT_FILE "cert.der"
#define SHIRUDO_CERT_PATH SHIRUDO_KEYS_DIR "/" SHIRUDO_CERT_FILE
/* Further certificates enrolled beside cert.der, and the revoked ones. */
-#define SHIRUDO_KEYS_TRUSTED_DIR SHIRUDO_KEYS_DIR "/trusted"
#define SHIRUDO_KEYS_REVOKED_DIR SHIRUDO_KEYS_DIR "/revoked"
/* The initrd's own copy of the keys, measured with the initrd. */
#define SHIRUDO_INITRD_KEYS_DIR "/etc/shirudo/keys"
diff --git a/util/similar.c b/util/similar.c
index 0275549c..e6fae60c 100644
--- a/util/similar.c
+++ b/util/similar.c
@@ -9,7 +9,7 @@
#include "similar.h"
-int shirudo_edit_distance(const char *s, const char *t, int max)
+static int shirudo_edit_distance(const char *s, const char *t, int max)
{
int prev[SHIRUDO_SIMILAR_MAX_LEN + 1];
int curr[SHIRUDO_SIMILAR_MAX_LEN + 1];
diff --git a/util/similar.h b/util/similar.h
index 47358c9d..6a3e664f 100644
--- a/util/similar.h
+++ b/util/similar.h
@@ -22,9 +22,6 @@ struct shirudo_suggestion {
int dist;
};
-/* Any value above max once the cap is exceeded, with an early exit. */
-int shirudo_edit_distance(const char *s, const char *t, int max);
-
size_t shirudo_suggest(const char *name,
const char *const *commands, size_t n_commands,
int max_dist,
diff --git a/util/tls_openssl.c b/util/tls_openssl.c
index fb99927f..bd050494 100644
--- a/util/tls_openssl.c
+++ b/util/tls_openssl.c
@@ -29,7 +29,7 @@ void shirudo_tls_ca_cleanup(struct shirudo_tls_ca *ca)
ca->impl = NULL;
}
-CURLcode shirudo_sslctx_callback(CURL *curl, void *sslctx, void *userptr)
+static CURLcode shirudo_sslctx_callback(CURL *curl, void *sslctx, void *userptr)
{
const struct shirudo_tls_ca *ca = userptr;
const char *path = ca ? ca->path : NULL;
diff --git a/util/tpm.h b/util/tpm.h
index c6997fb1..75d9659f 100644
--- a/util/tpm.h
+++ b/util/tpm.h
@@ -18,7 +18,6 @@
#define SHIRUDO_TPM_PUBLIC_MAX 512
#define SHIRUDO_TPM_ATTEST_MAX 1024
#define SHIRUDO_TPM_SIGNATURE_MAX 160
-#define SHIRUDO_TPM_NONCE_MAX 64
struct shirudo_tpm;
diff --git a/util/tpm_wire.c b/util/tpm_wire.c
index f1ad1ec9..179225a3 100644
--- a/util/tpm_wire.c
+++ b/util/tpm_wire.c
@@ -130,8 +130,9 @@ void shirudo_tpm_policy_nv_written(const uint8_t prev[32], bool written,
policy_hash(prev, TPM_CC_POLICY_NV_WRITTEN, &set, 1, NULL, 0, out);
}
-void shirudo_tpm_pcr_selection(uint32_t pcr_mask,
- uint8_t out[SHIRUDO_TPM_PCR_SELECTION_LEN])
+static void
+shirudo_tpm_pcr_selection(uint32_t pcr_mask,
+ uint8_t out[SHIRUDO_TPM_PCR_SELECTION_LEN])
{
put32(out, 1);
put16(out + 4, SHIRUDO_TPM_ALG_SHA256);
diff --git a/util/tpm_wire.h b/util/tpm_wire.h
index 442fafea..e699f6b7 100644
--- a/util/tpm_wire.h
+++ b/util/tpm_wire.h
@@ -62,9 +62,6 @@ void shirudo_tpm_register_policy(uint32_t pcr_mask,
uint8_t branch_init[32],
uint8_t policy[32]);
-void shirudo_tpm_pcr_selection(uint32_t pcr_mask,
- uint8_t out[SHIRUDO_TPM_PCR_SELECTION_LEN]);
-
/* Name of an NV index: nameAlg || SHA-256(TPMS_NV_PUBLIC). */
void shirudo_tpm_nv_name(uint32_t index, uint32_t attrs,
const uint8_t policy[SHIRUDO_TPM_DIGEST_LEN],
diff --git a/util/upatch_maps.c b/util/upatch_maps.c
index db29ba57..ec2424cd 100644
--- a/util/upatch_maps.c
+++ b/util/upatch_maps.c
@@ -1371,13 +1371,6 @@ void shirudo_upatch_maps_print_summary(const struct shirudo_map_summary *list,
}
}
-void shirudo_upatch_map_print_inline(const struct shirudo_map_summary *m)
-{
- printf(" %-22s %-16s max=%u%s\n",
- m->name, m->type_name, m->max_entries,
- m->n_cpus > 1 ? " (per-cpu)" : "");
-}
-
char *shirudo_upatch_map_format_cell(const struct shirudo_map_view *v,
uint32_t type_id, const void *bytes,
uint32_t bytes_size,
diff --git a/util/upatch_maps.h b/util/upatch_maps.h
index 5904749a..9b5eb024 100644
--- a/util/upatch_maps.h
+++ b/util/upatch_maps.h
@@ -123,8 +123,6 @@ void shirudo_upatch_maps_print_summary(const struct shirudo_map_summary *list,
size_t n);
void shirudo_upatch_maps_print_detail(const struct shirudo_map_view *v);
-void shirudo_upatch_map_print_inline(const struct shirudo_map_summary *m);
-
/* NULL v emits nothing. The shape is part of the status report. */
void shirudo_upatch_maps_emit_json_fields(struct shirudo_json_emit *e,
const struct shirudo_map_view *v);
diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.c
index 067fe796..8cf5eaf6 100644
--- a/util/upatch_maps_otel.c
+++ b/util/upatch_maps_otel.c
@@ -787,8 +787,8 @@ static int build_log_payload(const char *path,
return 0;
}
-int shirudo_upatch_maps_otel_build_log(const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+static int shirudo_upatch_maps_otel_build_log(const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
return build_log_payload(NULL, v, out, out_len);
}
@@ -1263,10 +1263,10 @@ out:
return rc;
}
-int shirudo_upatch_maps_otel_build_metric(
- const struct shirudo_map_view *v,
- const struct shirudo_otel_opts *opts,
- char **out, size_t *out_len)
+static int
+shirudo_upatch_maps_otel_build_metric(const struct shirudo_map_view *v,
+ const struct shirudo_otel_opts *opts,
+ char **out, size_t *out_len)
{
return build_metric_decoded_payload(NULL, v, opts, out, out_len);
}
diff --git a/util/upatch_maps_otel.h b/util/upatch_maps_otel.h
index e31e896d..0fe7055a 100644
--- a/util/upatch_maps_otel.h
+++ b/util/upatch_maps_otel.h
@@ -45,14 +45,9 @@ struct shirudo_otel_opts {
int shirudo_upatch_maps_otel_classify(const struct shirudo_map_view *v,
enum shirudo_otel_signal *signal,
char *reason, size_t reason_sz);
-int shirudo_upatch_maps_otel_build_log(const struct shirudo_map_view *v,
- char **out, size_t *out_len);
int shirudo_upatch_maps_otel_build_log_file(
const char *path, const struct shirudo_map_view *v,
char **out, size_t *out_len);
-int shirudo_upatch_maps_otel_build_metric(
- const struct shirudo_map_view *v, const struct shirudo_otel_opts *opts,
- char **out, size_t *out_len);
int shirudo_upatch_maps_otel_build_metric_file(
const char *path, const struct shirudo_map_view *v,
const struct shirudo_otel_opts *opts, char **out, size_t *out_len);