]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/sockunion.c
Merge pull request #5625 from qlyoung/fix-zapi-ipset-name-nullterm
[mirror_frr.git] / lib / sockunion.c
index e1bbbaa0c0777f3d32c49f5d7c11b82f3c61be7f..8fa9a3fad99187073a9114fedb42b66397237d50 100644 (file)
@@ -140,8 +140,7 @@ int sockunion_socket(const union sockunion *su)
        sock = socket(su->sa.sa_family, SOCK_STREAM, 0);
        if (sock < 0) {
                char buf[SU_ADDRSTRLEN];
-               flog_err(LIB_ERR_SOCKET,
-                        "Can't make socket for %s : %s",
+               flog_err(EC_LIB_SOCKET, "Can't make socket for %s : %s",
                         sockunion_log(su, buf, SU_ADDRSTRLEN),
                         safe_strerror(errno));
                return -1;
@@ -164,7 +163,7 @@ int sockunion_accept(int sock, union sockunion *su)
 }
 
 /* Return sizeof union sockunion.  */
-static int sockunion_sizeof(const union sockunion *su)
+int sockunion_sizeof(const union sockunion *su)
 {
        int ret;
 
@@ -236,7 +235,7 @@ int sockunion_stream_socket(union sockunion *su)
        sock = socket(su->sa.sa_family, SOCK_STREAM, 0);
 
        if (sock < 0)
-               flog_err(LIB_ERR_SOCKET,
+               flog_err(EC_LIB_SOCKET,
                         "can't make socket sockunion_stream_socket");
 
        return sock;
@@ -275,8 +274,7 @@ int sockunion_bind(int sock, union sockunion *su, unsigned short port,
        ret = bind(sock, (struct sockaddr *)su, size);
        if (ret < 0) {
                char buf[SU_ADDRSTRLEN];
-               flog_err(LIB_ERR_SOCKET,
-                        "can't bind socket for %s : %s",
+               flog_err(EC_LIB_SOCKET, "can't bind socket for %s : %s",
                         sockunion_log(su, buf, SU_ADDRSTRLEN),
                         safe_strerror(errno));
        }
@@ -292,7 +290,7 @@ int sockopt_reuseaddr(int sock)
        ret = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&on,
                         sizeof(on));
        if (ret < 0) {
-               flog_err(LIB_ERR_SOCKET,
+               flog_err(EC_LIB_SOCKET,
                         "can't set sockopt SO_REUSEADDR to socket %d", sock);
                return -1;
        }
@@ -308,7 +306,7 @@ int sockopt_reuseport(int sock)
        ret = setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void *)&on,
                         sizeof(on));
        if (ret < 0) {
-               flog_err(LIB_ERR_SOCKET,
+               flog_err(EC_LIB_SOCKET,
                         "can't set sockopt SO_REUSEPORT to socket %d", sock);
                return -1;
        }
@@ -330,9 +328,9 @@ int sockopt_ttl(int family, int sock, int ttl)
                ret = setsockopt(sock, IPPROTO_IP, IP_TTL, (void *)&ttl,
                                 sizeof(int));
                if (ret < 0) {
-                       flog_err(LIB_ERR_SOCKET,
+                       flog_err(EC_LIB_SOCKET,
                                 "can't set sockopt IP_TTL %d to socket %d",
-                                 ttl, sock);
+                                ttl, sock);
                        return -1;
                }
                return 0;
@@ -342,9 +340,10 @@ int sockopt_ttl(int family, int sock, int ttl)
                ret = setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
                                 (void *)&ttl, sizeof(int));
                if (ret < 0) {
-                       flog_err(LIB_ERR_SOCKET,
-                                "can't set sockopt IPV6_UNICAST_HOPS %d to socket %d",
-                                ttl, sock);
+                       flog_err(
+                               EC_LIB_SOCKET,
+                               "can't set sockopt IPV6_UNICAST_HOPS %d to socket %d",
+                               ttl, sock);
                        return -1;
                }
                return 0;
@@ -357,7 +356,7 @@ int sockopt_ttl(int family, int sock, int ttl)
  * Which on linux is a no-op since it is enabled by
  * default and on BSD it uses TCP_NOPUSH to do
  * the same thing( which it was not configured to
- * use).  This cleanup of the api occured on 8/1/17
+ * use).  This cleanup of the api occurred on 8/1/17
  * I imagine if after more than 1 year of no-one
  * complaining, and a major upgrade release we
  * can deprecate and remove this function call
@@ -367,21 +366,6 @@ int sockopt_cork(int sock, int onoff)
        return 0;
 }
 
-int sockopt_mark_default(int sock, int mark, struct zebra_privs_t *cap)
-{
-#ifdef SO_MARK
-       int ret;
-
-       frr_elevate_privs(cap) {
-               ret = setsockopt(sock, SOL_SOCKET, SO_MARK, &mark,
-                                sizeof(mark));
-       }
-       return ret;
-#else
-       return 0;
-#endif
-}
-
 int sockopt_minttl(int family, int sock, int minttl)
 {
 #ifdef IP_MINTTL
@@ -389,9 +373,10 @@ int sockopt_minttl(int family, int sock, int minttl)
                int ret = setsockopt(sock, IPPROTO_IP, IP_MINTTL, &minttl,
                                     sizeof(minttl));
                if (ret < 0)
-                       flog_err(LIB_ERR_SOCKET,
-                                "can't set sockopt IP_MINTTL to %d on socket %d: %s",
-                                minttl, sock, safe_strerror(errno));
+                       flog_err(
+                               EC_LIB_SOCKET,
+                               "can't set sockopt IP_MINTTL to %d on socket %d: %s",
+                               minttl, sock, safe_strerror(errno));
                return ret;
        }
 #endif /* IP_MINTTL */
@@ -400,9 +385,10 @@ int sockopt_minttl(int family, int sock, int minttl)
                int ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MINHOPCOUNT,
                                     &minttl, sizeof(minttl));
                if (ret < 0)
