Prepare udp connection id generation and checking

dynamic-accesslists
erdgeist 17 years ago
parent 65c3b24045
commit 8d00b1e039

@ -4,6 +4,7 @@
/* System */ /* System */
#include <string.h> #include <string.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <stdio.h>
/* Libowfat */ /* Libowfat */
#include "socket.h" #include "socket.h"
@ -17,6 +18,24 @@
static char static_inbuf[8192]; static char static_inbuf[8192];
static char static_outbuf[8192]; static char static_outbuf[8192];
static const uint8_t g_static_connid[8] = { 0x23, 0x42, 0x05, 0x17, 0xde, 0x41, 0x50, 0xff };
static void udp_make_connectionid( uint32_t * connid, const char * remoteip ) {
/* Touch unused variable */
remoteip = remoteip;
/* Use a static secret for now */
memcpy( connid, g_static_connid, 8 );
}
static int udp_test_connectionid( const uint32_t * const connid, const char * remoteip ) {
/* Touch unused variable */
remoteip = remoteip;
/* Test against our static secret */
return !memcmp( connid, g_static_connid, 8 );
}
/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */ /* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */
void handle_udp4( int64 serversocket ) { void handle_udp4( int64 serversocket ) {
ot_peer peer; ot_peer peer;
@ -44,8 +63,9 @@ void handle_udp4( int64 serversocket ) {
switch( ntohl( inpacket[2] ) ) { switch( ntohl( inpacket[2] ) ) {
case 0: /* This is a connect action */ case 0: /* This is a connect action */
outpacket[0] = 0; outpacket[1] = inpacket[3]; outpacket[0] = 0;
outpacket[2] = inpacket[0]; outpacket[3] = inpacket[1]; outpacket[1] = inpacket[3];
udp_make_connectionid( outpacket + 2, remoteip );
socket_send4( serversocket, static_outbuf, 16, remoteip, remoteport ); socket_send4( serversocket, static_outbuf, 16, remoteip, remoteport );
stats_issue_event( EVENT_CONNECT, 0, 16 ); stats_issue_event( EVENT_CONNECT, 0, 16 );
break; break;
@ -54,6 +74,9 @@ void handle_udp4( int64 serversocket ) {
if( r < 98 ) if( r < 98 )
return; return;
if( !udp_test_connectionid( inpacket, remoteip ))
fprintf( stderr, "UDP Connection id missmatch\n" );
numwant = 200; numwant = 200;
/* We do only want to know, if it is zero */ /* We do only want to know, if it is zero */
left = inpacket[64/4] | inpacket[68/4]; left = inpacket[64/4] | inpacket[68/4];
@ -93,6 +116,9 @@ void handle_udp4( int64 serversocket ) {
break; break;
case 2: /* This is a scrape action */ case 2: /* This is a scrape action */
if( !udp_test_connectionid( inpacket, remoteip ))
fprintf( stderr, "UDP Connection id missmatch\n" );
outpacket[0] = htonl( 2 ); /* scrape action */ outpacket[0] = htonl( 2 ); /* scrape action */
outpacket[1] = inpacket[12/4]; outpacket[1] = inpacket[12/4];

Loading…
Cancel
Save