Use temporary socket for path MTU discovery

This commit is contained in:
Keith Winstein
2011-08-13 19:33:56 -04:00
parent f2f0cd574a
commit 3bac586a04
3 changed files with 18 additions and 12 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ repos = templates.rpo
executables = parse termemu ntester encrypt decrypt stm-server stm executables = parse termemu ntester encrypt decrypt stm-server stm
CXX = g++ CXX = g++
CXXFLAGS = -g -O2 --std=c++0x -pedantic -Werror -Wall -Wextra -Weffc++ -fno-implicit-templates -fno-default-inline -pipe -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_BSD_SOURCE CXXFLAGS = -g --std=c++0x -pedantic -Werror -Wall -Wextra -Weffc++ -fno-implicit-templates -fno-default-inline -pipe -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_BSD_SOURCE
LIBS = -lutil -lssl -lrt -lm -lprotobuf-lite LIBS = -lutil -lssl -lrt -lm -lprotobuf-lite
PROTOC = protoc PROTOC = protoc
+15 -10
View File
@@ -136,13 +136,23 @@ Connection::Connection( const char *key_str, const char *ip, int port ) /* clien
void Connection::update_MTU( void ) void Connection::update_MTU( void )
{ {
/* Temporarily connect socket so we can retrieve path MTU */ if ( !attached ) {
if ( connect( sock, (sockaddr *)&remote_addr, sizeof( remote_addr ) ) < 0 ) { return;
}
/* We don't want to use our main socket because we don't want to have to connect it */
int path_MTU_socket = socket( AF_INET, SOCK_DGRAM, 0 );
if ( path_MTU_socket < 0 ) {
throw NetworkException( "socket", errno );
}
/* Connect socket so we can retrieve path MTU */
if ( connect( path_MTU_socket, (sockaddr *)&remote_addr, sizeof( remote_addr ) ) < 0 ) {
throw NetworkException( "connect", errno ); throw NetworkException( "connect", errno );
} }
socklen_t optlen = sizeof( MTU ); socklen_t optlen = sizeof( MTU );
if ( getsockopt( sock, IPPROTO_IP, IP_MTU, &MTU, &optlen ) < 0 ) { if ( getsockopt( path_MTU_socket, IPPROTO_IP, IP_MTU, &MTU, &optlen ) < 0 ) {
throw NetworkException( "getsockopt", errno ); throw NetworkException( "getsockopt", errno );
} }
@@ -150,14 +160,9 @@ void Connection::update_MTU( void )
throw NetworkException( "Error getting path MTU", errno ); throw NetworkException( "Error getting path MTU", errno );
} }
/* Disconnect socket */ if ( close( path_MTU_socket ) < 0 ) {
struct sockaddr disconnect; throw NetworkException( "close", errno );
disconnect.sa_family = AF_UNSPEC;
if ( connect( sock, (sockaddr *)&disconnect, sizeof( disconnect ) ) < 0 ) {
throw NetworkException( "connect", errno );
} }
} }
void Connection::send( string &s, bool send_timestamp ) void Connection::send( string &s, bool send_timestamp )
+2 -1
View File
@@ -180,7 +180,8 @@ void client( const char *ip, int port, const char *key )
if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents) if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents)
& (POLLERR | POLLHUP | POLLNVAL) ) { & (POLLERR | POLLHUP | POLLNVAL) ) {
break; perror( "poll" );
// break;
} }
} }
} }