diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2019-11-20 03:35:37 +0100 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2020-04-30 19:22:24 +0200 |
commit | ab7dc40f168da4326f207ef8aeeec40229c94486 (patch) | |
tree | ce45f461c6dee3a93ee99eb98e5af7ca8cb2257c /src/timestamp.c | |
parent | 86b507b6ea529f9cf861286d8e6fa3b5fde851d2 (diff) |
D-GSM 1/n: add mslookup server in osmo-hlr
Implement the mslookup server to service remote mslookup requests.
This patch merely adds the logic to answer incoming mslookup requests, an
actual method to receive requests (mDNS) follows in a subsequent patch.
- API to configure service names and addresses for the local site (per MSC).
- determine whether a subscriber is on a local MSC
(checking the local proxy will be added in subsequent patch that adds proxy
capability).
- VTY config follows in a subsequent patch.
For a detailed overview of the D-GSM and mslookup related files, please see the
elaborate comment at the top of mslookup.c (already added in an earlier patch).
Change-Id: Ife4a61d71926d08f310a1aeed9d9f1974f64178b
Diffstat (limited to 'src/timestamp.c')
-rw-r--r-- | src/timestamp.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/timestamp.c b/src/timestamp.c new file mode 100644 index 0000000..002857d --- /dev/null +++ b/src/timestamp.c @@ -0,0 +1,53 @@ +/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> + * + * All Rights Reserved + * + * 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 <osmocom/core/timer.h> +#include <osmocom/hlr/timestamp.h> + +/* Central implementation to set a timestamp to the current time, in case we want to modify this in the future. */ +void timestamp_update(timestamp_t *timestamp) +{ + struct timeval tv; + time_t raw; + struct tm utc; + /* The simpler way would be just time(&raw), but by using osmo_gettimeofday() we can also use + * osmo_gettimeofday_override for unit tests independent from real time. */ + osmo_gettimeofday(&tv, NULL); + raw = tv.tv_sec; + gmtime_r(&raw, &utc); + *timestamp = mktime(&utc); +} + +/* Calculate seconds since a given timestamp was taken. Return true for a valid age returned in age_p, return false if + * the timestamp is either in the future or the age surpasses uint32_t range. When false is returned, *age_p is set to + * UINT32_MAX. */ +bool timestamp_age(const timestamp_t *timestamp, uint32_t *age_p) +{ + int64_t age64; + timestamp_t now; + timestamp_update(&now); + age64 = (int64_t)now - (int64_t)(*timestamp); + if (age64 < 0 || age64 > UINT32_MAX) { + *age_p = UINT32_MAX; + return false; + } + *age_p = (uint32_t)age64; + return true; +} + |