]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripd: minor code simplification
authorRenato Westphal <renato@opensourcerouting.org>
Sat, 12 Nov 2016 21:34:37 +0000 (19:34 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Fri, 25 Nov 2016 13:46:06 +0000 (11:46 -0200)
* Simplify the RIP_TIMER_OFF macro and use it on more places;
* Be more explicit when creating the RIP UDP socket - cosmetic change
  since socket(AF_INET,SOCK_DGRAM,0) defaults to UDP on every known
  UNIX/Linux platform.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/ripd.c
ripd/ripd.h

index c2872d937a868705409cf6edbf00bafda00996d3..e9d610cea79f6b8aa02b2dbefb864d01422f78ec 100644 (file)
@@ -1355,7 +1355,7 @@ rip_create_socket (void)
   addr.sin_port = htons (RIP_PORT_DEFAULT);
   
   /* Make datagram socket. */
-  sock = socket (AF_INET, SOCK_DGRAM, 0);
+  sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
   if (sock < 0) 
     {
       zlog_err("Cannot create UDP socket: %s", safe_strerror(errno));
@@ -2548,11 +2548,7 @@ rip_update (struct thread *t)
 
   /* Triggered updates may be suppressed if a regular update is due by
      the time the triggered update would be sent. */
-  if (rip->t_triggered_interval)
-    {
-      thread_cancel (rip->t_triggered_interval);
-      rip->t_triggered_interval = NULL;
-    }
+  RIP_TIMER_OFF (rip->t_triggered_interval);
   rip->trigger = 0;
 
   /* Register myself. */
@@ -2606,11 +2602,7 @@ rip_triggered_update (struct thread *t)
   rip->t_triggered_update = NULL;
 
   /* Cancel interval timer. */
-  if (rip->t_triggered_interval)
-    {
-      thread_cancel (rip->t_triggered_interval);
-      rip->t_triggered_interval = NULL;
-    }
+  RIP_TIMER_OFF (rip->t_triggered_interval);
   rip->trigger = 0;
 
   /* Logging triggered update. */
@@ -2788,11 +2780,7 @@ rip_event (enum rip_event event, int sock)
       rip->t_read = thread_add_read (master, rip_read, NULL, sock);
       break;
     case RIP_UPDATE_EVENT:
-      if (rip->t_update)
-       {
-         thread_cancel (rip->t_update);
-         rip->t_update = NULL;
-       }
+      RIP_TIMER_OFF (rip->t_update);
       jitter = rip_update_jitter (rip->update_time);
       rip->t_update = 
        thread_add_timer (master, rip_update, NULL, 
@@ -3887,11 +3875,7 @@ rip_clean (void)
       RIP_TIMER_OFF (rip->t_triggered_interval);
 
       /* Cancel read thread. */
-      if (rip->t_read)
-       {
-         thread_cancel (rip->t_read);
-         rip->t_read = NULL;
-       }
+      THREAD_READ_OFF (rip->t_read);
 
       /* Close RIP socket. */
       if (rip->sock >= 0)
index b26a1d234cf4db112be4a59f192d31479bf5ca52..cb4764a7f144664f18465d4a94a8386d0a4ce2f6 100644 (file)
@@ -373,14 +373,7 @@ enum rip_event
   } while (0)
 
 /* Macro for timer turn off. */
-#define RIP_TIMER_OFF(X) \
-  do { \
-    if (X) \
-      { \
-        thread_cancel (X); \
-        (X) = NULL; \
-      } \
-  } while (0)
+#define RIP_TIMER_OFF(X) THREAD_TIMER_OFF(X)
 
 /* Prototypes. */
 extern void rip_init (void);