return dl_instance(ctx, out, transport_cs, parent_inst, name, DL_TYPE_SUBMODULE);
}
-/** Decode the packet, and set the request->process function
+/** Decode the packet.
*
*/
static int mod_decode(void const *instance, REQUEST *request, uint8_t *const data, size_t data_len)
{
proto_vmps_t const *inst = talloc_get_type_abort(instance, proto_vmps_t);
-#if 0
- rad_assert(data[0] < FR_MAX_PACKET_CODE);
-
- client = inst->app_io_private->client(inst->app_io, request->async->packet_ctx);
- rad_assert(client);
-
- /*
- * Hacks for now until we have a lower-level decode routine.
- */
- request->packet->code = data[0];
- request->packet->id = data[1];
- request->reply->id = data[1];
- memcpy(request->packet->vector, data + 4, sizeof(request->packet->vector));
-
- request->packet->data = talloc_memdup(request->packet, data, data_len);
- request->packet->data_len = data_len;
-
- if (fr_vmps_packet_decode(request->packet, NULL, client->secret) < 0) {
- RDEBUG("Failed decoding packet: %s", fr_strerror());
- return -1;
- }
-#endif
-
- /*
- * Let the app_io take care of populating additional fields in the request
- */
return inst->app_io->decode(inst->app_io_instance, request, data, data_len);
}
-static ssize_t mod_encode(UNUSED void const *instance, UNUSED REQUEST *request, UNUSED uint8_t *buffer, UNUSED size_t buffer_len)
+static ssize_t mod_encode(void const *instance, REQUEST *request, uint8_t *buffer, size_t buffer_len)
{
-#if 0
- size_t len;
-
proto_vmps_t const *inst = talloc_get_type_abort(instance, proto_vmps_t);
- RADCLIENT *client;
-
- client = inst->app_io_private->client(inst->app_io, request->async->packet_ctx);
- rad_assert(client);
-
- if (fr_vmps_packet_encode(request->reply, request->packet, client->secret) < 0) {
- RDEBUG("Failed encoding VMPS reply: %s", fr_strerror());
- return -1;
- }
-
- if (fr_vmps_packet_sign(request->reply, request->packet, client->secret) < 0) {
- RDEBUG("Failed signing VMPS reply: %s", fr_strerror());
- return -1;
- }
-
- len = request->reply->data_len;
- if (buffer_len < len) len = buffer_len;
-
- memcpy(buffer, request->reply->data, len);
-
- return len;
-#endif
- return -1;
+ return inst->app_io->encode(inst->app_io_instance, request, buffer, buffer_len);
}
static void mod_process_set(void const *instance, REQUEST *request)
#include <freeradius-devel/rad_assert.h>
#include "proto_vmps.h"
-typedef struct {
- int if_index;
-
- fr_ipaddr_t src_ipaddr;
- fr_ipaddr_t dst_ipaddr;
- uint16_t src_port;
- uint16_t dst_port;
-
- fr_time_t timestamp;
-
- RADCLIENT *client;
-} proto_vmps_udp_address_t;
-
typedef struct {
proto_vmps_t const *parent; //!< The module that spawned us!
int sockfd;
- fr_event_list_t *el; //!< for cleanup timers on Access-Request
-
fr_ipaddr_t ipaddr; //!< Ipaddr to listen on.
bool ipaddr_is_set; //!< ipaddr config item is set.
uint32_t recv_buff; //!< How big the kernel's receive buffer should be.
bool recv_buff_is_set; //!< Whether we were provided with a receive
//!< buffer value.
-
-// fr_tracking_t *ft; //!< tracking table
- uint32_t cleanup_delay; //!< cleanup delay for Access-Request packets
} proto_vmps_udp_t;
static const CONF_PARSER udp_listen_config[] = {
{ FR_CONF_OFFSET("port", FR_TYPE_UINT16, proto_vmps_udp_t, port) },
{ FR_CONF_IS_SET_OFFSET("recv_buff", FR_TYPE_UINT32, proto_vmps_udp_t, recv_buff) },
- { FR_CONF_OFFSET("cleanup_delay", FR_TYPE_UINT32, proto_vmps_udp_t, cleanup_delay), .dflt = "5" },
-
CONF_PARSER_TERMINATOR
};
*/
static int mod_src_address(fr_socket_addr_t *src, UNUSED void const *instance, void const *packet_ctx)
{
- fr_tracking_entry_t const *track = packet_ctx;
- proto_vmps_udp_address_t const *address = track->src_dst;
-
- rad_assert(track->src_dst_size == sizeof(proto_vmps_udp_address_t));
+ fr_ip_srcdst_t const *ip = packet_ctx;
memset(src, 0, sizeof(*src));
src->proto = IPPROTO_UDP;
- memcpy(&src->ipaddr, &address->src_ipaddr, sizeof(src->ipaddr));
+ memcpy(&src->ipaddr, &ip->src_ipaddr, sizeof(src->ipaddr));
return 0;
}
*/
static int mod_dst_address(fr_socket_addr_t *dst, UNUSED void const *instance, void const *packet_ctx)
{
- fr_tracking_entry_t const *track = packet_ctx;
- proto_vmps_udp_address_t const *address = track->src_dst;
-
- rad_assert(track->src_dst_size == sizeof(proto_vmps_udp_address_t));
+ fr_ip_srcdst_t const *ip = packet_ctx;
memset(dst, 0, sizeof(*dst));
dst->proto = IPPROTO_UDP;
- memcpy(&dst->ipaddr, &address->dst_ipaddr, sizeof(dst->ipaddr));
+ memcpy(&dst->ipaddr, &ip->dst_ipaddr, sizeof(dst->ipaddr));
return 0;
}
-/** Return the client associated with the packet_ctx
+
+/** Decode the packet.
*
*/
-static RADCLIENT *mod_client(UNUSED void const *instance, void const *packet_ctx)
+static int mod_decode(UNUSED void const *instance, REQUEST *request, uint8_t *const data, size_t data_len)
{
- fr_tracking_entry_t const *track = packet_ctx;
- proto_vmps_udp_address_t const *address = track->src_dst;
+// proto_vmps_udp_t const *inst = talloc_get_type_abort(instance, proto_vmps_udp_t);
+ fr_ip_srcdst_t *ip;
+ uint8_t *packet;
+ size_t packet_len;
- rad_assert(track->src_dst_size == sizeof(proto_vmps_udp_address_t));
+ ip = talloc_memdup(request, request->async->packet_ctx, sizeof(*ip));
+ if (!ip) return -1;
- return address->client;
-}
+ request->async->packet_ctx = ip;
-static int mod_decode(UNUSED void const *instance, REQUEST *request, UNUSED uint8_t *const data, UNUSED size_t data_len)
-{
+ packet = data + sizeof(*ip);
+ packet_len = data_len - sizeof(*ip);
- fr_tracking_entry_t const *track = request->async->packet_ctx;
- proto_vmps_udp_address_t const *address = track->src_dst;
+ // decode the packet into attributes.
- rad_assert(track->src_dst_size == sizeof(proto_vmps_udp_address_t));
+ return 0;
+}
- request->client = address->client;
- request->packet->if_index = address->if_index;
- request->packet->src_ipaddr = address->src_ipaddr;
- request->packet->src_port = address->src_port;
- request->packet->dst_ipaddr = address->dst_ipaddr;
- request->packet->dst_port = address->dst_port;
+static ssize_t mod_encode(UNUSED void const *instance, REQUEST *request, uint8_t *buffer, size_t buffer_len)
+{
+// proto_vmps_udp_t const *inst = talloc_get_type_abort(instance, proto_vmps_udp_t);
+ fr_ip_srcdst_t *ip;
+ uint8_t *packet;
+ size_t packet_len;
- request->reply->if_index = address->if_index;
- request->reply->src_ipaddr = address->dst_ipaddr;
- request->reply->src_port = address->dst_port;
- request->reply->dst_ipaddr = address->src_ipaddr;
- request->reply->dst_port = address->src_port;
+ ip = request->async->packet_ctx;
+ packet = buffer + sizeof(*ip);
+ packet_len = buffer_len - sizeof(*ip);
+
+ memcpy(buffer, ip, sizeof(*ip));
- request->root = &main_config;
- VERIFY_REQUEST(request);
+ // encode packet in buffer
return 0;
}
inst->port = ntohl(s->s_port);
}
- FR_INTEGER_BOUND_CHECK("cleanup_delay", inst->cleanup_delay, <=, 30);
-
-#if 0
- inst->ft = fr_vmps_tracking_create(inst, sizeof(proto_vmps_udp_address_t), inst->parent->code_allowed);
- if (!inst->ft) {
- cf_log_err(cs, "Failed to create tracking table: %s", fr_strerror());
- }
-#endif
-
return 0;
}
*/
extern proto_vmps_app_io_t proto_vmps_app_io_private;
proto_vmps_app_io_t proto_vmps_app_io_private = {
- .client = mod_client,
.src = mod_src_address,
.dst = mod_dst_address
};
.open = mod_open,
.read = mod_read,
.decode = mod_decode,
+ .encode = mod_encode,
.write = mod_write,
.fd = mod_fd,
};