-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.c
More file actions
790 lines (675 loc) · 18.9 KB
/
Copy pathshared.c
File metadata and controls
790 lines (675 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
#include "shared.h"
/** global variables present in both daemon and module **/
int debug = 0; /* doesn't actually do anything right now */
int is_module = 1; /* the daemon sets this to 0 immediately */
int pulse_interval = 15;
int use_database = 0;
merlin_nodeinfo self;
char *binlog_dir = "/opt/monitor/op5/merlin/binlogs";
#ifndef ISSPACE
# define ISSPACE(c) (c == ' ' || c == '\t')
#endif
/*
* XXX Update this when the nodeinfo version changes so users
* know which merlin version to get. It's really only helpful
* from the side with the highest version, but it's the best
* we can do.
*/
const char *nodeinfo_version_string(int version)
{
const char *versions[] = { "v1.0", "v1.2" };
if (version < 0 || version > ARRAY_SIZE(versions))
return "the latest version";
return versions[version];
}
/*
* XXX Update this when protocol version changes.
*/
const char *protocol_version_string(int version)
{
const char *versions[] = { "v1.0", "v1.2" };
if (version < 0 || version > ARRAY_SIZE(versions))
return "the latest version";
return versions[version];
}
char *next_word(char *str)
{
while (!ISSPACE(*str) && *str != 0)
str++;
while (ISSPACE(*str) || *str == ',')
str++;
if (*str)
return str;
return NULL;
}
/*
* Crack a string into several pieces based on the delimiter
*/
strvec *str_explode(char *str, int delim)
{
int i = 0, entries = 1;
char *p;
struct strvec *ret = NULL;
if (!str || !*str)
return NULL;
p = str;
while ((p = strchr(p + 1, delim))) {
entries++;
}
ret = malloc(sizeof(*ret));
ret->entries = entries;
ret->str = malloc(entries * sizeof(char *));
ret->str[i++] = p = str;
while ((p = strchr(p, delim))) {
*p++ = 0;
ret->str[i++] = p;
}
return ret;
}
/*
* "yes", "true", "on" and any non-zero integer makes us return 1
* For every other case, we return 0.
*/
int strtobool(const char *str)
{
int c = tolower(*str);
if (!str || !*str)
return 0;
if (c == 'y' || c == 't' || c == '1')
return 1;
if (c == 'o' && tolower(str[1]) == 'n')
return 1;
return !!atoi(str);
}
/*
* grok second-based intervals, with suffixes.
* "1h 3m 4s" should return 3600 + 180 + 3 = 3783.
* "0.5h 0.5m" should return 1800 + 30 = 1830
* Subsecond precision is not possible (obviously...)
*
* Limited to "week" as its highest possible suffix and
* quite clumsy and forgiving in its parsing. Since we'll
* most likely be dealing with very short strings I don't
* care overly about that though.
*/
int grok_seconds(const char *p, long *result)
{
const char *real_end, suffix[] = "smhdw";
int factors[] = { 1, 60, 3600, 3600 * 24, 3600 * 24 * 7 };
long res = 0;
if (!p)
return -1;
real_end = p + strlen(p);
while (p && *p && p < real_end) {
int factor;
double val;
char *endp, *pos;
/* skip whitespace between one suffix and the next value */
while (*p == ' ' || *p == '\t')
p++;
/* trailing whitespace in *p */
if (!*p) {
*result = res;
return 0;
}
val = strtod(p, &endp);
if (!val && endp == p) {
/* invalid value */
return -1;
}
/* valid value. set p to endp and look for a suffix */
p = endp;
while (*p == ' ' || *p == '\t')
p++;
/* trailing whitespace (again) */
if (!*p) {
res += val;
*result = res;
return 0;
}
/* if there's no suffix we just move on */
pos = strchr(suffix, *p);
if (!pos) {
res += val;
continue;
}
factor = pos - suffix;
val *= factors[factor];
res += val;
while (*p && *p != ' ' && *p != '\t' && (*p < '0' || *p > '9'))
p++;
if (!*p)
break;
}
*result = res;
return 0;
}
/*
* Returns an ISO 8601 formatted date string (YYYY-MM-DD HH:MM:SS.UUU)
* with the desired precision.
* Semi-threadsafe since we round-robin rotate between two buffers for
* the return value
*/
const char *isotime(struct timeval *tv, int precision)
{
static char buffers[2][32];
static int bufi = 0;
struct timeval now;
struct tm tm;
char *buf, *fmt_string;
int bufsize;
size_t len;
bufsize = sizeof(buffers[0]) - 1;
if (!tv) {
gettimeofday(&now, NULL);
tv = &now;
}
buf = buffers[bufi++ % ARRAY_SIZE(buffers)];
localtime_r(&tv->tv_sec, &tm);
switch (precision) {
case ISOTIME_PREC_YEAR:
fmt_string = "%Y";
break;
case ISOTIME_PREC_MONTH:
fmt_string = "%Y-%m";
break;
case ISOTIME_PREC_DAY:
fmt_string = "%F";
break;
case ISOTIME_PREC_HOUR:
fmt_string = "%F %H";
break;
case ISOTIME_PREC_MINUTE:
fmt_string = "%F %H:%M";
break;
case ISOTIME_PREC_SECOND:
case ISOTIME_PREC_USECOND:
default: /* second precision is the default */
fmt_string = "%F %H:%M:%S";
break;
}
len = strftime(buf, bufsize, fmt_string, &tm);
if (precision != ISOTIME_PREC_USECOND)
return buf;
snprintf(&buf[len], bufsize - len, ".%4lu", (unsigned long)tv->tv_usec);
return buf;
}
/*
* converts an arbitrarily long string of data into its
* hexadecimal representation
*/
char *tohex(const unsigned char *data, int len)
{
/* number of bufs must be a power of 2 */
static char bufs[4][41], hex[] = "0123456789abcdef";
static int bufno;
char *buf;
int i;
buf = bufs[bufno & (ARRAY_SIZE(bufs) - 1)];
for (i = 0; i < 20 && i < len; i++) {
unsigned int val = *data++;
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];
}
*buf = '\0';
return bufs[bufno++ & (ARRAY_SIZE(bufs) - 1)];
}
#define CB_ENTRY(s) { NEBCALLBACK_##s##_DATA, #s, sizeof(#s) - 1 }
struct {
int id;
char *name;
uint name_len;
} callback_list[NEBCALLBACK_NUMITEMS] = {
CB_ENTRY(PROCESS),
CB_ENTRY(TIMED_EVENT),
CB_ENTRY(LOG),
CB_ENTRY(SYSTEM_COMMAND),
CB_ENTRY(EVENT_HANDLER),
CB_ENTRY(NOTIFICATION),
CB_ENTRY(SERVICE_CHECK),
CB_ENTRY(HOST_CHECK),
CB_ENTRY(COMMENT),
CB_ENTRY(DOWNTIME),
CB_ENTRY(FLAPPING),
CB_ENTRY(PROGRAM_STATUS),
CB_ENTRY(HOST_STATUS),
CB_ENTRY(SERVICE_STATUS),
CB_ENTRY(ADAPTIVE_PROGRAM),
CB_ENTRY(ADAPTIVE_HOST),
CB_ENTRY(ADAPTIVE_SERVICE),
CB_ENTRY(EXTERNAL_COMMAND),
CB_ENTRY(AGGREGATED_STATUS),
CB_ENTRY(RETENTION),
CB_ENTRY(CONTACT_NOTIFICATION),
CB_ENTRY(CONTACT_NOTIFICATION_METHOD),
CB_ENTRY(ACKNOWLEDGEMENT),
CB_ENTRY(STATE_CHANGE),
CB_ENTRY(CONTACT_STATUS),
CB_ENTRY(ADAPTIVE_CONTACT)
};
const char *callback_name(int id)
{
if (id < 0 || id > NEBCALLBACK_NUMITEMS - 1) {
if (id == NEBCALLBACK_NUMITEMS)
return "CTRL_PACKET";
return "(invalid/unknown)";
}
return callback_list[id].name;
}
int callback_id(const char *orig_name)
{
uint i, len;
char name[100];
if (!orig_name)
return -1;
len = strlen(orig_name);
if (len > sizeof(name))
return -1;
for (i = 0; i < len; i++) {
name[i] = toupper(orig_name[i]);
}
name[i] = '\0';
for (i = 0; i < ARRAY_SIZE(callback_list); i++) {
if (len != callback_list[i].name_len)
continue;
if (!strcmp(callback_list[i].name, name)) {
return callback_list[i].id;
}
}
/* not found */
return -1;
}
#define CTRL_ENTRY(s) "CTRL_"#s
static const char *control_names[] = {
CTRL_ENTRY(NOTHING),
CTRL_ENTRY(PULSE),
CTRL_ENTRY(INACTIVE),
CTRL_ENTRY(ACTIVE),
CTRL_ENTRY(PATHS),
CTRL_ENTRY(STALL),
CTRL_ENTRY(RESUME),
CTRL_ENTRY(STOP),
};
const char *ctrl_name(uint code)
{
if (code >= ARRAY_SIZE(control_names))
return "(invalid/unknown)";
if (code == CTRL_GENERIC)
return "CTRL_GENERIC";
return control_names[code];
}
const char *node_state_name(int state)
{
switch (state) {
case STATE_NONE: return "STATE_NONE";
case STATE_PENDING: return "STATE_PENDING";
case STATE_NEGOTIATING: return "STATE_NEGOTIATING";
case STATE_CONNECTED: return "STATE_CONNECTED";
}
return "STATE_unknown_voodoo";
}
#if (defined(__GLIBC__) && (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1))
#include <execinfo.h>
void bt_scan(const char *mark, int count)
{
#define TRACE_SIZE 100
char **strings;
void *trace[TRACE_SIZE];
int i, bt_count, have_mark = 0;
bt_count = backtrace(trace, TRACE_SIZE);
if (!bt_count)
return;
strings = backtrace_symbols(trace, bt_count);
if (!strings)
return;
for (i = 0; i < bt_count; i++) {
char *paren;
if (mark && !have_mark) {
if (strstr(strings[i], mark))
have_mark = i;
continue;
}
if (mark && count && i >= have_mark + count)
break;
paren = strchr(strings[i], '(');
paren = paren ? paren : strings[i];
ldebug("%2d: %s", i, paren);
}
free(strings);
}
#else
void bt_scan(const char *mark, int count) {}
#endif
static const char *config_key_expires(const char *var)
{
if (!strcmp(var, "ipc_debug_write"))
return "2011-05";
if (!strcmp(var, "ipc_debug_read"))
return "2011-05";
return NULL;
}
/* converts huge values to a more humanfriendly byte-representation */
const char *human_bytes(unsigned long long n)
{
const char *suffix = "KMGTP";
static char tbuf[8][16];
static int t = 0;
unsigned int shift = 1;
t++;
t &= 0x7;
if (n < 1024) {
sprintf(tbuf[t], "%llu bytes", n);
return tbuf[t];
}
while (n >> (shift * 10) > 1024 && shift < sizeof(suffix) - 1)
shift++;
sprintf(tbuf[t], "%0.2f %ciB",
(float)n / (float)(1 << (shift * 10)), suffix[shift - 1]);
return tbuf[t];
}
linked_item *add_linked_item(linked_item *list, void *item)
{
struct linked_item *entry = malloc(sizeof(linked_item));
if (!entry) {
lerr("Failed to malloc(%u): %s", sizeof(linked_item), strerror(errno));
return NULL;
}
entry->item = item;
entry->next_item = list;
return entry;
}
const char *tv_delta(const struct timeval *start, const struct timeval *stop)
{
static char buf[50];
unsigned long weeks, days, hours, mins, secs, usecs;
unsigned long stop_usec;
secs = stop->tv_sec - start->tv_sec;
stop_usec = stop->tv_usec;
if (stop_usec < start->tv_usec) {
secs--;
stop_usec += 1000000;
}
usecs = stop_usec - start->tv_usec;
/* we only want 2 decimals */
while (usecs > 1000)
usecs /= 1000;
weeks = secs / 604800;
secs -= weeks * 604800;
days = secs / 86400;
secs -= days * 86400;
hours = secs / 3600;
secs -= hours * 3600;
mins = secs / 60;
secs -= mins * 60;
if (!mins && !hours && !days) {
sprintf(buf, "%lu.%03lus", secs, usecs);
} else if (!hours && !days) {
sprintf(buf, "%lum %lu.%03lus", mins, secs, usecs);
} else if (!days) {
sprintf(buf, "%luh %lum %lu.%03lus", hours, mins, secs, usecs);
} else if (!weeks){
sprintf(buf, "%lud %luh %lum %lu.%03lus", days, hours, mins, secs, usecs);
} else {
sprintf(buf, "%luw %lud %luh %lum %lu.%03lus",
weeks, days, hours, mins, secs, usecs);
}
return buf;
}
/*
* Parse config sync options.
*
* This is used for each node and also in the daemon compound
*/
int grok_confsync_compound(struct cfg_comp *comp, merlin_confsync *csync)
{
unsigned i;
if (!comp || !csync) {
return -1;
}
/*
* first we reset it. An empty compound in the configuration
* means "reset the defaults and don't bother syncing this
* server automagically"
*/
memset(csync, 0, sizeof(*csync));
for (i = 0; i < comp->vars; i++) {
struct cfg_var *v = comp->vlist[i];
if (!strcmp(v->key, "push")) {
csync->push.cmd = strdup(v->value);
continue;
}
if (!strcmp(v->key, "fetch") || !strcmp(v->key, "pull")) {
csync->fetch.cmd = strdup(v->value);
continue;
}
/*
* we ignore additional variables here, since the
* config sync script may want to add additional
* stuff to handle
*/
}
return 0;
}
static int grok_binlog_var(const char *key, const char *value)
{
if (!strcmp(key, "binlog_dir")) {
binlog_dir = strdup(value);
return 1;
}
return 0;
}
int grok_common_var(struct cfg_comp *config, struct cfg_var *v)
{
const char *expires;
if (!strcmp(v->key, "pulse_interval")) {
pulse_interval = (unsigned)strtoul(v->value, NULL, 10);
if (!pulse_interval) {
cfg_warn(config, v, "Illegal pulse_interval. Using default.");
pulse_interval = 15;
}
return 1;
}
expires = config_key_expires(v->key);
if (expires) {
cfg_warn(config, v, "'%s' is a deprecated variable, scheduled for "
"removal at the first release after %s", v->key, expires);
/* it's understood, in a way */
return 1;
}
if (!prefixcmp(v->key, "ipc_")) {
if (!ipc_grok_var(v->key, v->value))
cfg_error(config, v, "Failed to grok IPC option");
return 1;
}
if (!prefixcmp(v->key, "log_")) {
if (!log_grok_var(v->key, v->value))
cfg_error(config, v, "Failed to grok logging option");
return 1;
}
if (!prefixcmp(v->key, "binlog_")) {
if (!grok_binlog_var(v->key, v->value))
cfg_error(config, v, "Failed to grok binlog option");
return 1;
}
return 0;
}
/*
* Set some common socket options
*/
int merlin_set_socket_options(int sd, int bufsize)
{
/*
* make sure random output from import programs and whatnot
* doesn't carry over into the net_sock
*/
fcntl(sd, F_SETFD, FD_CLOEXEC);
if (bufsize) {
if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(int)) < 0) {
ldebug("Failed to set sendbuffer for %d to %d bytes: %s",
sd, bufsize, strerror(errno));
}
if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(int)) < 0) {
ldebug("Failed to set recvbuffer for %d to %d bytes: %s",
sd, bufsize, strerror(errno));
}
}
return 0;
}
/*
* Handles all the subtleties regarding CTRL_ACTIVE packets,
* which also send a sort of compatibility check along with
* capabilities and attributes about node.
* node is in this case the source, for which we want to set
* the proper info structure. Since CTRL_ACTIVE packets are
* only ever forwarded from daemon to module and from module
* to 'hood', and never from network to 'hood', we know this
* packet originated from the module at 'node'.
*
* Returns 0 if everything is fine and dandy and info is new
* Returns -1 on general muppet errors
* Returns < -1 if node is incompatible with us.
* Returns 1 if node is compatible in word and byte alignment
* but has more features than we do.
* Returns 1 if node is compatible, but info isn't new
* Returns > 1 if node is compatible but lacks features we have
*/
int handle_ctrl_active(merlin_node *node, merlin_event *pkt)
{
merlin_nodeinfo *info;
uint32_t len;
int ret = 0; /* assume ok. we'll flip it if needed */
int version_delta = 0;
if (!node || !pkt)
return -1;
info = (merlin_nodeinfo *)&pkt->body;
len = pkt->hdr.len;
/* if body len is smaller than the least amount of
* data we will check, we're too incompatible to check
* for and report incompatibilities, so just bail out
* with an error
*/
if (len < MERLIN_NODEINFO_MINSIZE) {
lerr("FATAL: %s: incompatible nodeinfo body size %d. Ours is %d. Required: %d",
node->name, len, sizeof(node->info), MERLIN_NODEINFO_MINSIZE);
lerr("FATAL: Completely incompatible");
return -128;
}
/*
* Basic check first, so people know what to expect of the
* comparisons below, but if byte_order differs, so may this.
*/
version_delta = info->version - MERLIN_NODEINFO_VERSION;
if (version_delta) {
lwarn("%s: incompatible nodeinfo version %d. Ours is %d",
node->name, info->version, MERLIN_NODEINFO_VERSION);
lwarn("Further compatibility comparisons may be wrong");
}
/*
* these two checks should never trigger for the daemon
* when node is &ipc unless someone hacks merlin to connect
* to a remote site instead of over the ipc socket.
* It will happen in net-to-net cases where the two systems
* have different wordsize (32-bit vs 64-bit) or byte order
* (big vs little endian, fe)
* If someone wants to jack in conversion functions into
* merlin, the right place to activate them would be here,
* setting them as in_handler(pkt) for the node in question
* (no out_handler() is needed, since the receiving end will
* transform the packet itself).
*/
if (info->word_size != COMPAT_WORDSIZE) {
lerr("FATAL: %s: incompatible wordsize %d. Ours is %d",
node->name, info->word_size, COMPAT_WORDSIZE);
ret -= 4;
}
if (info->byte_order != endianness()) {
lerr("FATAL: %s: incompatible byte order %d. Ours is %d",
node->name, info->byte_order, endianness());
ret -= 8;
}
/*
* this could potentially happen if someone forgets to
* restart either Nagios or Merlin after upgrading either
* or both to a newer version and the object structure
* version has been bumped. It's quite unlikely though,
* but since CTRL_ACTIVE packets are so uncommon we can
* afford to waste the extra cycles.
*/
if (info->object_structure_version != CURRENT_OBJECT_STRUCTURE_VERSION) {
lerr("FATAL: %s: incompatible object structure version %d. Ours is %d",
node->name, info->object_structure_version, CURRENT_OBJECT_STRUCTURE_VERSION);
ret -= 16;
}
/*
* If the remote end has a newer info_version we can be reasonably
* sure that everything we want from it is present
*/
if (!ret) {
if (version_delta > 0 && len > sizeof(node->info)) {
/*
* version is greater and struct is bigger. Everything we
* need is almost certainly present in that struct
*/
lwarn("WARNING: Possible compatibility issues with '%s'", node->name);
lwarn(" - '%s' nodeinfo version %d; nodeinfo size %d.",
node->name, node->info.version, len);
lwarn(" - we have nodeinfo version %d; nodeinfo size %d.",
self.version, sizeof(self));
lwarn(" - upgrading Merlin (on this server) to %s should fix things",
nodeinfo_version_string(node->info.version));
len = sizeof(node->info);
} else if (version_delta < 0 && len < sizeof(node->info)) {
/*
* version is less, and struct is smaller. Update this
* place with warnings about what won't work when we
* add new things to the info struct, and ignore copying
* anything right now
*/
lwarn("WARNING: '%s' needs to be updated to at least version %s",
node->name, nodeinfo_version_string(self.version));
ret -= 2;
} else if (version_delta && len != sizeof(node->info)) {
/*
* version is greater and struct is smaller, or
* version is lesser and struct is bigger. Either way,
* this should never happen
*/
lerr("FATAL: %s: impossible info_version / sizeof(nodeinfo_version) combo",
node->name);
lerr("FATAL: %s: %d / %d; We: %d / %d",
node->name, len, info->version, sizeof(node->info), MERLIN_NODEINFO_VERSION);
ret -= 32;
}
}
if (ret < 0) {
lerr("FATAL: %s; incompatibility code %d. Ignoring CTRL_ACTIVE event",
node->name, ret);
memset(&node->info, 0, sizeof(node->info));
return ret;
}
/* everything seems ok, so handle it properly */
/* if info isn't new, we return 1 */
if (!memcmp(&node->info, pkt->body, len)) {
ldebug("%s re-sent identical CTRL_ACTIVE info", node->name);
return 1;
}
/*
* otherwise update the node's info and
* print some debug logging.
*/
memcpy(&node->info, pkt->body, len);
ldebug("Received CTRL_ACTIVE from %s", node->name);
ldebug(" version: %u", info->version);
ldebug(" word_size: %u", info->word_size);
ldebug(" byte_order: %u", info->byte_order);
ldebug("object struct: %u", info->object_structure_version);
ldebug(" start time: %lu.%lu",
info->start.tv_sec, info->start.tv_usec);
ldebug(" config hash: %s", tohex(info->config_hash, 20));
ldebug(" config mtime: %lu", info->last_cfg_change);
ldebug(" peer id: %u", node->peer_id);
ldebug(" self peer id: %u", info->peer_id);
ldebug(" active peers: %u", info->active_peers);
ldebug(" confed peers: %u", info->configured_peers);
return 0;
}