blob: 0a4164c738303f64a58d2c792dc6127f740b91ff [file] [log] [blame]
Neels Hofmeyr9f796642015-09-24 17:32:30 +02001/* GTP Hub Implementation */
2
3/* (C) 2015 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4 * All Rights Reserved
5 *
6 * gtphub_ext.c -- ext means extern. This file is kept separate so that these
7 * functions can be wrapped for gtphub_test.c. When a function and its callers
8 * are in the same compilational unit, the wrappability may be optimized away.
9 *
10 * Author: Neels Hofmeyr
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Affero General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include <string.h>
27
28#include <openbsc/gtphub.h>
29#include <osmocom/core/utils.h>
30
31#define __llist_first(head) (((head)->next == (head)) ? NULL : (head)->next)
32#define llist_first(head, type, entry) llist_entry(__llist_first(head), type, entry)
33
34int gtphub_resolve_ggsn_addr(struct gtphub *hub,
35 struct osmo_sockaddr *result,
36 struct gtp_packet_desc *p)
37{
38 /* TODO This is just hardcodedly returning the first known address.
39 * Should resolve from actual subscriber data. */
40 struct gtphub_peer *peer = llist_first(&hub->to_ggsns[GTPH_PLANE_CTRL].peers,
41 struct gtphub_peer, entry);
42 if (!peer)
43 return -1;
44
45 struct gtphub_peer_addr *pa = llist_first(&peer->addresses,
46 struct gtphub_peer_addr, entry);
47 if (!pa)
48 return -1;
49
50 struct gtphub_peer_port *pp = llist_first(&pa->ports,
51 struct gtphub_peer_port, entry);
52 if (!pp)
53 return -1;
54
55 *result = pp->sa;
56 return 0;
57}
58