socket.c error 'SO_REUSEPORT' undeclared
Hello developer of bind.
Sorry about poor my english.
I have a issue about building bind-9.14.1 with linux-2.6.34.13.
$ ./configure --with-openssl=/usr/local/ssl --disable-linux-caps && make
... snip ...
socket.c: In function 'isc_socket_bind':
socket.c:4480:40: error: 'SO_REUSEPORT' undeclared (first use in this function)
socket.c:4480:40: note: each undeclared identifier is reported only once for each function it appears in
make[3]: *** [socket.o] Error 1
make[3]: Leaving directory `/home/m-ito/tmp/bind-9.14.1/lib/isc/unix'
make[2]: *** [subdirs] Error 1
make[2]: Leaving directory `/home/m-ito/tmp/bind-9.14.1/lib/isc'
make[1]: *** [subdirs] Error 1
make[1]: Leaving directory `/home/m-ito/tmp/bind-9.14.1/lib'
make: *** [subdirs] Error 1
I searched `SO_REUSEPORT' in my system, but it has been comment-outed.
$ egrep -r SO_REUSEPORT /usr/include/
/usr/include/asm/socket.h:/* To add :#define SO_REUSEPORT 15 */
/usr/include/asm-i386/socket.h:/* To add :#define SO_REUSEPORT 15 */
I understand SO_REUSEPORT is implemented in linux-3.9 or later.
In bind-9.14.1/lib/isc/unix/socket.c, next code is controled to ignore in environment SO_REUSEPORT is not defined.
5335 #if defined(SO_REUSEPORT) && defined(__linux__)
5336 int sock, yes = 1;
5337 sock = socket(AF_INET, SOCK_DGRAM, 0);
5338 if (sock < 0) {
5339 sock = socket(AF_INET6, SOCK_DGRAM, 0);
5340 if (sock < 0) {
5341 return;
5342 }
5343 }
5344 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
5345 (void *)&yes, sizeof(yes)) < 0)
5346 {
5347 close(sock);
5348 return;
5349 } else if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT,
5350 (void *)&yes, sizeof(yes)) < 0)
5351 {
5352 close(sock);
5353 return;
5354 }
5355 hasreuseport = true;
5356 close(sock);
5357 #endif
But next code is not controled at all.
I guess next code should be ignore too in environment SO_REUSEPORT is not defined.
4480 if (setsockopt(sock->fd, SOL_SOCKET, SO_REUSEPORT,
4481 (void *)&on, sizeof(on)) < 0)
4482 {
4483 UNEXPECTED_ERROR(__FILE__, __LINE__,
4484 "setsockopt(%d) failed", sock->fd);
4485 }
I tried to edit simply like below and built it.
#if defined(SO_REUSEPORT) && defined(__linux__)
4480 if (setsockopt(sock->fd, SOL_SOCKET, SO_REUSEPORT,
4481 (void *)&on, sizeof(on)) < 0)
4482 {
4483 UNEXPECTED_ERROR(__FILE__, __LINE__,
4484 "setsockopt(%d) failed", sock->fd);
4485 }
#endif
But it become not to responce after about few hours from invoke it.
I strongly hope to fix this issue in next version of bind.
Thank you.