Neels Hofmeyr | 76328bd | 2019-11-20 03:35:37 +0100 | [diff] [blame] | 1 | /* 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/cni_peer_id.h> |
| 26 | #include <osmocom/hlr/timestamp.h> |
| 27 | |
| 28 | struct osmo_gsup_req; |
| 29 | struct remote_hlr; |
| 30 | |
| 31 | struct proxy { |
| 32 | struct llist_head subscr_list; |
| 33 | struct llist_head pending_gsup_reqs; |
| 34 | |
| 35 | /* When messages arrive back from a remote HLR that this is the proxy for, reach the VLR to forward the response |
| 36 | * to via this osmo_gsup_server. */ |
| 37 | struct osmo_gsup_server *gsup_server_to_vlr; |
| 38 | |
| 39 | /* How long to keep proxy entries without a refresh, in seconds. */ |
| 40 | uint32_t fresh_time; |
| 41 | |
| 42 | /* How often to garbage collect the proxy cache, period in seconds. |
| 43 | * To change this and take effect immediately, rather use proxy_set_gc_period(). */ |
| 44 | uint32_t gc_period; |
| 45 | |
| 46 | struct osmo_timer_list gc_timer; |
| 47 | }; |
| 48 | |
| 49 | struct proxy_subscr_domain_state { |
| 50 | struct osmo_ipa_name vlr_name; |
| 51 | timestamp_t last_lu; |
| 52 | |
| 53 | /* The name from which an Update Location Request was received. Copied to vlr_name as soon as the LU is |
| 54 | * completed successfully. */ |
| 55 | struct osmo_ipa_name vlr_name_preliminary; |
| 56 | |
| 57 | /* Set if this is a middle proxy, i.e. a proxy behind another proxy. |
| 58 | * That is mostly to know whether the MS is attached at a local MSC/SGSN or further away. |
| 59 | * It could be a boolean, but store the full name for logging. Set only at successful LU acceptance. */ |
| 60 | struct osmo_ipa_name vlr_via_proxy; |
| 61 | }; |
| 62 | |
| 63 | struct proxy_subscr { |
| 64 | char imsi[GSM23003_IMSI_MAX_DIGITS+1]; |
| 65 | char msisdn[GSM23003_MSISDN_MAX_DIGITS+1]; |
| 66 | struct osmo_sockaddr_str remote_hlr_addr; |
| 67 | struct proxy_subscr_domain_state cs, ps; |
| 68 | }; |
| 69 | |
| 70 | void proxy_init(struct osmo_gsup_server *gsup_server_to_vlr); |
| 71 | void proxy_del(struct proxy *proxy); |
| 72 | void proxy_set_gc_period(struct proxy *proxy, uint32_t gc_period); |
| 73 | |
| 74 | /* The API to access / modify proxy entries keeps the implementation opaque, to make sure that we can easily move proxy |
| 75 | * storage to SQLite db. */ |
| 76 | int proxy_subscr_get_by_imsi(struct proxy_subscr *dst, struct proxy *proxy, const char *imsi); |
| 77 | int proxy_subscr_get_by_msisdn(struct proxy_subscr *dst, struct proxy *proxy, const char *msisdn); |
| 78 | void proxy_subscrs_get_by_remote_hlr(struct proxy *proxy, const struct osmo_sockaddr_str *remote_hlr_addr, |
| 79 | bool (*yield)(struct proxy *proxy, const struct proxy_subscr *subscr, void *data), |
| 80 | void *data); |
| 81 | int proxy_subscr_create_or_update(struct proxy *proxy, const struct proxy_subscr *proxy_subscr); |
| 82 | int proxy_subscr_del(struct proxy *proxy, const char *imsi); |
| 83 | |
| 84 | int proxy_subscr_forward_to_remote_hlr(struct proxy *proxy, const struct proxy_subscr *proxy_subscr, |
| 85 | struct osmo_gsup_req *req); |
| 86 | void proxy_subscr_forward_to_remote_hlr_resolved(struct proxy *proxy, const struct proxy_subscr *proxy_subscr, |
| 87 | struct remote_hlr *remote_hlr, struct osmo_gsup_req *req); |
| 88 | |
| 89 | int proxy_subscr_forward_to_vlr(struct proxy *proxy, const struct proxy_subscr *proxy_subscr, |
| 90 | const struct osmo_gsup_message *gsup, struct remote_hlr *from_remote_hlr); |
| 91 | |
| 92 | void proxy_subscr_remote_hlr_resolved(struct proxy *proxy, const struct proxy_subscr *proxy_subscr, |
| 93 | const struct osmo_sockaddr_str *remote_hlr_addr); |
| 94 | void proxy_subscr_remote_hlr_up(struct proxy *proxy, const struct proxy_subscr *proxy_subscr, |
| 95 | struct remote_hlr *remote_hlr); |