libosmo-netif[master]: tests: osmo-pcap: Allow different l2 pkts

2017-08-09 Thread Harald Welte

Patch Set 2: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/3064
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ie62fa0a8e45e1e141edb64b116dad185ad9c7a5f
Gerrit-PatchSet: 2
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[MERGED] libosmo-netif[master]: tests: osmo-pcap: Allow different l2 pkts

2017-08-09 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: tests: osmo-pcap: Allow different l2 pkts
..


tests: osmo-pcap: Allow different l2 pkts

Before this patch, ETH was assumed and other types were not supported.
This patch also adds Linux cooked packet support for L2.

Change-Id: Ie62fa0a8e45e1e141edb64b116dad185ad9c7a5f
---
M tests/osmo-pcap-test/Makefile.am
A tests/osmo-pcap-test/l2_eth.c
A tests/osmo-pcap-test/l2_sll.c
M tests/osmo-pcap-test/l3_ipv4.c
M tests/osmo-pcap-test/l4_tcp.c
M tests/osmo-pcap-test/l4_udp.c
M tests/osmo-pcap-test/pcap.c
M tests/osmo-pcap-test/proto.c
M tests/osmo-pcap-test/proto.h
9 files changed, 189 insertions(+), 50 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/tests/osmo-pcap-test/Makefile.am b/tests/osmo-pcap-test/Makefile.am
index a256005..3e5bdf1 100644
--- a/tests/osmo-pcap-test/Makefile.am
+++ b/tests/osmo-pcap-test/Makefile.am
@@ -3,6 +3,8 @@
 check_PROGRAMS = osmo-pcap-test
 
 osmo_pcap_test_SOURCES = proto.c   \
+l2_eth.c   \
+l2_sll.c   \
 l3_ipv4.c  \
 l4_tcp.c   \
 l4_udp.c   \
diff --git a/tests/osmo-pcap-test/l2_eth.c b/tests/osmo-pcap-test/l2_eth.c
new file mode 100644
index 000..3171fd7
--- /dev/null
+++ b/tests/osmo-pcap-test/l2_eth.c
@@ -0,0 +1,48 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso 
+ * (C) 2012 by On Waves ehf 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#include "proto.h"
+
+#define PRINT_CMP(...)
+
+static int unsigned l2_eth_pkt_l3proto_num(const uint8_t *pkt)
+{
+   const struct ethhdr *eh = (const struct ethhdr *)pkt;
+   switch(ntohs(eh->h_proto)) {
+   case ETH_P_IP:
+   return htons(AF_INET);
+   default:
+   return eh->h_proto;
+   }
+}
+
+static unsigned int l2_eth_pkt_l2hdr_len(const uint8_t *pkt)
+{
+
+   return ETH_HLEN;
+}
+
+static struct osmo_pcap_proto_l2 eth = {
+   //.l2protonum   = ETH_P_IP,
+   .l2protonum = DLT_EN10MB,
+   .l2pkt_hdr_len  = l2_eth_pkt_l2hdr_len,
+   .l3pkt_proto= l2_eth_pkt_l3proto_num,
+};
+
+void l2_eth_init(void)
+{
+   osmo_pcap_proto_l2_register();
+}
diff --git a/tests/osmo-pcap-test/l2_sll.c b/tests/osmo-pcap-test/l2_sll.c
new file mode 100644
index 000..5a600ff
--- /dev/null
+++ b/tests/osmo-pcap-test/l2_sll.c
@@ -0,0 +1,47 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso 
+ * (C) 2012 by On Waves ehf 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#include "proto.h"
+
+#define PRINT_CMP(...)
+
+static unsigned int l2_sll_pkt_l3proto_num(const uint8_t *pkt)
+{
+   const struct sll_header *lh = (const struct sll_header *)pkt;
+   switch(ntohs(lh->sll_protocol)) {
+   case ETH_P_IP:
+   return htons(AF_INET);
+   default:
+   return lh->sll_protocol;
+   }
+}
+
+static unsigned int l2_sll_pkt_l2hdr_len(const uint8_t *pkt)
+{
+
+   return SLL_HDR_LEN;
+}
+
+static struct osmo_pcap_proto_l2 sll = {
+   .l2protonum = DLT_LINUX_SLL,
+   .l2pkt_hdr_len  = l2_sll_pkt_l2hdr_len,
+   .l3pkt_proto= l2_sll_pkt_l3proto_num,
+};
+
+void l2_sll_init(void)
+{
+   osmo_pcap_proto_l2_register();
+}
diff --git a/tests/osmo-pcap-test/l3_ipv4.c b/tests/osmo-pcap-test/l3_ipv4.c
index 83e3479..521a803 100644
--- a/tests/osmo-pcap-test/l3_ipv4.c
+++ b/tests/osmo-pcap-test/l3_ipv4.c
@@ -16,29 +16,27 @@
 
 #define PRINT_CMP(...)
 
