]> git.ipfire.org Git - thirdparty/squid.git/blob - acinclude/os-deps.m4
Source Format Enforcement (#763)
[thirdparty/squid.git] / acinclude / os-deps.m4
1 ## Copyright (C) 1996-2021 The Squid Software Foundation and contributors
2 ##
3 ## Squid software is distributed under GPLv2+ license and includes
4 ## contributions from numerous individuals and organizations.
5 ## Please see the COPYING and CONTRIBUTORS files for details.
6 ##
7
8 dnl check that strnstr() works fine. On Macos X it can cause a buffer overrun
9 dnl sets squid_cv_func_strnstr to "yes" or "no", and defines HAVE_STRNSTR
10 AC_DEFUN([SQUID_CHECK_FUNC_STRNSTR],[
11
12 # Yay! This one is a MacOSX brokenness. Its not good enough
13 # to know that strnstr() exists, because MacOSX 10.4 have a bad
14 # copy that crashes with a buffer over-run!
15 AH_TEMPLATE(HAVE_STRNSTR,[MacOS brokenness: strnstr() can overrun on that system])
16 AC_CACHE_CHECK([if strnstr is well implemented], squid_cv_func_strnstr,
17 AC_RUN_IFELSE([AC_LANG_SOURCE([[
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 // we expect this to succeed, or crash on over-run.
22 // if it passes otherwise we may need a better check.
23 int main(int argc, char **argv)
24 {
25 int size = 20;
26 char *str = malloc(size);
27 memset(str, 'x', size);
28 strnstr(str, "fubar", size);
29 return 0;
30 }
31 ]])],[squid_cv_func_strnstr="yes"],[squid_cv_func_strnstr="no"],[:])
32 )
33 if test "$squid_cv_func_strnstr" = "yes" ; then
34 AC_DEFINE(HAVE_STRNSTR,1)
35 fi
36
37 ]) dnl SQUID_CHECK_FUNC_STRNSTR
38
39 dnl check that epoll actually works
40 dnl sets squid_cv_epoll_works to "yes" or "no"
41 AC_DEFUN([SQUID_CHECK_EPOLL],[
42
43 AC_CACHE_CHECK(if epoll works, squid_cv_epoll_works,
44 AC_RUN_IFELSE([AC_LANG_SOURCE([[
45 #include <sys/epoll.h>
46 #include <stdlib.h>
47 #include <stdio.h>
48 int main(int argc, char **argv)
49 {
50 int fd = epoll_create(256);
51 if (fd < 0) {
52 perror("epoll_create:");
53 return 1;
54 }
55 return 0;
56 }
57 ]])],[squid_cv_epoll_works=yes],[squid_cv_epoll_works=no],[:]))
58
59 ]) dnl SQUID_CHECK_EPOLL
60
61 dnl check that /dev/poll actually works
62 dnl sets squid_cv_devpoll_works to "yes" or "no"
63 AC_DEFUN([SQUID_CHECK_DEVPOLL],[
64
65 AC_CACHE_CHECK(if /dev/poll works, squid_cv_devpoll_works,
66 AC_RUN_IFELSE([AC_LANG_SOURCE([[
67 #include <sys/devpoll.h>
68 #include <fcntl.h>
69 #include <stdlib.h>
70 #include <stdio.h>
71 int main(int argc, char **argv)
72 {
73 int fd = open("/dev/poll", O_RDWR);
74 if (fd < 0) {
75 perror("devpoll_create:");
76 return 1;
77 }
78 return 0;
79 }
80 ]])],[squid_cv_devpoll_works=yes],[squid_cv_devpoll_works=no],[:]))
81
82 ]) dnl SQUID_CHECK_DEVPOLL
83
84
85 dnl check that we have functional libcap2 headers
86 dnl sets squid_cv_sys_capability_works to "yes" or "no"
87
88 AC_DEFUN([SQUID_CHECK_FUNCTIONAL_LIBCAP2],[
89 AC_CACHE_CHECK([for operational libcap2 headers],
90 squid_cv_sys_capability_works,
91 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
92 #include <stdlib.h>
93 #include <stddef.h>
94 #include <sys/capability.h>
95 ]], [[
96 capget(NULL, NULL);
97 capset(NULL, NULL);
98 ]])],
99 [squid_cv_sys_capability_works=yes],
100 [squid_cv_sys_capability_works=no])
101 )
102 ])
103
104
105 dnl From Samba. Thanks!
106 dnl check that we have Unix sockets. Sets squid_cv_unixsocket to either yes or no depending on the check
107
108 AC_DEFUN([SQUID_CHECK_UNIX_SOCKET],[
109 AC_CACHE_CHECK([for unix domain sockets],squid_cv_unixsocket, [
110 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
111 #include <sys/types.h>
112 #include <stdlib.h>
113 #include <stddef.h>
114 #include <sys/socket.h>
115 #include <sys/un.h>]], [[
116 struct sockaddr_un sunaddr;
117 sunaddr.sun_family = AF_UNIX;
118 ]])],[squid_cv_unixsocket=yes],[squid_cv_unixsocket=no])])
119 ])
120
121
122 dnl check the default FD_SETSIZE size.
123 dnl not cached, people are likely to tune this
124 dnl defines DEFAULT_FD_SETSIZE
125
126 AC_DEFUN([SQUID_CHECK_DEFAULT_FD_SETSIZE],[
127 AC_MSG_CHECKING(Default FD_SETSIZE value)
128 AC_RUN_IFELSE([AC_LANG_SOURCE([[
129 #if HAVE_STDIO_H
130 #include <stdio.h>
131 #endif
132 #if HAVE_UNISTD_H
133 #include <unistd.h>
134 #endif
135 #if HAVE_STDLIB_H
136 #include <stdlib.h>
137 #endif
138 #if HAVE_SYS_TIME_H
139 #include <sys/time.h>
140 #endif
141 #if HAVE_SYS_SELECT_H
142 #include <sys/select.h>
143 #endif
144 #if HAVE_SYS_TYPES_H
145 #include <sys/types.h>
146 #endif
147 #if HAVE_WINSOCK2_H
148 #include <winsock2.h>
149 #elif HAVE_WINSOCK_H
150 #include <winsock.h>
151 #endif
152 int main(int argc, char **argv) {
153 FILE *fp = fopen("conftestval", "w");
154 fprintf (fp, "%d\n", FD_SETSIZE);
155 return 0;
156 }
157 ]])],[DEFAULT_FD_SETSIZE=`cat conftestval`],[DEFAULT_FD_SETSIZE=256],[DEFAULT_FD_SETSIZE=256])
158 AC_MSG_RESULT($DEFAULT_FD_SETSIZE)
159 AC_DEFINE_UNQUOTED(DEFAULT_FD_SETSIZE, $DEFAULT_FD_SETSIZE, [Default FD_SETSIZE value])
160 ])
161
162
163 dnl checks the maximum number of filedescriptor we can open
164 dnl sets shell var squid_filedescriptors_num
165
166 AC_DEFUN([SQUID_CHECK_MAXFD],[
167 AC_CHECK_FUNCS(getrlimit setrlimit)
168 AC_MSG_CHECKING(Maximum number of filedescriptors we can open)
169 SQUID_STATE_SAVE(maxfd)
170 dnl FreeBSD pthreads break dup2().
171 AS_CASE([$host_os],[freebsd],[ LDFLAGS=`echo $LDFLAGS | sed -e "s/-pthread//"` ])
172 AC_RUN_IFELSE([AC_LANG_SOURCE([[
173 #include <stdio.h>
174 #include <unistd.h>
175 #include <stdlib.h>
176 #include <sys/time.h> /* needed on FreeBSD */
177 #include <sys/param.h>
178 #include <sys/resource.h>
179 int main(int argc, char **argv) {
180 FILE *fp;
181 int i,j;
182 #if defined(__CYGWIN32__) || defined (__CYGWIN__)
183 /* getrlimit and sysconf returns bogous values on cygwin32.
184 * Number of fds is virtually unlimited in cygwin (sys/param.h)
185 * __CYGWIN32__ is deprecated.
186 */
187 i = NOFILE;
188 #else
189 #if HAVE_GETRLIMIT && HAVE_SETRLIMIT
190 struct rlimit rl;
191 #if defined(RLIMIT_NOFILE)
192 if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
193 perror("getrlimit: RLIMIT_NOFILE");
194 } else {
195 #if defined(__APPLE__)
196 /* asking for more than OPEN_MAX fails on Leopard */
197 rl.rlim_cur = (OPEN_MAX < rl.rlim_max ? OPEN_MAX : rl.rlim_max);
198 #else
199 rl.rlim_cur = rl.rlim_max; /* set it to the max */
200 #endif
201 if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
202 perror("setrlimit: RLIMIT_NOFILE");
203 }
204 }
205 #elif defined(RLIMIT_OFILE)
206 if (getrlimit(RLIMIT_OFILE, &rl) < 0) {
207 perror("getrlimit: RLIMIT_OFILE");
208 } else {
209 rl.rlim_cur = rl.rlim_max; /* set it to the max */
210 if (setrlimit(RLIMIT_OFILE, &rl) < 0) {
211 perror("setrlimit: RLIMIT_OFILE");
212 }
213 }
214 #endif /* RLIMIT_NOFILE */
215 #endif /* HAVE_SETRLIMIT */
216 /* by starting at 2^14, we will never get higher
217 than 2^15 for squid_filedescriptors_num */
218 i = j = 1<<14;
219 while (j) {
220 j >>= 1;
221 if (dup2(0, i) < 0) {
222 i -= j;
223 } else {
224 close(i);
225 i += j;
226 }
227 }
228 i++;
229 #endif /* IF !DEF CYGWIN */
230 fp = fopen("conftestval", "w");
231 fprintf (fp, "%d\n", i & ~0x3F);
232 return 0;
233 }
234 ]])],[squid_filedescriptors_limit=`cat conftestval`],[],[:])
235 dnl Microsoft MSVCRT.DLL supports 2048 maximum FDs
236 AS_CASE(["$host_os"],[mingw|mingw32],[squid_filedescriptors_limit="2048"])
237 AC_MSG_RESULT($squid_filedescriptors_limit)
238 AS_IF([ test "x$squid_filedescriptors_num" = "x" ],[
239 AS_IF([ test "x$squid_filedescriptors_limit" != "x" ],[
240 squid_filedescriptors_num=$squid_filedescriptors_limit
241 ],[
242 AC_MSG_NOTICE([Unable to detect filedescriptor limits. Assuming 256 is okay.])
243 squid_filedescriptors_num=256
244 ])
245 ])
246 SQUID_STATE_ROLLBACK(maxfd)
247
248 AC_MSG_NOTICE([Default number of filedescriptors: $squid_filedescriptors_num])
249
250 AS_IF([ test `expr $squid_filedescriptors_num % 64` != 0 ],[
251 AC_MSG_WARN([$squid_filedescriptors_num is not an multiple of 64. This may cause issues on certain platforms.])
252 ])
253
254 AS_IF([ test "$squid_filedescriptors_num" -lt 512 ],[
255 AC_MSG_WARN([$squid_filedescriptors_num may not be enough filedescriptors if your])
256 AC_MSG_WARN([cache will be very busy. Please see the FAQ page])
257 AC_MSG_WARN([http://wiki.squid-cache.org/SquidFaq/TroubleShooting])
258 AC_MSG_WARN([on how to increase your filedescriptor limit])
259 ])
260 AC_DEFINE_UNQUOTED(SQUID_MAXFD,$squid_filedescriptors_num,[Maximum number of open filedescriptors])
261 ])
262
263
264 dnl Check whether this OS defines sin6_len as a member of sockaddr_in6 as a backup to ss_len
265 dnl defines HAVE_SIN6_LEN_IN_SAI
266 dnl TODO: move to AC_CHECK_MEMBER?
267
268 AC_DEFUN([SQUID_CHECK_SIN6_LEN_IN_SAI],[
269 AC_CACHE_CHECK([for sin6_len field in struct sockaddr_in6],
270 ac_cv_have_sin6_len_in_struct_sai, [
271 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
272 #include <sys/types.h>
273 #include <sys/socket.h>
274 #include <netinet/in.h>
275 ]], [[ struct sockaddr_in6 s; s.sin6_len = 1; ]])],[ ac_cv_have_sin6_len_in_struct_sai="yes" ],[ ac_cv_have_sin6_len_in_struct_sai="no"
276 ])
277 ])
278 SQUID_DEFINE_BOOL(HAVE_SIN6_LEN_IN_SAI,$ac_cv_have_sin6_len_in_struct_sai,
279 [Defined if struct sockaddr_in6 has sin6_len])
280 ])
281
282
283 dnl Check whether this OS defines ss_len as a member of sockaddr_storage
284 dnl defines HAVE_SS_LEN_IN_SS
285 dnl TODO: move to AC_CHECK_MEMBER?
286
287 AC_DEFUN([SQUID_CHECK_SS_LEN_IN_SOCKADDR_STORAGE],[
288 AC_CACHE_CHECK([for ss_len field in struct sockaddr_storage],
289 ac_cv_have_ss_len_in_struct_ss, [
290 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
291 #include <sys/types.h>
292 #include <sys/socket.h>
293 #include <netinet/in.h>
294 ]], [[ struct sockaddr_storage s; s.ss_len = 1; ]])],[ ac_cv_have_ss_len_in_struct_ss="yes" ],[ ac_cv_have_ss_len_in_struct_ss="no"
295 ])
296 ])
297 SQUID_DEFINE_BOOL(HAVE_SS_LEN_IN_SS,$ac_cv_have_ss_len_in_struct_ss,
298 [Define if sockaddr_storage has field ss_len])
299 ])
300
301
302 dnl Check whether this OS defines sin_len as a member of sockaddr_in as a backup to ss_len
303 dnl defines HAVE_SIN_LEN_IN_SAI
304 dnl TODO: move to AC_CHECK_MEMBER?
305
306 AC_DEFUN([SQUID_CHECK_SIN_LEN_IN_SOCKADDR_IN],[
307 AC_CACHE_CHECK([for sin_len field in struct sockaddr_in],
308 ac_cv_have_sin_len_in_struct_sai, [
309 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
310 #include <sys/types.h>
311 #include <sys/socket.h>
312 #include <netinet/in.h>
313 ]], [[ struct sockaddr_in s; s.sin_len = 1; ]])],[ ac_cv_have_sin_len_in_struct_sai="yes" ],[ ac_cv_have_sin_len_in_struct_sai="no"
314 ])
315 ])
316 SQUID_DEFINE_BOOL(HAVE_SIN_LEN_IN_SAI,$ac_cv_have_sin_len_in_struct_sai,[Define if sockaddr_in has field sin_len])
317 ])
318
319
320 dnl detects default UDP buffer size
321 dnl not cached since people are likely to tune this
322 dnl defines SQUID_DETECT_UDP_SO_SNDBUF
323
324 AC_DEFUN([SQUID_DETECT_UDP_SND_BUFSIZE],[
325 AC_MSG_CHECKING(Default UDP send buffer size)
326 AC_RUN_IFELSE([AC_LANG_SOURCE([[
327 #include <stdlib.h>
328 #include <stdio.h>
329 #include <sys/types.h>
330 #if HAVE_SYS_SOCKET_H
331 #include <sys/socket.h>
332 #endif
333 #if HAVE_NETINET_IN_H
334 #include <netinet/in.h>
335 #endif
336 #if HAVE_WINSOCK2_H
337 #include <winsock2.h>
338 #elif HAVE_WINSOCK_H
339 #include <winsock.h>
340 #endif
341 int main(int argc, char **argv)
342 {
343 FILE *fp;
344 int fd,val=0;
345 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
346 int len=sizeof(int);
347 WSADATA wsaData;
348 WSAStartup(2, &wsaData);
349 #else
350 socklen_t len=sizeof(socklen_t);
351 #endif
352 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return 1;
353 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
354 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&val, &len) < 0) return 1;
355 WSACleanup();
356 #else
357 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) return 1;
358 #endif
359 if (val<=0) return 1;
360 fp = fopen("conftestval", "w");
361 fprintf (fp, "%d\n", val);
362 return 0;
363 }
364 ]])],[SQUID_DETECT_UDP_SO_SNDBUF=`cat conftestval`],[SQUID_DETECT_UDP_SO_SNDBUF=16384],[SQUID_DETECT_UDP_SO_SNDBUF=16384])
365 AC_MSG_RESULT($SQUID_DETECT_UDP_SO_SNDBUF)
366 AC_DEFINE_UNQUOTED(SQUID_DETECT_UDP_SO_SNDBUF, $SQUID_DETECT_UDP_SO_SNDBUF,[UDP send buffer size])
367 ])
368
369
370 dnl detects default UDP buffer size
371 dnl not cached since people are likely to tune this
372 dnl defines SQUID_DETECT_UDP_SO_RCVBUF
373
374 AC_DEFUN([SQUID_DETECT_UDP_RECV_BUFSIZE],[
375 AC_MSG_CHECKING(Default UDP receive buffer size)
376 AC_RUN_IFELSE([AC_LANG_SOURCE([[
377 #include <stdlib.h>
378 #include <stdio.h>
379 #include <sys/types.h>
380 #if HAVE_SYS_SOCKET_H
381 #include <sys/socket.h>
382 #endif
383 #if HAVE_NETINET_IN_H
384 #include <netinet/in.h>
385 #endif
386 #if HAVE_WINSOCK2_H
387 #include <winsock2.h>
388 #elif HAVE_WINSOCK_H
389 #include <winsock.h>
390 #endif
391 int main(int argc, char **argv)
392 {
393 FILE *fp;
394 int fd,val=0;
395 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
396 int len=sizeof(int);
397 WSADATA wsaData;
398 WSAStartup(2, &wsaData);
399 #else
400 socklen_t len=sizeof(socklen_t);
401 #endif
402 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return 1;
403 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
404 if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&val, &len) < 0) return 1;
405 WSACleanup();
406 #else
407 if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) return 1;
408 #endif
409 if (val <= 0) return 1;
410 fp = fopen("conftestval", "w");
411 fprintf (fp, "%d\n", val);
412 return 0;
413 }
414 ]])],[SQUID_DETECT_UDP_SO_RCVBUF=`cat conftestval`],[SQUID_DETECT_UDP_SO_RCVBUF=16384],[SQUID_DETECT_UDP_SO_RCVBUF=16384])
415 AC_MSG_RESULT($SQUID_DETECT_UDP_SO_RCVBUF)
416 AC_DEFINE_UNQUOTED(SQUID_DETECT_UDP_SO_RCVBUF, $SQUID_DETECT_UDP_SO_RCVBUF,[UDP receive buffer size])
417 ])
418
419
420 dnl detects default TCP buffer size
421 dnl not cached since people are likely to tune this
422 dnl defines SQUID_TCP_SO_SNDBUF
423
424 AC_DEFUN([SQUID_DETECT_TCP_SND_BUFSIZE],[
425 AC_MSG_CHECKING(Default TCP send buffer size)
426 AC_RUN_IFELSE([AC_LANG_SOURCE([[
427 #include <stdlib.h>
428 #include <stdio.h>
429 #include <sys/types.h>
430 #if HAVE_SYS_SOCKET_H
431 #include <sys/socket.h>
432 #endif
433 #if HAVE_NETINET_IN_H
434 #include <netinet/in.h>
435 #endif
436 #if HAVE_WINSOCK2_H
437 #include <winsock2.h>
438 #elif HAVE_WINSOCK_H
439 #include <winsock.h>
440 #endif
441 int main(int argc, char **argv)
442 {
443 FILE *fp;
444 int fd,val=0;
445 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
446 int len=sizeof(int);
447 WSADATA wsaData;
448 WSAStartup(2, &wsaData);
449 #else
450 socklen_t len=sizeof(socklen_t);
451 #endif
452 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return 1;
453 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
454 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&val, &len) < 0) return 1;
455 WSACleanup();
456 #else
457 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) return 1;
458 #endif
459 if (val <= 0) return 1;
460 fp = fopen("conftestval", "w");
461 fprintf (fp, "%d\n", val);
462 return 0;
463 }
464 ]])],[SQUID_TCP_SO_SNDBUF=`cat conftestval`],[SQUID_TCP_SO_SNDBUF=16384],[SQUID_TCP_SO_SNDBUF=16384])
465 AC_MSG_RESULT($SQUID_TCP_SO_SNDBUF)
466 if test $SQUID_TCP_SO_SNDBUF -gt 32768; then
467 AC_MSG_NOTICE([Limiting send buffer size to 32K])
468 SQUID_TCP_SO_SNDBUF=32768
469 fi
470 AC_DEFINE_UNQUOTED(SQUID_TCP_SO_SNDBUF, $SQUID_TCP_SO_SNDBUF,[TCP send buffer size])
471 ])
472
473
474 dnl detects default TCP buffer size
475 dnl not cached since people are likely to tune this
476 dnl defines SQUID_TCP_SO_RECVBUF
477
478 AC_DEFUN([SQUID_DETECT_TCP_RECV_BUFSIZE],[
479 AC_MSG_CHECKING(Default TCP receive buffer size)
480 AC_RUN_IFELSE([AC_LANG_SOURCE([[
481 #include <stdlib.h>
482 #include <stdio.h>
483 #include <sys/types.h>
484 #if HAVE_SYS_SOCKET_H
485 #include <sys/socket.h>
486 #endif
487 #if HAVE_NETINET_IN_H
488 #include <netinet/in.h>
489 #endif
490 #if HAVE_WINSOCK2_H
491 #include <winsock2.h>
492 #elif HAVE_WINSOCK_H
493 #include <winsock.h>
494 #endif
495 int main(int argc, char **argv)
496 {
497 FILE *fp;
498 int fd,val=0;
499 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
500 int len=sizeof(int);
501 WSADATA wsaData;
502 WSAStartup(2, &wsaData);
503 #else
504 socklen_t len=sizeof(socklen_t);
505 #endif
506 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return 1;
507 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
508 if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&val, &len) < 0) return 1;
509 WSACleanup();
510 #else
511 if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) return 1;
512 #endif
513 if (val <= 0) return 1;
514 fp = fopen("conftestval", "w");
515 fprintf (fp, "%d\n", val);
516 return 0;
517 }
518 ]])],[SQUID_TCP_SO_RCVBUF=`cat conftestval`],[SQUID_TCP_SO_RCVBUF=16384],[SQUID_TCP_SO_RCVBUF=16384])
519 AC_MSG_RESULT($SQUID_TCP_SO_RCVBUF)
520 if test $SQUID_TCP_SO_RCVBUF -gt 65535; then
521 AC_MSG_NOTICE([Limiting receive buffer size to 64K])
522 SQUID_TCP_SO_RCVBUF=65535
523 fi
524 AC_DEFINE_UNQUOTED(SQUID_TCP_SO_RCVBUF, $SQUID_TCP_SO_RCVBUF,[TCP receive buffer size])
525 ])
526
527
528 dnl check if we need to define sys_errlist as external
529 dnl defines NEED_SYS_ERRLIST
530
531 AC_DEFUN([SQUID_CHECK_NEED_SYS_ERRLIST],[
532 AC_CACHE_CHECK(if sys_errlist is already defined, ac_cv_needs_sys_errlist,
533 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[char *s = sys_errlist;]])],[ac_cv_needs_sys_errlist="no"],[ac_cv_needs_sys_errlist="yes"])
534 )
535 SQUID_DEFINE_BOOL(NEED_SYS_ERRLIST,$ac_cv_needs_sys_errlist,[If we need to declare sys_errlist as extern])
536 ])
537
538
539 dnl check if MAXPATHLEN is defined in the system headers
540 dnl or define it ourselves
541
542 AC_DEFUN([SQUID_CHECK_MAXPATHLEN],[
543 AC_MSG_CHECKING(for system-provided MAXPATHLEN)
544 AC_LINK_IFELSE([
545 AC_LANG_PROGRAM([[
546 #include <sys/param.h>]], [[
547 int i = MAXPATHLEN;]])], [
548 AC_MSG_RESULT(yes)], [
549 AC_MSG_RESULT(no)
550 AC_DEFINE(MAXPATHLEN,256,[If MAXPATHLEN has not been defined])])
551 ])
552
553
554 dnl check that we have a working statvfs
555 dnl sets the ac_cv_func_statvfs shell variable and defines HAVE_STATVFS
556
557 AC_DEFUN([SQUID_CHECK_WORKING_STATVFS],[
558 AC_CACHE_CHECK(for working statvfs() interface,ac_cv_func_statvfs,[
559 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
560 #include <stdlib.h>
561 #include <stdio.h>
562 #include <sys/types.h>
563 #include <sys/statvfs.h>
564 ]], [[
565 struct statvfs sfs;
566 sfs.f_blocks = sfs.f_bfree = sfs.f_frsize =
567 sfs.f_files = sfs.f_ffree = 0;
568 statvfs("/tmp", &sfs);
569 ]])],[ac_cv_func_statvfs=yes],[ac_cv_func_statvfs=no])
570 ])
571 SQUID_DEFINE_BOOL(HAVE_STATVFS,$ac_cv_func_statvfs,[set to 1 if our system has statvfs(), and if it actually works])
572 ])
573
574
575 dnl Check whether this OS defines f_frsize as a member of struct statfs
576 AC_DEFUN([SQUID_CHECK_F_FRSIZE_IN_STATFS],[
577 AC_CACHE_CHECK([for f_frsize field in struct statfs],
578 ac_cv_have_f_frsize_in_struct_statfs, [
579 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
580 #if HAVE_SYS_STATFS_H
581 #include <sts/statfs.h>
582 #endif
583 #if HAVE_SYS_STATVFS_H
584 #include <sts/statvfs.h>
585 #endif
586 #if HAVE_SYS_VFS_H
587 #include <sts/vfs.h>
588 #endif
589 ]], [[ struct statfs s; s.f_frsize = 0; ]])],[ ac_cv_have_f_frsize_in_struct_statfs="yes" ],[ ac_cv_have_f_frsize_in_struct_statfs="no"
590 ])
591 ])
592 SQUID_DEFINE_BOOL(HAVE_F_FRSIZE_IN_STATFS,$ac_cv_have_f_frsize_in_struct_statfs,[Define if struct statfs has field f_frsize (Linux 2.6 or later)])
593 ])
594
595
596 dnl check that we can use the libresolv _dns_ttl_ hack
597 dnl sets the ac_cv_libresolv_dns_ttl_hack shell variable and defines LIBRESOLV_DNS_TTL_HACK
598
599 AC_DEFUN([SQUID_CHECK_LIBRESOLV_DNS_TTL_HACK],[
600 AC_CACHE_CHECK(for libresolv _dns_ttl_ hack, ac_cv_libresolv_dns_ttl_hack, [
601 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern int _dns_ttl_;]], [[return _dns_ttl_;]])],
602 [ac_cv_libresolv_dns_ttl_hack=yes],[ac_cv_libresolv_dns_ttl_hack=no]) ])
603 SQUID_DEFINE_BOOL(LIBRESOLV_DNS_TTL_HACK,$ac_cv_libresolv_dns_ttl_hack,
604 [libresolv.a has been hacked to export _dns_ttl_])
605 ])
606
607
608 dnl checks for availability of some resolver fields
609 dnl sets ac_cv_have_res_ext_nsaddr_list shell variable
610 dnl defines _SQUID_RES_NSADDR6_COUNT _SQUID_RES_NSADDR6_LARRAY
611 dnl defines _SQUID_RES_NSADDR6_LPTR _SQUID_RES_NSADDR6_COUNT
612 dnl defines _SQUID_RES_NSADDR_LIST _SQUID_RES_NSADDR_COUNT
613
614 AC_DEFUN([SQUID_CHECK_RESOLVER_FIELDS],[
615 AC_CACHE_CHECK(for _res_ext.nsaddr_list, ac_cv_have_res_ext_nsaddr_list,
616 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
617 #if HAVE_SYS_TYPES_H
618 #include <sys/types.h>
619 #endif
620 #if HAVE_NETINET_IN_H
621 #include <netinet/in.h>
622 #endif
623 #if HAVE_ARPA_INET_H
624 #include <arpa/inet.h>
625 #endif
626 #if HAVE_ARPA_NAMESER_H
627 #include <arpa/nameser.h>
628 #endif
629 #if HAVE_RESOLV_H
630 #include <resolv.h>
631 #endif
632 ]],
633 [[_res_ext.nsaddr_list[[0]].s_addr;]])],[
634 ac_cv_have_res_ext_nsaddr_list="yes" ],[
635 ac_cv_have_res_ext_nsaddr_list="no"]))
636 if test "$ac_cv_have_res_ext_nsaddr_list" = "yes" ; then
637 AC_DEFINE(_SQUID_RES_NSADDR6_LARRAY,_res_ext.nsaddr_list,[If _res_ext structure has nsaddr_list member])
638 AC_DEFINE(_SQUID_RES_NSADDR6_COUNT,ns6count,[Nameserver Counter for IPv6 _res_ext])
639 fi
640
641 if test "$_SQUID_RES_NSADDR6_LIST" = ""; then
642 AC_CACHE_CHECK(for _res._u._ext.nsaddrs, ac_cv_have_res_ext_nsaddrs,
643 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
644 #if HAVE_SYS_TYPES_H
645 #include <sys/types.h>
646 #endif
647 #if HAVE_NETINET_IN_H
648 #include <netinet/in.h>
649 #endif
650 #if HAVE_ARPA_INET_H
651 #include <arpa/inet.h>
652 #endif
653 #if HAVE_ARPA_NAMESER_H
654 #include <arpa/nameser.h>
655 #endif
656 #if HAVE_RESOLV_H
657 #include <resolv.h>
658 #endif
659 ]], i
660 [[_res._u._ext.nsaddrs[[0]]->sin6_addr;]])],
661 [ac_cv_have_res_ext_nsaddrs="yes"],[ac_cv_have_res_ext_nsaddrs="no"]))
662 if test "$ac_cv_have_res_ext_nsaddrs" = "yes" ; then
663 AC_DEFINE(_SQUID_RES_NSADDR6_LPTR,_res._u._ext.nsaddrs,[If _res structure has _ext.nsaddrs member])
664 AC_DEFINE(_SQUID_RES_NSADDR6_COUNT,_res._u._ext.nscount6,[Nameserver Counter for IPv6 _res])
665 fi
666 fi
667
668 AC_CACHE_CHECK(for _res.nsaddr_list, ac_cv_have_res_nsaddr_list,
669 AC_COMPILE_IFELSE([
670 AC_LANG_PROGRAM([[
671 #if HAVE_SYS_TYPES_H
672 #include <sys/types.h>
673 #endif
674 #if HAVE_NETINET_IN_H
675 #include <netinet/in.h>
676 #endif
677 #if HAVE_ARPA_INET_H
678 #include <arpa/inet.h>
679 #endif
680 #if HAVE_ARPA_NAMESER_H
681 #include <arpa/nameser.h>
682 #endif
683 #if HAVE_RESOLV_H
684 #include <resolv.h>
685 #endif
686 ]], [[_res.nsaddr_list[[0]];]])],
687 [ac_cv_have_res_nsaddr_list="yes"],[ac_cv_have_res_nsaddr_list="no"]))
688 if test $ac_cv_have_res_nsaddr_list = "yes" ; then
689 AC_DEFINE(_SQUID_RES_NSADDR_LIST,_res.nsaddr_list,[If _res structure has nsaddr_list member])
690 AC_DEFINE(_SQUID_RES_NSADDR_COUNT,_res.nscount,[Nameserver counter for IPv4 _res])
691 fi
692
693 if test "$_SQUID_RES_NSADDR_LIST" = ""; then
694 AC_CACHE_CHECK(for _res.ns_list, ac_cv_have_res_ns_list,
695 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
696 #if HAVE_SYS_TYPES_H
697 #include <sys/types.h>
698 #endif
699 #if HAVE_NETINET_IN_H
700 #include <netinet/in.h>
701 #endif
702 #if HAVE_ARPA_INET_H
703 #include <arpa/inet.h>
704 #endif
705 #if HAVE_ARPA_NAMESER_H
706 #include <arpa/nameser.h>
707 #endif
708 #if HAVE_RESOLV_H
709 #include <resolv.h>
710 #endif
711 ]],
712 [[_res.ns_list[[0]].addr;]])],
713 [ac_cv_have_res_ns_list="yes"],[ac_cv_have_res_ns_list="no"]))
714 if test $ac_cv_have_res_ns_list = "yes" ; then
715 AC_DEFINE(_SQUID_RES_NSADDR_LIST,_res.ns_list,[If _res structure has ns_list member])
716 AC_DEFINE(_SQUID_RES_NSADDR_COUNT,_res.nscount,[Nameserver counter for IPv4 _res])
717 fi
718 fi
719 ])
720
721
722 dnl checks the winsock library to use (ws2_32 or wsock32)
723 dnl may set ac_cv_func_select as a side effect
724 AC_DEFUN([SQUID_CHECK_WINSOCK_LIB],[
725 AC_CHECK_HEADERS(winsock2.h winsock.h)
726 SQUID_STATE_SAVE(winsock)
727 SQUID_SEARCH_LIBS([squid_getprotobynumber],[ws2_32 wsock32],,,,[
728 #if HAVE_WINSOCK2_H
729 #include <winsock2.h>
730 #elif HAVE_WINSOCK_H
731 #include <winsock.h>
732 #endif
733 /* ugly hack. */
734 void squid_getprotobynumber(void) {
735 getprotobynumber(1);
736 }
737 ])
738 AC_MSG_CHECKING([for winsock library])
739 case "$ac_cv_search_squid_getprotobynumber" in
740 "no")
741 AC_MSG_RESULT([winsock library not found])
742 ;;
743 "none required")
744 AC_MSG_RESULT([winsock library already in LIBS])
745 ;;
746 "-lws2_32")
747 AC_MSG_RESULT([winsock2])
748 XTRA_LIBS="-lws2_32 $XTRA_LIBS"
749 ac_cv_func_select='yes'
750 ;;
751 "-lwsock32")
752 AC_MSG_RESULT([winsock])
753 XTRA_LIBS="-lwsock32 $XTRA_LIBS"
754 ac_cv_func_select='yes'
755 ;;
756 esac
757 SQUID_STATE_ROLLBACK(winsock)
758 ])
759
760 dnl check that setresuid is properly implemented.
761 dnl sets squid_cv_resuid_works to "yes" or "no"
762 AC_DEFUN([SQUID_CHECK_SETRESUID_WORKS],[
763 AC_CACHE_CHECK(if setresuid is actually implemented, squid_cv_resuid_works,
764 AC_RUN_IFELSE([
765 AC_LANG_SOURCE([[
766 #if HAVE_STDLIB_H
767 #include <stdlib.h>
768 #endif
769 #if HAVE_STDIO_H
770 #include <stdio.h>
771 #endif
772 #if HAVE_UNISTD_H
773 #include <unistd.h>
774 #endif
775 int main(int argc, char **argv) {
776 if(setresuid(-1,-1,-1)) {
777 perror("setresuid:");
778 return 1;
779 }
780 return 0;
781 }
782 ]])],[
783 squid_cv_resuid_works="yes" ],[
784 squid_cv_resuid_works="no" ],[:])
785 )
786 ])
787
788 dnl check that we have functional CPU clock access for the profiler
789 dnl sets squid_cv_profiler_works to "yes" or "no"
790
791 AC_DEFUN([SQUID_CHECK_FUNCTIONAL_CPU_PROFILER],[
792 AC_CACHE_CHECK([for operational CPU clock access],
793 squid_cv_cpu_profiler_works,
794 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
795 #include <ctime>
796 #if defined(__GNUC__) && ( defined(__i386) || defined(__i386__) )
797 // okay
798 #elif defined(__GNUC__) && ( defined(__x86_64) || defined(__x86_64__) )
799 // okay
800 #elif defined(__GNUC__) && defined(__alpha)
801 // okay
802 #elif defined(_M_IX86) && defined(_MSC_VER) /* x86 platform on Microsoft C Compiler ONLY */
803 // okay
804 #elif defined(HAVE_CLOCK_GETTIME_NSEC_NP) && defined(CLOCK_MONOTONIC_RAW)
805 // okay
806 #else
807 #error This CPU is unsupported. No profiling available here.
808 #endif
809 ]])],[
810 squid_cv_cpu_profiler_works=yes],[
811 squid_cv_cpu_profiler_works=no])
812 )
813 ])
814
815 dnl check whether recv takes a char* or void* as a second argument
816 AC_DEFUN([SQUID_CHECK_RECV_ARG_TYPE],[
817 AC_CACHE_CHECK([whether recv takes a pointer to void or char as second argument],
818 squid_cv_recv_second_arg_type, [
819 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
820 #include <sys/types.h>
821 #if HAVE_SYS_SOCKET_H
822 #include <sys/socket.h>
823 #endif
824 #if HAVE_WINSOCK2_H
825 #include <winsock2.h>
826 #elif HAVE_WINSOCK_H
827 #include <winsock.h>
828 #endif
829 int main (int argc, char ** argv) {
830 void *buf;
831 recv(0,buf,0,0);
832 }
833 ]])],[squid_cv_recv_second_arg_type=void],
834 [squid_cv_recv_second_arg_type=char])
835 AC_MSG_RESULT($squid_cv_recv_second_arg_type*)
836 ])
837 AC_DEFINE_UNQUOTED(RECV_ARG_TYPE,$squid_cv_recv_second_arg_type,
838 [Base type of the second argument to recv(2)])
839 ])
840
841
842 dnl check whether Solaris has broken IPFilter headers (Solaris 10 at least does)
843 AC_DEFUN([SQUID_CHECK_BROKEN_SOLARIS_IPFILTER],[
844 if test "x$squid_cv_broken_ipfilter_minor_t" = "x"; then
845 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
846 # include <sys/types.h>
847 # include <sys/time.h>
848 # include <sys/ioccom.h>
849 # include <netinet/in.h>
850
851 # include <netinet/ip_compat.h>
852 # include <netinet/ip_fil.h>
853 # include <netinet/ip_nat.h>
854 ]])],[
855 AC_MSG_RESULT(no)
856 squid_cv_broken_ipfilter_minor_t=0
857 ],[
858 ## on fail, test the hack
859 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
860 #define minor_t fubaar
861 # include <sys/types.h>
862 # include <sys/time.h>
863 # include <sys/ioccom.h>
864 # include <netinet/in.h>
865 #undef minor_t
866 # include <netinet/ip_compat.h>
867 # include <netinet/ip_fil.h>
868 # include <netinet/ip_nat.h>
869 ]])],[
870 AC_MSG_RESULT(yes)
871 squid_cv_broken_ipfilter_minor_t=1
872 ],[
873 AC_MSG_ERROR(unable to make IPFilter work with netinet/ headers)
874 ])
875 ])
876 fi
877
878 AC_DEFINE_UNQUOTED(USE_SOLARIS_IPFILTER_MINOR_T_HACK,$squid_cv_broken_ipfilter_minor_t,
879 [Workaround IPFilter minor_t breakage])
880
881 ## check for IPFilter headers that require this hack
882 ## (but first netinet/in.h and sys/ioccom.h which they depend on)
883 AC_CHECK_HEADERS( \
884 netinet/in.h \
885 sys/ioccom.h \
886 ip_compat.h \
887 ip_fil_compat.h \
888 ip_fil.h \
889 ip_nat.h \
890 netinet/ip_compat.h \
891 netinet/ip_fil_compat.h \
892 netinet/ip_fil.h \
893 netinet/ip_nat.h \
894 ,,,[
895 #if USE_SOLARIS_IPFILTER_MINOR_T_HACK
896 #define minor_t fubar
897 #endif
898 #if HAVE_SYS_TYPES_H
899 #include <sys/types.h>
900 #endif
901 #if HAVE_SYS_TIME_H
902 #include <sys/time.h>
903 #endif
904 #if HAVE_NETINET_IN_H
905 #include <netinet/in.h>
906 #endif
907 #if HAVE_SYS_IOCCOM_H
908 #include <sys/ioccom.h>
909 #endif
910 #if USE_SOLARIS_IPFILTER_MINOR_T_HACK
911 #undef minor_t
912 #endif
913 #if HAVE_IP_COMPAT_H
914 #include <ip_compat.h>
915 #elif HAVE_NETINET_IP_COMPAT_H
916 #include <netinet/ip_compat.h>
917 #endif
918 #if HAVE_IP_FIL_H
919 #include <ip_fil.h>
920 #elif HAVE_NETINET_IP_FIL_H
921 #include <netinet/ip_fil.h>
922 #endif
923 #if !defined(IPFILTER_VERSION)
924 #define IPFILTER_VERSION 5000004
925 #endif
926 ])
927
928 ## Solaris 10+ backported IPv6 NAT to their IPFilter v4.1 instead of using v5
929 AC_CHECK_MEMBERS([
930 struct natlookup.nl_inipaddr.in6,
931 struct natlookup.nl_realipaddr.in6],,,[
932 #if USE_SOLARIS_IPFILTER_MINOR_T_HACK
933 #define minor_t fubar
934 #endif
935 #if HAVE_SYS_PARAM_H
936 #include <sys/param.h>
937 #endif
938 #if HAVE_SYS_TYPES_H
939 #include <sys/types.h>
940 #endif
941 #if HAVE_SYS_TIME_H
942 #include <sys/time.h>
943 #endif
944 #if HAVE_NETINET_IN_H
945 #include <netinet/in.h>
946 #endif
947 #if HAVE_SYS_IOCCOM_H
948 #include <sys/ioccom.h>
949 #endif
950 #if USE_SOLARIS_IPFILTER_MINOR_T_HACK
951 #undef minor_t
952 #endif
953 #if HAVE_IP_COMPAT_H
954 #include <ip_compat.h>
955 #elif HAVE_NETINET_IP_COMPAT_H
956 #include <netinet/ip_compat.h>
957 #endif
958 #if HAVE_IP_FIL_H
959 #include <ip_fil.h>
960 #elif HAVE_NETINET_IP_FIL_H
961 #include <netinet/ip_fil.h>
962 #endif
963 #if HAVE_IP_NAT_H
964 #include <ip_nat.h>
965 #elif HAVE_NETINET_IP_NAT_H
966 #include <netinet/ip_nat.h>
967 #endif
968 ])
969
970 ])