diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 0a31c071e1..01da488020 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -45,6 +45,7 @@ typedef struct { std::string gtpu_bind_addr; std::string sgi_if_addr; std::string sgi_if_name; + std::string sgi_if_netmask; uint32_t max_paging_queue; } spgw_args_t; diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index ee1c3c734c..1a700c0ed2 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -90,6 +90,7 @@ void parse_args(all_args_t* args, int argc, char* argv[]) string spgw_bind_addr; string sgi_if_addr; string sgi_if_name; + string sgi_if_netmask; string dns_addr; string full_net_name; string short_net_name; @@ -128,6 +129,7 @@ void parse_args(all_args_t* args, int argc, char* argv[]) ("spgw.gtpu_bind_addr", bpo::value(&spgw_bind_addr)->default_value("127.0.0.1"), "IP address of SP-GW for the S1-U connection") ("spgw.sgi_if_addr", bpo::value(&sgi_if_addr)->default_value("176.16.0.1"), "IP address of TUN interface for the SGi connection") ("spgw.sgi_if_name", bpo::value(&sgi_if_name)->default_value("srs_spgw_sgi"), "Name of TUN interface for the SGi connection") + ("spgw.sgi_if_netmask", bpo::value(&sgi_if_netmask)->default_value("255.255.255.0"), "IP mask of TUN interface for the SGi connection") ("spgw.max_paging_queue", bpo::value(&max_paging_queue)->default_value(100), "Max number of packets in paging queue") ("pcap.enable", bpo::value(&args->mme_args.s1ap_args.pcap_enable)->default_value(false), "Enable S1AP PCAP") @@ -287,6 +289,7 @@ void parse_args(all_args_t* args, int argc, char* argv[]) args->spgw_args.gtpu_bind_addr = spgw_bind_addr; args->spgw_args.sgi_if_addr = sgi_if_addr; args->spgw_args.sgi_if_name = sgi_if_name; + args->spgw_args.sgi_if_netmask = sgi_if_netmask; args->spgw_args.max_paging_queue = max_paging_queue; args->hss_args.db_file = hss_db_file; diff --git a/srsepc/src/spgw/gtpc.cc b/srsepc/src/spgw/gtpc.cc index 17e4826733..6fb7ce0d24 100644 --- a/srsepc/src/spgw/gtpc.cc +++ b/srsepc/src/spgw/gtpc.cc @@ -561,9 +561,17 @@ int spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::mapsgi_if_netmask.c_str(), &netmask_addr.s_addr) != 1) { + m_logger.error("Invalid sgi_if_netmask: %s", args->sgi_if_netmask.c_str()); + srsran::console("Invalid sgi_if_netmask: %s\n", args->sgi_if_netmask.c_str()); + perror("inet_pton"); + return SRSRAN_ERROR; + } + uint32_t hosts_bound = (~ntohl(netmask_addr.s_addr)) - 1; + // first address is allocated to the epc tun interface, start w/next addr - for (uint32_t n = 1; n < 254; ++n) { + for (uint32_t n = 1; n < hosts_bound; ++n) { struct in_addr ue_addr; if (inet_pton(AF_INET, args->sgi_if_addr.c_str(), &ue_addr.s_addr) != 1) { m_logger.error("Invalid sgi_if_addr: %s", args->sgi_if_addr.c_str()); @@ -571,7 +579,7 @@ int spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map::const_iterator iter = ip_to_imsi.find(inet_ntoa(ue_addr)); if (iter != ip_to_imsi.end()) { diff --git a/srsepc/src/spgw/gtpu.cc b/srsepc/src/spgw/gtpu.cc index b8df8e53aa..eff50c63f6 100644 --- a/srsepc/src/spgw/gtpu.cc +++ b/srsepc/src/spgw/gtpu.cc @@ -156,7 +156,7 @@ int spgw::gtpu::init_sgi(spgw_args_t* args) } ifr.ifr_netmask.sa_family = AF_INET; - if (inet_pton(ifr.ifr_netmask.sa_family , "255.255.255.0", &((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr) != 1) { + if (inet_pton(ifr.ifr_netmask.sa_family , args->sgi_if_netmask.c_str(), &((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr) != 1) { perror("inet_pton"); return false; }