import from branch_1_1:
[freeradius.git] / src / include / radsniff.h
1 /*
2  *  radsniff.h  Structures and defines for the RADIUS sniffer.
3  *
4  *  Version:    $Id$
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  as published by the Free Software Foundation; either version 2
9  *  of the License, or (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  *  Copyright 2006  The FreeRADIUS server project
21  *  Copyright 2006  Nicolas Baradakis <nicolas.baradakis@cegetel.net>
22  */
23
24 #include <freeradius-devel/ident.h>
25 RCSIDH(radsniff_h, "$Id$")
26
27 #include <sys/types.h>
28 #include <netinet/in.h>
29
30 /*
31  *      The number of bytes in an ethernet (MAC) address.
32  */
33 #define ETHER_ADDR_LEN          6
34
35 /*
36  *      Structure of a DEC/Intel/Xerox or 802.3 Ethernet header.
37  */
38 struct  ethernet_header {
39         u_int8_t        ethernet_dhost[ETHER_ADDR_LEN];
40         u_int8_t        ethernet_shost[ETHER_ADDR_LEN];
41         u_int16_t       ethernet_type;
42 };
43
44 /*
45  *      Length of a DEC/Intel/Xerox or 802.3 Ethernet header.
46  *      Note that some compilers may pad "struct ether_header" to
47  *      a multiple of 4 *bytes, for example, so "sizeof (struct
48  *      ether_header)" may not give the right answer.
49  */
50 #define ETHER_HDRLEN            14
51
52 /*
53  *      Structure of an internet header, naked of options.
54  */
55 struct ip_header {
56         u_int8_t        ip_vhl;         /* header length, version */
57 #define IP_V(ip)        (((ip)->ip_vhl & 0xf0) >> 4)
58 #define IP_HL(ip)       ((ip)->ip_vhl & 0x0f)
59         u_int8_t        ip_tos;         /* type of service */
60         u_int16_t       ip_len;         /* total length */
61         u_int16_t       ip_id;          /* identification */
62         u_int16_t       ip_off;         /* fragment offset field */
63 #define IP_DF 0x4000                    /* dont fragment flag */
64 #define IP_MF 0x2000                    /* more fragments flag */
65 #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
66         u_int8_t        ip_ttl;         /* time to live */
67         u_int8_t        ip_p;           /* protocol */
68         u_int16_t       ip_sum;         /* checksum */
69         struct in_addr  ip_src,ip_dst;  /* source and dest address */
70 };
71
72 /*
73  *      UDP protocol header.
74  *      Per RFC 768, September, 1981.
75  */
76 struct udp_header {
77         u_int16_t       udp_sport;               /* source port */
78         u_int16_t       udp_dport;               /* destination port */
79         u_int16_t       udp_ulen;                /* udp length */
80         u_int16_t       udp_sum;                 /* udp checksum */
81 };
82
83 /*
84  *      RADIUS packet length.
85  *      RFC 2865, Section 3., subsection 'length' says:
86  *      " ... and maximum length is 4096."
87  */
88 #define MAX_RADIUS_LEN 4096
89 #define MIN_RADIUS_LEN 20
90 #define SNAPLEN (sizeof(struct ethernet_header) + sizeof(struct ip_header) + sizeof(struct udp_header) + MAX_RADIUS_LEN)
91
92 typedef struct radius_packet_t {
93         uint8_t       code;
94         uint8_t       id;
95         uint8_t       length[2];
96         uint8_t       vector[AUTH_VECTOR_LEN];
97         uint8_t       data[1];
98 } radius_packet_t;
99
100 #define AUTH_HDR_LEN 20