This commit is contained in:
Keith Winstein
2011-08-03 21:20:44 -04:00
parent 829d060fbb
commit 7ea81ca237
3 changed files with 35 additions and 4 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
static void dos_detected( const char *expression, const char *file, int line, const char *function )
{
fprintf( stderr, "Illegal counterparty input (possible DOS) in function %s at %s:%d, failed test: %s\n",
fprintf( stderr, "Illegal counterparty input (possible denial of service) in function %s at %s:%d, failed test: %s\n",
function, file, line, expression );
exit( 1 );
}
+29 -1
View File
@@ -60,7 +60,8 @@ Connection<Outgoing, Incoming>::Connection( bool s_server )
sock( -1 ),
remote_addr(),
server( s_server ),
attached( false )
attached( false ),
MTU( RECEIVE_MTU )
{
/* create socket */
@@ -80,6 +81,31 @@ Connection<Outgoing, Incoming>::Connection( bool s_server )
perror( "bind" );
exit( 1 );
}
/* Enable path MTU discovery */
char flag = IP_PMTUDISC_DO;
socklen_t optlen = sizeof( flag );
if ( setsockopt( sock, IPPROTO_IP, IP_MTU_DISCOVER, &flag, optlen ) < 0 ) {
perror( "setsockopt" );
exit( 1 );
}
}
template <class Outgoing, class Incoming>
void Connection<Outgoing, Incoming>::update_MTU( void )
{
socklen_t optlen = sizeof( MTU );
if ( getsockopt( sock, IPPROTO_IP, IP_MTU, &MTU, &optlen ) < 0 ) {
perror( "getsockopt" );
exit( 1 );
}
if ( optlen != sizeof( MTU ) ) {
fprintf( stderr, "Error getting path MTU.\n" );
exit( 1 );
}
fprintf( stderr, "Path MTU: %d\n", MTU );
}
template <class Outgoing, class Incoming>
@@ -115,6 +141,8 @@ void Connection<Outgoing, Incoming>::send( Outgoing &s )
perror( "sendto" );
exit( 1 );
}
update_MTU();
}
template <class Outgoing, class Incoming>
+5 -2
View File
@@ -49,10 +49,9 @@ namespace Network {
uint64_t next_seq;
const Direction direction;
int MTU;
Flow( Direction s_direction )
: next_seq( 0 ), direction( s_direction ), MTU( 2048 )
: next_seq( 0 ), direction( s_direction )
{}
Packet new_packet( Payload &s_payload );
@@ -71,6 +70,10 @@ namespace Network {
bool server;
bool attached;
int MTU;
void update_MTU( void );
public:
Connection( bool s_server );