Skip to content

Commit 5e078a8

Browse files
committed
pkt_init: check feature bits.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent ec64e77 commit 5e078a8

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

daemon/peer.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,28 @@ static struct io_plan *init_pkt_in(struct io_conn *conn, struct peer *peer)
21042104
state_name(peer->state)));
21052105
return pkt_out(conn, peer);
21062106
}
2107-
2107+
2108+
if (peer->inpkt->init->has_features) {
2109+
size_t i;
2110+
2111+
for (i = 0; i < peer->inpkt->init->features.len*CHAR_BIT; i++) {
2112+
size_t byte = i / CHAR_BIT, bit = i % CHAR_BIT;
2113+
if (peer->inpkt->init->features.data[byte] & (1<<bit)) {
2114+
/* Can't handle even features. */
2115+
if (i % 2 != 0) {
2116+
log_debug(peer->log,
2117+
"They offered feature %zu", i);
2118+
continue;
2119+
}
2120+
queue_pkt_err(peer,
2121+
pkt_err(peer,
2122+
"Unsupported feature %zu",
2123+
i));
2124+
return pkt_out(conn, peer);
2125+
}
2126+
}
2127+
}
2128+
21082129
/* Send any packets they missed. */
21092130
retransmit_pkts(peer, peer->inpkt->init->ack);
21102131

lightning.pb-c.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ const ProtobufCMessageDescriptor authenticate__descriptor =
16441644
(ProtobufCMessageInit) authenticate__init,
16451645
NULL,NULL,NULL /* reserved[123] */
16461646
};
1647-
static const ProtobufCFieldDescriptor init__field_descriptors[1] =
1647+
static const ProtobufCFieldDescriptor init__field_descriptors[2] =
16481648
{
16491649
{
16501650
"ack",
@@ -1658,14 +1658,27 @@ static const ProtobufCFieldDescriptor init__field_descriptors[1] =
16581658
0, /* flags */
16591659
0,NULL,NULL /* reserved1,reserved2, etc */
16601660
},
1661+
{
1662+
"features",
1663+
2,
1664+
PROTOBUF_C_LABEL_OPTIONAL,
1665+
PROTOBUF_C_TYPE_BYTES,
1666+
offsetof(Init, has_features),
1667+
offsetof(Init, features),
1668+
NULL,
1669+
NULL,
1670+
0, /* flags */
1671+
0,NULL,NULL /* reserved1,reserved2, etc */
1672+
},
16611673
};
16621674
static const unsigned init__field_indices_by_name[] = {
16631675
0, /* field[0] = ack */
1676+
1, /* field[1] = features */
16641677
};
16651678
static const ProtobufCIntRange init__number_ranges[1 + 1] =
16661679
{
16671680
{ 1, 0 },
1668-
{ 0, 1 }
1681+
{ 0, 2 }
16691682
};
16701683
const ProtobufCMessageDescriptor init__descriptor =
16711684
{
@@ -1675,7 +1688,7 @@ const ProtobufCMessageDescriptor init__descriptor =
16751688
"Init",
16761689
"",
16771690
sizeof(Init),
1678-
1,
1691+
2,
16791692
init__field_descriptors,
16801693
init__field_indices_by_name,
16811694
1, init__number_ranges,

lightning.pb-c.h

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lightning.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ message authenticate {
7070
message init {
7171
// How many update_commit and update_revocation messages already received
7272
required uint64 ack = 1;
73+
// What features do we support (odd) and require (even)
74+
optional bytes features = 2;
7375
};
7476

7577
// Set channel params.

0 commit comments

Comments
 (0)