Commit 38bf0c358f for frr
commit 38bf0c358f0d8a836fee4421358295fd106fb537
Author: Abdul Wasey <w453y.me@gmail.com>
Date: Fri Oct 30 18:01:29 2026 +0000
bfdd: tell the data plane which keyed SHA1 a key uses
A data plane is given the keys of a session and computes the digest
itself, so it has to know whether a keyed SHA1 key uses the RFC 5880
construction or the HMAC. Mark sha-1 keys with BFDDP_AUTH_KEY_RFC_SHA1
in a byte that was reserved, and offload a session holding one only to
a data plane that declared BFDDP_CAP_AUTH_RFC_SHA1. A data plane built
before this sees the byte as zero and is never sent such a key.
The listener records the flags and dumps them with each key.
Signed-off-by: Abdul Wasey <w453y.me@gmail.com>
diff --git a/bfdd/bfd_dplane_listener.c b/bfdd/bfd_dplane_listener.c
index 054c268ebd..233c2f230e 100644
--- a/bfdd/bfd_dplane_listener.c
+++ b/bfdd/bfd_dplane_listener.c
@@ -71,6 +71,7 @@ struct listener_auth_key {
uint8_t type;
uint8_t key_id;
uint8_t key_len;
+ uint8_t flags;
int64_t send_start;
int64_t send_end;
int64_t accept_start;
@@ -237,12 +238,13 @@ static void sigusr1_handler(int signum)
fprintf(out, "Auth last lid: %u\n", glob->auth_lid);
fprintf(out, "Auth last key count: %zu\n", glob->auth_key_count);
for (i = 0; i < glob->auth_key_count; i++)
- fprintf(out, " auth key: id %u type %u len %u send %lld %lld accept %lld %lld\n",
+ fprintf(out,
+ " auth key: id %u type %u len %u send %lld %lld accept %lld %lld flags %u\n",
glob->auth_key[i].key_id, glob->auth_key[i].type,
glob->auth_key[i].key_len, (long long)glob->auth_key[i].send_start,
(long long)glob->auth_key[i].send_end,
(long long)glob->auth_key[i].accept_start,
- (long long)glob->auth_key[i].accept_end);
+ (long long)glob->auth_key[i].accept_end, glob->auth_key[i].flags);
fprintf(out, "Echo requested: %s\n", glob->echo_flag ? "yes" : "no");
fprintf(out, "Echo interval requested: %u\n", glob->echo_tx_requested);
@@ -482,6 +484,7 @@ static void record_auth_keys(const struct bfddp_message *msg)
glob->auth_key[i].type = keys[i].type;
glob->auth_key[i].key_id = keys[i].key_id;
glob->auth_key[i].key_len = keys[i].key_len;
+ glob->auth_key[i].flags = keys[i].flags;
glob->auth_key[i].send_start = (int64_t)be64toh((uint64_t)keys[i].send.start);
glob->auth_key[i].send_end = (int64_t)be64toh((uint64_t)keys[i].send.end);
glob->auth_key[i].accept_start = (int64_t)be64toh((uint64_t)keys[i].accept.start);
diff --git a/bfdd/bfddp_packet.h b/bfdd/bfddp_packet.h
index 082c174f60..7c87d90cc1 100644
--- a/bfdd/bfddp_packet.h
+++ b/bfdd/bfddp_packet.h
@@ -110,6 +110,10 @@ enum bfddp_message_type {
*/
/** Authenticates sessions with the keys `DP_SESSION_AUTH` carries. */
#define BFDDP_CAP_SESSION_AUTH (1ULL << 0)
+/** Computes keyed SHA1 as RFC 5880 Section 6.7.4 does, for keys flagged
+ * `BFDDP_AUTH_KEY_RFC_SHA1`.
+ */
+#define BFDDP_CAP_AUTH_RFC_SHA1 (1ULL << 1)
/**
* `ECHO_REQUEST`/`ECHO_REPLY` data payload.
@@ -386,13 +390,18 @@ struct bfddp_auth_key {
uint8_t key_id;
/** Length of `key`, in bytes. */
uint8_t key_len;
+ /**
+ * \see BFDDP_AUTH_KEY_RFC_SHA1. Without it, keyed SHA1 is an
+ * HMAC-SHA1 over the packet with the digest field zeroed.
+ */
+ uint8_t flags;
/**
* Reserved / zeroed.
*
* Sized so the lifetimes below start on an eight byte boundary
* without the compiler inserting padding of its own.
*/
- uint8_t zero[5];
+ uint8_t zero[4];
/** When this key may be used to transmit. */
struct bfddp_key_lifetime send;
@@ -403,6 +412,13 @@ struct bfddp_auth_key {
char key[BFDDP_AUTH_KEY_MAX];
};
+/**
+ * `bfddp_auth_key.flags`: keyed SHA1 as RFC 5880 Section 6.7.4 describes,
+ * SHA1 over the packet with the key in the digest field. Only sent to a
+ * data plane that declared `BFDDP_CAP_AUTH_RFC_SHA1`.
+ */
+#define BFDDP_AUTH_KEY_RFC_SHA1 0x01
+
/**
* `DP_SESSION_AUTH` data payload.
*
diff --git a/bfdd/dplane.c b/bfdd/dplane.c
index 2d72daa475..7bf05bfadc 100644
--- a/bfdd/dplane.c
+++ b/bfdd/dplane.c
@@ -772,10 +772,17 @@ static void bfd_dplane_read(struct event *t)
/* The capabilities a data plane must have declared to run this session. */
static uint64_t bfd_dplane_session_needs(const struct bfd_session *bs)
{
+ struct listnode *node;
+ struct key *key;
uint64_t needs = 0;
- if (bs->kc)
- needs |= BFDDP_CAP_SESSION_AUTH;
+ if (!bs->kc)
+ return needs;
+
+ needs |= BFDDP_CAP_SESSION_AUTH;
+ for (ALL_LIST_ELEMENTS_RO(bs->kc->key, node, key))
+ if (key->hash_algo == KEYCHAIN_ALGO_SHA1)
+ needs |= BFDDP_CAP_AUTH_RFC_SHA1;
return needs;
}
@@ -1654,6 +1661,8 @@ static int bfd_dplane_send_session_auth(const struct bfd_session *bs)
}
keys[count].type = type;
+ if (key->hash_algo == KEYCHAIN_ALGO_SHA1)
+ keys[count].flags = BFDDP_AUTH_KEY_RFC_SHA1;
keys[count].key_id = (uint8_t)key->index;
keys[count].key_len = (uint8_t)keylen;
keys[count].send.start = htobe64((uint64_t)key->send.start);
diff --git a/doc/user/bfd.rst b/doc/user/bfd.rst
index 74aa640c9e..cf30b93970 100644
--- a/doc/user/bfd.rst
+++ b/doc/user/bfd.rst
@@ -901,6 +901,10 @@ the message is treated as supporting none of them. The features are:
daemon sends. Without it a session configured with an authentication key
chain stays in the BFD daemon.
+* ``BFDDP_CAP_AUTH_RFC_SHA1``: computes keyed SHA1 as RFC 5880 Section 6.7.4
+ describes for keys flagged ``BFDDP_AUTH_KEY_RFC_SHA1``. Without it a
+ session whose key chain holds a ``sha-1`` key stays in the BFD daemon.
+
BFD daemon will also keep record of data plane communication statistics with
the command :clicmd:`show bfd distributed`.