Start implementing osmo_epdg state
This commit is contained in:
parent
c469464d8a
commit
05d9dc8552
|
@ -22,4 +22,5 @@ libstrongswan_osmo_epdg_la_SOURCES = \
|
|||
osmo_epdg_listener.h osmo_epdg_listener.c \
|
||||
gsup_client.h gsup_client.c \
|
||||
ipa_client.h ipa_client.c \
|
||||
osmo_epdg_utils.h osmo_epdg_utils.c
|
||||
osmo_epdg_utils.h osmo_epdg_utils.c \
|
||||
osmo_epdg_db.h osmo_epdg_db.c
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright (C) 2023 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
|
||||
* Author: Alexander Couzens <acouzens@sysmocom.de>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <daemon.h>
|
||||
#include <plugins/plugin.h>
|
||||
#include <collections/hashtable.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "osmo_epdg_plugin.h"
|
||||
#include "osmo_epdg_db.h"
|
||||
#include "osmo_epdg_utils.h"
|
||||
|
||||
typedef struct private_osmo_epdg_db_t private_osmo_epdg_db_t;
|
||||
|
||||
/**
|
||||
* Private data of an osmo_epdg_db_t object.
|
||||
*/
|
||||
struct private_osmo_epdg_db_t {
|
||||
/**
|
||||
* Public osmo_epdg_db_t interface.
|
||||
*/
|
||||
osmo_epdg_db_t public;
|
||||
|
||||
/**
|
||||
* GSUP client
|
||||
*/
|
||||
osmo_epdg_gsup_client_t *gsup;
|
||||
|
||||
/**
|
||||
* subscriber hash by ID
|
||||
*/
|
||||
hashtable_t *subscribers;
|
||||
|
||||
/**
|
||||
* subscriber hash by imsi (how to handle multiple?)
|
||||
*/
|
||||
hashtable_t *subscribers_imsi;
|
||||
|
||||
/**
|
||||
* subscriber by ike_sa
|
||||
*/
|
||||
hashtable_t *subscribers_ike_sa_t;
|
||||
};
|
||||
|
||||
METHOD(osmo_epdg_db_t, create_subscriber_imsi, osmo_epdg_ue_t *,
|
||||
private_osmo_epdg_db_t *this, ike_sa_t *ike_sa,
|
||||
char *imsi)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
METHOD(osmo_epdg_db_t, get_subscriber_imsi, osmo_epdg_ue_t *,
|
||||
private_osmo_epdg_db_t *this, char *imsi, int offset)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
METHOD(osmo_epdg_db_t, get_subscriber_id, osmo_epdg_ue_t *,
|
||||
private_osmo_epdg_db_t *this, uint32_t id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
METHOD(osmo_epdg_db_t, get_subscriber_ike, osmo_epdg_ue_t *,
|
||||
private_osmo_epdg_db_t *this, ike_sa_t *ike_sa)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
METHOD(osmo_epdg_db_t, destroy_subscriber_id, void,
|
||||
private_osmo_epdg_db_t *this, uint32_t id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
METHOD(osmo_epdg_db_t, destroy_subscriber_ike, void,
|
||||
private_osmo_epdg_db_t *this, ike_sa_t *ike_sa)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
METHOD(osmo_epdg_db_t, destroy_subscriber, void,
|
||||
private_osmo_epdg_db_t *this, osmo_epdg_ue_t *ue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
METHOD(osmo_epdg_db_t, destroy, void,
|
||||
private_osmo_epdg_db_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* See header
|
||||
*/
|
||||
osmo_epdg_db_t *osmo_epdg_db_create(osmo_epdg_gsup_client_t *gsup)
|
||||
{
|
||||
private_osmo_epdg_db_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.create_subscriber = _create_subscriber_imsi,
|
||||
.get_subscriber_id = _get_subscriber_id,
|
||||
.get_subscriber_imsi = _get_subscriber_imsi,
|
||||
.get_subscriber_ike = _get_subscriber_ike,
|
||||
.destroy_subscriber_ike = _destroy_subscriber_ike,
|
||||
.destroy_subscriber_id = _destroy_subscriber_id,
|
||||
.destroy_subscriber = _destroy_subscriber,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (C) 2023 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
|
||||
* Author: Alexander Couzens <acouzens@sysmocom.de>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
// TODO: check license
|
||||
|
||||
/**
|
||||
* @defgroup osmo_epdg_db osmo_epdg_db
|
||||
* @{ @ingroup osmo_epdg
|
||||
*/
|
||||
|
||||
#ifndef OSMO_EPDG_DB_H_
|
||||
#define OSMO_EPDG_DB_H_
|
||||
|
||||
#include <bus/listeners/listener.h>
|
||||
#include "gsup_client.h"
|
||||
#include "osmo_epdg_utils.h"
|
||||
|
||||
typedef struct osmo_epdg_db_t osmo_epdg_db_t;
|
||||
|
||||
/**
|
||||
* SIM listener implementation using a set of AKA functions.
|
||||
*/
|
||||
struct osmo_epdg_db_t {
|
||||
/**
|
||||
* Create new subscriber by imsi, before sending authentication
|
||||
*/
|
||||
osmo_epdg_ue_t *(*create_subscriber)(osmo_epdg_db_t *this, ike_sa_t *ike_sa, char *imsi);
|
||||
|
||||
/**
|
||||
* Get subscriber by imsi, there might be multiple UE by this IMSI
|
||||
*/
|
||||
osmo_epdg_ue_t *(*get_subscriber_imsi)(osmo_epdg_db_t *this, char *imsi, int offset);
|
||||
|
||||
/**
|
||||
* Get subscriber by ike
|
||||
*/
|
||||
osmo_epdg_ue_t *(*get_subscriber_ike)(osmo_epdg_db_t *this, ike_sa_t *ike_sa);
|
||||
|
||||
/**
|
||||
* Get subscriber by id
|
||||
*/
|
||||
osmo_epdg_ue_t *(*get_subscriber_id)(osmo_epdg_db_t *this, uint32_t id);
|
||||
|
||||
/**
|
||||
* Destroy subscriber by imsi
|
||||
*/
|
||||
void (*destroy_subscriber_ike)(osmo_epdg_db_t *this, ike_sa_t *ike_sa);
|
||||
|
||||
/**
|
||||
* Destroy subscriber by imsi
|
||||
*/
|
||||
void (*destroy_subscriber_id)(osmo_epdg_db_t *this, uint32_t id);
|
||||
|
||||
/**
|
||||
* Destroy subscriber by object
|
||||
*/
|
||||
void (*destroy_subscriber)(osmo_epdg_db_t *this, osmo_epdg_ue_t *ue);
|
||||
|
||||
/**
|
||||
* Destroy a osmo_epdg_db_t.
|
||||
*/
|
||||
void (*destroy)(osmo_epdg_db_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a osmo_epdg_db instance.
|
||||
*/
|
||||
osmo_epdg_db_t *osmo_epdg_db_create(osmo_epdg_gsup_client_t *gsup);
|
||||
|
||||
#endif /* OSMO_EPDG_DB_H_ */
|
|
@ -27,6 +27,35 @@
|
|||
|
||||
#define IPA_ALLOC_SIZE 1200
|
||||
|
||||
enum ue_state {
|
||||
/* Initial */
|
||||
UE_UNAUTHENTICATED,
|
||||
/* Authenticated */
|
||||
UE_AUTHENTICATED,
|
||||
/* Wait for GSUP Update Location Request */
|
||||
UE_WAIT_LOCATION_UPDATE,
|
||||
/* Wait for GSUP Tunnel Request */
|
||||
UE_WAIT_TUNNEL,
|
||||
/* Everything ready, data can flow */
|
||||
UE_CONNECTED,
|
||||
/* Notify the osmo-epdg about destruction, wait for an answer */
|
||||
UE_DISCONNECTING,
|
||||
UE_DESTROYED,
|
||||
};
|
||||
|
||||
/* TODO: how to clean up/garbage collect */
|
||||
struct osmo_epdg_ue {
|
||||
/* increasing uniq id */
|
||||
uint32_t id;
|
||||
/* imsi should be uniq, need protected against fake UE */
|
||||
char *imsi;
|
||||
enum ue_state state;
|
||||
|
||||
/* TODO: missing strongswan session pointer */
|
||||
ike_sa_t *ike_sa;
|
||||
};
|
||||
typedef struct osmo_epdg_ue osmo_epdg_ue_t;
|
||||
|
||||
struct msgb *chunk_to_msgb(chunk_t *chunk);
|
||||
int get_imsi(identification_t *id, char *imsi, size_t imsi_len);
|
||||
int get_apn(ike_sa_t *sa, char *apn, size_t apn_len);
|
||||
|
|
Loading…
Reference in New Issue