From b68acb8cf05630715d907136669a90f813486ed5 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 17 Jun 2021 11:52:50 +0200 Subject: [PATCH] opts: Add option to register extra TLV types to accept Incoming HTLCs are rejected by the HTLC logic if the payload contains an even type that `lightningd` doesn't recognize. This is to prevent us from accidentally accepting a payment that has extra semantics attached (for example if we get a keysend payment and don't know what to do with the TLV field containing the message we should reject it, otherwise the overall semantics of the message delivery fail). --- lightningd/lightningd.c | 3 +++ lightningd/lightningd.h | 4 ++++ lightningd/options.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index ca9a1ae97..01fb41ef5 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -233,6 +233,9 @@ static struct lightningd *new_lightningd(const tal_t *ctx) * so set it to NULL explicitly now. */ ld->wallet = NULL; + /*~ Behavioral options */ + ld->accept_extra_tlv_types = tal_arr(ld, u64, 0); + /*~ In the next step we will initialize the plugins. This will * also populate the JSON-RPC with passthrough methods, hence * lightningd needs to have something to put those in. This diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 22dba04f0..9bd8f696a 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -278,6 +278,10 @@ struct lightningd { /* Should we re-exec ourselves instead of just exiting? */ bool try_reexec; + + /* Array of (even) TLV types that we should allow. This is required + * since we otherwise would outright reject them. */ + u64 *accept_extra_tlv_types; }; /* Turning this on allows a tal allocation to return NULL, rather than aborting. diff --git a/lightningd/options.c b/lightningd/options.c index 669355991..99bc32fad 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -131,6 +131,30 @@ static char *opt_set_mode(const char *arg, mode_t *m) return NULL; } +#if EXPERIMENTAL_FEATURES +static char *opt_set_accept_extra_tlv_types(const char *arg, + struct lightningd *ld) +{ + char *endp, **elements = tal_strsplit(NULL, arg, ",", STR_NO_EMPTY);; + unsigned long long l; + u64 u; + for (int i = 0; elements[i] != NULL; i++) { + /* This is how the manpage says to do it. Yech. */ + errno = 0; + l = strtoull(elements[i], &endp, 0); + if (*endp || !arg[0]) + return tal_fmt(NULL, "'%s' is not a number", arg); + u = l; + if (errno || u != l) + return tal_fmt(NULL, "'%s' is out of range", arg); + tal_arr_expand(&ld->accept_extra_tlv_types, u); + } + + tal_free(elements); + return NULL; +} +#endif + static char *opt_add_addr_withtype(const char *arg, struct lightningd *ld, enum addr_listen_announce ala, @@ -957,6 +981,12 @@ static void register_opts(struct lightningd *ld) &ld->tor_service_password, "Set a Tor hidden service password"); +#if EXPERIMENTAL_FEATURES + opt_register_arg("--experimental-accept-extra-tlv-types", + opt_set_accept_extra_tlv_types, NULL, ld, + "Comma separated list of extra TLV types to accept."); +#endif + opt_register_noarg("--disable-dns", opt_set_invbool, &ld->config.use_dns, "Disable DNS lookups of peers"); @@ -1401,6 +1431,10 @@ static void add_config(struct lightningd *ld, || opt->cb_arg == (void *)plugin_opt_flag_set) { /* FIXME: We actually treat it as if they specified * --plugin for each one, so ignore these */ +#if EXPERIMENTAL_FEATURES + } else if (opt->cb_arg == (void *)opt_set_accept_extra_tlv_types) { +#endif + /* TODO Actually print the option */ } else { /* Insert more decodes here! */ abort();