blob: a142867d6c6d3a5711f431a46b121656f4239fd2 [file] [log] [blame]
Neels Hofmeyrc8a614d2015-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 * Author: Neels Hofmeyr
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <stdint.h>
25#include <sys/socket.h>
26
27#include <osmocom/core/select.h>
28#include <osmocom/core/timer.h>
Neels Hofmeyr1ba50c62015-11-20 01:28:40 +010029#include <osmocom/core/rate_ctr.h>
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020030
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +010031#include <openbsc/gprs_sgsn.h>
32
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020033
34/* support */
35
36/* TODO move to osmocom/core/socket.c ? */
37#include <netdb.h> /* for IPPROTO_* etc */
38struct osmo_sockaddr {
39 struct sockaddr_storage a;
40 socklen_t l;
41};
42
43/* TODO move to osmocom/core/socket.c ? */
44/*! \brief Initialize a sockaddr
45 * \param[out] addr Valid osmo_sockaddr pointer to write result to
46 * \param[in] family Address Family like AF_INET, AF_INET6, AF_UNSPEC
47 * \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM
48 * \param[in] proto Protocol like IPPROTO_TCP, IPPROTO_UDP
49 * \param[in] host Remote host name or IP address in string form
50 * \param[in] port Remote port number in host byte order
51 * \returns 0 on success, otherwise an error code (from getaddrinfo()).
52 *
53 * Copy the first result from a getaddrinfo() call with the given parameters to
54 * *addr and *addr_len. On error, do not change *addr and return nonzero.
55 */
56int osmo_sockaddr_init(struct osmo_sockaddr *addr,
57 uint16_t family, uint16_t type, uint8_t proto,
58 const char *host, uint16_t port);
59
60/* Conveniently pass AF_UNSPEC, SOCK_DGRAM and IPPROTO_UDP to
61 * osmo_sockaddr_init(). */
62static inline int osmo_sockaddr_init_udp(struct osmo_sockaddr *addr,
63 const char *host, uint16_t port)
64{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010065 return osmo_sockaddr_init(addr, AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP,
66 host, port);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020067}
68
69/*! \brief convert sockaddr to human readable string.
70 * \param[out] addr_str Valid pointer to a buffer of length addr_str_len.
71 * \param[in] addr_str_len Size of buffer addr_str points at.
72 * \param[out] port_str Valid pointer to a buffer of length port_str_len.
73 * \param[in] port_str_len Size of buffer port_str points at.
74 * \param[in] addr Binary representation as returned by osmo_sockaddr_init().
75 * \param[in] flags flags as passed to getnameinfo().
76 * \returns 0 on success, an error code on error.
77 *
78 * Return the IPv4 or IPv6 address string and the port (a.k.a. service) string
79 * representations of the given struct osmo_sockaddr in two caller provided
80 * char buffers. Flags of (NI_NUMERICHOST | NI_NUMERICSERV) return numeric
81 * address and port. Either one of addr_str or port_str may be NULL, in which
82 * case nothing is returned there.
83 *
84 * See also osmo_sockaddr_to_str() (less flexible, but much more convenient). */
85int osmo_sockaddr_to_strs(char *addr_str, size_t addr_str_len,
86 char *port_str, size_t port_str_len,
87 const struct osmo_sockaddr *addr,
88 int flags);
89
90
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010091/*! \brief concatenate the parts returned by osmo_sockaddr_to_strs().
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020092 * \param[in] addr Binary representation as returned by osmo_sockaddr_init().
93 * \param[in] buf A buffer to use for string operations.
94 * \param[in] buf_len Length of the buffer.
95 * \returns Address string (in buffer).
96 *
97 * Compose a string of the numeric IP-address and port represented by *addr of
98 * the form "<ip-addr> port <port>". The returned string is valid until the
99 * next invocation of this function.
100 */
101const char *osmo_sockaddr_to_strb(const struct osmo_sockaddr *addr,
102 char *buf, size_t buf_len);
103
104/*! \brief conveniently return osmo_sockaddr_to_strb() in a static buffer.
105 * \param[in] addr Binary representation as returned by osmo_sockaddr_init().
106 * \returns Address string in static buffer.
107 *
108 * See osmo_sockaddr_to_strb().
109 *
110 * Note: only one osmo_sockaddr_to_str() call will work per print/log
111 * statement. For two or more, use osmo_sockaddr_to_strb() with a separate
112 * buffer each.
113 */
114const char *osmo_sockaddr_to_str(const struct osmo_sockaddr *addr);
115
116/*! \brief compare two osmo_sockaddr.
117 * \param[in] a The first address to compare.
118 * \param[in] b The other address to compare.
119 * \returns 0 if equal, otherwise -1 or 1.
120 */
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100121int osmo_sockaddr_cmp(const struct osmo_sockaddr *a,
122 const struct osmo_sockaddr *b);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200123
124/*! \brief Overwrite *dst with *src.
125 * Like memcpy(), but copy only the valid bytes. */
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100126void osmo_sockaddr_copy(struct osmo_sockaddr *dst,
127 const struct osmo_sockaddr *src);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200128
129
130/* general */
131
132enum gtphub_plane_idx {
133 GTPH_PLANE_CTRL = 0,
134 GTPH_PLANE_USER = 1,
135 GTPH_PLANE_N
136};
137
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100138enum gtphub_side_idx {
139 GTPH_SIDE_GGSN = 0,
140 GTPH_SIDE_SGSN = 1,
141 GTPH_SIDE_N
142};
143
Neels Hofmeyrf9773202015-11-27 00:05:56 +0100144#define for_each_side(I) for (I = 0; I < GTPH_SIDE_N; I++)
145#define for_each_plane(I) for (I = 0; I < GTPH_PLANE_N; I++)
146#define for_each_side_and_plane(I,J) for_each_side(I) for_each_plane(J)
147
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100148static inline int other_side_idx(int side_idx)
149{
150 return (side_idx + 1) & 1;
151}
152
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200153extern const char* const gtphub_plane_idx_names[GTPH_PLANE_N];
154extern const uint16_t gtphub_plane_idx_default_port[GTPH_PLANE_N];
155
156/* A host address in the form that is expected in the 7.7.32 GSN Address IE.
157 * len is either 4 (IPv4) or 16 (IPv6), any other value is invalid. If no
158 * address is set, len shall be 0. */
159struct gsn_addr {
160 uint16_t len;
161 uint8_t buf[16];
162};
163
164void gsn_addr_copy(struct gsn_addr *gsna, const struct gsn_addr *src);
165int gsn_addr_from_str(struct gsn_addr *gsna, const char *numeric_addr_str);
166
167/* Return gsna in numeric string form, in a static buffer. */
168const char *gsn_addr_to_str(const struct gsn_addr *gsna);
169
170/* note: strbuf_len doesn't need to be larger than INET6_ADDRSTRLEN + 1. */
171const char *gsn_addr_to_strb(const struct gsn_addr *gsna,
172 char *strbuf, int strbuf_len);
173
174/* Return 1 on match, zero otherwise. */
175int gsn_addr_same(const struct gsn_addr *a, const struct gsn_addr *b);
176
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100177/* Decode sa to gsna. Return 0 on success. If port is non-NULL, the port number
178 * from sa is also returned. */
179int gsn_addr_from_sockaddr(struct gsn_addr *gsna, uint16_t *port,
180 const struct osmo_sockaddr *sa);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200181
182/* expiry */
183
184struct expiring_item;
185typedef void (*del_cb_t)(struct expiring_item *);
186
187struct expiring_item {
188 struct llist_head entry;
189 time_t expiry;
190 del_cb_t del_cb;
191};
192
193struct expiry {
194 int expiry_in_seconds;
195 struct llist_head items;
196};
197
198/* Initialize an expiry queue. */
199void expiry_init(struct expiry *exq, int expiry_in_seconds);
200
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100201/* Add a new mapping, or restart the expiry timeout for an already listed
202 * mapping. */
Neels Hofmeyr231653a2015-11-24 13:23:44 +0100203void expiry_add(struct expiry *exq, struct expiring_item *item, time_t now);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200204
Neels Hofmeyr16c3f572015-11-11 17:27:01 +0100205/* Initialize to all-empty; must be called before using the item in any way. */
206void expiring_item_init(struct expiring_item *item);
207
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200208/* Remove the given item from its expiry queue, and call item->del_cb, if set.
209 * This sets item->del_cb to NULL and is harmless when run a second time on the
210 * same item, so the del_cb may choose to call this function, too, to allow
211 * deleting items from several code paths. */
212void expiring_item_del(struct expiring_item *item);
213
214/* Carry out due expiry of mappings. Must be invoked regularly.
215 * 'now' is the current clock count in seconds and must correspond to the clock
216 * count passed to nr_map_add(). A monotonous clock counter should be used. */
217int expiry_tick(struct expiry *exq, time_t now);
218
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100219/* Expire all items. */
220void expiry_clear(struct expiry *exq);
221
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200222
223/* number map */
224
225/* A number map assigns a "random" mapped number to each user provided number.
226 * If the same number is requested multiple times, the same mapped number is
227 * returned.
228 *
229 * Number maps plug into possibly shared pools and expiry queues, for example:
230 *
231 * mapA -----------+-> pool1 <-+-- mapB
232 * {10->1, 11->5} | {1, 2, 3, ...} | {10->2, 11->3}
233 * | |
234 * | |
235 * /-> \-> expiry1 <-/
236 * | (30 seconds)
237 * |
238 * mapC -------+-----> pool2 <-+-- mapD
239 * {10->1, 11->3} {1, 2, 3, ...} | {10->2, 11->5}
240 * |
241 * expiry2 <-/
242 * (60 seconds)
243 *
244 * A map contains mappings ("10->1"). Each map needs a number pool, which can
245 * be shared with other maps. Each new mapping receives a number from the pool,
246 * which is then unavailable to any other map using the same pool.
247 *
248 * A map may point at an expiry queue, in which case all mappings added to it
249 * are also appended to the expiry queue (using a separate llist entry in the
250 * mapping). Any number of maps may submit to the same expiry queue, if they
251 * desire the same expiry timeout. An expiry queue stores the mappings in
252 * chronological order, so that expiry checking is needed only from the start
253 * of the queue; hence only mappings with identical expiry timeout can be added
254 * to the same expiry queue. Upon expiry, a mapping is dropped from the map it
255 * was submitted at. expiry_tick() needs to be called regularly for each expiry
256 * queue.
257 *
258 * A nr_mapping can be embedded in a larger struct: each mapping can have a
259 * distinct destructor (del_cb), and each del_cb can figure out the container
260 * struct's address and free that upon expiry or manual deletion. So in expiry
261 * queues (and even maps), mappings of different container types can be mixed.
262 * This can help to drastically reduce the amount of unnecessary visits during
263 * expiry checking, for the case that no expiry is pending. An expiry queue
264 * always knows which mappings to expire next, because they are right at the
265 * start of its list.
266 *
267 * Mapping allocation and a del_cb are provided by the caller. If del_cb is
268 * NULL, no deallocation will be done (allowing statically allocated entries).
269 */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200270
Neels Hofmeyr334af5d2015-11-17 14:24:46 +0100271typedef unsigned int nr_t;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200272
273/* Generator for unused numbers. So far this counts upwards from zero, but the
274 * implementation may change in the future. Treat this like an opaque struct.
275 * If this becomes random, the tests need to be fixed. */
276struct nr_pool {
277 nr_t last_nr;
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100278 nr_t nr_min;
279 nr_t nr_max;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200280};
281
282struct nr_mapping {
283 struct llist_head entry;
284 struct expiring_item expiry_entry;
285
286 void *origin;
287 nr_t orig;
288 nr_t repl;
289};
290
291struct nr_map {
292 struct nr_pool *pool; /* multiple nr_maps can share a nr_pool. */
293 struct expiry *add_items_to_expiry;
294 struct llist_head mappings;
295};
296
297
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100298void nr_pool_init(struct nr_pool *pool, nr_t nr_min, nr_t nr_max);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200299
300/* Return the next unused number from the nr_pool. */
301nr_t nr_pool_next(struct nr_pool *pool);
302
303/* Initialize the nr_mapping to zero/empty values. */
304void nr_mapping_init(struct nr_mapping *mapping);
305
306/* Remove the given mapping from its parent map and expiry queue, and call
307 * mapping->del_cb, if set. */
308void nr_mapping_del(struct nr_mapping *mapping);
309
310/* Initialize an (already allocated) nr_map, and set the map's number pool.
311 * Multiple nr_map instances may use the same nr_pool. Set the nr_map's expiry
312 * queue to exq, so that all added mappings are automatically expired after the
313 * time configured in exq. exq may be NULL to disable automatic expiry. */
314void nr_map_init(struct nr_map *map, struct nr_pool *pool,
315 struct expiry *exq);
316
317/* Add a new entry to the map. mapping->orig, mapping->origin and
318 * mapping->del_cb must be set before calling this function. The remaining
319 * fields of *mapping will be overwritten. mapping->repl is set to the next
320 * available mapped number from map->pool. 'now' is the current clock count in
321 * seconds; if no map->expiry is used, just pass 0 for 'now'. */
322void nr_map_add(struct nr_map *map, struct nr_mapping *mapping,
323 time_t now);
324
Neels Hofmeyr508514c2015-11-24 13:30:38 +0100325/* Restart the timeout for the given mapping. mapping must be a member of map.
326 */
327void nr_map_refresh(struct nr_map *map, struct nr_mapping *mapping,
328 time_t now);
329
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200330/* Return a known mapping from nr_orig and the given origin. If nr_orig is
331 * unknown, return NULL. */
332struct nr_mapping *nr_map_get(const struct nr_map *map,
333 void *origin, nr_t nr_orig);
334
335/* Return a known mapping to nr_repl. If nr_repl is unknown, return NULL. */
336struct nr_mapping *nr_map_get_inv(const struct nr_map *map, nr_t nr_repl);
337
338/* Remove all mappings from map. */
339void nr_map_clear(struct nr_map *map);
340
341/* Return 1 if map has no entries, 0 otherwise. */
342int nr_map_empty(const struct nr_map *map);
343
344
345/* config */
346
Neels Hofmeyr2c8b5812015-11-25 16:45:59 +0100347static const int GTPH_EXPIRE_QUICKLY_SECS = 30; /* TODO is there a spec for this? */
348static const int GTPH_EXPIRE_SLOWLY_MINUTES = 6 * 60; /* TODO is there a spec for this? */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200349
350struct gtphub_cfg_addr {
351 const char *addr_str;
352 uint16_t port;
353};
354
355struct gtphub_cfg_bind {
356 struct gtphub_cfg_addr bind;
357};
358
359struct gtphub_cfg {
360 struct gtphub_cfg_bind to_sgsns[GTPH_PLANE_N];
361 struct gtphub_cfg_bind to_ggsns[GTPH_PLANE_N];
362 struct gtphub_cfg_addr sgsn_proxy[GTPH_PLANE_N];
363 struct gtphub_cfg_addr ggsn_proxy[GTPH_PLANE_N];
364};
365
366
367/* state */
368
369struct gtphub_peer {
370 struct llist_head entry;
371
372 struct llist_head addresses; /* Alternatives, not load balancing. */
373 struct nr_pool seq_pool;
374 struct nr_map seq_map;
375};
376
377struct gtphub_peer_addr {
378 struct llist_head entry;
379
380 struct gtphub_peer *peer;
381 struct gsn_addr addr;
382 struct llist_head ports;
383};
384
385struct gtphub_peer_port {
386 struct llist_head entry;
387
388 struct gtphub_peer_addr *peer_addr;
389 uint16_t port;
390 unsigned int ref_count; /* references from other peers' seq_maps */
391 struct osmo_sockaddr sa;
392};
393
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100394struct gtphub_tunnel_endpoint {
395 struct gtphub_peer_port *peer;
396 uint32_t tei_orig; /* from/to peer */
397 uint32_t tei_repl; /* from/to the other tunnel endpoint */
398};
399
400struct gtphub_tunnel {
401 struct llist_head entry;
402 struct expiring_item expiry_entry;
403
404 struct gtphub_tunnel_endpoint endpoint[GTPH_SIDE_N][GTPH_PLANE_N];
405};
406
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200407struct gtphub_bind {
408 struct gsn_addr local_addr;
Neels Hofmeyr4b2cbda2015-11-20 03:16:19 +0100409 uint16_t local_port;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200410 struct osmo_fd ofd;
411
412 /* list of struct gtphub_peer */
413 struct llist_head peers;
Neels Hofmeyr390e9102015-11-16 13:45:13 +0100414
415 const char *label; /* For logging */
Neels Hofmeyr1ba50c62015-11-20 01:28:40 +0100416 struct rate_ctr_group *counters_io;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200417};
418
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100419struct gtphub_resolved_ggsn {
420 struct llist_head entry;
421 struct expiring_item expiry_entry;
422
423 /* The APN OI, the Operator Identifier, is the combined address,
424 * including parts of the IMSI and APN NI, and ending with ".gprs". */
425 char apn_oi_str[GSM_APN_LENGTH];
426
427 /* Which address and port we resolved that to. */
428 struct gtphub_peer_port *peer;
429};
430
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200431struct gtphub {
432 struct gtphub_bind to_sgsns[GTPH_PLANE_N];
433 struct gtphub_bind to_ggsns[GTPH_PLANE_N];
434
435 /* pointers to an entry of to_sgsns[x].peers */
436 struct gtphub_peer_port *sgsn_proxy[GTPH_PLANE_N];
437
438 /* pointers to an entry of to_ggsns[x].peers */
439 struct gtphub_peer_port *ggsn_proxy[GTPH_PLANE_N];
440
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100441 /* The TEI numbers will simply wrap and be reused, which will work out
442 * in practice. Problems would arise if one given peer maintained the
443 * same TEI for a time long enough for the TEI nr map to wrap an entire
444 * uint32_t; if a new TEI were mapped every second, this would take
445 * more than 100 years (in which a single given TEI must not time out)
446 * to cause a problem. */
Neels Hofmeyrd121ea62015-11-27 01:20:53 +0100447 struct nr_pool tei_pool;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200448
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100449 struct llist_head tunnels; /* struct gtphub_tunnel */
450
Neels Hofmeyr4960fab2015-11-18 17:53:00 +0100451 struct llist_head ggsn_lookups; /* opaque (gtphub_ares.c) */
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100452 struct llist_head resolved_ggsns; /* struct gtphub_resolved_ggsn */
453
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200454 struct osmo_timer_list gc_timer;
Neels Hofmeyr2c8b5812015-11-25 16:45:59 +0100455 struct expiry expire_quickly;
456 struct expiry expire_slowly;
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100457
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100458 uint8_t restart_counter;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200459};
460
461struct gtp_packet_desc;
462
463
464/* api */
465
Neels Hofmeyr4b2cbda2015-11-20 03:16:19 +0100466int gtphub_vty_init(struct gtphub *global_hub, struct gtphub_cfg *global_cfg);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200467int gtphub_cfg_read(struct gtphub_cfg *cfg, const char *config_file);
468
469/* Initialize and start gtphub: bind to ports, run expiry timers. */
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100470int gtphub_start(struct gtphub *hub, struct gtphub_cfg *cfg,
471 uint8_t restart_counter);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200472
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100473/* Close all sockets, expire all maps and peers and free all allocations. The
474 * struct is then unusable, unless gtphub_start() is run on it again. */
475void gtphub_stop(struct gtphub *hub);
476
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200477time_t gtphub_now(void);
478
479/* Remove expired items, empty peers, ... */
480void gtphub_gc(struct gtphub *hub, time_t now);
481
482/* Return the string of the first address for this peer. */
483const char *gtphub_peer_str(struct gtphub_peer *peer);
484/* Same with a different static buffer. We often want to print two peers. */
485const char *gtphub_peer_str2(struct gtphub_peer *peer);
486
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100487/* Return a human readable description of tun in a static buffer. */
488const char *gtphub_tunnel_str(struct gtphub_tunnel *tun);
489
490/* Return 1 if all of tun's endpoints are fully established, 0 otherwise. */
491int gtphub_tunnel_complete(struct gtphub_tunnel *tun);
492
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200493int gtphub_from_sgsns_handle_buf(struct gtphub *hub,
494 unsigned int port_idx,
495 const struct osmo_sockaddr *from_addr,
496 uint8_t *buf,
497 size_t received,
498 time_t now,
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100499 uint8_t **reply_buf,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200500 struct osmo_fd **to_ofd,
501 struct osmo_sockaddr *to_addr);
502
503int gtphub_from_ggsns_handle_buf(struct gtphub *hub,
504 unsigned int port_idx,
505 const struct osmo_sockaddr *from_addr,
506 uint8_t *buf,
507 size_t received,
508 time_t now,
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100509 uint8_t **reply_buf,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200510 struct osmo_fd **to_ofd,
511 struct osmo_sockaddr *to_addr);
512
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100513struct gtphub_peer_port *gtphub_port_have(struct gtphub *hub,
514 struct gtphub_bind *bind,
515 const struct gsn_addr *addr,
516 uint16_t port);
517
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200518struct gtphub_peer_port *gtphub_port_find_sa(const struct gtphub_bind *bind,
519 const struct osmo_sockaddr *addr);
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100520
521void gtphub_resolved_ggsn(struct gtphub *hub, const char *apn_oi_str,
522 struct gsn_addr *resolved_addr,
523 time_t now);
524
525const char *gtphub_port_str(struct gtphub_peer_port *port);