]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
-1 is error
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 Jun 2017 17:34:46 +0000 (13:34 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 Jun 2017 17:34:59 +0000 (13:34 -0400)
src/lib/util/inet.c
src/lib/util/socket.c
src/lib/util/udp.c
src/main/listen.c
src/protocols/radius/list.c

index b3e524f5e6069c9ce5c1a2a28956c0aad0124508..b4c76da7cab1caeb519fa933c133b827f375062c 100644 (file)
@@ -240,7 +240,7 @@ int fr_inet_hton(fr_ipaddr_t *out, int af, char const *hostname, bool fallback)
 
        rcode = fr_ipaddr_from_sockaddr((struct sockaddr_storage *)ai->ai_addr, ai->ai_addrlen, out, NULL);
        freeaddrinfo(res);
-       if (!rcode) {
+       if (rcode < 0) {
                fr_strerror_printf("Failed converting sockaddr to ipaddr");
                return -1;
        }
@@ -269,9 +269,7 @@ char const *fr_inet_ntoh(fr_ipaddr_t const *src, char *out, size_t outlen)
                return inet_ntop(src->af, &(src->addr), out, outlen);
        }
 
-       if (!fr_ipaddr_to_sockaddr(src, 0, &ss, &salen)) {
-               return NULL;
-       }
+       if (fr_ipaddr_to_sockaddr(src, 0, &ss, &salen) < 0) return NULL;
 
        if ((error = getnameinfo((struct sockaddr *)&ss, salen, out, outlen, NULL, 0,
                                 NI_NUMERICHOST | NI_NUMERICSERV)) != 0) {
@@ -944,7 +942,7 @@ int fr_ipaddr_from_ifname(fr_ipaddr_t *out, int af, char const *name)
         *      be OK.
         */
        if (fr_ipaddr_from_sockaddr((struct sockaddr_storage *)&if_req.ifr_addr,
-                              sizeof(if_req.ifr_addr), &ipaddr, NULL) == 0) goto error;
+                                   sizeof(if_req.ifr_addr), &ipaddr, NULL) < 0) goto error;
        *out = ipaddr;
 
        close(fd);
@@ -1071,7 +1069,7 @@ int fr_ipaddr_from_ifindex(fr_ipaddr_t *out, int fd, int af, int if_index)
         *      be OK.
         */
        if (fr_ipaddr_from_sockaddr((struct sockaddr_storage *)&if_req.ifr_addr,
-                                   sizeof(if_req.ifr_addr), &ipaddr, NULL) == 0) return -1;
+                                   sizeof(if_req.ifr_addr), &ipaddr, NULL) < 0) return -1;
        *out = ipaddr;
 
        return 0;
@@ -1144,10 +1142,11 @@ int fr_ipaddr_to_sockaddr(fr_ipaddr_t const *ipaddr, uint16_t port,
                memcpy(sa, &s6, sizeof(s6));
 #endif
        } else {
-               return 0;
+               fr_strerror_printf("Unsupported address famility %d", ipaddr->af);
+               return -1;
        }
 
-       return 1;
+       return 0;
 }
 
 int fr_ipaddr_from_sockaddr(struct sockaddr_storage const *sa, socklen_t salen,
@@ -1189,8 +1188,8 @@ int fr_ipaddr_from_sockaddr(struct sockaddr_storage const *sa, socklen_t salen,
 
        } else {
                fr_strerror_printf("Unsupported address famility %d", sa->ss_family);
-               return 0;
+               return -1;
        }
 
-       return 1;
+       return 0;
 }
