telnetd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Simple telnet server
  4. * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
  5. *
  6. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  7. *
  8. * ---------------------------------------------------------------------------
  9. * (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN
  10. ****************************************************************************
  11. *
  12. * The telnetd manpage says it all:
  13. *
  14. * Telnetd operates by allocating a pseudo-terminal device (see pty(4)) for
  15. * a client, then creating a login process which has the slave side of the
  16. * pseudo-terminal as stdin, stdout, and stderr. Telnetd manipulates the
  17. * master side of the pseudo-terminal, implementing the telnet protocol and
  18. * passing characters between the remote client and the login process.
  19. *
  20. * Vladimir Oleynik <dzo@simtreas.ru> 2001
  21. * Set process group corrections, initial busybox port
  22. */
  23. #define DEBUG 0
  24. #include "libbb.h"
  25. #include <syslog.h>
  26. #if DEBUG
  27. #define TELCMDS
  28. #define TELOPTS
  29. #endif
  30. #include <arpa/telnet.h>
  31. /* Structure that describes a session */
  32. struct tsession {
  33. struct tsession *next;
  34. int sockfd_read, sockfd_write, ptyfd;
  35. int shell_pid;
  36. /* two circular buffers */
  37. /*char *buf1, *buf2;*/
  38. /*#define TS_BUF1 ts->buf1*/
  39. /*#define TS_BUF2 TS_BUF2*/
  40. #define TS_BUF1 ((unsigned char*)(ts + 1))
  41. #define TS_BUF2 (((unsigned char*)(ts + 1)) + BUFSIZE)
  42. int rdidx1, wridx1, size1;
  43. int rdidx2, wridx2, size2;
  44. };
  45. /* Two buffers are directly after tsession in malloced memory.
  46. * Make whole thing fit in 4k */
  47. enum { BUFSIZE = (4 * 1024 - sizeof(struct tsession)) / 2 };
  48. /* Globals */
  49. static int maxfd;
  50. static struct tsession *sessions;
  51. static const char *loginpath = "/bin/login";
  52. static const char *issuefile = "/etc/issue.net";
  53. /*
  54. Remove all IAC's from buf1 (received IACs are ignored and must be removed
  55. so as to not be interpreted by the terminal). Make an uninterrupted
  56. string of characters fit for the terminal. Do this by packing
  57. all characters meant for the terminal sequentially towards the end of buf.
  58. Return a pointer to the beginning of the characters meant for the terminal.
  59. and make *num_totty the number of characters that should be sent to
  60. the terminal.
  61. Note - If an IAC (3 byte quantity) starts before (bf + len) but extends
  62. past (bf + len) then that IAC will be left unprocessed and *processed
  63. will be less than len.
  64. FIXME - if we mean to send 0xFF to the terminal then it will be escaped,
  65. what is the escape character? We aren't handling that situation here.
  66. CR-LF ->'s CR mapping is also done here, for convenience.
  67. NB: may fail to remove iacs which wrap around buffer!
  68. */
  69. static unsigned char *
  70. remove_iacs(struct tsession *ts, int *pnum_totty)
  71. {
  72. unsigned char *ptr0 = TS_BUF1 + ts->wridx1;
  73. unsigned char *ptr = ptr0;
  74. unsigned char *totty = ptr;
  75. unsigned char *end = ptr + MIN(BUFSIZE - ts->wridx1, ts->size1);
  76. int num_totty;
  77. while (ptr < end) {
  78. if (*ptr != IAC) {
  79. char c = *ptr;
  80. *totty++ = c;
  81. ptr++;
  82. /* We now map \r\n ==> \r for pragmatic reasons.
  83. * Many client implementations send \r\n when
  84. * the user hits the CarriageReturn key.
  85. */
  86. if (c == '\r' && ptr < end && (*ptr == '\n' || *ptr == '\0'))
  87. ptr++;
  88. } else {
  89. /*
  90. * TELOPT_NAWS support!
  91. */
  92. if ((ptr+2) >= end) {
  93. /* only the beginning of the IAC is in the
  94. buffer we were asked to process, we can't
  95. process this char. */
  96. break;
  97. }
  98. /*
  99. * IAC -> SB -> TELOPT_NAWS -> 4-byte -> IAC -> SE
  100. */
  101. else if (ptr[1] == SB && ptr[2] == TELOPT_NAWS) {
  102. struct winsize ws;
  103. if ((ptr+8) >= end)
  104. break; /* incomplete, can't process */
  105. ws.ws_col = (ptr[3] << 8) | ptr[4];
  106. ws.ws_row = (ptr[5] << 8) | ptr[6];
  107. ioctl(ts->ptyfd, TIOCSWINSZ, (char *)&ws);
  108. ptr += 9;
  109. } else {
  110. /* skip 3-byte IAC non-SB cmd */
  111. #if DEBUG
  112. fprintf(stderr, "Ignoring IAC %s,%s\n",
  113. TELCMD(ptr[1]), TELOPT(ptr[2]));
  114. #endif
  115. ptr += 3;
  116. }
  117. }
  118. }
  119. num_totty = totty - ptr0;
  120. *pnum_totty = num_totty;
  121. /* the difference between ptr and totty is number of iacs
  122. we removed from the stream. Adjust buf1 accordingly. */
  123. if ((ptr - totty) == 0) /* 99.999% of cases */
  124. return ptr0;
  125. ts->wridx1 += ptr - totty;
  126. ts->size1 -= ptr - totty;
  127. /* move chars meant for the terminal towards the end of the buffer */
  128. return memmove(ptr - num_totty, ptr0, num_totty);
  129. }
  130. static struct tsession *
  131. make_new_session(
  132. USE_FEATURE_TELNETD_STANDALONE(int sock)
  133. SKIP_FEATURE_TELNETD_STANDALONE(void)
  134. ) {
  135. const char *login_argv[2];
  136. struct termios termbuf;
  137. int fd, pid;
  138. char tty_name[GETPTY_BUFSIZE];
  139. struct tsession *ts = xzalloc(sizeof(struct tsession) + BUFSIZE * 2);
  140. /*ts->buf1 = (char *)(ts + 1);*/
  141. /*ts->buf2 = ts->buf1 + BUFSIZE;*/
  142. /* Got a new connection, set up a tty. */
  143. fd = xgetpty(tty_name);
  144. if (fd > maxfd)
  145. maxfd = fd;
  146. ts->ptyfd = fd;
  147. ndelay_on(fd);
  148. #if ENABLE_FEATURE_TELNETD_STANDALONE
  149. ts->sockfd_read = sock;
  150. ndelay_on(sock);
  151. if (!sock) { /* We are called with fd 0 - we are in inetd mode */
  152. sock++; /* so use fd 1 for output */
  153. ndelay_on(sock);
  154. }
  155. ts->sockfd_write = sock;
  156. if (sock > maxfd)
  157. maxfd = sock;
  158. #else
  159. /* ts->sockfd_read = 0; - done by xzalloc */
  160. ts->sockfd_write = 1;
  161. ndelay_on(0);
  162. ndelay_on(1);
  163. #endif
  164. /* Make the telnet client understand we will echo characters so it
  165. * should not do it locally. We don't tell the client to run linemode,
  166. * because we want to handle line editing and tab completion and other
  167. * stuff that requires char-by-char support. */
  168. {
  169. static const char iacs_to_send[] ALIGN1 = {
  170. IAC, DO, TELOPT_ECHO,
  171. IAC, DO, TELOPT_NAWS,
  172. IAC, DO, TELOPT_LFLOW,
  173. IAC, WILL, TELOPT_ECHO,
  174. IAC, WILL, TELOPT_SGA
  175. };
  176. memcpy(TS_BUF2, iacs_to_send, sizeof(iacs_to_send));
  177. ts->rdidx2 = sizeof(iacs_to_send);
  178. ts->size2 = sizeof(iacs_to_send);
  179. }
  180. fflush(NULL); /* flush all streams */
  181. pid = vfork(); /* NOMMU-friendly */
  182. if (pid < 0) {
  183. free(ts);
  184. close(fd);
  185. /* sock will be closed by caller */
  186. bb_perror_msg("vfork");
  187. return NULL;
  188. }
  189. if (pid > 0) {
  190. /* Parent */
  191. ts->shell_pid = pid;
  192. return ts;
  193. }
  194. /* Child */
  195. /* Careful - we are after vfork! */
  196. /* make new session and process group */
  197. setsid();
  198. /* Restore default signal handling */
  199. bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL);
  200. /* open the child's side of the tty. */
  201. /* NB: setsid() disconnects from any previous ctty's. Therefore
  202. * we must open child's side of the tty AFTER setsid! */
  203. close(0);
  204. xopen(tty_name, O_RDWR); /* becomes our ctty */
  205. xdup2(0, 1);
  206. xdup2(0, 2);
  207. tcsetpgrp(0, getpid()); /* switch this tty's process group to us */
  208. /* The pseudo-terminal allocated to the client is configured to operate in
  209. * cooked mode, and with XTABS CRMOD enabled (see tty(4)). */
  210. tcgetattr(0, &termbuf);
  211. termbuf.c_lflag |= ECHO; /* if we use readline we dont want this */
  212. termbuf.c_oflag |= ONLCR | XTABS;
  213. termbuf.c_iflag |= ICRNL;
  214. termbuf.c_iflag &= ~IXOFF;
  215. /*termbuf.c_lflag &= ~ICANON;*/
  216. tcsetattr(0, TCSANOW, &termbuf);
  217. /* Uses FILE-based I/O to stdout, but does fflush(stdout),
  218. * so should be safe with vfork.
  219. * I fear, though, that some users will have ridiculously big
  220. * issue files, and they may block writing to fd 1,
  221. * (parent is supposed to read it, but parent waits
  222. * for vforked child to exec!) */
  223. print_login_issue(issuefile, tty_name);
  224. /* Exec shell / login / whatever */
  225. login_argv[0] = loginpath;
  226. login_argv[1] = NULL;
  227. /* exec busybox applet (if PREFER_APPLETS=y), if that fails,
  228. * exec external program */
  229. BB_EXECVP(loginpath, (char **)login_argv);
  230. /* _exit is safer with vfork, and we shouldn't send message
  231. * to remote clients anyway */
  232. _exit(EXIT_FAILURE); /*bb_perror_msg_and_die("execv %s", loginpath);*/
  233. }
  234. /* Must match getopt32 string */
  235. enum {
  236. OPT_WATCHCHILD = (1 << 2), /* -K */
  237. OPT_INETD = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
  238. OPT_PORT = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
  239. OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
  240. };
  241. #if ENABLE_FEATURE_TELNETD_STANDALONE
  242. static void
  243. free_session(struct tsession *ts)
  244. {
  245. struct tsession *t = sessions;
  246. if (option_mask32 & OPT_INETD)
  247. exit(EXIT_SUCCESS);
  248. /* Unlink this telnet session from the session list */
  249. if (t == ts)
  250. sessions = ts->next;
  251. else {
  252. while (t->next != ts)
  253. t = t->next;
  254. t->next = ts->next;
  255. }
  256. #if 0
  257. /* It was said that "normal" telnetd just closes ptyfd,
  258. * doesn't send SIGKILL. When we close ptyfd,
  259. * kernel sends SIGHUP to processes having slave side opened. */
  260. kill(ts->shell_pid, SIGKILL);
  261. wait4(ts->shell_pid, NULL, 0, NULL);
  262. #endif
  263. close(ts->ptyfd);
  264. close(ts->sockfd_read);
  265. /* We do not need to close(ts->sockfd_write), it's the same
  266. * as sockfd_read unless we are in inetd mode. But in inetd mode
  267. * we do not reach this */
  268. free(ts);
  269. /* Scan all sessions and find new maxfd */
  270. maxfd = 0;
  271. ts = sessions;
  272. while (ts) {
  273. if (maxfd < ts->ptyfd)
  274. maxfd = ts->ptyfd;
  275. if (maxfd < ts->sockfd_read)
  276. maxfd = ts->sockfd_read;
  277. #if 0
  278. /* Again, sockfd_write == sockfd_read here */
  279. if (maxfd < ts->sockfd_write)
  280. maxfd = ts->sockfd_write;
  281. #endif
  282. ts = ts->next;
  283. }
  284. }
  285. #else /* !FEATURE_TELNETD_STANDALONE */
  286. /* Used in main() only, thus "return 0" actually is exit(EXIT_SUCCESS). */
  287. #define free_session(ts) return 0
  288. #endif
  289. static void handle_sigchld(int sig UNUSED_PARAM)
  290. {
  291. pid_t pid;
  292. struct tsession *ts;
  293. /* Looping: more than one child may have exited */
  294. while (1) {
  295. pid = wait_any_nohang(NULL);
  296. if (pid <= 0)
  297. break;
  298. ts = sessions;
  299. while (ts) {
  300. if (ts->shell_pid == pid) {
  301. ts->shell_pid = -1;
  302. break;
  303. }
  304. ts = ts->next;
  305. }
  306. }
  307. }
  308. int telnetd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  309. int telnetd_main(int argc UNUSED_PARAM, char **argv)
  310. {
  311. fd_set rdfdset, wrfdset;
  312. unsigned opt;
  313. int count;
  314. struct tsession *ts;
  315. #if ENABLE_FEATURE_TELNETD_STANDALONE
  316. #define IS_INETD (opt & OPT_INETD)
  317. int master_fd = master_fd; /* be happy, gcc */
  318. unsigned portnbr = 23;
  319. char *opt_bindaddr = NULL;
  320. char *opt_portnbr;
  321. #else
  322. enum {
  323. IS_INETD = 1,
  324. master_fd = -1,
  325. portnbr = 23,
  326. };
  327. #endif
  328. /* Even if !STANDALONE, we accept (and ignore) -i, thus people
  329. * don't need to guess whether it's ok to pass -i to us */
  330. opt = getopt32(argv, "f:l:Ki" USE_FEATURE_TELNETD_STANDALONE("p:b:F"),
  331. &issuefile, &loginpath
  332. USE_FEATURE_TELNETD_STANDALONE(, &opt_portnbr, &opt_bindaddr));
  333. if (!IS_INETD /*&& !re_execed*/) {
  334. /* inform that we start in standalone mode?
  335. * May be useful when people forget to give -i */
  336. /*bb_error_msg("listening for connections");*/
  337. if (!(opt & OPT_FOREGROUND)) {
  338. /* DAEMON_CHDIR_ROOT was giving inconsistent
  339. * behavior with/without -F, -i */
  340. bb_daemonize_or_rexec(0 /*was DAEMON_CHDIR_ROOT*/, argv);
  341. }
  342. }
  343. /* Redirect log to syslog early, if needed */
  344. if (IS_INETD || !(opt & OPT_FOREGROUND)) {
  345. openlog(applet_name, 0, LOG_USER);
  346. logmode = LOGMODE_SYSLOG;
  347. }
  348. USE_FEATURE_TELNETD_STANDALONE(
  349. if (opt & OPT_PORT)
  350. portnbr = xatou16(opt_portnbr);
  351. );
  352. /* Used to check access(loginpath, X_OK) here. Pointless.
  353. * exec will do this for us for free later. */
  354. #if ENABLE_FEATURE_TELNETD_STANDALONE
  355. if (IS_INETD) {
  356. sessions = make_new_session(0);
  357. if (!sessions) /* pty opening or vfork problem, exit */
  358. return 1; /* make_new_session prints error message */
  359. } else {
  360. master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
  361. xlisten(master_fd, 1);
  362. }
  363. #else
  364. sessions = make_new_session();
  365. if (!sessions) /* pty opening or vfork problem, exit */
  366. return 1; /* make_new_session prints error message */
  367. #endif
  368. /* We don't want to die if just one session is broken */
  369. signal(SIGPIPE, SIG_IGN);
  370. if (opt & OPT_WATCHCHILD)
  371. signal(SIGCHLD, handle_sigchld);
  372. else /* prevent dead children from becoming zombies */
  373. signal(SIGCHLD, SIG_IGN);
  374. /*
  375. This is how the buffers are used. The arrows indicate the movement
  376. of data.
  377. +-------+ wridx1++ +------+ rdidx1++ +----------+
  378. | | <-------------- | buf1 | <-------------- | |
  379. | | size1-- +------+ size1++ | |
  380. | pty | | socket |
  381. | | rdidx2++ +------+ wridx2++ | |
  382. | | --------------> | buf2 | --------------> | |
  383. +-------+ size2++ +------+ size2-- +----------+
  384. size1: "how many bytes are buffered for pty between rdidx1 and wridx1?"
  385. size2: "how many bytes are buffered for socket between rdidx2 and wridx2?"
  386. Each session has got two buffers. Buffers are circular. If sizeN == 0,
  387. buffer is empty. If sizeN == BUFSIZE, buffer is full. In both these cases
  388. rdidxN == wridxN.
  389. */
  390. again:
  391. FD_ZERO(&rdfdset);
  392. FD_ZERO(&wrfdset);
  393. /* Select on the master socket, all telnet sockets and their
  394. * ptys if there is room in their session buffers.
  395. * NB: scalability problem: we recalculate entire bitmap
  396. * before each select. Can be a problem with 500+ connections. */
  397. ts = sessions;
  398. while (ts) {
  399. struct tsession *next = ts->next; /* in case we free ts. */
  400. if (ts->shell_pid == -1) {
  401. /* Child died and we detected that */
  402. free_session(ts);
  403. } else {
  404. if (ts->size1 > 0) /* can write to pty */
  405. FD_SET(ts->ptyfd, &wrfdset);
  406. if (ts->size1 < BUFSIZE) /* can read from socket */
  407. FD_SET(ts->sockfd_read, &rdfdset);
  408. if (ts->size2 > 0) /* can write to socket */
  409. FD_SET(ts->sockfd_write, &wrfdset);
  410. if (ts->size2 < BUFSIZE) /* can read from pty */
  411. FD_SET(ts->ptyfd, &rdfdset);
  412. }
  413. ts = next;
  414. }
  415. if (!IS_INETD) {
  416. FD_SET(master_fd, &rdfdset);
  417. /* This is needed because free_session() does not
  418. * take master_fd into account when it finds new
  419. * maxfd among remaining fd's */
  420. if (master_fd > maxfd)
  421. maxfd = master_fd;
  422. }
  423. count = select(maxfd + 1, &rdfdset, &wrfdset, NULL, NULL);
  424. if (count < 0)
  425. goto again; /* EINTR or ENOMEM */
  426. #if ENABLE_FEATURE_TELNETD_STANDALONE
  427. /* First check for and accept new sessions. */
  428. if (!IS_INETD && FD_ISSET(master_fd, &rdfdset)) {
  429. int fd;
  430. struct tsession *new_ts;
  431. fd = accept(master_fd, NULL, NULL);
  432. if (fd < 0)
  433. goto again;
  434. /* Create a new session and link it into our active list */
  435. new_ts = make_new_session(fd);
  436. if (new_ts) {
  437. new_ts->next = sessions;
  438. sessions = new_ts;
  439. } else {
  440. close(fd);
  441. }
  442. }
  443. #endif
  444. /* Then check for data tunneling. */
  445. ts = sessions;
  446. while (ts) { /* For all sessions... */
  447. struct tsession *next = ts->next; /* in case we free ts. */
  448. if (/*ts->size1 &&*/ FD_ISSET(ts->ptyfd, &wrfdset)) {
  449. int num_totty;
  450. unsigned char *ptr;
  451. /* Write to pty from buffer 1. */
  452. ptr = remove_iacs(ts, &num_totty);
  453. count = safe_write(ts->ptyfd, ptr, num_totty);
  454. if (count < 0) {
  455. if (errno == EAGAIN)
  456. goto skip1;
  457. goto kill_session;
  458. }
  459. ts->size1 -= count;
  460. ts->wridx1 += count;
  461. if (ts->wridx1 >= BUFSIZE) /* actually == BUFSIZE */
  462. ts->wridx1 = 0;
  463. }
  464. skip1:
  465. if (/*ts->size2 &&*/ FD_ISSET(ts->sockfd_write, &wrfdset)) {
  466. /* Write to socket from buffer 2. */
  467. count = MIN(BUFSIZE - ts->wridx2, ts->size2);
  468. count = safe_write(ts->sockfd_write, TS_BUF2 + ts->wridx2, count);
  469. if (count < 0) {
  470. if (errno == EAGAIN)
  471. goto skip2;
  472. goto kill_session;
  473. }
  474. ts->size2 -= count;
  475. ts->wridx2 += count;
  476. if (ts->wridx2 >= BUFSIZE) /* actually == BUFSIZE */
  477. ts->wridx2 = 0;
  478. }
  479. skip2:
  480. /* Should not be needed, but... remove_iacs is actually buggy
  481. * (it cannot process iacs which wrap around buffer's end)!
  482. * Since properly fixing it requires writing bigger code,
  483. * we rely instead on this code making it virtually impossible
  484. * to have wrapped iac (people don't type at 2k/second).
  485. * It also allows for bigger reads in common case. */
  486. if (ts->size1 == 0) {
  487. ts->rdidx1 = 0;
  488. ts->wridx1 = 0;
  489. }
  490. if (ts->size2 == 0) {
  491. ts->rdidx2 = 0;
  492. ts->wridx2 = 0;
  493. }
  494. if (/*ts->size1 < BUFSIZE &&*/ FD_ISSET(ts->sockfd_read, &rdfdset)) {
  495. /* Read from socket to buffer 1. */
  496. count = MIN(BUFSIZE - ts->rdidx1, BUFSIZE - ts->size1);
  497. count = safe_read(ts->sockfd_read, TS_BUF1 + ts->rdidx1, count);
  498. if (count <= 0) {
  499. if (count < 0 && errno == EAGAIN)
  500. goto skip3;
  501. goto kill_session;
  502. }
  503. /* Ignore trailing NUL if it is there */
  504. if (!TS_BUF1[ts->rdidx1 + count - 1]) {
  505. --count;
  506. }
  507. ts->size1 += count;
  508. ts->rdidx1 += count;
  509. if (ts->rdidx1 >= BUFSIZE) /* actually == BUFSIZE */
  510. ts->rdidx1 = 0;
  511. }
  512. skip3:
  513. if (/*ts->size2 < BUFSIZE &&*/ FD_ISSET(ts->ptyfd, &rdfdset)) {
  514. /* Read from pty to buffer 2. */
  515. count = MIN(BUFSIZE - ts->rdidx2, BUFSIZE - ts->size2);
  516. count = safe_read(ts->ptyfd, TS_BUF2 + ts->rdidx2, count);
  517. if (count <= 0) {
  518. if (count < 0 && errno == EAGAIN)
  519. goto skip4;
  520. goto kill_session;
  521. }
  522. ts->size2 += count;
  523. ts->rdidx2 += count;
  524. if (ts->rdidx2 >= BUFSIZE) /* actually == BUFSIZE */
  525. ts->rdidx2 = 0;
  526. }
  527. skip4:
  528. ts = next;
  529. continue;
  530. kill_session:
  531. free_session(ts);
  532. ts = next;
  533. }
  534. goto again;
  535. }