flooder.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /**
  2. * @file flooder.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <protocol/addr.h>
  27. #include <protocol/scproto.h>
  28. #include <misc/loglevel.h>
  29. #include <misc/version.h>
  30. #include <misc/nsskey.h>
  31. #include <misc/byteorder.h>
  32. #include <misc/loggers_string.h>
  33. #include <misc/dead.h>
  34. #include <system/BLog.h>
  35. #include <system/BReactor.h>
  36. #include <system/BSignal.h>
  37. #include <flow/SinglePacketBuffer.h>
  38. #include <flow/PacketProtoEncoder.h>
  39. #include <nspr_support/DummyPRFileDesc.h>
  40. #include <nspr_support/BSocketPRFileDesc.h>
  41. #include <server_connection/ServerConnection.h>
  42. #ifndef BADVPN_USE_WINAPI
  43. #include <system/BLog_syslog.h>
  44. #endif
  45. #include <flooder/flooder.h>
  46. #include <generated/blog_channel_flooder.h>
  47. #define LOGGER_STDOUT 1
  48. #define LOGGER_SYSLOG 2
  49. // program dead variable
  50. dead_t dead;
  51. // command-line options
  52. struct {
  53. int help;
  54. int version;
  55. int logger;
  56. #ifndef BADVPN_USE_WINAPI
  57. char *logger_syslog_facility;
  58. char *logger_syslog_ident;
  59. #endif
  60. int loglevel;
  61. int loglevels[BLOG_NUM_CHANNELS];
  62. int ssl;
  63. char *nssdb;
  64. char *client_cert_name;
  65. char *server_name;
  66. char *server_addr;
  67. peerid_t floods[MAX_FLOODS];
  68. int num_floods;
  69. } options;
  70. // server address we connect to
  71. BAddr server_addr;
  72. // server name to use for SSL
  73. char server_name[256];
  74. // reactor
  75. BReactor ss;
  76. // client certificate if using SSL
  77. CERTCertificate *client_cert;
  78. // client private key if using SSL
  79. SECKEYPrivateKey *client_key;
  80. // server connection
  81. ServerConnection server;
  82. // whether server is ready
  83. int server_ready;
  84. // my ID, defined only after server_ready
  85. peerid_t my_id;
  86. // flooding output
  87. PacketRecvInterface flood_source;
  88. PacketProtoEncoder flood_encoder;
  89. SinglePacketBuffer flood_buffer;
  90. // whether we were asked for a packet and blocked
  91. int flood_blocking;
  92. // index of next peer to send packet too
  93. int flood_next;
  94. /**
  95. * Cleans up everything that can be cleaned up from inside the event loop.
  96. */
  97. static void terminate (void);
  98. /**
  99. * Prints command line help.
  100. */
  101. static void print_help (const char *name);
  102. /**
  103. * Prints program name, version and copyright notice.
  104. */
  105. static void print_version (void);
  106. /**
  107. * Parses command line options into the options strucute.
  108. *
  109. * @return 1 on success, 0 on failure
  110. */
  111. static int parse_arguments (int argc, char *argv[]);
  112. /**
  113. * Processes command line options.
  114. *
  115. * @return 1 on success, 0 on failure
  116. */
  117. static int resolve_arguments (void);
  118. /**
  119. * Handler invoked when program termination is requested.
  120. */
  121. static void signal_handler (void *unused);
  122. static void server_handler_error (void *user);
  123. static void server_handler_ready (void *user, peerid_t param_my_id, uint32_t ext_ip);
  124. static void server_handler_newclient (void *user, peerid_t peer_id, int flags, const uint8_t *cert, int cert_len);
  125. static void server_handler_endclient (void *user, peerid_t peer_id);
  126. static void server_handler_message (void *user, peerid_t peer_id, uint8_t *data, int data_len);
  127. static int flood_source_handler_recv (void *user, uint8_t *data, int *data_len);
  128. int main (int argc, char *argv[])
  129. {
  130. if (argc <= 0) {
  131. return 1;
  132. }
  133. // init dead variable
  134. DEAD_INIT(dead);
  135. // parse command-line arguments
  136. if (!parse_arguments(argc, argv)) {
  137. fprintf(stderr, "Failed to parse arguments\n");
  138. print_help(argv[0]);
  139. goto fail0;
  140. }
  141. // handle --help and --version
  142. if (options.help) {
  143. print_version();
  144. print_help(argv[0]);
  145. return 0;
  146. }
  147. if (options.version) {
  148. print_version();
  149. return 0;
  150. }
  151. // initialize logger
  152. switch (options.logger) {
  153. case LOGGER_STDOUT:
  154. BLog_InitStdout();
  155. break;
  156. #ifndef BADVPN_USE_WINAPI
  157. case LOGGER_SYSLOG:
  158. if (!BLog_InitSyslog(options.logger_syslog_ident, options.logger_syslog_facility)) {
  159. fprintf(stderr, "Failed to initialize syslog logger\n");
  160. goto fail0;
  161. }
  162. break;
  163. #endif
  164. default:
  165. ASSERT(0);
  166. }
  167. // configure logger channels
  168. for (int i = 0; i < BLOG_NUM_CHANNELS; i++) {
  169. if (options.loglevels[i] >= 0) {
  170. BLog_SetChannelLoglevel(i, options.loglevels[i]);
  171. }
  172. else if (options.loglevel >= 0) {
  173. BLog_SetChannelLoglevel(i, options.loglevel);
  174. }
  175. }
  176. BLog(BLOG_NOTICE, "initializing "GLOBAL_PRODUCT_NAME" client "GLOBAL_VERSION);
  177. // initialize sockets
  178. if (BSocket_GlobalInit() < 0) {
  179. BLog(BLOG_ERROR, "BSocket_GlobalInit failed");
  180. goto fail1;
  181. }
  182. // init time
  183. BTime_Init();
  184. // resolve addresses
  185. if (!resolve_arguments()) {
  186. BLog(BLOG_ERROR, "Failed to resolve arguments");
  187. goto fail1;
  188. }
  189. // init reactor
  190. if (!BReactor_Init(&ss)) {
  191. BLog(BLOG_ERROR, "BReactor_Init failed");
  192. goto fail1;
  193. }
  194. // setup signal handler
  195. if (!BSignal_Init()) {
  196. BLog(BLOG_ERROR, "BSignal_Init failed");
  197. goto fail1a;
  198. }
  199. BSignal_Capture();
  200. if (!BSignal_SetHandler(&ss, signal_handler, NULL)) {
  201. BLog(BLOG_ERROR, "BSignal_SetHandler failed");
  202. goto fail1a;
  203. }
  204. if (options.ssl) {
  205. // init NSPR
  206. PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  207. // register local NSPR file types
  208. if (!DummyPRFileDesc_GlobalInit()) {
  209. BLog(BLOG_ERROR, "DummyPRFileDesc_GlobalInit failed");
  210. goto fail2;
  211. }
  212. if (!BSocketPRFileDesc_GlobalInit()) {
  213. BLog(BLOG_ERROR, "BSocketPRFileDesc_GlobalInit failed");
  214. goto fail2;
  215. }
  216. // init NSS
  217. if (NSS_Init(options.nssdb) != SECSuccess) {
  218. BLog(BLOG_ERROR, "NSS_Init failed (%d)", (int)PR_GetError());
  219. goto fail2;
  220. }
  221. // set cipher policy
  222. if (NSS_SetDomesticPolicy() != SECSuccess) {
  223. BLog(BLOG_ERROR, "NSS_SetDomesticPolicy failed (%d)", (int)PR_GetError());
  224. goto fail3;
  225. }
  226. // init server cache
  227. if (SSL_ConfigServerSessionIDCache(0, 0, 0, NULL) != SECSuccess) {
  228. BLog(BLOG_ERROR, "SSL_ConfigServerSessionIDCache failed (%d)", (int)PR_GetError());
  229. goto fail3;
  230. }
  231. // open server certificate and private key
  232. if (!open_nss_cert_and_key(options.client_cert_name, &client_cert, &client_key)) {
  233. BLog(BLOG_ERROR, "Cannot open certificate and key");
  234. goto fail4;
  235. }
  236. }
  237. // start connecting to server
  238. if (!ServerConnection_Init(
  239. &server, &ss, server_addr, SC_KEEPALIVE_INTERVAL, SERVER_BUFFER_MIN_PACKETS, options.ssl, client_cert, client_key, server_name, NULL,
  240. server_handler_error, server_handler_ready, server_handler_newclient, server_handler_endclient, server_handler_message
  241. )) {
  242. BLog(BLOG_ERROR, "ServerConnection_Init failed");
  243. goto fail5;
  244. }
  245. // set server not ready
  246. server_ready = 0;
  247. goto event_loop;
  248. // cleanup on error
  249. fail5:
  250. if (options.ssl) {
  251. CERT_DestroyCertificate(client_cert);
  252. SECKEY_DestroyPrivateKey(client_key);
  253. fail4:
  254. SSL_ShutdownServerSessionIDCache();
  255. fail3:
  256. SSL_ClearSessionCache();
  257. ASSERT_FORCE(NSS_Shutdown() == SECSuccess)
  258. fail2:
  259. ASSERT_FORCE(PR_Cleanup() == PR_SUCCESS)
  260. PL_ArenaFinish();
  261. }
  262. BSignal_RemoveHandler();
  263. fail1a:
  264. BReactor_Free(&ss);
  265. fail1:
  266. BLog(BLOG_ERROR, "initialization failed");
  267. BLog_Free();
  268. fail0:
  269. // finish objects
  270. DebugObjectGlobal_Finish();
  271. return 1;
  272. event_loop:
  273. // enter event loop
  274. BLog(BLOG_NOTICE, "entering event loop");
  275. int ret = BReactor_Exec(&ss);
  276. // free reactor
  277. BReactor_Free(&ss);
  278. // free logger
  279. BLog(BLOG_NOTICE, "exiting");
  280. BLog_Free();
  281. // finish objects
  282. DebugObjectGlobal_Finish();
  283. return ret;
  284. }
  285. void terminate (void)
  286. {
  287. BLog(BLOG_NOTICE, "tearing down");
  288. if (server_ready) {
  289. // free flooding
  290. // free buffer
  291. SinglePacketBuffer_Free(&flood_buffer);
  292. // free encoder
  293. PacketProtoEncoder_Free(&flood_encoder);
  294. // free source
  295. PacketRecvInterface_Free(&flood_source);
  296. }
  297. // free server
  298. ServerConnection_Free(&server);
  299. if (options.ssl) {
  300. // free client certificate and private key
  301. CERT_DestroyCertificate(client_cert);
  302. SECKEY_DestroyPrivateKey(client_key);
  303. // free server cache
  304. ASSERT_FORCE(SSL_ShutdownServerSessionIDCache() == SECSuccess)
  305. // free client cache
  306. SSL_ClearSessionCache();
  307. // free NSS
  308. ASSERT_FORCE(NSS_Shutdown() == SECSuccess)
  309. // free NSPR
  310. ASSERT_FORCE(PR_Cleanup() == PR_SUCCESS)
  311. PL_ArenaFinish();
  312. }
  313. // remove signal handler
  314. BSignal_RemoveHandler();
  315. // kill dead variable
  316. DEAD_KILL(dead);
  317. // exit reactor
  318. BReactor_Quit(&ss, 1);
  319. }
  320. void print_help (const char *name)
  321. {
  322. printf(
  323. "Usage:\n"
  324. " %s\n"
  325. " [--help]\n"
  326. " [--version]\n"
  327. " [--logger <"LOGGERS_STRING">]\n"
  328. #ifndef BADVPN_USE_WINAPI
  329. " (logger=syslog?\n"
  330. " [--syslog-facility <string>]\n"
  331. " [--syslog-ident <string>]\n"
  332. " )\n"
  333. #endif
  334. " [--loglevel <0-5/none/error/warning/notice/info/debug>]\n"
  335. " [--channel-loglevel <channel-name> <0-5/none/error/warning/notice/info/debug>] ...\n"
  336. " [--ssl --nssdb <string> --client-cert-name <string>]\n"
  337. " [--server-name <string>]\n"
  338. " --server-addr <addr>\n"
  339. " [--flood-id <id> ...]\n"
  340. "Address format is a.b.c.d:port (IPv4) or [addr]:port (IPv6).\n",
  341. name
  342. );
  343. }
  344. void print_version (void)
  345. {
  346. printf(GLOBAL_PRODUCT_NAME" "PROGRAM_NAME" "GLOBAL_VERSION"\n"GLOBAL_COPYRIGHT_NOTICE"\n");
  347. }
  348. int parse_arguments (int argc, char *argv[])
  349. {
  350. if (argc <= 0) {
  351. return 0;
  352. }
  353. options.help = 0;
  354. options.version = 0;
  355. options.logger = LOGGER_STDOUT;
  356. #ifndef BADVPN_USE_WINAPI
  357. options.logger_syslog_facility = "daemon";
  358. options.logger_syslog_ident = argv[0];
  359. #endif
  360. options.loglevel = -1;
  361. for (int i = 0; i < BLOG_NUM_CHANNELS; i++) {
  362. options.loglevels[i] = -1;
  363. }
  364. options.ssl = 0;
  365. options.nssdb = NULL;
  366. options.client_cert_name = NULL;
  367. options.server_name = NULL;
  368. options.server_addr = NULL;
  369. options.num_floods = 0;
  370. int i;
  371. for (i = 1; i < argc; i++) {
  372. char *arg = argv[i];
  373. if (!strcmp(arg, "--help")) {
  374. options.help = 1;
  375. }
  376. else if (!strcmp(arg, "--version")) {
  377. options.version = 1;
  378. }
  379. else if (!strcmp(arg, "--logger")) {
  380. if (1 >= argc - i) {
  381. fprintf(stderr, "%s: requires an argument\n", arg);
  382. return 0;
  383. }
  384. char *arg2 = argv[i + 1];
  385. if (!strcmp(arg2, "stdout")) {
  386. options.logger = LOGGER_STDOUT;
  387. }
  388. #ifndef BADVPN_USE_WINAPI
  389. else if (!strcmp(arg2, "syslog")) {
  390. options.logger = LOGGER_SYSLOG;
  391. }
  392. #endif
  393. else {
  394. fprintf(stderr, "%s: wrong argument\n", arg);
  395. return 0;
  396. }
  397. i++;
  398. }
  399. #ifndef BADVPN_USE_WINAPI
  400. else if (!strcmp(arg, "--syslog-facility")) {
  401. if (1 >= argc - i) {
  402. fprintf(stderr, "%s: requires an argument\n", arg);
  403. return 0;
  404. }
  405. options.logger_syslog_facility = argv[i + 1];
  406. i++;
  407. }
  408. else if (!strcmp(arg, "--syslog-ident")) {
  409. if (1 >= argc - i) {
  410. fprintf(stderr, "%s: requires an argument\n", arg);
  411. return 0;
  412. }
  413. options.logger_syslog_ident = argv[i + 1];
  414. i++;
  415. }
  416. #endif
  417. else if (!strcmp(arg, "--loglevel")) {
  418. if (1 >= argc - i) {
  419. fprintf(stderr, "%s: requires an argument\n", arg);
  420. return 0;
  421. }
  422. if ((options.loglevel = parse_loglevel(argv[i + 1])) < 0) {
  423. fprintf(stderr, "%s: wrong argument\n", arg);
  424. return 0;
  425. }
  426. i++;
  427. }
  428. else if (!strcmp(arg, "--channel-loglevel")) {
  429. if (2 >= argc - i) {
  430. fprintf(stderr, "%s: requires two arguments\n", arg);
  431. return 0;
  432. }
  433. int channel = BLogGlobal_GetChannelByName(argv[i + 1]);
  434. if (channel < 0) {
  435. fprintf(stderr, "%s: wrong channel argument\n", arg);
  436. return 0;
  437. }
  438. int loglevel = parse_loglevel(argv[i + 2]);
  439. if (loglevel < 0) {
  440. fprintf(stderr, "%s: wrong loglevel argument\n", arg);
  441. return 0;
  442. }
  443. options.loglevels[channel] = loglevel;
  444. i += 2;
  445. }
  446. else if (!strcmp(arg, "--ssl")) {
  447. options.ssl = 1;
  448. }
  449. else if (!strcmp(arg, "--nssdb")) {
  450. if (1 >= argc - i) {
  451. fprintf(stderr, "%s: requires an argument\n", arg);
  452. return 0;
  453. }
  454. options.nssdb = argv[i + 1];
  455. i++;
  456. }
  457. else if (!strcmp(arg, "--client-cert-name")) {
  458. if (1 >= argc - i) {
  459. fprintf(stderr, "%s: requires an argument\n", arg);
  460. return 0;
  461. }
  462. options.client_cert_name = argv[i + 1];
  463. i++;
  464. }
  465. else if (!strcmp(arg, "--server-name")) {
  466. if (1 >= argc - i) {
  467. fprintf(stderr, "%s: requires an argument\n", arg);
  468. return 0;
  469. }
  470. options.server_name = argv[i + 1];
  471. i++;
  472. }
  473. else if (!strcmp(arg, "--server-addr")) {
  474. if (1 >= argc - i) {
  475. fprintf(stderr, "%s: requires an argument\n", arg);
  476. return 0;
  477. }
  478. options.server_addr = argv[i + 1];
  479. i++;
  480. }
  481. else if (!strcmp(arg, "--flood-id")) {
  482. if (1 >= argc - i) {
  483. fprintf(stderr, "%s: requires an argument\n", arg);
  484. return 0;
  485. }
  486. if (options.num_floods == MAX_FLOODS) {
  487. fprintf(stderr, "%s: too many\n", arg);
  488. return 0;
  489. }
  490. options.floods[options.num_floods] = atoi(argv[i + 1]);
  491. options.num_floods++;
  492. i++;
  493. }
  494. else {
  495. fprintf(stderr, "unknown option: %s\n", arg);
  496. return 0;
  497. }
  498. }
  499. if (options.help || options.version) {
  500. return 1;
  501. }
  502. if (options.ssl != !!options.nssdb) {
  503. fprintf(stderr, "False: --ssl <=> --nssdb\n");
  504. return 0;
  505. }
  506. if (options.ssl != !!options.client_cert_name) {
  507. fprintf(stderr, "False: --ssl <=> --client-cert-name\n");
  508. return 0;
  509. }
  510. if (!options.server_addr) {
  511. fprintf(stderr, "False: --server-addr\n");
  512. return 0;
  513. }
  514. return 1;
  515. }
  516. int resolve_arguments (void)
  517. {
  518. // resolve server address
  519. ASSERT(options.server_addr)
  520. if (!BAddr_Parse(&server_addr, options.server_addr, server_name, sizeof(server_name))) {
  521. BLog(BLOG_ERROR, "server addr: BAddr_Parse failed");
  522. return 0;
  523. }
  524. if (!addr_supported(server_addr)) {
  525. BLog(BLOG_ERROR, "server addr: not supported");
  526. return 0;
  527. }
  528. // override server name if requested
  529. if (options.server_name) {
  530. snprintf(server_name, sizeof(server_name), "%s", options.server_name);
  531. }
  532. return 1;
  533. }
  534. void signal_handler (void *unused)
  535. {
  536. BLog(BLOG_NOTICE, "termination requested");
  537. terminate();
  538. }
  539. void server_handler_error (void *user)
  540. {
  541. BLog(BLOG_ERROR, "server connection failed, exiting");
  542. terminate();
  543. }
  544. void server_handler_ready (void *user, peerid_t param_my_id, uint32_t ext_ip)
  545. {
  546. ASSERT(!server_ready)
  547. // remember our ID
  548. my_id = param_my_id;
  549. // init flooding
  550. // init source
  551. PacketRecvInterface_Init(&flood_source, SC_MAX_ENC, flood_source_handler_recv, NULL);
  552. // init encoder
  553. PacketProtoEncoder_Init(&flood_encoder, &flood_source);
  554. // init buffer
  555. if (!SinglePacketBuffer_Init(&flood_buffer, PacketProtoEncoder_GetOutput(&flood_encoder), ServerConnection_GetSendInterface(&server), BReactor_PendingGroup(&ss))) {
  556. BLog(BLOG_ERROR, "SinglePacketBuffer_Init failed, exiting");
  557. goto fail1;
  558. }
  559. // set not blocking
  560. flood_blocking = 0;
  561. // set server ready
  562. server_ready = 1;
  563. BLog(BLOG_INFO, "server: ready, my ID is %d", (int)my_id);
  564. return;
  565. fail1:
  566. PacketProtoEncoder_Free(&flood_encoder);
  567. PacketRecvInterface_Free(&flood_source);
  568. terminate();
  569. }
  570. void server_handler_newclient (void *user, peerid_t peer_id, int flags, const uint8_t *cert, int cert_len)
  571. {
  572. ASSERT(server_ready)
  573. BLog(BLOG_INFO, "newclient %d", (int)peer_id);
  574. }
  575. void server_handler_endclient (void *user, peerid_t peer_id)
  576. {
  577. ASSERT(server_ready)
  578. BLog(BLOG_INFO, "endclient %d", (int)peer_id);
  579. }
  580. void server_handler_message (void *user, peerid_t peer_id, uint8_t *data, int data_len)
  581. {
  582. ASSERT(server_ready)
  583. ASSERT(data_len >= 0)
  584. ASSERT(data_len <= SC_MAX_MSGLEN)
  585. BLog(BLOG_INFO, "message from %d", (int)peer_id);
  586. }
  587. int flood_source_handler_recv (void *user, uint8_t *data, int *data_len)
  588. {
  589. ASSERT(server_ready)
  590. ASSERT(!flood_blocking)
  591. if (options.num_floods > 0) {
  592. ASSERT(flood_next >= 0)
  593. ASSERT(flood_next < options.num_floods)
  594. }
  595. if (options.num_floods == 0) {
  596. flood_blocking = 1;
  597. return 0;
  598. }
  599. peerid_t peer_id = options.floods[flood_next];
  600. flood_next = (flood_next + 1) % options.num_floods;
  601. BLog(BLOG_INFO, "message to %d", (int)peer_id);
  602. struct sc_header *header = (struct sc_header *)data;
  603. header->type = SCID_OUTMSG;
  604. struct sc_client_outmsg *msg = (struct sc_client_outmsg *)(data + sizeof(struct sc_header));
  605. msg->clientid = htol16(peer_id);
  606. memset(data + sizeof(struct sc_header) + sizeof(struct sc_client_outmsg), 0, SC_MAX_MSGLEN);
  607. *data_len = sizeof(struct sc_header) + sizeof(struct sc_client_outmsg) + SC_MAX_MSGLEN;
  608. return 1;
  609. }