]> git.proxmox.com Git - mirror_frr.git/blobdiff - ripngd/ripngd.c
*: use frr_elevate_privs() (1/2: coccinelle)
[mirror_frr.git] / ripngd / ripngd.c
index 51475dc642abbfcfd7c4450a10613dcc95dcad08..925b3f13786712684c42be2ea92ea5d31e3eef9d 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -36,6 +35,7 @@
 #include "routemap.h"
 #include "if_rmap.h"
 #include "privs.h"
+#include "lib_errors.h"
 
 #include "ripngd/ripngd.h"
 #include "ripngd/ripng_route.h"
@@ -51,8 +51,6 @@ enum { ripng_all_route,
        ripng_changed_route,
 };
 
-extern struct zebra_privs_t ripngd_privs;
-
 /* Prototypes. */
 void ripng_output_process(struct interface *, struct sockaddr_in6 *, int);
 
@@ -97,28 +95,28 @@ static int ripng_make_socket(void)
 
        sock = socket(AF_INET6, SOCK_DGRAM, 0);
        if (sock < 0) {
-               zlog_err("Can't make ripng socket");
+               flog_err_sys(LIB_ERR_SOCKET, "Can't make ripng socket");
                return sock;
        }
 
        setsockopt_so_recvbuf(sock, 8096);
        ret = setsockopt_ipv6_pktinfo(sock, 1);
        if (ret < 0)
-               return ret;
+               goto error;
 #ifdef IPTOS_PREC_INTERNETCONTROL
        ret = setsockopt_ipv6_tclass(sock, IPTOS_PREC_INTERNETCONTROL);
        if (ret < 0)
-               return ret;
+               goto error;
 #endif
        ret = setsockopt_ipv6_multicast_hops(sock, 255);
        if (ret < 0)
-               return ret;
+               goto error;
        ret = setsockopt_ipv6_multicast_loop(sock, 0);
        if (ret < 0)
-               return ret;
+               goto error;
        ret = setsockopt_ipv6_hoplimit(sock, 1);
        if (ret < 0)
-               return ret;
+               goto error;
 
        memset(&ripaddr, 0, sizeof(ripaddr));
        ripaddr.sin6_family = AF_INET6;
@@ -127,19 +125,19 @@ static int ripng_make_socket(void)
 #endif /* SIN6_LEN */
        ripaddr.sin6_port = htons(RIPNG_PORT_DEFAULT);
 
-       if (ripngd_privs.change(ZPRIVS_RAISE))
-               zlog_err("ripng_make_socket: could not raise privs");
+       frr_elevate_privs(&ripngd_privs) {
 
-       ret = bind(sock, (struct sockaddr *)&ripaddr, sizeof(ripaddr));
-       if (ret < 0) {
-               zlog_err("Can't bind ripng socket: %s.", safe_strerror(errno));
-               if (ripngd_privs.change(ZPRIVS_LOWER))
-                       zlog_err("ripng_make_socket: could not lower privs");
-               return ret;
+               ret = bind(sock, (struct sockaddr *)&ripaddr, sizeof(ripaddr));
+               if (ret < 0) {
+                       zlog_err("Can't bind ripng socket: %s.", safe_strerror(errno));
+                       goto error;
+               }
        }
-       if (ripngd_privs.change(ZPRIVS_LOWER))
-               zlog_err("ripng_make_socket: could not lower privs");
        return sock;
+
+error:
+       close(sock);
+       return ret;
 }
 
 /* Send RIPng packet. */
@@ -177,6 +175,7 @@ int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
                addr.sin6_port = htons(RIPNG_PORT_DEFAULT);
        }
 
+       memset(&msg, 0, sizeof(msg));
        msg.msg_name = (void *)&addr;
        msg.msg_namelen = sizeof(struct sockaddr_in6);
        msg.msg_iov = &iov;
