53#define SEQ_UNSEEN ((time_t)0)
54#define SEQ_EXPIRED ((time_t)1)
57static void packet_id_debug_print(
int msglevel,
75 packet_id_debug_print(msglevel, p, pin, message, value);
98 dmsg(
D_PID_DEBUG,
"PID packet_id_init seq_backtrack=%d time_backtrack=%d",
140 const time_t local_now =
now;
163 while (p->
id < pin->
id
164#ifdef PID_SIMULATE_BACKTRACK
173 diff = p->
id - pin->
id;
195 const time_t local_now =
now;
255 diff = p->
id - pin->
id;
304 return !p->
id || pin->
id == p->
id + 1;
331 if (!
buf_read(buf, &net_id,
sizeof(net_id)))
338 if (!
buf_read(buf, &net_time,
sizeof(net_time)))
359 if (!long_form || now <= p->time)
412 if (!
buf_write(buf, &net_id,
sizeof(net_id)))
418 if (!
buf_write(buf, &net_time,
sizeof(net_time)))
450 p->time =
p->time_last_written = 0;
451 p->id =
p->id_last_written = 0;
482 "Cannot open --replay-persist file %s for read/write",
490#if defined(HAVE_FLOCK) && defined(LOCK_EX) && defined(LOCK_NB)
491 if (flock(p->
fd, LOCK_EX | LOCK_NB))
493 msg(
M_ERR,
"Cannot obtain exclusive lock on --replay-persist file %s", filename);
498 n =
read(p->
fd, &image,
sizeof(image));
499 if (n ==
sizeof(image))
509 "Read error on --replay-persist file %s",
531 seek_ret = lseek(p->
fd, (off_t)0, SEEK_SET);
532 if (seek_ret == (off_t)0)
534 n =
write(p->
fd, &image,
sizeof(image));
535 if (n ==
sizeof(image))
545 "Cannot write to --replay-persist file %s",
552 "Cannot seek to beginning of --replay-persist file %s",
589 return (
char *)out.
data;
604 const time_t prev_now =
now;
605 const struct seq_list *sl = p->
seq_list;
609 gettimeofday(&tv, NULL);
613 for (i = 0; sl != NULL && i < sl->x_size; ++i)
630 diff = (int)(prev_now - v);
637 c = (char)(
'0' + diff);
654 (
int)(prev_now - tv.tv_sec));
656 buf_printf(&out,
" r=[%d,%" PRIu64
",%d,%" PRIu64
",%d]",
672 msg(msglevel,
"%s",
BSTR(&out));
689 uint16_t epoch =
id >> 48;
706 uint64_t net_id = ((uint64_t) epoch) << 48 | p->
id;
712 return buf_write(buf, &net_id,
sizeof(net_id));
bool buf_printf(struct buffer *buf, const char *format,...)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
static bool buf_read(struct buffer *src, void *dest, int size)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
static void gc_free(struct gc_arena *a)
static struct gc_arena gc_new(void)
#define CIRC_LIST_ALLOC(dest, list_type, size)
#define CIRC_LIST_PUSH(obj, item)
#define CIRC_LIST_ITEM(obj, index)
#define CIRC_LIST_RESET(obj)
#define CIRC_LIST_SIZE(obj)
long int get_random(void)
#define D_PID_DEBUG_MEDIUM
#define D_PID_PERSIST_DEBUG
static bool check_debug_level(unsigned int level)
const char * time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc)
static void packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin, const char *message, uint64_t value)
static void packet_id_init_recv(struct packet_id_rec *rec, int seq_backtrack, int time_backtrack, const char *name, int unit)
void packet_id_persist_save(struct packet_id_persist *p)
const char * packet_id_persist_print(const struct packet_id_persist *p, struct gc_arena *gc)
void packet_id_persist_load_obj(const struct packet_id_persist *p, struct packet_id *pid)
void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *name, int unit)
void packet_id_persist_close(struct packet_id_persist *p)
void packet_id_free(struct packet_id *p)
static bool packet_id_send_update_epoch(struct packet_id_send *p)
bool packet_id_test(struct packet_id_rec *p, const struct packet_id_net *pin)
bool packet_id_read(struct packet_id_net *pin, struct buffer *buf, bool long_form)
static bool packet_id_send_update(struct packet_id_send *p, bool long_form)
void packet_id_move_recv(struct packet_id_rec *dest, struct packet_id_rec *src)
Move the packet id recv structure from src to dest.
void packet_id_reap(struct packet_id_rec *p)
const char * packet_id_net_print(const struct packet_id_net *pin, bool print_timestamp, struct gc_arena *gc)
void packet_id_add(struct packet_id_rec *p, const struct packet_id_net *pin)
void packet_id_persist_load(struct packet_id_persist *p, const char *filename)
void packet_id_persist_init(struct packet_id_persist *p)
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.
static bool packet_id_persist_enabled(const struct packet_id_persist *p)
uint64_t packet_id_print_type
#define MAX_SEQ_BACKTRACK
bool packet_id_write_epoch(struct packet_id_send *p, uint16_t epoch, struct buffer *buf)
Writes the packet ID containing both the epoch and the packet id to the buffer specified by buf.
uint16_t packet_id_read_epoch(struct packet_id_net *p, struct buffer *buf)
Reads the packet ID containing both the epoch and the per-epoch counter from the buf.
#define MIN_SEQ_BACKTRACK
#define MAX_TIME_BACKTRACK
#define MIN_TIME_BACKTRACK
#define PACKET_ID_EPOCH_MAX
#define PACKET_ID_MASK
Mask of the bits that contain the 48-bit of the per-epoch packet counter in the packet id.
Wrapper structure for dynamically allocated memory.
uint8_t * data
Pointer to the allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
Data structure for describing the packet id that is received/send to the network.
packet_id_type id_last_written
uint64_t max_backtrack_stat
struct seq_list * seq_list