void nethdr_track_update_seq(uint32_t seq) { if (!local_seq_set) local_seq_set = 1; STATE_SYNC(last_seq_recv) = seq; }
/* this function only tracks, it does not update the last sequence received */ int nethdr_track_seq(uint32_t seq, uint32_t *exp_seq) { int ret = SEQ_UNKNOWN; /* netlink sequence tracking initialization */ if (!local_seq_set) { ret = SEQ_UNSET; goto out; } /* fast path: we received the correct sequence */ if (seq == STATE_SYNC(last_seq_recv)+1) { ret = SEQ_IN_SYNC; goto out; } /* out of sequence: some messages got lost */ if (after(seq, STATE_SYNC(last_seq_recv)+1)) { STATE_SYNC(error).msg_rcv_lost += seq - STATE_SYNC(last_seq_recv) + 1; ret = SEQ_AFTER; goto out; } /* out of sequence: replayed/delayed packet? */ if (before(seq, STATE_SYNC(last_seq_recv)+1)) { STATE_SYNC(error).msg_rcv_before++; ret = SEQ_BEFORE; } out: *exp_seq = STATE_SYNC(last_seq_recv)+1; return ret; }
static int external_cache_init(void) { external = cache_create("external", STATE_SYNC(sync)->external_cache_flags, NULL); if (external == NULL) { dlog(LOG_ERR, "can't allocate memory for the external cache"); return -1; } return 0; }
int cache_add(struct cache *c, struct cache_object *obj, int id) { int ret; obj->owner = STATE_SYNC(channel)->current; ret = __add(c, obj, id); if (ret == -1) { c->stats.add_fail++; if (errno == ENOSPC) c->stats.add_fail_enospc++; return -1; } c->stats.add_ok++; return 0; }
void cache_update(struct cache *c, struct cache_object *obj, int id, void *ptr) { char *data = obj->data; unsigned int i; c->ops->copy(obj->ptr, ptr, NFCT_CP_META); for (i = 0; i < c->num_features; i++) { c->features[i]->update(obj, data); data += c->features[i]->size; } if (c->extra && c->extra->update) c->extra->update(obj, ((char *) obj) + c->extra_offset); c->stats.upd_ok++; obj->lastupdate = time_cached(); obj->status = C_OBJ_ALIVE; obj->owner = STATE_SYNC(channel)->current; }
void cache_commit(struct cache *c, struct nfct_handle *h, int clientfd) { unsigned int commit_ok, commit_fail; struct __commit_container tmp = { .h = h, .c = c, }; struct timeval commit_stop, res; switch(STATE_SYNC(commit).state) { case COMMIT_STATE_INACTIVE: gettimeofday(&STATE_SYNC(commit).stats.start, NULL); STATE_SYNC(commit).stats.ok = c->stats.commit_ok; STATE_SYNC(commit).stats.fail = c->stats.commit_fail; STATE_SYNC(commit).clientfd = clientfd; case COMMIT_STATE_MASTER: STATE_SYNC(commit).current = hashtable_iterate_limit(c->h, &tmp, STATE_SYNC(commit).current, CONFIG(general).commit_steps, do_commit_master); if (STATE_SYNC(commit).current < CONFIG(hashsize)) { STATE_SYNC(commit).state = COMMIT_STATE_MASTER; /* give it another step as soon as possible */ write_evfd(STATE_SYNC(commit).evfd); return; } STATE_SYNC(commit).current = 0; STATE_SYNC(commit).state = COMMIT_STATE_RELATED; case COMMIT_STATE_RELATED: STATE_SYNC(commit).current = hashtable_iterate_limit(c->h, &tmp, STATE_SYNC(commit).current, CONFIG(general).commit_steps, do_commit_related); if (STATE_SYNC(commit).current < CONFIG(hashsize)) { STATE_SYNC(commit).state = COMMIT_STATE_RELATED; /* give it another step as soon as possible */ write_evfd(STATE_SYNC(commit).evfd); return; } /* calculate the time that commit has taken */ gettimeofday(&commit_stop, NULL); timersub(&commit_stop, &STATE_SYNC(commit).stats.start, &res); /* calculate new entries committed */ commit_ok = c->stats.commit_ok - STATE_SYNC(commit).stats.ok; commit_fail = c->stats.commit_fail - STATE_SYNC(commit).stats.fail; /* log results */ dlog(LOG_NOTICE, "Committed %u new entries", commit_ok); if (commit_fail) dlog(LOG_NOTICE, "%u entries can't be " "committed", commit_fail); dlog(LOG_NOTICE, "commit has taken %lu.%06lu seconds", res.tv_sec, res.tv_usec); /* prepare the state machine for new commits */ STATE_SYNC(commit).current = 0; STATE_SYNC(commit).state = COMMIT_STATE_INACTIVE; /* Close the client socket now that we're done. */ close(STATE_SYNC(commit).clientfd); } }