Browse Source

[tls] Eliminate polling while TX state machine is idle

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
5eb60f4883
1 changed files with 67 additions and 13 deletions
  1. 67
    13
      src/net/tls.c

+ 67
- 13
src/net/tls.c View File

580
 	digest_final ( sha1, sha1_ctx, sha1_digest );
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
  * Record handling
641
  * Record handling
929
 	}
985
 	}
930
 
986
 
931
 	/* Start sending the Client Key Exchange */
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
 	return 0;
990
 	return 0;
935
 }
991
 }
946
 			      void *data, size_t len ) {
1002
 			      void *data, size_t len ) {
947
 
1003
 
948
 	/* FIXME: Handle this properly */
1004
 	/* FIXME: Handle this properly */
949
-	tls->tx_state = TLS_TX_DATA;
1005
+	tls_tx_data ( tls );
950
 	( void ) data;
1006
 	( void ) data;
951
 	( void ) len;
1007
 	( void ) len;
952
 
1008
 
953
-	/* Send notification of a window change */
954
-	xfer_window_changed ( &tls->plainstream );
955
-
956
 	return 0;
1009
 	return 0;
957
 }
1010
 }
958
 
1011
 
1627
 static struct interface_operation tls_cipherstream_ops[] = {
1680
 static struct interface_operation tls_cipherstream_ops[] = {
1628
 	INTF_OP ( xfer_deliver, struct tls_session *,
1681
 	INTF_OP ( xfer_deliver, struct tls_session *,
1629
 		  tls_cipherstream_deliver ),
1682
 		  tls_cipherstream_deliver ),
1683
+	INTF_OP ( xfer_window_changed, struct tls_session *, tls_tx_resume ),
1630
 	INTF_OP ( intf_close, struct tls_session *, tls_close ),
1684
 	INTF_OP ( intf_close, struct tls_session *, tls_close ),
1631
 };
1685
 };
1632
 
1686
 
1647
  *
1701
  *
1648
  * @v tls		TLS session
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
 	int rc;
1705
 	int rc;
1652
 
1706
 
1653
 	/* Wait for cipherstream to become ready */
1707
 	/* Wait for cipherstream to become ready */
1665
 			       tls, strerror ( rc ) );
1719
 			       tls, strerror ( rc ) );
1666
 			goto err;
1720
 			goto err;
1667
 		}
1721
 		}
1668
-		tls->tx_state = TLS_TX_NONE;
1722
+		tls_tx_none ( tls );
1669
 		break;
1723
 		break;
1670
 	case TLS_TX_CLIENT_KEY_EXCHANGE:
1724
 	case TLS_TX_CLIENT_KEY_EXCHANGE:
1671
 		/* Send Client Key Exchange */
1725
 		/* Send Client Key Exchange */
1674
 			       "%s\n", tls, strerror ( rc ) );
1728
 			       "%s\n", tls, strerror ( rc ) );
1675
 			goto err;
1729
 			goto err;
1676
 		}
1730
 		}
1677
-		tls->tx_state = TLS_TX_CHANGE_CIPHER;
1731
+		tls_tx_start ( tls, TLS_TX_CHANGE_CIPHER );
1678
 		break;
1732
 		break;
1679
 	case TLS_TX_CHANGE_CIPHER:
1733
 	case TLS_TX_CHANGE_CIPHER:
1680
 		/* Send Change Cipher, and then change the cipher in use */
1734
 		/* Send Change Cipher, and then change the cipher in use */
1691
 			goto err;
1745
 			goto err;
1692
 		}
1746
 		}
1693
 		tls->tx_seq = 0;
1747
 		tls->tx_seq = 0;
1694
-		tls->tx_state = TLS_TX_FINISHED;
1748
+		tls_tx_start ( tls, TLS_TX_FINISHED );
1695
 		break;
1749
 		break;
1696
 	case TLS_TX_FINISHED:
1750
 	case TLS_TX_FINISHED:
1697
 		/* Send Finished */
1751
 		/* Send Finished */
1700
 			       tls, strerror ( rc ) );
1754
 			       tls, strerror ( rc ) );
1701
 			goto err;
1755
 			goto err;
1702
 		}
1756
 		}
1703
-		tls->tx_state = TLS_TX_NONE;
1757
+		tls_tx_none ( tls );
1704
 		break;
1758
 		break;
1705
 	case TLS_TX_DATA:
1759
 	case TLS_TX_DATA:
1706
 		/* Nothing to do */
1760
 		/* Nothing to do */
1717
 
1771
 
1718
 /** TLS TX process descriptor */
1772
 /** TLS TX process descriptor */
1719
 static struct process_descriptor tls_process_desc =
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
 			      ( sizeof ( tls->pre_master_secret.random ) ) );
1803
 			      ( sizeof ( tls->pre_master_secret.random ) ) );
1750
 	digest_init ( &md5_algorithm, tls->handshake_md5_ctx );
1804
 	digest_init ( &md5_algorithm, tls->handshake_md5_ctx );
1751
 	digest_init ( &sha1_algorithm, tls->handshake_sha1_ctx );
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
 	/* Attach to parent interface, mortalise self, and return */
1809
 	/* Attach to parent interface, mortalise self, and return */
1756
 	intf_plug_plug ( &tls->plainstream, xfer );
1810
 	intf_plug_plug ( &tls->plainstream, xfer );

Loading…
Cancel
Save