@@ -200,19 +199,21 @@ int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
 
        if (ret < 0) {
                if (to)
-                       zlog_err("RIPng send fail on %s to %s: %s", ifp->name,
-                                inet6_ntoa(to->sin6_addr),
-                                safe_strerror(errno));
+                       flog_err_sys(LIB_ERR_SOCKET,
+                                    "RIPng send fail on %s to %s: %s",
+                                    ifp->name, inet6_ntoa(to->sin6_addr),
+                                    safe_strerror(errno));
                else
-                       zlog_err("RIPng send fail on %s: %s", ifp->name,
-                                safe_strerror(errno));
+                       flog_err_sys(LIB_ERR_SOCKET,
+                                    "RIPng send fail on %s: %s", ifp->name,
+                                    safe_strerror(errno));
        }
 
        return ret;
 }
 
 /* Receive UDP RIPng packet from socket. */
-static int ripng_recv_packet(int sock, u_char *buf, int bufsize,
+static int ripng_recv_packet(int sock, uint8_t *buf, int bufsize,
                             struct sockaddr_in6 *from, ifindex_t *ifindex,
                             int *hoplimit)
 {
@@ -229,6 +230,7 @@ static int ripng_recv_packet(int sock, u_char *buf, int bufsize,
        char adata[1024];
 
        /* Fill in message and iovec. */
+       memset(&msg, 0, sizeof(msg));
        msg.msg_name = (void *)from;
        msg.msg_namelen = sizeof(struct sockaddr_in6);
        msg.msg_iov = &iov;
@@ -406,8 +408,7 @@ static int ripng_garbage_collect(struct thread *t)
        /* Unlock route_node. */
        listnode_delete(rp->info, rinfo);
        if (list_isempty((struct list *)rp->info)) {
-               list_free(rp->info);
-               rp->info = NULL;
+               list_delete_and_null((struct list **)&rp->info);
                route_unlock_node(rp);
        }
 
@@ -842,6 +843,8 @@ static void ripng_route_process(struct rte *rte, struct sockaddr_in6 *from,
                   unusable). */
                if (rte->metric != RIPNG_METRIC_INFINITY)
                        ripng_ecmp_add(&newinfo);
+               else
+                       route_unlock_node(rp);
        } else {
                /* If there is an existing route, compare the next hop address
                   to the address of the router from which the datagram came.
@@ -1377,7 +1380,7 @@ static void ripng_clear_changed_flag(void)
    enabled interface. */
 static int ripng_update(struct thread *t)
 {
-       struct listnode *node;
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
        struct ripng_interface *ri;
 
@@ -1389,7 +1392,7 @@ static int ripng_update(struct thread *t)
                zlog_debug("RIPng update timer expired!");
 
        /* Supply routes to each interface. */
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) {
+       FOR_ALL_INTERFACES (vrf, ifp) {
                ri = ifp->info;
 
                if (if_is_loopback(ifp) || !if_is_up(ifp))
@@ -1445,7 +1448,7 @@ static int ripng_triggered_interval(struct thread *t)
 /* Execute triggered update. */
 int ripng_triggered_update(struct thread *t)
 {
-       struct listnode *node;
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
        struct ripng_interface *ri;
        int interval;
@@ -1465,7 +1468,7 @@ int ripng_triggered_update(struct thread *t)
 
        /* Split Horizon processing is done when generating triggered
           updates as well as normal updates (see section 2.6). */
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) {
+       FOR_ALL_INTERFACES (vrf, ifp) {
                ri = ifp->info;
 
                if (if_is_loopback(ifp) || !if_is_up(ifp))
@@ -1492,8 +1495,9 @@ int ripng_triggered_update(struct thread *t)
           update is triggered when the timer expires. */
        interval = (random() % 5) + 1;
 
-       ripng->t_triggered_interval = thread_add_timer(
-               master, ripng_triggered_interval, NULL, interval);
+       ripng->t_triggered_interval = NULL;
+       thread_add_timer(master, ripng_triggered_interval, NULL, interval,
+                        &ripng->t_triggered_interval);
 
        return 0;
 }
@@ -1501,7 +1505,7 @@ int ripng_triggered_update(struct thread *t)
 /* Write routing table entry to the stream and return next index of
    the routing table entry in the stream. */
 int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p,
-                   struct in6_addr *nexthop, u_int16_t tag, u_char metric)
+                   struct in6_addr *nexthop, uint16_t tag, uint8_t metric)
 {
        /* RIPng packet header. */
        if (num == 0) {
@@ -1511,10 +1515,11 @@ int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p,
        }
 
        /* Write routing table entry. */
-       if (!nexthop)
-               stream_write(s, (u_char *)&p->prefix, sizeof(struct in6_addr));
-       else
-               stream_write(s, (u_char *)nexthop, sizeof(struct in6_addr));
+       if (!nexthop) {
+               assert(p);
+               stream_write(s, (uint8_t *)&p->prefix, sizeof(struct in6_addr));
+       } else
+               stream_write(s, (uint8_t *)nexthop, sizeof(struct in6_addr));
        stream_putw(s, tag);
        if (p)
                stream_putc(s, p->prefixlen);
@@ -1858,9 +1863,7 @@ void ripng_event(enum ripng_event event, int sock)
 
        switch (event) {
        case RIPNG_READ:
-               if (!ripng->t_read)
-                       ripng->t_read =
-                               thread_add_read(master, ripng_read, NULL, sock);
+               thread_add_read(master, ripng_read, NULL, sock, &ripng->t_read);
                break;
        case RIPNG_UPDATE_EVENT:
                if (ripng->t_update) {
@@ -1870,16 +1873,17 @@ void ripng_event(enum ripng_event event, int sock)
                /* Update timer jitter. */
                jitter = ripng_update_jitter(ripng->update_time);
 
-               ripng->t_update = thread_add_timer(
-                       master, ripng_update, NULL,
-                       sock ? 2 : ripng->update_time + jitter);
+               ripng->t_update = NULL;
+               thread_add_timer(master, ripng_update, NULL,
+                                sock ? 2 : ripng->update_time + jitter,
+                                &ripng->t_update);
                break;
        case RIPNG_TRIGGERED_UPDATE:
                if (ripng->t_triggered_interval)
                        ripng->trigger = 1;
-               else if (!ripng->t_triggered_update)
-                       ripng->t_triggered_update = thread_add_event(
-                               master, ripng_triggered_update, NULL, 0);
+               else
+                       thread_add_event(master, ripng_triggered_update, NULL,
+                                        0, &ripng->t_triggered_update);
                break;
        default:
                break;
@@ -1961,13 +1965,11 @@ DEFUN (show_ipv6_ripng,
 
        /* Header of display. */
        vty_out(vty,
-               "Codes: R - RIPng, C - connected, S - Static, O - OSPF, B - BGP%s"
-               "Sub-codes:%s"
-               "      (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
-               "      (i) - interface, (a/S) - aggregated/Suppressed%s%s"
-               "   Network      Next Hop                      Via     Metric Tag Time%s",
-               VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE,
-               VTY_NEWLINE);
+               "Codes: R - RIPng, C - connected, S - Static, O - OSPF, B - BGP\n"
+               "Sub-codes:\n"
+               "      (n) - normal, (s) - static, (d) - default, (r) - redistribute,\n"
+               "      (i) - interface, (a/S) - aggregated/Suppressed\n\n"
+               "   Network      Next Hop                      Via     Metric Tag Time\n");
 
        for (rp = route_top(ripng->table); rp; rp = route_next(rp)) {
                if ((aggregate = rp->aggregate) != NULL) {
@@ -1981,13 +1983,12 @@ DEFUN (show_ipv6_ripng,
                        vty_out(vty, "R(a) %s/%d ", inet6_ntoa(p->prefix),
                                p->prefixlen);
 #endif /* DEBUG */
-                       vty_out(vty, "%s", VTY_NEWLINE);
+                       vty_out(vty, "\n");
                        vty_out(vty, "%*s", 18, " ");
 
                        vty_out(vty, "%*s", 28, " ");
-                       vty_out(vty, "self      %2d  %3" ROUTE_TAG_PRI "%s",
-                               aggregate->metric, (route_tag_t)aggregate->tag,
-                               VTY_NEWLINE);
+                       vty_out(vty, "self      %2d  %3" ROUTE_TAG_PRI "\n",
+                               aggregate->metric, (route_tag_t)aggregate->tag);
                }
 
                if ((list = rp->info) != NULL)
@@ -2006,14 +2007,14 @@ DEFUN (show_ipv6_ripng,
                                        ripng_route_subtype_print(rinfo),
                                        inet6_ntoa(p->prefix), p->prefixlen);
 #endif /* DEBUG */
-                               vty_out(vty, "%s", VTY_NEWLINE);
+                               vty_out(vty, "\n");
                                vty_out(vty, "%*s", 18, " ");
                                len = vty_out(vty, "%s",
                                              inet6_ntoa(rinfo->nexthop));
 
                                len = 28 - len;
                                if (len > 0)
-                                       len = vty_out(vty, "%*s", len, " ");
+                                       vty_out(vty, "%*s", len, " ");
 
                                /* from */
                                if ((rinfo->type == ZEBRA_ROUTE_RIPNG)
@@ -2046,7 +2047,7 @@ DEFUN (show_ipv6_ripng,
                                        ripng_vty_out_uptime(vty, rinfo);
                                }
 
-                               vty_out(vty, "%s", VTY_NEWLINE);
+                               vty_out(vty, "\n");
                        }
        }
 
@@ -2061,58 +2062,57 @@ DEFUN (show_ipv6_ripng_status,
        "Show RIPng routes\n"
        "IPv6 routing protocol process parameters and statistics\n")
 {
-       struct listnode *node;
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
 
        if (!ripng)
                return CMD_SUCCESS;
 
-       vty_out(vty, "Routing Protocol is \"RIPng\"%s", VTY_NEWLINE);
+       vty_out(vty, "Routing Protocol is \"RIPng\"\n");
        vty_out(vty, "  Sending updates every %ld seconds with +/-50%%,",
                ripng->update_time);
-       vty_out(vty, " next due in %lu seconds%s",
-               thread_timer_remain_second(ripng->t_update), VTY_NEWLINE);
+       vty_out(vty, " next due in %lu seconds\n",
+               thread_timer_remain_second(ripng->t_update));
        vty_out(vty, "  Timeout after %ld seconds,", ripng->timeout_time);
-       vty_out(vty, " garbage collect after %ld seconds%s",
-               ripng->garbage_time, VTY_NEWLINE);
+       vty_out(vty, " garbage collect after %ld seconds\n",
+               ripng->garbage_time);
 
        /* Filtering status show. */
        config_show_distribute(vty);
 
        /* Default metric information. */
-       vty_out(vty, "  Default redistribution metric is %d%s",
-               ripng->default_metric, VTY_NEWLINE);
+       vty_out(vty, "  Default redistribution metric is %d\n",
+               ripng->default_metric);
 
        /* Redistribute information. */
        vty_out(vty, "  Redistributing:");
        ripng_redistribute_write(vty, 0);
-       vty_out(vty, "%s", VTY_NEWLINE);
+       vty_out(vty, "\n");
 
        vty_out(vty, "  Default version control: send version %d,",
                ripng->version);
-       vty_out(vty, " receive version %d %s", ripng->version, VTY_NEWLINE);
+       vty_out(vty, " receive version %d \n", ripng->version);
 
-       vty_out(vty, "    Interface        Send  Recv%s", VTY_NEWLINE);
+       vty_out(vty, "    Interface        Send  Recv\n");
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) {
+       FOR_ALL_INTERFACES (vrf, ifp) {
                struct ripng_interface *ri;
 
                ri = ifp->info;
 
                if (ri->enable_network || ri->enable_interface) {
 
-                       vty_out(vty, "    %-17s%-3d   %-3d%s", ifp->name,
-                               ripng->version, ripng->version, VTY_NEWLINE);
+                       vty_out(vty, "    %-17s%-3d   %-3d\n", ifp->name,
+                               ripng->version, ripng->version);
                }
        }
 
-       vty_out(vty, "  Routing for Networks:%s", VTY_NEWLINE);
+       vty_out(vty, "  Routing for Networks:\n");
        ripng_network_write(vty, 0);
 
-       vty_out(vty, "  Routing Information Sources:%s", VTY_NEWLINE);
+       vty_out(vty, "  Routing Information Sources:\n");
        vty_out(vty,
-               "    Gateway          BadPackets BadRoutes  Distance Last Update%s",
-               VTY_NEWLINE);
+               "    Gateway          BadPackets BadRoutes  Distance Last Update\n");
        ripng_peer_display(vty);
 
        return CMD_SUCCESS;
@@ -2123,7 +2123,7 @@ DEFUN (clear_ipv6_rip,
        "clear ipv6 ripng",
        CLEAR_STR
        IPV6_STR
-       "Clear IPv6 RIP database")
+       "Clear IPv6 RIP database\n")
 {
        struct route_node *rp;
        struct ripng_info *rinfo;
@@ -2153,7 +2153,7 @@ DEFUN (clear_ipv6_rip,
                }
 
                if (list_isempty(list)) {
-                       list_free(list);
+                       list_delete_and_null(&list);
                        rp->info = NULL;
                        route_unlock_node(rp);
                }
@@ -2178,7 +2178,7 @@ DEFUN_NOSH (router_ripng,
                /* Notice to user we couldn't create RIPng. */
                if (ret < 0) {
                        zlog_warn("can't create RIPng");
-                       return CMD_WARNING;
+                       return CMD_WARNING_CONFIG_FAILED;
                }
        }
 
@@ -2211,15 +2211,14 @@ DEFUN (ripng_route,
        ret = str2prefix_ipv6(argv[idx_ipv6addr]->arg,
                              (struct prefix_ipv6 *)&p);
        if (ret <= 0) {
-               vty_out(vty, "Malformed address%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Malformed address\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
        apply_mask_ipv6(&p);
 
        rp = route_node_get(ripng->route, (struct prefix *)&p);
        if (rp->info) {
-               vty_out(vty, "There is already same static route.%s",
-                       VTY_NEWLINE);
+               vty_out(vty, "There is already same static route.\n");
                route_unlock_node(rp);
                return CMD_WARNING;
        }
@@ -2246,15 +2245,15 @@ DEFUN (no_ripng_route,
        ret = str2prefix_ipv6(argv[idx_ipv6addr]->arg,
                              (struct prefix_ipv6 *)&p);
        if (ret <= 0) {
-               vty_out(vty, "Malformed address%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Malformed address\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
        apply_mask_ipv6(&p);
 
        rp = route_node_lookup(ripng->route, (struct prefix *)&p);
        if (!rp) {
-               vty_out(vty, "Can't find static route.%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Can't find static route.\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
 
        ripng_redistribute_delete(ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0);
@@ -2280,15 +2279,14 @@ DEFUN (ripng_aggregate_address,
        ret = str2prefix_ipv6(argv[idx_ipv6_prefixlen]->arg,
                              (struct prefix_ipv6 *)&p);
        if (ret <= 0) {
-               vty_out(vty, "Malformed address%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Malformed address\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
 
        /* Check aggregate alredy exist or not. */
        node = route_node_get(ripng->aggregate, &p);
        if (node->info) {
-               vty_out(vty, "There is already same aggregate route.%s",
-                       VTY_NEWLINE);
+               vty_out(vty, "There is already same aggregate route.\n");
                route_unlock_node(node);
                return CMD_WARNING;
        }
@@ -2304,7 +2302,7 @@ DEFUN (no_ripng_aggregate_address,
        "no aggregate-address X:X::X:X/M",
        NO_STR
        "Delete aggregate RIPng route announcement\n"
-       "Aggregate network")
+       "Aggregate network\n")
 {
        int idx_ipv6_prefixlen = 2;
        int ret;
@@ -2314,14 +2312,14 @@ DEFUN (no_ripng_aggregate_address,
        ret = str2prefix_ipv6(argv[idx_ipv6_prefixlen]->arg,
                              (struct prefix_ipv6 *)&p);
        if (ret <= 0) {
-               vty_out(vty, "Malformed address%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Malformed address\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
 
        rn = route_node_lookup(ripng->aggregate, &p);
        if (!rn) {
-               vty_out(vty, "Can't find aggregate route.%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Can't find aggregate route.\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
        route_unlock_node(rn);
        rn->info = NULL;
@@ -2373,8 +2371,8 @@ DEFUN (ripng_update_timer,
   update = strtoul (argv[0], &endptr, 10);
   if (update == ULONG_MAX || *endptr != '\0')
     {
-      vty_out (vty, "update timer value error%s", VTY_NEWLINE);
-      return CMD_WARNING;
+      vty_out (vty, "update timer value error\n");
+      return CMD_WARNING_CONFIG_FAILED;
     }
 
   ripng->update_time = update;
@@ -2408,8 +2406,8 @@ DEFUN (ripng_timeout_timer,
   timeout = strtoul (argv[0], &endptr, 10);
   if (timeout == ULONG_MAX || *endptr != '\0')
     {
-      vty_out (vty, "timeout timer value error%s", VTY_NEWLINE);
-      return CMD_WARNING;
+      vty_out (vty, "timeout timer value error\n");
+      return CMD_WARNING_CONFIG_FAILED;
     }
 
   ripng->timeout_time = timeout;
@@ -2441,8 +2439,8 @@ DEFUN (ripng_garbage_timer,
   garbage = strtoul (argv[0], &endptr, 10);
   if (garbage == ULONG_MAX || *endptr != '\0')
     {
-      vty_out (vty, "garbage timer value error%s", VTY_NEWLINE);
-      return CMD_WARNING;
+      vty_out (vty, "garbage timer value error\n");
+      return CMD_WARNING_CONFIG_FAILED;
     }
 
   ripng->garbage_time = garbage;
@@ -2478,12 +2476,9 @@ DEFUN (ripng_timers,
        unsigned long timeout;
        unsigned long garbage;
 
-       VTY_GET_INTEGER_RANGE("update timer", update, argv[idx_number]->arg, 0,
-                             65535);
-       VTY_GET_INTEGER_RANGE("timeout timer", timeout, argv[idx_number_2]->arg,
-                             0, 65535);
-       VTY_GET_INTEGER_RANGE("garbage timer", garbage, argv[idx_number_3]->arg,
-                             0, 65535);
+       update = strtoul(argv[idx_number]->arg, NULL, 10);
+       timeout = strtoul(argv[idx_number_2]->arg, NULL, 10);
+       garbage = strtoul(argv[idx_number_3]->arg, NULL, 10);
 
        /* Set each timer value. */
        ripng->update_time = update;
@@ -2523,21 +2518,19 @@ DEFUN (show_ipv6_protocols,
        "show ipv6 protocols",
        SHOW_STR
        IPV6_STR
-       "Routing protocol information")
+       "Routing protocol information\n")
 {
   if (! ripng)
     return CMD_SUCCESS;
 
-  vty_out (vty, "Routing Protocol is \"ripng\"%s", VTY_NEWLINE);
+  vty_out (vty, "Routing Protocol is \"ripng\"\n");
   
-  vty_out (vty, "Sending updates every %ld seconds, next due in %d seconds%s",
-          ripng->update_time, 0,
-          VTY_NEWLINE);
+  vty_out (vty, "Sending updates every %ld seconds, next due in %d seconds\n",
+          ripng->update_time, 0);
 
-  vty_out (vty, "Timerout after %ld seconds, garbage correct %ld%s",
+  vty_out (vty, "Timerout after %ld seconds, garbage correct %ld\n",
           ripng->timeout_time,
-          ripng->garbage_time,
-          VTY_NEWLINE);
+          ripng->garbage_time);
 
   vty_out (vty, "Outgoing update filter list for all interfaces is not set");
   vty_out (vty, "Incoming update filter list for all interfaces is not set");
@@ -2630,7 +2623,7 @@ DEFUN (ripng_allow_ecmp,
        "Allow Equal Cost MultiPath\n")
 {
        if (ripng->ecmp) {
-               vty_out(vty, "ECMP is already enabled.%s", VTY_NEWLINE);
+               vty_out(vty, "ECMP is already enabled.\n");
                return CMD_WARNING;
        }
 
@@ -2646,7 +2639,7 @@ DEFUN (no_ripng_allow_ecmp,
        "Allow Equal Cost MultiPath\n")
 {
        if (!ripng->ecmp) {
-               vty_out(vty, "ECMP is already disabled.%s", VTY_NEWLINE);
+               vty_out(vty, "ECMP is already disabled.\n");
                return CMD_WARNING;
        }
 
@@ -2667,18 +2660,17 @@ static int ripng_config_write(struct vty *vty)
        if (ripng) {
 
                /* RIPng router. */
-               vty_out(vty, "router ripng%s", VTY_NEWLINE);
+               vty_out(vty, "router ripng\n");
 
                if (ripng->default_information)
-                       vty_out(vty, " default-information originate%s",
-                               VTY_NEWLINE);
+                       vty_out(vty, " default-information originate\n");
 
                ripng_network_write(vty, 1);
 
                /* RIPng default metric configuration */
                if (ripng->default_metric != RIPNG_DEFAULT_METRIC_DEFAULT)
-                       vty_out(vty, " default-metric %d%s",
-                               ripng->default_metric, VTY_NEWLINE);
+                       vty_out(vty, " default-metric %d\n",
+                               ripng->default_metric);
 
                ripng_redistribute_write(vty, 1);
 
@@ -2688,41 +2680,36 @@ static int ripng_config_write(struct vty *vty)
                /* RIPng aggregate routes. */
                for (rp = route_top(ripng->aggregate); rp; rp = route_next(rp))
                        if (rp->info != NULL)
-                               vty_out(vty, " aggregate-address %s/%d%s",
+                               vty_out(vty, " aggregate-address %s/%d\n",
                                        inet6_ntoa(rp->p.u.prefix6),
-                                       rp->p.prefixlen,
-
-                                       VTY_NEWLINE);
+                                       rp->p.prefixlen);
 
                /* ECMP configuration. */
                if (ripng->ecmp)
-                       vty_out(vty, " allow-ecmp%s", VTY_NEWLINE);
+                       vty_out(vty, " allow-ecmp\n");
 
                /* RIPng static routes. */
                for (rp = route_top(ripng->route); rp; rp = route_next(rp))
                        if (rp->info != NULL)
-                               vty_out(vty, " route %s/%d%s",
+                               vty_out(vty, " route %s/%d\n",
                                        inet6_ntoa(rp->p.u.prefix6),
-                                       rp->p.prefixlen, VTY_NEWLINE);
+                                       rp->p.prefixlen);
 
                /* RIPng timers configuration. */
                if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT
                    || ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT
                    || ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT) {
-                       vty_out(vty, " timers basic %ld %ld %ld%s",
+                       vty_out(vty, " timers basic %ld %ld %ld\n",
                                ripng->update_time, ripng->timeout_time,
-                               ripng->garbage_time, VTY_NEWLINE);
+                               ripng->garbage_time);
                }
 #if 0
       if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT)
-       vty_out (vty, " update-timer %d%s", ripng->update_time,
-                VTY_NEWLINE);
+       vty_out (vty, " update-timer %d\n", ripng->update_time);
       if (ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT)
-       vty_out (vty, " timeout-timer %d%s", ripng->timeout_time,
-                VTY_NEWLINE);
+       vty_out (vty, " timeout-timer %d\n", ripng->timeout_time);
       if (ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT)
-       vty_out (vty, " garbage-timer %d%s", ripng->garbage_time,
-                VTY_NEWLINE);
+       vty_out (vty, " garbage-timer %d\n", ripng->garbage_time);
 #endif /* 0 */
 
                write += config_write_distribute(vty);
@@ -2808,10 +2795,10 @@ void ripng_distribute_update_interface(struct interface *ifp)
 /* Update all interface's distribute list. */
 static void ripng_distribute_update_all(struct prefix_list *notused)
 {
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
-       struct listnode *node;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
+       FOR_ALL_INTERFACES (vrf, ifp)
                ripng_distribute_update_interface(ifp);
 }
 
@@ -2845,7 +2832,7 @@ void ripng_clean()
                                                rinfo->t_garbage_collect);
                                        ripng_info_free(rinfo);
                                }
-                               list_delete(list);
+                               list_delete_and_null(&list);
                                rp->info = NULL;
                                route_unlock_node(rp);
                        }
@@ -2985,10 +2972,10 @@ static void ripng_routemap_update_redistribute(void)
 
 static void ripng_routemap_update(const char *unused)
 {
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct interface *ifp;
-       struct listnode *node;
 
-       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
+       FOR_ALL_INTERFACES (vrf, ifp)
                ripng_if_rmap_update_interface(ifp);
 
        ripng_routemap_update_redistribute();