udpint.c (xinetd-2.3.15) | : | udpint.c (xinetd-2.3.15.4.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 17 | skipping to change at line 17 | |||
#include "config.h" | #include "config.h" | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <sys/socket.h> | #include <sys/socket.h> | |||
#include <netinet/in.h> | #include <netinet/in.h> | |||
#include <arpa/inet.h> | #include <arpa/inet.h> | |||
#include <netdb.h> | #include <netdb.h> | |||
#include <sys/time.h> | #include <sys/time.h> | |||
#include <syslog.h> | #include <syslog.h> | |||
#include <errno.h> | #include <errno.h> | |||
#ifdef HAVE_SYS_SELECT_H | ||||
#include <sys/select.h> | #include <sys/select.h> | |||
#ifdef HAVE_POLL | ||||
#include <poll.h> | ||||
#endif | #endif | |||
#include "udpint.h" | #include "udpint.h" | |||
#include "intcommon.h" | #include "intcommon.h" | |||
#include "util.h" | #include "util.h" | |||
#include "connection.h" | #include "connection.h" | |||
#include "access.h" | #include "access.h" | |||
#include "log.h" | #include "log.h" | |||
#include "msg.h" | #include "msg.h" | |||
#include "sconf.h" | #include "sconf.h" | |||
skipping to change at line 94 | skipping to change at line 94 | |||
drain( INT_REMOTE( ip ) ) ; | drain( INT_REMOTE( ip ) ) ; | |||
int_exit( ip ) ; | int_exit( ip ) ; | |||
} | } | |||
/* | /* | |||
* Returns only if there is an I/O error while communicating with the server | * Returns only if there is an I/O error while communicating with the server | |||
*/ | */ | |||
static void di_mux(void) | static void di_mux(void) | |||
{ | { | |||
struct intercept_s *ip = &dgram_intercept_state ; | struct intercept_s *ip = &dgram_intercept_state ; | |||
#ifdef HAVE_POLL | ||||
struct pollfd *pfd_array; | ||||
int pfds_last = 0; | ||||
#else | ||||
fd_set socket_mask ; | fd_set socket_mask ; | |||
int mask_max ; | int mask_max ; | |||
#endif | ||||
#ifdef HAVE_POLL | ||||
pfd_array = (struct pollfd *)calloc(sizeof(struct pollfd),MAX_FDS); | ||||
pfd_array[ pfds_last ].fd = INT_REMOTE( ip ); | ||||
pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT; | ||||
#else | ||||
FD_ZERO( &socket_mask ) ; | FD_ZERO( &socket_mask ) ; | |||
FD_SET( INT_REMOTE( ip ), &socket_mask ) ; | FD_SET( INT_REMOTE( ip ), &socket_mask ) ; | |||
mask_max = INT_REMOTE( ip ) ; | mask_max = INT_REMOTE( ip ) ; | |||
#endif | ||||
for ( ;; ) | for ( ;; ) | |||
{ | { | |||
unsigned u ; | unsigned u ; | |||
channel_s *chp ; | channel_s *chp ; | |||
#ifndef HAVE_POLL | ||||
fd_set read_mask ; | fd_set read_mask ; | |||
#endif | ||||
int n_ready ; | int n_ready ; | |||
#ifdef HAVE_POLL | ||||
n_ready = int_poll( pfds_last, pfd_array ) ; | ||||
#else | ||||
read_mask = socket_mask ; | read_mask = socket_mask ; | |||
n_ready = int_select( mask_max+1, &read_mask ) ; | n_ready = int_select( mask_max+1, &read_mask ) ; | |||
#endif | ||||
if ( n_ready == -1 ) | if ( n_ready == -1 ) | |||
return ; | return ; | |||
#ifdef HAVE_POLL | ||||
if ( pfd_array[0].revents & ( POLLIN | POLLOUT ) ) | ||||
#else | ||||
if ( FD_ISSET( INT_REMOTE( ip ), &read_mask ) ) | if ( FD_ISSET( INT_REMOTE( ip ), &read_mask ) ) | |||
#endif | ||||
{ | { | |||
udp_remote_to_local( ip, &chp ) ; | udp_remote_to_local( ip, &chp ) ; | |||
if ( chp != NULL ) | if ( chp != NULL ) | |||
{ | { | |||
#ifdef HAVE_POLL | ||||
pfd_array[ pfds_last ].fd = chp->ch_local_socket ; | ||||
pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT ; | ||||
#else | ||||
FD_SET( chp->ch_local_socket, &socket_mask ) ; | FD_SET( chp->ch_local_socket, &socket_mask ) ; | |||
if ( chp->ch_local_socket > mask_max ) | if ( chp->ch_local_socket > mask_max ) | |||
mask_max = chp->ch_local_socket ; | mask_max = chp->ch_local_socket ; | |||
#endif | ||||
} | } | |||
if ( --n_ready == 0 ) | if ( --n_ready == 0 ) | |||
continue ; | continue ; | |||
} | } | |||
for ( u = 0 ; u < pset_count( INT_CONNECTIONS( ip ) ) ; u++ ) | for ( u = 0 ; u < pset_count( INT_CONNECTIONS( ip ) ) ; u++ ) | |||
{ | { | |||
chp = CHP( pset_pointer( INT_CONNECTIONS( ip ), u ) ) ; | chp = CHP( pset_pointer( INT_CONNECTIONS( ip ), u ) ) ; | |||
#ifdef HAVE_POLL | ||||
int i; | ||||
/* TODO: detection with O(n)=1 */ | ||||
for (i = 0 ; i < pfds_last ; i++) | ||||
if (pfd_array[i].fd == chp->ch_local_socket) | ||||
break; | ||||
if (pfd_array[i].fd == chp->ch_local_socket && | ||||
(pfd_array[i].revents & ( POLLIN | POLLOUT ))) | ||||
#else | ||||
if ( FD_ISSET( chp->ch_local_socket, &read_mask ) ) | if ( FD_ISSET( chp->ch_local_socket, &read_mask ) ) | |||
#endif | ||||
{ | { | |||
if ( udp_local_to_remote( chp ) == FAILED ) | if ( udp_local_to_remote( chp ) == FAILED ) | |||
return ; | return ; | |||
if ( --n_ready == 0 ) | if ( --n_ready == 0 ) | |||
break ; | break ; | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
skipping to change at line 206 | skipping to change at line 242 | |||
*chpp = chp ; | *chpp = chp ; | |||
} | } | |||
else if ( chp->ch_state == BAD_CHANNEL ) | else if ( chp->ch_state == BAD_CHANNEL ) | |||
return ; | return ; | |||
#ifdef DEBUG_UDPINT | #ifdef DEBUG_UDPINT | |||
if ( debug.on ) | if ( debug.on ) | |||
msg( LOG_DEBUG, "udp_remote_to_local", | msg( LOG_DEBUG, "udp_remote_to_local", | |||
"sending %d bytes to server on port %d", | "sending %d bytes to server on port %d", | |||
packet.size, ntohs( INT_LOCALADDR( ip )->sin_port ) ) ; | packet.size, ntohs( INT_LOCALADDR( ip )->sa_in.sin_port ) ) ; | |||
#endif | #endif | |||
send_data( chp->ch_local_socket, | send_data( chp->ch_local_socket, | |||
packet.data, packet.size, NULL ) ; | packet.data, packet.size, NULL ) ; | |||
} | } | |||
/* | /* | |||
* Send the data in buf to destination addr using the socket sd. | * Send the data in buf to destination addr using the socket sd. | |||
* If addr is NULL, use the default socket destination | * If addr is NULL, use the default socket destination | |||
*/ | */ | |||
End of changes. 17 change blocks. | ||||
3 lines changed or deleted | 39 lines changed or added |