Commit Graph

128 Commits

Author SHA1 Message Date
Pablo Neira Ayuso 6deca6cede gtp-tunnel: validate GTP version and interface
This patch only allows v0 and v1 as possible GTP versions and
check that the interface is valid.
2014-02-19 16:02:52 +01:00
Pablo Neira Ayuso b2309afc4d gtp: inconditionally set don't fragment flag
Don't use the inner header frag_off, this breaks GTP with fragments.
Instead, inconditionally set the DF flag, this should force us to
fragment the GTP traffic and I think this should also help with wrong
network topologies that result in network loops (that may
encapsulated GTP traffic over and over again).

Other tunnel implementation allows you to configure this.
2014-02-19 15:48:18 +01:00
Pablo Neira Ayuso 943da964ec gtp: remove GTP_CMD_CFG_* genetlink and use rtnetlink interface
This patch converts GTP_CMD_CFG_* genetlink commands to rtnl to
configure the socket address and the hashtable. The trick is to
use a workqueue to configure the socket.

This simplifies the netlink interface, now we have two:

* One to bring up the interface and the socket via rtnl.
* Another to configure tunnels / GTP version.

Before the socket configuration was separated from the the device
setup, which was sloppy.
2014-02-18 19:20:11 +01:00
Pablo Neira Ayuso 0d61da7cab gtp: fix handling of gso packets
Don't get confused with big GSO packets, we should not send
icmp frag needed as the temporary internal mtu of the linux
stack is not bounded to the real device mtu.
2014-02-18 17:22:46 +01:00
Pablo Neira Ayuso 2734d0fa31 gtp: fix MTU handling
Fix MTU handling by using the real device hardware address length
and substract the IP header + UDP header + GTPvX header.

While at it, remove flags that are not required to be reset.
2014-02-18 17:22:26 +01:00
Pablo Neira Ayuso 60f54097ba gtp: use netdev_dbg in prepare_xmit_ipv4
Instead of early debugging with pr_info.
2014-02-18 17:22:24 +01:00
Pablo Neira Ayuso c993e26f15 gtp: use lookup table to calculate gtp1u header length
Based on Harald's suggestion from the code.
2014-02-18 16:27:01 +01:00
Pablo Neira Ayuso 28da979257 gtp: consolidate error path in gtp_ip4_prepare_xmit 2014-02-13 18:31:41 +01:00
Pablo Neira Ayuso 3bc7019c7a gtp: more code preparation to add IPv6 support in the xmit path
This patch refactorizes the xmit path to consolidate the common
handling and move the specific IPv4/IPv6 handling to helper
functions. The IPv6 support is incomplete though.

This patch adds the struct gtp_pktinfo that contains the context
information for tunneling this packet. This should help to avoid
functions with lots of parameters.

