gtp_{ggsn,mme}: Allocate contexts under struct sgsn_instance
This way apns are managed by the lifcycle of the main global struct sgsn_instance automatically. Change-Id: Ie65d59632a368c6957c33dca64e856ace792b2c6
This commit is contained in:
parent
fd4d435442
commit
69569879ae
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
struct gsn_t;
|
struct gsn_t;
|
||||||
struct sgsn_pdp_ctx;
|
struct sgsn_pdp_ctx;
|
||||||
|
struct sgsn_instance;
|
||||||
|
|
||||||
struct sgsn_ggsn_ctx {
|
struct sgsn_ggsn_ctx {
|
||||||
struct llist_head list;
|
struct llist_head list;
|
||||||
|
@ -22,11 +23,11 @@ struct sgsn_ggsn_ctx {
|
||||||
struct osmo_timer_list echo_timer;
|
struct osmo_timer_list echo_timer;
|
||||||
unsigned int echo_interval;
|
unsigned int echo_interval;
|
||||||
};
|
};
|
||||||
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id);
|
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(struct sgsn_instance *sgsn, uint32_t id);
|
||||||
void sgsn_ggsn_ctx_free(struct sgsn_ggsn_ctx *ggc);
|
void sgsn_ggsn_ctx_free(struct sgsn_ggsn_ctx *ggc);
|
||||||
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id);
|
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(struct sgsn_instance *sgsn, uint32_t id);
|
||||||
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr);
|
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct sgsn_instance *sgsn, struct in_addr *addr);
|
||||||
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id);
|
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(struct sgsn_instance *sgsn, uint32_t id);
|
||||||
void sgsn_ggsn_ctx_drop_pdp(struct sgsn_pdp_ctx *pctx);
|
void sgsn_ggsn_ctx_drop_pdp(struct sgsn_pdp_ctx *pctx);
|
||||||
int sgsn_ggsn_ctx_drop_all_pdp_except(struct sgsn_ggsn_ctx *ggsn, struct sgsn_pdp_ctx *except);
|
int sgsn_ggsn_ctx_drop_all_pdp_except(struct sgsn_ggsn_ctx *ggsn, struct sgsn_pdp_ctx *except);
|
||||||
int sgsn_ggsn_ctx_drop_all_pdp(struct sgsn_ggsn_ctx *ggsn);
|
int sgsn_ggsn_ctx_drop_all_pdp(struct sgsn_ggsn_ctx *ggsn);
|
||||||
|
|
|
@ -713,11 +713,11 @@ struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx,
|
||||||
ggsn = apn_ctx->ggsn;
|
ggsn = apn_ctx->ggsn;
|
||||||
} else if (llist_empty(&sgsn->apn_list)) {
|
} else if (llist_empty(&sgsn->apn_list)) {
|
||||||
/* No configuration -> use GGSN 0 */
|
/* No configuration -> use GGSN 0 */
|
||||||
ggsn = sgsn_ggsn_ctx_by_id(0);
|
ggsn = sgsn_ggsn_ctx_by_id(sgsn, 0);
|
||||||
} else if (allow_any_apn &&
|
} else if (allow_any_apn &&
|
||||||
(selected_apn_str == NULL || strlen(selected_apn_str) == 0)) {
|
(selected_apn_str == NULL || strlen(selected_apn_str) == 0)) {
|
||||||
/* No APN given and no default configuration -> Use GGSN 0 */
|
/* No APN given and no default configuration -> Use GGSN 0 */
|
||||||
ggsn = sgsn_ggsn_ctx_by_id(0);
|
ggsn = sgsn_ggsn_ctx_by_id(sgsn, 0);
|
||||||
} else {
|
} else {
|
||||||
/* No matching configuration found */
|
/* No matching configuration found */
|
||||||
LOGMMCTXP(LOGL_NOTICE, mmctx,
|
LOGMMCTXP(LOGL_NOTICE, mmctx,
|
||||||
|
|
|
@ -378,7 +378,7 @@ static void ggsn_lookup_cb(void *arg, int status, int timeouts, struct hostent *
|
||||||
goto reject_due_failure;
|
goto reject_due_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
ggsn = sgsn_ggsn_ctx_alloc(UINT32_MAX);
|
ggsn = sgsn_ggsn_ctx_alloc(sgsn, UINT32_MAX);
|
||||||
if (!ggsn) {
|
if (!ggsn) {
|
||||||
LOGMMCTXP(LOGL_ERROR, lookup->mmctx, "Failed to create ggsn.\n");
|
LOGMMCTXP(LOGL_ERROR, lookup->mmctx, "Failed to create ggsn.\n");
|
||||||
goto reject_due_failure;
|
goto reject_due_failure;
|
||||||
|
|
|
@ -35,8 +35,6 @@
|
||||||
#include <osmocom/sgsn/gprs_gmm_fsm.h>
|
#include <osmocom/sgsn/gprs_gmm_fsm.h>
|
||||||
#include <osmocom/sgsn/gprs_sm.h>
|
#include <osmocom/sgsn/gprs_sm.h>
|
||||||
|
|
||||||
extern void *tall_sgsn_ctx;
|
|
||||||
|
|
||||||
void sgsn_ggsn_ctx_check_echo_timer(struct sgsn_ggsn_ctx *ggc)
|
void sgsn_ggsn_ctx_check_echo_timer(struct sgsn_ggsn_ctx *ggc)
|
||||||
{
|
{
|
||||||
bool pending = osmo_timer_pending(&ggc->echo_timer);
|
bool pending = osmo_timer_pending(&ggc->echo_timer);
|
||||||
|
@ -59,11 +57,11 @@ static void echo_timer_cb(void *data)
|
||||||
osmo_timer_schedule(&ggc->echo_timer, ggc->echo_interval, 0);
|
osmo_timer_schedule(&ggc->echo_timer, ggc->echo_interval, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id)
|
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(struct sgsn_instance *sgsn, uint32_t id)
|
||||||
{
|
{
|
||||||
struct sgsn_ggsn_ctx *ggc;
|
struct sgsn_ggsn_ctx *ggc;
|
||||||
|
|
||||||
ggc = talloc_zero(tall_sgsn_ctx, struct sgsn_ggsn_ctx);
|
ggc = talloc_zero(sgsn, struct sgsn_ggsn_ctx);
|
||||||
if (!ggc)
|
if (!ggc)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -86,7 +84,7 @@ void sgsn_ggsn_ctx_free(struct sgsn_ggsn_ctx *ggc)
|
||||||
talloc_free(ggc);
|
talloc_free(ggc);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id)
|
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(struct sgsn_instance *sgsn, uint32_t id)
|
||||||
{
|
{
|
||||||
struct sgsn_ggsn_ctx *ggc;
|
struct sgsn_ggsn_ctx *ggc;
|
||||||
|
|
||||||
|
@ -97,7 +95,7 @@ struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr)
|
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct sgsn_instance *sgsn, struct in_addr *addr)
|
||||||
{
|
{
|
||||||
struct sgsn_ggsn_ctx *ggc;
|
struct sgsn_ggsn_ctx *ggc;
|
||||||
|
|
||||||
|
@ -109,13 +107,13 @@ struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id)
|
struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(struct sgsn_instance *sgsn, uint32_t id)
|
||||||
{
|
{
|
||||||
struct sgsn_ggsn_ctx *ggc;
|
struct sgsn_ggsn_ctx *ggc;
|
||||||
|
|
||||||
ggc = sgsn_ggsn_ctx_by_id(id);
|
ggc = sgsn_ggsn_ctx_by_id(sgsn, id);
|
||||||
if (!ggc)
|
if (!ggc)
|
||||||
ggc = sgsn_ggsn_ctx_alloc(id);
|
ggc = sgsn_ggsn_ctx_alloc(sgsn, id);
|
||||||
return ggc;
|
return ggc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ static bool _eutran_tai_equal(const struct osmo_eutran_tai *t1, const struct osm
|
||||||
struct sgsn_mme_ctx *sgsn_mme_ctx_alloc(struct sgsn_instance *sgsn, const char *name)
|
struct sgsn_mme_ctx *sgsn_mme_ctx_alloc(struct sgsn_instance *sgsn, const char *name)
|
||||||
{
|
{
|
||||||
struct sgsn_mme_ctx *mme;
|
struct sgsn_mme_ctx *mme;
|
||||||
mme = talloc_zero(tall_sgsn_ctx, struct sgsn_mme_ctx);
|
mme = talloc_zero(sgsn, struct sgsn_mme_ctx);
|
||||||
if (!mme)
|
if (!mme)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -600,7 +600,7 @@ static int cb_recovery3(struct gsn_t *gsn, struct sockaddr_in *peer, struct pdp_
|
||||||
struct sgsn_ggsn_ctx *ggsn;
|
struct sgsn_ggsn_ctx *ggsn;
|
||||||
struct sgsn_pdp_ctx *pctx = NULL;
|
struct sgsn_pdp_ctx *pctx = NULL;
|
||||||
|
|
||||||
ggsn = sgsn_ggsn_ctx_by_addr(&peer->sin_addr);
|
ggsn = sgsn_ggsn_ctx_by_addr(sgsn, &peer->sin_addr);
|
||||||
if (!ggsn) {
|
if (!ggsn) {
|
||||||
LOGP(DGPRS, LOGL_NOTICE, "Received Recovery IE for unknown GGSN\n");
|
LOGP(DGPRS, LOGL_NOTICE, "Received Recovery IE for unknown GGSN\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -422,7 +422,7 @@ DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd,
|
||||||
"IPv4 Address\n")
|
"IPv4 Address\n")
|
||||||
{
|
{
|
||||||
uint32_t id = atoi(argv[0]);
|
uint32_t id = atoi(argv[0]);
|
||||||
struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
|
struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(sgsn, id);
|
||||||
|
|
||||||
inet_aton(argv[1], &ggc->remote_addr);
|
inet_aton(argv[1], &ggc->remote_addr);
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd,
|
||||||
"Version 0\n" "Version 1\n")
|
"Version 0\n" "Version 1\n")
|
||||||
{
|
{
|
||||||
uint32_t id = atoi(argv[0]);
|
uint32_t id = atoi(argv[0]);
|
||||||
struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
|
struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(sgsn, id);
|
||||||
|
|
||||||
if (atoi(argv[1]))
|
if (atoi(argv[1]))
|
||||||
ggc->gtp_version = 1;
|
ggc->gtp_version = 1;
|
||||||
|
@ -465,7 +465,7 @@ DEFUN(cfg_ggsn_echo_interval, cfg_ggsn_echo_interval_cmd,
|
||||||
"Interval between echo requests in seconds.\n")
|
"Interval between echo requests in seconds.\n")
|
||||||
{
|
{
|
||||||
uint32_t id = atoi(argv[0]);
|
uint32_t id = atoi(argv[0]);
|
||||||
struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
|
struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(sgsn, id);
|
||||||
|
|
||||||
ggc->echo_interval = atoi(argv[1]);
|
ggc->echo_interval = atoi(argv[1]);
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ DEFUN(cfg_ggsn_no_echo_interval, cfg_ggsn_no_echo_interval_cmd,
|
||||||
NO_STR "Send an echo request to this static GGSN every interval.\n")
|
NO_STR "Send an echo request to this static GGSN every interval.\n")
|
||||||
{
|
{
|
||||||
uint32_t id = atoi(argv[0]);
|
uint32_t id = atoi(argv[0]);
|
||||||
struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
|
struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(sgsn, id);
|
||||||
|
|
||||||
ggc->echo_interval = 0;
|
ggc->echo_interval = 0;
|
||||||
sgsn_ggsn_ctx_check_echo_timer(ggc);
|
sgsn_ggsn_ctx_check_echo_timer(ggc);
|
||||||
|
@ -525,7 +525,7 @@ static int add_apn_ggsn_mapping(struct vty *vty, const char *apn_str,
|
||||||
struct apn_ctx *actx;
|
struct apn_ctx *actx;
|
||||||
struct sgsn_ggsn_ctx *ggsn;
|
struct sgsn_ggsn_ctx *ggsn;
|
||||||
|
|
||||||
ggsn = sgsn_ggsn_ctx_by_id(ggsn_id);
|
ggsn = sgsn_ggsn_ctx_by_id(sgsn, ggsn_id);
|
||||||
if (ggsn == NULL) {
|
if (ggsn == NULL) {
|
||||||
vty_out(vty, "%% a GGSN with id %d has not been defined%s",
|
vty_out(vty, "%% a GGSN with id %d has not been defined%s",
|
||||||
ggsn_id, VTY_NEWLINE);
|
ggsn_id, VTY_NEWLINE);
|
||||||
|
|
|
@ -1473,9 +1473,9 @@ static void test_ggsn_selection(void)
|
||||||
|
|
||||||
/* TODO: Add PDP info entries to s1 */
|
/* TODO: Add PDP info entries to s1 */
|
||||||
|
|
||||||
ggcs[0] = sgsn_ggsn_ctx_find_alloc(0);
|
ggcs[0] = sgsn_ggsn_ctx_find_alloc(sgsn, 0);
|
||||||
ggcs[1] = sgsn_ggsn_ctx_find_alloc(1);
|
ggcs[1] = sgsn_ggsn_ctx_find_alloc(sgsn, 1);
|
||||||
ggcs[2] = sgsn_ggsn_ctx_find_alloc(2);
|
ggcs[2] = sgsn_ggsn_ctx_find_alloc(sgsn, 2);
|
||||||
|
|
||||||
actxs[0] = sgsn_apn_ctx_find_alloc("test.apn", "123456");
|
actxs[0] = sgsn_apn_ctx_find_alloc("test.apn", "123456");
|
||||||
actxs[0]->ggsn = ggcs[0];
|
actxs[0]->ggsn = ggcs[0];
|
||||||
|
|
Loading…
Reference in New Issue