Changed hss ue_ctx map to use unique pointers.

master
Pedro Alvarez 5 years ago
parent 58bd5631e3
commit 98400f65e2

@ -112,7 +112,7 @@ private:
bool set_auth_algo(std::string auth_algo); bool set_auth_algo(std::string auth_algo);
bool read_db_file(std::string db_file); bool read_db_file(std::string db_file);
bool write_db_file(std::string db_file); bool write_db_file(std::string db_file);
const std::unique_ptr<hss_ue_ctx_t>& get_ue_ctx(uint64_t imsi); hss_ue_ctx_t* get_ue_ctx(uint64_t imsi);
std::string hex_string(uint8_t* hex, int size); std::string hex_string(uint8_t* hex, int size);

@ -114,8 +114,8 @@ bool hss::read_db_file(std::string db_filename)
m_hss_log->console("See 'srsepc/user_db.csv.example' for an example.\n\n"); m_hss_log->console("See 'srsepc/user_db.csv.example' for an example.\n\n");
return false; return false;
} }
hss_ue_ctx_t* ue_ctx = new hss_ue_ctx_t; std::unique_ptr<hss_ue_ctx_t> ue_ctx = std::unique_ptr<hss_ue_ctx_t>(new hss_ue_ctx_t);
ue_ctx->name = split[0]; ue_ctx->name = split[0];
if (split[1] == std::string("xor")) { if (split[1] == std::string("xor")) {
ue_ctx->algo = HSS_ALGO_XOR; ue_ctx->algo = HSS_ALGO_XOR;
} else if (split[1] == std::string("mil")) { } else if (split[1] == std::string("mil")) {
@ -168,7 +168,7 @@ bool hss::read_db_file(std::string db_filename)
return false; return false;
} }
} }
m_imsi_to_ue_ctx.insert(std::pair<uint64_t, hss_ue_ctx_t*>(ue_ctx->imsi, ue_ctx)); m_imsi_to_ue_ctx.insert(std::pair<uint64_t, std::unique_ptr<hss_ue_ctx_t> >(ue_ctx->imsi, std::move(ue_ctx)));
} }
} }
@ -256,15 +256,15 @@ bool hss::write_db_file(std::string db_filename)
bool hss::gen_auth_info_answer(uint64_t imsi, uint8_t* k_asme, uint8_t* autn, uint8_t* rand, uint8_t* xres) bool hss::gen_auth_info_answer(uint64_t imsi, uint8_t* k_asme, uint8_t* autn, uint8_t* rand, uint8_t* xres)
{ {
hss_ue_ctx_t* ue_ctx = NULL;
bool ret = get_ue_ctx(imsi, &ue_ctx); hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
if (ret == false) { if (ue_ctx == nullptr) {
m_hss_log->console("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi); m_hss_log->console("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi);
m_hss_log->error("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi); m_hss_log->error("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi);
return false; return false;
} }
bool ret = false; // FIXME
switch (ue_ctx->algo) { switch (ue_ctx->algo) {
case HSS_ALGO_XOR: case HSS_ALGO_XOR:
ret = gen_auth_info_answer_xor(imsi, k_asme, autn, rand, xres); ret = gen_auth_info_answer_xor(imsi, k_asme, autn, rand, xres);
@ -459,15 +459,15 @@ bool hss::get_k_amf_opc_sqn(uint64_t imsi, uint8_t* k, uint8_t* amf, uint8_t* op
bool hss::resync_sqn(uint64_t imsi, uint8_t* auts) bool hss::resync_sqn(uint64_t imsi, uint8_t* auts)
{ {
hss_ue_ctx_t* ue_ctx = NULL;
bool ret = get_ue_ctx(imsi, &ue_ctx); hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
if (ret == false) { if (ue_ctx == nullptr) {
m_hss_log->console("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi); m_hss_log->console("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi);
m_hss_log->error("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi); m_hss_log->error("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi);
return false; return false;
} }
bool ret = false; //FIXME
switch (ue_ctx->algo) { switch (ue_ctx->algo) {
case HSS_ALGO_XOR: case HSS_ALGO_XOR:
ret = resync_sqn_xor(imsi, auts); ret = resync_sqn_xor(imsi, auts);
@ -548,9 +548,8 @@ bool hss::resync_sqn_milenage(uint64_t imsi, uint8_t* auts)
void hss::increment_ue_sqn(uint64_t imsi) void hss::increment_ue_sqn(uint64_t imsi)
{ {
hss_ue_ctx_t* ue_ctx = NULL; hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
bool ret = get_ue_ctx(imsi, &ue_ctx); if (ue_ctx == nullptr) {
if (ret == false) {
return; return;
} }
@ -592,9 +591,8 @@ void hss::increment_sqn(uint8_t* sqn, uint8_t* next_sqn)
void hss::increment_seq_after_resync(uint64_t imsi) void hss::increment_seq_after_resync(uint64_t imsi)
{ {
// This function only increment the SEQ part of the SQN for resynchronization purpose // This function only increment the SEQ part of the SQN for resynchronization purpose
hss_ue_ctx_t* ue_ctx = NULL; hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
bool ret = get_ue_ctx(imsi, &ue_ctx); if (ue_ctx == nullptr) {
if (ret == false) {
return; return;
} }
@ -627,9 +625,8 @@ void hss::increment_seq_after_resync(uint64_t imsi)
void hss::set_sqn(uint64_t imsi, uint8_t* sqn) void hss::set_sqn(uint64_t imsi, uint8_t* sqn)
{ {
hss_ue_ctx_t* ue_ctx = NULL; hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
bool ret = get_ue_ctx(imsi, &ue_ctx); if (ue_ctx == nullptr) {
if (ret == false) {
return; return;
} }
memcpy(ue_ctx->sqn, sqn, 6); memcpy(ue_ctx->sqn, sqn, 6);
@ -637,9 +634,8 @@ void hss::set_sqn(uint64_t imsi, uint8_t* sqn)
void hss::set_last_rand(uint64_t imsi, uint8_t* rand) void hss::set_last_rand(uint64_t imsi, uint8_t* rand)
{ {
hss_ue_ctx_t* ue_ctx = NULL; hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
bool ret = get_ue_ctx(imsi, &ue_ctx); if (ue_ctx == nullptr) {
if (ret == false) {
return; return;
} }
memcpy(ue_ctx->last_rand, rand, 16); memcpy(ue_ctx->last_rand, rand, 16);
@ -647,9 +643,8 @@ void hss::set_last_rand(uint64_t imsi, uint8_t* rand)
void hss::get_last_rand(uint64_t imsi, uint8_t* rand) void hss::get_last_rand(uint64_t imsi, uint8_t* rand)
{ {
hss_ue_ctx_t* ue_ctx = NULL; hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
bool ret = get_ue_ctx(imsi, &ue_ctx); if (ue_ctx == nullptr) {
if (ret == false) {
return; return;
} }
memcpy(rand, ue_ctx->last_rand, 16); memcpy(rand, ue_ctx->last_rand, 16);
@ -663,16 +658,15 @@ void hss::gen_rand(uint8_t rand_[16])
return; return;
} }
const std::unique_ptr<hss_ue_ctx_t>& hss::get_ue_ctx(uint64_t imsi) hss_ue_ctx_t* hss::get_ue_ctx(uint64_t imsi)
{ {
std::map<uint64_t, std::unique_ptr<hss_ue_ctx_t> >::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); std::map<uint64_t, std::unique_ptr<hss_ue_ctx_t> >::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi);
if (ue_ctx_it == m_imsi_to_ue_ctx.end()) { if (ue_ctx_it == m_imsi_to_ue_ctx.end()) {
m_hss_log->info("User not found. IMSI: %015" PRIu64 "\n", imsi); m_hss_log->info("User not found. IMSI: %015" PRIu64 "\n", imsi);
return false; return nullptr;
} }
*ue_ctx = ue_ctx_it->second; return ue_ctx_it->second.get();
return true;
} }
/* Helper functions*/ /* Helper functions*/

Loading…
Cancel
Save