X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=lib%2Fpcap-file.c;h=a850d217fb68f28ec29e4f4fc8257476f6293f4e;hb=HEAD;hp=191e690e637815801269054bc286e9580a5cbbab;hpb=6b8c377a6e25b18da473c3a24dfad8ec9e01ad7f;p=cascardo%2Fovs.git diff --git a/lib/pcap-file.c b/lib/pcap-file.c index 191e690e6..a850d217f 100644 --- a/lib/pcap-file.c +++ b/lib/pcap-file.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2012, 2013, 2014 Nicira, Inc. + * Copyright (c) 2009, 2010, 2012, 2013, 2014, 2015 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,13 +23,13 @@ #include #include "byte-order.h" #include "compiler.h" +#include "dp-packet.h" #include "flow.h" #include "hmap.h" -#include "ofpbuf.h" #include "packets.h" #include "timeval.h" #include "unaligned.h" -#include "vlog.h" +#include "openvswitch/vlog.h" VLOG_DEFINE_THIS_MODULE(pcap); @@ -130,13 +130,14 @@ ovs_pcap_write_header(FILE *file) ph.snaplen = 1518; ph.network = 1; /* Ethernet */ ignore(fwrite(&ph, sizeof ph, 1, file)); + fflush(file); } int -ovs_pcap_read(FILE *file, struct ofpbuf **bufp, long long int *when) +ovs_pcap_read(FILE *file, struct dp_packet **bufp, long long int *when) { struct pcaprec_hdr prh; - struct ofpbuf *buf; + struct dp_packet *buf; void *data; size_t len; bool swap; @@ -176,13 +177,13 @@ ovs_pcap_read(FILE *file, struct ofpbuf **bufp, long long int *when) } /* Read packet. */ - buf = ofpbuf_new(len); - data = ofpbuf_put_uninit(buf, len); + buf = dp_packet_new(len); + data = dp_packet_put_uninit(buf, len); if (fread(data, len, 1, file) != 1) { int error = ferror(file) ? errno : EOF; VLOG_WARN("failed to read pcap packet: %s", ovs_retval_to_string(error)); - ofpbuf_delete(buf); + dp_packet_delete(buf); return error; } *bufp = buf; @@ -190,7 +191,7 @@ ovs_pcap_read(FILE *file, struct ofpbuf **bufp, long long int *when) } void -ovs_pcap_write(FILE *file, struct ofpbuf *buf) +ovs_pcap_write(FILE *file, struct dp_packet *buf) { struct pcaprec_hdr prh; struct timeval tv; @@ -198,10 +199,11 @@ ovs_pcap_write(FILE *file, struct ofpbuf *buf) xgettimeofday(&tv); prh.ts_sec = tv.tv_sec; prh.ts_usec = tv.tv_usec; - prh.incl_len = ofpbuf_size(buf); - prh.orig_len = ofpbuf_size(buf); + prh.incl_len = dp_packet_size(buf); + prh.orig_len = dp_packet_size(buf); ignore(fwrite(&prh, sizeof prh, 1, file)); - ignore(fwrite(ofpbuf_data(buf), ofpbuf_size(buf), 1, file)); + ignore(fwrite(dp_packet_data(buf), dp_packet_size(buf), 1, file)); + fflush(file); } struct tcp_key { @@ -213,7 +215,7 @@ struct tcp_stream { struct hmap_node hmap_node; struct tcp_key key; uint32_t seq_no; - struct ofpbuf payload; + struct dp_packet payload; }; struct tcp_reader { @@ -224,7 +226,7 @@ static void tcp_stream_destroy(struct tcp_reader *r, struct tcp_stream *stream) { hmap_remove(&r->streams, &stream->hmap_node); - ofpbuf_uninit(&stream->payload); + dp_packet_uninit(&stream->payload); free(stream); } @@ -276,7 +278,7 @@ tcp_stream_new(struct tcp_reader *r, const struct tcp_key *key, uint32_t hash) hmap_insert(&r->streams, &stream->hmap_node, hash); memcpy(&stream->key, key, sizeof *key); stream->seq_no = 0; - ofpbuf_init(&stream->payload, 2048); + dp_packet_init(&stream->payload, 2048); return stream; } @@ -284,35 +286,35 @@ tcp_stream_new(struct tcp_reader *r, const struct tcp_key *key, uint32_t hash) * extracted the packet's headers into 'flow', using flow_extract(). * * If 'packet' is a TCP packet, then the reader attempts to reconstruct the - * data stream. If successful, it returns an ofpbuf that represents the data - * stream so far. The caller may examine the data in the ofpbuf and pull off + * data stream. If successful, it returns an dp_packet that represents the data + * stream so far. The caller may examine the data in the dp_packet and pull off * any data that it has fully processed. The remaining data that the caller * does not pull off will be presented again in future calls if more data * arrives in the stream. * * Returns null if 'packet' doesn't add new data to a TCP stream. */ -struct ofpbuf * +struct dp_packet * tcp_reader_run(struct tcp_reader *r, const struct flow *flow, - const struct ofpbuf *packet) + const struct dp_packet *packet) { struct tcp_stream *stream; struct tcp_header *tcp; - struct ofpbuf *payload; + struct dp_packet *payload; unsigned int l7_length; struct tcp_key key; uint32_t hash; uint32_t seq; uint8_t flags; - const char *l7 = ofpbuf_get_tcp_payload(packet); + const char *l7 = dp_packet_get_tcp_payload(packet); if (flow->dl_type != htons(ETH_TYPE_IP) || flow->nw_proto != IPPROTO_TCP || !l7) { return NULL; } - tcp = ofpbuf_l4(packet); + tcp = dp_packet_l4(packet); flags = TCP_FLAGS(tcp->tcp_ctl); - l7_length = (char *) ofpbuf_tail(packet) - l7; + l7_length = (char *) dp_packet_tail(packet) - l7; seq = ntohl(get_16aligned_be32(&tcp->tcp_seq)); /* Construct key. */ @@ -336,7 +338,7 @@ tcp_reader_run(struct tcp_reader *r, const struct flow *flow, payload = &stream->payload; if (flags & TCP_SYN || !stream->seq_no) { - ofpbuf_clear(payload); + dp_packet_clear(payload); stream->seq_no = seq + 1; return NULL; } else if (flags & (TCP_FIN | TCP_RST)) { @@ -346,9 +348,9 @@ tcp_reader_run(struct tcp_reader *r, const struct flow *flow, /* Shift all of the existing payload to the very beginning of the * allocated space, so that we reuse allocated space instead of * continually expanding it. */ - ofpbuf_shift(payload, (char *) ofpbuf_base(payload) - (char *) ofpbuf_data(payload)); + dp_packet_shift(payload, (char *) dp_packet_base(payload) - (char *) dp_packet_data(payload)); - ofpbuf_put(payload, l7, l7_length); + dp_packet_put(payload, l7, l7_length); stream->seq_no += l7_length; return payload; } else {