83
84
Server::accept(Connection * c)
86
socklen_t sz = sizeof(c->sa);
87
socklen_t sz = sizeof(c->addr);
88
res = socketManager.accept(fd, (struct sockaddr *)&c->sa, &sz);
89
res = socketManager.accept(fd, &c->addr.sa, &sz);
93
if (is_debug_tag_set("iocore_net_server")) {
94
ip_port_text_buffer ipb1, ipb2;
95
Debug("iocore_net_server", "Connection accepted [Server]. %s -> %s\n"
96
, ats_ip_nptop(&c->addr, ipb2, sizeof(ipb2))
97
, ats_ip_nptop(&addr, ipb1, sizeof(ipb1))
93
101
#ifdef SET_CLOSE_ON_EXEC
94
102
if ((res = safe_fcntl(fd, F_SETFD, 1)) < 0)
102
110
#ifdef SET_SO_KEEPALIVE
103
111
// enables 2 hour inactivity probes, also may fix IRIX FIN_WAIT_2 leak
104
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int))) < 0)
112
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, SOCKOPT_ON, sizeof(int))) < 0)
140
add_http_filter(int fd) {
142
#if defined(SOL_FILTER) && defined(FIL_ATTACH)
143
err = setsockopt(fd, SOL_FILTER, FIL_ATTACH, "httpfilt", 9);
132
Server::setup_fd_for_listen(bool non_blocking, int recv_bufsize, int send_bufsize)
149
Server::setup_fd_for_listen(
158
if (http_accept_filter)
135
161
#ifdef SEND_BUF_SIZE
137
163
int send_buf_size = SEND_BUF_SIZE;
186
212
#ifdef SET_TCP_NO_DELAY
187
if ((res = safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, ON, sizeof(int))) < 0)
213
if ((res = safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, SOCKOPT_ON, sizeof(int))) < 0)
190
216
#ifdef SET_SO_KEEPALIVE
191
217
// enables 2 hour inactivity probes, also may fix IRIX FIN_WAIT_2 leak
192
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int))) < 0)
218
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, SOCKOPT_ON, sizeof(int))) < 0)
208
234
if ((res = safe_nonblocking(fd)) < 0)
211
int namelen = sizeof(sa);
212
if ((res = safe_getsockname(fd, (struct sockaddr *) &sa, &namelen)))
237
int namelen = sizeof(addr);
238
if ((res = safe_getsockname(fd, &addr.sa, &namelen)))
244
int transparent_value = 1;
245
Debug("http_tproxy", "Listen port inbound transparency enabled.\n");
246
if (setsockopt(fd, SOL_IP, TS_IP_TRANSPARENT, &transparent_value, sizeof(transparent_value)) == -1) {
247
Error("[Server::setup_fd_for_listen] Unable to set transparent socket option [%d] %s\n", errno, strerror(errno));
251
Error("[Server::setup_fd_for_listen] Transparency requested but TPROXY not configured\n");
226
Server::listen(int port_number, int domain, bool non_blocking, int recv_bufsize, int send_bufsize)
266
Server::listen(bool non_blocking, int recv_bufsize, int send_bufsize, bool transparent)
228
268
ink_assert(fd == NO_FD);
232
char port[6] = {'\0'};
233
struct addrinfo hints;
234
struct addrinfo *ai_res = NULL;
235
struct addrinfo *ai = NULL;
236
socklen_t addrlen = 0; // keep track of length of socket address info
237
snprintf(port, sizeof(port), "%d", port_number);
239
memset(&hints, 0, sizeof(hints));
240
hints.ai_family = domain;
241
hints.ai_socktype = SOCK_STREAM;
242
hints.ai_flags = AI_PASSIVE|AI_NUMERICHOST|AI_ADDRCONFIG;
243
gai_errno = getaddrinfo(accept_ip_str, port, &hints, &ai_res);
245
Error("getaddrinfo error %i: %s", gai_errno, gai_strerror(gai_errno));
272
if (!ats_is_ip(&accept_addr)) {
273
ats_ip4_set(&addr, INADDR_ANY,0);
275
ats_ip_copy(&addr, &accept_addr);
251
res = socketManager.socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
253
memset(&sa, 0, sizeof(sa));
254
addrlen = ai->ai_addrlen; // save value for later since ai will be freed asap
255
memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
257
freeaddrinfo(ai_res);
278
res = socketManager.socket(addr.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
284
if (http_accept_filter)
263
287
#ifdef SEND_BUF_SIZE
265
289
int send_buf_size = SEND_BUF_SIZE;
319
if (domain == AF_INET6 && (res = safe_setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, ON, sizeof(int))) < 0)
322
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, ON, sizeof(int))) < 0)
325
if ((res = socketManager.ink_bind(fd, (struct sockaddr *) &sa, addrlen, IPPROTO_TCP)) < 0) {
343
if (ats_is_ip6(&addr) && (res = safe_setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, SOCKOPT_ON, sizeof(int))) < 0)
346
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, SOCKOPT_ON, sizeof(int))) < 0)
349
if ((res = socketManager.ink_bind(fd, &addr.sa, ats_ip_size(&addr.sa), IPPROTO_TCP)) < 0) {
328
352
#ifdef SET_TCP_NO_DELAY
329
if ((res = safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, ON, sizeof(int))) < 0)
353
if ((res = safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, SOCKOPT_ON, sizeof(int))) < 0)
332
356
#ifdef SET_SO_KEEPALIVE
333
357
// enables 2 hour inactivity probes, also may fix IRIX FIN_WAIT_2 leak
334
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, ON, sizeof(int))) < 0)
358
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, SOCKOPT_ON, sizeof(int))) < 0)
364
int transparent_value = 1;
365
Debug("http_tproxy", "Listen port inbound transparency enabled.\n");
366
if (setsockopt(fd, SOL_IP, TS_IP_TRANSPARENT, &transparent_value, sizeof(transparent_value)) == -1) {
367
Error("[Server::listen] Unable to set transparent socket option [%d] %s\n", errno, strerror(errno));
371
Error("[Server::listen] Transparency requested but TPROXY not configured\n");
338
375
#if defined(linux)
339
376
if (NetProcessor::accept_mss > 0)
340
377
if ((res = safe_setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, (char *) &NetProcessor::accept_mss, sizeof(int))) < 0)
346
383
if (non_blocking)
347
384
if ((res = safe_nonblocking(fd)) < 0)
350
int namelen = sizeof(sa);
351
if ((res = safe_getsockname(fd, (struct sockaddr *) &sa, &namelen)))
386
// Original just did this on port == 0.
387
namelen = sizeof(addr);
388
if ((res = safe_getsockname(fd, &addr.sa, &namelen)))
359
Error("Could not bind or listen to port %d (error: %d)", port_number, res);
395
Error("Could not bind or listen to port %d (error: %d)", ats_ip_port_host_order(&addr), res);