#include <fcntl.h>
/*
- * Take the key fields of a request packet, and convert it to a
- * hash.
- */
-uint32_t fr_request_packet_hash(const RADIUS_PACKET *packet)
-{
- uint32_t hash;
-
- if (packet->hash) return packet->hash;
-
- hash = fr_hash(&packet->sockfd, sizeof(packet->sockfd));
- hash = fr_hash_update(&packet->src_port, sizeof(packet->src_port),
- hash);
- hash = fr_hash_update(&packet->dst_port,
- sizeof(packet->dst_port), hash);
- hash = fr_hash_update(&packet->src_ipaddr.af,
- sizeof(packet->src_ipaddr.af), hash);
-
- /*
- * The caller ensures that src & dst AF are the same.
- */
- switch (packet->src_ipaddr.af) {
- case AF_INET:
- hash = fr_hash_update(&packet->src_ipaddr.ipaddr.ip4addr,
- sizeof(packet->src_ipaddr.ipaddr.ip4addr),
- hash);
- hash = fr_hash_update(&packet->dst_ipaddr.ipaddr.ip4addr,
- sizeof(packet->dst_ipaddr.ipaddr.ip4addr),
- hash);
- break;
- case AF_INET6:
- hash = fr_hash_update(&packet->src_ipaddr.ipaddr.ip6addr,
- sizeof(packet->src_ipaddr.ipaddr.ip6addr),
- hash);
- hash = fr_hash_update(&packet->dst_ipaddr.ipaddr.ip6addr,
- sizeof(packet->dst_ipaddr.ipaddr.ip6addr),
- hash);
- break;
- default:
- break;
- }
-
- return fr_hash_update(&packet->id, sizeof(packet->id), hash);
-}
-
-
-/*
- * Take the key fields of a reply packet, and convert it to a
- * hash.
- *
- * i.e. take a reply packet, and find the hash of the request packet
- * that asked for the reply. To do this, we hash the reverse fields
- * of the request. e.g. where the request does (src, dst), we do
- * (dst, src)
- */
-uint32_t fr_reply_packet_hash(const RADIUS_PACKET *packet)
-{
- uint32_t hash;
-
- hash = fr_hash(&packet->sockfd, sizeof(packet->sockfd));
- hash = fr_hash_update(&packet->id, sizeof(packet->id), hash);
- hash = fr_hash_update(&packet->src_port, sizeof(packet->src_port),
- hash);
- hash = fr_hash_update(&packet->dst_port,
- sizeof(packet->dst_port), hash);
- hash = fr_hash_update(&packet->src_ipaddr.af,
- sizeof(packet->src_ipaddr.af), hash);
-
- /*
- * The caller ensures that src & dst AF are the same.
- */
- switch (packet->src_ipaddr.af) {
- case AF_INET:
- hash = fr_hash_update(&packet->dst_ipaddr.ipaddr.ip4addr,
- sizeof(packet->dst_ipaddr.ipaddr.ip4addr),
- hash);
- hash = fr_hash_update(&packet->src_ipaddr.ipaddr.ip4addr,
- sizeof(packet->src_ipaddr.ipaddr.ip4addr),
- hash);
- break;
- case AF_INET6:
- hash = fr_hash_update(&packet->dst_ipaddr.ipaddr.ip6addr,
- sizeof(packet->dst_ipaddr.ipaddr.ip6addr),
- hash);
- hash = fr_hash_update(&packet->src_ipaddr.ipaddr.ip6addr,
- sizeof(packet->src_ipaddr.ipaddr.ip6addr),
- hash);
- break;
- default:
- break;
- }
-
- return fr_hash_update(&packet->id, sizeof(packet->id), hash);
-}
-
-
-/*
* See if two packets are identical.
*
* Note that we do NOT compare the authentication vectors.