[Olsr-cvs] olsrd-current/lib/dyn_gw/src olsrd_dyn_gw.c, 1.19, 1.20 olsrd_dyn_gw.h, 1.11, 1.12 olsrd_plugin.c, 1.12, 1.13
Bernd Petrovitsch
(spam-protected)
Fri Apr 20 16:06:20 CEST 2007
- Previous message: [Olsr-cvs] olsrd-current/lib/dot_draw/src olsrd_dot_draw.c, 1.22, 1.23 olsrd_plugin.c, 1.13, 1.14
- Next message: [Olsr-cvs] olsrd-current/lib/bmf/src Address.c, 1.2, 1.3 Bmf.c, 1.2, 1.3 NetworkInterfaces.c, 1.3, 1.4 PacketHistory.c, 1.2, 1.3 olsrd_plugin.c, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/olsrd/olsrd-current/lib/dyn_gw/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7046/lib/dyn_gw/src
Modified Files:
olsrd_dyn_gw.c olsrd_dyn_gw.h olsrd_plugin.c
Log Message:
cleanup, 1. step (to get some local changes away):
* killed lots of warnings
* added __attribure__((unused)) and __attribure__((format(printf, ..., ...)))
* added "const"
* moved declarations of static functions into .c files
* added "static" declarations
* removed all "inline" declarations. Usually the compiler knows better anyways.
* removed emtpy "return" statements at the end of functions
* localized declarations
* avoided unnecessary data copies
* removed lots of empty lines
There is much more to do.
Index: olsrd_dyn_gw.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dyn_gw/src/olsrd_dyn_gw.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** olsrd_dyn_gw.c 30 Jan 2007 16:48:34 -0000 1.19
--- olsrd_dyn_gw.c 20 Apr 2007 14:06:18 -0000 1.20
***************
*** 88,92 ****
void *Arg;
};
-
#endif
--- 88,91 ----
***************
*** 104,109 ****
add_to_ping_list(char *, struct ping_list *);
- //struct ping_list *the_ping_list = NULL;
-
struct hna_list {
union olsr_ip_addr hna_net;
--- 103,106 ----
***************
*** 122,127 ****
struct hna_list *the_hna_list = NULL;
! static void *
! looped_checks(void *foo);
static int
--- 119,124 ----
struct hna_list *the_hna_list = NULL;
! static void
! looped_checks(void *) __attribute__((noreturn));
static int
***************
*** 131,136 ****
ping_is_possible(struct ping_list *);
!
!
/**
--- 128,134 ----
ping_is_possible(struct ping_list *);
! /* Event function to register with the scheduler */
! static void
! olsr_event_doing_hna(void *);
/**
***************
*** 198,202 ****
*/
int
! olsrd_plugin_init()
{
pthread_t ping_thread;
--- 196,200 ----
*/
int
! olsrd_plugin_init(void)
{
pthread_t ping_thread;
***************
*** 215,219 ****
}*/
! pthread_create(&ping_thread, NULL, looped_checks, NULL);
/* Register the GW check */
--- 213,217 ----
}*/
! pthread_create(&ping_thread, NULL, (void *(*)(void *))looped_checks, NULL);
/* Register the GW check */
***************
*** 228,233 ****
* called from olsrd main thread to keep the hna table thread-safe
*/
! void
! olsr_event_doing_hna(void *foo)
{
struct hna_list *li;
--- 226,231 ----
* called from olsrd main thread to keep the hna table thread-safe
*/
! static void
! olsr_event_doing_hna(void *foo __attribute__((unused)))
{
struct hna_list *li;
***************
*** 266,296 ****
* the default value)
*/
! static void *
! looped_checks(void *foo)
{
- /*
- struct hna_list {
- union olsr_ip_addr hna_net;
- union hna_netmask hna_netmask;
- struct ping_list *ping_hosts;
- int hna_added;
- int probe_ok;
- struct hna_list *next;
- };
- */
- struct hna_list *li;
-
for(;;) {
struct timespec remainder_spec;
/* the time to wait in "Interval" sec (see connfig), default=5sec */
! struct timespec sleeptime_spec = {(time_t) check_interval, 0L };
! li=the_hna_list;
! while(li){
! /* check for gw in table entry and if Ping IPs are given also do pings */
! li->probe_ok = check_gw(&li->hna_net,&li->hna_netmask,li->ping_hosts);
! //has_available_gw = check_gw(&gw_net, &gw_netmask);
!
! li=li->next;
}
--- 264,280 ----
* the default value)
*/
! static void
! looped_checks(void *foo __attribute__((unused)))
{
for(;;) {
+ struct hna_list *li;
struct timespec remainder_spec;
/* the time to wait in "Interval" sec (see connfig), default=5sec */
! struct timespec sleeptime_spec = { check_interval, 0L };
! for(li = the_hna_list; li; li = li->next){
! /* check for gw in table entry and if Ping IPs are given also do pings */
! li->probe_ok = check_gw(&li->hna_net,&li->hna_netmask,li->ping_hosts);
! //has_available_gw = check_gw(&gw_net, &gw_netmask);
}
***************
*** 298,316 ****
sleeptime_spec = remainder_spec;
}
! return NULL;
}
static int
check_gw(union olsr_ip_addr *net, union olsr_ip_addr *mask, struct ping_list *the_ping_list)
{
! char buff[1024], iface[16];
olsr_u32_t gate_addr, dest_addr, netmask;
unsigned int iflags;
! int num, metric, refcnt, use;
int retval = 0;
FILE *fp = fopen(PROCENTRY_ROUTE, "r");
-
if (!fp)
{
--- 282,300 ----
sleeptime_spec = remainder_spec;
}
! // return NULL;
}
+
static int
check_gw(union olsr_ip_addr *net, union olsr_ip_addr *mask, struct ping_list *the_ping_list)
{
! char buf[1024], iface[16];
olsr_u32_t gate_addr, dest_addr, netmask;
unsigned int iflags;
! int metric, refcnt, use;
int retval = 0;
FILE *fp = fopen(PROCENTRY_ROUTE, "r");
if (!fp)
{
***************
*** 318,324 ****
olsr_printf(1, "INET (IPv4) not configured in this system.\n");
return -1;
! }
!
! rewind(fp);
/*
--- 302,306 ----
olsr_printf(1, "INET (IPv4) not configured in this system.\n");
return -1;
! }
/*
***************
*** 326,339 ****
"Flags Metric Ref Use Iface\n");
*/
! while (fgets(buff, 1023, fp))
! {
! num = sscanf(buff, "%15s %128X %128X %X %d %d %d %128X \n",
! iface, &dest_addr, &gate_addr,
! &iflags, &refcnt, &use, &metric, &netmask);
!
if (num < 8)
- {
continue;
- }
/*
--- 308,318 ----
"Flags Metric Ref Use Iface\n");
*/
! while (fgets(buf, sizeof(buf), fp))
! {
! int num = sscanf(buf, "%15s %128X %128X %X %d %d %d %128X \n",
! iface, &dest_addr, &gate_addr,
! &iflags, &refcnt, &use, &metric, &netmask);
if (num < 8)
continue;
/*
***************
*** 347,377 ****
*/
! if( (iflags & RTF_UP) &&
! (metric == 0) &&
! (netmask == mask->v4) &&
! (dest_addr == net->v4))
! {
! if ( ((mask->v4==INET_PREFIX)&&(net->v4==INET_NET))&&(!(iflags & RTF_GATEWAY)))
! return retval;
! /* don't ping, if there was no "Ping" IP addr in the config file */
! if (the_ping_list != NULL) {
! /*validate the found inet gw by pinging*/
! if (ping_is_possible(the_ping_list)) {
! olsr_printf(1, "HNA[%08x/%08x](ping is possible) VIA %s detected in routing table.\n", dest_addr,netmask,iface);
! retval=1;
! }
! } else {
! olsr_printf(1, "HNA[%08x/%08x] VIA %s detected in routing table.\n", dest_addr,netmask,iface);
! retval=1;
! }
! }
!
! }//while
! fclose(fp);
!
! if(retval == 0){
! olsr_printf(1, "HNA[%08x/%08x] is invalid\n", net->v4,mask->v4);
! }
return retval;
}
--- 326,357 ----
*/
! if( (iflags & RTF_UP) &&
! (metric == 0) &&
! (netmask == mask->v4) &&
! (dest_addr == net->v4))
! {
! if ( ((mask->v4==INET_PREFIX)&&(net->v4==INET_NET))&&(!(iflags & RTF_GATEWAY)))
! {
! fclose(fp);
! return retval;
! }
! /* don't ping, if there was no "Ping" IP addr in the config file */
! if (the_ping_list != NULL) {
! /*validate the found inet gw by pinging*/
! if (ping_is_possible(the_ping_list)) {
! olsr_printf(1, "HNA[%08x/%08x](ping is possible) VIA %s detected in routing table.\n", dest_addr,netmask,iface);
! retval=1;
! }
! } else {
! olsr_printf(1, "HNA[%08x/%08x] VIA %s detected in routing table.\n", dest_addr,netmask,iface);
! retval=1;
! }
! }
! }
! fclose(fp);
! if(retval == 0){
! olsr_printf(1, "HNA[%08x/%08x] is invalid\n", net->v4,mask->v4);
! }
return retval;
}
***************
*** 381,394 ****
{
struct ping_list *list;
! for (list = the_ping_list; list != NULL; list = list->next) {
! char ping_command[50] = "ping -c 1 -q ";
! strcat(ping_command, list->ping_address);
olsr_printf(1, "\nDo ping on %s ...\n", list->ping_address);
if (system(ping_command) == 0) {
olsr_printf(1, "...OK\n\n");
return 1;
- } else {
- olsr_printf(1, "...FAILED\n\n");
}
}
return 0;
--- 361,373 ----
{
struct ping_list *list;
! for(list = the_ping_list; list; list = list->next) {
! char ping_command[50];
! snprintf(ping_command, sizeof(ping_command), "ping -c 1 -q %s", list->ping_address);
olsr_printf(1, "\nDo ping on %s ...\n", list->ping_address);
if (system(ping_command) == 0) {
olsr_printf(1, "...OK\n\n");
return 1;
}
+ olsr_printf(1, "...FAILED\n\n");
}
return 0;
***************
*** 399,404 ****
add_to_ping_list(char *ping_address, struct ping_list *the_ping_list)
{
! struct ping_list *new = (struct ping_list *) malloc(sizeof(struct ping_list));
! if(new == NULL)
{
fprintf(stderr, "DYN GW: Out of memory!\n");
--- 378,383 ----
add_to_ping_list(char *ping_address, struct ping_list *the_ping_list)
{
! struct ping_list *new = malloc(sizeof(struct ping_list));
! if(!new)
{
fprintf(stderr, "DYN GW: Out of memory!\n");
***************
*** 415,419 ****
add_to_hna_list(struct hna_list * list_root, union olsr_ip_addr *hna_net, union olsr_ip_addr *hna_netmask )
{
! struct hna_list *new = (struct hna_list *) malloc(sizeof(struct hna_list));
if(new == NULL)
{
--- 394,398 ----
add_to_hna_list(struct hna_list * list_root, union olsr_ip_addr *hna_net, union olsr_ip_addr *hna_netmask )
{
! struct hna_list *new = malloc(sizeof(struct hna_list));
if(new == NULL)
{
***************
*** 429,440 ****
new->ping_hosts=NULL;
new->next=list_root;
-
return new;
}
-
-
#ifdef WIN32
-
/*
* Windows ptread compat stuff
--- 408,415 ----
Index: olsrd_dyn_gw.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dyn_gw/src/olsrd_dyn_gw.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** olsrd_dyn_gw.h 29 May 2005 12:47:40 -0000 1.11
--- olsrd_dyn_gw.h 20 Apr 2007 14:06:18 -0000 1.12
***************
*** 51,62 ****
#define PROCENTRY_ROUTE "/proc/net/route"
! /* Timeout function to register with the scheduler */
! void
! olsr_timeout(void);
! /* Event function to register with the scheduler */
! void
! olsr_event_doing_hna(void *);
#endif
--- 51,62 ----
#define PROCENTRY_ROUTE "/proc/net/route"
! int
! olsrd_plugin_init(void);
+ int
+ olsrd_plugin_interface_version(void);
! int
! olsrd_plugin_register_param(char *key, char *value);
#endif
Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dyn_gw/src/olsrd_plugin.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** olsrd_plugin.c 29 May 2005 12:47:40 -0000 1.12
--- olsrd_plugin.c 20 Apr 2007 14:06:18 -0000 1.13
***************
*** 65,69 ****
*/
int
! olsrd_plugin_interface_version()
{
return PLUGIN_INTERFACE_VERSION;
--- 65,69 ----
*/
int
! olsrd_plugin_interface_version(void)
{
return PLUGIN_INTERFACE_VERSION;
***************
*** 75,79 ****
*/
void
! my_init()
{
/* Print plugin info to stdout */
--- 75,79 ----
*/
void
! my_init(void)
{
/* Print plugin info to stdout */
- Previous message: [Olsr-cvs] olsrd-current/lib/dot_draw/src olsrd_dot_draw.c, 1.22, 1.23 olsrd_plugin.c, 1.13, 1.14
- Next message: [Olsr-cvs] olsrd-current/lib/bmf/src Address.c, 1.2, 1.3 Bmf.c, 1.2, 1.3 NetworkInterfaces.c, 1.3, 1.4 PacketHistory.c, 1.2, 1.3 olsrd_plugin.c, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Olsr-cvs
mailing list