]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/if_ioctl_solaris.c
Merge pull request #5706 from mjstapp/fix_nh_debug_show
[mirror_frr.git] / zebra / if_ioctl_solaris.c
index 5a58fe1751cbc54bbbb131aaf1ccc4007db85284..2a2504ebf8adec7b49a23a15bd6623ee7e08e8d9 100644 (file)
@@ -39,6 +39,8 @@
 #include "zebra/interface.h"
 #include "zebra/ioctl_solaris.h"
 #include "zebra/rib.h"
+#include "zebra/rt.h"
+#include "zebra/zebra_errors.h"
 
 static int if_get_addr(struct interface *, struct sockaddr *, const char *);
 static void interface_info_ioctl(struct interface *);
@@ -55,34 +57,32 @@ static int interface_list_ioctl(int af)
        struct lifconf lifconf;
        struct interface *ifp;
        int n;
-       int save_errno;
        size_t needed, lastneeded = 0;
        char *buf = NULL;
 
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                sock = socket(af, SOCK_DGRAM, 0);
        }
 
        if (sock < 0) {
-               zlog_warn("Can't make %s socket stream: %s",
-                         (af == AF_INET ? "AF_INET" : "AF_INET6"),
-                         safe_strerror(errno));
+               flog_err_sys(EC_LIB_SOCKET, "Can't make %s socket stream: %s",
+                            (af == AF_INET ? "AF_INET" : "AF_INET6"),
+                            safe_strerror(errno));
                return -1;
        }
 
 calculate_lifc_len:
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                lifn.lifn_family = af;
                lifn.lifn_flags = LIFC_NOXMIT;
                /* we want NOXMIT interfaces too */
                ret = ioctl(sock, SIOCGLIFNUM, &lifn);
-               save_errno = errno;
-
        }
 
        if (ret < 0) {
-               zlog_warn("interface_list_ioctl: SIOCGLIFNUM failed %s",
-                         safe_strerror(save_errno));
+               flog_err_sys(EC_LIB_SYSTEM_CALL,
+                            "interface_list_ioctl: SIOCGLIFNUM failed %s",
+                            safe_strerror(errno));
                close(sock);
                return -1;
        }
@@ -107,7 +107,7 @@ calculate_lifc_len:
        lifconf.lifc_len = needed;
        lifconf.lifc_buf = buf;
 
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                ret = ioctl(sock, SIOCGLIFCONF, &lifconf);
        }
 
@@ -115,7 +115,8 @@ calculate_lifc_len:
                if (errno == EINVAL)
                        goto calculate_lifc_len;
 
-               zlog_warn("SIOCGLIFCONF: %s", safe_strerror(errno));
+               flog_err_sys(EC_LIB_SYSTEM_CALL, "SIOCGLIFCONF: %s",
+                            safe_strerror(errno));
                goto end;
        }
 
@@ -155,7 +156,7 @@ calculate_lifc_len:
                       && (*(lifreq->lifr_name + normallen) != ':'))
                        normallen++;
 
-               ifp = if_get_by_name(lifreq->lifr_name, VRF_DEFAULT, 0);
+               ifp = if_get_by_name(lifreq->lifr_name, VRF_DEFAULT);
 
                if (lifreq->lifr_addr.ss_family == AF_INET)
                        ifp->flags |= IFF_IPV4;
@@ -206,7 +207,8 @@ static int if_get_index(struct interface *ifp)
                ret = -1;
 
        if (ret < 0) {
-               zlog_warn("SIOCGLIFINDEX(%s) failed", ifp->name);
+               flog_err_sys(EC_LIB_SYSTEM_CALL, "SIOCGLIFINDEX(%s) failed",
+                            ifp->name);
                return ret;
        }
 
@@ -245,7 +247,8 @@ static int if_get_addr(struct interface *ifp, struct sockaddr *addr,
         * We need to use the logical interface name / label, if we've been
         * given one, in order to get the right address
         */
-       strncpy(lifreq.lifr_name, (label ? label : ifp->name), IFNAMSIZ);
+       strlcpy(lifreq.lifr_name, (label ? label : ifp->name),
+               sizeof(lifreq.lifr_name));
 
        /* Interface's address. */
        memcpy(&lifreq.lifr_addr, addr, ADDRLEN(addr));
@@ -268,8 +271,9 @@ static int if_get_addr(struct interface *ifp, struct sockaddr *addr,
 
                if (ret < 0) {
                        if (errno != EADDRNOTAVAIL) {
-                               zlog_warn("SIOCGLIFNETMASK (%s) fail: %s",
-                                         ifp->name, safe_strerror(errno));
+                               flog_err_sys(EC_LIB_SYSTEM_CALL,
+                                            "SIOCGLIFNETMASK (%s) fail: %s",
+                                            ifp->name, safe_strerror(errno));
                                return ret;
                        }
                        return 0;
@@ -288,8 +292,9 @@ static int if_get_addr(struct interface *ifp, struct sockaddr *addr,
                        if (ifp->flags & IFF_POINTOPOINT)
                                prefixlen = IPV6_MAX_BITLEN;
                        else
-                               zlog_warn("SIOCGLIFSUBNET (%s) fail: %s",
-                                         ifp->name, safe_strerror(errno));
+                               flog_err_sys(EC_LIB_SYSTEM_CALL,
+                                            "SIOCGLIFSUBNET (%s) fail: %s",
+                                            ifp->name, safe_strerror(errno));
                } else {
                        prefixlen = lifreq.lifr_addrlen;
                }
@@ -298,10 +303,11 @@ static int if_get_addr(struct interface *ifp, struct sockaddr *addr,
        /* Set address to the interface. */
        if (af == AF_INET)
                connected_add_ipv4(ifp, flags, &SIN(addr)->sin_addr, prefixlen,
-                                  (struct in_addr *)dest_pnt, label);
+                                  (struct in_addr *)dest_pnt, label,
+                                  METRIC_MAX);
        else if (af == AF_INET6)
                connected_add_ipv6(ifp, flags, &SIN6(addr)->sin6_addr, NULL,
-                                  prefixlen, label);
+                                  prefixlen, label, METRIC_MAX);
 
        return 0;
 }
@@ -319,7 +325,7 @@ static void interface_info_ioctl(struct interface *ifp)
 void interface_list(struct zebra_ns *zns)
 {
        if (zns->ns_id != NS_DEFAULT) {
-               zlog_warn("interface_list: ignore NS %u", zns->ns_id);
+               zlog_debug("interface_list: ignore NS %u", zns->ns_id);
                return;
        }
        interface_list_ioctl(AF_INET);