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
*/
2015-10-26 08:50:46 +03:00
# include "replace.h"
2006-11-28 03:51:33 +03:00
# include "system/network.h"
# include "system/filesys.h"
2015-10-26 08:50:46 +03:00
# include "lib/util/dlinklist.h"
# include "lib/util/debug.h"
# include "ctdb_private.h"
2015-10-23 06:17:34 +03:00
# include "common/common.h"
2015-11-11 07:22:52 +03:00
# include "common/logging.h"
2015-10-23 06:17:34 +03:00
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
{
2019-08-09 08:29:36 +03:00
struct ctdb_tcp_node * tnode = talloc_get_type_abort (
args , struct ctdb_tcp_node ) ;
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 ( 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
}
2014-10-21 04:53:29 +04:00
if ( hdr - > ctdb_version ! = CTDB_PROTOCOL ) {
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 */
2019-08-09 08:29:36 +03:00
tnode - > ctdb - > upcalls - > recv_pkt ( tnode - > ctdb , data , cnt ) ;
2007-05-26 10:32:32 +04:00
return ;
failed :
2019-08-09 08:29:36 +03:00
TALLOC_FREE ( tnode - > in_queue ) ;
close ( tnode - > in_fd ) ;
tnode - > in_fd = - 1 ;
2018-03-13 11:34:52 +03:00
TALLOC_FREE ( data ) ;
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 ) ;
2019-08-15 08:57:31 +03:00
if ( tnode - > out_queue = = NULL ) {
DBG_DEBUG ( " No outgoing connection, dropping packet \n " ) ;
return 0 ;
}
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
}