-                       flog_err(LIB_ERR_SOCKET,
-                                "can't set sockopt IPV6_MINHOPCOUNT to %d on socket %d: %s",
-                                minttl, sock, safe_strerror(errno));
+                       flog_err(
+                               EC_LIB_SOCKET,
+                               "can't set sockopt IPV6_MINHOPCOUNT to %d on socket %d: %s",
+                               minttl, sock, safe_strerror(errno));
                return ret;
        }
 #endif
@@ -420,7 +406,7 @@ int sockopt_v6only(int family, int sock)
                ret = setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on,
                                 sizeof(int));
                if (ret < 0) {
-                       flog_err(LIB_ERR_SOCKET,
+                       flog_err(EC_LIB_SOCKET,
                                 "can't set sockopt IPV6_V6ONLY "
                                 "to socket %d",
                                 sock);
@@ -471,7 +457,7 @@ unsigned int sockunion_hash(const union sockunion *su)
                return jhash_1word(su->sin.sin_addr.s_addr, 0);
        case AF_INET6:
                return jhash2(su->sin6.sin6_addr.s6_addr32,
-                             ZEBRA_NUM_OF(su->sin6.sin6_addr.s6_addr32), 0);
+                             array_size(su->sin6.sin6_addr.s6_addr32), 0);
        }
        return 0;
 }
@@ -538,7 +524,7 @@ union sockunion *sockunion_getsockname(int fd)
 
        ret = getsockname(fd, (struct sockaddr *)&name, &len);
        if (ret < 0) {
-               flog_err(LIB_ERR_SOCKET,
+               flog_err(EC_LIB_SOCKET,
                         "Can't get local address and port by getsockname: %s",
                         safe_strerror(errno));
                return NULL;
@@ -575,8 +561,7 @@ union sockunion *sockunion_getpeername(int fd)
        len = sizeof name;
        ret = getpeername(fd, (struct sockaddr *)&name, &len);
        if (ret < 0) {
-               flog_err(LIB_ERR_SOCKET,
-                        "Can't get remote address and port: %s",
+               flog_err(EC_LIB_SOCKET, "Can't get remote address and port: %s",
                         safe_strerror(errno));
                return NULL;
        }