PERFORCE change 124141 for review
Matus Harvan
mharvan at FreeBSD.org
Thu Jul 26 23:15:37 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=124141
Change 124141 by mharvan at mharvan_twoflower on 2007/07/26 23:15:08
clean up fragment reassembly information on exit
check gettimeofday(2) return value
Affected files ...
.. //depot/projects/soc2007/mharvan-mtund/mtund.src/tunneld.c#12 edit
Differences ...
==== //depot/projects/soc2007/mharvan-mtund/mtund.src/tunneld.c#12 (text+ko) ====
@@ -21,6 +21,8 @@
#include <signal.h>
#include <sys/time.h>
#include <event.h>
+#include <err.h>
+#include <sysexits.h>
#include "tun_dev.h"
@@ -55,6 +57,7 @@
/* fragment id for the next packet to be fragmented */
uint frag_id = 0; // TODO: randomize
+/* fragmentat reassembly info list */
LIST_HEAD(frag_info_list_head, frag_info) frag_info_list =
LIST_HEAD_INITIALIZER(frag_info_list);
@@ -240,6 +243,10 @@
}
/* fragment reassembly timeout */
+ if (gettimeofday(&tv, NULL) != 0) {
+ errx(EX_OSERR, "gettimeofday() failed");
+ //TODO: maybe fail
+ }
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);
@@ -331,8 +338,10 @@
memset(p->bitmap, 0, sizeof(*(p->bitmap)));
/* collect information about the fragments */
- // TODO: error checking
- (void) gettimeofday(&tv, NULL);
+ if (gettimeofday(&tv, NULL) != 0) {
+ errx(EX_OSERR, "gettimeofday() failed");
+ //TODO: maybe fail
+ }
p->id = frag_hdr->id;
p->size = frag_hdr->size;
memcpy(&p->tv_sec, &tv.tv_sec, sizeof(tv.tv_sec));
@@ -512,12 +521,22 @@
void cleanup()
{
plugint *pl;
+ struct frag_info *p;
event_del(&timer_ev);
event_del(&tun_ev);
tun_close(tun_fd, tun_dev);
+ /* deallocate fragment reassembly information */
+ while (!LIST_EMPTY(&frag_info_list)) {
+ p = LIST_FIRST(&frag_info_list);
+ LIST_REMOVE(p, frag_infos);
+ free(p->bitmap);
+ free(p->buf);
+ free(p);
+ }
+
/* deinitialize all plugins and free memory */
while(plugins) {
pl = plugins;
More information about the p4-projects
mailing list