From f40a5721ea02d805342b16b78190202aae56f6c3 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 10 Feb 2014 17:55:48 +0100 Subject: [PATCH] gtp: reorganize headers * gtp_nl.h now contains exported netlink attributes and commands to userspace. * gtp.h contains internal definition for the GTP protocol implementation. --- gtp-cfg-add.c | 2 +- gtp-tunnel.c | 2 +- gtp.c | 41 +---------------------------- gtp.h | 71 +++++++++++++++++++++++++++------------------------ gtp_nl.h | 40 +++++++++++++++++++++++++++++ gtpnl.c | 2 +- 6 files changed, 82 insertions(+), 76 deletions(-) create mode 100644 gtp_nl.h diff --git a/gtp-cfg-add.c b/gtp-cfg-add.c index 3becf8d..dd47f49 100644 --- a/gtp-cfg-add.c +++ b/gtp-cfg-add.c @@ -6,7 +6,7 @@ #include #include -#include "gtp.h" +#include "gtp_nl.h" #include "genl.h" static uint32_t seq; diff --git a/gtp-tunnel.c b/gtp-tunnel.c index de1c1b0..06826a5 100644 --- a/gtp-tunnel.c +++ b/gtp-tunnel.c @@ -10,7 +10,7 @@ #include #include -#include "gtp.h" +#include "gtp_nl.h" #include "genl.h" static int diff --git a/gtp.c b/gtp.c index de6b4c3..0433b79 100644 --- a/gtp.c +++ b/gtp.c @@ -25,46 +25,7 @@ #include #include "gtp.h" - -/* Resides in include/uapi/linux/udp.h */ -#ifndef UDP_ENCAP_GTP0 -#define UDP_ENCAP_GTP0 4 -#endif - -#ifndef UDP_ENCAP_GTP1U -#define UDP_ENCAP_GTP1U 5 -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) -#define pcpu_sw_netstats pcpu_tstats -#endif - -/* general GTP protocol related definitions */ - -#define GTP0_PORT 3386 -#define GTP1U_PORT 2152 - -#define GTP_TPDU 255 - -struct gtp0_header { /* According to GSM TS 09.60 */ - uint8_t flags; - uint8_t type; - uint16_t length; - uint16_t seq; - uint16_t flow; - uint8_t number; - uint8_t spare[3]; - uint64_t tid; -} __attribute__ ((packed)); - -struct gtp1_header_short { /* According to 3GPP TS 29.060 */ - uint8_t flags; - uint8_t type; - uint16_t length; - uint32_t tid; -} __attribute__ ((packed)); - -#define gtp1u_header gtp1_header_short /* XXX */ +#include "gtp_nl.h" /* implementation-specific definitions */ diff --git a/gtp.h b/gtp.h index 27c861a..19ce33d 100644 --- a/gtp.h +++ b/gtp.h @@ -1,39 +1,44 @@ -#ifndef _UAPI_LINUX_GTP_H_ +#ifndef _GTP_H_ +#define _GTP_H -enum gtp_genl_cmds { - GTP_CMD_CFG_NEW, - GTP_CMD_CFG_DELETE, - GTP_CMD_CFG_GET, - GTP_CMD_TUNNEL_NEW, - GTP_CMD_TUNNEL_DELETE, - GTP_CMD_TUNNEL_GET, +/* Resides in include/uapi/linux/udp.h */ +#ifndef UDP_ENCAP_GTP0 +#define UDP_ENCAP_GTP0 4 +#endif - GTP_CMD_TUNNEL_MAX, -}; +#ifndef UDP_ENCAP_GTP1U +#define UDP_ENCAP_GTP1U 5 +#endif -enum gtp_version { - GTP_V0 = 0, - GTP_V1, -}; +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) +#define pcpu_sw_netstats pcpu_tstats +#endif -enum gtp_cfg_attrs { - GTPA_CFG_UNSPEC = 0, - GTPA_CFG_LINK, - GTPA_CFG_LOCAL_ADDR_IPV4, - GTPA_CFG_HSIZE, - __GTPA_CFG_MAX, -}; -#define GTPA_CFG_MAX (__GTPA_CFG_MAX + 1) +/* general GTP protocol related definitions */ -enum gtp_attrs { - GTPA_UNSPEC = 0, - GTPA_LINK, - GTPA_VERSION, - GTPA_TID, /* 64 bits for GTPv1 */ - GTPA_SGSN_ADDRESS, - GTPA_MS_ADDRESS, - __GTPA_MAX, -}; -#define GTPA_MAX (__GTPA_MAX + 1) +#define GTP0_PORT 3386 +#define GTP1U_PORT 2152 -#endif /* _UAPI_LINUX_GTP_H_ */ +#define GTP_TPDU 255 + +struct gtp0_header { /* According to GSM TS 09.60 */ + uint8_t flags; + uint8_t type; + uint16_t length; + uint16_t seq; + uint16_t flow; + uint8_t number; + uint8_t spare[3]; + uint64_t tid; +} __attribute__ ((packed)); + +struct gtp1_header_short { /* According to 3GPP TS 29.060 */ + uint8_t flags; + uint8_t type; + uint16_t length; + uint32_t tid; +} __attribute__ ((packed)); + +#define gtp1u_header gtp1_header_short /* XXX */ + +#endif diff --git a/gtp_nl.h b/gtp_nl.h new file mode 100644 index 0000000..825165c --- /dev/null +++ b/gtp_nl.h @@ -0,0 +1,40 @@ +#ifndef _UAPI_LINUX_GTP_H_ +#define _UAPI_LINUX_GTP_H__ + +enum gtp_genl_cmds { + GTP_CMD_CFG_NEW, + GTP_CMD_CFG_DELETE, + GTP_CMD_CFG_GET, + GTP_CMD_TUNNEL_NEW, + GTP_CMD_TUNNEL_DELETE, + GTP_CMD_TUNNEL_GET, + + GTP_CMD_TUNNEL_MAX, +}; + +enum gtp_version { + GTP_V0 = 0, + GTP_V1, +}; + +enum gtp_cfg_attrs { + GTPA_CFG_UNSPEC = 0, + GTPA_CFG_LINK, + GTPA_CFG_LOCAL_ADDR_IPV4, + GTPA_CFG_HSIZE, + __GTPA_CFG_MAX, +}; +#define GTPA_CFG_MAX (__GTPA_CFG_MAX + 1) + +enum gtp_attrs { + GTPA_UNSPEC = 0, + GTPA_LINK, + GTPA_VERSION, + GTPA_TID, /* 64 bits for GTPv1 */ + GTPA_SGSN_ADDRESS, + GTPA_MS_ADDRESS, + __GTPA_MAX, +}; +#define GTPA_MAX (__GTPA_MAX + 1) + +#endif /* _UAPI_LINUX_GTP_H_ */ diff --git a/gtpnl.c b/gtpnl.c index 10040c7..e98b9da 100644 --- a/gtpnl.c +++ b/gtpnl.c @@ -1,6 +1,6 @@ #include #include -#include "gtp.h" +#include "gtp_nl.h" void gtp_build_payload(struct nlmsghdr *nlh, uint64_t tid, uint32_t ifidx, uint32_t sgsn_addr, uint32_t ms_addr, uint32_t version)