]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Added API to allocate a reply packet from a request packet.
authorAlan T. DeKok <aland@freeradius.org>
Tue, 17 Mar 2009 16:04:08 +0000 (17:04 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 17 Mar 2009 16:04:08 +0000 (17:04 +0100)
This simplifies the rest of the code, as it now doesn't have to
copy src/dst of packet to dst/src reply.

src/include/libradius.h
src/lib/radius.c

index 0c8230361d974cf491fb26a752d42da8bb2d7dc8..01712edbc9e414b820f53854bb8de2b5a0c462e5 100644 (file)
@@ -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);
index e3bb49d16cfda2fe9e387c678721f34d3de55ba0..679e2aeafd4bca612ec7cd9aebe85b809f41ce34 100644 (file)
@@ -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
  */