Add GTP hub initial code base.
First steps towards a new GTP hub. The aim is to mux GTP connections, so that
multiple SGSN <--> GGSN links can pass through a single point. Background:
allow having more than one SGSN, possibly in various remote locations.
The recent addition of OAP to GSUP is related to the same background idea.
(This is a collapsed patch of various changes that do not make sense to review
in chronological order anymore, since a lot of it has thorougly transmorphed
after it was first committed.)
Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gtphub_ext.c b/openbsc/src/gprs/gtphub_ext.c
new file mode 100644
index 0000000..0a4164c
--- /dev/null
+++ b/openbsc/src/gprs/gtphub_ext.c
@@ -0,0 +1,58 @@
+/* GTP Hub Implementation */
+
+/* (C) 2015 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ * All Rights Reserved
+ *
+ * gtphub_ext.c -- ext means extern. This file is kept separate so that these
+ * functions can be wrapped for gtphub_test.c. When a function and its callers
+ * are in the same compilational unit, the wrappability may be optimized away.
+ *
+ * Author: Neels Hofmeyr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+
+#include <openbsc/gtphub.h>
+#include <osmocom/core/utils.h>
+
+#define __llist_first(head) (((head)->next == (head)) ? NULL : (head)->next)
+#define llist_first(head, type, entry) llist_entry(__llist_first(head), type, entry)
+
+int gtphub_resolve_ggsn_addr(struct gtphub *hub,
+ struct osmo_sockaddr *result,
+ struct gtp_packet_desc *p)
+{
+ /* TODO This is just hardcodedly returning the first known address.
+ * Should resolve from actual subscriber data. */
+ struct gtphub_peer *peer = llist_first(&hub->to_ggsns[GTPH_PLANE_CTRL].peers,
+ struct gtphub_peer, entry);
+ if (!peer)
+ return -1;
+
+ struct gtphub_peer_addr *pa = llist_first(&peer->addresses,
+ struct gtphub_peer_addr, entry);
+ if (!pa)
+ return -1;
+
+ struct gtphub_peer_port *pp = llist_first(&pa->ports,
+ struct gtphub_peer_port, entry);
+ if (!pp)
+ return -1;
+
+ *result = pp->sa;
+ return 0;
+}
+