]> 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 673f0637c79cfc83fa0c3dd96a74ce8f4e8053d6..925b3f13786712684c42be2ea92ea5d31e3eef9d 100644 (file)
@@ -35,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"
@@ -94,7 +95,7 @@ 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;
        }
 
@@ -124,18 +125,14 @@ 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");
-               goto error;
+               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:
@@ -202,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)
 {
@@ -1506,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) {
@@ -1516,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);