Add "extern C {...} to header files for C++ builds.
[freeradius.git] / src / include / stats.h
index 1b067a5..a781eb7 100644 (file)
 #include <freeradius-devel/ident.h>
 RCSIDH(stats_h, "$Id$")
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifdef WITH_STATS_64BIT
 typedef uint64_t fr_uint_t;
 #else
@@ -48,30 +52,61 @@ typedef struct fr_stats_t {
        fr_uint_t               total_unknown_types;
 } fr_stats_t;
 
-/*
- *  Taken from RFC 2619 and RFC 2621
- */
-typedef struct fr_client_stats_t {
-       /* IP address */
-       /* Client ID (string ) */
-       fr_uint_t               requests;
-       fr_uint_t       dup_requests;
-       fr_uint_t       responses;
-       fr_uint_t       accepts;
-       fr_uint_t       rejects;
-       fr_uint_t       challenges;
-       fr_uint_t       malformed_requests;
-       fr_uint_t       bad_authenticators;
-       fr_uint_t       packets_dropped;
-       fr_uint_t       unknown_types;
-} fr_client_stats_t;
+typedef struct fr_stats_ema_t {
+       int             window;
+
+       int             f1, f10;
+       int             ema1, ema10;
 
+} fr_stats_ema_t;
 
+extern fr_stats_t      radius_auth_stats;
+extern fr_stats_t      radius_acct_stats;
+#ifdef WITH_PROXY
+extern fr_stats_t      proxy_auth_stats;
+extern fr_stats_t      proxy_acct_stats;
+#endif
+
+void radius_stats_init(int flag);
 void request_stats_final(REQUEST *request);
+void request_stats_reply(REQUEST *request);
+void radius_stats_ema(fr_stats_ema_t *ema,
+                     struct timeval *start, struct timeval *end);
 
+#define RAD_STATS_INC(_x) _x++
+#ifdef WITH_ACCOUNTING
+#define RAD_STATS_TYPE_INC(_listener, _x) if (_listener->type == RAD_LISTEN_AUTH) { \
+                                       radius_auth_stats._x++; \
+                                    } else if (_listener->type == RAD_LISTEN_ACCT) { \
+                                       radius_acct_stats._x++; } \
+                                      _listener->stats._x++
 
-#else
+#define RAD_STATS_CLIENT_INC(_listener, _client, _x) if (_listener->type == RAD_LISTEN_AUTH) \
+                                       _client->auth->_x++; \
+                                    else if (_listener->type == RAD_LISTEN_ACCT) \
+                                       _client->acct->_x++
+
+#else  /* WITH_ACCOUNTING */
+
+#define RAD_STATS_TYPE_INC(_listener, _x) { radius_auth_stats._x++; _listener->stats._x++; }
+
+#define RAD_STATS_CLIENT_INC(_listener, _client, _x) _client->auth->_x++
+
+#endif /* WITH_ACCOUNTING */
+
+
+#else  /* WITH_STATS */
+#define request_stats_init(_x)
 #define request_stats_final(_x)
+
+#define  RAD_STATS_INC(_x)
+#define RAD_STATS_TYPE_INC(_listener, _x)
+#define RAD_STATS_CLIENT_INC(_listener, _client, _x)
+
+#endif
+
+#ifdef __cplusplus
+}
 #endif
 
 #endif /* FR_STATS_H */