3
0

tcpudp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /* Based on ipsvd utilities written by Gerrit Pape <pape@smarden.org>
  2. * which are released into public domain by the author.
  3. * Homepage: http://smarden.sunsite.dk/ipsvd/
  4. *
  5. * Copyright (C) 2007 Denys Vlasenko.
  6. *
  7. * Licensed under GPLv2, see file LICENSE in this source tree.
  8. */
  9. /* Based on ipsvd-0.12.1. This tcpsvd accepts all options
  10. * which are supported by one from ipsvd-0.12.1, but not all are
  11. * functional. See help text at the end of this file for details.
  12. *
  13. * Code inside "#ifdef SSLSVD" is for sslsvd and is currently unused.
  14. *
  15. * Busybox version exports TCPLOCALADDR instead of
  16. * TCPLOCALIP + TCPLOCALPORT pair. ADDR more closely matches reality
  17. * (which is "struct sockaddr_XXX". Port is not a separate entity,
  18. * it's just a part of (AF_INET[6]) sockaddr!).
  19. *
  20. * TCPORIGDSTADDR is Busybox-specific addition.
  21. *
  22. * udp server is hacked up by reusing TCP code. It has the following
  23. * limitation inherent in Unix DGRAM sockets implementation:
  24. * - local IP address is retrieved (using recvmsg voodoo) but
  25. * child's socket is not bound to it (bind cannot be called on
  26. * already bound socket). Thus it still can emit outgoing packets
  27. * with wrong source IP...
  28. * - don't know how to retrieve ORIGDST for udp.
  29. */
  30. //usage:#define tcpsvd_trivial_usage
  31. //usage: "[-hEv] [-c N] [-C N[:MSG]] [-b N] [-u USER] [-l NAME] IP PORT PROG"
  32. /* with not-implemented options: */
  33. /* //usage: "[-hpEvv] [-c N] [-C N[:MSG]] [-b N] [-u USER] [-l NAME] [-i DIR|-x CDB] [-t SEC] IP PORT PROG" */
  34. //usage:#define tcpsvd_full_usage "\n\n"
  35. //usage: "Create TCP socket, bind to IP:PORT and listen\n"
  36. //usage: "for incoming connection. Run PROG for each connection.\n"
  37. //usage: "\n IP IP to listen on, 0 = all"
  38. //usage: "\n PORT Port to listen on"
  39. //usage: "\n PROG ARGS Program to run"
  40. //usage: "\n -l NAME Local hostname (else looks up local hostname in DNS)"
  41. //usage: "\n -u USER[:GRP] Change to user/group after bind"
  42. //usage: "\n -c N Handle up to N connections simultaneously"
  43. //usage: "\n -b N Allow a backlog of approximately N TCP SYNs"
  44. //usage: "\n -C N[:MSG] Allow only up to N connections from the same IP"
  45. //usage: "\n New connections from this IP address are closed"
  46. //usage: "\n immediately. MSG is written to the peer before close"
  47. //usage: "\n -h Look up peer's hostname"
  48. //usage: "\n -E Don't set up environment variables"
  49. //usage: "\n -v Verbose"
  50. //usage:
  51. //usage:#define udpsvd_trivial_usage
  52. //usage: "[-hEv] [-c N] [-u USER] [-l NAME] IP PORT PROG"
  53. //usage:#define udpsvd_full_usage "\n\n"
  54. //usage: "Create UDP socket, bind to IP:PORT and wait\n"
  55. //usage: "for incoming packets. Run PROG for each packet,\n"
  56. //usage: "redirecting all further packets with same peer ip:port to it.\n"
  57. //usage: "\n IP IP to listen on, 0 = all"
  58. //usage: "\n PORT Port to listen on"
  59. //usage: "\n PROG ARGS Program to run"
  60. //usage: "\n -l NAME Local hostname (else looks up local hostname in DNS)"
  61. //usage: "\n -u USER[:GRP] Change to user/group after bind"
  62. //usage: "\n -c N Handle up to N connections simultaneously"
  63. //usage: "\n -h Look up peer's hostname"
  64. //usage: "\n -E Don't set up environment variables"
  65. //usage: "\n -v Verbose"
  66. #include "libbb.h"
  67. /* Wants <limits.h> etc, thus included after libbb.h: */
  68. #ifdef __linux__
  69. #include <linux/types.h> /* for __be32 etc */
  70. #include <linux/netfilter_ipv4.h>
  71. #endif
  72. // TODO: move into this file:
  73. #include "tcpudp_perhost.h"
  74. #ifdef SSLSVD
  75. #include "matrixSsl.h"
  76. #include "ssl_io.h"
  77. #endif
  78. struct globals {
  79. unsigned verbose;
  80. unsigned max_per_host;
  81. unsigned cur_per_host;
  82. unsigned cnum;
  83. unsigned cmax;
  84. char **env_cur;
  85. char *env_var[1]; /* actually bigger */
  86. } FIX_ALIASING;
  87. #define G (*(struct globals*)&bb_common_bufsiz1)
  88. #define verbose (G.verbose )
  89. #define max_per_host (G.max_per_host)
  90. #define cur_per_host (G.cur_per_host)
  91. #define cnum (G.cnum )
  92. #define cmax (G.cmax )
  93. #define env_cur (G.env_cur )
  94. #define env_var (G.env_var )
  95. #define INIT_G() do { \
  96. cmax = 30; \
  97. env_cur = &env_var[0]; \
  98. } while (0)
  99. /* We have to be careful about leaking memory in repeated setenv's */
  100. static void xsetenv_plain(const char *n, const char *v)
  101. {
  102. char *var = xasprintf("%s=%s", n, v);
  103. *env_cur++ = var;
  104. putenv(var);
  105. }
  106. static void xsetenv_proto(const char *proto, const char *n, const char *v)
  107. {
  108. char *var = xasprintf("%s%s=%s", proto, n, v);
  109. *env_cur++ = var;
  110. putenv(var);
  111. }
  112. static void undo_xsetenv(void)
  113. {
  114. char **pp = env_cur = &env_var[0];
  115. while (*pp) {
  116. char *var = *pp;
  117. bb_unsetenv_and_free(var);
  118. *pp++ = NULL;
  119. }
  120. }
  121. static void sig_term_handler(int sig)
  122. {
  123. if (verbose)
  124. bb_error_msg("got signal %u, exit", sig);
  125. kill_myself_with_sig(sig);
  126. }
  127. /* Little bloated, but tries to give accurate info how child exited.
  128. * Makes easier to spot segfaulting children etc... */
  129. static void print_waitstat(unsigned pid, int wstat)
  130. {
  131. unsigned e = 0;
  132. const char *cause = "?exit";
  133. if (WIFEXITED(wstat)) {
  134. cause++;
  135. e = WEXITSTATUS(wstat);
  136. } else if (WIFSIGNALED(wstat)) {
  137. cause = "signal";
  138. e = WTERMSIG(wstat);
  139. }
  140. bb_error_msg("end %d %s %d", pid, cause, e);
  141. }
  142. /* Must match getopt32 in main! */
  143. enum {
  144. OPT_c = (1 << 0),
  145. OPT_C = (1 << 1),
  146. OPT_i = (1 << 2),
  147. OPT_x = (1 << 3),
  148. OPT_u = (1 << 4),
  149. OPT_l = (1 << 5),
  150. OPT_E = (1 << 6),
  151. OPT_b = (1 << 7),
  152. OPT_h = (1 << 8),
  153. OPT_p = (1 << 9),
  154. OPT_t = (1 << 10),
  155. OPT_v = (1 << 11),
  156. OPT_V = (1 << 12),
  157. OPT_U = (1 << 13), /* from here: sslsvd only */
  158. OPT_slash = (1 << 14),
  159. OPT_Z = (1 << 15),
  160. OPT_K = (1 << 16),
  161. };
  162. static void connection_status(void)
  163. {
  164. /* "only 1 client max" desn't need this */
  165. if (cmax > 1)
  166. bb_error_msg("status %u/%u", cnum, cmax);
  167. }
  168. static void sig_child_handler(int sig UNUSED_PARAM)
  169. {
  170. int wstat;
  171. pid_t pid;
  172. while ((pid = wait_any_nohang(&wstat)) > 0) {
  173. if (max_per_host)
  174. ipsvd_perhost_remove(pid);
  175. if (cnum)
  176. cnum--;
  177. if (verbose)
  178. print_waitstat(pid, wstat);
  179. }
  180. if (verbose)
  181. connection_status();
  182. }
  183. int tcpudpsvd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  184. int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
  185. {
  186. char *str_C, *str_t;
  187. char *user;
  188. struct hcc *hccp;
  189. const char *instructs;
  190. char *msg_per_host = NULL;
  191. unsigned len_per_host = len_per_host; /* gcc */
  192. #ifndef SSLSVD
  193. struct bb_uidgid_t ugid;
  194. #endif
  195. bool tcp;
  196. uint16_t local_port;
  197. char *preset_local_hostname = NULL;
  198. char *remote_hostname = remote_hostname; /* for compiler */
  199. char *remote_addr = remote_addr; /* for compiler */
  200. len_and_sockaddr *lsa;
  201. len_and_sockaddr local, remote;
  202. socklen_t sa_len;
  203. int pid;
  204. int sock;
  205. int conn;
  206. unsigned backlog = 20;
  207. unsigned opts;
  208. INIT_G();
  209. tcp = (applet_name[0] == 't');
  210. /* 3+ args, -i at most once, -p implies -h, -v is counter, -b N, -c N */
  211. opt_complementary = "-3:i--i:ph:vv:b+:c+";
  212. #ifdef SSLSVD
  213. opts = getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:",
  214. &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
  215. &backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
  216. );
  217. #else
  218. /* "+": stop on first non-option */
  219. opts = getopt32(argv, "+c:C:i:x:u:l:Eb:hpt:v",
  220. &cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
  221. &backlog, &str_t, &verbose
  222. );
  223. #endif
  224. if (opts & OPT_C) { /* -C n[:message] */
  225. max_per_host = bb_strtou(str_C, &str_C, 10);
  226. if (str_C[0]) {
  227. if (str_C[0] != ':')
  228. bb_show_usage();
  229. msg_per_host = str_C + 1;
  230. len_per_host = strlen(msg_per_host);
  231. }
  232. }
  233. if (max_per_host > cmax)
  234. max_per_host = cmax;
  235. if (opts & OPT_u) {
  236. xget_uidgid(&ugid, user);
  237. }
  238. #ifdef SSLSVD
  239. if (opts & OPT_U) ssluser = optarg;
  240. if (opts & OPT_slash) root = optarg;
  241. if (opts & OPT_Z) cert = optarg;
  242. if (opts & OPT_K) key = optarg;
  243. #endif
  244. argv += optind;
  245. if (!argv[0][0] || LONE_CHAR(argv[0], '0'))
  246. argv[0] = (char*)"0.0.0.0";
  247. /* Per-IP flood protection is not thought-out for UDP */
  248. if (!tcp)
  249. max_per_host = 0;
  250. bb_sanitize_stdio(); /* fd# 0,1,2 must be opened */
  251. #ifdef SSLSVD
  252. sslser = user;
  253. client = 0;
  254. if ((getuid() == 0) && !(opts & OPT_u)) {
  255. xfunc_exitcode = 100;
  256. bb_error_msg_and_die(bb_msg_you_must_be_root);
  257. }
  258. if (opts & OPT_u)
  259. if (!uidgid_get(&sslugid, ssluser, 1)) {
  260. if (errno) {
  261. bb_perror_msg_and_die("can't get user/group: %s", ssluser);
  262. }
  263. bb_error_msg_and_die("unknown user/group %s", ssluser);
  264. }
  265. if (!cert) cert = "./cert.pem";
  266. if (!key) key = cert;
  267. if (matrixSslOpen() < 0)
  268. fatal("can't initialize ssl");
  269. if (matrixSslReadKeys(&keys, cert, key, 0, ca) < 0) {
  270. if (client)
  271. fatal("can't read cert, key, or ca file");
  272. fatal("can't read cert or key file");
  273. }
  274. if (matrixSslNewSession(&ssl, keys, 0, SSL_FLAGS_SERVER) < 0)
  275. fatal("can't create ssl session");
  276. #endif
  277. sig_block(SIGCHLD);
  278. signal(SIGCHLD, sig_child_handler);
  279. bb_signals(BB_FATAL_SIGS, sig_term_handler);
  280. signal(SIGPIPE, SIG_IGN);
  281. if (max_per_host)
  282. ipsvd_perhost_init(cmax);
  283. local_port = bb_lookup_port(argv[1], tcp ? "tcp" : "udp", 0);
  284. lsa = xhost2sockaddr(argv[0], local_port);
  285. argv += 2;
  286. sock = xsocket(lsa->u.sa.sa_family, tcp ? SOCK_STREAM : SOCK_DGRAM, 0);
  287. setsockopt_reuseaddr(sock);
  288. sa_len = lsa->len; /* I presume sockaddr len stays the same */
  289. xbind(sock, &lsa->u.sa, sa_len);
  290. if (tcp) {
  291. xlisten(sock, backlog);
  292. close_on_exec_on(sock);
  293. } else { /* udp: needed for recv_from_to to work: */
  294. socket_want_pktinfo(sock);
  295. }
  296. /* ndelay_off(sock); - it is the default I think? */
  297. #ifndef SSLSVD
  298. if (opts & OPT_u) {
  299. /* drop permissions */
  300. xsetgid(ugid.gid);
  301. xsetuid(ugid.uid);
  302. }
  303. #endif
  304. if (verbose) {
  305. char *addr = xmalloc_sockaddr2dotted(&lsa->u.sa);
  306. if (opts & OPT_u)
  307. bb_error_msg("listening on %s, starting, uid %u, gid %u", addr,
  308. (unsigned)ugid.uid, (unsigned)ugid.gid);
  309. else
  310. bb_error_msg("listening on %s, starting", addr);
  311. free(addr);
  312. }
  313. /* Main accept() loop */
  314. again:
  315. hccp = NULL;
  316. while (cnum >= cmax)
  317. wait_for_any_sig(); /* expecting SIGCHLD */
  318. /* Accept a connection to fd #0 */
  319. again1:
  320. close(0);
  321. again2:
  322. sig_unblock(SIGCHLD);
  323. local.len = remote.len = sa_len;
  324. if (tcp) {
  325. conn = accept(sock, &remote.u.sa, &remote.len);
  326. } else {
  327. /* In case recv_from_to won't be able to recover local addr.
  328. * Also sets port - recv_from_to is unable to do it. */
  329. local = *lsa;
  330. conn = recv_from_to(sock, NULL, 0, MSG_PEEK,
  331. &remote.u.sa, &local.u.sa, sa_len);
  332. }
  333. sig_block(SIGCHLD);
  334. if (conn < 0) {
  335. if (errno != EINTR)
  336. bb_perror_msg(tcp ? "accept" : "recv");
  337. goto again2;
  338. }
  339. xmove_fd(tcp ? conn : sock, 0);
  340. if (max_per_host) {
  341. /* Drop connection immediately if cur_per_host > max_per_host
  342. * (minimizing load under SYN flood) */
  343. remote_addr = xmalloc_sockaddr2dotted_noport(&remote.u.sa);
  344. cur_per_host = ipsvd_perhost_add(remote_addr, max_per_host, &hccp);
  345. if (cur_per_host > max_per_host) {
  346. /* ipsvd_perhost_add detected that max is exceeded
  347. * (and did not store ip in connection table) */
  348. free(remote_addr);
  349. if (msg_per_host) {
  350. /* don't block or test for errors */
  351. send(0, msg_per_host, len_per_host, MSG_DONTWAIT);
  352. }
  353. goto again1;
  354. }
  355. /* NB: remote_addr is not leaked, it is stored in conn table */
  356. }
  357. if (!tcp) {
  358. /* Voodoo magic: making udp sockets each receive its own
  359. * packets is not trivial, and I still not sure
  360. * I do it 100% right.
  361. * 1) we have to do it before fork()
  362. * 2) order is important - is it right now? */
  363. /* Open new non-connected UDP socket for further clients... */
  364. sock = xsocket(lsa->u.sa.sa_family, SOCK_DGRAM, 0);
  365. setsockopt_reuseaddr(sock);
  366. /* Make plain write/send work for old socket by supplying default
  367. * destination address. This also restricts incoming packets
  368. * to ones coming from this remote IP. */
  369. xconnect(0, &remote.u.sa, sa_len);
  370. /* hole? at this point we have no wildcard udp socket...
  371. * can this cause clients to get "port unreachable" icmp?
  372. * Yup, time window is very small, but it exists (is it?) */
  373. /* ..."open new socket", continued */
  374. xbind(sock, &lsa->u.sa, sa_len);
  375. socket_want_pktinfo(sock);
  376. /* Doesn't work:
  377. * we cannot replace fd #0 - we will lose pending packet
  378. * which is already buffered for us! And we cannot use fd #1
  379. * instead - it will "intercept" all following packets, but child
  380. * does not expect data coming *from fd #1*! */
  381. #if 0
  382. /* Make it so that local addr is fixed to localp->u.sa
  383. * and we don't accidentally accept packets to other local IPs. */
  384. /* NB: we possibly bind to the _very_ same_ address & port as the one
  385. * already bound in parent! This seems to work in Linux.
  386. * (otherwise we can move socket to fd #0 only if bind succeeds) */
  387. close(0);
  388. set_nport(&localp->u.sa, htons(local_port));
  389. xmove_fd(xsocket(localp->u.sa.sa_family, SOCK_DGRAM, 0), 0);
  390. setsockopt_reuseaddr(0); /* crucial */
  391. xbind(0, &localp->u.sa, localp->len);
  392. #endif
  393. }
  394. pid = vfork();
  395. if (pid == -1) {
  396. bb_perror_msg("vfork");
  397. goto again;
  398. }
  399. if (pid != 0) {
  400. /* Parent */
  401. cnum++;
  402. if (verbose)
  403. connection_status();
  404. if (hccp)
  405. hccp->pid = pid;
  406. /* clean up changes done by vforked child */
  407. undo_xsetenv();
  408. goto again;
  409. }
  410. /* Child: prepare env, log, and exec prog */
  411. { /* vfork alert! every xmalloc in this block should be freed! */
  412. char *local_hostname = local_hostname; /* for compiler */
  413. char *local_addr = NULL;
  414. char *free_me0 = NULL;
  415. char *free_me1 = NULL;
  416. char *free_me2 = NULL;
  417. if (verbose || !(opts & OPT_E)) {
  418. if (!max_per_host) /* remote_addr is not yet known */
  419. free_me0 = remote_addr = xmalloc_sockaddr2dotted(&remote.u.sa);
  420. if (opts & OPT_h) {
  421. free_me1 = remote_hostname = xmalloc_sockaddr2host_noport(&remote.u.sa);
  422. if (!remote_hostname) {
  423. bb_error_msg("can't look up hostname for %s", remote_addr);
  424. remote_hostname = remote_addr;
  425. }
  426. }
  427. /* Find out local IP peer connected to.
  428. * Errors ignored (I'm not paranoid enough to imagine kernel
  429. * which doesn't know local IP). */
  430. if (tcp)
  431. getsockname(0, &local.u.sa, &local.len);
  432. /* else: for UDP it is done earlier by parent */
  433. local_addr = xmalloc_sockaddr2dotted(&local.u.sa);
  434. if (opts & OPT_h) {
  435. local_hostname = preset_local_hostname;
  436. if (!local_hostname) {
  437. free_me2 = local_hostname = xmalloc_sockaddr2host_noport(&local.u.sa);
  438. if (!local_hostname)
  439. bb_error_msg_and_die("can't look up hostname for %s", local_addr);
  440. }
  441. /* else: local_hostname is not NULL, but is NOT malloced! */
  442. }
  443. }
  444. if (verbose) {
  445. pid = getpid();
  446. if (max_per_host) {
  447. bb_error_msg("concurrency %s %u/%u",
  448. remote_addr,
  449. cur_per_host, max_per_host);
  450. }
  451. bb_error_msg((opts & OPT_h)
  452. ? "start %u %s-%s (%s-%s)"
  453. : "start %u %s-%s",
  454. pid,
  455. local_addr, remote_addr,
  456. local_hostname, remote_hostname);
  457. }
  458. if (!(opts & OPT_E)) {
  459. /* setup ucspi env */
  460. const char *proto = tcp ? "TCP" : "UDP";
  461. #ifdef SO_ORIGINAL_DST
  462. /* Extract "original" destination addr:port
  463. * from Linux firewall. Useful when you redirect
  464. * an outbond connection to local handler, and it needs
  465. * to know where it originally tried to connect */
  466. if (tcp && getsockopt(0, SOL_IP, SO_ORIGINAL_DST, &local.u.sa, &local.len) == 0) {
  467. char *addr = xmalloc_sockaddr2dotted(&local.u.sa);
  468. xsetenv_plain("TCPORIGDSTADDR", addr);
  469. free(addr);
  470. }
  471. #endif
  472. xsetenv_plain("PROTO", proto);
  473. xsetenv_proto(proto, "LOCALADDR", local_addr);
  474. xsetenv_proto(proto, "REMOTEADDR", remote_addr);
  475. if (opts & OPT_h) {
  476. xsetenv_proto(proto, "LOCALHOST", local_hostname);
  477. xsetenv_proto(proto, "REMOTEHOST", remote_hostname);
  478. }
  479. //compat? xsetenv_proto(proto, "REMOTEINFO", "");
  480. /* additional */
  481. if (cur_per_host > 0) /* can not be true for udp */
  482. xsetenv_plain("TCPCONCURRENCY", utoa(cur_per_host));
  483. }
  484. free(local_addr);
  485. free(free_me0);
  486. free(free_me1);
  487. free(free_me2);
  488. }
  489. xdup2(0, 1);
  490. signal(SIGPIPE, SIG_DFL); /* this one was SIG_IGNed */
  491. /* Non-ignored signals revert to SIG_DFL on exec anyway */
  492. /*signal(SIGCHLD, SIG_DFL);*/
  493. sig_unblock(SIGCHLD);
  494. #ifdef SSLSVD
  495. strcpy(id, utoa(pid));
  496. ssl_io(0, argv);
  497. bb_perror_msg_and_die("can't execute '%s'", argv[0]);
  498. #else
  499. BB_EXECVP_or_die(argv);
  500. #endif
  501. }
  502. /*
  503. tcpsvd [-hpEvv] [-c n] [-C n:msg] [-b n] [-u user] [-l name]
  504. [-i dir|-x cdb] [ -t sec] host port prog
  505. tcpsvd creates a TCP/IP socket, binds it to the address host:port,
  506. and listens on the socket for incoming connections.
  507. On each incoming connection, tcpsvd conditionally runs a program,
  508. with standard input reading from the socket, and standard output
  509. writing to the socket, to handle this connection. tcpsvd keeps
  510. listening on the socket for new connections, and can handle
  511. multiple connections simultaneously.
  512. tcpsvd optionally checks for special instructions depending
  513. on the IP address or hostname of the client that initiated
  514. the connection, see ipsvd-instruct(5).
  515. host
  516. host either is a hostname, or a dotted-decimal IP address,
  517. or 0. If host is 0, tcpsvd accepts connections to any local
  518. IP address.
  519. * busybox accepts IPv6 addresses and host:port pairs too
  520. In this case second parameter is ignored
  521. port
  522. tcpsvd accepts connections to host:port. port may be a name
  523. from /etc/services or a number.
  524. prog
  525. prog consists of one or more arguments. For each connection,
  526. tcpsvd normally runs prog, with file descriptor 0 reading from
  527. the network, and file descriptor 1 writing to the network.
  528. By default it also sets up TCP-related environment variables,
  529. see tcp-environ(5)
  530. -i dir
  531. read instructions for handling new connections from the instructions
  532. directory dir. See ipsvd-instruct(5) for details.
  533. * ignored by busyboxed version
  534. -x cdb
  535. read instructions for handling new connections from the constant database
  536. cdb. The constant database normally is created from an instructions
  537. directory by running ipsvd-cdb(8).
  538. * ignored by busyboxed version
  539. -t sec
  540. timeout. This option only takes effect if the -i option is given.
  541. While checking the instructions directory, check the time of last access
  542. of the file that matches the clients address or hostname if any, discard
  543. and remove the file if it wasn't accessed within the last sec seconds;
  544. tcpsvd does not discard or remove a file if the user's write permission
  545. is not set, for those files the timeout is disabled. Default is 0,
  546. which means that the timeout is disabled.
  547. * ignored by busyboxed version
  548. -l name
  549. local hostname. Do not look up the local hostname in DNS, but use name
  550. as hostname. This option must be set if tcpsvd listens on port 53
  551. to avoid loops.
  552. -u user[:group]
  553. drop permissions. Switch user ID to user's UID, and group ID to user's
  554. primary GID after creating and binding to the socket. If user is followed
  555. by a colon and a group name, the group ID is switched to the GID of group
  556. instead. All supplementary groups are removed.
  557. -c n
  558. concurrency. Handle up to n connections simultaneously. Default is 30.
  559. If there are n connections active, tcpsvd defers acceptance of a new
  560. connection until an active connection is closed.
  561. -C n[:msg]
  562. per host concurrency. Allow only up to n connections from the same IP
  563. address simultaneously. If there are n active connections from one IP
  564. address, new incoming connections from this IP address are closed
  565. immediately. If n is followed by :msg, the message msg is written
  566. to the client if possible, before closing the connection. By default
  567. msg is empty. See ipsvd-instruct(5) for supported escape sequences in msg.
  568. For each accepted connection, the current per host concurrency is
  569. available through the environment variable TCPCONCURRENCY. n and msg
  570. can be overwritten by ipsvd(7) instructions, see ipsvd-instruct(5).
  571. By default tcpsvd doesn't keep track of connections.
  572. -h
  573. Look up the client's hostname in DNS.
  574. -p
  575. paranoid. After looking up the client's hostname in DNS, look up the IP
  576. addresses in DNS for that hostname, and forget about the hostname
  577. if none of the addresses match the client's IP address. You should
  578. set this option if you use hostname based instructions. The -p option
  579. implies the -h option.
  580. * ignored by busyboxed version
  581. -b n
  582. backlog. Allow a backlog of approximately n TCP SYNs. On some systems n
  583. is silently limited. Default is 20.
  584. -E
  585. no special environment. Do not set up TCP-related environment variables.
  586. -v
  587. verbose. Print verbose messsages to standard output.
  588. -vv
  589. more verbose. Print more verbose messages to standard output.
  590. * no difference between -v and -vv in busyboxed version
  591. */