]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/irdp_interface.c
quagga: option "-z" ("--socket <path>") added
[mirror_frr.git] / zebra / irdp_interface.c
index 1e5ad0e9a62c18971fb16ee0ae73787be3473cb9..8742b62b8cc8572a9a1af508ea55037af9636449 100644 (file)
 /* Master of threads. */
 extern struct zebra_t zebrad;
 
-int in_cksum (void *ptr, int nbytes);
 extern int irdp_sock;
-int irdp_send_thread(struct thread *t_advert);
-char *inet_2a(u_int32_t a, char *b);
-void irdp_advert_off(struct interface *ifp);
 
+static const char *
+inet_2a(u_int32_t a, char *b)
+{
+  sprintf(b, "%u.%u.%u.%u",
+          (a    ) & 0xFF,
+          (a>> 8) & 0xFF,
+          (a>>16) & 0xFF,
+          (a>>24) & 0xFF);
+  return  b;
+}
 
-char b1[16], b2[16], b3[16], b4[16];  /* For inet_2a */
 
-struct prefix *irdp_get_prefix(struct interface *ifp)
+static struct prefix *
+irdp_get_prefix(struct interface *ifp)
 {
-  listnode node;
+  struct listnode *node;
   struct connected *ifc;
   
-  if(ifp->connected) 
-    for (node = listhead (ifp->connected); node; nextnode (node)) {
-      ifc = getdata (node);
+  if (ifp->connected)
+    for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
       return ifc->address;
-    }
+
   return NULL;
 }
 
 /* Join to the add/leave multicast group. */
-int if_group (struct interface *ifp, 
+static int
+if_group (struct interface *ifp, 
          int sock, 
          u_int32_t group, 
          int add_leave)
@@ -97,10 +103,11 @@ int if_group (struct interface *ifp,
   struct ip_mreq m;
   struct prefix *p;
   int ret;
+  char b1[INET_ADDRSTRLEN];
 
   zi = ifp->info;
 
-  bzero (&m, sizeof (m));
+  memset (&m, 0, sizeof (m));
   m.imr_multiaddr.s_addr = htonl (group);
   p = irdp_get_prefix(ifp);
 
@@ -116,17 +123,19 @@ int if_group (struct interface *ifp,
   if (ret < 0)
     zlog_warn ("IRDP: %s can't setsockopt %s: %s",
               add_leave == IP_ADD_MEMBERSHIP? "join group":"leave group", 
-               inet_2a(group, b1),
-               strerror (errno));
+              inet_2a(group, b1),
+              safe_strerror (errno));
 
   return ret;
 }
 
-int if_add_group (struct interface *ifp)
+static int
+if_add_group (struct interface *ifp)
 {
   struct zebra_if *zi= ifp->info;
   struct irdp_interface *irdp = &zi->irdp;
   int ret;
+  char b1[INET_ADDRSTRLEN];
 
   ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP);
   if (ret < 0) {
@@ -134,41 +143,32 @@ int if_add_group (struct interface *ifp)
   }
 
   if(irdp->flags & IF_DEBUG_MISC )
-    zlog_warn("IRDP: Adding group %s for %s\n", 
-             inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
-             ifp->name);
+    zlog_debug("IRDP: Adding group %s for %s", 
+              inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
+              ifp->name);
   return 0;
 }
-int if_drop_group (struct interface *ifp)
+
+static int
+if_drop_group (struct interface *ifp)
 {
   struct zebra_if *zi= ifp->info;
   struct irdp_interface *irdp = &zi->irdp;
   int ret;
+  char b1[INET_ADDRSTRLEN];
 
   ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_DROP_MEMBERSHIP);
   if (ret < 0)
     return ret;
 
   if(irdp->flags & IF_DEBUG_MISC)
-    zlog_warn("IRDP: Leaving group %s for %s\n", 
-             inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
-             ifp->name);
+    zlog_debug("IRDP: Leaving group %s for %s", 
+              inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
+              ifp->name);
   return 0;
 }
 
-struct interface *get_iflist_ifp(int idx)
-{
-  listnode node;
-  struct interface *ifp;
-
-  for (node = listhead (iflist); node; nextnode (node)) {
-      ifp = getdata (node);
-      if(ifp->ifindex == idx) return ifp;
-    }
-  return NULL;
-}
-
-void
+static void
 if_set_defaults(struct interface *ifp)
 {
   struct zebra_if *zi=ifp->info;
@@ -181,28 +181,33 @@ if_set_defaults(struct interface *ifp)
 }
 
 
