}
}
-void GREProtocol::send_packet(uint16_t proto, const string &data)
+void GREProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
{
char buf[4096];
gre_header *gre = (gre_header *)buf;
gre->protocol_type = htons(proto);
char *ptr = buf + sizeof(*gre);
- int seq_be = htonl(seq++);
+ int seq_be = htonl(seq++); // Ignore incoming_seq.
memcpy(ptr, &seq_be, sizeof(seq_be));
ptr += sizeof(seq_be);
return sock;
}
-void GREProtocol::read_packet(Reorderer *sender)
+void GREProtocol::read_packet(Protocol *sender)
{
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(addr);
//printf("gre packet: proto=%x\n", ntohs(gre->protocol_type));
- sender->handle_packet(ntohs(gre->protocol_type), string(ptr, buf + ret), seq);
+ sender->send_packet(ntohs(gre->protocol_type), string(ptr, buf + ret), seq);
}
class GREProtocol : public Protocol {
public:
GREProtocol(const in6_addr &myaddr, const in6_addr &dst);
- virtual void send_packet(uint16_t proto, const std::string &data);
+ virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
virtual int fd() const;
- void read_packet(Reorderer* sender);
+ void read_packet(Protocol* sender);
private:
int seq;
class Protocol {
public:
- virtual void send_packet(uint16_t proto, const std::string &data) = 0;
+ virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq) = 0;
virtual int fd() const = 0;
};
{
}
-void Reorderer::handle_packet(uint16_t proto, const string& data, int seq)
+void Reorderer::send_packet(uint16_t proto, const string& data, int seq)
{
bool silence = false;
if (packet_buffer.size() >= PACKET_BUFFER_SIZE) {
// printf("seq=%d\n", front_seq);
//}
const string &data = packet_buffer.top().data;
- send_packet(packet_buffer.top().proto, data, silence);
+ check_ts_discontinuity(packet_buffer.top().proto, data, silence);
+ sender->send_packet(proto, data, seq);
packet_buffer.pop();
last_seq = front_seq;
if (!silence && !packet_buffer.empty()) {
}
}
-void Reorderer::send_packet(uint16_t proto, const string &data, bool silence)
+void Reorderer::check_ts_discontinuity(uint16_t proto, const string &data, bool silence)
{
if (data.size() == 1344) {
for (int i = 0; i < 7; ++i) {
}
}
}
- sender->send_packet(proto, data);
}
#ifndef _REORDERER_H
#define _REORDERER_H 1
+#include <assert.h>
#include <stdint.h>
#include <algorithm>
#include <string>
#include <vector>
-class Protocol;
+#include "protocol.h"
struct GREPacket {
int seq;
}
};
-class Reorderer {
+class Reorderer : public Protocol {
public:
Reorderer(Protocol* sender);
- void handle_packet(uint16_t proto, const std::string& data, int seq);
+ void send_packet(uint16_t proto, const std::string& data, int seq);
+ virtual int fd() const { assert(false); }
private:
- void send_packet(uint16_t proto, const std::string &data, bool silence);
+ void check_ts_discontinuity(uint16_t proto, const std::string &data, bool silence);
Protocol* sender;
int last_seq;
: tunfd(tun_open(devname)) {
}
-void TUNProtocol::send_packet(uint16_t proto, const string &data)
+void TUNProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
{
char buf[4096];
ptr += 2;
//fprintf(stderr, "tun packet: flags=%x proto=%x len=%d\n",
// flags, proto, ret - 4);
- sender->send_packet(proto, string(ptr, buf + ret));
+ sender->send_packet(proto, string(ptr, buf + ret), -1);
}
class TUNProtocol : public Protocol {
public:
TUNProtocol(const char *devname);
- virtual void send_packet(uint16_t proto, const std::string &data);
+ virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
virtual int fd() const;
void read_packet(Protocol* sender);