index a76bd3d207229ca9e889f19a4bd1675130b28b5e..2c2e717fbbd030d49eb99ff043616d6be534905a 100644 (file)
@@ -392,7 +392,7 @@ int fr_socket_client_udp(fr_ipaddr_t const *src_ipaddr, fr_ipaddr_t const *dst_i
         *      Allow the caller to bind us to a specific source IP.
         */
        if (src_ipaddr && (src_ipaddr->af != AF_UNSPEC)) {
-               if (!fr_ipaddr_to_sockaddr(src_ipaddr, 0, &salocal, &salen)) {
+               if (fr_ipaddr_to_sockaddr(src_ipaddr, 0, &salocal, &salen) < 0) {
                        close(sockfd);
                        return -1;
                }
@@ -404,7 +404,7 @@ int fr_socket_client_udp(fr_ipaddr_t const *src_ipaddr, fr_ipaddr_t const *dst_i
                }
        }
 
-       if (!fr_ipaddr_to_sockaddr(dst_ipaddr, dst_port, &salocal, &salen)) {
+       if (fr_ipaddr_to_sockaddr(dst_ipaddr, dst_port, &salocal, &salen) < 0) {
                close(sockfd);
                return -1;
        }
@@ -495,7 +495,7 @@ int fr_socket_client_tcp(fr_ipaddr_t const *src_ipaddr, fr_ipaddr_t const *dst_i
         *      Allow the caller to bind us to a specific source IP.
         */
        if (src_ipaddr && (src_ipaddr->af != AF_UNSPEC)) {
-               if (!fr_ipaddr_to_sockaddr(src_ipaddr, 0, &salocal, &salen)) {
+               if (fr_ipaddr_to_sockaddr(src_ipaddr, 0, &salocal, &salen) < 0) {
                        close(sockfd);
                        return -1;
                }
@@ -507,7 +507,7 @@ int fr_socket_client_tcp(fr_ipaddr_t const *src_ipaddr, fr_ipaddr_t const *dst_i
                }
        }
 
-       if (!fr_ipaddr_to_sockaddr(dst_ipaddr, dst_port, &salocal, &salen)) {
+       if (fr_ipaddr_to_sockaddr(dst_ipaddr, dst_port, &salocal, &salen) < 0) {
                close(sockfd);
                return -1;
        }
@@ -880,7 +880,7 @@ int fr_socket_bind(int sockfd, fr_ipaddr_t const *src_ipaddr, uint16_t *src_port
        /*
         *      Set up sockaddr stuff.
         */
-       if (!fr_ipaddr_to_sockaddr(&my_ipaddr, my_port, &salocal, &salen)) return -1;
+       if (fr_ipaddr_to_sockaddr(&my_ipaddr, my_port, &salocal, &salen) < 0) return -1;
 
        rcode = bind(sockfd, (struct sockaddr *) &salocal, salen);
        if (rcode < 0) return rcode;
@@ -897,7 +897,7 @@ int fr_socket_bind(int sockfd, fr_ipaddr_t const *src_ipaddr, uint16_t *src_port
                return -1;
        }
 
-       if (!fr_ipaddr_from_sockaddr(&salocal, salen, &my_ipaddr, &my_port)) return -1;
+       if (fr_ipaddr_from_sockaddr(&salocal, salen, &my_ipaddr, &my_port) < 0) return -1;
        if (src_port) *src_port = my_port;
 
        return 0;
index 461b67b49c787735f8c0cedc2b99035fd07ddbfe..f0777e46c57f80418cef827d82db9c70b8b335c5 100644 (file)
@@ -67,9 +67,7 @@ ssize_t udp_send(int sockfd, void *data, size_t data_len, int flags,
                 *      @fixme: We shoul probably just move to sockaddr_storage for
                 *      all IP address things.
                 */
-               if (!fr_ipaddr_to_sockaddr(dst_ipaddr, dst_port, &dst, &sizeof_dst)) {
-                       return -1;
-               }
+               if (fr_ipaddr_to_sockaddr(dst_ipaddr, dst_port, &dst, &sizeof_dst) < 0) return -1;
 
 #ifdef WITH_UDPFROMTO
                /*
@@ -147,7 +145,7 @@ ssize_t udp_recv_peek(int sockfd, void *data, size_t data_len, int flags, fr_ipa
        /*
         *      Convert AF.  If unknown, discard packet.
         */
-       if (!fr_ipaddr_from_sockaddr(&src, sizeof_src, src_ipaddr, src_port)) {
+       if (fr_ipaddr_from_sockaddr(&src, sizeof_src, src_ipaddr, src_port) < 0) {
                FR_DEBUG_STRERROR_PRINTF("Unknown address family");
                (void) udp_recv_discard(sockfd);
 
@@ -227,7 +225,7 @@ ssize_t udp_recv(int sockfd, void *data, size_t data_len, int flags,
 
        if (received < 0) return received;
 
-       if (!fr_ipaddr_from_sockaddr(&src, sizeof_src, src_ipaddr, &port)) return -1;
+       if (fr_ipaddr_from_sockaddr(&src, sizeof_src, src_ipaddr, &port) < 0) return -1;
        *src_port = port;
 
        if (when && !when->tv_sec) gettimeofday(when, NULL);
index ebab841e229c5983bfa84cfe59983907c8447a63..6d5a5d77473c786dc734df4ccddc650768cf787e 100644 (file)
@@ -880,7 +880,7 @@ static int dual_tcp_accept(rad_listen_t *listener)
                return -1;
        }
 
-       if (!fr_ipaddr_from_sockaddr(&src, salen, &src_ipaddr, &src_port)) {
+       if (fr_ipaddr_from_sockaddr(&src, salen, &src_ipaddr, &src_port) < 0) {
                close(newfd);
                DEBUG2(" ... unknown address family");
                return 0;
@@ -3062,8 +3062,7 @@ rad_listen_t *proxy_new_listener(TALLOC_CTX *ctx, home_server_t *home, uint16_t
                        return NULL;
                }
 
-               if (!fr_ipaddr_from_sockaddr(&src, sizeof_src,
-                                       &sock->my_ipaddr, &sock->my_port)) {
+               if (fr_ipaddr_from_sockaddr(&src, sizeof_src, &sock->my_ipaddr, &sock->my_port) < 0) {
                        ERROR("Socket has unsupported address family for '%s'", buffer);
                        home->last_failed_open = now;
                        listen_free(&this);
index f0dbcb4e3c3cb4cab11d7566890a6eef79df1f2b..48c38d42f2d2668b631f33269ad66fe5fa44b3ab 100644 (file)
@@ -280,8 +280,7 @@ bool fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd, int proto,
                return false;
        }
 
-       if (!fr_ipaddr_from_sockaddr(&src, sizeof_src, &ps->src_ipaddr,
-                               &ps->src_port)) {
+       if (fr_ipaddr_from_sockaddr(&src, sizeof_src, &ps->src_ipaddr, &ps->src_port) < 0) {
                fr_strerror_printf("Failed to get IP");
                return false;
        }