CLEANUP: socket: replace SOL_IP/IPV6/TCP with IPPROTO_IP/IPV6/TCP

Historically we've used SOL_IP/SOL_IPV6/SOL_TCP everywhere as the socket
level value in getsockopt() and setsockopt() but as we've seen over time
it regularly broke the build and required to have them defined to their
IPPROTO_* equivalent. The Linux ip(7) man page says:

   Using the SOL_IP socket options level isn't portable; BSD-based
   stacks use the IPPROTO_IP level.

And it indeed looks like a pure linuxism inherited from old examples and
documentation. strace also reports SOL_* instead of IPPROTO_*, which does
not help... A check to linux/in.h shows they have the same values. Only
SOL_SOCKET and other non-IP values make sense since there is no IPPROTO
equivalent.

Let's get rid of this annoying confusion by removing all redefinitions of
SOL_IP/IPV6/TCP and using IPPROTO_* instead, just like any other operating
system. This also removes duplicated tests for the same value.

Note that this should not result in exposing syscalls to other OSes
as the only ones that were still conditionned to SOL_IPV6 were for
IPV6_UNICAST_HOPS which already had an IPPROTO_IPV6 equivalent, and
IPV6_TRANSPARENT which is Linux-specific.
diff --git a/contrib/tcploop/tcploop.c b/contrib/tcploop/tcploop.c
index 7786494..0571a6d 100644
--- a/contrib/tcploop/tcploop.c
+++ b/contrib/tcploop/tcploop.c
@@ -50,10 +50,6 @@
 #include <time.h>
 #include <unistd.h>
 
-#ifndef SOL_TCP
-#define SOL_TCP IPPROTO_TCP
-#endif
-
 #ifndef MSG_MORE
 #define MSG_MORE 0
 #endif
@@ -316,7 +312,7 @@
 
 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 @@
 {
 #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 0c1d9c9..39d46c2 100644
--- a/include/haproxy/compat.h
+++ b/include/haproxy/compat.h
@@ -215,16 +215,6 @@
 #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 c52d792..dac7c23 100644
--- a/src/proto_quic.c
+++ b/src/proto_quic.c
@@ -406,7 +406,7 @@
 		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 cef2ff8..1317d31 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -443,7 +443,7 @@
 		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 6adaf18..ab881d8 100644
--- a/src/sock_inet.c
+++ b/src/sock_inet.c
@@ -154,7 +154,7 @@
 		 * 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 @@
 	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 @@
 		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 @@
 {
 	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_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 fa0a989..46157c1 100644
--- a/src/tcp_act.c
+++ b/src/tcp_act.c
@@ -182,7 +182,7 @@
 	/* 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 @@
 	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,17 +208,12 @@
 	 */
 #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 */
 	if (strm) {
diff --git a/src/tcp_sample.c b/src/tcp_sample.c
index 91a5fb3..06ad6c6 100644
--- a/src/tcp_sample.c
+++ b/src/tcp_sample.c
@@ -260,7 +260,7 @@
 	/* 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. */