Commit f932b6ce717e65687c3095e3e41a6c18972f996c

Authored by Jan Kiszka
Committed by Anthony Liguori
1 parent 3c6a0580

slirp: Prepare for persistent socket state flags

This prepares for adding flags to socket.so_state that must not be
removed during the lifetime of a socket.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
slirp/slirp.c
... ... @@ -495,7 +495,8 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
495 495 continue;
496 496  
497 497 /* else failed */
498   - so->so_state = SS_NOFDREF;
  498 + so->so_state &= SS_PERSISTENT_MASK;
  499 + so->so_state |= SS_NOFDREF;
499 500 }
500 501 /* else so->so_state &= ~SS_ISFCONNECTING; */
501 502  
... ... @@ -529,7 +530,8 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
529 530 continue; /* Still connecting, continue */
530 531  
531 532 /* else failed */
532   - so->so_state = SS_NOFDREF;
  533 + so->so_state &= SS_PERSISTENT_MASK;
  534 + so->so_state |= SS_NOFDREF;
533 535  
534 536 /* tcp_input will take care of it */
535 537 } else {
... ... @@ -540,7 +542,8 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
540 542 errno == EINPROGRESS || errno == ENOTCONN)
541 543 continue;
542 544 /* else failed */
543   - so->so_state = SS_NOFDREF;
  545 + so->so_state &= SS_PERSISTENT_MASK;
  546 + so->so_state |= SS_NOFDREF;
544 547 } else
545 548 so->so_state &= ~SS_ISFCONNECTING;
546 549  
... ...
slirp/socket.c
... ... @@ -581,7 +581,8 @@ sosendto(struct socket *so, struct mbuf *m)
581 581 */
582 582 if (so->so_expire)
583 583 so->so_expire = curtime + SO_EXPIRE;
584   - so->so_state = SS_ISFCONNECTED; /* So that it gets select()ed */
  584 + so->so_state &= SS_PERSISTENT_MASK;
  585 + so->so_state |= SS_ISFCONNECTED; /* So that it gets select()ed */
585 586 return 0;
586 587 }
587 588  
... ... @@ -620,7 +621,8 @@ tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags
620 621 if (flags & SS_FACCEPTONCE)
621 622 so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2;
622 623  
623   - so->so_state = (SS_FACCEPTCONN|flags);
  624 + so->so_state &= SS_PERSISTENT_MASK;
  625 + so->so_state |= (SS_FACCEPTCONN | flags);
624 626 so->so_lport = lport; /* Kept in network format */
625 627 so->so_laddr.s_addr = laddr; /* Ditto */
626 628  
... ... @@ -715,10 +717,12 @@ sofcantrcvmore(struct socket *so)
715 717 }
716 718 }
717 719 so->so_state &= ~(SS_ISFCONNECTING);
718   - if (so->so_state & SS_FCANTSENDMORE)
719   - so->so_state = SS_NOFDREF; /* Don't select it */ /* XXX close() here as well? */
720   - else
  720 + if (so->so_state & SS_FCANTSENDMORE) {
  721 + so->so_state &= SS_PERSISTENT_MASK;
  722 + so->so_state |= SS_NOFDREF; /* Don't select it */
  723 + } else {
721 724 so->so_state |= SS_FCANTRCVMORE;
  725 + }
722 726 }
723 727  
724 728 static void
... ... @@ -734,10 +738,12 @@ sofcantsendmore(struct socket *so)
734 738 }
735 739 }
736 740 so->so_state &= ~(SS_ISFCONNECTING);
737   - if (so->so_state & SS_FCANTRCVMORE)
738   - so->so_state = SS_NOFDREF; /* as above */
739   - else
  741 + if (so->so_state & SS_FCANTRCVMORE) {
  742 + so->so_state &= SS_PERSISTENT_MASK;
  743 + so->so_state |= SS_NOFDREF; /* as above */
  744 + } else {
740 745 so->so_state |= SS_FCANTSENDMORE;
  746 + }
741 747 }
742 748  
743 749 void
... ...
slirp/socket.h
... ... @@ -71,6 +71,8 @@ struct socket {
71 71 #define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */
72 72 #define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */
73 73  
  74 +#define SS_PERSISTENT_MASK 0xf000 /* Unremovable state bits */
  75 +
74 76 extern struct socket tcb;
75 77  
76 78 struct socket * solookup _P((struct socket *, struct in_addr, u_int, struct in_addr, u_int));
... ...
slirp/tcp_input.c
... ... @@ -1038,7 +1038,8 @@ trimthenstep6:
1038 1038 soisfconnected(so);
1039 1039 so->so_state &= ~SS_CTL; /* success XXX */
1040 1040 } else if (ret == 2) {
1041   - so->so_state = SS_NOFDREF; /* CTL_CMD */
  1041 + so->so_state &= SS_PERSISTENT_MASK;
  1042 + so->so_state |= SS_NOFDREF; /* CTL_CMD */
1042 1043 } else {
1043 1044 needoutput = 1;
1044 1045 tp->t_state = TCPS_FIN_WAIT_1;
... ...
slirp/udp.c
... ... @@ -666,7 +666,8 @@ udp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport,
666 666 if (flags != SS_FACCEPTONCE)
667 667 so->so_expire = 0;
668 668  
669   - so->so_state = SS_ISFCONNECTED;
  669 + so->so_state &= SS_PERSISTENT_MASK;
  670 + so->so_state |= SS_ISFCONNECTED;
670 671  
671 672 return so;
672 673 }
... ...