2006-11-28 03:51:33 +03:00
/*
ctdb over TCP
Copyright ( C ) Andrew Tridgell 2006
2007-05-31 07:50:53 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 09:29:31 +04:00
the Free Software Foundation ; either version 3 of the License , or
2007-05-31 07:50:53 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
2006-11-28 03:51:33 +03:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2007-05-31 07:50:53 +04:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 09:29:31 +04:00
along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2006-11-28 03:51:33 +03:00
*/
# include "includes.h"
2007-01-23 03:38:45 +03:00
# include "lib/util/dlinklist.h"
2013-06-06 23:58:02 +04:00
# include "tdb.h"
2006-11-28 03:51:33 +03:00
# include "system/network.h"
# include "system/filesys.h"
2007-01-23 03:38:45 +03:00
# include "../include/ctdb_private.h"
2006-11-28 03:51:33 +03:00
# include "ctdb_tcp.h"
2006-12-19 04:03:10 +03:00
2006-11-28 06:15:46 +03:00
/*
2007-04-10 13:33:21 +04:00
called when a complete packet has come in
*/
void ctdb_tcp_read_cb ( uint8_t * data , size_t cnt , void * args )
2006-11-28 06:15:46 +03:00
{
2007-04-10 13:33:21 +04:00
struct ctdb_incoming * in = talloc_get_type ( args , struct ctdb_incoming ) ;
2007-05-26 10:32:32 +04:00
struct ctdb_req_header * hdr = ( struct ctdb_req_header * ) data ;
2006-11-28 06:15:46 +03:00
2007-04-10 13:33:21 +04:00
if ( data = = NULL ) {
/* incoming socket has died */
2007-05-26 10:32:32 +04:00
goto failed ;
2006-11-28 06:15:46 +03:00
}
2007-04-10 07:17:15 +04:00
if ( cnt < sizeof ( * hdr ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ALERT , ( __location__ " Bad packet length %u \n " , ( unsigned ) cnt ) ) ;
2007-05-26 10:32:32 +04:00
goto failed ;
2006-11-28 06:15:46 +03:00
}
2007-05-26 10:32:32 +04:00
if ( cnt & ( CTDB_TCP_ALIGNMENT - 1 ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ALERT , ( __location__ " Length 0x%x not multiple of alignment \n " ,
2007-05-29 07:58:41 +04:00
( unsigned ) cnt ) ) ;
2007-05-26 10:32:32 +04:00
goto failed ;
}
2007-04-10 07:17:15 +04:00
if ( cnt ! = hdr - > length ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ALERT , ( __location__ " Bad header length %u expected %u \n " ,
2007-05-26 10:32:32 +04:00
( unsigned ) hdr - > length , ( unsigned ) cnt ) ) ;
goto failed ;
2006-11-28 03:51:33 +03:00
}
2006-11-28 06:15:46 +03:00
2007-04-10 07:17:15 +04:00
if ( hdr - > ctdb_magic ! = CTDB_MAGIC ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ALERT , ( __location__ " Non CTDB packet 0x%x rejected \n " ,
2007-05-26 10:32:32 +04:00
hdr - > ctdb_magic ) ) ;
goto failed ;
2006-11-28 06:15:46 +03:00
}
2007-04-10 07:17:15 +04:00
if ( hdr - > ctdb_version ! = CTDB_VERSION ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ALERT , ( __location__ " Bad CTDB version 0x%x rejected \n " ,
2007-05-26 10:32:32 +04:00
hdr - > ctdb_version ) ) ;
goto failed ;
2006-12-19 04:03:10 +03:00
}
2007-05-26 10:32:32 +04:00
/* tell the ctdb layer above that we have a packet */
2007-04-10 07:17:15 +04:00
in - > ctdb - > upcalls - > recv_pkt ( in - > ctdb , data , cnt ) ;
2007-05-26 10:32:32 +04:00
return ;
failed :
talloc_free ( in ) ;
2007-04-10 07:17:15 +04:00
}
2006-12-19 04:03:10 +03:00
2006-11-28 06:15:46 +03:00
/*
queue a packet for sending
*/
int ctdb_tcp_queue_pkt ( struct ctdb_node * node , uint8_t * data , uint32_t length )
{
2007-04-11 22:12:15 +04:00
struct ctdb_tcp_node * tnode = talloc_get_type ( node - > private_data ,
2006-11-28 06:15:46 +03:00
struct ctdb_tcp_node ) ;
2007-07-02 08:26:50 +04:00
return ctdb_queue_send ( tnode - > out_queue , data , length ) ;
2006-11-28 06:15:46 +03:00
}