add srsUE parameter to change netns before creating TUN in GW

master
Andre Puschmann 5 years ago
parent 260648582e
commit 77522a6b69

@ -41,6 +41,7 @@ struct gw_args_t {
std::string gw_level;
int gw_hex_limit;
} log;
std::string netns;
std::string tun_dev_name;
std::string tun_dev_netmask;
};
@ -78,6 +79,7 @@ private:
bool running = false;
bool run_enable = false;
int32_t netns_fd = 0;
int32_t tun_fd = 0;
struct ifreq ifr = {};
int32_t sock = 0;

@ -152,6 +152,7 @@ static int parse_args(all_args_t* args, int argc, char* argv[])
("usim.pin", bpo::value<string>(&args->stack.usim.pin), "PIN in case real SIM card is used")
("usim.reader", bpo::value<string>(&args->stack.usim.reader)->default_value(""), "Force specific PCSC reader. Default: Try all available readers.")
("gw.netns", bpo::value<string>(&args->gw.netns)->default_value(""), "Network namespace to for TUN device (empty for default netns)")
("gw.ip_devname", bpo::value<string>(&args->gw.tun_dev_name)->default_value("tun_srsue"), "Name of the tun_srsue device")
("gw.ip_netmask", bpo::value<string>(&args->gw.tun_dev_netmask)->default_value("255.255.255.0"), "Netmask of the tun_srsue device")

@ -342,12 +342,24 @@ int gw::init_if(char* err_str)
return SRSLTE_ERROR_ALREADY_STARTED;
}
// change into netns
if (!args.netns.empty()) {
std::string netns("/run/netns/");
netns += args.netns;
netns_fd = open(netns.c_str(), O_RDONLY);
if (setns(netns_fd, CLONE_NEWNET) == -1) {
err_str = strerror(errno);
log.error("Failed to change netns: %s\n", err_str);
return SRSLTE_ERROR_CANT_START;
}
}
// Construct the TUN device
tun_fd = open("/dev/net/tun", O_RDWR);
log.info("TUN file descriptor = %d\n", tun_fd);
if (0 > tun_fd) {
err_str = strerror(errno);
log.debug("Failed to open TUN device: %s\n", err_str);
log.error("Failed to open TUN device: %s\n", err_str);
return SRSLTE_ERROR_CANT_START;
}
@ -358,7 +370,7 @@ int gw::init_if(char* err_str)
ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0;
if (0 > ioctl(tun_fd, TUNSETIFF, &ifr)) {
err_str = strerror(errno);
log.debug("Failed to set TUN device name: %s\n", err_str);
log.error("Failed to set TUN device name: %s\n", err_str);
close(tun_fd);
return SRSLTE_ERROR_CANT_START;
}
@ -367,14 +379,14 @@ int gw::init_if(char* err_str)
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (0 > ioctl(sock, SIOCGIFFLAGS, &ifr)) {
err_str = strerror(errno);
log.debug("Failed to bring up socket: %s\n", err_str);
log.error("Failed to bring up socket: %s\n", err_str);
close(tun_fd);
return SRSLTE_ERROR_CANT_START;
}
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (0 > ioctl(sock, SIOCSIFFLAGS, &ifr)) {
err_str = strerror(errno);
log.debug("Failed to set socket flags: %s\n", err_str);
log.error("Failed to set socket flags: %s\n", err_str);
close(tun_fd);
return SRSLTE_ERROR_CANT_START;
}

@ -167,10 +167,12 @@ imei = 353490069873319
#####################################################################
# GW configuration
#
# netns: Network namespace to create TUN device. Default: empty
# ip_devname: Name of the tun_srsue device. Default: tun_srsue
# ip_netmask: Netmask of the tun_srsue device. Default: 255.255.255.0
#####################################################################
[gw]
#netns =
#ip_devname = tun_srsue
#ip_netmask = 255.255.255.0

Loading…
Cancel
Save