This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.org
Review at https://gerrit.osmocom.org/3404
lib/tun.h: Remove non-endian-safe redefinition of IP header
We can simply use 'struct iphdr' from netinet/ip.h to achieve
the same goal (and be portable).
Change-Id: Ieece22e127dc14a7ffdc3b05656628989ad00b32
---
M ggsn/ggsn.c
M lib/tun.h
M sgsnemu/sgsnemu.c
3 files changed, 8 insertions(+), 21 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/04/3404/1
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 00c7174..11aea78 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -34,6 +34,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <netinet/ip.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <sys/stat.h>
@@ -42,6 +43,7 @@
#include <inttypes.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <net/if.h>
#include <net/if.h>
#include <errno.h>
@@ -219,13 +221,13 @@
{
struct ippoolm_t *ipm;
struct in46_addr dst;
- struct tun_packet_t *iph = (struct tun_packet_t *)pack;
+ struct iphdr *iph = (struct iphdr *)pack;
- if (iph->ver == 4) {
+ if (iph->version == 4) {
if (len < sizeof(*iph) || len < 4*iph->ihl)
return -1;
dst.len = 4;
- dst.v4.s_addr = iph->dst;
+ dst.v4.s_addr = iph->daddr;
} else {
LOGP(DGGSN, LOGL_NOTICE, "non-IPv4 packet received from tun\n");
return -1;
diff --git a/lib/tun.h b/lib/tun.h
index ce7b91c..5143ccd 100644
--- a/lib/tun.h
+++ b/lib/tun.h
@@ -17,22 +17,6 @@
#define TUN_ADDRSIZE 128
#define TUN_NLBUFSIZE 1024
-struct tun_packet_t {
- unsigned int ver:4;
- unsigned int ihl:4;
- unsigned int dscp:6;
- unsigned int ecn:2;
- unsigned int length:16;
- unsigned int id:16;
- unsigned int flags:3;
- unsigned int fragment:13;
- unsigned int ttl:8;
- unsigned int protocol:8;
- unsigned int check:16;
- unsigned int src:32;
- unsigned int dst:32;
-};
-
/* ***********************************************************
* Information storage for each tun instance
*************************************************************/
diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c
index 90a6200..af8f9fa 100644
--- a/sgsnemu/sgsnemu.c
+++ b/sgsnemu/sgsnemu.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <netinet/ip.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <sys/stat.h>
@@ -1281,10 +1282,10 @@
{
struct iphash_t *ipm;
struct in46_addr src;
- struct tun_packet_t *iph = (struct tun_packet_t *)pack;
+ struct iphdr *iph = (struct iphdr *)pack;
src.len = 4;
- src.v4.s_addr = iph->src;
+ src.v4.s_addr = iph->saddr;
if (ipget(&ipm, &src)) {
printf("Dropping packet from invalid source address: %s\n",
--
To view, visit https://gerrit.osmocom.org/3404
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieece22e127dc14a7ffdc3b05656628989ad00b32
Gerrit-PatchSet: 1
Gerrit-Project: openggsn
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>