commit f640c300c2cd343475a561ddb944bf373ed04bf6
Author: Marcin Krol <[email protected]>
Date:   Fri Jul 27 12:18:18 2012 +0000

    - require target and source IP addresses to be specified in config
    - cosmetics

 apinger-srcip.patch | 55 ++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 42 insertions(+), 13 deletions(-)
---
diff --git a/apinger-srcip.patch b/apinger-srcip.patch
index 2493b91..3396fe1 100644
--- a/apinger-srcip.patch
+++ b/apinger-srcip.patch
@@ -15,7 +15,7 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
        else
                fprintf(f,"alarm canceled: %s\n",a->name);
        fprintf(f,"Target: %s\n",t->name);
-+      fprintf(f,"Source IP: %s\n",t->config->srcip);
++      fprintf(f,"Source: %s\n",t->config->srcip);
        fprintf(f,"Description: %s\n",t->description);
        fprintf(f,"Probes sent: %i\n",t->last_sent+1);
        fprintf(f,"Replies received: %i\n",t->received);
@@ -37,8 +37,11 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
                        free(t->queue);
                        free(t->rbuf);
                        free(t->name);
-@@ -684,11 +690,6 @@
+@@ -682,20 +688,16 @@
+                               break;
+               if (t==NULL) { /* new target */
                        memset(&addr,0,sizeof(addr));
++                      logit("Checking target IP %s", tc->srcip);
                        r=inet_pton(AF_INET,tc->name,&addr.addr4.sin_addr);
                        if (r){
 -                              if (icmp_sock<0){
@@ -49,12 +52,20 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
                                addr.addr.sa_family=AF_INET;
                        }else{
  #ifdef HAVE_IPV6
-@@ -708,12 +709,38 @@
+                               
r=inet_pton(AF_INET6,tc->name,&addr.addr6.sin6_addr);
+                               if (r==0){
+ #endif
+-                                      logit("Bad host address: 
%s\n",tc->name);
++                                      logit("Bad target IP address: 
%s\n",tc->name);
+                                       logit("Ignoring target %s\n",tc->name);
+                                       continue;
+ #ifdef HAVE_IPV6
+@@ -708,12 +710,38 @@
                                addr.addr.sa_family=AF_INET6;
  #endif
                        }
 +                      memset(&srcaddr,0,sizeof(srcaddr));
-+                      debug("Converting srcip %s", tc->srcip);
++                      logit("Checking source IP %s", tc->srcip);
 +                      r=inet_pton(AF_INET,tc->srcip,&srcaddr.addr4.sin_addr);
 +                      if (r){
 +                              srcaddr.addr.sa_family=AF_INET;
@@ -63,7 +74,7 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
 +                              
r=inet_pton(AF_INET6,tc->srcip,&srcaddr.addr6.sin6_addr);
 +                              if (r==0){
 +#endif
-+                                      logit("Bad srcip address %s for target 
%s\n", tc->srcip, tc->name);
++                                      logit("Bad source IP address %s for 
target %s\n", tc->srcip, tc->name);
 +                                      logit("Ignoring target %s\n",tc->name);
 +                                      continue;
 +#ifdef HAVE_IPV6
@@ -88,7 +99,7 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
                        targets=t;
                }
                t->config=tc;
-@@ -733,6 +760,7 @@
+@@ -733,6 +761,7 @@
                assert(t->rbuf!=NULL);
                memset(t->rbuf,0,l);
        }
@@ -96,7 +107,7 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
        if (targets==NULL){
                logit("No usable targets found, exiting");
                exit(1);
-@@ -753,6 +781,8 @@
+@@ -753,6 +782,8 @@
                        nal=al->next;
                        free(al);
                }
@@ -105,15 +116,15 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
                free(t->queue);
                free(t->rbuf);
                free(t->name);
-@@ -800,6 +830,7 @@
+@@ -800,6 +831,7 @@
        fprintf(f,"%s\n",ctime(&tm));
        for(t=targets;t;t=t->next){
                fprintf(f,"Target: %s\n",t->name);
-+              fprintf(f,"Source IP: %s\n",t->config->srcip);
++              fprintf(f,"Source: %s\n",t->config->srcip);
                fprintf(f,"Description: %s\n",t->description);
                fprintf(f,"Last reply received: #%i %s",t->last_received,
                        ctime(&t->last_received_tv.tv_sec));
-@@ -865,7 +896,7 @@
+@@ -865,7 +897,7 @@
  void main_loop(void){
  struct target *t;
  struct timeval 
cur_time,next_status={0,0},tv,next_report={0,0},next_rrd_update={0,0};
@@ -122,7 +133,7 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
  int timeout;
  int npfd=0;
  int i;
-@@ -876,16 +907,8 @@
+@@ -876,16 +908,8 @@
  struct alarm_cfg *a;
  
        configure_targets();
@@ -141,7 +152,7 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
        if (config->status_interval){
                gettimeofday(&cur_time,NULL);
                tv.tv_sec=config->status_interval/1000;
-@@ -893,10 +916,16 @@
+@@ -893,10 +917,16 @@
                timeradd(&cur_time,&tv,&next_status);
        }
        while(!interrupted_by){
@@ -158,7 +169,7 @@ diff -ur apinger-0.6.1.orig//src/apinger.c 
apinger-0.6.1/src/apinger.c
                        for(al=t->config->alarms;al;al=nal){
                                a=al->alarm;
                                nal=al->next;
-@@ -972,8 +1001,20 @@
+@@ -972,8 +1002,20 @@
                poll(pfd,npfd,timeout);
                for(i=0;i<npfd;i++){
                        if (!pfd[i].revents&POLLIN) continue;
@@ -278,6 +289,24 @@ diff -ur apinger-0.6.1.orig//src/cfgparser2.l 
apinger-0.6.1/src/cfgparser2.l
  down          { LOC; LOCINC; return DOWN; }
  false         { LOC; LOCINC; return FALSE; }
  file          { LOC; LOCINC; return FILE_; }
+diff -ur apinger-0.6.1.orig//src/conf.c apinger-0.6.1/src/conf.c
+--- apinger-0.6.1.orig//src/conf.c     2003-03-26 11:27:47.000000000 +0000
++++ apinger-0.6.1/src/conf.c   2012-07-27 10:54:53.563251145 +0000
+@@ -175,6 +175,14 @@
+                       }
+               }
+               for(t=cur_config.targets;t;t=t->next){
++                      if (t->name==NULL || strlen(t->name)==0){
++                              logit("Target name can't be empty.");
++                              return 1;
++                      }
++                      else if (t->srcip==NULL){
++                              logit("No source IP defined for target 
\"%s\".", t->name);
++                              return 1;
++                      }
+                       if (t->description==NULL)
+                               
t->description=cur_config.target_defaults.description;
+                       if (t->interval<=0)
 diff -ur apinger-0.6.1.orig//src/conf.h apinger-0.6.1/src/conf.h
 --- apinger-0.6.1.orig//src/conf.h     2003-03-26 11:27:47.000000000 +0000
 +++ apinger-0.6.1/src/conf.h   2012-07-25 17:44:41.643063909 +0000
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to