lynxis lazus has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ggsn/+/38930?usp=email )
Change subject: gtp_new(): use talloc instead of calloc/free ......................................................................
gtp_new(): use talloc instead of calloc/free
Required for SGSN Context Req fsm which is using talloc. Adds a new api to set the libgtp talloc context via gtp_set_talloc_ctx()
Change-Id: I7c4a29c4bb1ef3c7bf506e59e99b3a804cabe34b --- M TODO-RELEASE M gtp/gsn.c M gtp/gtp.c M gtp/gtp_internal.h M include/osmocom/gtp/gtp.h 5 files changed, 18 insertions(+), 3 deletions(-)
Approvals: pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified daniel: Looks good to me, approved
diff --git a/TODO-RELEASE b/TODO-RELEASE index 194885d..1e70d13 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -10,4 +10,5 @@ libgtp append new field dir_tun_flags in struct pdp_t (older users not using the field should be fine since struct pdp_t is allocated internally) libgtp ABI break new field cb_create_context_ind in struct gsn_t libgtp new API gtp_set_cb_update_context_ind(), gtp_update_context_resp() -libosmocore >1.10.0 osmo_tundev_get_fd() \ No newline at end of file +libosmocore >1.10.0 osmo_tundev_get_fd() +libgtp new API gtp_set_talloc_ctx() diff --git a/gtp/gsn.c b/gtp/gsn.c index 612baf2..2fee812 100644 --- a/gtp/gsn.c +++ b/gtp/gsn.c @@ -63,6 +63,7 @@
#include "queue.h" #include "gsn_internal.h" +#include "gtp_internal.h"
/* Error reporting functions */
@@ -466,7 +467,7 @@ { LOGP(DLGTP, LOGL_NOTICE, "GTP: gtp_newgsn() started at %s\n", inet_ntoa(*listen));
- *gsn = calloc(sizeof(struct gsn_t), 1); /* TODO */ + *gsn = talloc_zero(tall_libgtp_ctx, struct gsn_t);
(*gsn)->statedir = statedir; log_restart(*gsn); @@ -551,7 +552,7 @@
rate_ctr_group_free(gsn->ctrg);
- free(gsn); + talloc_free(gsn); return 0; }
diff --git a/gtp/gtp.c b/gtp/gtp.c index 3b32229..34852eb 100644 --- a/gtp/gtp.c +++ b/gtp/gtp.c @@ -77,6 +77,8 @@ inet_ntoa((addr).sin_addr), htons((addr).sin_port), \ ##args);
+TALLOC_CTX *tall_libgtp_ctx = NULL; + /* API Functions */
const char *gtp_version() @@ -3190,3 +3192,8 @@ } return imsi64; } + +void gtp_set_talloc_ctx(void *ctx) +{ + tall_libgtp_ctx = ctx; +} diff --git a/gtp/gtp_internal.h b/gtp/gtp_internal.h index f04b220..06ba342 100644 --- a/gtp/gtp_internal.h +++ b/gtp/gtp_internal.h @@ -1,5 +1,8 @@ #pragma once
#include <stdint.h> +#include <talloc.h>
uint64_t gtp_imsi_str2gtp(const char *str); + +extern TALLOC_CTX *tall_libgtp_ctx; diff --git a/include/osmocom/gtp/gtp.h b/include/osmocom/gtp/gtp.h index 5c03eaf..801837a 100644 --- a/include/osmocom/gtp/gtp.h +++ b/include/osmocom/gtp/gtp.h @@ -281,4 +281,7 @@
extern const char *imsi_gtp2str(const uint64_t *imsi);
+/*! Set the talloc context for internal objects */ +void gtp_set_talloc_ctx(void *ctx); + #endif /* !_GTP_H */