osmo-epdg: UE: save apn in the UE object

This commit is contained in:
Alexander Couzens 2024-02-18 17:55:49 +01:00
parent 9b427b7341
commit 0e8b7ee01d
3 changed files with 38 additions and 3 deletions

View File

@ -22,6 +22,8 @@
#include <threading/rwlock.h>
#include <unistd.h>
#include <osmocom/gsm/apn.h>
#include "osmo_epdg_plugin.h"
#include "osmo_epdg_db.h"
#include "osmo_epdg_utils.h"
@ -53,6 +55,7 @@ METHOD(osmo_epdg_db_t, create_subscriber, osmo_epdg_ue_t *,
{
osmo_epdg_ue_t *ue;
char imsi[16] = {0};
char apn[APN_MAXLEN];
uint32_t unique = ike_sa->get_unique_id(ike_sa);
if (epdg_get_imsi_ike(ike_sa, imsi, sizeof(imsi) - 1))
@ -60,6 +63,12 @@ METHOD(osmo_epdg_db_t, create_subscriber, osmo_epdg_ue_t *,
return NULL;
}
if (epdg_get_apn(ike_sa, apn, APN_MAXLEN))
{
DBG1(DBG_NET, "epdg: get_quintuplet: Can't get APN.");
return FALSE;
}
this->lock->write_lock(this->lock);
ue = this->subscribers_imsi->remove(this->subscribers_imsi, imsi);
if (ue)
@ -68,7 +77,7 @@ METHOD(osmo_epdg_db_t, create_subscriber, osmo_epdg_ue_t *,
ue->put(ue);
}
ue = osmo_epdg_ue_create(unique, imsi);
ue = osmo_epdg_ue_create(unique, imsi, apn);
if (!ue)
{
DBG1(DBG_NET, "epdg_db: failed to create UE!");

View File

@ -24,6 +24,7 @@
#include <utils/debug.h>
#include "osmo_epdg_ue.h"
#include "osmo_epdg_utils.h"
typedef struct private_osmo_epdg_ue_t private_osmo_epdg_ue_t;
@ -48,6 +49,11 @@ struct private_osmo_epdg_ue_t {
*/
char *imsi;
/**
* APN encoded as character (foo.example)
*/
char *apn;
/**
* IP address of the client. Might become a llist_t in the future
*/
@ -73,6 +79,12 @@ METHOD(osmo_epdg_ue_t, get_imsi, const char *,
return this->imsi;
}
METHOD(osmo_epdg_ue_t, get_apn, const char *,
private_osmo_epdg_ue_t *this)
{
return this->apn;
}
METHOD(osmo_epdg_ue_t, set_address, void,
private_osmo_epdg_ue_t *this, host_t *address)
{
@ -140,18 +152,26 @@ METHOD(osmo_epdg_ue_t, destroy, void,
private_osmo_epdg_ue_t *this)
{
this->lock->destroy(this->lock);
free(this->apn);
free(this->imsi);
free(this);
}
osmo_epdg_ue_t *osmo_epdg_ue_create(uint32_t id, const char *imsi)
osmo_epdg_ue_t *osmo_epdg_ue_create(uint32_t id, const char *imsi, const char *apn)
{
private_osmo_epdg_ue_t *this;
if (epdg_validate_apn(apn) ||
epdg_validate_imsi(imsi))
{
return NULL;
}
INIT(this,
.public = {
.get = _get,
.put = _put,
.get_apn = _get_apn,
.get_imsi = _get_imsi,
.get_address = _get_address,
.set_address = _set_address,
@ -159,6 +179,7 @@ osmo_epdg_ue_t *osmo_epdg_ue_create(uint32_t id, const char *imsi)
.set_state = _set_state,
.destroy = _destroy,
},
.apn = strdup(apn),
.imsi = strdup(imsi),
.id = id,
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),

View File

@ -55,6 +55,11 @@ enum osmo_epdg_ue_state {
* UE object
*/
struct osmo_epdg_ue_t {
/**
* Get APN
*/
const char *(*get_apn)(osmo_epdg_ue_t *this);
/**
* Get IMSI
*/
@ -103,6 +108,6 @@ struct osmo_epdg_ue_t {
* Create a osmo_epdg_ue instance.
* A newly created object will come with refcount = 1. Use put() to destroy it.
*/
osmo_epdg_ue_t *osmo_epdg_ue_create(uint32_t id, const char *imsi);
osmo_epdg_ue_t *osmo_epdg_ue_create(uint32_t id, const char *imsi, const char *apn);
#endif /* OSMO_EPDG_UE_H_ */