Compile-time option WITH_ACCOUNTING
[freeradius.git] / src / include / radius_snmp.h
1 #ifndef _RADIUS_SNMP_H
2 #define _RADIUS_SNMP_H
3 /*
4  * Version:     $Id$
5  */
6
7 #include <freeradius-devel/ident.h>
8 RCSIDH(radius_snmp_h, "$Id$")
9
10 #ifdef WITH_SNMP
11
12 typedef enum smux_event_t {
13   SMUX_NONE, SMUX_CONNECT, SMUX_READ
14 } smux_event_t;
15
16 extern int radius_snmp_init(CONF_SECTION *);
17 extern int smux_connect(void);
18 extern int smux_read(void);
19
20 /*
21  *      The RADIUS server snmp data structures.
22  */
23 typedef struct rad_snmp_server_t {
24         const char      *ident;
25         time_t          start_time;
26         int32_t         uptime; /* in hundredths of a second */
27
28         time_t          last_reset_time;
29         int32_t         reset_time;
30         int32_t         config_reset;
31         int32_t         total_requests;
32         int32_t         total_invalid_requests;
33         int32_t         total_dup_requests;
34         int32_t         total_responses;
35         int32_t         total_access_accepts;
36         int32_t         total_access_rejects;
37         int32_t         total_access_challenges;
38         int32_t         total_malformed_requests;
39         int32_t         total_bad_authenticators;
40         int32_t         total_packets_dropped;
41         int32_t         total_no_records;
42         int32_t         total_unknown_types;
43 } rad_snmp_server_t;
44
45 typedef struct rad_snmp_t {
46         rad_snmp_server_t auth;
47 #ifdef WITH_ACCOUNTING
48         rad_snmp_server_t acct;
49 #endif
50         smux_event_t      smux_event;
51         const char        *smux_password;
52         int               snmp_write_access;
53         int               smux_fd;
54         int               smux_failures;
55         int               smux_max_failures;
56 } rad_snmp_t;
57
58 /*
59  *  Taken from RFC 2619 and RFC 2621
60  */
61 struct rad_snmp_client_entry_t {
62         int             index;
63         /* IP address */
64         /* Client ID (string ) */
65         uint32_t        requests;
66         uint32_t        dup_requests;
67         uint32_t        responses;
68         uint32_t        accepts;
69         uint32_t        rejects;
70         uint32_t        challenges;
71         uint32_t        malformed_requests;
72         uint32_t        bad_authenticators;
73         uint32_t        packets_dropped;
74         uint32_t        unknown_types;
75 };
76
77 extern rad_snmp_t       rad_snmp;
78
79 #define RAD_SNMP_INC(_x) if (mainconfig.do_snmp) _x++
80 #ifdef WITH_ACCOUNTING
81 #define RAD_SNMP_TYPE_INC(_listener, _x) if (mainconfig.do_snmp) { \
82                                      if (_listener->type == RAD_LISTEN_AUTH) { \
83                                        rad_snmp.auth._x++; \
84                                      } else { if (_listener->type == RAD_LISTEN_ACCT) \
85                                        rad_snmp.acct._x++; } }
86
87 #define RAD_SNMP_CLIENT_INC(_listener, _client, _x) if (mainconfig.do_snmp) { \
88                                      if (_listener->type == RAD_LISTEN_AUTH) { \
89                                        _client->auth->_x++; \
90                                      } else { if (_listener->type == RAD_LISTEN_ACCT) \
91                                        _client->acct->_x++; } }
92
93 #else  /* WITH_ACCOUNTING */
94
95 #define RAD_SNMP_TYPE_INC(_listener, _x) if (mainconfig.do_snmp) { \
96                                      rad_snmp.auth._x++; }
97
98 #define RAD_SNMP_CLIENT_INC(_listener, _client, _x) if (mainconfig.do_snmp) { \
99                                      _client->auth->_x++; }
100
101 #endif
102
103
104 #else
105 #define  RAD_SNMP_INC(_x)
106 #define RAD_SNMP_TYPE_INC(_listener, _x)
107 #define RAD_SNMP_CLIENT_INC(_listener, _client, _x)
108
109 #endif /* WITH_SNMP */
110
111 #endif /* _RADIUS_SNMP_H */