From 7e30d62b79704280825cb83b385e9fd70b0382c0 Mon Sep 17 00:00:00 2001 From: gardners Date: Fri, 12 Aug 2011 21:05:11 +0200 Subject: [PATCH] Cleaned up various compiler warnings. Added packet parser framework for handling overlay frames. --- Makefile | 7 +++++-- Makefile.in | 7 +++++-- client.c | 6 +++--- mphlr.h | 7 +++++++ overlay_interface.c | 42 ++++++++++++++++++++++++++++++++++-------- packetformats.c | 16 +++++++++++++--- peers.c | 6 ++---- server.c | 12 ++++++++---- 8 files changed, 77 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 5ec7c2cb..ff5cca98 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,13 @@ SRCS= dna.c server.c client.c peers.c ciphers.c responses.c packetformats.c dataformats.c \ hlrdata.c srandomdev.c simulate.c batman.c export.c gateway.c \ - overlay.c overlay_buffer.c overlay_interface.c overlay_payload.c overlay_route.c + overlay.c overlay_buffer.c overlay_interface.c overlay_payload.c overlay_route.c \ + overlay_packetformats.c OBJS= dna.o server.o client.o peers.o ciphers.o responses.o packetformats.o dataformats.o \ hlrdata.o srandomdev.o simulate.o batman.o export.o gateway.o \ - overlay.o overlay_buffer.o overlay_interface.o overlay_payload.o overlay_route.o + overlay.o overlay_buffer.o overlay_interface.o overlay_payload.o overlay_route.o \ + overlay_packetformats.o + HDRS= Makefile mphlr.h LDFLAGS= -L/Developer/SDKs/MacOSX10.6.sdk/usr/lib CFLAGS= -I/Developer/SDKs/MacOSX10.6.sdk/usr/include diff --git a/Makefile.in b/Makefile.in index 1f1fbb2a..11b266e4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,10 +1,13 @@ SRCS= dna.c server.c client.c peers.c ciphers.c responses.c packetformats.c dataformats.c \ hlrdata.c srandomdev.c simulate.c batman.c export.c gateway.c \ - overlay.c overlay_buffer.c overlay_interface.c overlay_payload.c overlay_route.c + overlay.c overlay_buffer.c overlay_interface.c overlay_payload.c overlay_route.c \ + overlay_packetformats.c OBJS= dna.o server.o client.o peers.o ciphers.o responses.o packetformats.o dataformats.o \ hlrdata.o srandomdev.o simulate.o batman.o export.o gateway.o \ - overlay.o overlay_buffer.o overlay_interface.o overlay_payload.o overlay_route.o + overlay.o overlay_buffer.o overlay_interface.o overlay_payload.o overlay_route.o \ + overlay_packetformats.o + HDRS= Makefile mphlr.h LDFLAGS= @LDFLAGS@ CFLAGS= @CFLAGS@ diff --git a/client.c b/client.c index ffbd4db2..ec3988bd 100644 --- a/client.c +++ b/client.c @@ -281,7 +281,7 @@ int fixResponses(struct response_set *responses) bcopy(rr->response,new,rr->value_bytes); bcopy(addr,&new[rr->value_bytes],alen+1); free(rr->response); rr->response=NULL; - rr->response=new; + rr->response=(unsigned char *)new; rr->value_len+=alen; rr->value_bytes+=alen; if (debug>1) fprintf(stderr,"Response string now '%s'\n",rr->response); @@ -607,7 +607,7 @@ int requestItem(char *did,char *sid,char *item,int instance,unsigned char *buffe extractSid(r->sid,&slen,sid); switch(r->code) { - case ACTION_OKAY: printf("OK:%s\n",sid); if (buffer) {strcpy(buffer,sid); *len=strlen(sid); } successes++; break; + case ACTION_OKAY: printf("OK:%s\n",sid); if (buffer) {strcpy((char *)buffer,sid); *len=strlen(sid); } successes++; break; case ACTION_DECLINED: printf("DECLINED:%s\n",sid); errors++; break; case ACTION_DATA: /* Display data. @@ -625,7 +625,7 @@ int requestItem(char *did,char *sid,char *item,int instance,unsigned char *buffe did[0]=0; extractDid(r->response,&dlen,did); printf("DIDS:%s:%d:%s\n",sid,r->var_instance,did); - if (buffer) {strcpy(buffer,did); *len=strlen(did); } + if (buffer) {strcpy((char *)buffer,did); *len=strlen(did); } successes++; } break; diff --git a/mphlr.h b/mphlr.h index cba3c8f6..001aeb3b 100644 --- a/mphlr.h +++ b/mphlr.h @@ -315,6 +315,7 @@ int getReplyPackets(int method,int peer,int batchP, unsigned char *transaction_id,int timeout); int clearResponse(struct response **response); int nextHlr(unsigned char *hlr,int *ofs); +int seedHlr(); int findHlr(unsigned char *hlr,int *ofs,char *sid,char *did); int createHlr(char *did,char *sid); struct hlrentry_handle *openhlrentry(unsigned char *hlr,int hofs); @@ -364,6 +365,10 @@ int exportHlr(unsigned char *hlr,char *text); int openHlrFile(char *backing_file,int size); int runCommand(char *cmd); int asteriskObtainGateway(char *requestor_sid,char *did,char *uri_out); +int packetOkDNA(unsigned char *packet,int len,unsigned char *transaction_id); +int packetOkOverlay(unsigned char *packet,int len,unsigned char *transaction_id); +int prepareGateway(char *gatewayspec); + #define CRYPT_CIPHERED 1 #define CRYPT_SIGNED 2 @@ -573,6 +578,8 @@ int overlay_rx_messages(); int overlay_check_ticks(); int overlay_add_selfannouncement(); int overlay_payload_package_fmt1(overlay_payload *p,overlay_buffer *b); +int overlay_interface_args(char *arg); +int overlay_get_nexthop(overlay_payload *p,unsigned char *nexthop,int *nexthoplen); extern int overlay_interface_count; diff --git a/overlay_interface.c b/overlay_interface.c index bec01a94..8904fc6d 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -152,6 +152,7 @@ int overlay_interface_init_socket(int interface,struct sockaddr_in src_addr,stru perror("bind()"); return WHY("MP HLR server could not bind to requested UDP port (bind() failed)"); } + fprintf(stderr,"Bound to port 0x%04x\n",src_addr.sin_port); int broadcastP=1; if(setsockopt(I(socket), SOL_SOCKET, SO_BROADCAST, &broadcastP, sizeof(broadcastP)) < 0) { @@ -203,11 +204,36 @@ int overlay_rx_messages() /* XXX Okay, so how are we managing out-of-process consumers? They need some way to register their interest in listening to a port. */ - for(i=0;i0); count+=c[i]; } - return WHY("Not implemented"); + /* Grab packets from interfaces in round-robin fashion until all have been grabbed, + or until we have spent too long (maybe 10ms?) */ + while(count>0) + for(i=0;inext; pp->next->prev=*p; - op_free(p); + op_free(*p); } else { @@ -421,7 +447,8 @@ int overlay_tick_interface(int i, long long now) } return 0; } - else WHY("overlay_broadcast_ensemble() failed"); + else return WHY("overlay_broadcast_ensemble() failed"); + } int overlay_check_ticks() @@ -441,7 +468,6 @@ int overlay_check_ticks() now=nowtv.tv_sec*1000; now=now+nowtv.tv_usec/1000; - /* Now check if the next tick time for the interfaces is no later than that time. If so, trigger a tick on the interface. */ for(i=0;iifa_addr)->sin_addr.s_addr; { - struct sockaddr_in broadcast; unsigned int local=(((struct sockaddr_in *)(ifa->ifa_addr))->sin_addr.s_addr); unsigned int netmask=(((struct sockaddr_in *)(ifa->ifa_netmask))->sin_addr.s_addr); peers[(*peer_count)++].s_addr=local|~netmask; diff --git a/server.c b/server.c index dca43a1d..a800981b 100644 --- a/server.c +++ b/server.c @@ -85,7 +85,7 @@ int server(char *backing_file,int size,int foregroundMode) waittime.tv_usec=(ms%1000)*1000; waittime.tv_sec=ms/1000; - fprintf(stderr,"%d,%d\n",waittime.tv_sec,waittime.tv_usec); + fprintf(stderr,"%d,%d\n",(int)waittime.tv_sec,waittime.tv_usec); int r=select(maxfd+1,&read_fds,NULL,NULL,&waittime); if (r<0) { /* select had a problem */ @@ -93,9 +93,13 @@ int server(char *backing_file,int size,int foregroundMode) return WHY("select() complained."); } else if (r>0) { /* We have data, so try to receive it */ + fprintf(stderr,"select() reports packets waiting\n"); overlay_rx_messages(); } else { - /* No data before tick occurred, so do nothing. */ + /* No data before tick occurred, so do nothing. + Well, for now let's just check anyway. */ + fprintf(stderr,"select() timeout.\n"); + overlay_rx_messages(); } /* Check if we need to trigger any ticks on any interfaces */ overlay_check_ticks(); @@ -234,11 +238,11 @@ int processRequest(unsigned char *packet,int len, char messageLen = packet[pofs]; pofs++; strncpy(emitterPhoneNumber, (const char*)packet+pofs, emitterPhoneNumberLen); - emitterPhoneNumber[emitterPhoneNumberLen]=0; + emitterPhoneNumber[(unsigned int)emitterPhoneNumberLen]=0; pofs+=emitterPhoneNumberLen; strncpy(message, (const char*)packet+pofs, messageLen); - message[messageLen]=0; + message[(unsigned int)messageLen]=0; pofs+=messageLen;