-static int l3_ipv4_pkt_l4proto_num(const uint8_t *pkt)
+static unsigned int l3_ipv4_pkt_l4proto_num(const uint8_t *pkt)
 {
const struct iphdr *iph = (const struct iphdr *)pkt;
 
return iph->protocol;
 }
 
-static int l3_ipv4_pkt_l3hdr_len(const uint8_t *pkt)
+static unsigned int l3_ipv4_pkt_l3hdr_len(const uint8_t *pkt)
 {
const struct iphdr *iph = (const struct iphdr *)pkt;
 
return iph->ihl << 2;
 }
 
-static struct osmo_pcap_proto_l2l3 ipv4 = {
-   .l2protonum = ETH_P_IP,
+static struct osmo_pcap_proto_l3 ipv4 = {
.l3protonum = AF_INET,
-   .l2hdr_len  = ETH_HLEN,
.l3pkt_hdr_len  = l3_ipv4_pkt_l3hdr_len,

[PATCH] libosmo-netif[master]: tests: osmo-pcap: Allow different l2 pkts

2017-08-08 Thread Pau Espin Pedrol
Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3064

to look at the new patch set (#2).

tests: osmo-pcap: Allow different l2 pkts

Before this patch, ETH was assumed and other types were not supported.
This patch also adds Linux cooked packet support for L2.

Change-Id: Ie62fa0a8e45e1e141edb64b116dad185ad9c7a5f
---
M tests/osmo-pcap-test/Makefile.am
A tests/osmo-pcap-test/l2_eth.c
A tests/osmo-pcap-test/l2_sll.c
M tests/osmo-pcap-test/l3_ipv4.c
M tests/osmo-pcap-test/l4_tcp.c
M tests/osmo-pcap-test/l4_udp.c
M tests/osmo-pcap-test/pcap.c
M tests/osmo-pcap-test/proto.c
M tests/osmo-pcap-test/proto.h
9 files changed, 189 insertions(+), 50 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/64/3064/2

diff --git a/tests/osmo-pcap-test/Makefile.am b/tests/osmo-pcap-test/Makefile.am
index a256005..3e5bdf1 100644
--- a/tests/osmo-pcap-test/Makefile.am
+++ b/tests/osmo-pcap-test/Makefile.am
@@ -3,6 +3,8 @@
 check_PROGRAMS = osmo-pcap-test
 
 osmo_pcap_test_SOURCES = proto.c   \
+l2_eth.c   \
+l2_sll.c   \
 l3_ipv4.c  \
 l4_tcp.c   \
 l4_udp.c   \
diff --git a/tests/osmo-pcap-test/l2_eth.c b/tests/osmo-pcap-test/l2_eth.c
new file mode 100644
index 000..3171fd7
--- /dev/null
+++ b/tests/osmo-pcap-test/l2_eth.c
@@ -0,0 +1,48 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso 
+ * (C) 2012 by On Waves ehf 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#include "proto.h"
+
+#define PRINT_CMP(...)
+
+static int unsigned l2_eth_pkt_l3proto_num(const uint8_t *pkt)
+{
+   const struct ethhdr *eh = (const struct ethhdr *)pkt;
+   switch(ntohs(eh->h_proto)) {
+   case ETH_P_IP:
+   return htons(AF_INET);
+   default:
+   return eh->h_proto;
+   }
+}
+
+static unsigned int l2_eth_pkt_l2hdr_len(const uint8_t *pkt)
+{
+
+   return ETH_HLEN;
+}
+
+static struct osmo_pcap_proto_l2 eth = {
+   //.l2protonum   = ETH_P_IP,
+   .l2protonum = DLT_EN10MB,
+   .l2pkt_hdr_len  = l2_eth_pkt_l2hdr_len,
+   .l3pkt_proto= l2_eth_pkt_l3proto_num,
+};
+
+void l2_eth_init(void)
+{
+   osmo_pcap_proto_l2_register();
+}
diff --git a/tests/osmo-pcap-test/l2_sll.c b/tests/osmo-pcap-test/l2_sll.c
new file mode 100644
index 000..5a600ff
--- /dev/null
+++ b/tests/osmo-pcap-test/l2_sll.c
@@ -0,0 +1,47 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso 
+ * (C) 2012 by On Waves ehf 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#include "proto.h"
+
+#define PRINT_CMP(...)
+
+static unsigned int l2_sll_pkt_l3proto_num(const uint8_t *pkt)
+{
+   const struct sll_header *lh = (const struct sll_header *)pkt;
+   switch(ntohs(lh->sll_protocol)) {
+   case ETH_P_IP:
+   return htons(AF_INET);
+   default:
+   return lh->sll_protocol;
+   }
+}
+
+static unsigned int l2_sll_pkt_l2hdr_len(const uint8_t *pkt)
+{
+
+   return SLL_HDR_LEN;
+}
+
+static struct osmo_pcap_proto_l2 sll = {
+   .l2protonum = DLT_LINUX_SLL,
+   .l2pkt_hdr_len  = l2_sll_pkt_l2hdr_len,
+   .l3pkt_proto= l2_sll_pkt_l3proto_num,
+};
+
+void l2_sll_init(void)
+{
+   osmo_pcap_proto_l2_register();
+}
diff --git a/tests/osmo-pcap-test/l3_ipv4.c b/tests/osmo-pcap-test/l3_ipv4.c
index 83e3479..521a803 100644
--- a/tests/osmo-pcap-test/l3_ipv4.c
+++ b/tests/osmo-pcap-test/l3_ipv4.c
@@ -16,29 +16,27 @@
 
 #define PRINT_CMP(...)
 
-static int l3_ipv4_pkt_l4proto_num(const uint8_t *pkt)
+static unsigned int l3_ipv4_pkt_l4proto_num(const uint8_t *pkt)
 {
const struct iphdr *iph = (const struct iphdr *)pkt;
 
return iph->protocol;
 }
 
-static int l3_ipv4_pkt_l3hdr_len(const uint8_t *pkt)
+static unsigned int l3_ipv4_pkt_l3hdr_len(const uint8_t *pkt)
 {
const struct iphdr *iph = (const struct iphdr *)pkt;
 
return iph->ihl << 2;
 }
 
-static struct osmo_pcap_proto_l2l3 ipv4 = {
-   .l2protonum = ETH_P_IP,
+static struct osmo_pcap_proto_l3 ipv4 = {
.l3protonum = AF_INET,
-   .l2hdr_len  = ETH_HLEN,
.l3pkt_hdr_len  = l3_ipv4_pkt_l3hdr_len,
.l4pkt_proto= 

libosmo-netif[master]: tests: osmo-pcap: Allow different l2 pkts

2017-08-08 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/3064
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ie62fa0a8e45e1e141edb64b116dad185ad9c7a5f
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


libosmo-netif[master]: tests: osmo-pcap: Allow different l2 pkts

2017-06-28 Thread Harald Welte

Patch Set 1: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/3064
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ie62fa0a8e45e1e141edb64b116dad185ad9c7a5f
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] libosmo-netif[master]: tests: osmo-pcap: Allow different l2 pkts

2017-06-26 Thread Pau Espin Pedrol

Review at  https://gerrit.osmocom.org/3064

tests: osmo-pcap: Allow different l2 pkts

Before this patch, ETH was assumed and other types were not supported.
This patch also adds Linux cooked packet support for L2.

Change-Id: Ie62fa0a8e45e1e141edb64b116dad185ad9c7a5f
---
M tests/osmo-pcap-test/Makefile.am
A tests/osmo-pcap-test/l2_eth.c
A tests/osmo-pcap-test/l2_sll.c
M tests/osmo-pcap-test/l3_ipv4.c
M tests/osmo-pcap-test/l4_tcp.c
M tests/osmo-pcap-test/l4_udp.c
M tests/osmo-pcap-test/pcap.c
M tests/osmo-pcap-test/proto.c
M tests/osmo-pcap-test/proto.h
9 files changed, 189 insertions(+), 50 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/64/3064/1

diff --git a/tests/osmo-pcap-test/Makefile.am b/tests/osmo-pcap-test/Makefile.am
index a256005..3e5bdf1 100644
--- a/tests/osmo-pcap-test/Makefile.am
+++ b/tests/osmo-pcap-test/Makefile.am
@@ -3,6 +3,8 @@
 check_PROGRAMS = osmo-pcap-test
 
 osmo_pcap_test_SOURCES = proto.c   \
+l2_eth.c   \
+l2_sll.c   \
 l3_ipv4.c  \
 l4_tcp.c   \
 l4_udp.c   \
diff --git a/tests/osmo-pcap-test/l2_eth.c b/tests/osmo-pcap-test/l2_eth.c
new file mode 100644
index 000..3171fd7
--- /dev/null
+++ b/tests/osmo-pcap-test/l2_eth.c
@@ -0,0 +1,48 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso 
+ * (C) 2012 by On Waves ehf 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#include "proto.h"
+
+#define PRINT_CMP(...)
+
+static int unsigned l2_eth_pkt_l3proto_num(const uint8_t *pkt)
+{
+   const struct ethhdr *eh = (const struct ethhdr *)pkt;
+   switch(ntohs(eh->h_proto)) {
+   case ETH_P_IP:
+   return htons(AF_INET);
+   default:
+   return eh->h_proto;
+   }
+}
+
+static unsigned int l2_eth_pkt_l2hdr_len(const uint8_t *pkt)
+{
+
+   return ETH_HLEN;
+}
+
+static struct osmo_pcap_proto_l2 eth = {
+   //.l2protonum   = ETH_P_IP,
+   .l2protonum = DLT_EN10MB,
+   .l2pkt_hdr_len  = l2_eth_pkt_l2hdr_len,
+   .l3pkt_proto= l2_eth_pkt_l3proto_num,
+};
+
+void l2_eth_init(void)
+{
+   osmo_pcap_proto_l2_register();
+}
diff --git a/tests/osmo-pcap-test/l2_sll.c b/tests/osmo-pcap-test/l2_sll.c
new file mode 100644
index 000..5a600ff
--- /dev/null
+++ b/tests/osmo-pcap-test/l2_sll.c
@@ -0,0 +1,47 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso 
+ * (C) 2012 by On Waves ehf 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#include "proto.h"
+
+#define PRINT_CMP(...)
+
+static unsigned int l2_sll_pkt_l3proto_num(const uint8_t *pkt)
+{
+   const struct sll_header *lh = (const struct sll_header *)pkt;
+   switch(ntohs(lh->sll_protocol)) {
+   case ETH_P_IP:
+   return htons(AF_INET);
+   default:
+   return lh->sll_protocol;
+   }
+}
+
+static unsigned int l2_sll_pkt_l2hdr_len(const uint8_t *pkt)
+{
+
+   return SLL_HDR_LEN;
+}
+
+static struct osmo_pcap_proto_l2 sll = {
+   .l2protonum = DLT_LINUX_SLL,
+   .l2pkt_hdr_len  = l2_sll_pkt_l2hdr_len,
+   .l3pkt_proto= l2_sll_pkt_l3proto_num,
+};
+
+void l2_sll_init(void)
+{
+   osmo_pcap_proto_l2_register();
+}
diff --git a/tests/osmo-pcap-test/l3_ipv4.c b/tests/osmo-pcap-test/l3_ipv4.c
index 83e3479..521a803 100644
--- a/tests/osmo-pcap-test/l3_ipv4.c
+++ b/tests/osmo-pcap-test/l3_ipv4.c
@@ -16,29 +16,27 @@
 
 #define PRINT_CMP(...)
 
-static int l3_ipv4_pkt_l4proto_num(const uint8_t *pkt)
+static unsigned int l3_ipv4_pkt_l4proto_num(const uint8_t *pkt)
 {
const struct iphdr *iph = (const struct iphdr *)pkt;
 
return iph->protocol;
 }
 
-static int l3_ipv4_pkt_l3hdr_len(const uint8_t *pkt)
+static unsigned int l3_ipv4_pkt_l3hdr_len(const uint8_t *pkt)
 {
const struct iphdr *iph = (const struct iphdr *)pkt;
 
return iph->ihl << 2;
 }
 
-static struct osmo_pcap_proto_l2l3 ipv4 = {
-   .l2protonum = ETH_P_IP,
+static struct osmo_pcap_proto_l3 ipv4 = {
.l3protonum = AF_INET,
-   .l2hdr_len  = ETH_HLEN,
.l3pkt_hdr_len  = l3_ipv4_pkt_l3hdr_len,
.l4pkt_proto= l3_ipv4_pkt_l4proto_num,
 };
 
-void l2l3_ipv4_init(void)
+void l3_ipv4_init(void)
 {
-   osmo_pcap_proto_l2l3_register();
+