blob: 8412dd2d2d4c3e92205332563031c5ac09cf6639 [file] [log] [blame]
Neels Hofmeyr62d916f2019-11-20 03:35:37 +01001/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
2 *
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#pragma once
21
22#include <time.h>
23#include <osmocom/gsm/protocol/gsm_23_003.h>
24#include <osmocom/core/sockaddr_str.h>
25#include <osmocom/gsupclient/gsup_peer_id.h>
26#include <osmocom/hlr/timestamp.h>
27
28struct osmo_gsup_req;
29struct remote_hlr;
30
31struct proxy_pending_gsup_req {
32 struct llist_head entry;
33 struct osmo_gsup_req *req;
34 timestamp_t received_at;
35};
36
37struct proxy {
38 struct llist_head subscr_list;
39 struct llist_head pending_gsup_reqs;
40
41 /* When messages arrive back from a remote HLR that this is the proxy for, reach the VLR to forward the response
42 * to via this osmo_gsup_server. */
43 struct osmo_gsup_server *gsup_server_to_vlr;
44
45 /* How long to keep proxy entries without a refresh, in seconds. */
46 uint32_t fresh_time;
47
48 /* How often to garbage collect the proxy cache, period in seconds.
49 * To change this and take effect immediately, rather use proxy_set_gc_period(). */
50 uint32_t gc_period;
51
52 struct osmo_timer_list gc_timer;
53};
54
55struct proxy_subscr_domain_state {
56 struct osmo_ipa_name vlr_name;
57 timestamp_t last_lu;
58
59 /* The name from which an Update Location Request was received. Copied to vlr_name as soon as the LU is
60 * completed successfully. */
61 struct osmo_ipa_name vlr_name_preliminary;
62
63 /* Set if this is a middle proxy, i.e. a proxy behind another proxy.
64 * That is mostly to know whether the MS is attached at a local MSC/SGSN or further away.
65 * It could be a boolean, but store the full name for logging. Set only at successful LU acceptance. */
66 struct osmo_ipa_name vlr_via_proxy;
67};
68
69struct proxy_subscr {
70 char imsi[GSM23003_IMSI_MAX_DIGITS+1];
71 char msisdn[GSM23003_MSISDN_MAX_DIGITS+1];
72 struct osmo_sockaddr_str remote_hlr_addr;
73 struct proxy_subscr_domain_state cs, ps;
74};
75
76void proxy_init(struct osmo_gsup_server *gsup_server_to_vlr);
77void proxy_del(struct proxy *proxy);
78void proxy_set_gc_period(struct proxy *proxy, uint32_t gc_period);
79
80/* The API to access / modify proxy entries keeps the implementation opaque, to make sure that we can easily move proxy
81 * storage to SQLite db. */
82int proxy_subscr_get_by_imsi(struct proxy_subscr *dst, struct proxy *proxy, const char *imsi);
83int proxy_subscr_get_by_msisdn(struct proxy_subscr *dst, struct proxy *proxy, const char *msisdn);
84void proxy_subscrs_get_by_remote_hlr(struct proxy *proxy, const struct osmo_sockaddr_str *remote_hlr_addr,
85 bool (*yield)(struct proxy *proxy, const struct proxy_subscr *subscr, void *data),
86 void *data);
87int proxy_subscr_create_or_update(struct proxy *proxy, const struct proxy_subscr *proxy_subscr);
88int proxy_subscr_del(struct proxy *proxy, const char *imsi);
89
90void proxy_subscr_forward_to_remote_hlr(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
91 struct osmo_gsup_req *req);
92void proxy_subscr_forward_to_remote_hlr_resolved(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
93 struct remote_hlr *remote_hlr, struct osmo_gsup_req *req);
94
95int proxy_subscr_forward_to_vlr(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
96 const struct osmo_gsup_message *gsup, struct remote_hlr *from_remote_hlr);
97
98void proxy_subscr_remote_hlr_resolved(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
99 struct remote_hlr *remote_hlr);
100void proxy_subscr_remote_hlr_up(struct proxy *proxy, const struct proxy_subscr *proxy_subscr,
101 struct remote_hlr *remote_hlr);