Removing deplicated error codes.

master
Pedro Alvarez 5 years ago committed by Andre Puschmann
parent bd3ec34f7b
commit d67d18cc6b

@ -86,22 +86,6 @@
namespace srslte {
typedef enum{
ERROR_NONE = 0,
ERROR_INVALID_PARAMS,
ERROR_INVALID_COMMAND,
ERROR_OUT_OF_BOUNDS,
ERROR_CANT_START,
ERROR_ALREADY_STARTED,
ERROR_N_ITEMS,
}error_t;
static const char error_text[ERROR_N_ITEMS][20] = { "None",
"Invalid parameters",
"Invalid command",
"Out of bounds",
"Can't start",
"Already started"};
//#define ENABLE_TIMESTAMP
/******************************************************************************

@ -54,12 +54,15 @@
#define STRING2(x) #x
#define STRING(x) STRING2(x)
// Common error codes
#define SRSLTE_SUCCESS 0
#define SRSLTE_ERROR -1
#define SRSLTE_ERROR_INVALID_INPUTS -2
#define SRSLTE_ERROR_TIMEOUT -3
#define SRSLTE_ERROR_INVALID_COMMAND -4
#define SRSLTE_ERROR_OUT_OF_BOUNDS -5
#define SRSLTE_ERROR_CANT_START -6
#define SRSLTE_ERROR_ALREADY_STARTED -7
// cf_t definition
typedef _Complex float cf_t;

@ -102,8 +102,7 @@ public:
class gw_interface_nas
{
public:
virtual srslte::error_t
setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_id, char* err_str) = 0;
virtual int setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t *ipv6_if_id, char *err_str) = 0;
};
// GW interface for RRC

@ -147,7 +147,7 @@ uint8_t security_128_eia1( uint8_t *key,
for(i=0; i<4; i++) {
mac[i] = m_ptr[i];
}
return ERROR_NONE;
return SRSLTE_SUCCESS;
}
uint8_t security_128_eia2( uint8_t *key,

@ -78,8 +78,8 @@ private:
virtual ~mbms_gw();
static mbms_gw *m_instance;
srslte::error_t init_sgi_mb_if(mbms_gw_args_t *args);
srslte::error_t init_m1_u(mbms_gw_args_t *args);
int init_sgi_mb_if(mbms_gw_args_t *args);
int init_m1_u(mbms_gw_args_t *args);
void handle_sgi_md_pdu(srslte::byte_buffer_t *msg);
uint16_t in_cksum(uint16_t *iphdr, int count);

@ -42,8 +42,8 @@ public:
const std::map<std::string, uint64_t>& ip_to_imsi);
void stop();
srslte::error_t init_s11(spgw_args_t* args);
srslte::error_t init_ue_ip(spgw_args_t* args, const std::map<std::string, uint64_t>& ip_to_imsi);
int init_s11(spgw_args_t* args);
int init_ue_ip(spgw_args_t* args, const std::map<std::string, uint64_t>& ip_to_imsi);
int get_s11();
uint64_t get_new_ctrl_teid();

@ -39,8 +39,8 @@ public:
int init(spgw_args_t* args, spgw* spgw, gtpc_interface_gtpu* gtpc, srslte::log_filter* gtpu_log);
void stop();
srslte::error_t init_sgi(spgw_args_t* args);
srslte::error_t init_s1u(spgw_args_t* args);
int init_sgi(spgw_args_t* args);
int init_s1u(spgw_args_t* args);
int get_sgi();
int get_s1u();

@ -74,29 +74,29 @@ mbms_gw::cleanup(void)
int
mbms_gw::init(mbms_gw_args_t* args, srslte::log_filter *mbms_gw_log)
{
srslte::error_t err;
int err;
m_pool = srslte::byte_buffer_pool::get_instance();
//Init log
m_mbms_gw_log = mbms_gw_log;
err = init_sgi_mb_if(args);
if (err != srslte::ERROR_NONE)
if (err != SRSLTE_SUCCESS)
{
m_mbms_gw_log->console("Error initializing SGi-MB.\n");
m_mbms_gw_log->error("Error initializing SGi-MB.\n");
return -1;
return SRSLTE_ERROR_CANT_START;
}
err = init_m1_u(args);
if (err != srslte::ERROR_NONE)
if (err != SRSLTE_SUCCESS)
{
m_mbms_gw_log->console("Error initializing SGi-MB.\n");
m_mbms_gw_log->error("Error initializing SGi-MB.\n");
return -1;
return SRSLTE_ERROR_CANT_START;
}
m_mbms_gw_log->info("MBMS GW Initiated\n");
m_mbms_gw_log->console("MBMS GW Initiated\n");
return 0;
return SRSLTE_SUCCESS;
}
void
@ -116,14 +116,14 @@ mbms_gw::stop()
return;
}
srslte::error_t
int
mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args)
{
struct ifreq ifr;
if(m_sgi_mb_up)
{
return(srslte::ERROR_ALREADY_STARTED);
return SRSLTE_ERROR_ALREADY_STARTED;
}
@ -132,7 +132,7 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args)
m_mbms_gw_log->info("TUN file descriptor = %d\n", m_sgi_mb_if);
if (m_sgi_mb_if < 0) {
m_mbms_gw_log->error("Failed to open TUN device: %s\n", strerror(errno));
return(srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
memset(&ifr, 0, sizeof(ifr));
@ -143,7 +143,7 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args)
if (ioctl(m_sgi_mb_if, TUNSETIFF, &ifr) < 0) {
m_mbms_gw_log->error("Failed to set TUN device name: %s\n", strerror(errno));
close(m_sgi_mb_if);
return(srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
} else {
m_mbms_gw_log->debug("Set TUN device name: %s\n", args->sgi_mb_if_name.c_str());
}
@ -154,7 +154,7 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args)
{
m_mbms_gw_log->error("Failed to bring up socket: %s\n", strerror(errno));
close(m_sgi_mb_if);
return(srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
if(ioctl(sgi_mb_sock, SIOCGIFFLAGS, &ifr) < 0)
@ -162,7 +162,7 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args)
m_mbms_gw_log->error("Failed to bring up interface: %s\n", strerror(errno));
close(m_sgi_mb_if);
close(sgi_mb_sock);
return(srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
@ -171,7 +171,7 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args)
m_mbms_gw_log->error("Failed to set socket flags: %s\n", strerror(errno));
close(sgi_mb_sock);
close(m_sgi_mb_if);
return(srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
//Set IP of the interface
@ -184,7 +184,7 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args)
m_mbms_gw_log->error("Failed to set TUN interface IP. Address: %s, Error: %s\n", args->sgi_mb_if_addr.c_str(), strerror(errno));
close(m_sgi_mb_if);
close(sgi_mb_sock);
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
ifr.ifr_netmask.sa_family = AF_INET;
@ -193,32 +193,30 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args)
m_mbms_gw_log->error("Failed to set TUN interface Netmask. Error: %s\n", strerror(errno));
close(m_sgi_mb_if);
close(sgi_mb_sock);
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
m_sgi_mb_up = true;
close(sgi_mb_sock);
return(srslte::ERROR_NONE);
return SRSLTE_SUCCESS;
}
srslte::error_t
mbms_gw::init_m1_u(mbms_gw_args_t *args)
int mbms_gw::init_m1_u(mbms_gw_args_t* args)
{
int addrlen;
struct sockaddr_in addr;
m_m1u = socket(AF_INET, SOCK_DGRAM, 0);
if(m_m1u<0)
{
if (m_m1u < 0) {
m_mbms_gw_log->error("Failed to open socket: %s\n", strerror(errno));
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
m_m1u_up = true;
/* set no loopback */
char loopch = 0;
if(setsockopt(m_m1u, IPPROTO_IP, IP_MULTICAST_LOOP, (char*)&loopch, sizeof(char))<0){
if (setsockopt(m_m1u, IPPROTO_IP, IP_MULTICAST_LOOP, (char*)&loopch, sizeof(char)) < 0) {
m_mbms_gw_log->error("Failed to disable loopback: %s\n", strerror(errno));
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
} else {
m_mbms_gw_log->debug("Loopback disabled\n");
}
@ -227,26 +225,26 @@ mbms_gw::init_m1_u(mbms_gw_args_t *args)
/* The IP must be associated with a local multicast capable interface */
struct in_addr local_if;
local_if.s_addr = inet_addr(args->m1u_multi_if.c_str());
if(setsockopt(m_m1u, IPPROTO_IP, IP_MULTICAST_IF, (char*)&local_if, sizeof(struct in_addr))<0){
if (setsockopt(m_m1u, IPPROTO_IP, IP_MULTICAST_IF, (char*)&local_if, sizeof(struct in_addr)) < 0) {
m_mbms_gw_log->error("Error %s setting multicast interface %s.\n", strerror(errno), args->m1u_multi_if.c_str());
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
} else {
printf("Multicast interface specified. Address: %s\n", args->m1u_multi_if.c_str());
}
/*Set Multicast TTL*/
if ( setsockopt(m_m1u, IPPROTO_IP,IP_MULTICAST_TTL,&args->m1u_multi_ttl,sizeof(args->m1u_multi_ttl)) <0 ) {
if (setsockopt(m_m1u, IPPROTO_IP, IP_MULTICAST_TTL, &args->m1u_multi_ttl, sizeof(args->m1u_multi_ttl)) < 0) {
perror("Error setting multicast ttl.\n");
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
bzero(&m_m1u_multi_addr,sizeof(m_m1u_multi_addr));
bzero(&m_m1u_multi_addr, sizeof(m_m1u_multi_addr));
m_m1u_multi_addr.sin_family = AF_INET;
m_m1u_multi_addr.sin_port = htons(GTPU_RX_PORT+1);
m_m1u_multi_addr.sin_port = htons(GTPU_RX_PORT + 1);
m_m1u_multi_addr.sin_addr.s_addr = inet_addr(args->m1u_multi_addr.c_str());
m_mbms_gw_log->info("Initialized M1-U\n");
return srslte::ERROR_NONE;
return SRSLTE_SUCCESS;
}
void

@ -55,7 +55,7 @@ int spgw::gtpc::init(spgw_args_t* args,
srslte::log_filter* gtpc_log,
const std::map<std::string, uint64_t>& ip_to_imsi)
{
srslte::error_t err;
int err;
m_pool = srslte::byte_buffer_pool::get_instance();
// Init log
@ -67,16 +67,16 @@ int spgw::gtpc::init(spgw_args_t* args,
// Init S11 interface
err = init_s11(args);
if (err != srslte::ERROR_NONE) {
if (err != SRSLTE_SUCCESS) {
m_gtpc_log->console("Could not initialize the S11 interface.\n");
return -1;
return err;
}
// Init IP pool
err = init_ue_ip(args, ip_to_imsi);
if (err != srslte::ERROR_NONE) {
if (err != SRSLTE_SUCCESS) {
m_gtpc_log->console("Could not initialize the IP pool.\n");
return -1;
return err;
}
// Limit paging queue
@ -99,7 +99,7 @@ void spgw::gtpc::stop()
return;
}
srslte::error_t spgw::gtpc::init_s11(spgw_args_t* args)
int spgw::gtpc::init_s11(spgw_args_t* args)
{
socklen_t sock_len;
char spgw_addr_name[] = "@spgw_s11";
@ -112,7 +112,7 @@ srslte::error_t spgw::gtpc::init_s11(spgw_args_t* args)
m_s11 = socket(AF_UNIX, SOCK_DGRAM, 0);
if (m_s11 < 0) {
m_gtpc_log->error("Error opening UNIX socket. Error %s\n", strerror(errno));
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
// Set MME Address
@ -130,9 +130,9 @@ srslte::error_t spgw::gtpc::init_s11(spgw_args_t* args)
// Bind socket to address
if (bind(m_s11, (const struct sockaddr*)&m_spgw_addr, sizeof(m_spgw_addr)) == -1) {
m_gtpc_log->error("Error binding UNIX socket. Error %s\n", strerror(errno));
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
return srslte::ERROR_NONE;
return SRSLTE_SUCCESS;
}
bool spgw::gtpc::send_s11_pdu(const srslte::gtpc_pdu& pdu)
@ -537,7 +537,7 @@ bool spgw::gtpc::free_all_queued_packets(spgw_tunnel_ctx_t* tunnel_ctx)
return true;
}
srslte::error_t spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map<std::string, uint64_t>& ip_to_imsi)
int spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map<std::string, uint64_t>& ip_to_imsi)
{
std::map<std::string, uint64_t>::const_iterator iter = ip_to_imsi.find(args->sgi_if_addr);
@ -545,7 +545,7 @@ srslte::error_t spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map<std::st
if (iter != ip_to_imsi.end()) {
m_gtpc_log->error("SPGW: static ip addr %s for imsi %015" PRIu64 ", is reserved for the epc tun interface\n",
iter->first.c_str(), iter->second);
return srslte::ERROR_OUT_OF_BOUNDS;
return SRSLTE_ERROR_OUT_OF_BOUNDS;
}
// load our imsi to ip lookup table
@ -554,7 +554,7 @@ srslte::error_t spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map<std::st
in_addr.s_addr = inet_addr(iter->first.c_str());
if (!m_imsi_to_ip.insert(std::make_pair(iter->second, in_addr)).second) {
m_gtpc_log->error("SPGW: duplicate imsi %015" PRIu64 " for static ip address %s.\n", iter->second, iter->first.c_str());
return srslte::ERROR_OUT_OF_BOUNDS;
return SRSLTE_ERROR_OUT_OF_BOUNDS;
}
}
@ -573,7 +573,7 @@ srslte::error_t spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map<std::st
m_gtpc_log->debug("SPGW: init_ue_ip ue ip addr %s is added to pool\n", inet_ntoa(ue_addr));
}
}
return srslte::ERROR_NONE;
return SRSLTE_SUCCESS;
}
in_addr_t spgw::gtpc::get_new_ue_ipv4(uint64_t imsi)

@ -54,7 +54,7 @@ spgw::gtpu::~gtpu()
int spgw::gtpu::init(spgw_args_t* args, spgw* spgw, gtpc_interface_gtpu* gtpc, srslte::log_filter* gtpu_log)
{
srslte::error_t err;
int err;
// Init log
m_gtpu_log = gtpu_log;
@ -65,21 +65,21 @@ int spgw::gtpu::init(spgw_args_t* args, spgw* spgw, gtpc_interface_gtpu* gtpc, s
// Init SGi interface
err = init_sgi(args);
if (err != srslte::ERROR_NONE) {
if (err != SRSLTE_SUCCESS) {
m_gtpu_log->console("Could not initialize the SGi interface.\n");
return -1;
return err;
}
// Init S1-U
err = init_s1u(args);
if (err != srslte::ERROR_NONE) {
if (err != SRSLTE_SUCCESS) {
m_gtpu_log->console("Could not initialize the S1-U interface.\n");
return -1;
return err;
}
m_gtpu_log->info("SPGW GTP-U Initialized.\n");
m_gtpu_log->console("SPGW GTP-U Initialized.\n");
return 0;
return SRSLTE_SUCCESS;
}
void spgw::gtpu::stop()
@ -94,13 +94,13 @@ void spgw::gtpu::stop()
}
}
srslte::error_t spgw::gtpu::init_sgi(spgw_args_t* args)
int spgw::gtpu::init_sgi(spgw_args_t* args)
{
struct ifreq ifr;
int sgi_sock;
if (m_sgi_up) {
return (srslte::ERROR_ALREADY_STARTED);
return SRSLTE_ERROR_ALREADY_STARTED;
}
// Construct the TUN device
@ -108,7 +108,7 @@ srslte::error_t spgw::gtpu::init_sgi(spgw_args_t* args)
m_gtpu_log->info("TUN file descriptor = %d\n", m_sgi);
if (m_sgi < 0) {
m_gtpu_log->error("Failed to open TUN device: %s\n", strerror(errno));
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
memset(&ifr, 0, sizeof(ifr));
@ -120,7 +120,7 @@ srslte::error_t spgw::gtpu::init_sgi(spgw_args_t* args)
if (ioctl(m_sgi, TUNSETIFF, &ifr) < 0) {
m_gtpu_log->error("Failed to set TUN device name: %s\n", strerror(errno));
close(m_sgi);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
// Bring up the interface
@ -128,7 +128,7 @@ srslte::error_t spgw::gtpu::init_sgi(spgw_args_t* args)
if (ioctl(sgi_sock, SIOCGIFFLAGS, &ifr) < 0) {
m_gtpu_log->error("Failed to bring up socket: %s\n", strerror(errno));
close(m_sgi);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
@ -136,7 +136,7 @@ srslte::error_t spgw::gtpu::init_sgi(spgw_args_t* args)
m_gtpu_log->error("Failed to set socket flags: %s\n", strerror(errno));
close(sgi_sock);
close(m_sgi);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
// Set IP of the interface
@ -150,7 +150,7 @@ srslte::error_t spgw::gtpu::init_sgi(spgw_args_t* args)
strerror(errno));
close(m_sgi);
close(sgi_sock);
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
ifr.ifr_netmask.sa_family = AF_INET;
@ -159,22 +159,22 @@ srslte::error_t spgw::gtpu::init_sgi(spgw_args_t* args)
m_gtpu_log->error("Failed to set TUN interface Netmask. Error: %s\n", strerror(errno));
close(m_sgi);
close(sgi_sock);
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
close(sgi_sock);
m_sgi_up = true;
m_gtpu_log->info("Initialized SGi interface\n");
return (srslte::ERROR_NONE);
return SRSLTE_SUCCESS;
}
srslte::error_t spgw::gtpu::init_s1u(spgw_args_t* args)
int spgw::gtpu::init_s1u(spgw_args_t* args)
{
// Open S1-U socket
m_s1u = socket(AF_INET, SOCK_DGRAM, 0);
if (m_s1u == -1) {
m_gtpu_log->error("Failed to open socket: %s\n", strerror(errno));
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
m_s1u_up = true;
@ -185,13 +185,13 @@ srslte::error_t spgw::gtpu::init_s1u(spgw_args_t* args)
if (bind(m_s1u, (struct sockaddr*)&m_s1u_addr, sizeof(struct sockaddr_in))) {
m_gtpu_log->error("Failed to bind socket: %s\n", strerror(errno));
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
m_gtpu_log->info("S1-U socket = %d\n", m_s1u);
m_gtpu_log->info("S1-U IP = %s, Port = %d \n", inet_ntoa(m_s1u_addr.sin_addr), ntohs(m_s1u_addr.sin_port));
m_gtpu_log->info("Initialized S1-U interface\n");
return srslte::ERROR_NONE;
return SRSLTE_SUCCESS;
}
void spgw::gtpu::handle_sgi_pdu(srslte::byte_buffer_t* msg)

@ -71,27 +71,27 @@ int spgw::init(spgw_args_t* args,
srslte::log_filter* spgw_log,
const std::map<std::string, uint64_t>& ip_to_imsi)
{
srslte::error_t err;
int err;
m_pool = srslte::byte_buffer_pool::get_instance();
// Init log
m_spgw_log = spgw_log;
// Init GTP-U
if (m_gtpu->init(args, this, m_gtpc, gtpu_log) != 0) {
if (m_gtpu->init(args, this, m_gtpc, gtpu_log) != SRSLTE_SUCCESS) {
m_spgw_log->console("Could not initialize the SPGW's GTP-U.\n");
return -1;
return SRSLTE_ERROR_CANT_START;
}
// Init GTP-C
if (m_gtpc->init(args, this, m_gtpu, gtpc_log, ip_to_imsi) != 0) {
if (m_gtpc->init(args, this, m_gtpu, gtpc_log, ip_to_imsi) != SRSLTE_SUCCESS) {
m_spgw_log->console("Could not initialize the S1-U interface.\n");
return -1;
return SRSLTE_ERROR_CANT_START;
}
m_spgw_log->info("SP-GW Initialized.\n");
m_spgw_log->console("SP-GW Initialized.\n");
return 0;
return SRSLTE_SUCCESS;
}
void spgw::stop()

@ -58,8 +58,7 @@ public:
void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu);
// NAS interface
srslte::error_t
setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_addr, char* err_str);
int setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_addr, char *err_str);
// RRC interface
void add_mch_port(uint32_t lcid, uint32_t port);
@ -91,11 +90,11 @@ private:
struct timeval metrics_time[3];
void run_thread();
srslte::error_t init_if(char *err_str);
srslte::error_t setup_if_addr4(uint32_t ip_addr, char *err_str);
srslte::error_t setup_if_addr6(uint8_t *ipv6_if_id, char *err_str);
bool find_ipv6_addr(struct in6_addr *in6_out);
void del_ipv6_addr(struct in6_addr *in6p);
int init_if(char* err_str);
int setup_if_addr4(uint32_t ip_addr, char* err_str);
int setup_if_addr6(uint8_t* ipv6_if_id, char* err_str);
bool find_ipv6_addr(struct in6_addr* in6_out);
void del_ipv6_addr(struct in6_addr* in6p);
// MBSFN
int mbsfn_sock_fd; // Sink UDP socket file descriptor

@ -196,19 +196,18 @@ void gw::write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu)
/*******************************************************************************
NAS interface
*******************************************************************************/
srslte::error_t
gw::setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_addr, char* err_str)
int gw::setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_addr, char* err_str)
{
srslte::error_t err;
int err;
if(pdn_type == LIBLTE_MME_PDN_TYPE_IPV4 || pdn_type == LIBLTE_MME_PDN_TYPE_IPV4V6 ){
err = setup_if_addr4(ip_addr, err_str);
if(err!= srslte::ERROR_NONE){
if(err!= SRSLTE_SUCCESS){
return err;
}
}
if(pdn_type == LIBLTE_MME_PDN_TYPE_IPV6 || pdn_type == LIBLTE_MME_PDN_TYPE_IPV4V6 ){
err = setup_if_addr6(ipv6_if_addr, err_str);
if(err!= srslte::ERROR_NONE){
if(err!= SRSLTE_SUCCESS){
return err;
}
}
@ -217,7 +216,7 @@ gw::setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ip
// Setup a thread to receive packets from the TUN device
start(GW_THREAD_PRIO);
return srslte::ERROR_NONE;
return SRSLTE_SUCCESS;
}
@ -333,10 +332,10 @@ void gw::run_thread()
/**************************/
/* TUN Interface Helpers */
/**************************/
srslte::error_t gw::init_if(char *err_str)
int gw::init_if(char *err_str)
{
if (if_up) {
return (srslte::ERROR_ALREADY_STARTED);
return SRSLTE_ERROR_ALREADY_STARTED;
}
// Construct the TUN device
@ -345,7 +344,7 @@ srslte::error_t gw::init_if(char *err_str)
if (0 > tun_fd) {
err_str = strerror(errno);
gw_log->debug("Failed to open TUN device: %s\n", err_str);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
memset(&ifr, 0, sizeof(ifr));
@ -357,7 +356,7 @@ srslte::error_t gw::init_if(char *err_str)
err_str = strerror(errno);
gw_log->debug("Failed to set TUN device name: %s\n", err_str);
close(tun_fd);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
// Bring up the interface
@ -366,14 +365,14 @@ srslte::error_t gw::init_if(char *err_str)
err_str = strerror(errno);
gw_log->debug("Failed to bring up socket: %s\n", err_str);
close(tun_fd);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (0 > ioctl(sock, SIOCSIFFLAGS, &ifr)) {
err_str = strerror(errno);
gw_log->debug("Failed to set socket flags: %s\n", err_str);
close(tun_fd);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
// Delete link-local IPv6 address.
@ -387,16 +386,16 @@ srslte::error_t gw::init_if(char *err_str)
}
if_up = true;
return(srslte::ERROR_NONE);
return SRSLTE_SUCCESS;
}
srslte::error_t gw::setup_if_addr4(uint32_t ip_addr, char *err_str)
int gw::setup_if_addr4(uint32_t ip_addr, char *err_str)
{
if (ip_addr != current_ip_addr) {
if (!if_up) {
if (init_if(err_str)) {
gw_log->error("init_if failed\n");
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
}
@ -408,7 +407,7 @@ srslte::error_t gw::setup_if_addr4(uint32_t ip_addr, char *err_str)
err_str = strerror(errno);
gw_log->debug("Failed to set socket address: %s\n", err_str);
close(tun_fd);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
ifr.ifr_netmask.sa_family = AF_INET;
((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr(args.tun_dev_netmask.c_str());
@ -416,14 +415,14 @@ srslte::error_t gw::setup_if_addr4(uint32_t ip_addr, char *err_str)
err_str = strerror(errno);
gw_log->debug("Failed to set socket netmask: %s\n", err_str);
close(tun_fd);
return (srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
current_ip_addr = ip_addr;
}
return(srslte::ERROR_NONE);
return SRSLTE_SUCCESS;
}
srslte::error_t gw::setup_if_addr6(uint8_t *ipv6_if_id, char *err_str)
int gw::setup_if_addr6(uint8_t *ipv6_if_id, char *err_str)
{
struct sockaddr_in6 sai;
struct in6_ifreq ifr6;
@ -440,7 +439,7 @@ srslte::error_t gw::setup_if_addr6(uint8_t *ipv6_if_id, char *err_str)
if (!if_up) {
if( init_if(err_str) ) {
gw_log->error("init_if failed\n");
return(srslte::ERROR_CANT_START);
return SRSLTE_ERROR_CANT_START;
}
}
@ -450,13 +449,13 @@ srslte::error_t gw::setup_if_addr6(uint8_t *ipv6_if_id, char *err_str)
if(inet_pton(AF_INET6, "fe80::", (void *)&sai.sin6_addr) <= 0) {
gw_log->error("Bad address\n");
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
memcpy(&sai.sin6_addr.s6_addr[8], ipv6_if_id, 8);
if (ioctl(sock, SIOGIFINDEX, &ifr) < 0) {
perror("SIOGIFINDEX");
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
ifr6.ifr6_ifindex = ifr.ifr_ifindex;
ifr6.ifr6_prefixlen = 64;
@ -466,7 +465,7 @@ srslte::error_t gw::setup_if_addr6(uint8_t *ipv6_if_id, char *err_str)
if (ioctl(sock, SIOCSIFADDR, &ifr6) < 0) {
err_str = strerror(errno);
gw_log->error("Could not set IPv6 Link local address. Error %s\n", err_str);
return srslte::ERROR_CANT_START;
return SRSLTE_ERROR_CANT_START;
}
for (int i=0; i<8; i++){
@ -474,7 +473,7 @@ srslte::error_t gw::setup_if_addr6(uint8_t *ipv6_if_id, char *err_str)
}
}
return(srslte::ERROR_NONE);
return SRSLTE_SUCCESS;
}
bool gw::find_ipv6_addr(struct in6_addr *in6_out)

@ -139,9 +139,9 @@ private:
class gw_dummy : public gw_interface_nas, public gw_interface_pdcp
{
error_t setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_id, char* err_str)
int setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_id, char* err_str)
{
return ERROR_NONE;
return SRSLTE_SUCCESS;
}
void write_pdu(uint32_t lcid, unique_byte_buffer_t pdu) {}
void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t sdu) {}

Loading…
Cancel
Save