diff --git a/common/onion.c b/common/onion.c index b9e8aa0a1..4b0f57cc7 100644 --- a/common/onion.c +++ b/common/onion.c @@ -205,7 +205,9 @@ size_t onion_payload_length(const u8 *raw_payload, size_t len, } struct onion_payload *onion_decode(const tal_t *ctx, - const struct route_step *rs) + const struct route_step *rs, + u64 *failtlvtype, + size_t *failtlvpos) { struct onion_payload *p = tal(ctx, struct onion_payload); const u8 *cursor = rs->raw_payload; @@ -245,9 +247,10 @@ struct onion_payload *onion_decode(const tal_t *ctx, if (!fromwire_tlv_payload(&cursor, &max, tlv)) goto fail; - if (!tlv_payload_is_valid(tlv, failtlvpos)) + if (!tlv_payload_is_valid(tlv, failtlvpos)) { + *failtlvtype = tlv->fields[*failtlvpos].numtype; goto fail; - + } /* BOLT #4: * diff --git a/common/onion.h b/common/onion.h index 558106330..1ec8d4eec 100644 --- a/common/onion.h +++ b/common/onion.h @@ -59,6 +59,8 @@ size_t onion_payload_length(const u8 *raw_payload, size_t len, * If the payload is not valid, returns NULL. */ struct onion_payload *onion_decode(const tal_t *ctx, - const struct route_step *rs); + const struct route_step *rs, + u64 *failtlvtype, + size_t *failtlvpos); #endif /* LIGHTNING_COMMON_ONION_H */ diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index fbf9da3e4..804c50389 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -780,6 +780,8 @@ struct htlc_accepted_hook_payload { struct channel *channel; struct lightningd *ld; u8 *next_onion; + u64 failtlvtype; + size_t failtlvpos; }; /* The possible return value types that a plugin may return for the @@ -1116,7 +1118,9 @@ static bool peer_accepted_htlc(const tal_t *ctx, hook_payload = tal(hin, struct htlc_accepted_hook_payload); hook_payload->route_step = tal_steal(hook_payload, rs); - hook_payload->payload = onion_decode(hook_payload, rs); + hook_payload->payload = onion_decode(hook_payload, rs, + &hook_payload->failtlvtype, + &hook_payload->failtlvpos); hook_payload->ld = ld; hook_payload->hin = hin; hook_payload->channel = channel; diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index a73586ff4..b555bc7e1 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -411,7 +411,9 @@ enum watch_result onchaind_funding_spent(struct channel *channel UNNEEDED, { fprintf(stderr, "onchaind_funding_spent called!\n"); abort(); } /* Generated stub for onion_decode */ struct onion_payload *onion_decode(const tal_t *ctx UNNEEDED, - const struct route_step *rs UNNEEDED) + const struct route_step *rs UNNEEDED, + u64 *failtlvtype UNNEEDED, + size_t *failtlvpos UNNEEDED) { fprintf(stderr, "onion_decode called!\n"); abort(); } /* Generated stub for onion_type_name */ const char *onion_type_name(int e UNNEEDED) @@ -654,6 +656,9 @@ u8 *towire_incorrect_cltv_expiry(const tal_t *ctx UNNEEDED, u32 cltv_expiry UNNE /* Generated stub for towire_incorrect_or_unknown_payment_details */ u8 *towire_incorrect_or_unknown_payment_details(const tal_t *ctx UNNEEDED, struct amount_msat htlc_msat UNNEEDED, u32 height UNNEEDED) { fprintf(stderr, "towire_incorrect_or_unknown_payment_details called!\n"); abort(); } +/* Generated stub for towire_invalid_onion_payload */ +u8 *towire_invalid_onion_payload(const tal_t *ctx UNNEEDED, varint type UNNEEDED, u16 offset UNNEEDED) +{ fprintf(stderr, "towire_invalid_onion_payload called!\n"); abort(); } /* Generated stub for towire_invalid_realm */ u8 *towire_invalid_realm(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_invalid_realm called!\n"); abort(); }