2 * Unix SMB/CIFS implementation.
3 * store smbd profiling information in shared memory
4 * Copyright (C) Andrew Tridgell 1999
5 * Copyright (C) James Peach 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <gnutls/gnutls.h>
24 #include <gnutls/crypto.h>
25 #include "lib/crypto/gnutls_helpers.h"
26 #include "lib/util/byteorder.h"
27 #include "source3/include/smbprofile.h"
29 void smbprofile_stats_accumulate(struct profile_stats
*acc
,
30 const struct profile_stats
*add
)
32 #define SMBPROFILE_STATS_START
33 #define SMBPROFILE_STATS_SECTION_START(name, display)
34 #define SMBPROFILE_STATS_COUNT(name) \
36 acc->values.name##_stats.count += \
37 add->values.name##_stats.count; \
39 #define SMBPROFILE_STATS_TIME(name) \
41 acc->values.name##_stats.time += \
42 add->values.name##_stats.time; \
44 #define SMBPROFILE_STATS_BASIC(name) \
46 acc->values.name##_stats.count += \
47 add->values.name##_stats.count; \
48 acc->values.name##_stats.time += \
49 add->values.name##_stats.time; \
51 #define SMBPROFILE_STATS_BYTES(name) \
53 acc->values.name##_stats.count += \
54 add->values.name##_stats.count; \
55 acc->values.name##_stats.time += \
56 add->values.name##_stats.time; \
57 acc->values.name##_stats.idle += \
58 add->values.name##_stats.idle; \
59 acc->values.name##_stats.bytes += \
60 add->values.name##_stats.bytes; \
62 #define SMBPROFILE_STATS_IOBYTES(name) \
64 acc->values.name##_stats.count += \
65 add->values.name##_stats.count; \
66 acc->values.name##_stats.time += \
67 add->values.name##_stats.time; \
68 acc->values.name##_stats.idle += \
69 add->values.name##_stats.idle; \
70 acc->values.name##_stats.inbytes += \
71 add->values.name##_stats.inbytes; \
72 acc->values.name##_stats.outbytes += \
73 add->values.name##_stats.outbytes; \
75 #define SMBPROFILE_STATS_SECTION_END
76 #define SMBPROFILE_STATS_END
77 SMBPROFILE_STATS_ALL_SECTIONS
78 #undef SMBPROFILE_STATS_START
79 #undef SMBPROFILE_STATS_SECTION_START
80 #undef SMBPROFILE_STATS_COUNT
81 #undef SMBPROFILE_STATS_TIME
82 #undef SMBPROFILE_STATS_BASIC
83 #undef SMBPROFILE_STATS_BYTES
84 #undef SMBPROFILE_STATS_IOBYTES
85 #undef SMBPROFILE_STATS_SECTION_END
86 #undef SMBPROFILE_STATS_END
89 int smbprofile_magic(const struct profile_stats
*stats
, uint64_t *_magic
)
91 uint8_t digest
[gnutls_hash_get_len(GNUTLS_DIG_SHA1
)];
92 gnutls_hash_hd_t hash_hnd
= NULL
;
95 GNUTLS_FIPS140_SET_LAX_MODE();
97 rc
= gnutls_hash_init(&hash_hnd
, GNUTLS_DIG_SHA1
);
101 rc
= gnutls_hash(hash_hnd
, stats
, sizeof(*stats
));
103 #define __UPDATE(str) \
105 rc |= gnutls_hash(hash_hnd, str, strlen(str)); \
107 #define SMBPROFILE_STATS_START
108 #define SMBPROFILE_STATS_SECTION_START(name, display) \
110 __UPDATE(#name "+" #display); \
112 #define SMBPROFILE_STATS_COUNT(name) \
114 __UPDATE(#name "+count"); \
116 #define SMBPROFILE_STATS_TIME(name) \
118 __UPDATE(#name "+time"); \
120 #define SMBPROFILE_STATS_BASIC(name) \
122 __UPDATE(#name "+count"); \
123 __UPDATE(#name "+time"); \
125 #define SMBPROFILE_STATS_BYTES(name) \
127 __UPDATE(#name "+count"); \
128 __UPDATE(#name "+time"); \
129 __UPDATE(#name "+idle"); \
130 __UPDATE(#name "+bytes"); \
132 #define SMBPROFILE_STATS_IOBYTES(name) \
134 __UPDATE(#name "+count"); \
135 __UPDATE(#name "+time"); \
136 __UPDATE(#name "+idle"); \
137 __UPDATE(#name "+inbytes"); \
138 __UPDATE(#name "+outbytes"); \
140 #define SMBPROFILE_STATS_SECTION_END
141 #define SMBPROFILE_STATS_END
142 SMBPROFILE_STATS_ALL_SECTIONS
144 #undef SMBPROFILE_STATS_START
145 #undef SMBPROFILE_STATS_SECTION_START
146 #undef SMBPROFILE_STATS_COUNT
147 #undef SMBPROFILE_STATS_TIME
148 #undef SMBPROFILE_STATS_BASIC
149 #undef SMBPROFILE_STATS_BYTES
150 #undef SMBPROFILE_STATS_IOBYTES
151 #undef SMBPROFILE_STATS_SECTION_END
152 #undef SMBPROFILE_STATS_END
154 gnutls_hash_deinit(hash_hnd
, NULL
);
158 gnutls_hash_deinit(hash_hnd
, digest
);
160 GNUTLS_FIPS140_SET_STRICT_MODE();
163 uint64_t magic
= PULL_LE_U64(digest
, 0);
165 magic
= PULL_LE_U64(digest
, 0);
173 static int smbprofile_collect_fn(struct tdb_context
*tdb
,
178 struct profile_stats
*acc
= (struct profile_stats
*)private_data
;
179 const struct profile_stats
*v
;
181 if (value
.dsize
!= sizeof(struct profile_stats
)) {
185 v
= (const struct profile_stats
*)value
.dptr
;
187 if (v
->magic
!= acc
->magic
) {
191 smbprofile_stats_accumulate(acc
, v
);
195 void smbprofile_collect_tdb(struct tdb_context
*tdb
,
197 struct profile_stats
*stats
)
199 *stats
= (struct profile_stats
){.magic
= magic
};
201 tdb_traverse_read(tdb
, smbprofile_collect_fn
, stats
);