| 66 | | socklen_t client_addr_len; |
|---|
| 67 | | struct sockaddr_in client_addr, server_addr; |
|---|
| 68 | | struct timeval c_timeout; |
|---|
| 69 | | struct hostent *proxy_addr; |
|---|
| 70 | | struct in_addr *p_addr; |
|---|
| 71 | | proxy_dest *proxy_dst; |
|---|
| 72 | | fd_set rfds; |
|---|
| 73 | | char *ip_l_str, *ip_r_str; |
|---|
| 74 | | Attack *attack; |
|---|
| 75 | | u_char port_mode; |
|---|
| 76 | | |
|---|
| 77 | | proxy_addr = NULL; |
|---|
| 78 | | proxy_dst = NULL; |
|---|
| 79 | | attack_string = NULL; |
|---|
| 80 | | ip_l_str = NULL; |
|---|
| 81 | | ip_r_str = NULL; |
|---|
| 82 | | attack = NULL; |
|---|
| 83 | | select_return = -1; |
|---|
| 84 | | listen_fd = -1; |
|---|
| 85 | | connection_fd = -1; |
|---|
| 86 | | mirror_sock_fd = -1; |
|---|
| 87 | | proxy_sock_fd = -1; |
|---|
| 88 | | proxy_this = 0; |
|---|
| 89 | | mirror_this = mirror_mode; |
|---|
| 90 | | established = 0; |
|---|
| 91 | | port_mode = PORTCONF_NONE; |
|---|
| 92 | | |
|---|
| 93 | | if (!((proto == TCP) || (proto == UDP))) { |
|---|
| 94 | | logmsg(LOG_DEBUG, 1, "Unsupported protocol type.\n"); |
|---|
| 95 | | return; |
|---|
| 96 | | } |
|---|
| 97 | | |
|---|
| 98 | | /* fork server process */ |
|---|
| 99 | | if ((pid = fork()) == 0) { |
|---|
| 100 | | |
|---|
| 101 | | /* use this port string as log prefix */ |
|---|
| 102 | | memset(portstr, 0, 16); |
|---|
| 103 | | if (snprintf(portstr, 16, "%u/%s\t", ntohs(port_l), PROTO(proto)) > 15) { |
|---|
| 104 | | logmsg(LOG_ERR, 1, "Error - Port string is too long.\n"); |
|---|
| 105 | | return; |
|---|
| | 66 | socklen_t client_addr_len; |
|---|
| | 67 | struct sockaddr_in client_addr, server_addr; |
|---|
| | 68 | struct timeval c_timeout; |
|---|
| | 69 | struct hostent *proxy_addr; |
|---|
| | 70 | struct in_addr *p_addr; |
|---|
| | 71 | proxy_dest *proxy_dst; |
|---|
| | 72 | fd_set rfds; |
|---|
| | 73 | char *ip_l_str, *ip_r_str; |
|---|
| | 74 | Attack *attack; |
|---|
| | 75 | u_char port_mode; |
|---|
| | 76 | |
|---|
| | 77 | proxy_addr = NULL; |
|---|
| | 78 | proxy_dst = NULL; |
|---|
| | 79 | attack_string = NULL; |
|---|
| | 80 | ip_l_str = NULL; |
|---|
| | 81 | ip_r_str = NULL; |
|---|
| | 82 | attack = NULL; |
|---|
| | 83 | select_return = -1; |
|---|
| | 84 | listen_fd = -1; |
|---|
| | 85 | connection_fd = -1; |
|---|
| | 86 | mirror_sock_fd = -1; |
|---|
| | 87 | proxy_sock_fd = -1; |
|---|
| | 88 | proxy_this = 0; |
|---|
| | 89 | mirror_this = mirror_mode; |
|---|
| | 90 | established = 0; |
|---|
| | 91 | port_mode = PORTCONF_NONE; |
|---|
| | 92 | |
|---|
| | 93 | if (!((proto == TCP) || (proto == UDP))) { |
|---|
| | 94 | logmsg(LOG_DEBUG, 1, "Unsupported protocol type.\n"); |
|---|
| | 95 | return; |
|---|
| 107 | | |
|---|
| 108 | | |
|---|
| 109 | | if (proto == TCP) { |
|---|
| 110 | | logmsg(LOG_DEBUG, 1, "Requesting tcp socket.\n"); |
|---|
| 111 | | if ((listen_fd = get_boundsock(&server_addr, port_l, SOCK_STREAM)) < 0) return; |
|---|
| 112 | | if (port_flags_tcp[htons(port_l)]) port_mode = port_flags_tcp[htons(port_l)]->mode; |
|---|
| 113 | | } else if (proto == UDP) { |
|---|
| 114 | | logmsg(LOG_DEBUG, 1, "Requesting udp socket.\n"); |
|---|
| 115 | | if ((listen_fd = get_boundsock(&server_addr, port_l, SOCK_DGRAM)) < 0) return; |
|---|
| 116 | | if (port_flags_udp[htons(port_l)]) port_mode = port_flags_udp[htons(port_l)]->mode; |
|---|
| 117 | | } |
|---|
| 118 | | |
|---|
| 119 | | ip_l_str = strdup(inet_ntoa(ip_l)); |
|---|
| 120 | | ip_r_str = strdup(inet_ntoa(ip_r)); |
|---|
| | 97 | |
|---|
| | 98 | /* fork server process */ |
|---|
| | 99 | if ((pid = fork()) == 0) { |
|---|
| | 100 | |
|---|
| | 101 | /* use this port string as log prefix */ |
|---|
| | 102 | memset(portstr, 0, 16); |
|---|
| | 103 | if (snprintf(portstr, 16, "%u/%s\t", ntohs(port_l), PROTO(proto)) > 15) { |
|---|
| | 104 | logmsg(LOG_ERR, 1, "Error - Port string is too long.\n"); |
|---|
| | 105 | exit(EXIT_FAILURE); |
|---|
| | 106 | } |
|---|
| | 107 | |
|---|
| | 108 | if (proto == TCP) { |
|---|
| | 109 | logmsg(LOG_DEBUG, 1, "Requesting tcp socket.\n"); |
|---|
| | 110 | if ((listen_fd = get_boundsock(&server_addr, port_l, SOCK_STREAM)) == -1) |
|---|
| | 111 | exit(EXIT_SUCCESS); |
|---|
| | 112 | if (port_flags_tcp[htons(port_l)]) |
|---|
| | 113 | port_mode = port_flags_tcp[htons(port_l)]->mode; |
|---|
| | 114 | } else if (proto == UDP) { |
|---|
| | 115 | logmsg(LOG_DEBUG, 1, "Requesting udp socket.\n"); |
|---|
| | 116 | if ((listen_fd = get_boundsock(&server_addr, port_l, SOCK_DGRAM)) == -1) |
|---|
| | 117 | exit(EXIT_SUCCESS); |
|---|
| | 118 | if (port_flags_udp[htons(port_l)]) |
|---|
| | 119 | port_mode = port_flags_udp[htons(port_l)]->mode; |
|---|
| | 120 | } |
|---|
| | 121 | |
|---|
| | 122 | ip_l_str = strdup(inet_ntoa(ip_l)); |
|---|
| | 123 | ip_r_str = strdup(inet_ntoa(ip_r)); |
|---|
| 140 | | /* hand packet processing back to the kernel */ |
|---|
| 141 | | if ((status = ipq_set_verdict(h, packet->packet_id, NF_ACCEPT, 0, NULL)) < 0) { |
|---|
| 142 | | logmsg(LOG_ERR, 1, "Error - Could not set verdict on packet.\n"); |
|---|
| 143 | | logmsg(LOG_ERR, 1, "IPQ Error: %s.\n", ipq_errstr()); |
|---|
| 144 | | ipq_destroy_handle(h); |
|---|
| 145 | | exit(EXIT_FAILURE); |
|---|
| 146 | | } |
|---|
| 147 | | logmsg(LOG_DEBUG, 1, "IPQ - Successfully set verdict on packet.\n"); |
|---|
| 148 | | |
|---|
| 149 | | /* don't need root privs any more */ |
|---|
| 150 | | drop_privileges(); |
|---|
| 151 | | logmsg(LOG_DEBUG, 1, "Server is now running with user id %d and group id %d.\n", getuid(), getgid()); |
|---|
| | 143 | /* hand packet processing back to the kernel */ |
|---|
| | 144 | if ((status = ipq_set_verdict(h, packet->packet_id, NF_ACCEPT, 0, NULL)) < 0) { |
|---|
| | 145 | logmsg(LOG_ERR, 1, "Error - Could not set verdict on packet.\n"); |
|---|
| | 146 | logmsg(LOG_ERR, 1, "IPQ Error: %s.\n", ipq_errstr()); |
|---|
| | 147 | ipq_destroy_handle(h); |
|---|
| | 148 | exit(EXIT_FAILURE); |
|---|
| | 149 | } |
|---|
| | 150 | logmsg(LOG_DEBUG, 1, "IPQ - Successfully set verdict on packet.\n"); |
|---|
| | 151 | |
|---|
| | 152 | /* don't need root privs any more */ |
|---|
| | 153 | drop_privileges(); |
|---|
| | 154 | logmsg(LOG_DEBUG, 1, "Server is now running with user id %d and group id %d.\n", getuid(), getgid()); |
|---|
| 154 | | /* hand packet processing back to the kernel */ |
|---|
| 155 | | /* nfq_set_verdict()'s return value is undocumented, |
|---|
| 156 | | * but digging the source of libnetfilter_queue and libnfnetlink reveals |
|---|
| 157 | | * that it's just the passed-through value of a sendmsg() */ |
|---|
| 158 | | if (nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL) == -1) { |
|---|
| 159 | | logmsg(LOG_ERR, 1, "Error - Could not set verdict on packet: %s.\n", strerror(errno)); |
|---|
| 160 | | nfq_destroy_queue(qh); |
|---|
| 161 | | exit(EXIT_FAILURE); |
|---|
| 162 | | } |
|---|
| 163 | | logmsg(LOG_DEBUG, 1, "NFQ - Successfully set verdict on packet.\n"); |
|---|
| 164 | | |
|---|
| 165 | | /* don't need root privs any more */ |
|---|
| 166 | | drop_privileges(); |
|---|
| 167 | | logmsg(LOG_DEBUG, 1, "Server is now running with user id %d and group id %d.\n", geteuid(), getegid()); |
|---|
| | 157 | /* hand packet processing back to the kernel |
|---|
| | 158 | * nfq_set_verdict()'s return value is undocumented, |
|---|
| | 159 | * but digging the source of libnetfilter_queue and libnfnetlink reveals |
|---|
| | 160 | * that it's just the passed-through value of a sendmsg() */ |
|---|
| | 161 | if (nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL) == -1) { |
|---|
| | 162 | logmsg(LOG_ERR, 1, "Error - Could not set verdict on packet: %s.\n", strerror(errno)); |
|---|
| | 163 | nfq_destroy_queue(qh); |
|---|
| | 164 | exit(EXIT_FAILURE); |
|---|
| | 165 | } |
|---|
| | 166 | logmsg(LOG_DEBUG, 1, "NFQ - Successfully set verdict on packet.\n"); |
|---|
| | 167 | |
|---|
| | 168 | /* don't need root privs any more */ |
|---|
| | 169 | drop_privileges(); |
|---|
| | 170 | logmsg(LOG_DEBUG, 1, "Server is now running with user id %d and group id %d.\n", geteuid(), getegid()); |
|---|
| 169 | | |
|---|
| 170 | | /* wait for incoming connections */ |
|---|
| | 172 | |
|---|
| | 173 | /* wait for incoming connections */ |
|---|
| | 174 | for (;;) { |
|---|
| | 175 | FD_ZERO(&rfds); |
|---|
| | 176 | FD_SET(listen_fd, &rfds); |
|---|
| | 177 | |
|---|
| | 178 | c_timeout.tv_sec = conn_timeout; |
|---|
| | 179 | c_timeout.tv_usec = 0; |
|---|
| | 180 | |
|---|
| | 181 | switch (select_return = select(listen_fd + 1, &rfds, NULL, NULL, &c_timeout)) { |
|---|
| | 182 | case -1: |
|---|
| | 183 | if (errno == EINTR) |
|---|
| | 184 | break; |
|---|
| | 185 | logmsg(LOG_ERR, 1, |
|---|
| | 186 | " %s Error - select() call failed: %s.\n", portstr, strerror(errno)); |
|---|
| | 187 | exit(EXIT_FAILURE); |
|---|
| | 188 | case 0: |
|---|
| | 189 | /* timeout */ |
|---|
| | 190 | close(listen_fd); |
|---|
| | 191 | logmsg(LOG_NOISY, 1, |
|---|
| | 192 | "-> %s No incoming connection for %u seconds - server terminated.\n", |
|---|
| | 193 | portstr, conn_timeout); |
|---|
| | 194 | exit(EXIT_SUCCESS); |
|---|
| | 195 | default: |
|---|
| | 196 | if (FD_ISSET(listen_fd, &rfds)) { |
|---|
| | 197 | logmsg(LOG_NOISY, 1, |
|---|
| | 198 | " %s Connection request from %s.\n", portstr, inet_ntoa(ip_r)); |
|---|
| | 199 | |
|---|
| | 200 | /* initialize attack record */ |
|---|
| | 201 | if ((attack = new_attack(ip_l, ip_r, ntohs(port_l), 0, proto)) == NULL) { |
|---|
| | 202 | logmsg(LOG_ERR, 1, "Error - Could not initialize attack record.\n"); |
|---|
| | 203 | free(attack); |
|---|
| | 204 | exit(EXIT_FAILURE); |
|---|
| | 205 | } |
|---|
| | 206 | if (port_mode & PORTCONF_NORMAL) { |
|---|
| | 207 | /* handle connection in normal mode if this port configured to be handled 'normal' */ |
|---|
| | 208 | logmsg(LOG_DEBUG, 1, |
|---|
| | 209 | " %s Handling connection in normal mode.\n", portstr); |
|---|
| | 210 | mirror_this = 0; |
|---|
| | 211 | proxy_this = 0; |
|---|
| | 212 | } else if (port_mode & PORTCONF_PROXY) { |
|---|
| | 213 | /* get proxy server address for port */ |
|---|
| | 214 | logmsg(LOG_DEBUG, 1, |
|---|
| | 215 | " %s Handling connection in proxy mode.\n", portstr); |
|---|
| | 216 | |
|---|
| | 217 | if (proto == TCP) { |
|---|
| | 218 | if (port_flags_tcp[htons(port_l)]) |
|---|
| | 219 | proxy_dst = port_flags_tcp[htons(port_l)]->target; |
|---|
| | 220 | } else if (proto == UDP) { |
|---|
| | 221 | if (port_flags_udp[htons(port_l)]) |
|---|
| | 222 | proxy_dst = port_flags_udp[htons(port_l)]->target; |
|---|
| | 223 | } |
|---|
| | 224 | |
|---|
| | 225 | /* try to establish proxy connection to server */ |
|---|
| | 226 | if ((proxy_addr = gethostbyname(proxy_dst->host)) == NULL) { |
|---|
| | 227 | logmsg(LOG_ERR, 1, |
|---|
| | 228 | " %s Error - Unable to resolve proxy host %s.\n", |
|---|
| | 229 | portstr, proxy_dst->host); |
|---|
| | 230 | free(attack); |
|---|
| | 231 | exit(EXIT_FAILURE); |
|---|
| | 232 | } |
|---|
| | 233 | logmsg(LOG_DEBUG, 1, |
|---|
| | 234 | "== %s Proxy hostname %s resolved to %s.\n", |
|---|
| | 235 | portstr, proxy_dst->host, |
|---|
| | 236 | inet_ntoa(*(struct in_addr *) proxy_addr->h_addr_list[0])); |
|---|
| | 237 | |
|---|
| | 238 | |
|---|
| | 239 | logmsg(LOG_DEBUG, 1, |
|---|
| | 240 | "== %s Requesting proxy connection to %s:%u.\n", |
|---|
| | 241 | portstr, inet_ntoa(*(struct in_addr *) proxy_addr->h_addr_list[0]), |
|---|
| | 242 | proxy_dst->port); |
|---|
| | 243 | p_addr = (struct in_addr *) proxy_addr->h_addr_list[0]; |
|---|
| | 244 | if ((proxy_sock_fd = |
|---|
| | 245 | proxy_connect(PORTCONF_PROXY, *p_addr, |
|---|
| | 246 | ntohs(port_l), proxy_dst->port, |
|---|
| | 247 | proto, attack)) == -1) { |
|---|
| | 248 | logmsg(LOG_INFO, 1, |
|---|
| | 249 | "== %s Proxy connection rejected, falling back to normal mode.\n", |
|---|
| | 250 | portstr); |
|---|
| | 251 | proxy_this = 0; |
|---|
| | 252 | } else |
|---|
| | 253 | logmsg(LOG_NOTICE, 1, |
|---|
| | 254 | "== %s Proxy connection to %s:%u established.\n", |
|---|
| | 255 | portstr, |
|---|
| | 256 | inet_ntoa(*(struct in_addr *) proxy_addr-> |
|---|
| | 257 | h_addr_list[0]), proxy_dst->port); |
|---|
| | 258 | } else if ((mirror_this) || (port_mode & PORTCONF_MIRROR)) { |
|---|
| | 259 | /* try to establish mirror connection back to the client */ |
|---|
| | 260 | logmsg(LOG_DEBUG, 1, |
|---|
| | 261 | " %s Handling connection in mirror mode.\n", portstr); |
|---|
| | 262 | |
|---|
| | 263 | logmsg(LOG_DEBUG, 1, |
|---|
| | 264 | "<> %s Requesting mirror connection to %s:%u.\n", |
|---|
| | 265 | portstr, inet_ntoa(ip_r), ntohs(port_l)); |
|---|
| | 266 | if ((mirror_sock_fd = |
|---|
| | 267 | proxy_connect(PORTCONF_MIRROR, |
|---|
| | 268 | (struct in_addr) ip_r, |
|---|
| | 269 | ntohs(port_l), ntohs(port_l), |
|---|
| | 270 | proto, attack)) == -1) { |
|---|
| | 271 | logmsg(LOG_INFO, 1, |
|---|
| | 272 | "<> %s Mirror connection rejected, falling back to normal mode.\n", |
|---|
| | 273 | portstr); |
|---|
| | 274 | mirror_this = 0; |
|---|
| | 275 | } else |
|---|
| | 276 | logmsg(LOG_NOTICE, 1, |
|---|
| | 277 | "<> %s Mirror connection to %s:%u established.\n", |
|---|
| | 278 | portstr, inet_ntoa(ip_r), (uint16_t) ntohs(port_l)); |
|---|
| | 279 | } |
|---|
| | 280 | |
|---|
| | 281 | bzero(&client_addr, sizeof(client_addr)); |
|---|
| | 282 | client_addr_len = sizeof(client_addr); |
|---|
| | 283 | established = 0; |
|---|
| | 284 | |
|---|
| | 285 | |
|---|
| | 286 | /* accept connection depending on protocol */ |
|---|
| | 287 | switch ((uint16_t) proto) { |
|---|
| | 288 | case TCP: |
|---|
| | 289 | /* accept tcp connection request */ |
|---|
| | 290 | if ((connection_fd = accept(listen_fd, (struct sockaddr *) |
|---|
| | 291 | &client_addr, &client_addr_len)) < 0) { |
|---|
| | 292 | if (errno == EINTR) |
|---|
| | 293 | break; |
|---|
| | 294 | else { |
|---|
| | 295 | logmsg(LOG_ERR, 1, |
|---|
| | 296 | " %s Error - Could not accept tcp connection: %s\n", |
|---|
| | 297 | portstr, strerror(errno)); |
|---|
| | 298 | close(mirror_sock_fd); |
|---|
| | 299 | free(attack); |
|---|
| | 300 | exit(EXIT_FAILURE); |
|---|
| | 301 | } |
|---|
| | 302 | } |
|---|
| | 303 | established = 1; |
|---|
| | 304 | break; |
|---|
| | 305 | case UDP: |
|---|
| | 306 | connection_fd = dup(listen_fd); |
|---|
| | 307 | client_addr.sin_family = AF_INET; |
|---|
| | 308 | client_addr.sin_addr = ip_r; |
|---|
| | 309 | client_addr.sin_port = port_r; |
|---|
| | 310 | |
|---|
| | 311 | /* connecting our udp socket enables us to use read() and write() */ |
|---|
| | 312 | if (connect |
|---|
| | 313 | (connection_fd, (struct sockaddr *) &client_addr, |
|---|
| | 314 | client_addr_len) < 0) { |
|---|
| | 315 | if (errno == EINTR) |
|---|
| | 316 | break; |
|---|
| | 317 | else { |
|---|
| | 318 | logmsg(LOG_ERR, 1, |
|---|
| | 319 | " %s Error - Could not connect udp socket: %s\n", |
|---|
| | 320 | portstr, strerror(errno)); |
|---|
| | 321 | close(mirror_sock_fd); |
|---|
| | 322 | free(attack); |
|---|
| | 323 | exit(EXIT_FAILURE); |
|---|
| | 324 | } |
|---|
| | 325 | } |
|---|
| | 326 | |
|---|
| | 327 | /* update remote endpoint information for attack structure */ |
|---|
| | 328 | if (getpeername |
|---|
| | 329 | (connection_fd, (struct sockaddr *) &client_addr, |
|---|
| | 330 | &client_addr_len) < 0) { |
|---|
| | 331 | if (errno == EINTR) |
|---|
| | 332 | break; |
|---|
| | 333 | else { |
|---|
| | 334 | logmsg(LOG_ERR, 1, |
|---|
| | 335 | " %s Error - Could not get remote host information: %s\n", |
|---|
| | 336 | portstr, strerror(errno)); |
|---|
| | 337 | close(mirror_sock_fd); |
|---|
| | 338 | free(attack); |
|---|
| | 339 | exit(EXIT_FAILURE); |
|---|
| | 340 | } |
|---|
| | 341 | } |
|---|
| | 342 | established = 1; |
|---|
| | 343 | break; |
|---|
| | 344 | default: |
|---|
| | 345 | logmsg(LOG_ERR, 1, "Error - Protocol %d not supported.\n", proto); |
|---|
| | 346 | exit(EXIT_FAILURE); |
|---|
| | 347 | } |
|---|
| | 348 | |
|---|
| | 349 | |
|---|
| | 350 | if (established) { |
|---|
| | 351 | /* connection successful established, fork handler process */ |
|---|
| | 352 | |
|---|
| | 353 | logmsg(LOG_NOTICE, 1, |
|---|
| | 354 | " %s Connection from %s:%u accepted.\n", |
|---|
| | 355 | portstr, inet_ntoa(client_addr.sin_addr), |
|---|
| | 356 | ntohs(client_addr.sin_port)); |
|---|
| | 357 | attack->a_conn.r_port = ntohs(client_addr.sin_port); |
|---|
| | 358 | |
|---|
| | 359 | if ((pid = fork()) == 0) { |
|---|
| | 360 | /* close listening socket in child */ |
|---|
| | 361 | close(listen_fd); |
|---|
| | 362 | disconnect = 0; |
|---|
| | 363 | total_bytes = 0; |
|---|
| | 364 | |
|---|
| | 365 | if ((proxy_this) || (port_mode & PORTCONF_PROXY)) { |
|---|
| | 366 | logmsg(LOG_DEBUG, 1, |
|---|
| | 367 | " %s Handling connection from %s:%u in proxy mode.\n", |
|---|
| | 368 | portstr, |
|---|
| | 369 | inet_ntoa(client_addr.sin_addr), |
|---|
| | 370 | ntohs(client_addr.sin_port)); |
|---|
| | 371 | handle_connection_proxied(connection_fd, |
|---|
| | 372 | PORTCONF_PROXY, |
|---|
| | 373 | proxy_sock_fd, (uint16_t) |
|---|
| | 374 | ntohs(port_l), |
|---|
| | 375 | client_addr.sin_port, |
|---|
| | 376 | client_addr.sin_addr, |
|---|
| | 377 | proto, |
|---|
| | 378 | m_read_timeout, |
|---|
| | 379 | read_timeout, attack); |
|---|
| | 380 | } else if ((mirror_this) |
|---|
| | 381 | || (port_mode & PORTCONF_MIRROR)) { |
|---|
| | 382 | logmsg(LOG_DEBUG, 1, |
|---|
| | 383 | " %s Handling connection from %s:%u in mirror mode.\n", |
|---|
| | 384 | portstr, |
|---|
| | 385 | inet_ntoa(client_addr.sin_addr), |
|---|
| | 386 | ntohs(client_addr.sin_port)); |
|---|
| | 387 | handle_connection_proxied(connection_fd, |
|---|
| | 388 | PORTCONF_MIRROR, |
|---|
| | 389 | mirror_sock_fd, (uint16_t) |
|---|
| | 390 | ntohs(port_l), |
|---|
| | 391 | client_addr.sin_port, |
|---|
| | 392 | client_addr.sin_addr, |
|---|
| | 393 | proto, |
|---|
| | 394 | m_read_timeout, |
|---|
| | 395 | read_timeout, attack); |
|---|
| | 396 | } else { |
|---|
| | 397 | logmsg(LOG_DEBUG, 1, |
|---|
| | 398 | " %s Handling connection from %s:%u in normal mode.\n", |
|---|
| | 399 | portstr, |
|---|
| | 400 | inet_ntoa(client_addr.sin_addr), |
|---|
| | 401 | ntohs(client_addr.sin_port)); |
|---|
| | 402 | handle_connection_normal(connection_fd, (uint16_t) |
|---|
| | 403 | ntohs(port_l), proto, |
|---|
| | 404 | read_timeout, attack); |
|---|
| | 405 | } |
|---|
| | 406 | free(attack); |
|---|
| | 407 | exit(EXIT_SUCCESS); |
|---|
| | 408 | |
|---|
| | 409 | } else if (pid == -1) |
|---|
| | 410 | logmsg(LOG_ERR, 1, |
|---|
| | 411 | "Error - forking connection handler failed.\n"); |
|---|
| | 412 | close(mirror_sock_fd); |
|---|
| | 413 | close(connection_fd); |
|---|
| | 414 | free(attack); |
|---|
| | 415 | } /* connection accepted */ |
|---|
| | 416 | } /* FD_ISSET - incoming connection */ |
|---|
| | 417 | } /* select return for listen_fd */ |
|---|
| | 418 | } /* for - incoming connections */ |
|---|
| | 419 | } /* fork - server process */ |
|---|
| | 420 | else if (pid == -1) logmsg(LOG_ERR, 1, "Error - forking server process failed.\n"); |
|---|
| | 421 | return; |
|---|
| | 422 | } |
|---|
| | 423 | |
|---|
| | 424 | |
|---|
| | 425 | /* handle connection in normal mode - respond with default answers */ |
|---|
| |
|---|