-struct Adv *Adv_new ()
+static struct Adv *Adv_new (void)
 {
-  struct Adv *new;
-  new = XMALLOC (MTYPE_TMP, sizeof (struct Adv));
-  memset (new, 0, sizeof (struct Adv));
-  return new;
+  return XCALLOC (MTYPE_TMP, sizeof (struct Adv));
 }
 
-void Adv_free (struct Adv *adv)
+static void
+Adv_free (struct Adv *adv)
 {
   XFREE (MTYPE_TMP, adv);
 }
 
-void irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
+static void
+irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
 {
   struct zebra_if *zi= ifp->info;
   struct irdp_interface *irdp = &zi->irdp;
-  listnode node;
+  struct listnode *node;
+  struct connected *ifc;
   u_int32_t timer, seed;
 
   if (irdp->flags & IF_ACTIVE ) {
-    zlog_warn("IRDP: Interface is already active %s\n", ifp->name);
+    zlog_warn("IRDP: Interface is already active %s", ifp->name);
+    return;
+  }
+  if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) {
+    zlog_warn("IRDP: Cannot activate interface %s (cannot create "
+             "IRDP socket)", ifp->name);
     return;
   }
   irdp->flags |= IF_ACTIVE;
@@ -213,7 +218,7 @@ void irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
   if_add_update(ifp);
 
   if (! (ifp->flags & IFF_UP)) {
-    zlog_warn("IRDP: Interface is down %s\n", ifp->name);
+    zlog_warn("IRDP: Interface is down %s", ifp->name);
   }
 
   /* Shall we cancel if_start if if_add_group fails? */
@@ -222,7 +227,7 @@ void irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
     if_add_group(ifp);
     
     if (! (ifp->flags & (IFF_MULTICAST|IFF_ALLMULTI))) {
-      zlog_warn("IRDP: Interface not multicast enabled %s\n", ifp->name);
+      zlog_warn("IRDP: Interface not multicast enabled %s", ifp->name);
     }
   }
 
@@ -234,18 +239,18 @@ void irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
   /* The spec suggests this for randomness */
 
   seed = 0;
-  if( ifp->connected) 
-         for (node = listhead (ifp->connected); node; nextnode (node)) 
-         {
-                 struct connected *ifc = getdata (node);
-                 seed = ifc->address->u.prefix4.s_addr;
-         }
+  if( ifp->connected)
+    for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
+      {
+        seed = ifc->address->u.prefix4.s_addr;
+        break;
+      }
   
   srandom(seed);
   timer =  (random () % IRDP_DEFAULT_INTERVAL) + 1; 
 
   irdp->AdvPrefList = list_new();
-  irdp->AdvPrefList->del =  (void *) Adv_free; /* Destructor */
+  irdp->AdvPrefList->del =  (void (*)(void *)) Adv_free; /* Destructor */
 
 
   /* And this for startup. Speed limit from 1991 :-). But it's OK*/
@@ -256,9 +261,9 @@ void irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
 
   
   if(irdp->flags & IF_DEBUG_MISC)
-    zlog_warn("IRDP: Init timer for %s set to %u\n", 
-             ifp->name, 
-             timer);
+    zlog_debug("IRDP: Init timer for %s set to %u", 
+              ifp->name, 
+              timer);
 
   irdp->t_advertise = thread_add_timer(zebrad.master, 
                                       irdp_send_thread, 
@@ -266,7 +271,8 @@ void irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
                                       timer);
 }
 
-void irdp_if_stop(struct interface *ifp)
+static void
+irdp_if_stop(struct interface *ifp)
 {
   struct zebra_if *zi=ifp->info;
   struct irdp_interface *irdp=&zi->irdp;
@@ -277,7 +283,7 @@ void irdp_if_stop(struct interface *ifp)
   }
 
   if (! (irdp->flags & IF_ACTIVE )) {
-    zlog_warn("Interface is not active %s\n", ifp->name);
+    zlog_warn("Interface is not active %s", ifp->name);
     return;
   }
 
@@ -293,13 +299,14 @@ void irdp_if_stop(struct interface *ifp)
 }
 
 
