瀏覽代碼

Expose PSH flag in TcpRepr.

whitequark 7 年之前
父節點
當前提交
a14c47655e
共有 3 個文件被更改,包括 13 次插入4 次删除
  1. 1 0
      src/iface/ethernet.rs
  2. 3 2
      src/socket/tcp.rs
  3. 9 2
      src/wire/tcp.rs

+ 1 - 0
src/iface/ethernet.rs

@@ -257,6 +257,7 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
                                     src_port:     tcp_packet.dst_port(),
                                     dst_port:     tcp_packet.src_port(),
                                     control:      TcpControl::Rst,
+                                    push:         false,
                                     seq_number:   tcp_packet.ack_number(),
                                     ack_number:   Some(tcp_packet.seq_number() +
                                                        tcp_packet.segment_len()),

+ 3 - 2
src/socket/tcp.rs

@@ -939,6 +939,7 @@ impl<'a> TcpSocket<'a> {
             src_port:     self.local_endpoint.port,
             dst_port:     self.remote_endpoint.port,
             control:      TcpControl::None,
+            push:         false,
             seq_number:   self.local_seq_no,
             ack_number:   None,
             window_len:   self.rx_buffer.window() as u16,
@@ -1199,14 +1200,14 @@ mod test {
 
     const SEND_TEMPL: TcpRepr<'static> = TcpRepr {
         src_port: REMOTE_PORT, dst_port: LOCAL_PORT,
-        control: TcpControl::None,
+        control: TcpControl::None, push: false,
         seq_number: TcpSeqNumber(0), ack_number: Some(TcpSeqNumber(0)),
         window_len: 256, max_seg_size: None,
         payload: &[]
     };
     const RECV_TEMPL:  TcpRepr<'static> = TcpRepr {
         src_port: LOCAL_PORT, dst_port: REMOTE_PORT,
-        control: TcpControl::None,
+        control: TcpControl::None, push: false,
         seq_number: TcpSeqNumber(0), ack_number: Some(TcpSeqNumber(0)),
         window_len: 64, max_seg_size: None,
         payload: &[]

+ 9 - 2
src/wire/tcp.rs

@@ -615,6 +615,7 @@ pub struct Repr<'a> {
     pub src_port:     u16,
     pub dst_port:     u16,
     pub control:      Control,
+    pub push:         bool,
     pub seq_number:   SeqNumber,
     pub ack_number:   Option<SeqNumber>,
     pub window_len:   u16,
@@ -670,6 +671,7 @@ impl<'a> Repr<'a> {
             src_port:     packet.src_port(),
             dst_port:     packet.dst_port(),
             control:      control,
+            push:         packet.psh(),
             seq_number:   packet.seq_number(),
             ack_number:   ack_number,
             window_len:   packet.window_len(),
@@ -710,6 +712,7 @@ impl<'a> Repr<'a> {
             Control::Fin  => packet.set_fin(true),
             Control::Rst  => packet.set_rst(true)
         }
+        packet.set_psh(self.push);
         packet.set_ack(self.ack_number.is_some());
         {
             let mut options = packet.options_mut();
@@ -780,6 +783,9 @@ impl<'a> fmt::Display for Repr<'a> {
             Control::Rst => write!(f, " rst")?,
             Control::None => ()
         }
+        if self.push {
+            write!(f, " psh")?;
+        }
         write!(f, " seq={}", self.seq_number)?;
         if let Some(ack_number) = self.ack_number {
             write!(f, " ack={}", ack_number)?;
@@ -892,8 +898,8 @@ mod test {
         [0xbf, 0x00, 0x00, 0x50,
          0x01, 0x23, 0x45, 0x67,
          0x00, 0x00, 0x00, 0x00,
-         0x50, 0x02, 0x01, 0x23,
-         0x7a, 0x8d, 0x00, 0x00,
+         0x50, 0x0a, 0x01, 0x23,
+         0x7a, 0x85, 0x00, 0x00,
          0xaa, 0x00, 0x00, 0xff];
 
     fn packet_repr() -> Repr<'static> {
@@ -904,6 +910,7 @@ mod test {
             ack_number:   None,
             window_len:   0x0123,
             control:      Control::Syn,
+            push:         true,
             max_seg_size: None,
             payload:      &PAYLOAD_BYTES
         }