Tested with IPv4, still working.
2014-02-13 18:21:39 +01:00
Pablo Neira Ayuso b4cfa8fde5 gtp: no hardcoded values in ipv6_hashfn
Use sizeof(u32) instead of 4, cleanup for readability.
2014-02-13 17:16:19 +01:00
Pablo Neira Ayuso e0ffa33de9 gtp: fix wrong header length validation in gtp1u_udp_encap_recv
Should check for gtp1_hdrlen which is the real length of the gtp1
header with all the available extensions in it.
2014-02-13 17:07:51 +01:00
Pablo Neira Ayuso 9ac4626ffa gtp: remove tid variable from gtp1u_udp_encap_recv
It's only used once.
2014-02-13 16:54:59 +01:00
Pablo Neira Ayuso bea2ae5e46 gtp: add GTP_F_* flags for GTPv1 2014-02-13 16:54:09 +01:00
Pablo Neira Ayuso ddb03d0551 gtp: use gtp1_header in gtp1u_udp_encap_recv
According to what I read in TS 29.060, that header should be enough.
2014-02-13 16:51:04 +01:00
Pablo Neira Ayuso d6eb80503d gtp: remove reference to gtp1u_header
use struct gtp1_header instead.
2014-02-13 16:45:13 +01:00
Pablo Neira Ayuso bf2b3b38a7 gtp: use endian-aware types
Good to spot endianness issues via sparse.
2014-02-13 16:37:37 +01:00
Pablo Neira Ayuso 19980460cc gtp: use GTP_VX constant when possible 2014-02-13 16:29:40 +01:00
Pablo Neira Ayuso 8f606efa88 gtp: remove redundant skb_reset_network_header().
Already done from the generic gtp_udp_encap_recv.
2014-02-13 15:35:37 +01:00
Pablo Neira Ayuso 4e2c9e3f14 gtp: check source IP address inner packet
Check if that mobile address is allow to send encapsulated packets.
2014-02-13 15:35:21 +01:00
Pablo Neira Ayuso 30d7dc1a0b gtp: initialize transmit sequence number
According to TS 09.60 (8.1.1.1), this has to be zero for the first T-PDU.
2014-02-11 03:20:16 +01:00
Pablo Neira Ayuso 5f59df2a24 gtp: fix stats memleak when releasing the gtp0 device
Make sure that the statistics are releasing when removing the module.
2014-02-11 02:20:49 +01:00
Pablo Neira Ayuso c119c2cd8d gtp: gtp0 does not have any queue
So no need to define a lock since our gtp devices have no queues.
2014-02-11 02:16:38 +01:00
Pablo Neira Ayuso 72aa29aaa6 gtp: drop input GTP packet if malformed
Harald's code was originally dropping malformed packets. Once this
code is ported to 3.14, we'll likely use iptunnel functions that
also mangle the checksum after stripping off the UDP header. Restoring
all that is expensive, so let's assume that malformed GTP packets are
unlikely to happen.
2014-02-11 02:06:40 +01:00
Pablo Neira Ayuso 3c4f414e72 gtp: refactor common encapsulation input code
Thus, we don't need to apply the same fixes to very similar code.
2014-02-11 01:51:42 +01:00
Pablo Neira Ayuso 574a0d4d06 gtp: make sure the udp is linear in the encapsulation input path
We cannot rely on the skb->len > sizeof(struct udphdr) checking that
happens just before the encapsulation since that doesn't guarantee
that the UDP header is linear. Calling __skb_pull may result in getting
us out of the skbuff head boundary. Let's use pskb_may_pull() instead
which internally calls __pskb_pull_tail() to linearize the UDP header
if needed.
2014-02-11 01:27:53 +01:00
Pablo Neira Ayuso 3d2d342b30 gtp: remove skb_orphan call from the input encap path
This call is not required at all. In __udp4_lib_rcv, just before
the encapsulation routine is called, the skb_steal_sock() call
makes sure that skb->sk is always null.
2014-02-11 00:10:27 +01:00
Pablo Neira Ayuso ddd8a74209 gtp: remove unused struct gsn
We'll use a per netns list instead.
2014-02-11 00:08:30 +01:00
Pablo Neira Ayuso edb298ba86 gtp: don't disable bottom halves when accessing the PDP context hashtable
The lists of the hashtable are already protected by rcu and
addition/removal of objects is protected via rtnl_lock and
genl_lock.

Remove the _bh from many rcu_read_{lock,unlock}(). I don't find a good
reason to disable bottom halves.
2014-02-10 18:53:58 +01:00
Pablo Neira Ayuso ac65fe65da gtp: use kernel types
u{8,16,32,64} instead of uint{8,16,32,64}_t.

