< Return to Video

35C3 - Transmission Control Protocol

  • 0:00 - 0:18
    35C3 preroll music
  • 0:18 - 0:23
    Herald-Angel: The next talk is by Hannes
    Mehnert, you can see him here already.
  • 0:23 - 0:31
    It's called Transmission Control Protocol,
    also known as TCP and Hannes Mehnert works
  • 0:31 - 0:36
    at a non-profit organization in Berlin.
    It's called Center for the cultivation of
  • 0:36 - 0:46
    technology. And he also works on an open
    ... no, Mirage OS. If you don't know it,
  • 0:46 - 0:52
    maybe you can find out what it is. And he
    researches in several engineering areas
  • 0:52 - 0:58
    such as: programming languages, network
    protocols, security protocols and many
  • 0:58 - 1:02
    many more. So give him a warm applause for
    his talk.
  • 1:02 - 1:11
    Applause
  • 1:11 - 1:12
    Hannes Mehnert: Thank you. Yes, today I
  • 1:12 - 1:17
    want to talk a bit about the Transmission
    Control Protocol and the Internet Protocol
  • 1:17 - 1:24
    suite. So, what is it all about? It's a
    foundation talk here, so if you already
  • 1:24 - 1:30
    know TCP/IP by heart then maybe only the
    last five minutes will be of interest for
  • 1:30 - 1:36
    you, otherwise. So, if you want to connect
    your laptop or if you want to browse to a
  • 1:36 - 1:43
    Web site somewhere, you want to read that
    Web site, it is that, the client on your
  • 1:43 - 1:50
    laptop or the browser that sends an HTTP
    request to the web server host. So it sends
  • 1:50 - 1:59
    an HTTP request which is specified by the
    HTTP protocol. It's maybe GET /. It's a
  • 1:59 - 2:06
    common method of getting the main page of
    a website, but how is this information
  • 2:06 - 2:11
    actually transmitted to the server? That
    is the question and the motivation for
  • 2:11 - 2:19
    this talk. So that is something I want to
    go deep into the answer for the question.
  • 2:19 - 2:24
    So let's look a bit at the network
    topology. So, on the left hand side we
  • 2:24 - 2:30
    have the laptop which sends to some server
    a GET request. You can see that by the
  • 2:30 - 2:36
    dashed arrow and the laptop itself is
    connected, likely via a wireless network
  • 2:36 - 2:42
    to the Internet. But what is actually the
    Internet? Well, the Internet is a
  • 2:42 - 2:47
    collection of computers and your laptop or
    anyone's mobile phone is likely connected
  • 2:47 - 2:54
    to a router, a router is just a normal
    computer which has some knowledge about
  • 2:54 - 3:00
    the network and that router is likely
    connected via fiber or a satellite or any
  • 3:00 - 3:13
    other link, can also be an ethernet cable
    to another router or to several routers.
  • 3:13 - 3:19
    And in this picture you can only see two
    routers, the router A and router B, but
  • 3:19 - 3:24
    there may be any number of routers or
    nearly any number of routers in between
  • 3:24 - 3:29
    you and the server. So here the router B
    is connected via Ethernet, which is just a
  • 3:29 - 3:37
    physical cable to the server and Ethernet
    is a protocol which is talked over the
  • 3:37 - 3:44
    cable. So I won't to go into the physical
    network connectivity like fibers and
  • 3:44 - 3:53
    satellite and cables and copper cables, in
    this talk at all but I will start with the
  • 3:53 - 4:02
    layer which is on top of the physical
    medium. So the first one is the data link
  • 4:02 - 4:09
    layer. And, well, what is the data link
    layer? What's task is it? It has a scope
  • 4:09 - 4:15
    of a network and it only spans over the
    local network to which a host is
  • 4:15 - 4:20
    connected. So in this picture, only the
    laptop and the router A share the same
  • 4:20 - 4:27
    data link layer as well as the router B
    and the router A, they share the same data
  • 4:27 - 4:32
    link layer. It's also the case that router
    B and the server share the same data link
  • 4:32 - 4:38
    layer. What is the task of the data link
    layer? Well it's pretty easy, it just
  • 4:38 - 4:43
    moves Internet layer packets between two
    different hosts that sit on the same link.
  • 4:43 - 4:50
    So, the data link layers really it's only
    purpose is to provide an abstraction over
  • 4:50 - 4:57
    the physical thing and how many bytes you
    can transport on the physical media over
  • 4:57 - 5:05
    the link. So the next layer is already the
    Internet layer. The internet layer which
  • 5:05 - 5:10
    task is to transport packets across
    multiple networks. So as you have seen in
  • 5:10 - 5:16
    the diagram there are router A and router
    B, they are both connected to several data
  • 5:16 - 5:21
    link layers and they use the Internet
    layer in order to transport packets
  • 5:21 - 5:30
    across. The Internet layer solves already
    the issue of addressing by providing for
  • 5:30 - 5:37
    every host an IP address. IP address is
    actually the Internet Protocol address and
  • 5:37 - 5:42
    the Internet layer provides another task
    or solves another task which is routing so
  • 5:42 - 5:48
    it forwards packets to the next router
    which is hope fully closer to the final
  • 5:48 - 5:54
    destination. That is the task. The
    Internet layer also has support for
  • 5:54 - 6:01
    fragmentation. So if your higher layer
    sends something which is way too big for
  • 6:01 - 6:06
    the data link layer, then the Internet
    layer can fragment that and the other side
  • 6:06 - 6:14
    has to reassemble it. What is on top of
    the Internet layer is the transport layer.
  • 6:14 - 6:20
    So the transport layer establishes host to
    host connectivity. It does multiplexing
  • 6:20 - 6:27
    usually using source and destination ports
    and there are two widely used transport
  • 6:27 - 6:33
    layer protocols, which I will go into more
    detail in this talk, which is the user
  • 6:33 - 6:38
    datagram protocol and the transmission
    control protocol, that's UDP and TCP and
  • 6:38 - 6:49
    they have different properties. So UDP is
    unreliable and it is not ordered and it is
  • 6:49 - 6:55
    only an abstraction over datagrams and it
    has on the advantage side, a very low
  • 6:55 - 7:06
    overhead. Whereas TCP is a reliable and
    ordered byte stream, so you have a
  • 7:06 - 7:11
    reliable byte stream which you can work
    on. The downside of TCP is that it's
  • 7:11 - 7:17
    connection establishment and teardown is
    slightly more complex. In UDP, you just
  • 7:17 - 7:22
    don't have to establish a connection and
    teardown and connect. But in TCP you have
  • 7:22 - 7:31
    to synchronize the two hosts. Then on top
    of the transport layer we have the
  • 7:31 - 7:36
    application layer and the application
    layer just exchanges application data over
  • 7:36 - 7:44
    the transport layer. So some examples for
    application layers are HTTP or TLS or DNS.
  • 7:44 - 7:52
    So in the first example we saw there was
    HTTP and HTTP was used to send the GET
  • 7:52 - 7:57
    request. So that is all application layer,
    which I won't focus on in this talk at
  • 7:57 - 8:04
    all. For the lower layers the application
    layers, just payload so it's just some
  • 8:04 - 8:11
    arbitrary data. So if we look again at
    that picture and we draw the different
  • 8:11 - 8:17
    layers which are supported or which are
    used by the different devices, we end up
  • 8:17 - 8:23
    with a diagram similar to that. So here on
    the left we have the laptop again which
  • 8:23 - 8:30
    has all four layers and then we have the
    routers in the middle which are only using
  • 8:30 - 8:35
    the data link and the Internet layer and
    then on the right hand side we have the
  • 8:35 - 8:42
    server which also has all four layers. So
    the transport layer is really host to
  • 8:42 - 8:49
    host, so the TCP we saw earlier, the TCP
    is establishing a connection from the
  • 8:49 - 8:55
    laptop to the server and on top of TCP. So
    on top of the transport layer there is the
  • 8:55 - 9:01
    process to process communication so the
    application layer which is the web browser
  • 9:01 - 9:07
    talking to the web server. So only on the
    highest layer here, we have the GET
  • 9:07 - 9:14
    request. And the routers in the middle
    they don't have to inspect or they don't
  • 9:14 - 9:21
    have to use information of the transport
    or application layer from the laptop or
  • 9:21 - 9:30
    the server. So the routers just for using
    the Internet layer they forward packets to
  • 9:30 - 9:35
    the next router or to the final
    destination. So the laptop first sends the
  • 9:35 - 9:43
    whole TCP segment or a TCP packet to the
    router and the router A decides, oh yeah
  • 9:43 - 9:49
    we'll forward it to router B because
    router B is more closer to the final
  • 9:49 - 9:54
    destination than myself and the router B
    says, oh yeah well I actually know and I'm
  • 9:54 - 9:59
    connected via ethernet to the final
    destination so I will just forward it to
  • 9:59 - 10:08
    the server. That's how the data flow of
    such a connection would look like. How
  • 10:08 - 10:13
    does a packet actually look like? So we
    have seen that at the application layer we
  • 10:13 - 10:19
    have the application data, which is here
    in blue and that one is just the GET
  • 10:19 - 10:24
    request. Then the transport layer actually
    prefixes the application data with a
  • 10:24 - 10:30
    header which is a common header that
    encodes some data, we will look into the
  • 10:30 - 10:39
    TCP header in more detail soon, then the
    Internet layer also adds a header, a
  • 10:39 - 10:46
    prefix: the IP header, which is just put
    in front of the TCP header. And then the
  • 10:46 - 10:52
    data link layer, well that is the lowest
    layer we actually care about and that one
  • 10:52 - 10:58
    will likely prepend a header and append a
    footer in order to synchronize or to make
  • 10:58 - 11:06
    sure that the physical wire only has only
    sees a single packet at a time. So as you
  • 11:06 - 11:12
    can see from the layering from those two
    pictures on the one side you have the
  • 11:12 - 11:17
    bottom two up layer and every layer if you
    go down from the application to the
  • 11:17 - 11:23
    transport, to the Internet, to data link,
    they basically add some header information
  • 11:23 - 11:28
    and the Internet layer for example that
    takes the TCP header, so the transport
  • 11:28 - 11:34
    layer and the application layer as
    payload, so it doesn't care that it is
  • 11:34 - 11:42
    TCP, it could as well be UDP in this case.
    So what is actually in the. So I will not
  • 11:42 - 11:50
    go into the data link layer details at
    all, but here is the header of an IP
  • 11:50 - 12:00
    version 4 frame or packet and that one is
    at least 20 bytes, it contains various
  • 12:00 - 12:07
    fields. The first one is a four bit
    version, which usually is version 4 in our
  • 12:07 - 12:15
    current world. Then it has a 4 bits header
    length, which is a header length invert,
  • 12:15 - 12:23
    so in multiples of 32 bits. Then it has
    some not really used stuff I won't deal
  • 12:23 - 12:29
    with in this talk. It has the total length
    field with just 16 bits and it describes
  • 12:29 - 12:36
    how long the entire IP frame is. Then it
    has an identification, which is also a 16
  • 12:36 - 12:43
    bit unique number and the 16 bits for
    fragmentation flags and offset. And that
  • 12:43 - 12:49
    is crucial. So, if the IP header decides:
    oh yeah well the package, the application
  • 12:49 - 12:53
    data you sent me is way too big for this
    data link, I need to fragment it, then it
  • 12:53 - 12:58
    will just reuse the very same
    identification number and then use here
  • 12:58 - 13:05
    the 16 bits in the fragmentation flags and
    offset in order to portion that
  • 13:05 - 13:11
    application data into multiple IP
    fragments. Then it has a field which is 8
  • 13:11 - 13:19
    bit, so 1 entire byte, it's the time to
    live and it's actually not a timestamp but
  • 13:19 - 13:27
    it's only a count. So how many routers
    should this package live. How long should
  • 13:27 - 13:34
    this package live and every router
    decreases that time to live by 1. Then it
  • 13:34 - 13:41
    has a 1 byte protocol field which
    specifies what is the type of the payload
  • 13:41 - 13:47
    carried by this IP version 4 packet, then
    it has a 16 bit header checksum which is
  • 13:47 - 13:57
    the CRC checksum to avoid that some bits
    got flipped on the transport. Then we can
  • 13:57 - 14:02
    see the source IP address and the
    destination IP address which is, yeah I
  • 14:02 - 14:07
    mean, the source IP address is the IP
    address of my laptop and the destination
  • 14:07 - 14:14
    IP address, is the IP address of the
    server. And then after those 20 bytes you
  • 14:14 - 14:23
    have either IP options, if the header
    length was more than 20 bytes or you have
  • 14:23 - 14:31
    directly the payload. Now for the protocol
    field here there are various types and
  • 14:31 - 14:35
    various types are predefined. 1 is ICMP
    which is the internet control message
  • 14:35 - 14:42
    protocol, I will talk a bit about that
    which is the product field, there the
  • 14:42 - 14:48
    number set to 1, then for TCP it's set to
    6 and for UDP it's 17. We have other
  • 14:48 - 14:55
    protocols which can be carried over an IP
    frame or an IP packet but I won't go into
  • 14:55 - 15:01
    the details here. As you can see there are
    at least 255 numbers here in the product
  • 15:01 - 15:08
    field. So because it's 8 bit long, you can
    store up to 256 different numbers in
  • 15:08 - 15:18
    there. So ICMP is a protocol I haven't
    talked about at all but it is the internet
  • 15:18 - 15:23
    control message protocol. So it sits on
    top of IP and its purpose is on the one
  • 15:23 - 15:30
    side, to deliver error messages such as
    destination host unreachable or time to
  • 15:30 - 15:34
    live exceeded and on the other side it can
    also carry operational information like
  • 15:34 - 15:43
    diagnostics. There's one program which you
    may know which is called ping. The purpose
  • 15:43 - 15:49
    of ping is to send an ICMP echo request to
    a remote host and the remote host is then
  • 15:49 - 15:57
    supposed to send the very same packet with
    only 1 single bit flipped and send that back
  • 15:57 - 16:04
    to you and that is an ICMP echo reply. And
    if you can successfully ping another host
  • 16:04 - 16:15
    you can verify that the other host has at
    least ip connectivity up and online. OK,
  • 16:15 - 16:21
    Let's look into the next layer which is
    the transport layer. And at first we will
  • 16:21 - 16:27
    look into a UDP header. A UDP header has
    only eight bytes. it contains. It consists
  • 16:27 - 16:32
    of a source port, the destination port.
    Then the length of the entire UDP frame
  • 16:32 - 16:41
    and the checksum the checksum is again a
    16 bit field computed over the entire
  • 16:41 - 16:49
    payload and the header plus some IP pseudo
    header. So this actually carries the
  • 16:49 - 16:55
    information of the source and destination
    ip address inside of itself. UDP as I
  • 16:55 - 17:02
    mentioned is unreliable, unordered and its
    advantage is that the low overhead data
  • 17:02 - 17:11
    grams as you can see it adds 8 bytes to the
    to the payload whereas IP already added 20
  • 17:11 - 17:20
    bytes to the payload. Here's a simple Unix
    program which is a UDP client. This
  • 17:20 - 17:24
    program does not compile because I left
    out some bits but in order to see what how
  • 17:24 - 17:30
    do you actually use this whole IP stack.
    So the IP stack the TCP IP stack is
  • 17:30 - 17:37
    usually embedded in the kernel and as a
    programmer as an API programmer you have the
  • 17:37 - 17:45
    API provided by the Unix sockets API. And
    that one usually contains of the very same
  • 17:45 - 17:52
    five or seven functions which is the first
    one is a socket socket opens or creates a
  • 17:52 - 17:59
    file descriptor and you specifie the
    address family and the socket type. So
  • 17:59 - 18:06
    this is the adress family Internet and the
    socket is a datagram socket. It's called
  • 18:06 - 18:14
    DGRAM in Unix. Once that is created then
    you for a UDP client and you just say Oh I
  • 18:14 - 18:20
    will use the function "send to" which
    takes a socket file descriptor. So just
  • 18:20 - 18:25
    the file descriptor and then some data and
    will just send it to the other side since
  • 18:25 - 18:33
    it's unreliable it's just fire and forget.
    Then afterwards we close the socket file
  • 18:33 - 18:39
    descriptor because we are nice here and we
    try to be nice the other side. So if you
  • 18:39 - 18:44
    don't have a UDP client but if you want to
    implement a UDP server or a UDP listener
  • 18:44 - 18:49
    what do you do is you again create a
    socket then you have the function which is
  • 18:49 - 18:57
    called bind. Bind binds it to a combined
    into a specific IP address on your server
  • 18:57 - 19:03
    or on your network stack then you say
    receive from recieve from takes the socket
  • 19:03 - 19:10
    file descriptor and a buffer and some
    maximum size and an offset. And yeah you
  • 19:10 - 19:18
    just receive from will only return once
    you actually receive the UDP frame on that
  • 19:18 - 19:27
    IP address and port and then you then we
    print out that we received some packets
  • 19:27 - 19:35
    and we close the socket file descriptor.
    So that's UDP. UDP is used for a variety
  • 19:35 - 19:42
    of protocols and that's crucial to have it
    TCP on the other hand is a bit bigger. So
  • 19:42 - 19:48
    instead of eight bytes header TCP adds
    another 20 bytes of header what does the
  • 19:48 - 19:54
    TCP header contain? Well similar to UDP it
    contains a source port and Destination Port
  • 19:54 - 20:00
    both again 16 bits then it contains two
    sequence numbers one is the sequence
  • 20:00 - 20:06
    number itself it's a 32 bit number and one
    is the acknowledgement number which is the
  • 20:06 - 20:13
    last sequence number we have seen from the
    other side then TCP contains a data offset
  • 20:13 - 20:21
    date offset is similar to the header
    length field so TCP a TCP segment may also
  • 20:21 - 20:27
    contain some options so the header may
    contain options before a payload. That's
  • 20:27 - 20:32
    why we need a data set field in order to
    be able to find out where this extra
  • 20:32 - 20:39
    payload start then TCP has certain flags
    and some of these flags a some of these
  • 20:39 - 20:44
    flags are just a single bit of values and
    some of them I mentioned down here of
  • 20:44 - 20:48
    which I will go into more detail later
    which is acknowledgement or ACK
  • 20:48 - 20:54
    synchronize or SYN and finished or FIN
    there is also reset and some urgent stuff
  • 20:54 - 21:00
    I will not go into detail of that then we
    have a six sixteen bit field which is the
  • 21:00 - 21:09
    window size which is the size of the
    receive buffer then we have again sixteen
  • 21:09 - 21:14
    bit field checksum and then we have some
    space for the urgent stuff I will not go
  • 21:14 - 21:22
    into detail. A TCP client if you program
    it in a Unix way. You have a very similar
  • 21:22 - 21:29
    API as we have seen in the UDP. So we
    first call. We first create a file
  • 21:29 - 21:36
    descriptor using the socket system call
    which we give again the adress family INET
  • 21:36 - 21:44
    and the SOCK_STREAM which is the since we
    are stream oriented. It's it's the name of
  • 21:44 - 21:55
    the TCP. It's the name for TCP socket.
    Then as a TCP client we connect using the
  • 21:55 - 22:01
    socket file descriptor to a remote host.
    And then once we are connected so connect
  • 22:01 - 22:10
    will only return once a TCP session has been
    established. Then we say here receive. So
  • 22:10 - 22:14
    we receive on the socket file descriptor.
    The specific buffer buffer then we print
  • 22:14 - 22:25
    it and then we close the socket file
    descriptor again. The TCP listener is very
  • 22:25 - 22:32
    similar. So well first we create a socket.
    Then we bind it and bind specifies the IP
  • 22:32 - 22:38
    address and also the port number. Then we
    use a function called listen on the socket
  • 22:38 - 22:48
    file descriptor and then we enter a loop.
    And so now we wait for client connections
  • 22:48 - 22:54
    which appear at some point. And for every
    client connection we well we call accept
  • 22:54 - 22:59
    and accept returns whenever there was a
    client which successfully established a
  • 22:59 - 23:09
    TCP connection. What accept returns is a
    new file descriptor so another file
  • 23:09 - 23:13
    descriptor not the same as a socket file
    descriptor. So the socket file descriptor
  • 23:13 - 23:20
    we call again except on it at a later
    point. Usually you then handle any work on
  • 23:20 - 23:26
    the client connection on this new_fd. You
    handle that in a separate process or set a
  • 23:26 - 23:31
    separate thread or a separate task in
    order to enable the server to accept
  • 23:31 - 23:39
    another connection while you are handling
    the the one client connection. Then we
  • 23:39 - 23:47
    just do some printf output and we send
    hello world to the client to the client
  • 23:47 - 23:53
    connection so to this new file descriptor
    then we close it and we start from the
  • 23:53 - 23:59
    while(1) and we accept a new client
    socket. So that is TCP listener as we have
  • 23:59 - 24:12
    seen it as you will see it in an in any
    network program. Now TCP as I mentioned it
  • 24:12 - 24:18
    has to do some work in order to establish
    a section a session and to tear down the
  • 24:18 - 24:24
    main work which needs to be done is to
    synchronize the initial sequence numbers
  • 24:24 - 24:30
    because we have seen in the header that we
    have this sequence number and somehow we
  • 24:30 - 24:36
    need to transform that information to the
    other side. So here's the TCP state machine
  • 24:36 - 24:41
    which is which has initially been part of
    the RFC, which is the specification
  • 24:41 - 24:48
    for TCP and also duplicated in books like
    Stevens design and implementation of the
  • 24:48 - 24:55
    of TCP IP and TCP IP illustrated and so
    on. So you can see it is it has here one
  • 24:55 - 25:00
    specific state which is listen and listen
    is as we've seen in the server
  • 25:00 - 25:05
    implementation if you call listen then you
    are in the listen stand in the listen
  • 25:05 - 25:12
    state and you always start well you always
    end up in the in the closed state after
  • 25:12 - 25:19
    you've called Close. Basically I will go
    into more detail of connection
  • 25:19 - 25:24
    establishment and teardown right now. So
    on the connection establishment we have
  • 25:24 - 25:32
    seen on the client side we start with the
    socket in the closed state. Then we say
  • 25:32 - 25:42
    the Unix call connect on that socket and
    that connect. Does send an initial TCP
  • 25:42 - 25:49
    segment to the server side which has the
    synchronized flag set to true or set to
  • 25:49 - 25:58
    one and the sequence number is some
    artificial number some random 32 bits
  • 25:58 - 26:08
    integer number. So just call it "a" here.
    The State of the file descriptor goes from
  • 26:08 - 26:16
    closed to SYN_SENT and SYN_SENT yeah well
    we just have sent out the the synchronize
  • 26:16 - 26:23
    segment so aTCP segment which doesn't carry
    any data but only the TCP header on the
  • 26:23 - 26:30
    server side. We had prepared previously.
    We started in a closed state then we
  • 26:30 - 26:37
    called Listen. Then we end up in a listen
    state. Now in the listen state we call
  • 26:37 - 26:43
    accept and accept blocks until the SYN is
    received and once the SYN is received, a
  • 26:43 - 26:49
    new socket is a new file descriptor
    spawned and that one ends up in the
  • 26:49 - 26:56
    SYN_RECIEVED state. The server sends out
    the TCP segment again without any data but
  • 26:56 - 27:00
    the SYN and acknowledgement flags are set
    and the sequence number is sent to some b
  • 27:00 - 27:06
    and the acknowledgement number is set to
    a+1. So the acknowledgement number
  • 27:06 - 27:14
    acknowledges that the SYN was received
    with the sequence number a +1. Upon
  • 27:14 - 27:19
    the client receiving that SYN and ACK, it is
    in the established state and it will send out
  • 27:19 - 27:27
    an acknowledgement segment so that the
    other side the server knows. Oh yeah. My
  • 27:27 - 27:32
    segment has been received and that one is
    sent with the sequence number of a+1
  • 27:32 - 27:41
    because a was already used here and the
    SYN flag consumes one one byte or 1 in the
  • 27:41 - 27:45
    sequence number range and the
    acknowledgement number is also set to
  • 27:45 - 27:51
    b + 1. So that is the sequence number
    from here plus 1. Once that is received
  • 27:51 - 27:58
    the server ends up in the established
    state. Sequence numbers. Yeah well it's a
  • 27:58 - 28:02
    good idea of both. Pick a random initial
    sequence number for each connection
  • 28:02 - 28:09
    otherwise we can get into some nasty
    attacks. The acknowledgement number is the
  • 28:09 - 28:15
    next sequence number from the other hosts
    and the sequence numbers always increased
  • 28:15 - 28:21
    for each byte of data. And for the SYN and
    FIN flags which only a single bits each
  • 28:21 - 28:26
    sequence number must be not acknowledged
    and each sent packet is retransmited unless
  • 28:26 - 28:33
    it is acknowledged after a certain timeout
    and after certain retransmit time after trying
  • 28:33 - 28:40
    it several times at some point the TCP
    stack gives up the trardown since I am a
  • 28:40 - 28:46
    bit short on time I will skip that. TCP
    provides us with the flow control. What
  • 28:46 - 28:52
    does that mean. Well every network stack
    has received so the Kernel has a receive
  • 28:52 - 28:57
    buffer for each TCP connection and that
    buffer is size limited to avoid Kernel
  • 28:57 - 29:03
    memory exhaustion which means that
    whenever the application so the web server
  • 29:03 - 29:11
    or the web browser is reading data some
    buffer spaces are reclaimed and when TCP
  • 29:11 - 29:18
    segments are arriving. Some of that buffer
    is consumed. It's a sliding window and we
  • 29:18 - 29:22
    have seen in the TCP header is is a
    windows size so there is a 16 bit field
  • 29:22 - 29:30
    called window size which specifies how
    many more bytes my TCP Stack has for
  • 29:30 - 29:42
    receiving data from the other side to
    avoid deadlocks there is also a timer in a
  • 29:42 - 29:47
    timer called the persist timer which is
    started when the window is when the window
  • 29:47 - 29:54
    size is zero and that then at a time out
    try retransmits TCP segment in order to
  • 29:54 - 30:00
    get information about the new window size
    from the other side. Congestion control
  • 30:00 - 30:08
    I will also skip a bit but the main idea is
    to control the rate of data entering the
  • 30:08 - 30:17
    network because if you're using multiple
    routers at some point you may saturate
  • 30:17 - 30:23
    some of the network links and that is
    avoided in TCP by doing by applying
  • 30:23 - 30:29
    congestion control which measures for
    example the time between segments sent and
  • 30:29 - 30:35
    acknowledgement received also has to do
    with a slow start and how your window size
  • 30:35 - 30:41
    your window buffer grows.
    Acknowledgments. Well there are some
  • 30:41 - 30:48
    strategys the basic one is every segment
    is acknowledged individually there's
  • 30:48 - 30:54
    delayed ACK where you collect multiple
    segments to acknowledge them at a certain
  • 30:54 - 30:59
    time then you have also selective
    acknowledgements where you can acknowledge
  • 30:59 - 31:08
    discontinuous segments which helps for
    lowering the amount of retransmissions. TCP
  • 31:08 - 31:14
    also carries some maximum segment size to
    avoid fragmentation. Actually on the IP
  • 31:14 - 31:19
    layer because to this partially open
    there's some struggle because you have
  • 31:19 - 31:26
    simultaneous open so what if both parties
    want to open a connection at the very same
  • 31:26 - 31:31
    time. Then you have a flag which is called
    the reset in order to terminate a
  • 31:31 - 31:37
    connection. There are some extensions like
    Window scaling and fast open to improve
  • 31:37 - 31:42
    the throughput and also to lower the
    delay. There are some attacks like denial
  • 31:42 - 31:48
    of service. So if your server
    implementation accepts something and
  • 31:48 - 31:53
    allocates a lot of memory for a client
    which doesn't do a lot but just sending a
  • 31:53 - 31:59
    SYN frame that is bad and leads to denial
    of service connection hijacking if you can
  • 31:59 - 32:06
    predict the sequence numbers then you can
    hijack and emit data into an established
  • 32:06 - 32:10
    connection. There have been some blind in-
    window attacks. What does that mean that
  • 32:10 - 32:17
    even without knowing the sequence number
    you can do something on an established TCP
  • 32:17 - 32:26
    connection such as, yeah sending a reset
    or sending a FIN frame and tearing that
  • 32:26 - 32:33
    connection down. The specification for TCP
    is written in English prose in a
  • 32:33 - 32:38
    collection of RFC and there are some
    widely deployed implementations. During
  • 32:38 - 32:46
    some research work in Cambridge over the
    last years me and various colleagues
  • 32:46 - 32:51
    implemented a formal model developed in
    the interactive theorem prover HOL4, which
  • 32:51 - 32:57
    has a precise specification with
    implementation looseness and we really use
  • 32:57 - 33:03
    that as an input so the sockets API and
    interface for getting the TCP control
  • 33:03 - 33:09
    block, which is the host internal state of
    the TCP and then the wire interface which
  • 33:09 - 33:17
    is data received and sent on that. And we
    use that formal model to validate itself,
  • 33:17 - 33:23
    so we used actual implementations to do
    that, we use it to draw some diagrams
  • 33:23 - 33:29
    where you can see the rules which fires on
    the left hand side, when something
  • 33:29 - 33:36
    happened like there was a CONNECT called
    and then the logical rule connect_1 was
  • 33:36 - 33:43
    used in the label transition system. Then
    we see here as well some TCP segments
  • 33:43 - 33:52
    which are going out and then what are the
    contributions of the network semantics, we
  • 33:52 - 34:00
    checked the model, we validated the model
    by recording traces and executing them. We
  • 34:00 - 34:03
    published a paper called Engineering with
    Logic: Rigorous Test-Oracle Specification
  • 34:03 - 34:09
    and Validation for TCP/IP and the unix
    Sockets API. The specification itself is
  • 34:09 - 34:16
    typeset in 384 pages, that's all the
    transitions you basically need. So roughly
  • 34:16 - 34:22
    10000 lines of HOL4 code and a lot of
    comments, where we embedded a lot of
  • 34:22 - 34:28
    LaTex code. And the Unix TCP/IP stack has
    usually around 15000 lines of code, the
  • 34:28 - 34:37
    TCP state machine we saw earlier, is here
    in this paragraph, in this diagram and we
  • 34:37 - 34:43
    try to draw a more correct TCP state
    machine which led us to this picture,
  • 34:43 - 34:49
    which is a bit more complicated. We have
    this state NONEXIST up here and we have
  • 34:49 - 34:55
    much more transitions due to timers and so
    on. So the state machine used in common
  • 34:55 - 35:03
    literature is actually not complete or not
    precise and we have a revision for that.
  • 35:03 - 35:10
    The conclusion is you have all TCP/IP
    widely deployed. I hope I managed to give
  • 35:10 - 35:16
    you some insight how TCP/IP actually
    works. It's a layered architecture which
  • 35:16 - 35:24
    is agnostic of underlying layers and in
    the network semantics working, we had an
  • 35:24 - 35:29
    executable specification. That's all I
    have to say and I welcome you to ask any
  • 35:29 - 35:33
    questions, either now or offline.
    Applause
  • 35:33 - 35:41
    Applause
  • 35:41 - 35:45
    Herald-Angel: Thank you. So, if you have
    any questions just go to the microphones.
  • 35:45 - 35:51
    We have two here and two on the right
    side. And do we have some question from
  • 35:51 - 36:05
    the Internet? No questions? No questions?
    Yeah, 1 question, come on, don't be shy.
  • 36:05 - 36:12
    Microphone 1: Right. Hi thanks, that was a
    very interesting talk. So your model, does
  • 36:12 - 36:17
    it allow synthesizing a implementation
    from the specification, or is it used
  • 36:17 - 36:22
    mostly for validating?
    HM: It's at the moment used for validation
  • 36:22 - 36:26
    because we have the specification
    looseness. So we have an implementation
  • 36:26 - 36:31
    looseness. So at some point in implementation
    you have to choose whether you take one
  • 36:31 - 36:36
    transition or the other one. So if you go
    into a failure state or if you go into a
  • 36:36 - 36:42
    success or if you transmit some piece of
    data and go into a success state. So we
  • 36:42 - 36:48
    don't have synthesized any implementation
    but there is ongoing work to use it as the
  • 36:48 - 36:50
    implementation, as a base for an
    implementation.
  • 36:50 - 36:56
    Mic: Okay. And do you think that such an
    implementation can be made, can it be made
  • 36:56 - 37:00
    efficient as well, once synthesized?
    HM: Yes.
  • 37:00 - 37:06
    Mic 1: Okay, thanks.
    Applause
  • 37:06 - 37:09
    Herald-Angel: Yeah, your question please.
  • 37:09 - 37:14
    Microphone 2: Yeah, thank you. How
    independent is TCP from IP? I mean, can
  • 37:14 - 37:22
    you integrate TCP over different protocols
    like Bluetooth or something like that?
  • 37:22 - 37:26
    HM: Sighs
    Since TCP requires for error messages, a
  • 37:26 - 37:33
    bit of ICMP, I haven't seen any TCP
    implementation on top of any other medium
  • 37:33 - 37:35
    than IP.
    Mic 2: Okay.
  • 37:35 - 37:42
    HM: So, I don't know, but I can think of
    it. Could work.
  • 37:42 - 37:48
    Herald-Angel: Okay, your question please.
    Microphone 3: Thank you. Hello. So you
  • 37:48 - 37:55
    used HOL4 for the specification part. Did
    you actually need the higher order logic
  • 37:55 - 37:59
    part of HOL, or would it be possible to
    just use predicate logics?
  • 37:59 - 38:10
    HM: Sighs
    I, I will have to reread. I think we need
  • 38:10 - 38:15
    actually some higher order logic for it,
    for the whole state and the transitions.
  • 38:15 - 38:20
    Mic 3: It would be interesting to meet
    and...
  • 38:20 - 38:24
    HM: Yes, well, the paper has been
    published at the journal of ACM and
  • 38:24 - 38:31
    luckily scihub.is is available and you can
    download it for free from there.
  • 38:31 - 38:34
    Laughs
    Mic 3: Okay, thanks.
  • 38:34 - 38:41
    Herald-Angel: Any more questions? No?
    Then, thank you Hannes. A warm applause
  • 38:41 - 38:50
    for Hannes please.
    Applause
  • 38:50 - 38:56
    postroll music
  • 38:56 - 39:13
    subtitles created by c3subtitles.de
    in the year 2018. Join, and help us!
Title:
35C3 - Transmission Control Protocol
Description:

more » « less
Video Language:
English
Duration:
39:13

English subtitles

Revisions