diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/capture.c pre_checkin/como/src/base/capture.c --- clean/como/src/base/capture.c 2005-01-23 19:52:20.000000000 +0000 +++ pre_checkin/como/src/base/capture.c 2005-02-14 11:29:01.202784753 +0000 @@ -39,6 +39,8 @@ /* poll time (in usec) */ #define POLL_WAIT 1000000 +#define MAX_PKTS 1000 + /* global state */ extern struct _como map; @@ -207,7 +209,7 @@ ct = cl->ca_hashtable; - for (i = 0; i < no_pkts; i++, pkt++) { + for (i = 0; i < no_pkts; i++, pkt = STDPKT_NEXT(pkt)) { rec_t *prev, *cand; uint32_t hash; uint bucket; @@ -472,7 +474,7 @@ if ( !(sn->cb.flags & SNIFF_POLL) && !FD_ISSET(sn->fd, &r)) continue; /* nothing to read here. */ - count = sn->cb.sniffer_next(sn->fd, pkts); + count = sn->cb.sniffer_next(sn->fd, pkts, sizeof(pkts)); if (count == 0) continue; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/query-ondemand.c pre_checkin/como/src/base/query-ondemand.c --- clean/como/src/base/query-ondemand.c 2005-01-25 19:15:21.000000000 +0000 +++ pre_checkin/como/src/base/query-ondemand.c 2005-02-14 11:29:24.569912544 +0000 @@ -269,12 +269,8 @@ * invoke the print() method to print data. * Replace the final NULL with a \n if not there */ - ptr = mdl->callbacks.print(ptr); - len = strlen(ptr); - if (len > 0 && ptr[len-1] != '\n') { - ptr[len] = '\n'; - len++; - } + len = -1; + ptr = mdl->callbacks.print(ptr, &len); } if (!qrysend(client_fd, reply_fmt, 0, ptr, len)) panic("sending data to the client: %s\n", strerror(errno)); diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/sniffer-bpf.c pre_checkin/como/src/base/sniffer-bpf.c --- clean/como/src/base/sniffer-bpf.c 2005-01-23 19:52:20.000000000 +0000 +++ pre_checkin/como/src/base/sniffer-bpf.c 2005-02-14 11:29:01.202784753 +0000 @@ -151,15 +151,17 @@ * plus alignment padding) */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *out_buf, size_t out_buf_size) { static char buf[BUFSIZE]; /* base of the capture buffer */ struct bpf_hdr *bh; /* BPF header */ char *base; /* where to copy from */ int len = 0; /* remaining bytes in buffer */ int ofs = 0; /* next pkt to read in buffer */ - uint npkt = 0; + uint out_buf_used = 0; /* output buffer consumed */ + pkt_t *hdr; uint hl; + uint npkt = 0; if ((len = read(fd, buf, BUFSIZE)) < 0) return -1; @@ -174,20 +176,23 @@ if (len < ofs + (int)bh->bh_hdrlen + (int)bh->bh_caplen) return -1; /* packet incomplete */ - if (MAX_PKTS < (npkt+1) * sizeof(pkt_t)) + if (out_buf_used + sizeof(pkt_t) + bh->bh_datalen > out_buf_size) return -1; /* not enough space in output buffer */ /* ok data is good now */ - hdr[npkt].ts = TIME2TS(bh->bh_tstamp.tv_sec, bh->bh_tstamp.tv_usec); - hdr[npkt].caplen = bh->bh_caplen; - hdr[npkt].len = bh->bh_datalen; + hdr = (pkt_t *)((unsigned long)out_buf + out_buf_used); + hdr->ts = TIME2TS(bh->bh_tstamp.tv_sec, bh->bh_tstamp.tv_usec); + hdr->caplen = bh->bh_caplen; + hdr->len = bh->bh_datalen; + base = buf + ofs; + bcopy(base, hdr->payload, hdr->caplen); /* skip BPF header */ - base = buf + ofs + bh->bh_hdrlen; + base += bh->bh_hdrlen; /* determine traffic direction, if applicable */ if (chkdir) - hdr[npkt].dir = get_direction((struct _como_machdr *)base); + hdr->dir = get_direction((struct _como_machdr *)base); /* increment ofs to next packet */ ofs += BPF_WORDALIGN(bh->bh_hdrlen + bh->bh_caplen); @@ -196,21 +201,21 @@ base += skip_layertwo(type); /* copy the header */ - hdr[npkt].ih = *(struct _como_iphdr *)base; + hdr->ih = *(struct _como_iphdr *)base; /* copy the rest */ - hl = (hdr[npkt].ih.vhl & 0x0f)*4; /* skip IP header */ - if (hdr[npkt].caplen >= hl) /* copy next header */ + hl = (hdr->ih.vhl & 0x0f)*4; /* skip IP header */ + if (hdr->caplen >= hl) /* copy next header */ { base += hl; - hl = hdr[npkt].len - hl; /* leftover bytes */ - if (hl > sizeof(hdr[npkt].p)) - hl = sizeof(hdr[npkt].p); - bcopy(base, &hdr[npkt].p, hl); + hl = hdr->len - hl; /* leftover bytes */ + if (hl > sizeof(hdr->p)) + hl = sizeof(hdr->p); + bcopy(base, &hdr->p, hl); } - /* increment the number of processed packets */ - npkt++; + out_buf_used += STDPKT_SIZE(hdr); + npkt++; } /* return the number of copied packets */ diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/sniffer-dag.c pre_checkin/como/src/base/sniffer-dag.c --- clean/como/src/base/sniffer-dag.c 2005-01-23 19:52:20.000000000 +0000 +++ pre_checkin/como/src/base/sniffer-dag.c 2005-02-14 11:29:01.203784630 +0000 @@ -86,16 +86,18 @@ * edag_next */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *out_buf, size_t out_buf_size) { static void *bot = NULL; /* pointer to bottom of stream buffer */ void *top = NULL; /* pointer to top of stream buffer */ dag_record_t *rec; /* pointer to current record */ char *base; /* where to copy from */ uint num = 0; /* number of processed bytes */ - uint npkt = 0; /* number of pkts processed */ int len; /* record length */ uint hl; /* IP header length */ + pkt_t *hdr; /* next CoMo header */ + unsigned out_buf_off = 0; /* How much of the output buffer we've used */ + uint npkt = 0; /* read ERF records from stream 0 */ if ((top = dag_advance_stream(fd, 0, &bot)) == NULL) @@ -107,10 +109,6 @@ while ((top-bot > dag_record_size) && num+dag_record_size < BUFSIZE) { - /* check if we have enough space in output buffer */ - if (MAX_PKTS < (npkt+1) * sizeof(pkt_t)) - return npkt; /* next call will return this remainder pkts too */ - /* access to packet record */ rec = (dag_record_t *)bot; len = ntohs(rec->rlen); @@ -119,42 +117,49 @@ if (top - bot < len) return npkt; + /* check if we have enough space in output buffer */ + if (out_buf_off + sizeof(pkt_t) + len > out_buf_size) + return out_buf_off; + /* check if record would go over extra window */ if (num + len > BUFSIZE) - return npkt; + return out_buf_off; /* ok data is good now */ - hdr[npkt].ts = rec->ts; - hdr[npkt].caplen = len; - hdr[npkt].len = ntohs(rec->wlen); + hdr = (pkt_t *)((unsigned long)out_buf + len); + hdr->ts = rec->ts; + hdr->caplen = len; + hdr->len = ntohs(rec->wlen); /* determine traffic direction, if applicable */ if (chkdir) - hdr[npkt].dir = rec->flags.iface; + hdr->dir = rec->flags.iface; bot += len; /* increment bottom pointer to next packet */ num += len; /* update number of processed bytes */ - /* skip ERF + link layer header */ base = bot + dag_record_size; + /* copy the packet body */ + bcopy(base, hdr->payload, len); + /* skip ERF + link layer header */ base += skip_layertwo(rec->type); /* copy the header */ - hdr[npkt].ih = *(struct _como_iphdr *)base; + hdr->ih = *(struct _como_iphdr *)base; /* copy the rest */ - hl = (hdr[npkt].ih.vhl & 0x0f)*4; /* skip IP header */ - if (hdr[npkt].caplen >= hl) /* copy next header */ + hl = (hdr->ih.vhl & 0x0f)*4; /* skip IP header */ + if (hdr->caplen >= hl) /* copy next header */ { base += hl; - hl = hdr[npkt].len - hl; /* leftover bytes */ - if (hl > sizeof(hdr[npkt].p)) - hl = sizeof(hdr[npkt].p); - bcopy(base, &hdr[npkt].p, hl); + hl = hdr->len - hl; /* leftover bytes */ + if (hl > sizeof(hdr->p)) + hl = sizeof(hdr->p); + bcopy(base, &hdr->p, hl); } - /* increment the number of processed packets */ - npkt++; + out_buf_off += STDPKT_SIZE(hdr); + npkt++; } /* return the number of copied packets */ diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/sniffer-erf.c pre_checkin/como/src/base/sniffer-erf.c --- clean/como/src/base/sniffer-erf.c 2005-01-23 19:52:20.000000000 +0000 +++ pre_checkin/como/src/base/sniffer-erf.c 2005-02-14 11:29:01.204784507 +0000 @@ -68,17 +68,19 @@ * erf_next */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *out_buf, size_t out_buf_size) { static char buf[BUFSIZE]; /* base of the capture buffer */ static uint num = 0; /* remaining bytes in buffer */ dag_record_t *rec; /* pointer to current record */ char *base; /* where to copy from */ uint ofs = 0; /* next pkt to read in buffer */ - uint npkt = 0; /* number of pkts processed */ int len; /* record length */ uint hl; /* IP header length */ int i; /* number of bytes readed */ + uint out_buf_used = 0; /* how much of the output buffer we've used */ + pkt_t *hdr; /* The next CoMo header */ + uint npkt = 0; /* read ERF records from fd */ if (((i = read(fd, buf + num, BUFSIZE - num)) < 0) || (!i && !num)) @@ -89,10 +91,6 @@ while (ofs < num) { - /* check if we have enough space in output buffer */ - if (MAX_PKTS < (npkt+1) * sizeof(pkt_t)) - goto need_more; - /* check if header is complete */ if (num < ofs + sizeof(dag_record_t)) goto need_more; @@ -101,41 +99,50 @@ rec = (dag_record_t *)(buf + ofs); len = ntohs(rec->rlen); + /* check if we have enough space in output buffer */ + if (out_buf_used + sizeof(pkt_t) + len > out_buf_size) + goto need_more; + /* check if entire record is available */ if (num < ofs + len) goto need_more; /* ok data is good now */ - hdr[npkt].ts = rec->ts; - hdr[npkt].caplen = len; - hdr[npkt].len = ntohs(rec->wlen); + hdr = (pkt_t *)((unsigned long)out_buf + len); + hdr->ts = rec->ts; + hdr->caplen = len; + hdr->len = ntohs(rec->wlen); /* determine traffic direction, if applicable */ if (chkdir) - hdr[npkt].dir = rec->flags.iface; + hdr->dir = rec->flags.iface; /* increment ofs to next packet */ ofs += len; + base = buf + ofs; + /* copy the payload */ + bcopy(base, hdr->payload, len); + /* skip ERF + link layer header */ - base = buf + ofs + dag_record_size + skip_layertwo(rec->type); + base += dag_record_size + skip_layertwo(rec->type); /* copy the header */ - hdr[npkt].ih = *(struct _como_iphdr *)base; + hdr->ih = *(struct _como_iphdr *)base; /* copy the rest */ - hl = (hdr[npkt].ih.vhl & 0x0f) * 4; /* skip IP header */ - if (hdr[npkt].caplen >= hl) /* copy next header */ + hl = (hdr->ih.vhl & 0x0f) * 4; /* skip IP header */ + if (hdr->caplen >= hl) /* copy next header */ { base += hl; - hl = hdr[npkt].len - hl; /* leftover bytes */ - if (hl > sizeof(hdr[npkt].p)) - hl = sizeof(hdr[npkt].p); - bcopy(base, &hdr[npkt].p, hl); + hl = hdr->len - hl; /* leftover bytes */ + if (hl > sizeof(hdr->p)) + hl = sizeof(hdr->p); + bcopy(base, &hdr->p, hl); } - /* increment the number of processed packets */ - npkt++; + out_buf_used += STDPKT_SIZE(hdr); + npkt++; } /* all packets of buffer have been readed */ diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/sniffer-libpcap.c pre_checkin/como/src/base/sniffer-libpcap.c --- clean/como/src/base/sniffer-libpcap.c 2005-01-27 17:00:44.000000000 +0000 +++ pre_checkin/como/src/base/sniffer-libpcap.c 2005-02-14 11:30:21.042971515 +0000 @@ -132,16 +132,16 @@ * int32 len; length of this packet (off wire) */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *buf, size_t buf_len) { pcap_t *pt = NULL; int chkdir = 0; sl_fdlist *p = NULL; - + pkt_t *hdr = buf; struct pcap_pkthdr pkthdr; u_char *pkt = 0; uint hl = 0; - + /* get the pcap handle associated to fd */ for (p = fdlist; p != NULL; p = p->next) if (p->fd == fd) { @@ -164,24 +164,26 @@ pkt = (u_char*)pcap_next( pt, &pkthdr ); if (pkt == NULL) return 0; - - hdr[0].ts = TIME2TS(pkthdr.ts.tv_sec, pkthdr.ts.tv_usec); - hdr[0].caplen = pkthdr.caplen; - hdr[0].len = pkthdr.len; - hdr[0].n_frags = 0; /* XXX: provisional */ + if (pkthdr.len + sizeof(*hdr) > buf_len) + return -1; + hdr->ts = TIME2TS(pkthdr.ts.tv_sec, pkthdr.ts.tv_usec); + hdr->caplen = pkthdr.caplen; + hdr->len = pkthdr.len; + hdr->n_frags = 0; /* XXX: provisional */ + bcopy(pkt, hdr->payload, pkthdr.caplen); if (chkdir) - hdr[0].dir = get_direction((struct _como_machdr *)pkt); - hdr[0].mach = *( struct _como_machdr* )pkt; + hdr->dir = get_direction((struct _como_machdr *)pkt); + hdr->mach = *( struct _como_machdr* )pkt; pkt += skip_val; - hdr[0].ih = *( struct _como_iphdr* )pkt; + hdr->ih = *( struct _como_iphdr* )pkt; /* IPV4 packets start with a 4 bit version number (0x4)... */ - if ((hdr[0].ih.vhl >> 4) != 0x04) + if ((hdr->ih.vhl >> 4) != 0x04) return 0; /* not an ipv4 packet */ /* ... and then have a 4 bit field: header length in words */ - hl = ( ( hdr[0].ih.vhl & 0x0f ) << 2 ); + hl = ( ( hdr->ih.vhl & 0x0f ) << 2 ); /* An ipv4 header is at least 20 bytes long */ if (hl < 20) @@ -192,14 +194,13 @@ * NOTE: caplen should be definitely >= 20; here, we take * in account the (unlikely?) presence of header options */ - if (hdr[0].caplen >= hl) { + if (hdr->caplen >= hl) { pkt += hl; /* skip header + options */ - hl = hdr[0].len - hl; /* leftover bytes */ + hl = hdr->len - hl; /* leftover bytes */ if (hl > sizeof(union _como_apphdr)) hl = sizeof(union _como_apphdr); - bcopy(pkt, &hdr[0].p, hl); + bcopy(pkt, &hdr->p, hl); } - return 1; } diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/sniffer-pcap.c pre_checkin/como/src/base/sniffer-pcap.c --- clean/como/src/base/sniffer-pcap.c 2005-01-23 19:52:20.000000000 +0000 +++ pre_checkin/como/src/base/sniffer-pcap.c 2005-02-14 11:29:24.569912544 +0000 @@ -99,16 +99,18 @@ * */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *outbuf, size_t out_buf_size) { static char buf[BUFSIZE]; /* base of the capture buffer */ static uint len = 0; /* remaining bytes in buffer */ pcap_hdr_t *ph; /* PCAP header */ char *base; /* where to copy from */ uint ofs = 0; /* next pkt to read in buffer */ - uint npkt = 0; uint hl; int i; + unsigned out_buf_off = 0; + pkt_t *hdr; + uint npkt = 0; errno = 0; if (((i = read(fd, buf + len, BUFSIZE - len)) < 0) || (!i && !len)) @@ -126,20 +128,24 @@ if (len < ofs + sizeof(pcap_hdr_t) + ph->caplen) goto need_more; /* packet incomplete */ - if (MAX_PKTS < (npkt+1) * sizeof(pkt_t)) + if (out_buf_off + sizeof(pkt_t) + ph->caplen > out_buf_size) goto need_more; /* not enough space in output batch */ + hdr = (pkt_t *)((unsigned long)outbuf + out_buf_off); /* ok data is good now */ - hdr[npkt].ts = TIME2TS(ph->ts.tv_sec, ph->ts.tv_usec); - hdr[npkt].caplen = ph->caplen; - hdr[npkt].len = ph->len; + hdr->ts = TIME2TS(ph->ts.tv_sec, ph->ts.tv_usec); + hdr->caplen = ph->caplen; + hdr->len = ph->len; /* skip PCAP header */ base = buf + ofs + sizeof(pcap_hdr_t); + /* stash the payload */ + bcopy(base, hdr->payload, ph->caplen); + /* determine traffic direction, if applicable */ if (chkdir) - hdr[npkt].dir = get_direction((struct _como_machdr *)base); + hdr->dir = get_direction((struct _como_machdr *)base); /* increment ofs to next packet */ ofs += sizeof(pcap_hdr_t) + ph->caplen; @@ -148,21 +154,21 @@ base += skip_layertwo(type); /* copy the header */ - hdr[npkt].ih = *(struct _como_iphdr *)base; + hdr->ih = *(struct _como_iphdr *)base; /* copy the rest */ - hl = (hdr[npkt].ih.vhl & 0x0f) * 4; /* skip IP header */ - if (hdr[npkt].caplen >= hl) /* copy next header */ + hl = (hdr->ih.vhl & 0x0f) * 4; /* skip IP header */ + if (hdr->caplen >= hl) /* copy next header */ { base += hl; - hl = hdr[npkt].len - hl; /* leftover bytes */ - if (hl > sizeof(hdr[npkt].p)) - hl = sizeof(hdr[npkt].p); - bcopy(base, &hdr[npkt].p, hl); + hl = hdr->len - hl; /* leftover bytes */ + if (hl > sizeof(hdr->p)) + hl = sizeof(hdr->p); + bcopy(base, &hdr->p, hl); } - /* increment the number of processed packets */ - npkt++; + out_buf_off += STDPKT_SIZE(hdr); + npkt++; } /* all packets of buffer have been readed */ diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/sniffer-sk98.c pre_checkin/como/src/base/sniffer-sk98.c --- clean/como/src/base/sniffer-sk98.c 2005-02-09 14:52:11.000000000 +0000 +++ pre_checkin/como/src/base/sniffer-sk98.c 2005-02-14 11:29:01.206784261 +0000 @@ -160,7 +160,7 @@ * */ static int -sniffer_next(int fd __unused, pkt_t *hdr) +sniffer_next(int fd __unused, void *out_buf, size_t out_buf_size) { unsigned nr_captured = 0; unsigned ind; @@ -169,9 +169,11 @@ struct timeval tv; struct _como_iphdr *ih; unsigned ih_octs; + uint out_buf_used = 0; + pkt_t *hdr; mb(); - while (nr_captured < MAX_PKTS) { + while (1) { if (m->k2u_cons == m->k2u_prod) { return nr_captured; } @@ -197,16 +199,19 @@ m->k2u_pipe[ind].tstamp, &tv, NULL); - hdr[nr_captured].ts = TIME2TS(tv.tv_sec, tv.tv_usec); - hdr[nr_captured].caplen = m->k2u_pipe[ind].len; - hdr[nr_captured].len = m->k2u_pipe[ind].len; - hdr[nr_captured].n_frags = 1; - hdr[nr_captured].dir = 0; - memcpy(&hdr[nr_captured].mach, + if (out_buf_used + sizeof(pkt_t) + m->k2u_pipe[ind].len > out_buf_size) + return nr_captured; + hdr = (pkt_t *)((unsigned long)out_buf + out_buf_used); + hdr->ts = TIME2TS(tv.tv_sec, tv.tv_usec); + hdr->caplen = m->k2u_pipe[ind].len; + hdr->len = m->k2u_pipe[ind].len; + hdr->n_frags = 1; + hdr->dir = 0; + memcpy(&hdr->mach, packet_pool[token].payload, - sizeof(hdr[nr_captured].mach)); + sizeof(hdr->mach)); ih = (struct _como_iphdr *)(packet_pool[token].payload + - sizeof(hdr[nr_captured].mach)); + sizeof(hdr->mach)); ih_octs = (ih->vhl & 0x0f) * 4; /* Note that we don't need to explicitly sanity check ih_octs here. It's guaranteed to be in [0,60], so we could @@ -216,35 +221,35 @@ garbage into the header area of the como packet, but the higher levels need to check them for validity anyway, so we're perfectly safe. */ - hdr[nr_captured].ih = *ih; + hdr->ih = *ih; switch (ih->proto) { case 1: { struct _como_icmphdr *icmph; icmph = (struct _como_icmphdr *)((char *)ih + ih_octs); - hdr[nr_captured].p.icmph = *icmph; + hdr->p.icmph = *icmph; break; } case 6: { struct _como_tcphdr *tcph; tcph = (struct _como_tcphdr *)((char *)ih + ih_octs); - hdr[nr_captured].p.tcph = *tcph; + hdr->p.tcph = *tcph; break; } case 17: { struct _como_udphdr *udph; udph = (struct _como_udphdr *)((char *)ih + ih_octs); - hdr[nr_captured].p.udph = *udph; + hdr->p.udph = *udph; break; } } nr_captured++; + out_buf_used += STDPKT_SIZE(hdr); m->k2u_cons++; return_token(token); } - return nr_captured; } diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/base/template pre_checkin/como/src/base/template --- clean/como/src/base/template 2005-01-23 19:52:20.000000000 +0000 +++ pre_checkin/como/src/base/template 2005-02-14 11:29:01.206784261 +0000 @@ -110,7 +110,7 @@ for (i = 0; i < n_out; i++) outs[i] = which + n_packets*i; - for (i=0; i < n_packets; i++, pkt++) { + for (i=0; i < n_packets; i++, pkt = STDPKT_NEXT(pkt)) { /* * here we expect lines of the form diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/include/comotypes.h pre_checkin/como/src/include/comotypes.h --- clean/como/src/include/comotypes.h 2005-01-23 19:52:20.000000000 +0000 +++ pre_checkin/como/src/include/comotypes.h 2005-02-14 11:29:24.570912421 +0000 @@ -172,10 +172,11 @@ /** * print_fn() given a data buffer, returns a printable * representation of the content of the data in a static buffer. + * Returns the length in *len. * On error returns NULL * Optional */ -typedef char * (print_fn)(char *buf); +typedef char * (print_fn)(char *buf, size_t *len); /* diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/include/sniffers.h pre_checkin/como/src/include/sniffers.h --- clean/como/src/include/sniffers.h 2005-01-23 19:52:20.000000000 +0000 +++ pre_checkin/como/src/include/sniffers.h 2005-02-14 11:29:01.207784138 +0000 @@ -34,8 +34,6 @@ #define BPF_ETH 7 -#define MAX_PKTS (1000 * sizeof(pkt_t)) - /* * A sniffer is in charge of delivering packets to CoMo from a given * input source. Each sniffer must implement three callbacks: @@ -65,7 +63,8 @@ /* sniffer callbacks */ typedef int (start_fn)(char *ifname, int dir); -typedef int (next_fn)(int fd, pkt_t *hdr); +/* Returns amount of buffer space consumed. */ +typedef int (next_fn)(int fd, void *buffer_space, size_t buf_size); typedef void (stop_fn)(int fd); struct _sniffer { diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/include/stdpkt.h pre_checkin/como/src/include/stdpkt.h --- clean/como/src/include/stdpkt.h 2005-02-10 17:39:35.000000000 +0000 +++ pre_checkin/como/src/include/stdpkt.h 2005-02-14 11:29:13.727245275 +0000 @@ -139,8 +139,16 @@ struct _como_udphdr udph; struct _como_icmphdr icmph; } p; + uint8_t payload[0]; }; +/* XXX SOS22: If anyone knows how to do this portably, feel free to do + it. */ +#define ALIGN_UP(x) ( ((x) + __alignof__(long)) & ~(__alignof__(long)-1) ) + +#define STDPKT_SIZE(x) ALIGN_UP((sizeof(pkt_t) + (x)->caplen)) +#define STDPKT_NEXT(p) (pkt_t *)((unsigned long)(p) + STDPKT_SIZE(p)) + /* * timestamp macros * diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/application.c pre_checkin/como/src/modules/application.c --- clean/como/src/modules/application.c 2005-01-24 12:27:26.000000000 +0000 +++ pre_checkin/como/src/modules/application.c 2005-02-14 11:29:24.571912298 +0000 @@ -238,16 +238,16 @@ } static char * -print(char *buf) +print(char *buf, size_t *len) { FLOWDESC *x = F(buf - sizeof(rec_t)); static char s[2048]; time_t ts = (time_t) ntohl(x->ts); - sprintf(s, "Ts: %.24s App: %3s Bytes (1s): %8llu Packets (1s): %llu\n", - asctime(localtime(&ts)), app2str[ntohl(x->app)], - NTOHLL(x->bytes), NTOHLL(x->pkts)); + *len = sprintf(s, "Ts: %.24s App: %3s Bytes (1s): %8llu Packets (1s): %llu\n", + asctime(localtime(&ts)), app2str[ntohl(x->app)], + NTOHLL(x->bytes), NTOHLL(x->pkts)); return s; }; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/como.gmk pre_checkin/como/src/modules/como.gmk --- clean/como/src/modules/como.gmk 2005-02-10 17:51:13.000000000 +0000 +++ pre_checkin/como/src/modules/como.gmk 2005-02-14 11:29:13.727245275 +0000 @@ -13,7 +13,8 @@ topdest.so \ connx.so \ utilization.so \ - trace.so + trace.so \ + full_cap.so INCDIRS = ../base diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/connx.c pre_checkin/como/src/modules/connx.c --- clean/como/src/modules/connx.c 2005-01-25 22:07:20.000000000 +0000 +++ pre_checkin/como/src/modules/connx.c 2005-02-14 11:29:24.571912298 +0000 @@ -208,7 +208,7 @@ static char * -print(char *buf) +print(char *buf, size_t *len) { EFLOWDESC *ex = EF(buf - sizeof(rec_t)); static char s[2048]; @@ -220,11 +220,12 @@ sprintf(src, "%s", inet_ntoa(saddr)); sprintf(dst, "%s", inet_ntoa(daddr)); - sprintf(s, "%15s %15s Src port: %5hu Dst port: %5hu Proto: %3u " - "Bytes: %8llu Packets: %8llu Start: %12llu End: %12llu", - src, dst, ntohs(N16(ex->src_port)), ntohs(N16(ex->dst_port)), - (uint) ex->proto, NTOHLL(ex->bytes), NTOHLL(ex->pkts), - NTOHLL(ex->first), NTOHLL(ex->last)); + *len = sprintf(s, "%15s %15s Src port: %5hu Dst port: %5hu Proto: %3u " + "Bytes: %8llu Packets: %8llu Start: %12llu End: %12llu", + src, dst, ntohs(N16(ex->src_port)), + ntohs(N16(ex->dst_port)), (uint) ex->proto, + NTOHLL(ex->bytes), NTOHLL(ex->pkts), NTOHLL(ex->first), + NTOHLL(ex->last)); return s; }; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/counter.c pre_checkin/como/src/modules/counter.c --- clean/como/src/modules/counter.c 2005-01-23 19:52:21.000000000 +0000 +++ pre_checkin/como/src/modules/counter.c 2005-02-14 11:29:24.572912175 +0000 @@ -98,16 +98,16 @@ } static char * -print(char *buf) +print(char *buf, size_t *len) { FLOWDESC *x = F(buf - sizeof(rec_t)); static char s[512]; time_t ts = (time_t)ntohl(x->ts); - sprintf(s, "Ts: %.24s Byte/s: %llu\tPkt/sec:%llu\n", - asctime(localtime(&ts)), NTOHLL(x->byts), NTOHLL(x->pkts)); + *len = sprintf(s, "Ts: %.24s Byte/s: %llu\tPkt/sec:%llu\n", + asctime(localtime(&ts)), NTOHLL(x->byts), NTOHLL(x->pkts)); return s; }; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/full_cap.c pre_checkin/como/src/modules/full_cap.c --- clean/como/src/modules/full_cap.c 1970-01-01 01:00:00.000000000 +0100 +++ pre_checkin/como/src/modules/full_cap.c 2005-02-14 11:30:07.958579645 +0000 @@ -0,0 +1,84 @@ +/* + * Full capture module + * + * This module captures entire packets and dumps them in pcap format. + * + * Config parameters: + * + * . hashsize 1 + * . blocksize: should match BUFSIZE defined below + 4 + sizeof(rec_t) + */ + +#include +#include +#include +#include "como.h" +#include "module.h" + +#define FLOWDESC struct _capture + +#define BUF_SIZE 65530 +FLOWDESC { + rec_t r; + uint bytes_used; + uint8_t bytes[BUF_SIZE]; +}; + +static int +update(pkt_t *pkt, rec_t *fh, int new_rec) +{ + FLOWDESC *x = F(fh); + struct pcap_pkthdr *phdr; + + if (new_rec) + x->bytes_used = 0; + phdr = (struct pcap_pkthdr *)((unsigned long)x->bytes + x->bytes_used); + phdr->ts.tv_sec = TS2SEC(pkt->ts); + phdr->ts.tv_usec = TS2USEC(pkt->ts); + phdr->caplen = pkt->caplen; + phdr->len = pkt->len; + bcopy(pkt->payload, phdr + 1, pkt->caplen); + x->bytes_used += sizeof(*phdr) + pkt->caplen; + if (x->bytes_used + sizeof(*phdr) + 1514 >= BUF_SIZE) + return 1; /* The record might overflow next time we try to use + * it. */ + else + return 0; +} + +static ssize_t +store(rec_t *fh, char *buf, size_t len) +{ + const FLOWDESC *x = F(fh); + + assert(len >= BUF_SIZE + 4); + *(size_t *)buf = x->bytes_used + 4; + memcpy(buf + 4, x->bytes, x->bytes_used); + return x->bytes_used + 4; +} + +static size_t +load(char *buf, size_t len __unused, timestamp_t *ts __unused) +{ + size_t s; + + if (len < 4) + return -1; + s = *(size_t *)buf; + return s; +} + +static char * +print(char *buf, size_t *len) +{ + *len = *(size_t *)buf - 4; + return buf + 4; +} + +callbacks_t callbacks = { + ca_recordsize: sizeof(FLOWDESC), + update: update, + store: store, + load: load, + print: print +}; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/protocol.c pre_checkin/como/src/modules/protocol.c --- clean/como/src/modules/protocol.c 2005-01-24 18:59:05.000000000 +0000 +++ pre_checkin/como/src/modules/protocol.c 2005-02-14 11:29:24.573912052 +0000 @@ -115,16 +115,17 @@ } static char * -print(char *buf) +print(char *buf, size_t *len) { FLOWDESC *x = F(buf - sizeof(rec_t)); static char s[2048]; time_t ts = (time_t)ntohl(x->ts); - sprintf(s, "Ts: %.24s Proto: %3u Bytes (1s): %10llu Pkts (1s): %10llu\n", - asctime(localtime(&ts)), (uint) ntohl(x->proto), - NTOHLL(x->bytes), NTOHLL(x->pkts)); + *len = sprintf(s, + "Ts: %.24s Proto: %3u Bytes (1s): %10llu Pkts (1s): %10llu\n", + asctime(localtime(&ts)), (uint) ntohl(x->proto), + NTOHLL(x->bytes), NTOHLL(x->pkts)); return s; }; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/topdest.c pre_checkin/como/src/modules/topdest.c --- clean/como/src/modules/topdest.c 2005-01-24 16:45:08.000000000 +0000 +++ pre_checkin/como/src/modules/topdest.c 2005-02-14 11:29:24.574911930 +0000 @@ -175,7 +175,7 @@ } static char * -print(char *buf) +print(char *buf, size_t *len) { FLOWDESC *x = F(buf - sizeof(rec_t)); static char s[2048]; @@ -184,9 +184,10 @@ addr.s_addr = N32(x->dst_ip); - sprintf(s, "Ts: %.24s Dest ip: %15s Bytes (1s): %llu\tPkts (1s): %llu\n", - asctime(localtime(&ts)), inet_ntoa(addr), - NTOHLL(x->bytes), NTOHLL(x->pkts)); + *len = sprintf(s, + "Ts: %.24s Dest ip: %15s Bytes (1s): %llu\tPkts (1s): %llu\n", + asctime(localtime(&ts)), inet_ntoa(addr), + NTOHLL(x->bytes), NTOHLL(x->pkts)); return s; }; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/trace.c pre_checkin/como/src/modules/trace.c --- clean/como/src/modules/trace.c 2005-01-27 18:03:59.000000000 +0000 +++ pre_checkin/como/src/modules/trace.c 2005-02-14 11:29:24.574911930 +0000 @@ -185,7 +185,7 @@ #define IP_ADDR(x) (inet_ntoa(*(struct in_addr*)&(N32(x)))) static char * -print (char *buf) +print (char *buf, size_t *out_len) { static char out[OUT_BUFF_SIZ]; static char tss[TIMESTR_LEN + 1]; @@ -298,7 +298,9 @@ } else { sprintf(out + len, "[unrecognized protocol...]"); } - + + *out_len = strlen(out); + return out; } diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/tuple.c pre_checkin/como/src/modules/tuple.c --- clean/como/src/modules/tuple.c 2005-01-25 22:07:20.000000000 +0000 +++ pre_checkin/como/src/modules/tuple.c 2005-02-14 11:29:24.575911807 +0000 @@ -136,7 +136,7 @@ } static char * -print(char *buf) +print(char *buf, size_t *len) { FLOWDESC *x = F(buf - sizeof(rec_t)); static char s[2048]; @@ -150,11 +150,11 @@ sprintf(src, "%s", inet_ntoa(saddr)); sprintf(dst, "%s", inet_ntoa(daddr)); - sprintf(s, "Time: %.24s %15s %15s sport %5u dport %5u proto: %3u " - "Bytes: %8llu Packets: %8llu", - asctime(localtime(&ts)), src, dst, - (uint) H16(x->src_port), (uint) H16(x->dst_port), - (uint) x->proto, NTOHLL(x->bytes), NTOHLL(x->pkts)); + *len = sprintf(s, "Time: %.24s %15s %15s sport %5u dport %5u proto: %3u " + "Bytes: %8llu Packets: %8llu", + asctime(localtime(&ts)), src, dst, + (uint) H16(x->src_port), (uint) H16(x->dst_port), + (uint) x->proto, NTOHLL(x->bytes), NTOHLL(x->pkts)); return s; }; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/modules/utilization.c pre_checkin/como/src/modules/utilization.c --- clean/como/src/modules/utilization.c 2005-01-25 17:59:52.000000000 +0000 +++ pre_checkin/como/src/modules/utilization.c 2005-02-14 11:29:24.575911807 +0000 @@ -117,17 +117,16 @@ } static char * -print(char *buf) +print(char *buf, size_t *len) { static char s[2048]; FLOWDESC *x = F(buf - sizeof(rec_t)); time_t ts = (time_t) ntohl(x->ts); - sprintf(s, "Time: %.24s Bytes: %10u HighWaterMark: %10u", - asctime(localtime(&ts)), (uint) ntohl(x->bytes), - (uint) ntohl(x->hi_watermark)); - + *len = sprintf(s, "Time: %.24s Bytes: %10u HighWaterMark: %10u", + asctime(localtime(&ts)), (uint) ntohl(x->bytes), + (uint) ntohl(x->hi_watermark)); return s; } diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf --exclude '.nfs*' clean/como/src/apps/getpcap.py pre_checkin/como/src/apps/getpcap.py --- clean/como/src/apps/getpcap.py 1970-01-01 01:00:00.000000000 +0100 +++ pre_checkin/como/src/apps/getpcap.py 2005-02-14 13:19:53.122085681 +0000 @@ -0,0 +1,41 @@ +#! /usr/bin/env python + +import sys +import socket + +host = "localhost" +if len(sys.argv) == 2: + host = sys.argv[1] +elif len(sys.argv) > 2: + print "Only valid argument is a hostname to connect to" + sys.exit(1) + +hostinfo = socket.getaddrinfo(host, 44444, socket.AF_INET, socket.SOCK_STREAM)[0] +sock = socket.socket(hostinfo[0], hostinfo[1], hostinfo[2]) +sock.connect(hostinfo[4]) + +sock.send("Module: full_cap\n") +sock.send("Tmin: 0\n\n") + +# Magic +sys.stdout.write("\xd4\xc3\xb2\xa1") +# Version major +sys.stdout.write("\x02\x00") +# Version minor +sys.stdout.write("\x04\x00") +# Timezone +sys.stdout.write("\0\0\0\0") +# Sigfigs +sys.stdout.write("\0\0\0\0") +# Snaplen +sys.stdout.write("\xff\xff\x00\x00") +# Linktype +sys.stdout.write("\x01\x00\x00\x00") + +while True: + b = sock.recv(4096) + if b == "": + break + sys.stdout.write(b) + +sys.exit(0)