/* copy record */ int lnf_rec_copy(lnf_rec_t *dst, lnf_rec_t *src) { if (dst == NULL || src == NULL) { return LNF_ERR_OTHER; } memcpy(dst->master_record, src->master_record, sizeof(master_record_t)); if ( bit_array_copy(dst->extensions_arr, src->extensions_arr)) { return LNF_OK; } else { return LNF_ERR_OTHER; } }
extension_map_t * lnf_lookup_map(lnf_file_t *lnf_file, bit_array_t *ext ) { extension_map_t *map; lnf_map_list_t *map_list; int i = 0; int is_set = 0; int id = 0; int map_id = 0; // find whether the template already exist map_id = 0; map_list = lnf_file->lnf_map_list; if (map_list == NULL) { // first map map_list = malloc(sizeof(lnf_map_list_t)); if (map_list == NULL) { return NULL; } lnf_file->lnf_map_list = map_list; } else { if (bit_array_cmp(&(map_list->bit_array), ext) == 0) { return map_list->map; } map_id++; while (map_list->next != NULL ) { if (bit_array_cmp(&(map_list->bit_array), ext) == 0) { return map_list->map; } else { map_id++; map_list = map_list->next; } } map_list->next = malloc(sizeof(lnf_map_list_t)); if (map_list->next == NULL) { return NULL; } map_list = map_list->next; } // allocate memory potentially for all extensions map = malloc(sizeof(extension_map_t) + (lnf_file->max_num_extensions + 1) * sizeof(uint16_t)); if (map == NULL) { return NULL; } map_list->map = map; map_list->next = NULL; bit_array_init(&map_list->bit_array, lnf_file->max_num_extensions + 1); bit_array_copy(&map_list->bit_array, ext); map->type = ExtensionMapType; map->map_id = map_id; // set extension map according the bits set in ext structure id = 0; i = 0; while ( (is_set = bit_array_get(ext, id)) != -1 ) { // fprintf(stderr, "i: %d, bit %d, val: %d\n", i, id, is_set); if (is_set) map->ex_id[i++] = id; id++; } map->ex_id[i++] = 0; // determine size and align 32bits map->size = sizeof(extension_map_t) + ( i - 1 ) * sizeof(uint16_t); if (( map->size & 0x3 ) != 0 ) { map->size += (4 - ( map->size & 0x3 )); } map->extension_size = 0; i=0; while (map->ex_id[i]) { int id = map->ex_id[i]; map->extension_size += extension_descriptor[id].size; i++; } //Insert_Extension_Map(&instance->extension_map_list, map); Insert_Extension_Map(lnf_file->extension_map_list, map); AppendToBuffer(lnf_file->nffile, (void *)map, map->size); return map; }
//note: file descriptors in dst will/must be closed, FD in src will be changed to NUL. int copy_peer(struct peer_profile_t* dst, struct peer_profile_t* src) { if(dst == NULL || src == NULL) { ERROR(0, "copy_peer: dst or src is NULL"); return -1; } if(dst->peeraddr == NULL || src->peeraddr == NULL) { ERROR(0, "copy_peer: dst->peeraddr or src->peeraddr is NULL"); return -1; } if(dst->pkt_index_array_pre == NULL || src->pkt_index_array_pre == NULL) { ERROR(0, "copy_peer: dst->pkt_index_array_pre or src->pkt_index_array_pre is NULL"); return -1; } if(dst->pkt_index_array_now == NULL || src->pkt_index_array_now == NULL) { ERROR(0, "copy_peer: dst->pkt_index_array_now or src->pkt_index_array_now is NULL"); return -1; } if(dst->timerfd_info == NULL || src->timerfd_info == NULL) { ERROR(0, "copy_peer: dst->timerfd_info or src->timerfd_info is NULL"); return -1; } if(dst->timerfd_info->ack_array_pre == NULL || src->timerfd_info->ack_array_pre == NULL) { ERROR(0, "copy_peer: dst->ack_array_pre or src->ack_array_pre is NULL"); return -1; } if(dst->timerfd_info->ack_array_now == NULL || src->timerfd_info->ack_array_now == NULL) { ERROR(0, "copy_peer: dst->ack_array_now or src->ack_array_now is NULL"); return -1; } if(dst->flow_src == NULL || src->flow_src == NULL) { ERROR(0, "copy_peer: dst->flow_src or src->flow_src is NULL"); return -1; } dst->id = src->id; dst->valid = src->valid; dst->discard = src->discard; dst->restricted = src->restricted; dst->dup = src->dup; dst->srtt = src->srtt; dst->total_pkt_cnt = src->total_pkt_cnt; dst->local_seq = src->local_seq; dst->involve_cnt = src->involve_cnt; dst->port = src->port; dst->vip = src->vip; dst->rip = src->rip; memcpy(dst->psk, src->psk, 2*AES_TEXT_LEN); memcpy(dst->peeraddr, src->peeraddr, sizeof(struct sockaddr_in)); uint32_t * index_array_tmp; index_array_tmp = dst->pkt_index_array_pre; dst->pkt_index_array_pre = src->pkt_index_array_pre; src->pkt_index_array_pre = index_array_tmp; index_array_tmp = dst->pkt_index_array_now; dst->pkt_index_array_now = src->pkt_index_array_now; src->pkt_index_array_now = index_array_tmp; dst->timerfd_info->time_pre = src->timerfd_info->time_pre; dst->timerfd_info->time_now = src->timerfd_info->time_now; struct ack_info_t * timerfd_tmp; timerfd_tmp = dst->timerfd_info->ack_array_pre; dst->timerfd_info->ack_array_pre = src->timerfd_info->ack_array_pre; src->timerfd_info->ack_array_pre = timerfd_tmp; timerfd_tmp = dst->timerfd_info->ack_array_now; dst->timerfd_info->ack_array_now = src->timerfd_info->ack_array_now; src->timerfd_info->ack_array_now = timerfd_tmp; //FD in src must be changed to NUL, to avoid close in accident. close_all_timerfd(src->timerfd_info->ack_array_pre, (SEQ_LEVEL_1+1)); close_all_timerfd(src->timerfd_info->ack_array_now, (SEQ_LEVEL_1+1)); dst->flow_src->time_pre = src->flow_src->time_pre; dst->flow_src->time_now = src->flow_src->time_now; dst->flow_src->dup_cnt = src->flow_src->dup_cnt; dst->flow_src->delay_cnt = src->flow_src->delay_cnt; dst->flow_src->replay_cnt = src->flow_src->replay_cnt; dst->flow_src->jump_cnt = src->flow_src->jump_cnt; dst->flow_src->time_min = src->flow_src->time_min; dst->flow_src->time_max = src->flow_src->time_max; bit_array_copy(dst->flow_src->ba_pre, src->flow_src->ba_pre); bit_array_copy(dst->flow_src->ba_now, src->flow_src->ba_now); return 0; }