astyle --recursive --indent=spaces=2 --style=kr --indent-col1-comments --break-blocks --convert-tabs --max-code-length=200
This is done for better merging branch/LG_PRE_RELEASE_0.3 into trunk (same process is applied on this branch) git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7073 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
+218
-213
@@ -53,200 +53,198 @@
|
||||
#include "UTIL/LOG/log.h"
|
||||
|
||||
|
||||
//default values according to the examples,
|
||||
//default values according to the examples,
|
||||
|
||||
char *baseNetAddress = "10.0" ;
|
||||
char *netMask = "255.255.255.0" ;
|
||||
char *broadcastAddr = "10.0.255.255" ;
|
||||
char *baseNetAddress = "10.0" ;
|
||||
char *netMask = "255.255.255.0" ;
|
||||
char *broadcastAddr = "10.0.255.255" ;
|
||||
|
||||
|
||||
void setBaseNetAddress (char* baseAddr){
|
||||
void setBaseNetAddress (char* baseAddr)
|
||||
{
|
||||
strcpy(baseNetAddress,baseAddr);
|
||||
}
|
||||
|
||||
char* getBaseNetAddress (){
|
||||
char* getBaseNetAddress ()
|
||||
{
|
||||
return baseNetAddress;
|
||||
}
|
||||
|
||||
void setNetMask (char* baseAddr){
|
||||
void setNetMask (char* baseAddr)
|
||||
{
|
||||
strcpy(netMask,baseAddr);
|
||||
}
|
||||
|
||||
char* getNetMask (){
|
||||
char* getNetMask ()
|
||||
{
|
||||
return netMask;
|
||||
}
|
||||
|
||||
void setBroadcastAddress (char* baseAddr){
|
||||
void setBroadcastAddress (char* baseAddr)
|
||||
{
|
||||
strcpy(broadcastAddr, baseAddr);
|
||||
}
|
||||
|
||||
char* getBroadcastAddress (){
|
||||
char* getBroadcastAddress ()
|
||||
{
|
||||
return broadcastAddr;
|
||||
}
|
||||
|
||||
//Add Gateway to the interface
|
||||
int set_gateway(char *interfaceName, char *gateway)
|
||||
{
|
||||
int sock_fd;
|
||||
struct rtentry rt;
|
||||
struct sockaddr_in addr;
|
||||
int sock_fd;
|
||||
struct rtentry rt;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
if((sock_fd = socket(AF_INET,SOCK_DGRAM,0)) < 0)
|
||||
{
|
||||
perror("socket failed");
|
||||
return 1;
|
||||
}
|
||||
if((sock_fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) {
|
||||
perror("socket failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset (&rt, 0, sizeof (rt));
|
||||
memset (&rt, 0, sizeof (rt));
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
/*set Destination addr*/
|
||||
inet_aton("0.0.0.0",&addr.sin_addr);
|
||||
memcpy(&rt.rt_dst, &addr, sizeof(struct sockaddr_in));
|
||||
addr.sin_family = AF_INET;
|
||||
/*set Destination addr*/
|
||||
inet_aton("0.0.0.0",&addr.sin_addr);
|
||||
memcpy(&rt.rt_dst, &addr, sizeof(struct sockaddr_in));
|
||||
|
||||
/*set gateway addr*/
|
||||
inet_aton(gateway,&addr.sin_addr);
|
||||
memcpy(&rt.rt_gateway, &addr, sizeof(struct sockaddr_in));
|
||||
/*set gateway addr*/
|
||||
inet_aton(gateway,&addr.sin_addr);
|
||||
memcpy(&rt.rt_gateway, &addr, sizeof(struct sockaddr_in));
|
||||
|
||||
/*set genmask addr*/
|
||||
inet_aton("0.0.0.0",&addr.sin_addr);
|
||||
memcpy(&rt.rt_genmask, &addr, sizeof(struct sockaddr_in));
|
||||
/*set genmask addr*/
|
||||
inet_aton("0.0.0.0",&addr.sin_addr);
|
||||
memcpy(&rt.rt_genmask, &addr, sizeof(struct sockaddr_in));
|
||||
|
||||
rt.rt_dev = interfaceName;
|
||||
//rt.rt_flags = RTF_UP|RTF_GATEWAY|RTF_DEFAULT;
|
||||
/* SR: rt_flags on 16 bits but RTF_DEFAULT = 0x00010000
|
||||
* therefore doesn't lie in container -> disable it
|
||||
*/
|
||||
//rt.rt_flags = RTF_GATEWAY|RTF_DEFAULT;
|
||||
rt.rt_flags = RTF_GATEWAY;
|
||||
|
||||
if (ioctl(sock_fd, SIOCADDRT, &rt) < 0)
|
||||
{
|
||||
close(sock_fd);
|
||||
|
||||
if(strstr(strerror(errno),"File exists") == NULL)
|
||||
{
|
||||
LOG_E(OIP,"ioctl SIOCADDRT failed : %s\n",strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
else /*if SIOCADDRT error is route exist, retrun success*/
|
||||
{
|
||||
LOG_I(OIP,"File Exist ...\n");
|
||||
LOG_I(OIP,"set_gateway OK!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
rt.rt_dev = interfaceName;
|
||||
//rt.rt_flags = RTF_UP|RTF_GATEWAY|RTF_DEFAULT;
|
||||
/* SR: rt_flags on 16 bits but RTF_DEFAULT = 0x00010000
|
||||
* therefore doesn't lie in container -> disable it
|
||||
*/
|
||||
//rt.rt_flags = RTF_GATEWAY|RTF_DEFAULT;
|
||||
rt.rt_flags = RTF_GATEWAY;
|
||||
|
||||
if (ioctl(sock_fd, SIOCADDRT, &rt) < 0) {
|
||||
close(sock_fd);
|
||||
|
||||
LOG_D(OIP,"Set Gateway OK!\n");
|
||||
return 0;
|
||||
if(strstr(strerror(errno),"File exists") == NULL) {
|
||||
LOG_E(OIP,"ioctl SIOCADDRT failed : %s\n",strerror(errno));
|
||||
return 2;
|
||||
} else { /*if SIOCADDRT error is route exist, retrun success*/
|
||||
LOG_I(OIP,"File Exist ...\n");
|
||||
LOG_I(OIP,"set_gateway OK!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
close(sock_fd);
|
||||
|
||||
LOG_D(OIP,"Set Gateway OK!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// sets a genneric interface parameter
|
||||
// (SIOCSIFADDR, SIOCSIFNETMASK, SIOCSIFBRDADDR, SIOCSIFFLAGS)
|
||||
int setInterfaceParameter(char *interfaceName, char *settingAddress, int operation)
|
||||
{
|
||||
int sock_fd;
|
||||
struct ifreq ifr;
|
||||
struct sockaddr_in addr;
|
||||
int sock_fd;
|
||||
struct ifreq ifr;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
if((sock_fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) {
|
||||
LOG_E(OIP,"Setting operation %d, for %s, address, %s : socket failed\n",
|
||||
operation, interfaceName, settingAddress);
|
||||
return 1;
|
||||
}
|
||||
if((sock_fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) {
|
||||
LOG_E(OIP,"Setting operation %d, for %s, address, %s : socket failed\n",
|
||||
operation, interfaceName, settingAddress);
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name)-1);
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name)-1);
|
||||
|
||||
memset(&addr, 0, sizeof(struct sockaddr_in));
|
||||
addr.sin_family = AF_INET;
|
||||
memset(&addr, 0, sizeof(struct sockaddr_in));
|
||||
addr.sin_family = AF_INET;
|
||||
|
||||
inet_aton(settingAddress,&addr.sin_addr);
|
||||
memcpy(&ifr.ifr_ifru.ifru_addr,&addr,sizeof(struct sockaddr_in));
|
||||
|
||||
if(ioctl(sock_fd,operation,&ifr) < 0) {
|
||||
close(sock_fd);
|
||||
LOG_E(OIP,"Setting operation %d, for %s, address, %s : ioctl call failed\n",
|
||||
operation, interfaceName, settingAddress);
|
||||
return 2;
|
||||
}
|
||||
inet_aton(settingAddress,&addr.sin_addr);
|
||||
memcpy(&ifr.ifr_ifru.ifru_addr,&addr,sizeof(struct sockaddr_in));
|
||||
|
||||
if(ioctl(sock_fd,operation,&ifr) < 0) {
|
||||
close(sock_fd);
|
||||
LOG_E(OIP,"Setting operation %d, for %s, address, %s : ioctl call failed\n",
|
||||
operation, interfaceName, settingAddress);
|
||||
return 2;
|
||||
}
|
||||
|
||||
// printf("Set OK!\n");
|
||||
return 0;
|
||||
close(sock_fd);
|
||||
|
||||
// printf("Set OK!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// sets a genneric interface parameter
|
||||
// (SIOCSIFADDR, SIOCSIFNETMASK, SIOCSIFBRDADDR, SIOCSIFFLAGS)
|
||||
int bringInterfaceUp(char *interfaceName, int up)
|
||||
{
|
||||
int sock_fd;
|
||||
struct ifreq ifr;
|
||||
int sock_fd;
|
||||
struct ifreq ifr;
|
||||
|
||||
if((sock_fd = socket(AF_INET,SOCK_DGRAM,0)) < 0)
|
||||
{
|
||||
LOG_E(OIP,"Bringing interface UP, for %s, failed creating socket\n", interfaceName);
|
||||
return 1;
|
||||
if((sock_fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) {
|
||||
LOG_E(OIP,"Bringing interface UP, for %s, failed creating socket\n", interfaceName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name)-1);
|
||||
|
||||
if(up) {
|
||||
ifr.ifr_flags |= IFF_UP | IFF_NOARP | IFF_MULTICAST;
|
||||
|
||||
if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t)&ifr) == -1) {
|
||||
close(sock_fd);
|
||||
LOG_E(OIP,"Bringing interface UP, for %s, failed UP ioctl\n", interfaceName);
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
// printf("desactivation de %s\n", interfaceName);
|
||||
ifr.ifr_flags &= (~IFF_UP);
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name)-1);
|
||||
|
||||
if(up)
|
||||
{
|
||||
ifr.ifr_flags |= IFF_UP | IFF_NOARP | IFF_MULTICAST;
|
||||
if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t)&ifr) == -1)
|
||||
{
|
||||
close(sock_fd);
|
||||
LOG_E(OIP,"Bringing interface UP, for %s, failed UP ioctl\n", interfaceName);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("desactivation de %s\n", interfaceName);
|
||||
ifr.ifr_flags &= (~IFF_UP);
|
||||
if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t)&ifr) == -1)
|
||||
{
|
||||
close(sock_fd);
|
||||
LOG_E(OIP,"Bringing interface down, for %s, failed UP ioctl\n", interfaceName);
|
||||
return 2;
|
||||
}
|
||||
if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t)&ifr) == -1) {
|
||||
close(sock_fd);
|
||||
LOG_E(OIP,"Bringing interface down, for %s, failed UP ioctl\n", interfaceName);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
// printf("UP/DOWN OK!\n");
|
||||
close( sock_fd );
|
||||
return 0;
|
||||
// printf("UP/DOWN OK!\n");
|
||||
close( sock_fd );
|
||||
return 0;
|
||||
}
|
||||
// non blocking full configuration of the interface (address, net mask, and broadcast mask)
|
||||
int NAS_config(char *interfaceName, char *ipAddress, char *networkMask, char *broadcastAddress)
|
||||
{
|
||||
bringInterfaceUp(interfaceName, 0);
|
||||
// sets the machine address
|
||||
int returnValue= setInterfaceParameter(interfaceName, ipAddress,SIOCSIFADDR);
|
||||
bringInterfaceUp(interfaceName, 0);
|
||||
// sets the machine address
|
||||
int returnValue= setInterfaceParameter(interfaceName, ipAddress,SIOCSIFADDR);
|
||||
|
||||
// sets the machine network mask
|
||||
if(!returnValue)
|
||||
returnValue= setInterfaceParameter(interfaceName, networkMask,SIOCSIFNETMASK);
|
||||
// sets the machine network mask
|
||||
if(!returnValue)
|
||||
returnValue= setInterfaceParameter(interfaceName, networkMask,SIOCSIFNETMASK);
|
||||
|
||||
// sets the machine broadcast address
|
||||
if(!returnValue)
|
||||
returnValue= setInterfaceParameter(interfaceName, broadcastAddress,SIOCSIFBRDADDR);
|
||||
// sets the machine broadcast address
|
||||
if(!returnValue)
|
||||
returnValue= setInterfaceParameter(interfaceName, broadcastAddress,SIOCSIFBRDADDR);
|
||||
|
||||
// if(!returnValue)
|
||||
// returnValue=set_gateway(interfaceName, broadcastAddress);
|
||||
// if(!returnValue)
|
||||
// returnValue=set_gateway(interfaceName, broadcastAddress);
|
||||
|
||||
bringInterfaceUp(interfaceName, 1);
|
||||
bringInterfaceUp(interfaceName, 1);
|
||||
|
||||
return returnValue;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
// non blocking full configuration of the interface (address, and the two lest octets of the address)
|
||||
int nas_config(int interface_id, int thirdOctet, int fourthOctet){
|
||||
int nas_config(int interface_id, int thirdOctet, int fourthOctet)
|
||||
{
|
||||
//char buf[5];
|
||||
char ipAddress[20];
|
||||
char broadcastAddress[20];
|
||||
@@ -255,78 +253,79 @@ int nas_config(int interface_id, int thirdOctet, int fourthOctet){
|
||||
sprintf(ipAddress, "10.0.%d.%d", thirdOctet,fourthOctet);
|
||||
|
||||
sprintf(broadcastAddress, "10.0.%d.255", thirdOctet);
|
||||
|
||||
|
||||
sprintf(interfaceName, "oai%d", interface_id);
|
||||
|
||||
|
||||
bringInterfaceUp(interfaceName, 0);
|
||||
// sets the machine address
|
||||
returnValue= setInterfaceParameter(interfaceName, ipAddress,SIOCSIFADDR);
|
||||
|
||||
|
||||
// sets the machine network mask
|
||||
if(!returnValue)
|
||||
returnValue= setInterfaceParameter(interfaceName, netMask,SIOCSIFNETMASK);
|
||||
|
||||
|
||||
// sets the machine broadcast address
|
||||
if(!returnValue)
|
||||
returnValue= setInterfaceParameter(interfaceName, broadcastAddress,SIOCSIFBRDADDR);
|
||||
|
||||
|
||||
bringInterfaceUp(interfaceName, 1);
|
||||
|
||||
|
||||
return returnValue;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Blocking full configuration of the interface (address, net mask, and broadcast mask)
|
||||
int blocking_NAS_config(char *interfaceName, char *ipAddress, char *networkMask, char *broadcastAddress)
|
||||
{
|
||||
|
||||
char command[200];
|
||||
command[0]='\0';
|
||||
char command[200];
|
||||
command[0]='\0';
|
||||
|
||||
strcat(command, "ifconfig ");
|
||||
strncat(command, interfaceName, sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, " ", sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, ipAddress, sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, " networkMask ", sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, networkMask, sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, " broadcast ", sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, broadcastAddress, sizeof(command) - strlen(command) - 1);
|
||||
|
||||
// ifconfig nasmesh0 10.0.1.1 networkMask 255.255.255.0 broadcast 10.0.1.255
|
||||
int i = system (command);
|
||||
strcat(command, "ifconfig ");
|
||||
strncat(command, interfaceName, sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, " ", sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, ipAddress, sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, " networkMask ", sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, networkMask, sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, " broadcast ", sizeof(command) - strlen(command) - 1);
|
||||
strncat(command, broadcastAddress, sizeof(command) - strlen(command) - 1);
|
||||
|
||||
return i;
|
||||
// ifconfig nasmesh0 10.0.1.1 networkMask 255.255.255.0 broadcast 10.0.1.255
|
||||
int i = system (command);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
// program help
|
||||
void helpOptions(char **argv)
|
||||
{
|
||||
printf("Help for %s\n", argv[0]);
|
||||
printf(" -i <interfaceName>\n");
|
||||
printf(" -a <IP address>\n");
|
||||
printf(" -n <Net mask>\n");
|
||||
printf(" -b <broadcast address>\n");
|
||||
printf(" -h Shows this help\n");
|
||||
printf("If no option is passed as parameter the default values are: \n");
|
||||
printf(" Interface Name: nasmesh0\n");
|
||||
printf(" IP Address: 10.0.1.1\n");
|
||||
printf(" Net mask: 255.255.255.0\n");
|
||||
printf(" Broadcast address: [Beginning of the IP address].255\n");
|
||||
printf("Help for %s\n", argv[0]);
|
||||
printf(" -i <interfaceName>\n");
|
||||
printf(" -a <IP address>\n");
|
||||
printf(" -n <Net mask>\n");
|
||||
printf(" -b <broadcast address>\n");
|
||||
printf(" -h Shows this help\n");
|
||||
printf("If no option is passed as parameter the default values are: \n");
|
||||
printf(" Interface Name: nasmesh0\n");
|
||||
printf(" IP Address: 10.0.1.1\n");
|
||||
printf(" Net mask: 255.255.255.0\n");
|
||||
printf(" Broadcast address: [Beginning of the IP address].255\n");
|
||||
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// creates the broadcast address if it wasn't set before
|
||||
void createBroadcast(char *broadcastAddress)
|
||||
{
|
||||
int pos=strlen(broadcastAddress)-1;
|
||||
int pos=strlen(broadcastAddress)-1;
|
||||
|
||||
while(broadcastAddress[pos]!='.')
|
||||
pos--;
|
||||
broadcastAddress[++pos]='2';
|
||||
broadcastAddress[++pos]='2';
|
||||
broadcastAddress[++pos]='5';
|
||||
broadcastAddress[++pos]='\0';
|
||||
while(broadcastAddress[pos]!='.')
|
||||
pos--;
|
||||
|
||||
broadcastAddress[++pos]='2';
|
||||
broadcastAddress[++pos]='2';
|
||||
broadcastAddress[++pos]='5';
|
||||
broadcastAddress[++pos]='\0';
|
||||
}
|
||||
#ifdef STANDALONE
|
||||
// main function
|
||||
@@ -334,58 +333,64 @@ void createBroadcast(char *broadcastAddress)
|
||||
int main(int argc,char **argv)
|
||||
//---------------------------------------------------------------------------
|
||||
{
|
||||
int c;
|
||||
char interfaceName[100];
|
||||
char ipAddress[100];
|
||||
char networkMask[100];
|
||||
char broadcastAddress[100];
|
||||
int c;
|
||||
char interfaceName[100];
|
||||
char ipAddress[100];
|
||||
char networkMask[100];
|
||||
char broadcastAddress[100];
|
||||
|
||||
strcpy(interfaceName, "oai0");
|
||||
strcpy(ipAddress, "10.0.1.1");
|
||||
strcpy(networkMask, "255.255.255.0");
|
||||
broadcastAddress[0]='\0';
|
||||
strcpy(interfaceName, "oai0");
|
||||
strcpy(ipAddress, "10.0.1.1");
|
||||
strcpy(networkMask, "255.255.255.0");
|
||||
broadcastAddress[0]='\0';
|
||||
|
||||
while ((c = getopt (argc, argv, "i:a:n:b:h")) != -1)
|
||||
switch (c)
|
||||
{
|
||||
case 'h':
|
||||
helpOptions(argv);
|
||||
break;
|
||||
case 'i':
|
||||
strcpy(interfaceName,optarg);
|
||||
break;
|
||||
case 'a':
|
||||
strcpy(ipAddress,optarg);
|
||||
break;
|
||||
case 'n':
|
||||
strcpy(networkMask,optarg);
|
||||
break;
|
||||
case 'b':
|
||||
strcpy(broadcastAddress,optarg);
|
||||
break;
|
||||
case '?':
|
||||
if (isprint (optopt))
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
else
|
||||
fprintf (stderr,
|
||||
"Unknown option character `\\x%x'.\n",
|
||||
optopt);
|
||||
return 1;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
while ((c = getopt (argc, argv, "i:a:n:b:h")) != -1)
|
||||
switch (c) {
|
||||
case 'h':
|
||||
helpOptions(argv);
|
||||
break;
|
||||
|
||||
if(strlen(broadcastAddress)==0)
|
||||
{
|
||||
strcpy(broadcastAddress,ipAddress);
|
||||
createBroadcast(broadcastAddress);
|
||||
case 'i':
|
||||
strcpy(interfaceName,optarg);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
strcpy(ipAddress,optarg);
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
strcpy(networkMask,optarg);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
strcpy(broadcastAddress,optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
if (isprint (optopt))
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
else
|
||||
fprintf (stderr,
|
||||
"Unknown option character `\\x%x'.\n",
|
||||
optopt);
|
||||
|
||||
return 1;
|
||||
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
printf("Command: ifconfig %s %s networkMask %s broadcast %s\n", interfaceName, ipAddress, networkMask, broadcastAddress);
|
||||
NAS_config(interfaceName, ipAddress, networkMask, broadcastAddress);
|
||||
//test
|
||||
// setBaseNetAddress("11.11");
|
||||
// nas_config(interfaceName, 33, 44);
|
||||
|
||||
|
||||
if(strlen(broadcastAddress)==0) {
|
||||
strcpy(broadcastAddress,ipAddress);
|
||||
createBroadcast(broadcastAddress);
|
||||
}
|
||||
|
||||
printf("Command: ifconfig %s %s networkMask %s broadcast %s\n", interfaceName, ipAddress, networkMask, broadcastAddress);
|
||||
NAS_config(interfaceName, ipAddress, networkMask, broadcastAddress);
|
||||
//test
|
||||
// setBaseNetAddress("11.11");
|
||||
// nas_config(interfaceName, 33, 44);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
|
||||
*******************************************************************************/
|
||||
/*! \file rb_config.c
|
||||
* \brief User-space utility for configuring NASMESH IOCTL interface
|
||||
* \brief User-space utility for configuring NASMESH IOCTL interface
|
||||
* \author Raymond Knopp and Navid Nikaein
|
||||
* \date 2009
|
||||
* \version 1.1
|
||||
* \warning
|
||||
* \version 1.1
|
||||
* \warning
|
||||
* @ingroup driver
|
||||
|
||||
*/
|
||||
@@ -65,41 +65,46 @@ struct nas_ioctl gifr;
|
||||
static int fd;
|
||||
static int socket_enabled;
|
||||
|
||||
void init_socket(void){
|
||||
|
||||
if ((fd=socket(AF_INET6, SOCK_DGRAM, 0)) < 0){
|
||||
void init_socket(void)
|
||||
{
|
||||
|
||||
if ((fd=socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
LOG_E(OIP,"ERROR opening socket\n");
|
||||
socket_enabled=0;
|
||||
}
|
||||
|
||||
socket_enabled=1;
|
||||
}
|
||||
|
||||
void rb_ioctl_init(int inst) {
|
||||
void rb_ioctl_init(int inst)
|
||||
{
|
||||
|
||||
/* init the gifr struct for the given inst */
|
||||
/* init the gifr struct for the given inst */
|
||||
sprintf(gifr.name, "oai%d",inst);
|
||||
memset ((void *)dummy_buffer,0,BUF_SIZE);
|
||||
gifr.msg= &(dummy_buffer[0]);
|
||||
}
|
||||
|
||||
|
||||
int rb_validate_config_ipv4(int cx, int inst, int rb) {
|
||||
int rb_validate_config_ipv4(int cx, int inst, int rb)
|
||||
{
|
||||
|
||||
if (inst == -1){
|
||||
if (inst == -1) {
|
||||
LOG_E(OIP,"Specify an interface\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
if (rb == -1) {
|
||||
LOG_E(OIP,"Specify an RAB identifier \n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
if (cx == -1) {
|
||||
LOG_E(OIP,"Specify an LCR \n");
|
||||
return(1);
|
||||
}
|
||||
/*
|
||||
|
||||
/*
|
||||
if ( inet_aton(src,&saddr_ipv4)<= 0) {
|
||||
LOG_E(OIP,"Specify a source IP address\n");
|
||||
return(1);
|
||||
@@ -110,161 +115,168 @@ int rb_validate_config_ipv4(int cx, int inst, int rb) {
|
||||
}
|
||||
*/
|
||||
return (0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
int rb_conf_ipv4(int action,int cx, int inst, int rb, int dscp, in_addr_t saddr_ipv4, in_addr_t daddr_ipv4) {
|
||||
//int rb_conf_ipv6(int action,int cx, int inst, int qos, in6_addr src, in6_addr dst) {
|
||||
//int rb_conf(rb_config *rb_cfg) {
|
||||
int rb_conf_ipv4(int action,int cx, int inst, int rb, int dscp, in_addr_t saddr_ipv4, in_addr_t daddr_ipv4)
|
||||
{
|
||||
//int rb_conf_ipv6(int action,int cx, int inst, int qos, in6_addr src, in6_addr dst) {
|
||||
//int rb_conf(rb_config *rb_cfg) {
|
||||
|
||||
int err;
|
||||
|
||||
struct nas_msg_rb_establishment_request *msgreq;
|
||||
struct nas_msg_class_add_request *msgreq_class;
|
||||
|
||||
struct nas_msg_rb_release_request *msgrel;
|
||||
struct nas_msg_class_del_request *msgdel_class;
|
||||
|
||||
if (socket_enabled ==0){
|
||||
init_socket();
|
||||
|
||||
struct nas_msg_rb_establishment_request *msgreq;
|
||||
struct nas_msg_class_add_request *msgreq_class;
|
||||
|
||||
struct nas_msg_rb_release_request *msgrel;
|
||||
struct nas_msg_class_del_request *msgdel_class;
|
||||
|
||||
if (socket_enabled ==0) {
|
||||
init_socket();
|
||||
}
|
||||
|
||||
|
||||
rb_ioctl_init(inst);
|
||||
|
||||
if (rb_validate_config_ipv4(cx,inst,rb) > 0){
|
||||
if (rb_validate_config_ipv4(cx,inst,rb) > 0) {
|
||||
LOG_E(OIP, "OIP configuration failed, inputs parameters incorrect\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
// add an OIP
|
||||
if (action == 0 ) {
|
||||
|
||||
|
||||
msgreq = (struct nas_msg_rb_establishment_request *)(gifr.msg);
|
||||
msgreq->rab_id = (nasRadioBearerId_t) rb;
|
||||
msgreq->lcr = (nasRadioBearerId_t) cx;
|
||||
msgreq->qos = 0;
|
||||
|
||||
|
||||
gifr.type = NAS_MSG_RB_ESTABLISHMENT_REQUEST;
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0){
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0) {
|
||||
perror("IOCTL error: OIP ESTAB REQ\n");
|
||||
LOG_E(OIP,"IOCTL error: OIP ESTAB REQ");
|
||||
}
|
||||
|
||||
|
||||
msgreq_class = (struct nas_msg_class_add_request *)(gifr.msg);
|
||||
msgreq_class->rab_id = (nasRadioBearerId_t) rb;
|
||||
msgreq_class->lcr = (nasRadioBearerId_t) cx;
|
||||
msgreq_class->version = 4;//ipv4
|
||||
|
||||
|
||||
msgreq_class->classref = 0 + (msgreq_class->lcr<<3);
|
||||
msgreq_class->dir = NAS_DIRECTION_SEND;
|
||||
msgreq_class->fct = NAS_FCT_QOS_SEND;
|
||||
msgreq_class->saddr.ipv4 = saddr_ipv4;
|
||||
msgreq_class->daddr.ipv4 = daddr_ipv4;
|
||||
|
||||
msgreq_class->saddr.ipv4 = saddr_ipv4;
|
||||
msgreq_class->daddr.ipv4 = daddr_ipv4;
|
||||
|
||||
// TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule
|
||||
msgreq_class->protocol = NAS_PROTOCOL_DEFAULT;
|
||||
msgreq_class->dscp=dscp;
|
||||
gifr.type = NAS_MSG_CLASS_ADD_REQUEST;
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ){
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ) {
|
||||
perror("IOCTL error: DIR SEND: ADD REQ");
|
||||
LOG_E(OIP,"IOCTL error: DIR SEND: ADD REQ\n");
|
||||
}
|
||||
|
||||
|
||||
msgreq_class->rab_id = (nasRadioBearerId_t)rb;
|
||||
msgreq_class->lcr = (nasRadioBearerId_t)cx;
|
||||
msgreq_class->classref = 1+(msgreq_class->lcr<<3);
|
||||
msgreq_class->dir = NAS_DIRECTION_RECEIVE;
|
||||
msgreq_class->daddr.ipv4 = saddr_ipv4;
|
||||
msgreq_class->saddr.ipv4 = daddr_ipv4;
|
||||
msgreq_class->daddr.ipv4 = saddr_ipv4;
|
||||
msgreq_class->saddr.ipv4 = daddr_ipv4;
|
||||
gifr.type = NAS_MSG_CLASS_ADD_REQUEST;
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ){
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ) {
|
||||
perror("IOCTL error: DIR RECEIVE: ADD REQ");
|
||||
LOG_E(OIP,"IOCTL error: DIR RECEIVE: ADD REQ\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// OIP DEL
|
||||
// OIP DEL
|
||||
else if (action == 1) {
|
||||
|
||||
|
||||
msgrel = (struct nas_msg_rb_release_request *)(gifr.msg);
|
||||
msgrel->rab_id = rb;
|
||||
msgrel->lcr = cx;
|
||||
|
||||
|
||||
gifr.type = NAS_MSG_RB_RELEASE_REQUEST;
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0){
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0) {
|
||||
perror("IOCTL error: OIP RELEASE REQ");
|
||||
LOG_E(OIP,"IOCTL error: OIP RELEASE REQ\n");
|
||||
}
|
||||
|
||||
|
||||
msgdel_class = (struct nas_msg_class_del_request *)(gifr.msg);
|
||||
msgdel_class->lcr = cx;
|
||||
msgdel_class->dir = NAS_DIRECTION_SEND;
|
||||
msgdel_class->classref = 0 + (msgdel_class->lcr<<3);
|
||||
msgdel_class->dscp=dscp;
|
||||
|
||||
|
||||
gifr.type = NAS_MSG_CLASS_DEL_REQUEST;
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ){
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ) {
|
||||
perror("IOCTL error: DIR SEND : CLASS DEL REQ");
|
||||
LOG_E(OIP,"IOCTL error: DIR SEND : CLASS DEL REQ\n");
|
||||
}
|
||||
|
||||
|
||||
msgdel_class->lcr = cx;
|
||||
msgdel_class->classref = 1+(msgdel_class->lcr<<3);
|
||||
msgdel_class->dir = NAS_DIRECTION_RECEIVE;
|
||||
|
||||
|
||||
gifr.type = NAS_MSG_CLASS_DEL_REQUEST;
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ){
|
||||
|
||||
if ((err=ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ) {
|
||||
perror("IOCTL error: DIR RECEIVE : CLASS DEL REQ");
|
||||
LOG_E(OIP,"IOCTL erro: DIR RECEIVE : CLASS DEL REQ\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int rb_stats_req(int inst) {
|
||||
|
||||
if ( fd <= 0 ){
|
||||
int rb_stats_req(int inst)
|
||||
{
|
||||
|
||||
if ( fd <= 0 ) {
|
||||
return (1);
|
||||
} /* request stats without defining the interface */
|
||||
else if (inst == -1){
|
||||
// printf("Specify an interface for statistics request \n");
|
||||
} /* request stats without defining the interface */
|
||||
else if (inst == -1) {
|
||||
// printf("Specify an interface for statistics request \n");
|
||||
LOG_E(OIP,"Specify an interface for statistics request \n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct nas_msg_statistic_reply *msgrep;
|
||||
|
||||
int err;
|
||||
|
||||
|
||||
rb_ioctl_init(inst);
|
||||
|
||||
gifr.type = NAS_MSG_STATISTIC_REQUEST;
|
||||
|
||||
msgrep=(struct nas_msg_statistic_reply *)(gifr.msg);
|
||||
|
||||
|
||||
if ((err = ioctl(fd, NAS_IOCTL_RRM, &gifr)) < 0 ) {
|
||||
perror("IOCTL error: STATS REQ FAILED\n");
|
||||
LOG_E(OIP,"IOCTL error: STATS REQ FAILED\n");
|
||||
}
|
||||
|
||||
|
||||
LOG_I(OIP,"ioctl :Statistics request");
|
||||
LOG_I(OIP,"tx_packets = %u, rx_packets = %u\n", msgrep->tx_packets, msgrep->rx_packets);
|
||||
LOG_I(OIP,"tx_bytes = %u, rx_bytes = %u\n", msgrep->tx_bytes, msgrep->rx_bytes);
|
||||
LOG_I(OIP,"tx_errors = %u, rx_errors = %u\n", msgrep->tx_errors, msgrep->rx_errors);
|
||||
LOG_I(OIP,"tx_dropped = %u, rx_dropped = %u\n", msgrep->tx_dropped, msgrep->rx_dropped);
|
||||
|
||||
|
||||
return (0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
in_addr_t ipv4_address (int thirdOctet, int fourthOctet){
|
||||
in_addr_t ipv4_address (int thirdOctet, int fourthOctet)
|
||||
{
|
||||
|
||||
struct in_addr saddr_ipv4;
|
||||
char ipAddress[20];
|
||||
|
||||
@@ -39,30 +39,30 @@
|
||||
/*
|
||||
typedef struct {
|
||||
|
||||
int fd; // socket file descriptor
|
||||
int fd; // socket file descriptor
|
||||
|
||||
int stats;
|
||||
|
||||
int action; // add or delete
|
||||
int stats;
|
||||
|
||||
int rb;
|
||||
int cx;
|
||||
int inst;
|
||||
|
||||
int saddr_ipv4set;
|
||||
int daddr_ipv4set;
|
||||
in_addr_t saddr_ipv4;
|
||||
in_addr_t daddr_ipv4;
|
||||
int action; // add or delete
|
||||
|
||||
int rb;
|
||||
int cx;
|
||||
int inst;
|
||||
|
||||
int saddr_ipv4set;
|
||||
int daddr_ipv4set;
|
||||
in_addr_t saddr_ipv4;
|
||||
in_addr_t daddr_ipv4;
|
||||
|
||||
int saddr_ipv6set;
|
||||
int daddr_ipv6set;
|
||||
struct in6_addr saddr_ipv6;
|
||||
struct in6_addr daddr_ipv6;
|
||||
|
||||
int dscp;
|
||||
|
||||
int saddr_ipv6set;
|
||||
int daddr_ipv6set;
|
||||
struct in6_addr saddr_ipv6;
|
||||
struct in6_addr daddr_ipv6;
|
||||
|
||||
int dscp;
|
||||
|
||||
|
||||
|
||||
} rb_config;
|
||||
*/
|
||||
int rb_validate_config_ipv4(int cx, int inst, int rb);
|
||||
|
||||
Reference in New Issue
Block a user