PERFORCE change 125663 for review
Matus Harvan
mharvan at FreeBSD.org
Sat Aug 25 06:54:35 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=125663
Change 125663 by mharvan at mharvan_bike-planet on 2007/08/25 13:54:24
fragment reassembly bugfix - bitmap was not correctly initialized
fragment reassembly code cleanup
fragment header modified - 16 bit unsigned integers are enough for our mtu
Affected files ...
.. //depot/projects/soc2007/mharvan-mtund/mtund.src/mtund.c#13 edit
Differences ...
==== //depot/projects/soc2007/mharvan-mtund/mtund.src/mtund.c#13 (text+ko) ====
@@ -71,23 +71,23 @@
/* DATA TYPES */
/* fragment header */
struct frag_hdr {
- u_int8_t dispatch;
- uint id; /* ID of the packet. same in each fragment
+ uint8_t dispatch;
+ uint16_t id; /* ID of the packet. same in each fragment
* belonging to the same packet */
- uint size; /* length of the whole packet, same in each fragment */
- uint offset; /* fragment offset (in bytes) from the beginning
+ uint16_t size; /* length of the whole packet, same in each fragment */
+ uint16_t offset;/* fragment offset (in bytes) from the beginning
* of the packet */
};
/* info about a packet being reassembled from fragments */
struct frag_info {
- uint id; /* ID of the packet. same in each fragment
+ uint16_t id; /* ID of the packet. same in each fragment
* belonging to the same packet */
- uint size; /* length of the whole packet, same
+ uint16_t size; /* length of the whole packet, same
* in each fragment */
time_t tv_sec; /* seconds after epoch when reassembly
* of this packet started */
- u_int8_t *bitmap; /* bitmap representing already
+ uint8_t *bitmap; /* bitmap representing already
* received parts of the packet */
char *buf; /* buffer into which the fragment is
* reassembled */
@@ -112,7 +112,7 @@
char frag_data[MTU+sizeof(struct frag_hdr)];
char *frag_datap;
int frag_data_len;
- uint frag_id;/* id for the next packet to be fragmented */
+ uint16_t frag_id;/* id for the next packet to be fragmented */
/* fragment reassembly information */
LIST_HEAD(frag_infos_head, frag_info) frag_infos;
};
@@ -709,8 +709,6 @@
break;
case DISPATCH_FRAG: /* fragment reassembly */
- pl->conn_map(pl, *clid, CONN_PERM);
-
if (len <= sizeof(*frag_hdr)) {
plugin_report(pl, *clid, REPORT_ERROR_RECEIVE);
return;
@@ -729,7 +727,7 @@
if (np->id == frag_hdr->id &&
np->size == frag_hdr->size) {
/* found in list */
- fprintf(stderr, "found frag info in list\n");
+ debug("found frag info in list\n");
p = np;
break;
}
@@ -753,7 +751,7 @@
"fragment reassembly: out of memory\n");
return;
}
- p->bitmap = malloc(frag_hdr->size/8 + 1);
+ p->bitmap = malloc(frag_hdr->size / 8 + 1);
if (!p->bitmap) {
free(p->buf);
free(p);
@@ -761,8 +759,8 @@
"fragment reassembly: out of memory\n");
return;
}
- memset(p->bitmap, 0, sizeof(*(p->bitmap)));
-
+ memset(p->bitmap, 0, frag_hdr->size / 8 + 1);
+
/* collect information about the fragments */
gettimeofday(&tv, NULL);
p->id = frag_hdr->id;
@@ -771,49 +769,47 @@
LIST_INSERT_HEAD(&cl->frag_infos, p, frag_infos);
}
- if (frag_hdr->offset + len <= p->size) {
- /* copy the data */
- memcpy(p->buf + frag_hdr->offset, data, len);
- /* update the bitmap
- *
- * We ignore fragment overlaps as these should
- * be caught by the upper layer
- * checksum. Actually, they should not happen
- * at all.
- */
- for (i = frag_hdr->offset; i < frag_hdr->offset+len;
- i++)
- p->bitmap[i/8] |= (0x1 << (i%8));
- } else {
- debug("fragment outside of packet payload\n");
+ if (frag_hdr->offset + len > p->size) {
+ debug("fragment payload outside of packet payload\n");
return;
}
+ /* copy the data */
+ memcpy(p->buf + frag_hdr->offset, data, len);
+ /* update the bitmap
+ *
+ * We ignore fragment overlaps as these should
+ * be caught by the upper layer
+ * checksum. Actually, they should not happen
+ * at all.
+ */
+ for (i = frag_hdr->offset; i < frag_hdr->offset+len; i++)
+ p->bitmap[i/8] |= (0x1 << (i%8));
/*
* Fragment was processed without errors, so it was
* valid traffic and the plugin used by this client
* should be updated.
*/
+ pl->conn_map(pl, *clid, CONN_PERM);
set_client_pl(cl, pl);
/* check if the complete packet has been reassembled */
dgram_reassembled = 1;
/* examine the bitmap */
- for(i=0; i < p->size/8 && dgram_reassembled; i++) {
+ for(i = 0; i < p->size / 8 && dgram_reassembled; i++) {
if (p->bitmap[i] != 0xff) {
dgram_reassembled = 0;
}
}
- for(i=0; i < p->size%8 && dgram_reassembled; i++) {
- if (! (p->bitmap[p->size/8] & (1 << i))) {
- dgram_reassembled=0;
+ for(i = 0; i < p->size % 8 && dgram_reassembled; i++) {
+ if ((p->bitmap[p->size / 8] & (1 << i)) == 0) {
+ dgram_reassembled = 0;
}
}
/* packet completely reassembled */
- if (dgram_reassembled) {
+ if (dgram_reassembled != 0) {
debug("frag reassembly: packet complete\n");
- set_client_pl(cl, pl);
/* pass the reassembled packet to the tun device */
tun_send(cl, p->buf, p->size);
@@ -1066,6 +1062,7 @@
int consumed;
int n;
+ debug("send_next_frag: frag_hdr.size: %u\n", cl->frag_hdr.size);
if (server) {
while(cl->frag_data_len > sizeof(cl->frag_hdr) &&
nwrite == SEND_PKT_SENT) {
@@ -1132,6 +1129,7 @@
n = cl->frag_data_len;
nwrite = cl->pl->send(cl->pl, cl->clid,
cl->frag_datap, n, NORMAL_DATA, &consumed);
+ debug("send_next_frag: consumed: %d\n", consumed);
switch (nwrite) {
case SEND_PKT_SENT:
case SEND_PKT_QUEUED:
@@ -1327,23 +1325,23 @@
signal(SIGTERM, sigcb);
/* load plugins */
- if (server) {
- pl = load_plugin("./plugin_udp_catchall.so");
- pl->name = "udp_catchall";
- } else { /* client */
+/* if (server) { */
+/* pl = load_plugin("./plugin_udp_catchall.so"); */
+/* pl->name = "udp_catchall"; */
+/* } else { /\* client *\/ */
pl = load_plugin("./plugin_udp.so");
pl->name = "udp_1234";
- pl = load_plugin("./plugin_udp.so");
- pl->name = "udp_1235";
/* pl = load_plugin("./plugin_udp.so"); */
-/* pl->name = "udp_53"; */
- }
- pl = load_plugin("./plugin_tcp.so");
- pl->name = "tcp_1234";
- pl = load_plugin("./plugin_icmp.so");
- pl->name = "icmp";
- pl = load_plugin("./plugin_dns/plugin_dns.so");
- pl->name = "dns_53";
+/* pl->name = "udp_1235"; */
+/* /\* pl = load_plugin("./plugin_udp.so"); *\/ */
+/* /\* pl->name = "udp_53"; *\/ */
+/* } */
+/* pl = load_plugin("./plugin_tcp.so"); */
+/* pl->name = "tcp_1234"; */
+/* pl = load_plugin("./plugin_icmp.so"); */
+/* pl->name = "icmp"; */
+/* pl = load_plugin("./plugin_dns/plugin_dns.so"); */
+/* pl->name = "dns_53"; */
if (server) {
/* initialize all plugins */
More information about the p4-projects
mailing list