diff --git a/contrib/tcploop/tcploop.c b/contrib/tcploop/tcploop.c index 7786494ca..0571a6dfd 100644 --- a/contrib/tcploop/tcploop.c +++ b/contrib/tcploop/tcploop.c @@ -50,10 +50,6 @@ #include #include -#ifndef SOL_TCP -#define SOL_TCP IPPROTO_TCP -#endif - #ifndef MSG_MORE #define MSG_MORE 0 #endif @@ -316,7 +312,7 @@ int wait_on_fd(int fd, int events) int tcp_set_nodelay(int sock, const char *arg) { - return setsockopt(sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one)); + return setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); } int tcp_set_nolinger(int sock, const char *arg) @@ -328,7 +324,7 @@ int tcp_set_noquickack(int sock, const char *arg) { #ifdef TCP_QUICKACK /* warning: do not use during connect if nothing is to be sent! */ - return setsockopt(sock, SOL_TCP, TCP_QUICKACK, &zero, sizeof(zero)); + return setsockopt(sock, IPPROTO_TCP, TCP_QUICKACK, &zero, sizeof(zero)); #else return 0; #endif diff --git a/include/haproxy/compat.h b/include/haproxy/compat.h index 0c1d9c9be..39d46c2be 100644 --- a/include/haproxy/compat.h +++ b/include/haproxy/compat.h @@ -215,16 +215,6 @@ typedef struct { } empty_t; #endif #endif -/* FreeBSD doesn't define SOL_IP and prefers IPPROTO_IP */ -#ifndef SOL_IP -#define SOL_IP IPPROTO_IP -#endif - -/* same for SOL_TCP */ -#ifndef SOL_TCP -#define SOL_TCP IPPROTO_TCP -#endif - /* If IPv6 is supported, define IN6_IS_ADDR_V4MAPPED() if missing. */ #if defined(IPV6_TCLASS) && !defined(IN6_IS_ADDR_V4MAPPED) #define IN6_IS_ADDR_V4MAPPED(a) \ diff --git a/src/proto_quic.c b/src/proto_quic.c index c52d7927d..dac7c2389 100644 --- a/src/proto_quic.c +++ b/src/proto_quic.c @@ -406,7 +406,7 @@ int quic_connect_server(struct connection *conn, int flags) else { #ifdef IP_BIND_ADDRESS_NO_PORT static THREAD_LOCAL int bind_address_no_port = 1; - setsockopt(fd, SOL_IP, IP_BIND_ADDRESS_NO_PORT, (const void *) &bind_address_no_port, sizeof(int)); + setsockopt(fd, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, (const void *) &bind_address_no_port, sizeof(int)); #endif ret = quic_bind_socket(fd, flags, &src->source_addr, conn->src); if (ret != 0) diff --git a/src/proto_tcp.c b/src/proto_tcp.c index cef2ff890..1317d3137 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -443,7 +443,7 @@ int tcp_connect_server(struct connection *conn, int flags) else { #ifdef IP_BIND_ADDRESS_NO_PORT static THREAD_LOCAL int bind_address_no_port = 1; - setsockopt(fd, SOL_IP, IP_BIND_ADDRESS_NO_PORT, (const void *) &bind_address_no_port, sizeof(int)); + setsockopt(fd, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, (const void *) &bind_address_no_port, sizeof(int)); #endif ret = tcp_bind_socket(fd, flags, &src->source_addr, conn->src); if (ret != 0) diff --git a/src/sock_inet.c b/src/sock_inet.c index 6adaf184e..ab881d869 100644 --- a/src/sock_inet.c +++ b/src/sock_inet.c @@ -154,7 +154,7 @@ int sock_inet_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir) * other families because v6-mapped IPv4 addresses are still * reported as v4. */ - if (getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, sa, &salen) == 0) + if (getsockopt(fd, IPPROTO_IP, SO_ORIGINAL_DST, sa, &salen) == 0) return 0; #endif return ret; @@ -174,12 +174,12 @@ int sock_inet_is_foreign(int fd, sa_family_t family) case AF_INET: #if defined(IP_TRANSPARENT) val = 0; len = sizeof(val); - if (getsockopt(fd, SOL_IP, IP_TRANSPARENT, &val, &len) == 0 && val) + if (getsockopt(fd, IPPROTO_IP, IP_TRANSPARENT, &val, &len) == 0 && val) return 1; #endif #if defined(IP_FREEBIND) val = 0; len = sizeof(val); - if (getsockopt(fd, SOL_IP, IP_FREEBIND, &val, &len) == 0 && val) + if (getsockopt(fd, IPPROTO_IP, IP_FREEBIND, &val, &len) == 0 && val) return 1; #endif #if defined(IP_BINDANY) @@ -195,14 +195,14 @@ int sock_inet_is_foreign(int fd, sa_family_t family) break; case AF_INET6: -#if defined(IPV6_TRANSPARENT) && defined(SOL_IPV6) +#if defined(IPV6_TRANSPARENT) val = 0; len = sizeof(val); - if (getsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT, &val, &len) == 0 && val) + if (getsockopt(fd, IPPROTO_IPV6, IPV6_TRANSPARENT, &val, &len) == 0 && val) return 1; #endif #if defined(IP_FREEBIND) val = 0; len = sizeof(val); - if (getsockopt(fd, SOL_IP, IP_FREEBIND, &val, &len) == 0 && val) + if (getsockopt(fd, IPPROTO_IP, IP_FREEBIND, &val, &len) == 0 && val) return 1; #endif #if defined(IPV6_BINDANY) @@ -229,10 +229,10 @@ int sock_inet4_make_foreign(int fd) { return #if defined(IP_TRANSPARENT) - setsockopt(fd, SOL_IP, IP_TRANSPARENT, &one, sizeof(one)) == 0 || + setsockopt(fd, IPPROTO_IP, IP_TRANSPARENT, &one, sizeof(one)) == 0 || #endif #if defined(IP_FREEBIND) - setsockopt(fd, SOL_IP, IP_FREEBIND, &one, sizeof(one)) == 0 || + setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) == 0 || #endif #if defined(IP_BINDANY) setsockopt(fd, IPPROTO_IP, IP_BINDANY, &one, sizeof(one)) == 0 || @@ -251,11 +251,11 @@ int sock_inet4_make_foreign(int fd) int sock_inet6_make_foreign(int fd) { return -#if defined(IPV6_TRANSPARENT) && defined(SOL_IPV6) - setsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT, &one, sizeof(one)) == 0 || +#if defined(IPV6_TRANSPARENT) + setsockopt(fd, IPPROTO_IPV6, IPV6_TRANSPARENT, &one, sizeof(one)) == 0 || #endif #if defined(IP_FREEBIND) - setsockopt(fd, SOL_IP, IP_FREEBIND, &one, sizeof(one)) == 0 || + setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) == 0 || #endif #if defined(IPV6_BINDANY) setsockopt(fd, IPPROTO_IPV6, IPV6_BINDANY, &one, sizeof(one)) == 0 || diff --git a/src/tcp_act.c b/src/tcp_act.c index fa0a9898b..46157c102 100644 --- a/src/tcp_act.c +++ b/src/tcp_act.c @@ -182,7 +182,7 @@ static enum act_return tcp_exec_action_silent_drop(struct act_rule *rule, struct /* re-enable quickack if it was disabled to ack all data and avoid * retransmits from the client that might trigger a real reset. */ - setsockopt(conn->handle.fd, SOL_TCP, TCP_QUICKACK, &one, sizeof(one)); + setsockopt(conn->handle.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one)); #endif /* lingering must absolutely be disabled so that we don't send a * shutdown(), this is critical to the TCP_REPAIR trick. When no stream @@ -197,7 +197,7 @@ static enum act_return tcp_exec_action_silent_drop(struct act_rule *rule, struct fdtab[conn->handle.fd].linger_risk = 1; #ifdef TCP_REPAIR - if (setsockopt(conn->handle.fd, SOL_TCP, TCP_REPAIR, &one, sizeof(one)) == 0) { + if (setsockopt(conn->handle.fd, IPPROTO_TCP, TCP_REPAIR, &one, sizeof(one)) == 0) { /* socket will be quiet now */ goto out; } @@ -208,16 +208,11 @@ static enum act_return tcp_exec_action_silent_drop(struct act_rule *rule, struct */ #ifdef IP_TTL if (conn->src && conn->src->ss_family == AF_INET) - setsockopt(conn->handle.fd, SOL_IP, IP_TTL, &one, sizeof(one)); + setsockopt(conn->handle.fd, IPPROTO_IP, IP_TTL, &one, sizeof(one)); #endif #ifdef IPV6_UNICAST_HOPS -#if defined(SOL_IPV6) - if (conn->src && conn->src->ss_family == AF_INET6) - setsockopt(conn->handle.fd, SOL_IPV6, IPV6_UNICAST_HOPS, &one, sizeof(one)); -#elif defined(IPPROTO_IPV6) if (conn->src && conn->src->ss_family == AF_INET6) setsockopt(conn->handle.fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &one, sizeof(one)); -#endif #endif out: /* kill the stream if any */ diff --git a/src/tcp_sample.c b/src/tcp_sample.c index 91a5fb306..06ad6c635 100644 --- a/src/tcp_sample.c +++ b/src/tcp_sample.c @@ -260,7 +260,7 @@ static inline int get_tcp_info(const struct arg *args, struct sample *smp, /* The fd may not be available for the tcp_info struct, and the syscal can fail. */ optlen = sizeof(info); - if (getsockopt(conn->handle.fd, SOL_TCP, TCP_INFO, &info, &optlen) == -1) + if (getsockopt(conn->handle.fd, IPPROTO_TCP, TCP_INFO, &info, &optlen) == -1) return 0; /* extract the value. */