diff options
author | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2014-09-19 16:34:01 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-10-09 17:46:34 +0200 |
commit | c6807c4405d6dcc42d9dab23fa5f259464fdfc32 (patch) | |
tree | 006aeab7ee384db356ac2520b5ee1db46884ed39 | |
parent | ba6267f05acbea1600360f40bd390a25cae50fbe (diff) |
gbproxy: Use monotonic system time instead of time-of-day
Currently time() is used for age calculations. This time source
may jump either forwards or backwards in time (NTP update, leap
seconds).
This patch replaces the use of time() by using
clock_gettime(CLOCK_MONOTONIC) instead.
Sponsored-by: On-Waves ehf
-rw-r--r-- | openbsc/src/gprs/gb_proxy.c | 9 | ||||
-rw-r--r-- | openbsc/src/gprs/gb_proxy_vty.c | 14 |
2 files changed, 19 insertions, 4 deletions
diff --git a/openbsc/src/gprs/gb_proxy.c b/openbsc/src/gprs/gb_proxy.c index 130ab4ee1..9aeb010be 100644 --- a/openbsc/src/gprs/gb_proxy.c +++ b/openbsc/src/gprs/gb_proxy.c @@ -518,6 +518,7 @@ static int gbprox_process_bssgp_ul(struct gbproxy_config *cfg, int rc; int len_change = 0; time_t now; + struct timespec ts = {0,}; struct gbproxy_link_info *link_info = NULL; uint32_t sgsn_nsei = cfg->nsip_sgsn_nsei; @@ -549,7 +550,9 @@ static int gbprox_process_bssgp_ul(struct gbproxy_config *cfg, if (!peer) return 0; - now = time(NULL); + + clock_gettime(CLOCK_MONOTONIC, &ts); + now = ts.tv_sec; gbprox_update_current_raid(parse_ctx.bssgp_raid_enc, peer, parse_ctx.llc_msg_name); @@ -611,6 +614,7 @@ static void gbprox_process_bssgp_dl(struct gbproxy_config *cfg, int rc; int len_change = 0; time_t now; + struct timespec ts = {0,}; struct gbproxy_link_info *link_info = NULL; if (!cfg->core_mcc && !cfg->core_mnc && !cfg->core_apn && @@ -640,7 +644,8 @@ static void gbprox_process_bssgp_dl(struct gbproxy_config *cfg, if (!peer) return; - now = time(NULL); + clock_gettime(CLOCK_MONOTONIC, &ts); + now = ts.tv_sec; if (parse_ctx.g48_hdr) { switch (parse_ctx.g48_hdr->msg_type) { diff --git a/openbsc/src/gprs/gb_proxy_vty.c b/openbsc/src/gprs/gb_proxy_vty.c index 5ba27cdf7..82d7d9541 100644 --- a/openbsc/src/gprs/gb_proxy_vty.c +++ b/openbsc/src/gprs/gb_proxy_vty.c @@ -450,7 +450,11 @@ DEFUN(show_gbproxy_links, show_gbproxy_links_cmd, "show gbproxy links", { struct gbproxy_peer *peer; char mi_buf[200]; - time_t now = time(NULL); + time_t now; + struct timespec ts = {0,}; + + clock_gettime(CLOCK_MONOTONIC, &ts); + now = ts.tv_sec; llist_for_each_entry(peer, &g_cfg->bts_peers, list) { struct gbproxy_link_info *link_info; @@ -666,6 +670,9 @@ DEFUN(delete_gb_link, delete_gb_link_cmd, struct gbproxy_peer *peer = 0; struct gbproxy_link_info *link_info, *nxt; struct gbproxy_patch_state *state; + time_t now; + struct timespec ts = {0,}; + int found = 0; match = argv[1][0]; @@ -679,8 +686,11 @@ DEFUN(delete_gb_link, delete_gb_link_cmd, state = &peer->patch_state; + clock_gettime(CLOCK_MONOTONIC, &ts); + now = ts.tv_sec; + if (match == MATCH_STALE) { - found = gbproxy_remove_stale_link_infos(peer, time(NULL)); + found = gbproxy_remove_stale_link_infos(peer, now); if (found) vty_out(vty, "Deleted %d stale logical link%s%s", found, found == 1 ? "" : "s", VTY_NEWLINE); |