ソースを参照

[tls] Eliminate polling while TX state machine is idle

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13年前
コミット
5eb60f4883
1個のファイルの変更67行の追加13行の削除
  1. 67
    13
      src/net/tls.c

+ 67
- 13
src/net/tls.c ファイルの表示

@@ -580,6 +580,62 @@ static void tls_verify_handshake ( struct tls_session *tls, void *out ) {
580 580
 	digest_final ( sha1, sha1_ctx, sha1_digest );
581 581
 }
582 582
 
583
+/******************************************************************************
584
+ *
585
+ * TX state machine transitions
586
+ *
587
+ ******************************************************************************
588
+ */
589
+
590
+/**
591
+ * Resume TX state machine
592
+ *
593
+ * @v tls		TLS session
594
+ */
595
+static void tls_tx_resume ( struct tls_session *tls ) {
596
+	process_add ( &tls->process );
597
+}
598
+
599
+/**
600
+ * Enter TX state machine active state
601
+ *
602
+ * @v tls		TLS session
603
+ * @v state		TX state
604
+ */
605
+static void tls_tx_start ( struct tls_session *tls, enum tls_tx_state state ) {
606
+
607
+	/* Enter specified state */
608
+	tls->tx_state = state;
609
+
610
+	/* Resume state machine */
611
+	tls_tx_resume ( tls );
612
+}
613
+
614
+/**
615
+ * Enter TX state machine idle state
616
+ *
617
+ * @v tls		TLS session
618
+ */
619
+static void tls_tx_none ( struct tls_session *tls ) {
620
+
621
+	/* Enter idle state */
622
+	tls->tx_state = TLS_TX_NONE;
623
+}
624
+
625
+/**
626
+ * Enter TX state machine data state
627
+ *
628
+ * @v tls		TLS session
629
+ */
630
+static void tls_tx_data ( struct tls_session *tls ) {
631
+
632
+	/* Enter data state */
633
+	tls->tx_state = TLS_TX_DATA;
634
+
635
+	/* Send notification of a window change */
636
+	xfer_window_changed ( &tls->plainstream );
637
+}
638
+
583 639
 /******************************************************************************
584 640
  *
585 641
  * Record handling
@@ -929,7 +985,7 @@ static int tls_new_server_hello_done ( struct tls_session *tls,
929 985
 	}
930 986
 
931 987
 	/* Start sending the Client Key Exchange */
932
-	tls->tx_state = TLS_TX_CLIENT_KEY_EXCHANGE;
988
+	tls_tx_start ( tls, TLS_TX_CLIENT_KEY_EXCHANGE );
933 989
 
934 990
 	return 0;
935 991
 }
@@ -946,13 +1002,10 @@ static int tls_new_finished ( struct tls_session *tls,
946 1002
 			      void *data, size_t len ) {
947 1003
 
948 1004
 	/* FIXME: Handle this properly */
949
-	tls->tx_state = TLS_TX_DATA;
1005
+	tls_tx_data ( tls );
950 1006
 	( void ) data;
951 1007
 	( void ) len;
952 1008
 
953
-	/* Send notification of a window change */
954
-	xfer_window_changed ( &tls->plainstream );
955
-
956 1009
 	return 0;
957 1010
 }
958 1011
 
@@ -1627,6 +1680,7 @@ static int tls_cipherstream_deliver ( struct tls_session *tls,
1627 1680
 static struct interface_operation tls_cipherstream_ops[] = {
1628 1681
 	INTF_OP ( xfer_deliver, struct tls_session *,
1629 1682
 		  tls_cipherstream_deliver ),
1683
+	INTF_OP ( xfer_window_changed, struct tls_session *, tls_tx_resume ),
1630 1684
 	INTF_OP ( intf_close, struct tls_session *, tls_close ),
1631 1685
 };
1632 1686
 
@@ -1647,7 +1701,7 @@ static struct interface_descriptor tls_cipherstream_desc =
1647 1701
  *
1648 1702
  * @v tls		TLS session
1649 1703
  */
1650
-static void tls_step ( struct tls_session *tls ) {
1704
+static void tls_tx_step ( struct tls_session *tls ) {
1651 1705
 	int rc;
1652 1706
 
1653 1707
 	/* Wait for cipherstream to become ready */
@@ -1665,7 +1719,7 @@ static void tls_step ( struct tls_session *tls ) {
1665 1719
 			       tls, strerror ( rc ) );
1666 1720
 			goto err;
1667 1721
 		}
1668
-		tls->tx_state = TLS_TX_NONE;
1722
+		tls_tx_none ( tls );
1669 1723
 		break;
1670 1724
 	case TLS_TX_CLIENT_KEY_EXCHANGE:
1671 1725
 		/* Send Client Key Exchange */
@@ -1674,7 +1728,7 @@ static void tls_step ( struct tls_session *tls ) {
1674 1728
 			       "%s\n", tls, strerror ( rc ) );
1675 1729
 			goto err;
1676 1730
 		}
1677
-		tls->tx_state = TLS_TX_CHANGE_CIPHER;
1731
+		tls_tx_start ( tls, TLS_TX_CHANGE_CIPHER );
1678 1732
 		break;
1679 1733
 	case TLS_TX_CHANGE_CIPHER:
1680 1734
 		/* Send Change Cipher, and then change the cipher in use */
@@ -1691,7 +1745,7 @@ static void tls_step ( struct tls_session *tls ) {
1691 1745
 			goto err;
1692 1746
 		}
1693 1747
 		tls->tx_seq = 0;
1694
-		tls->tx_state = TLS_TX_FINISHED;
1748
+		tls_tx_start ( tls, TLS_TX_FINISHED );
1695 1749
 		break;
1696 1750
 	case TLS_TX_FINISHED:
1697 1751
 		/* Send Finished */
@@ -1700,7 +1754,7 @@ static void tls_step ( struct tls_session *tls ) {
1700 1754
 			       tls, strerror ( rc ) );
1701 1755
 			goto err;
1702 1756
 		}
1703
-		tls->tx_state = TLS_TX_NONE;
1757
+		tls_tx_none ( tls );
1704 1758
 		break;
1705 1759
 	case TLS_TX_DATA:
1706 1760
 		/* Nothing to do */
@@ -1717,7 +1771,7 @@ static void tls_step ( struct tls_session *tls ) {
1717 1771
 
1718 1772
 /** TLS TX process descriptor */
1719 1773
 static struct process_descriptor tls_process_desc =
1720
-	PROC_DESC ( struct tls_session, process, tls_step );
1774
+	PROC_DESC_ONCE ( struct tls_session, process, tls_tx_step );
1721 1775
 
1722 1776
 /******************************************************************************
1723 1777
  *
@@ -1749,8 +1803,8 @@ int add_tls ( struct interface *xfer, struct interface **next ) {
1749 1803
 			      ( sizeof ( tls->pre_master_secret.random ) ) );
1750 1804
 	digest_init ( &md5_algorithm, tls->handshake_md5_ctx );
1751 1805
 	digest_init ( &sha1_algorithm, tls->handshake_sha1_ctx );
1752
-	tls->tx_state = TLS_TX_CLIENT_HELLO;
1753
-	process_init ( &tls->process, &tls_process_desc, &tls->refcnt );
1806
+	process_init_stopped ( &tls->process, &tls_process_desc, &tls->refcnt );
1807
+	tls_tx_start ( tls, TLS_TX_CLIENT_HELLO );
1754 1808
 
1755 1809
 	/* Attach to parent interface, mortalise self, and return */
1756 1810
 	intf_plug_plug ( &tls->plainstream, xfer );

読み込み中…
キャンセル
保存