-void irdp_if_shutdown(struct interface *ifp)
+static void
+irdp_if_shutdown(struct interface *ifp)
 {
   struct zebra_if *zi= ifp->info;
   struct irdp_interface *irdp = &zi->irdp;
 
   if (irdp->flags & IF_SHUTDOWN ) {
-    zlog_warn("IRDP: Interface is already shutdown %s\n", ifp->name);
+    zlog_warn("IRDP: Interface is already shutdown %s", ifp->name);
     return;
   }
 
@@ -313,13 +320,14 @@ void irdp_if_shutdown(struct interface *ifp)
   irdp_advert_off(ifp);
 }
 
-void irdp_if_no_shutdown(struct interface *ifp)
+static void
+irdp_if_no_shutdown(struct interface *ifp)
 {
   struct zebra_if *zi= ifp->info;
   struct irdp_interface *irdp = &zi->irdp;
 
   if (! (irdp->flags & IF_SHUTDOWN )) {
-    zlog_warn("IRDP: Interface is not shutdown %s\n", ifp->name);
+    zlog_warn("IRDP: Interface is not shutdown %s", ifp->name);
     return;
   }
 
@@ -337,7 +345,8 @@ void irdp_config_write (struct vty *vty, struct interface *ifp)
   struct zebra_if *zi=ifp->info;
   struct irdp_interface *irdp=&zi->irdp;
   struct Adv *adv;
-  listnode node;
+  struct listnode *node;
+  char b1[INET_ADDRSTRLEN];
 
   if(irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) {
 
@@ -352,14 +361,11 @@ void irdp_config_write (struct vty *vty, struct interface *ifp)
     vty_out (vty, " ip irdp preference %ld%s",  
             irdp->Preference, VTY_NEWLINE);
 
-    for (node = listhead (irdp->AdvPrefList); node; nextnode (node)) {
-           adv = getdata (node);
-           vty_out (vty, " ip irdp address %s preference %d%s",
-                    inet_2a(adv->ip.s_addr, b1),
-                    adv->pref,
-                    VTY_NEWLINE);
-
-    }
+    for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
+      vty_out (vty, " ip irdp address %s preference %d%s",
+                    inet_2a(adv->ip.s_addr, b1),
+                    adv->pref, 
+                    VTY_NEWLINE);
 
     vty_out (vty, " ip irdp holdtime %d%s",  
             irdp->Lifetime, VTY_NEWLINE);
@@ -408,9 +414,10 @@ DEFUN (ip_irdp_broadcast,
   return CMD_SUCCESS;
 }
 
-DEFUN (ip_irdp_no,
-       ip_irdp_cmd_no,
+DEFUN (no_ip_irdp,
+       no_ip_irdp_cmd,
        "no ip irdp",
+       NO_STR
        IP_STR
        "Disable ICMP Router discovery on this interface\n")
 {
@@ -442,9 +449,10 @@ DEFUN (ip_irdp_shutdown,
   return CMD_SUCCESS;
 }
 
-DEFUN (ip_irdp_no_shutdown,
-       ip_irdp_no_shutdown_cmd,
+DEFUN (no_ip_irdp_shutdown,
+       no_ip_irdp_shutdown_cmd,
        "no ip irdp shutdown",
+       NO_STR
        IP_STR
        "ICMP Router discovery no shutdown on this interface\n")
 {
@@ -501,7 +509,7 @@ DEFUN (ip_irdp_minadvertinterval,
   zi=ifp->info;
   irdp=&zi->irdp;
 
-  if( atoi(argv[0]) <= irdp->MaxAdvertInterval) {
+  if( (unsigned) atoi(argv[0]) <= irdp->MaxAdvertInterval) {
       irdp->MinAdvertInterval = atoi(argv[0]);
 
       return CMD_SUCCESS;
@@ -535,7 +543,7 @@ DEFUN (ip_irdp_maxadvertinterval,
   irdp=&zi->irdp;
 
 
-  if( irdp->MinAdvertInterval <= atoi(argv[0]) ) {
+  if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[0]) ) {
     irdp->MaxAdvertInterval = atoi(argv[0]);
 
       return CMD_SUCCESS;
@@ -549,16 +557,13 @@ DEFUN (ip_irdp_maxadvertinterval,
   return CMD_WARNING;
 }
 
+/* DEFUN needs to be fixed for negative ranages...
+ * "ip irdp preference <-2147483648-2147483647>",
+ * Be positive for now. :-)
+ */
+
 DEFUN (ip_irdp_preference,
        ip_irdp_preference_cmd,
-
-       /* DEFUN needs to be fixed for negative ranages...
-         Be positive for now. :-)
-
-         "ip irdp preference <-2147483648-2147483647>",
-       */
-
-
        "ip irdp preference <0-2147483647>",
        IP_STR
        "ICMP Router discovery on this interface\n"
@@ -589,7 +594,7 @@ DEFUN (ip_irdp_address_preference,
        "Set IRDP address for advertise\n"
        "Preference level\n")
 {
-  listnode node;
+  struct listnode *node;
   struct in_addr ip; 
   int pref;
   int ret;
@@ -611,10 +616,9 @@ DEFUN (ip_irdp_address_preference,
 
   pref = atoi(argv[1]);
 
-  for (node = listhead (irdp->AdvPrefList); node; nextnode (node)) {
-         adv = getdata (node);
-      if(adv->ip.s_addr == ip.s_addr) return CMD_SUCCESS;
-  }
+  for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
+    if(adv->ip.s_addr == ip.s_addr) 
+      return CMD_SUCCESS;
 
   adv = Adv_new();
   adv->ip = ip;
@@ -625,16 +629,17 @@ DEFUN (ip_irdp_address_preference,
 
 }
 
-DEFUN (ip_irdp_address_preference_no,
-       ip_irdp_address_preference_cmd_no,
+DEFUN (no_ip_irdp_address_preference,
+       no_ip_irdp_address_preference_cmd,
        "no ip irdp address A.B.C.D preference <0-2147483647>",
+       NO_STR
        IP_STR
        "Alter ICMP Router discovery preference this interface\n"
        "Removes IRDP non-default preference\n"
        "Select IRDP address\n"
        "Old preference level\n")
 {
-  listnode node;
+  struct listnode *node, *nnode;
   struct in_addr ip; 
   int pref;
   int ret;
@@ -652,21 +657,21 @@ DEFUN (ip_irdp_address_preference_no,
   irdp=&zi->irdp;
 
   ret = inet_aton(argv[0], &ip);
-  if(!ret) return CMD_WARNING;
+  if (!ret) 
+    return CMD_WARNING;
 
   pref = atoi(argv[1]);
 
-  for (node = listhead (irdp->AdvPrefList); node; nextnode (node)) {
-         adv = getdata (node);
-         if(adv->ip.s_addr == ip.s_addr ) {
-                 listnode_delete(irdp->AdvPrefList, adv);
-                 break;
-         }
-  }
-
+  for (ALL_LIST_ELEMENTS (irdp->AdvPrefList, node, nnode, adv))
+    {
+      if(adv->ip.s_addr == ip.s_addr )
+        {
+          listnode_delete(irdp->AdvPrefList, adv);
+          break;
+        }
+    }
+  
   return CMD_SUCCESS;
-
-
 }
 
 DEFUN (ip_irdp_debug_messages,
@@ -761,19 +766,19 @@ DEFUN (ip_irdp_debug_disable,
 }
 
 void
-irdp_if_init ()
+irdp_init ()
 {
   install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd);
   install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd);
-  install_element (INTERFACE_NODE, &ip_irdp_cmd_no);
+  install_element (INTERFACE_NODE, &no_ip_irdp_cmd);
   install_element (INTERFACE_NODE, &ip_irdp_shutdown_cmd);
-  install_element (INTERFACE_NODE, &ip_irdp_no_shutdown_cmd);
+  install_element (INTERFACE_NODE, &no_ip_irdp_shutdown_cmd);
   install_element (INTERFACE_NODE, &ip_irdp_holdtime_cmd);
   install_element (INTERFACE_NODE, &ip_irdp_maxadvertinterval_cmd);
   install_element (INTERFACE_NODE, &ip_irdp_minadvertinterval_cmd);
   install_element (INTERFACE_NODE, &ip_irdp_preference_cmd);
   install_element (INTERFACE_NODE, &ip_irdp_address_preference_cmd);
-  install_element (INTERFACE_NODE, &ip_irdp_address_preference_cmd_no);
+  install_element (INTERFACE_NODE, &no_ip_irdp_address_preference_cmd);
 
   install_element (INTERFACE_NODE, &ip_irdp_debug_messages_cmd);
   install_element (INTERFACE_NODE, &ip_irdp_debug_misc_cmd);