VALUE Packet-Type Up 3
#
-# This is our version of our current link state, which is copied
-# to the request packet.
+# Additional data which gets added to the end of the BFD packet.
#
-DEFINE Link-State uint32 enum=Packet-Type
+DEFINE Additional-Data group
static fr_dict_attr_t const *attr_bfd_packet;
static fr_dict_attr_t const *attr_my_discriminator;
static fr_dict_attr_t const *attr_your_discriminator;
-static fr_dict_attr_t const *attr_link_state;
extern fr_dict_attr_autoload_t proto_bfd_dict_attr[];
fr_dict_attr_autoload_t proto_bfd_dict_attr[] = {
{ .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_bfd},
- { .out = &attr_link_state, .name = "Link-State", .type = FR_TYPE_UINT32, .dict = &dict_bfd},
{ .out = &attr_bfd_packet, .name = "Packet", .type = FR_TYPE_STRUCT, .dict = &dict_bfd},
{ .out = &attr_my_discriminator, .name = "Packet.my-discriminator", .type = FR_TYPE_UINT32, .dict = &dict_bfd},
extern HIDDEN fr_dict_attr_t const *attr_packet_type;
extern HIDDEN fr_dict_attr_t const *attr_bfd_packet;
+extern HIDDEN fr_dict_attr_t const *attr_bfd_additional_data;
fr_dict_attr_t const *attr_packet_type;
fr_dict_attr_t const *attr_bfd_packet;
+fr_dict_attr_t const *attr_bfd_additional_data;
extern fr_dict_attr_autoload_t libfreeradius_bfd_dict_attr[];
fr_dict_attr_autoload_t libfreeradius_bfd_dict_attr[] = {
{ .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_bfd },
{ .out = &attr_bfd_packet, .name = "Packet", .type = FR_TYPE_STRUCT, .dict = &dict_bfd },
+ { .out = &attr_bfd_additional_data, .name = "Additional-Data", .type = FR_TYPE_GROUP, .dict = &dict_bfd },
{ NULL }
};
#include <freeradius-devel/util/struct.h>
#include <freeradius-devel/io/test_point.h>
-#include <freeradius-devel/protocol/radius/freeradius.internal.h>
+#include <freeradius-devel/internal/internal.h>
#include "attrs.h"
{
ssize_t slen;
fr_bfd_ctx_t packet_ctx;
+ bfd_packet_t const *bfd;
+ fr_pair_t *vp;
+ fr_dbuff_t dbuff;
packet_ctx.secret = secret;
- slen = fr_struct_from_network(ctx, out, attr_bfd_packet, packet, packet_len, true,
+ bfd = (bfd_packet_t const *) packet;
+
+ slen = fr_struct_from_network(ctx, out, attr_bfd_packet, packet, bfd->length, true,
&packet_ctx, decode_value, NULL);
if (slen < 0) return slen;
+ if (bfd->length == packet_len) return packet_len;
+
+ /*
+ * Try to decode additional data.
+ */
+ vp = fr_pair_afrom_da(ctx, attr_bfd_additional_data);
+ if (!vp) return packet_len;
+
+ fr_dbuff_init(&dbuff, packet + slen, packet_len - slen);
+
+ if ((fr_internal_decode_list_dbuff(vp, &vp->vp_group, fr_dict_root(dict_bfd), &dbuff, NULL) < 0) ||
+ (fr_pair_list_num_elements(&vp->vp_group) == 0)) {
+ TALLOC_FREE(vp);
+ } else {
+ fr_pair_append(out, vp);
+ }
+
return slen;
}
RCSID("$Id$")
#include <freeradius-devel/util/dbuff.h>
-#include <freeradius-devel/util/md5.h>
#include <freeradius-devel/util/struct.h>
#include <freeradius-devel/io/test_point.h>
+#include <freeradius-devel/internal/internal.h>
+
#include "attrs.h"
/** Encodes the data portion of an attribute
static ssize_t fr_bfd_encode_proto(UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, void *proto_ctx)
{
fr_bfd_ctx_t *test_ctx = talloc_get_type_abort(proto_ctx, fr_bfd_ctx_t);
- ssize_t slen;
+ ssize_t slen, alen;
+ fr_pair_t *vp;
+ fr_dbuff_t dbuff;
/*
* @todo - pass in test_ctx to this function, so that we
slen = fr_bfd_encode(data, data_len, NULL, test_ctx->secret, talloc_array_length(test_ctx->secret) - 1, vps);
if (slen <= 0) return slen;
- return slen;
+ vp = fr_pair_find_by_da(vps, NULL, attr_bfd_additional_data);
+ if (!vp) return slen;
+
+ fr_dbuff_init(&dbuff, data + slen, data_len - slen);
+ alen = fr_internal_encode_list(&dbuff, &vp->vp_group, NULL);
+ if (alen <= 0) return slen;
+
+ return slen + alen;
}
/*
decode-proto -
match Packet-Type = Up, Packet = { version = 1, diagnostic = none, state = up, poll = no, final = no, control-plane-independent = no, auth-present = no, demand = no, multipoint = no, detect-multi = 3, length = 24, my-discriminator = 3735928559, your-discriminator = 554854409, desired-min-tx-interval = 31, required-min-tx-interval = 127, required-min-echo-interval = 255 }
+
+#
+# And with additional data.
+#
+# The BFD packet is exactly the same, but we also have a 3 octet string "foo", which is encoded via the internal dictionary, after the packet.
+#
+encode-proto Packet = { version = 1, diagnostic = none, state = up, poll = false, final = false, control-plane-independent = false, auth-present = false, demand = false, multipoint = false, detect-multi = 3, my-discriminator = 0xdeadbeef, your-discriminator = 0x21126809, desired-min-tx-interval = 31us, required-min-tx-interval = 127us, required-min-echo-interval = 255us }, Additional-Data = { Tmp-String-0 = "foo" }
+match 20 c0 03 18 de ad be ef 21 12 68 09 00 00 00 1f 00 00 00 7f 00 00 00 ff 21 40 06 ae 03 66 6f 6f
+
+decode-proto -
+match Packet-Type = Up, Packet = { version = 1, diagnostic = none, state = up, poll = no, final = no, control-plane-independent = no, auth-present = no, demand = no, multipoint = no, detect-multi = 3, length = 24, my-discriminator = 3735928559, your-discriminator = 554854409, desired-min-tx-interval = 31, required-min-tx-interval = 127, required-min-echo-interval = 255 }, Additional-Data = { Tmp-String-0 = "foo" }
+
count
-match 7
+match 11