The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
packet.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /** Structures and functions for packet manipulation
19  *
20  * @file src/lib/util/packet.h
21  *
22  * @copyright 2001, 2002, 2003, 2004, 2005, 2006 The FreeRADIUS server project
23  */
24 RCSIDH(packet_h, "$Id: 99b4344a827e345c7660130ceaf5c83398c0f6bd $")
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <freeradius-devel/build.h>
31 #include <freeradius-devel/missing.h>
32 #include <freeradius-devel/util/inet.h>
33 #include <freeradius-devel/util/pair.h>
34 #include <freeradius-devel/util/rb.h>
35 #include <freeradius-devel/util/socket.h>
36 #include <freeradius-devel/util/talloc.h>
37 #include <freeradius-devel/util/time.h>
38 
39 #ifdef WITH_VERIFY_PTR
40 # define PACKET_VERIFY(_x) (void) talloc_get_type_abort_const(_x, fr_packet_t)
41 #else
42 # define PACKET_VERIFY(_x) fr_cond_assert(_x)
43 #endif
44 
45 #define RADIUS_AUTH_VECTOR_LENGTH 16
46 
47 /*
48  * vector: Request authenticator from access-request packet
49  * Put in there by rad_decode, and must be put in the
50  * response fr_packet_t as well before calling fr_packet_send
51  *
52  * verified: Filled in by rad_decode for accounting-request packets
53  *
54  * data,data_len: Used between fr_radius_recv and fr_radius_decode.
55  */
56 typedef struct {
57  fr_socket_t socket; //!< This packet was received on.
58  fr_time_t timestamp; //!< When we received the packet.
59 
60  int id; //!< Packet ID (used to link requests/responses).
61  unsigned int code; //!< Packet code (type).
62 
63  uint8_t *data; //!< Packet data (body).
64  size_t data_len; //!< Length of packet data.
65 
66  /*
67  * The vector should go away soon
68  */
69  uint8_t vector[RADIUS_AUTH_VECTOR_LENGTH];//!< RADIUS authentication vector.
70 
71  /*
72  * The following fields are deprecated, and only used by old code.
73  */
74  fr_rb_node_t node; //!< Allows insertion into the list.c
75  ///< rbtree, may be removed in future.
76 
77  size_t partial;
78 
79  void *uctx;
80 } fr_packet_t;
81 
82 fr_packet_t *fr_packet_alloc(TALLOC_CTX *ctx, bool new_vector);
83 fr_packet_t *fr_packet_alloc_reply(TALLOC_CTX *ctx, fr_packet_t *);
85 
86 #ifdef __cplusplus
87 }
88 #endif
#define RCSIDH(h, id)
Definition: build.h:445
unsigned char uint8_t
Definition: merged_model.c:30
"server local" time.
Definition: time.h:69
void fr_packet_free(fr_packet_t **)
Free a fr_packet_t.
Definition: packet.c:89
void * uctx
Definition: packet.h:79
fr_rb_node_t node
Allows insertion into the list.c rbtree, may be removed in future.
Definition: packet.h:74
unsigned int code
Packet code (type).
Definition: packet.h:61
fr_socket_t socket
This packet was received on.
Definition: packet.h:57
int id
Packet ID (used to link requests/responses).
Definition: packet.h:60
uint8_t * data
Packet data (body).
Definition: packet.h:63
fr_packet_t * fr_packet_alloc(TALLOC_CTX *ctx, bool new_vector)
Allocate a new fr_packet_t.
Definition: packet.c:38
size_t data_len
Length of packet data.
Definition: packet.h:64
#define RADIUS_AUTH_VECTOR_LENGTH
Definition: packet.h:45
size_t partial
Definition: packet.h:77
fr_time_t timestamp
When we received the packet.
Definition: packet.h:58
fr_packet_t * fr_packet_alloc_reply(TALLOC_CTX *ctx, fr_packet_t *)
Allocate a new fr_packet_t response.
Definition: packet.c:63
Holds information necessary for binding or connecting to a socket.
Definition: socket.h:63