Commit 2e4c3e10 authored by 's avatar
Browse files

Friendly subnets for resource control

git-svn-id: file:///home/svn/mapi/trunk@367 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 6dac9715
......@@ -48,6 +48,7 @@ int main(int argc, char **argv) {
int new_sock = 0; /* client's socket descriptor (from connect()) */
socklen_t clnt_len; /* length of client address data structure */
int yes=1;
unsigned char* arg;
struct sockaddr_in serv_addr;
struct sockaddr_in clnt_addr;
......@@ -89,7 +90,10 @@ int main(int argc, char **argv) {
//continue;
printf("<*> got connection from %s\n", inet_ntoa(clnt_addr.sin_addr));
if (pthread_create(&chld_thr, NULL, handle_request, (void *)new_sock) != 0)
arg=(unsigned char*)malloc((sizeof(int)+sizeof(clnt_addr.sin_addr)));
memcpy(arg, &new_sock, sizeof(int));
memcpy(arg+sizeof(int), &clnt_addr.sin_addr, sizeof(clnt_addr.sin_addr));
if (pthread_create(&chld_thr, NULL, handle_request, (void *)arg) != 0)
die("pthread_create() failed");
}
......@@ -98,7 +102,7 @@ int main(int argc, char **argv) {
void *handle_request(void *arg) {
int sock = (int) arg;
int sock;
int recv_bytes;
char buffer[MAX_SEND_SIZE];
struct dmapiipcbuf *dbuf=NULL;
......@@ -113,6 +117,11 @@ void *handle_request(void *arg) {
struct timeval tv; /*used for timestamping results when produced */
struct timezone tz;
struct mapipkt *pkt;
struct in_addr client;
char* dev_addr;
memcpy(&sock, (unsigned char*)arg, sizeof(int));
memcpy(&client, ((unsigned char*)arg)+sizeof(int), sizeof(struct in_addr));
/* Guarantees that thread resources are deallocated upon return */
pthread_detach(pthread_self());
......@@ -143,7 +152,11 @@ void *handle_request(void *arg) {
memcpy(dbuf,buffer,((struct dmapiipcbuf *)buffer)->length);
switch(dbuf->cmd) {
case CREATE_FLOW:
mapid_result = mapi_create_flow((char *)dbuf->data);
dev_addr=(char*)malloc( (strlen((char *)dbuf->data)+strlen(inet_ntoa(client)))*sizeof(char) );
strcpy(dev_addr, (char *)dbuf->data);
strcat(dev_addr, "#");
strcat(dev_addr, inet_ntoa(client));
mapid_result = mapi_create_flow(dev_addr);
fprintf(stdout,"CREATE_FLOW (%s, %d)\n",dbuf->data, mapid_result);
if(mapid_result <0)
dbuf->cmd = ERROR_ACK;
......@@ -154,6 +167,7 @@ void *handle_request(void *arg) {
active_flows[ac_fl_size++] = mapid_result;
print_table(active_flows,ac_fl_size);
dbuf->length = BASIC_SIZE+sizeof(int);
free(dev_addr);
break;
case CLOSE_FLOW:
fprintf(stdout,"CLOSE_FLOW (%d)\n",dbuf->fd);
......
......@@ -751,7 +751,7 @@ cmd_get_libs (int pid, int sock) /*removed id, id==pid here */
}
static void
cmd_create_flow (char *dev, int pid, uid_t uid, int sock) /*removed id, id==pid here */
cmd_create_flow (char *device, int pid, uid_t uid, int sock) /*removed id, id==pid here */
//Create a new flow
//dev = device
//if = IPC id used to send ack message back to client
......@@ -762,7 +762,16 @@ cmd_create_flow (char *dev, int pid, uid_t uid, int sock) /*removed id, id==pid
char *devtype;
mapidrv *drv;
int err = 0;
char* dev=device;
char* tmp=NULL;
char* client_addr;
tmp=strchr(device, '#');
if (tmp!=NULL) {
*tmp='\0';
client_addr=tmp+1;
}
//flist_node_t *tmpnode = NULL;
fl->id = pid;
......@@ -773,7 +782,11 @@ cmd_create_flow (char *dev, int pid, uid_t uid, int sock) /*removed id, id==pid
// fl->errno=0;
#ifdef WITH_PRIORITIES
fl->priority = fl->id % PRIORITIES;
// danton TODO: search for client_addr in conf file
// and set fl->priority proportionately
//
//printf("client's ip address %s\n",client_addr);
#endif
//Decide which driver to use
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment