]> git.proxmox.com Git - mirror_frr.git/blobdiff - babeld/babel_interface.c
*: fix source file headers & includes for errcodes
[mirror_frr.git] / babeld / babel_interface.c
index d14c4d8471492c4df3bf3ce878c4a9d93b6660fe..dc47ff002e1eec3908ea2bb35d0728299c88bc05 100644 (file)
@@ -27,6 +27,7 @@ THE SOFTWARE.
 #include "prefix.h"
 #include "vector.h"
 #include "distribute.h"
+#include "lib_errors.h"
 
 #include "babel_main.h"
 #include "util.h"
@@ -39,6 +40,7 @@ THE SOFTWARE.
 #include "route.h"
 #include "xroute.h"
 #include "babel_memory.h"
+#include "babel_errors.h"
 
 #define IS_ENABLE(ifp) (babel_enable_if_lookup(ifp->name) >= 0)
 
@@ -138,7 +140,7 @@ babel_interface_delete (int cmd, struct zclient *client, zebra_size_t length, vr
 
     /* To support pseudo interface do not free interface structure.  */
     /* if_delete(ifp); */
-    ifp->ifindex = IFINDEX_INTERNAL;
+    if_set_index(ifp, IFINDEX_INTERNAL);
 
     return 0;
 }
@@ -167,7 +169,7 @@ babel_interface_address_add (int cmd, struct zclient *client,
         if (babel_ifp->ipv4 == NULL) {
             babel_ifp->ipv4 = malloc(4);
             if (babel_ifp->ipv4 == NULL) {
-                zlog_err("not einough memory");
+                zlog_ferr(BABEL_ERR_MEMORY, "not enough memory");
             } else {
                 memcpy(babel_ifp->ipv4, &prefix->u.prefix4, 4);
             }
@@ -290,9 +292,9 @@ DEFUN (babel_network,
         ret = babel_enable_if_add (argv[1]->arg);
 
     if (ret < 0) {
-        vty_outln (vty, "There is same network configuration %s",
+        vty_out (vty, "There is same network configuration %s\n",
                    argv[1]->arg);
-        return CMD_WARNING_CONFIG_FAILED;
+        return CMD_WARNING;
     }
 
     return CMD_SUCCESS;
@@ -318,7 +320,7 @@ DEFUN (no_babel_network,
         ret = babel_enable_if_delete (argv[2]->arg);
 
     if (ret < 0) {
-        vty_outln (vty, "can't find network %s",argv[2]->arg);
+        vty_out (vty, "can't find network %s\n",argv[2]->arg);
         return CMD_WARNING_CONFIG_FAILED;
     }
 
@@ -707,7 +709,7 @@ interface_recalculate(struct interface *ifp)
     tmp = babel_ifp->sendbuf;
     babel_ifp->sendbuf = realloc(babel_ifp->sendbuf, babel_ifp->bufsize);
     if(babel_ifp->sendbuf == NULL) {
-        zlog_err("Couldn't reallocate sendbuf.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't reallocate sendbuf.");
         free(tmp);
         babel_ifp->bufsize = 0;
         return -1;
@@ -727,8 +729,9 @@ interface_recalculate(struct interface *ifp)
     rc = setsockopt(protocol_socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
                     (char*)&mreq, sizeof(mreq));
     if(rc < 0) {
-        zlog_err("setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
-                 ifp->name, safe_strerror(errno));
+        zlog_ferr(LIB_ERR_SOCKET,
+                 "setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
+                  ifp->name, safe_strerror(errno));
         /* This is probably due to a missing link-local address,
          so down this interface, and wait until the main loop
          tries to up it again. */
@@ -790,8 +793,9 @@ interface_reset(struct interface *ifp)
         rc = setsockopt(protocol_socket, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
                         (char*)&mreq, sizeof(mreq));
         if(rc < 0)
-            zlog_err("setsockopt(IPV6_LEAVE_GROUP) on interface '%s': %s",
-                     ifp->name, safe_strerror(errno));
+            zlog_ferr(LIB_ERR_SOCKET,
+                     "setsockopt(IPV6_LEAVE_GROUP) on interface '%s': %s",
+                      ifp->name, safe_strerror(errno));
     }
 
     update_interface_metric(ifp);
@@ -809,10 +813,10 @@ interface_reset(struct interface *ifp)
 void
 babel_interface_close_all(void)
 {
+    struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
     struct interface *ifp = NULL;
-    struct listnode *linklist_node = NULL;
 
-    FOR_ALL_INTERFACES(ifp, linklist_node) {
+    FOR_ALL_INTERFACES(vrf, ifp) {
         if(!if_up(ifp))
             continue;
         send_wildcard_retraction(ifp);
@@ -823,7 +827,7 @@ babel_interface_close_all(void)
         usleep(roughly(1000));
         gettime(&babel_now);
     }
-    FOR_ALL_INTERFACES(ifp, linklist_node) {
+    FOR_ALL_INTERFACES(vrf, ifp) {
         if(!if_up(ifp))
             continue;
         /* Make sure they got it. */
@@ -861,31 +865,31 @@ show_babel_interface_sub (struct vty *vty, struct interface *ifp)
   int is_up;
   babel_interface_nfo *babel_ifp;
 
-  vty_outln (vty, "%s is %s", ifp->name,
+  vty_out (vty, "%s is %s\n", ifp->name,
     ((is_up = if_is_operative(ifp)) ? "up" : "down"));
-  vty_outln (vty, "  ifindex %u, MTU %u bytes %s",
+  vty_out (vty, "  ifindex %u, MTU %u bytes %s\n",
     ifp->ifindex, MIN(ifp->mtu, ifp->mtu6), if_flag_dump(ifp->flags));
 
   if (!IS_ENABLE(ifp))
   {
-    vty_outln (vty, "  Babel protocol is not enabled on this interface");
+    vty_out (vty, "  Babel protocol is not enabled on this interface\n");
     return;
   }
   if (!is_up)
   {
-    vty_outln (vty,
-               "  Babel protocol is enabled, but not running on this interface");
+    vty_out (vty,
+               "  Babel protocol is enabled, but not running on this interface\n");
     return;
   }
   babel_ifp = babel_get_if_nfo (ifp);
-  vty_outln (vty, "  Babel protocol is running on this interface");
-  vty_outln (vty, "  Operating mode is \"%s\"",
+  vty_out (vty, "  Babel protocol is running on this interface\n");
+  vty_out (vty, "  Operating mode is \"%s\"\n",
            CHECK_FLAG(babel_ifp->flags, BABEL_IF_WIRED) ? "wired" : "wireless");
-  vty_outln (vty, "  Split horizon mode is %s",
+  vty_out (vty, "  Split horizon mode is %s\n",
            CHECK_FLAG(babel_ifp->flags, BABEL_IF_SPLIT_HORIZON) ? "On" : "Off");
-  vty_outln (vty, "  Hello interval is %u ms", babel_ifp->hello_interval);
-  vty_outln (vty, "  Update interval is %u ms", babel_ifp->update_interval);
-  vty_outln (vty, "  Rxcost multiplier is %u", babel_ifp->cost);
+  vty_out (vty, "  Hello interval is %u ms\n", babel_ifp->hello_interval);
+  vty_out (vty, "  Update interval is %u ms\n", babel_ifp->update_interval);
+  vty_out (vty, "  Rxcost multiplier is %u\n", babel_ifp->cost);
 }
 
 DEFUN (show_babel_interface,
@@ -896,18 +900,18 @@ DEFUN (show_babel_interface,
        "Interface information\n"
        "Interface\n")
 {
+  struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
   struct interface *ifp;
-  struct listnode *node;
 
   if (argc == 3)
   {
-    for (ALL_LIST_ELEMENTS_RO (vrf_iflist(VRF_DEFAULT), node, ifp))
+    FOR_ALL_INTERFACES (vrf, ifp)
       show_babel_interface_sub (vty, ifp);
     return CMD_SUCCESS;
   }
   if ((ifp = if_lookup_by_name (argv[3]->arg, VRF_DEFAULT)) == NULL)
   {
-    vty_outln (vty, "No such interface name");
+    vty_out (vty, "No such interface name\n");
     return CMD_WARNING;
   }
   show_babel_interface_sub (vty, ifp);
@@ -917,9 +921,9 @@ DEFUN (show_babel_interface,
 static void
 show_babel_neighbour_sub (struct vty *vty, struct neighbour *neigh)
 {
-    vty_outln (vty,
+    vty_out (vty,
              "Neighbour %s dev %s reach %04x rxcost %d txcost %d "
-             "rtt %s rttcost %d%s.",
+             "rtt %s rttcost %d%s.\n",
              format_address(neigh->address),
              neigh->ifp->name,
              neigh->reach,
@@ -949,7 +953,7 @@ DEFUN (show_babel_neighbour,
     }
     if ((ifp = if_lookup_by_name (argv[3]->arg, VRF_DEFAULT)) == NULL)
     {
-        vty_outln (vty, "No such interface name");
+        vty_out (vty, "No such interface name\n");
         return CMD_WARNING;
     }
     FOR_ALL_NEIGHBOURS(neigh) {
@@ -1001,7 +1005,7 @@ show_babel_routes_sub(struct babel_route *route, struct vty *vty,
                 break;
             if(k > 0)
                 channels[j++] = ',';
-            snprintf(channels + j, 100 - j, "%d", route->channels[k]);
+            snprintf(channels + j, 100 - j, "%u", route->channels[k]);
             j = strlen(channels);
         }
         snprintf(channels + j, 100 - j, ")");
@@ -1009,9 +1013,9 @@ show_babel_routes_sub(struct babel_route *route, struct vty *vty,
             channels[0] = '\0';
     }
 
-    vty_outln (vty,
+    vty_out (vty,
             "%s metric %d refmetric %d id %s seqno %d%s age %d "
-            "via %s neigh %s%s%s%s",
+            "via %s neigh %s%s%s%s\n",
             format_prefix(route->src->prefix, route->src->plen),
             route_metric(route), route->refmetric,
             format_eui64(route->src->id),
@@ -1032,7 +1036,7 @@ show_babel_xroutes_sub (struct xroute *xroute, struct vty *vty,
     if(prefix && !babel_prefix_eq(prefix, xroute->prefix, xroute->plen))
         return;
 
-    vty_outln (vty, "%s metric %d (exported)",
+    vty_out (vty, "%s metric %d (exported)\n",
             format_prefix(xroute->prefix, xroute->plen),
             xroute->metric);
 }
@@ -1056,7 +1060,7 @@ DEFUN (show_babel_route,
         }
         route_stream_done(routes);
     } else {
-        zlog_err("Couldn't allocate route stream.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
     }
     xroutes = xroute_stream();
     if(xroutes) {
@@ -1068,7 +1072,7 @@ DEFUN (show_babel_route,
         }
         xroute_stream_done(xroutes);
     } else {
-        zlog_err("Couldn't allocate route stream.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
     }
     return CMD_SUCCESS;
 }
@@ -1089,7 +1093,7 @@ DEFUN (show_babel_route_prefix,
 
     ret = str2prefix(argv[3]->arg, &prefix);
     if(ret == 0) {
-      vty_outln (vty, "%% Malformed address");
+      vty_out (vty, "%% Malformed address\n");
       return CMD_WARNING;
     }
         
@@ -1103,7 +1107,7 @@ DEFUN (show_babel_route_prefix,
         }
         route_stream_done(routes);
     } else {
-        zlog_err("Couldn't allocate route stream.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
     }
     xroutes = xroute_stream();
     if(xroutes) {
@@ -1115,7 +1119,7 @@ DEFUN (show_babel_route_prefix,
         }
         xroute_stream_done(xroutes);
     } else {
-        zlog_err("Couldn't allocate route stream.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
     }
     return CMD_SUCCESS;
 }
@@ -1138,7 +1142,7 @@ DEFUN (show_babel_route_addr,
 
     ret = inet_aton (argv[3]->arg, &addr);
     if (ret <= 0) {
-        vty_outln (vty, "%% Malformed address");
+        vty_out (vty, "%% Malformed address\n");
         return CMD_WARNING;
     }
 
@@ -1147,7 +1151,7 @@ DEFUN (show_babel_route_addr,
 
     ret = str2prefix(buf, &prefix);
     if (ret == 0) {
-        vty_outln (vty, "%% Parse error -- this shouldn't happen");
+        vty_out (vty, "%% Parse error -- this shouldn't happen\n");
         return CMD_WARNING;
     }
 
@@ -1161,7 +1165,7 @@ DEFUN (show_babel_route_addr,
         }
         route_stream_done(routes);
     } else {
-        zlog_err("Couldn't allocate route stream.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
     }
     xroutes = xroute_stream();
     if(xroutes) {
@@ -1173,7 +1177,7 @@ DEFUN (show_babel_route_addr,
         }
         xroute_stream_done(xroutes);
     } else {
-        zlog_err("Couldn't allocate route stream.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
     }
     return CMD_SUCCESS;
 }
@@ -1196,7 +1200,7 @@ DEFUN (show_babel_route_addr6,
 
     ret = inet_pton (AF_INET6, argv[3]->arg, &addr);
     if (ret <= 0) {
-        vty_outln (vty, "%% Malformed address");
+        vty_out (vty, "%% Malformed address\n");
         return CMD_WARNING;
     }
 
@@ -1206,7 +1210,7 @@ DEFUN (show_babel_route_addr6,
 
     ret = str2prefix(buf, &prefix);
     if (ret == 0) {
-        vty_outln (vty, "%% Parse error -- this shouldn't happen");
+        vty_out (vty, "%% Parse error -- this shouldn't happen\n");
         return CMD_WARNING;
     }
 
@@ -1220,7 +1224,7 @@ DEFUN (show_babel_route_addr6,
         }
         route_stream_done(routes);
     } else {
-        zlog_err("Couldn't allocate route stream.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
     }
     xroutes = xroute_stream();
     if(xroutes) {
@@ -1232,7 +1236,7 @@ DEFUN (show_babel_route_addr6,
         }
         xroute_stream_done(xroutes);
     } else {
-        zlog_err("Couldn't allocate route stream.");
+        zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
     }
     return CMD_SUCCESS;
 }
@@ -1244,9 +1248,9 @@ DEFUN (show_babel_parameters,
        "Babel information\n"
        "Configuration information\n")
 {
-    vty_outln (vty, "    -- Babel running configuration --");
+    vty_out (vty, "    -- Babel running configuration --\n");
     show_babel_main_configuration(vty);
-    vty_outln (vty, "    -- distribution lists --");
+    vty_out (vty, "    -- distribution lists --\n");
     config_show_distribute(vty);
 
     return CMD_SUCCESS;
@@ -1256,8 +1260,8 @@ void
 babel_if_init ()
 {
     /* initialize interface list */
-    if_add_hook (IF_NEW_HOOK,    babel_if_new_hook);
-    if_add_hook (IF_DELETE_HOOK, babel_if_delete_hook);
+    hook_register_prio(if_add, 0, babel_if_new_hook);
+    hook_register_prio(if_del, 0, babel_if_delete_hook);
 
     babel_enable_if = vector_init (1);
 
@@ -1316,68 +1320,68 @@ babeld-specific statement lines where appropriate. */
 static int
 interface_config_write (struct vty *vty)
 {
-    struct listnode *node;
+    struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
     struct interface *ifp;
     int write = 0;
 
-    for (ALL_LIST_ELEMENTS_RO (vrf_iflist(VRF_DEFAULT), node, ifp)) {
-        vty_outln (vty, "interface %s",ifp->name);
+    FOR_ALL_INTERFACES (vrf, ifp) {
+        vty_frame (vty, "interface %s\n",ifp->name);
         if (ifp->desc)
-            vty_outln (vty, " description %s",ifp->desc);
+            vty_out (vty, " description %s\n",ifp->desc);
         babel_interface_nfo *babel_ifp = babel_get_if_nfo (ifp);
         /* wireless is the default*/
         if (CHECK_FLAG (babel_ifp->flags, BABEL_IF_WIRED))
         {
-            vty_outln (vty, " babel wired");
+            vty_out (vty, " babel wired\n");
             write++;
         }
         if (babel_ifp->hello_interval != BABEL_DEFAULT_HELLO_INTERVAL)
         {
-            vty_outln (vty, " babel hello-interval %u",
+            vty_out (vty, " babel hello-interval %u\n",
                        babel_ifp->hello_interval);
             write++;
         }
         if (babel_ifp->update_interval != BABEL_DEFAULT_UPDATE_INTERVAL)
         {
-            vty_outln (vty, " babel update-interval %u",
+            vty_out (vty, " babel update-interval %u\n",
                        babel_ifp->update_interval);
             write++;
         }
         /* Some parameters have different defaults for wired/wireless. */
         if (CHECK_FLAG (babel_ifp->flags, BABEL_IF_WIRED)) {
             if (!CHECK_FLAG (babel_ifp->flags, BABEL_IF_SPLIT_HORIZON)) {
-                vty_outln (vty, " no babel split-horizon");
+                vty_out (vty, " no babel split-horizon\n");
                 write++;
             }
             if (babel_ifp->cost != BABEL_DEFAULT_RXCOST_WIRED) {
-                vty_outln (vty, " babel rxcost %u", babel_ifp->cost);
+                vty_out (vty, " babel rxcost %u\n", babel_ifp->cost);
                 write++;
             }
             if (babel_ifp->channel == BABEL_IF_CHANNEL_INTERFERING) {
-                vty_outln (vty, " babel channel interfering");
+                vty_out (vty, " babel channel interfering\n");
                 write++;
             } else if(babel_ifp->channel != BABEL_IF_CHANNEL_NONINTERFERING) {
-                vty_outln (vty, " babel channel %d",babel_ifp->channel);
+                vty_out (vty, " babel channel %d\n",babel_ifp->channel);
                 write++;
             }
         } else {
             if (CHECK_FLAG (babel_ifp->flags, BABEL_IF_SPLIT_HORIZON)) {
-                vty_outln (vty, " babel split-horizon");
+                vty_out (vty, " babel split-horizon\n");
                 write++;
             }
             if (babel_ifp->cost != BABEL_DEFAULT_RXCOST_WIRELESS) {
-                vty_outln (vty, " babel rxcost %u", babel_ifp->cost);
+                vty_out (vty, " babel rxcost %u\n", babel_ifp->cost);
                 write++;
             }
             if (babel_ifp->channel == BABEL_IF_CHANNEL_NONINTERFERING) {
-                vty_outln (vty, " babel channel noninterfering");
+                vty_out (vty, " babel channel noninterfering\n");
                 write++;
             } else if(babel_ifp->channel != BABEL_IF_CHANNEL_INTERFERING) {
-                vty_outln (vty, " babel channel %d",babel_ifp->channel);
+                vty_out (vty, " babel channel %d\n",babel_ifp->channel);
                 write++;
             }
         }
-        vty_outln (vty, "!");
+        vty_endframe (vty, "!\n");
         write++;
     }
     return write;
@@ -1393,7 +1397,7 @@ babel_enable_if_config_write (struct vty * vty)
     for (i = 0; i < vector_active (babel_enable_if); i++)
         if ((str = vector_slot (babel_enable_if, i)) != NULL)
         {
-            vty_outln (vty, " network %s", str);
+            vty_out (vty, " network %s\n", str);
             lines++;
         }
     return lines;