- /* Look for the last frag while inserting the new item in the chain */
- if (item->frag_last)
- last_frag = item->frag_num;
-
- if (iph1->frag_chain == NULL) {
- iph1->frag_chain = item;
- } else {
- struct isakmp_frag_item *current;
- int dup = 0;
-
- current = iph1->frag_chain;
- if (!current->frag_next && current->frag_last) {
- last_frag = current->frag_num;
- }
- while (current->frag_next) {
- if (current->frag_last)
- last_frag = current->frag_num;
- if (current->frag_num == item->frag_num) {
- dup = 1;
- }
- current = current->frag_next;
- }
- // avoid duplicates
- if (!dup) {
- current->frag_next = item;
- } else {
- racoon_free(item);
- vfree(buf);
- item = NULL;
- buf = NULL;
- }
- }
-
- /* If we saw the last frag, check if the chain is complete */
- if (last_frag != 0) {
- for (i = 1; i <= last_frag; i++) {
- item = iph1->frag_chain;
- do {
- if (item->frag_num == i)
- break;
- item = item->frag_next;
- } while (item != NULL);
-
- if (item == NULL) /* Not found */
- break;
- }
-
- if (item != NULL) /* It is complete */
- return 1;
- }
-
- plog(LLV_DEBUG2, LOCATION, NULL,
- "%s: processed %d fragments\n", __FUNCTION__, last_frag);
-
- return 0;