github.com/borderzero/water@v0.0.1/waterutil/doc.go (about)

     1  /*
     2  Package waterutil provides utility functions for interpreting TUN/TAP MAC farme headers and IP packet headers. It defines some constants such as protocol numbers and ethernet frame types. Use waterutil along with package water to work with TUN/TAP interface data.
     3  
     4  Frames/packets are interpreted in following format (as in TUN/TAP devices):
     5  
     6  TAP - MAC Frame:
     7     No Tagging
     8    +-----------------------------------------------------------------------------
     9    | Octet |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|...
    10    +-----------------------------------------------------------------------------
    11    | Field | MAC Destination |   MAC  Source   |EType| Payload
    12    +-----------------------------------------------------------------------------
    13  
    14     Single-Tagged -- Octets [12,13] == {0x81, 0x00}
    15    +-----------------------------------------------------------------------------
    16    | Octet |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|...
    17    +-----------------------------------------------------------------------------
    18    | Field | MAC Destination |   MAC  Source   |    Tag    | Payload
    19    +-----------------------------------------------------------------------------
    20  
    21     Double-Tagged -- Octets [12,13] == {0x88, 0xA8}
    22    +-----------------------------------------------------------------------------
    23    | Octet |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|...
    24    +-----------------------------------------------------------------------------
    25    | Field | MAC Destination |   MAC  Source   | Outer Tag | Inner Tag | Payload
    26    +-----------------------------------------------------------------------------
    27  
    28  TUN - IPv4 Packet:
    29    +---------------------------------------------------------------------------------------------------------------+
    30    |       | Octet |           0           |           1           |           2           |           3           |
    31    | Octet |  Bit  |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|
    32    +---------------------------------------------------------------------------------------------------------------+
    33    |   0   |   0   |  Version  |    IHL    |      DSCP       | ECN |                 Total  Length                 |
    34    +---------------------------------------------------------------------------------------------------------------+
    35    |   4   |  32   |                Identification                 | Flags  |           Fragment Offset            |
    36    +---------------------------------------------------------------------------------------------------------------+
    37    |   8   |  64   |     Time To Live      |       Protocol        |                Header Checksum                |
    38    +---------------------------------------------------------------------------------------------------------------+
    39    |  12   |  96   |                                       Source IP Address                                       |
    40    +---------------------------------------------------------------------------------------------------------------+
    41    |  16   |  128  |                                    Destination IP Address                                     |
    42    +---------------------------------------------------------------------------------------------------------------+
    43    |  20   |  160  |                                     Options (if IHL > 5)                                      |
    44    +---------------------------------------------------------------------------------------------------------------+
    45    |  24   |  192  |                                                                                               |
    46    |  30   |  224  |                                            Payload                                            |
    47    |  ...  |  ...  |                                                                                               |
    48    +---------------------------------------------------------------------------------------------------------------+
    49  
    50  */
    51  package waterutil