aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-12-26 11:56:29 +0100
committerHarald Welte <laforge@gnumonks.org>2010-12-26 11:56:29 +0100
commitc7d8e582acf83bbe1f0cca1894ffdc46cd8804cd (patch)
treebcb6d8541d34f58acd7a0424314a46df6c85ecd4
parent7bf59a94a50d6c923058c1020e5e27d08761aa7b (diff)
HACK / unfinished: persistent storage of SGSN statelaforge/gprs_persistent
-rw-r--r--openbsc/src/gprs/gprs_llc.c28
-rw-r--r--openbsc/src/gprs/gprs_sgsn.c78
2 files changed, 106 insertions, 0 deletions
diff --git a/openbsc/src/gprs/gprs_llc.c b/openbsc/src/gprs/gprs_llc.c
index e873420ad..68510bedf 100644
--- a/openbsc/src/gprs/gprs_llc.c
+++ b/openbsc/src/gprs/gprs_llc.c
@@ -851,3 +851,31 @@ int gprs_llc_init(const char *cipher_plugin_path)
{
return gprs_cipher_load(cipher_plugin_path);
}
+
+
+int gprs_llc_dump(struct osmo_dumper *od)
+{
+ llist_for_each_entry(llme, &gprs_llc_llmes, list)
+ osmo_dump_struct(od, OD_TYPE_LLC_ME, llme, sizeof(*llme));
+}
+
+/* callback to restore one data structure from disk */
+static int gprs_llc_restore(int type, uint8_t *data, int data_len)
+{
+ struct gprs_llc_llme *llme;
+
+ if (type != OD_TYPE_LLC_ME)
+ return -EINVAL;
+ if (sizeof(*llme) != data_len)
+ return -EMSGSIZE;
+
+ llme = talloc_zero(llc_tall_ctx, struct gprs_llc_llme);
+ if (!llme)
+ return -ENOMEM;
+
+ memcpy(llme, data, sizeof(*llme));
+
+ llist_add(&llme->list, &gprs_llc_llmes);
+
+ return 0;
+}
diff --git a/openbsc/src/gprs/gprs_sgsn.c b/openbsc/src/gprs/gprs_sgsn.c
index 48a00b822..cc687f8d5 100644
--- a/openbsc/src/gprs/gprs_sgsn.c
+++ b/openbsc/src/gprs/gprs_sgsn.c
@@ -320,3 +320,81 @@ restart:
return ptmsi;
}
+
+int gprs_mmctx_dump(struct osmo_dumper *od)
+{
+ struct sgsn_mm_ctx *ctx;
+
+ llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
+ struct sgsn_mm_ctx *pdp;
+
+ /* first dump the MM context itself */
+ osmo_dump_struct(od, OD_TYPE_GPRS_MM_CTX, ctx, sizeof(*ctx));
+
+ /* dump all pdp contexts for this MM context */
+ llist_for_each_entry(pdp, &ctx->pdp_list, list)
+ osmo_dump_struct(od, OD_TYPE_GPRS_PDP_CTX, ctx, sizeof(*ctx));
+ }
+}
+
+/* pointer to the last-restored MM context */
+static struct sgsn_mm_ctx *restore_last_mm_ctx;
+
+/* callback to restore one data structure from disk */
+static int gprs_mmctx_restore(int type, uint8_t *data, int data_len)
+{
+ struct sgsn_mm_ctx *ctx;
+
+ if (type != OD_TYPE_GPRS_MM_CTX)
+ return -EINVAL;
+ if (sizeof(*ctx) != data_len)
+ return -EMSGSIZE;
+
+ ctx = talloc_zero(tall_bsc_ctx, struct sgsn_mm_ctx);
+ if (!ctx)
+ return -ENOMEM;
+
+ memcpy(ctx, data, sizeof(*llme));
+
+ ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, tlli);
+ INIT_LLIST_HEAD(&ctx->pdp_list);
+
+ llist_add(&ctx->list, &sgsn_mm_ctxts);
+
+ restore_last_mm_ctx = ctx;
+
+ return 0;
+}
+
+static int gprs_pdpctx_restore(int type, uint8_t *data, int data_len)
+{
+ struct sgsn_pdp_ctx *pdp;
+
+ if (type != OD_TYPE_GPRS_PDP_CTX)
+ return -EINVAL;
+
+ if (sizeof(*pdp) != data_len)
+ return -EMSGSIZE;
+
+ pdp = sgsn_pdp_ctx_by_nsapi(mm, nsapi);
+ if (pdp)
+ return -EEXIST;
+
+ pdp = talloc_zero(tall_bsc_ctx, struct sgsn_pdp_ctx);
+ if (!pdp)
+ return -ENOMEM;
+
+ /* FIXME: how to restore the reference to the MM context? */
+ pdp->mm = restore_last_mm_ctx;
+ if (!pdp->mm) {
+ talloc_free(pdp);
+ return -EIO;
+ }
+
+ pdp->ctrg = rate_ctr_group_alloc(pdp, &pdpctx_ctrg_desc, nsapi);
+
+ llist_add(&pdp->list, &mm->pdp_list);
+ llist_add(&pdp->g_list, &sgsn_pdp_ctxts);
+
+ return pdp;
+}