|
|
@ -590,15 +590,15 @@ int main(int argc, char *argv[])
|
|
|
|
/******************* This is copied from srsue gw **********************/
|
|
|
|
/******************* This is copied from srsue gw **********************/
|
|
|
|
int setup_if_addr(char *ip_addr)
|
|
|
|
int setup_if_addr(char *ip_addr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
char *dev = (char*) "tun_srsenb";
|
|
|
|
char *dev = (char*) "tun_srsenb";
|
|
|
|
|
|
|
|
int sock = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Construct the TUN device
|
|
|
|
// Construct the TUN device
|
|
|
|
int tun_fd = open("/dev/net/tun", O_RDWR);
|
|
|
|
int tun_fd = open("/dev/net/tun", O_RDWR);
|
|
|
|
if(0 > tun_fd)
|
|
|
|
if(0 > tun_fd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
perror("open");
|
|
|
|
perror("open");
|
|
|
|
return(-1);
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct ifreq ifr;
|
|
|
|
struct ifreq ifr;
|
|
|
@ -609,30 +609,23 @@ int setup_if_addr(char *ip_addr)
|
|
|
|
if(0 > ioctl(tun_fd, TUNSETIFF, &ifr))
|
|
|
|
if(0 > ioctl(tun_fd, TUNSETIFF, &ifr))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
perror("ioctl1");
|
|
|
|
perror("ioctl1");
|
|
|
|
close(tun_fd);
|
|
|
|
goto clean_exit;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Bring up the interface
|
|
|
|
// Bring up the interface
|
|
|
|
int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if(0 > ioctl(sock, SIOCGIFFLAGS, &ifr))
|
|
|
|
if(0 > ioctl(sock, SIOCGIFFLAGS, &ifr))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
perror("socket");
|
|
|
|
perror("socket");
|
|
|
|
close(sock);
|
|
|
|
goto clean_exit;
|
|
|
|
close(tun_fd);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
|
|
|
|
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
|
|
|
|
if(0 > ioctl(sock, SIOCSIFFLAGS, &ifr))
|
|
|
|
if(0 > ioctl(sock, SIOCSIFFLAGS, &ifr))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
perror("ioctl2");
|
|
|
|
perror("ioctl2");
|
|
|
|
close(sock);
|
|
|
|
goto clean_exit;
|
|
|
|
close(tun_fd);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
close(sock);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setup the IP address
|
|
|
|
// Setup the IP address
|
|
|
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
ifr.ifr_addr.sa_family = AF_INET;
|
|
|
|
ifr.ifr_addr.sa_family = AF_INET;
|
|
|
@ -640,21 +633,19 @@ int setup_if_addr(char *ip_addr)
|
|
|
|
if(0 > ioctl(sock, SIOCSIFADDR, &ifr))
|
|
|
|
if(0 > ioctl(sock, SIOCSIFADDR, &ifr))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
perror("ioctl");
|
|
|
|
perror("ioctl");
|
|
|
|
close(sock);
|
|
|
|
goto clean_exit;
|
|
|
|
close(tun_fd);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ifr.ifr_netmask.sa_family = AF_INET;
|
|
|
|
ifr.ifr_netmask.sa_family = AF_INET;
|
|
|
|
((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0");
|
|
|
|
((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0");
|
|
|
|
if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr))
|
|
|
|
if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
perror("ioctl");
|
|
|
|
perror("ioctl");
|
|
|
|
close(sock);
|
|
|
|
goto clean_exit;
|
|
|
|
close(tun_fd);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
close(sock);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return(tun_fd);
|
|
|
|
return(tun_fd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clean_exit:
|
|
|
|
|
|
|
|
close(tun_fd);
|
|
|
|
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|