From: Alan T. DeKok Date: Tue, 17 Mar 2009 16:04:08 +0000 (+0100) Subject: Added API to allocate a reply packet from a request packet. X-Git-Tag: release_2_1_7~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6d5b23403f04029df6e9ac77ca6b697be3f5053;p=thirdparty%2Ffreeradius-server.git Added API to allocate a reply packet from a request packet. This simplifies the rest of the code, as it now doesn't have to copy src/dst of packet to dst/src reply. --- diff --git a/src/include/libradius.h b/src/include/libradius.h index 0c8230361d9..01712edbc9e 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -300,6 +300,7 @@ int rad_sign(RADIUS_PACKET *packet, const RADIUS_PACKET *original, const char *secret); RADIUS_PACKET *rad_alloc(int newvector); +RADIUS_PACKET *rad_alloc_reply(RADIUS_PACKET *); void rad_free(RADIUS_PACKET **); int rad_pwencode(char *encpw, size_t *len, const char *secret, const uint8_t *vector); diff --git a/src/lib/radius.c b/src/lib/radius.c index e3bb49d16cf..679e2aeafd4 100644 --- a/src/lib/radius.c +++ b/src/lib/radius.c @@ -3447,6 +3447,35 @@ RADIUS_PACKET *rad_alloc(int newvector) return rp; } +RADIUS_PACKET *rad_alloc_reply(RADIUS_PACKET *packet) +{ + RADIUS_PACKET *reply; + + if (!packet) return NULL; + + reply = rad_alloc(0); + if (!reply) return NULL; + + /* + * Initialize the fields from the request. + */ + reply->sockfd = packet->sockfd; + reply->dst_ipaddr = packet->src_ipaddr; + reply->src_ipaddr = packet->dst_ipaddr; + reply->dst_port = packet->src_port; + reply->src_port = packet->dst_port; + reply->id = packet->id; + reply->code = 0; /* UNKNOWN code */ + memcpy(reply->vector, packet->vector, + sizeof(reply->vector)); + reply->vps = NULL; + reply->data = NULL; + reply->data_len = 0; + + return reply; +} + + /* * Free a RADIUS_PACKET */