aboutsummaryrefslogtreecommitdiffstats
path: root/tests/osmo-pcap-test/l4_tcp.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2012-06-28 12:53:45 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2012-06-28 16:42:22 +0200
commit75755dd7d948992d6c5d05f298559f01b511607d (patch)
treefa6276508c9ef6f1c8e5a16238b6d2149b3e9a52 /tests/osmo-pcap-test/l4_tcp.c
parent729a0917ac17e2c5a70ab24cc884ff68a7df52af (diff)
test: add osmo-pcap-test infrastructure
This patch adds the osmo-pcap-test infrastructure that allows you to take packets stored in one pcap file, convert them to msgb and pass it to some function. The infrastructure also provides timing reconstruction based on the pcap file information. This is useful for easy protocol development, automated testing and fuzzying of the existing code to validate the code. Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
Diffstat (limited to 'tests/osmo-pcap-test/l4_tcp.c')
-rw-r--r--tests/osmo-pcap-test/l4_tcp.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/osmo-pcap-test/l4_tcp.c b/tests/osmo-pcap-test/l4_tcp.c
new file mode 100644
index 0000000..1e024b5
--- /dev/null
+++ b/tests/osmo-pcap-test/l4_tcp.c
@@ -0,0 +1,38 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso <pablo@gnumonks.org>
+ * (C) 2012 by On Waves ehf <http://www.on-waves.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later vers
+ */
+
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+
+#include "proto.h"
+
+static int l4_tcp_pkt_hdr_len(const uint8_t *pkt)
+{
+ const struct tcphdr *tcph = (const struct tcphdr *)pkt;
+
+ return tcph->doff << 2;
+}
+
+static int l4_tcp_pkt_no_data(const uint8_t *pkt)
+{
+ const struct tcphdr *tcph = (const struct tcphdr *)pkt;
+ return tcph->syn || tcph->fin || tcph->rst || !tcph->psh;
+}
+
+static struct osmo_pcap_proto_l4 tcp = {
+ .l4protonum = IPPROTO_TCP,
+ .l4pkt_hdr_len = l4_tcp_pkt_hdr_len,
+ .l4pkt_no_data = l4_tcp_pkt_no_data,
+};
+
+void l4_tcp_init(void)
+{
+ osmo_pcap_proto_l4_register(&tcp);
+}