Also convert several uint32_t to struct in_addr.
2014-02-10 18:35:37 +01:00
Pablo Neira Ayuso 268455a2ae gtp: initial random seed for the hash tables
I think it's very hard to deploy any hashbomb attack since the
entries are created via netlink, but let's just avoid that someone
generates traffic to spend cycles on a busy hashtable chain.
2014-02-10 18:23:43 +01:00
Pablo Neira Ayuso bb8c47d957 gtp: remove useless comment on tree / hashtable size
We already use a hashtable, the size is still hardcoded but that
should be easy to fix. I think the hashtable is just fine, no
need to add a rb-tree here.
2014-02-10 18:19:36 +01:00
Pablo Neira Ayuso 1f8f1b1ba3 genl: remove error message from library
The caller should call perror() instead.
2014-02-10 18:08:28 +01:00
Pablo Neira Ayuso 0a50537206 gtp-tunnel: fix deletion
Use the right genetlink command for deletion.
2014-02-10 18:05:58 +01:00
Pablo Neira Ayuso f40a5721ea 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.
2014-02-10 18:04:26 +01:00
Pablo Neira Ayuso a2f957390a gtp: fix wrong version number
It was including the tunnel ID.
2014-02-10 17:45:51 +01:00
Pablo Neira Ayuso de47c7a03d add gtp-tunnel command line tool
Merge gtp-tunnel-add and gtp-tunnel-get. Then, add the deletion feature.
Useful to inspect kernel configuration and for testing purposes.
2014-02-10 17:41:52 +01:00
Pablo Neira Ayuso 9ac07011ae gtp: release tunnels on module and configuration removal
This fixes a release when removing the module or destroying a
configuration.
2014-02-10 17:16:04 +01:00
Pablo Neira Ayuso df0ab6880b gtp-tunnel-get: display GTP version
# ./gtp-tunnel-get
 version 1 tid 1 ms_addr 192.168.2.1 sgsn_addr 192.168.2.1
2014-02-10 17:15:39 +01:00
Pablo Neira Ayuso 2fa9f8e151 gtp-tunnel-add: add gtp_build_payload
Simple refactoring to prepare the tunnel deletion operation.
2014-02-10 17:14:54 +01:00
Pablo Neira Ayuso d98dfb845b gtp: allow to delete tunnel entries via genetlink
Add missing code to delete tunnel entries.
2014-02-10 16:57:54 +01:00
Pablo Neira Ayuso c4cc08f2cd gtp: sanity check tunnel ID
GTPv1 allows 32-bits tunnel IDs only.
2014-02-10 14:58:07 +01:00
Pablo Neira Ayuso a7012e1376 gtp: sanity check gtp version for PDP context
make sure it's GTP_V0 or GTP_V1.
2014-02-10 14:54:43 +01:00
Pablo Neira Ayuso 2060f60afe gtp: move gtp header setup before UDP header
This is just another cleanup to prepare IPv6 support. Move code
to the correct context, just before pushing and setting up the
UDP header.
2014-02-10 14:52:41 +01:00
Pablo Neira Ayuso aa0b2e338a gtp: fix shadowed iph variable declaration
Add new old_ipv6h variable.
2014-02-10 14:46:46 +01:00
Pablo Neira Ayuso 39862e8552 gtp: clean up IPv4 header setup
To prepare IPv6 support.
2014-02-10 14:44:59 +01:00
Pablo Neira Ayuso 738e35207e gtp: fix xmit statistics
Use copy and paste of iptunnel_xmit_stats() available in 3.13.
2014-02-10 14:20:53 +01:00
Pablo Neira Ayuso 293a6a29b8 gtp: don't drop malformed packets in the input path
If the gtp tunneling code receives a too small/malformed message,
just let it continue its travel through the stack since it will
will just simply drop it itself.

This fixes a memory leak in these case, since we should release
the skbuff if the handler returns <= 0.
2014-02-10 13:44:25 +01:00
Pablo Neira Ayuso c594e57aac gtp: working input encapsulation
Several changes to get a working input handling:

* Set skb->dev to the tunnel device instead of the real_dev, to follow
  the logical flow which is:

  input packet -> eth0 -> gtp0
  eth0 <- gtp0 <- output packet

* Set skb->ip_summed = CHECKSUM_NONE to avoid a crash in skb_checksum()
  when forwarding the packet.

* dev_forward_skb(), among many other things, calls skb_scrub_packet()
  which resets the skb->mark. We already reset what we need from the
  input path and the mark should still remain the same for decapsulated
  packets for netfilter/iptables classification. So use netrx_if()
  instead.
2014-02-09 21:47:15 +01:00
Pablo Neira Ayuso b45621e1cf gtp: reset network header after decapsulation
ip_rcv() needs that the new network header after decapsulation is
set to approapriately set the transport header pointer.
2014-02-09 21:47:09 +01:00
Pablo Neira Ayuso b968ddf47f gtp: fix receival path of version 0
After this patch, it already forwards a (yet malformed) packet to
the real device. GTPv1 receival path yet untested but similar
changes that were done to GTPv0 has been done.
2014-02-05 01:14:26 +01:00