From owner-p4-projects@FreeBSD.ORG Thu Jul 26 22:54:10 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6E52016A421; Thu, 26 Jul 2007 22:54:10 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 211A916A417 for ; Thu, 26 Jul 2007 22:54:10 +0000 (UTC) (envelope-from mharvan@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 121A713C49D for ; Thu, 26 Jul 2007 22:54:10 +0000 (UTC) (envelope-from mharvan@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l6QMs9ic080478 for ; Thu, 26 Jul 2007 22:54:09 GMT (envelope-from mharvan@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l6QMs9av080475 for perforce@freebsd.org; Thu, 26 Jul 2007 22:54:09 GMT (envelope-from mharvan@FreeBSD.org) Date: Thu, 26 Jul 2007 22:54:09 GMT Message-Id: <200707262254.l6QMs9av080475@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to mharvan@FreeBSD.org using -f From: Matus Harvan To: Perforce Change Reviews Cc: Subject: PERFORCE change 124140 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jul 2007 22:54:10 -0000 http://perforce.freebsd.org/chv.cgi?CH=124140 Change 124140 by mharvan@mharvan_twoflower on 2007/07/26 22:53:22 replaced my own linked list for fragment reassembly with queue(3) macros - segfaults fixed;) Affected files ... .. //depot/projects/soc2007/mharvan-mtund/mtund.src/tunneld.c#11 edit .. //depot/projects/soc2007/mharvan-mtund/mtund.src/tunneld.h#6 edit Differences ... ==== //depot/projects/soc2007/mharvan-mtund/mtund.src/tunneld.c#11 (text+ko) ==== @@ -54,7 +54,9 @@ /* fragment id for the next packet to be fragmented */ uint frag_id = 0; // TODO: randomize -frag_llist_t *frag_list; + +LIST_HEAD(frag_info_list_head, frag_info) frag_info_list = + LIST_HEAD_INITIALIZER(frag_info_list); /* server host */ char *host; @@ -223,11 +225,12 @@ void timer_ev_handler(int fd, short ev_type, void *arg) { struct timeval tv; - frag_llist_t *p, *q; + struct frag_info *np, *np_temp; plugint *pl = current_pl; fprintf(stderr, "timer fired\n"); - + + /* check if too many ping requests have not failed */ if (pl) { if (! pl->ping_counter) { report_plugin_error(pl, PLUGIN_ERROR_PING); @@ -237,18 +240,16 @@ } /* fragment reassembly timeout */ - // TODO: fragment reassembly timeout - for (p=frag_list; p;) { - q = p->next; - if (tv.tv_sec - p->tv_sec > FRAG_TIMEOUT) { - free(p->bitmap); - free(p->buf); - free(p); + LIST_FOREACH_SAFE(np, &frag_info_list, frag_infos, np_temp) { + if (tv.tv_sec - np->tv_sec > FRAG_TIMEOUT) { + LIST_REMOVE(np, frag_infos); + free(np->bitmap); + free(np->buf); + free(np); } - p = q; } - /* register a timer event */ + /* register a timer event again */ tv.tv_sec=1; tv.tv_usec=0; evtimer_set(&timer_ev, timer_ev_handler, NULL); @@ -262,8 +263,8 @@ { u_int8_t dispatch = *data; frag_hdr_t *frag_hdr = NULL; - frag_llist_t *p; /* pointer to frag info about the processed fragment */ - frag_llist_t **pp; /* previous item before p */ + struct frag_info *p;/* pointer to frag info about the processed fragment */ + struct frag_info *np; struct timeval tv; int i; int dgram_reassembled; @@ -290,22 +291,22 @@ frag_hdr->id, frag_hdr->size, frag_hdr->offset, len); /* check if reassembly for this fragment has already started */ - pp = &frag_list; - for(p = frag_list; p; p = p->next) { - if (p->id == frag_hdr->id && - p->size == frag_hdr->size) { + p = NULL; + LIST_FOREACH(np, &frag_info_list, frag_infos) { + if (np->id == frag_hdr->id && + np->size == frag_hdr->size) { + /* found in list */ + fprintf(stderr, "found frag info in list\n"); + p = np; break; } - pp = &p; } - /* found in list */ - if (p) { - fprintf(stderr, "found frag info in list\n"); + /* fragment info not found in list, start a new reassembly */ - } else { + if (p == NULL) { fprintf(stderr, "frag info NOT found in list\n"); /* allocate memory */ - p = malloc(sizeof(frag_llist_t)); + p = malloc(sizeof(struct frag_info)); if (!p) { fprintf(stderr, "process_data_from_plugin - " "fragment reassembly: out of memory\n"); @@ -332,11 +333,10 @@ /* collect information about the fragments */ // TODO: error checking (void) gettimeofday(&tv, NULL); - p->next = frag_list; - frag_list = p; p->id = frag_hdr->id; p->size = frag_hdr->size; memcpy(&p->tv_sec, &tv.tv_sec, sizeof(tv.tv_sec)); + LIST_INSERT_HEAD(&frag_info_list, p, frag_infos); } if (frag_hdr->offset + len <= p->size) { @@ -373,7 +373,7 @@ tun_send(p->buf, p->size); /* remove fragment info from linked list */ - *pp = p->next; + LIST_REMOVE(p, frag_infos); free(p->buf); free(p->bitmap); free(p); @@ -632,8 +632,8 @@ plugins->name = "tcp_2222"; load_plugin("./plugin_tcp.so"); plugins->name = "tcp_3333"; - // load_plugin("./plugin_icmp.so"); - // plugins->name = "icmp"; + load_plugin("./plugin_icmp.so"); + plugins->name = "icmp"; if (server) { /* initialize all plugins */ ==== //depot/projects/soc2007/mharvan-mtund/mtund.src/tunneld.h#6 (text+ko) ==== @@ -2,6 +2,7 @@ #define _TUNNELD_H #include +#include #define PACKETLEN 1400 /* encapsulated data size */ #define SOCKET_TIMEOUT 5 /* timeout for socket operations */ @@ -16,7 +17,7 @@ * of the packet */ } frag_hdr_t; -typedef struct _frag_llist_t { +struct frag_info { uint id; /* Id of the whole packet, same in each fragment */ uint size; /* length of the whole packet, same in each fragment */ time_t tv_sec; /* seconds after epoch when reassembly @@ -24,8 +25,8 @@ u_int8_t *bitmap;/* bitmap representing already * received parts of the packet */ char *buf; /* buffer into which the fragment is reassembled */ - struct _frag_llist_t *next; -} frag_llist_t; + LIST_ENTRY(frag_info) frag_infos; +}; /* * code for setting timeout on a socket: