proto_bfd_t const *inst = talloc_get_type_abort_const(instance, proto_bfd_t);
fr_io_track_t const *track = talloc_get_type_abort_const(request->async->packet_ctx, fr_io_track_t);
fr_io_address_t const *address = track->address;
- fr_client_t const *client;
+ fr_client_t const *client;
fr_pair_t *vp, *reply, *my, *your;
+ bfd_wrapper_t const *wrapper = (bfd_wrapper_t const *) data;
+ bfd_packet_t const *packet = (bfd_packet_t const *) wrapper->packet;
/*
* Set the request dictionary so that we can do
/*
* Hacks for now until we have a lower-level decode routine.
*/
- request->packet->code = data[1] >> 6;
- request->packet->id = fr_nbo_to_uint32(data + 4);
+ request->packet->code = packet->state;
+ request->packet->id = fr_nbo_to_uint32((uint8_t const *) &packet->my_disc);
request->reply->id = request->packet->id;
request->packet->data = talloc_memdup(request->packet, data, data_len);
* transport, via a call to fr_radius_ok().
*/
if (fr_bfd_decode(request->request_ctx, &request->request_pairs,
- request->packet->data, request->packet->data_len,
+ (uint8_t const *) packet, packet->length,
client->secret, talloc_array_length(client->secret) - 1) < 0) {
RPEDEBUG("Failed decoding packet");
return -1;
ssize_t data_size;
size_t packet_len;
- bfd_packet_t *packet;
+ bfd_packet_t *packet;
char const *err = NULL;
bfd_state_change_t state_change;
+ bfd_wrapper_t *wrapper = (bfd_wrapper_t *) buffer;
*leftover = 0; /* always for UDP */
*/
flags = UDP_FLAGS_CONNECTED * (thread->connection != NULL);
- data_size = udp_recv(thread->sockfd, flags, &address->socket, buffer, buffer_len, recv_time_p);
+ data_size = udp_recv(thread->sockfd, flags, &address->socket, wrapper->packet, buffer_len - (wrapper->packet - buffer), recv_time_p);
if (data_size < 0) {
PDEBUG2("proto_bfd_udp got read error");
return data_size;
packet_len = data_size;
- if (!fr_bfd_packet_ok(&err, buffer, packet_len)) {
+ if (!fr_bfd_packet_ok(&err, wrapper->packet, packet_len)) {
DEBUG2("proto_bfd_udp - Received invalid packet on %s - %s", thread->name, err);
thread->stats.total_malformed_requests++;
return 0;
}
thread->stats.total_requests++;
-
- packet = (bfd_packet_t *) buffer;
+ packet = (bfd_packet_t *) wrapper->packet;
/*
* Print out what we received.
* we either send the packet through to unlang, or not.
*/
state_change = bfd_session_process((bfd_session_t *) client, packet);
+
if ((state_change == BFD_STATE_CHANGE_INVALID) || (state_change == BFD_STATE_CHANGE_ADMIN_DOWN)) return 0;
if ((state_change == BFD_STATE_CHANGE_NONE) && inst->only_state_changes) return 0;
- return packet_len;
+ wrapper->type = BFD_WRAPPER_RECV_PACKET;
+ wrapper->state_change = state_change;
+
+ return sizeof(wrapper) + packet_len;
}
static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t request_time,
if (peer->inst != inst) continue;
peer->el = el;
+ peer->listen = li;
peer->nr = (fr_network_t *) nr;
peer->sockfd = thread->sockfd;
* we will need to define some other kind of fake packet to send to the process
* module.
*/
-static void bfd_trigger(bfd_session_t *session, UNUSED bfd_state_change_t change)
+static void bfd_trigger(bfd_session_t *session, bfd_state_change_t change)
{
-// fr_radius_packet_t packet;
-// request_t *request = request_local_alloc_external(session, NULL);
- char buffer[256];
+ bfd_wrapper_t wrapper;
- snprintf(buffer, sizeof(buffer), "server.bfd.%s",
- fr_bfd_packet_names[session->session_state]);
+ wrapper.type = BFD_WRAPPER_STATE_CHANGE;
+ wrapper.state_change = change;
+ wrapper.session = session;
- DEBUG("BFD %s trigger %s", session->client.shortname, buffer);
-
-// bfd_request(session, request, &packet);
+ /*
+ * @todo - proto_bfd.c mod_decode() has to be updated to check for non-existent packet,
+ * and create a fake "timeout" packet with appropriate data.
+ */
-// trigger_exec(unlang_interpret_get_thread_default(), NULL, buffer, false, NULL);
+// (void) fr_network_listen_inject(session->nr, session->listen, (uint8_t const *) &wrapper, sizeof(wrapper), fr_time());
}
/*
} bfd_state_change_t;
typedef struct {
- uint32_t type;
- union {
- bfd_packet_t packet;
- struct {
- bfd_state_change_t state_change;
- bfd_session_t *peer;
- };
- };
+ uint32_t type;
+ bfd_state_change_t state_change;
+ bfd_session_t *session;
+ uint8_t packet[];
} bfd_wrapper_t;
int bfd_session_init(bfd_session_t *session);