Go to the documentation of this file.
51 #define SEQ_UNSEEN ((time_t)0)
52 #define SEQ_EXPIRED ((time_t)1)
55 static void packet_id_debug_print(
int msglevel,
73 packet_id_debug_print(msglevel, p, pin, message, value);
81 dmsg(
D_PID_DEBUG,
"PID packet_id_init seq_backtrack=%d time_backtrack=%d",
115 const time_t local_now =
now;
138 while (p->
id < pin->
id
139 #ifdef PID_SIMULATE_BACKTRACK
148 diff = p->
id - pin->
id;
170 const time_t local_now =
now;
231 diff = p->
id - pin->
id;
280 return !p->
id || pin->
id == p->
id + 1;
307 if (!
buf_read(buf, &net_id,
sizeof(net_id)))
314 if (!
buf_read(buf, &net_time,
sizeof(net_time)))
335 if (!long_form || now <= p->time)
373 if (!
buf_write(buf, &net_id,
sizeof(net_id)))
379 if (!
buf_write(buf, &net_time,
sizeof(net_time)))
394 if (print_timestamp && pin->
time)
443 "Cannot open --replay-persist file %s for read/write",
451 #if defined(HAVE_FLOCK) && defined(LOCK_EX) && defined(LOCK_NB)
452 if (flock(p->
fd, LOCK_EX | LOCK_NB))
454 msg(
M_ERR,
"Cannot obtain exclusive lock on --replay-persist file %s", filename);
459 n =
read(p->
fd, &image,
sizeof(image));
460 if (n ==
sizeof(image))
470 "Read error on --replay-persist file %s",
492 seek_ret = lseek(p->
fd, (off_t)0, SEEK_SET);
493 if (seek_ret == (off_t)0)
495 n =
write(p->
fd, &image,
sizeof(image));
496 if (n ==
sizeof(image))
506 "Cannot write to --replay-persist file %s",
513 "Cannot seek to beginning of --replay-persist file %s",
550 return (
char *)out.
data;
556 packet_id_debug_print(
int msglevel,
565 const time_t prev_now =
now;
566 const struct seq_list *sl = p->
seq_list;
570 gettimeofday(&tv, NULL);
574 for (i = 0; sl != NULL && i < sl->x_size; ++i)
591 diff = (int) prev_now - v;
615 (
int)(prev_now - tv.tv_sec));
633 msg(msglevel,
"%s",
BSTR(&out));
static bool buf_read(struct buffer *src, void *dest, int size)
static struct gc_arena gc_new(void)
static void packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin, const char *message, int value)
void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *name, int unit)
#define MAX_SEQ_BACKTRACK
void packet_id_persist_load(struct packet_id_persist *p, const char *filename)
static bool packet_id_persist_enabled(const struct packet_id_persist *p)
void packet_id_reap(struct packet_id_rec *p)
long int get_random(void)
#define MAX_TIME_BACKTRACK
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
#define D_PID_DEBUG_MEDIUM
bool packet_id_test(struct packet_id_rec *p, const struct packet_id_net *pin)
#define CIRC_LIST_PUSH(obj, item)
void packet_id_persist_save(struct packet_id_persist *p)
static bool packet_id_send_update(struct packet_id_send *p, bool long_form)
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
void packet_id_persist_init(struct packet_id_persist *p)
bool packet_id_read(struct packet_id_net *pin, struct buffer *buf, bool long_form)
#define CIRC_LIST_ALLOC(dest, list_type, size)
void packet_id_add(struct packet_id_rec *p, const struct packet_id_net *pin)
Wrapper structure for dynamically allocated memory.
const char * packet_id_net_print(const struct packet_id_net *pin, bool print_timestamp, struct gc_arena *gc)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
unsigned int packet_id_print_type
Garbage collection arena used to keep track of dynamically allocated memory.
bool packet_id_write(struct packet_id_send *p, struct buffer *buf, bool long_form, bool prepend)
Write a packet ID to buf, and update the packet ID state.
#define MIN_TIME_BACKTRACK
static bool check_debug_level(unsigned int level)
const char * packet_id_persist_print(const struct packet_id_persist *p, struct gc_arena *gc)
packet_id_type id_last_written
void packet_id_persist_load_obj(const struct packet_id_persist *p, struct packet_id *pid)
static void gc_free(struct gc_arena *a)
#define CIRC_LIST_ITEM(obj, index)
#define CIRC_LIST_RESET(obj)
const char * time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
#define MIN_SEQ_BACKTRACK
#define CIRC_LIST_SIZE(obj)
void packet_id_free(struct packet_id *p)
void packet_id_persist_close(struct packet_id_persist *p)
bool buf_printf(struct buffer *buf, const char *format,...)
struct seq_list * seq_list
uint8_t * data
Pointer to the allocated memory.
#define D_PID_PERSIST_DEBUG