Commit b35725c544eca03f09783f03a677c9faa5658e2e

Authored by Jan Kiszka
Committed by Anthony Liguori
1 parent 753a5f17

slirp: Refactor tcp_ctl

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 30 additions and 79 deletions
slirp/tcp_subr.c
@@ -1228,84 +1228,35 @@ do_prompt: @@ -1228,84 +1228,35 @@ do_prompt:
1228 * Return 0 if this connections is to be closed, 1 otherwise, 1228 * Return 0 if this connections is to be closed, 1 otherwise,
1229 * return 2 if this is a command-line connection 1229 * return 2 if this is a command-line connection
1230 */ 1230 */
1231 -int  
1232 -tcp_ctl(struct socket *so) 1231 +int tcp_ctl(struct socket *so)
1233 { 1232 {
1234 - struct sbuf *sb = &so->so_snd;  
1235 - int command;  
1236 - struct ex_list *ex_ptr;  
1237 - int do_pty;  
1238 - // struct socket *tmpso;  
1239 -  
1240 - DEBUG_CALL("tcp_ctl");  
1241 - DEBUG_ARG("so = %lx", (long )so);  
1242 -  
1243 -#if 0  
1244 - /*  
1245 - * Check if they're authorised  
1246 - */  
1247 - if (ctl_addr.s_addr && (ctl_addr.s_addr == -1 || (so->so_laddr.s_addr != ctl_addr.s_addr))) {  
1248 - sb->sb_cc = sprintf(sb->sb_wptr,"Error: Permission denied.\r\n");  
1249 - sb->sb_wptr += sb->sb_cc;  
1250 - return 0;  
1251 - }  
1252 -#endif  
1253 - command = (ntohl(so->so_faddr.s_addr) & 0xff);  
1254 -  
1255 - switch(command) {  
1256 - default: /* Check for exec's */  
1257 -  
1258 - /*  
1259 - * Check if it's pty_exec  
1260 - */  
1261 - for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {  
1262 - if (ex_ptr->ex_fport == so->so_fport &&  
1263 - command == ex_ptr->ex_addr) {  
1264 - if (ex_ptr->ex_pty == 3) {  
1265 - so->s = -1;  
1266 - so->extra = (void *)ex_ptr->ex_exec;  
1267 - return 1;  
1268 - }  
1269 - do_pty = ex_ptr->ex_pty;  
1270 - goto do_exec;  
1271 - }  
1272 - }  
1273 -  
1274 - /*  
1275 - * Nothing bound..  
1276 - */  
1277 - /* tcp_fconnect(so); */  
1278 -  
1279 - /* FALLTHROUGH */  
1280 - case CTL_ALIAS:  
1281 - sb->sb_cc = snprintf(sb->sb_wptr, sb->sb_datalen - (sb->sb_wptr - sb->sb_data),  
1282 - "Error: No application configured.\r\n");  
1283 - sb->sb_wptr += sb->sb_cc;  
1284 - return(0);  
1285 -  
1286 - do_exec:  
1287 - DEBUG_MISC((dfd, " executing %s \n",ex_ptr->ex_exec));  
1288 - return(fork_exec(so, ex_ptr->ex_exec, do_pty));  
1289 -  
1290 -#if 0  
1291 - case CTL_CMD:  
1292 - for (tmpso = tcb.so_next; tmpso != &tcb; tmpso = tmpso->so_next) {  
1293 - if (tmpso->so_emu == EMU_CTL &&  
1294 - !(tmpso->so_tcpcb?  
1295 - (tmpso->so_tcpcb->t_state & (TCPS_TIME_WAIT|TCPS_LAST_ACK))  
1296 - :0)) {  
1297 - /* Ooops, control connection already active */  
1298 - sb->sb_cc = sprintf(sb->sb_wptr,"Sorry, already connected.\r\n");  
1299 - sb->sb_wptr += sb->sb_cc;  
1300 - return 0;  
1301 - }  
1302 - }  
1303 - so->so_emu = EMU_CTL;  
1304 - ctl_password_ok = 0;  
1305 - sb->sb_cc = sprintf(sb->sb_wptr, "Slirp command-line ready (type \"help\" for help).\r\nSlirp> ");  
1306 - sb->sb_wptr += sb->sb_cc;  
1307 - do_echo=-1;  
1308 - return(2);  
1309 -#endif  
1310 - } 1233 + int command = (ntohl(so->so_faddr.s_addr) & 0xff);
  1234 + struct sbuf *sb = &so->so_snd;
  1235 + struct ex_list *ex_ptr;
  1236 + int do_pty;
  1237 +
  1238 + DEBUG_CALL("tcp_ctl");
  1239 + DEBUG_ARG("so = %lx", (long )so);
  1240 +
  1241 + if (command != CTL_ALIAS) {
  1242 + /* Check if it's pty_exec */
  1243 + for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
  1244 + if (ex_ptr->ex_fport == so->so_fport &&
  1245 + command == ex_ptr->ex_addr) {
  1246 + if (ex_ptr->ex_pty == 3) {
  1247 + so->s = -1;
  1248 + so->extra = (void *)ex_ptr->ex_exec;
  1249 + return 1;
  1250 + }
  1251 + do_pty = ex_ptr->ex_pty;
  1252 + DEBUG_MISC((dfd, " executing %s \n",ex_ptr->ex_exec));
  1253 + return fork_exec(so, ex_ptr->ex_exec, do_pty);
  1254 + }
  1255 + }
  1256 + }
  1257 + sb->sb_cc =
  1258 + snprintf(sb->sb_wptr, sb->sb_datalen - (sb->sb_wptr - sb->sb_data),
  1259 + "Error: No application configured.\r\n");
  1260 + sb->sb_wptr += sb->sb_cc;
  1261 + return 0;
1311 } 1262 }