package tcpip

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file ipv6_wire.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

[%%cstruct
type ipv6 = {
    version_flow: uint32_t;
    len:          uint16_t;  (* payload length (includes extensions) *)
    nhdr:         uint8_t; (* next header *)
    hlim:         uint8_t; (* hop limit *)
    src:          uint8_t [@len 16];
    dst:          uint8_t [@len 16];
  } [@@big_endian]
]

let int_to_protocol = function
  | 58  -> Some `ICMP
  | 6  -> Some `TCP
  | 17 -> Some `UDP
  | _  -> None

let protocol_to_int = function
  | `ICMP   -> 58
  | `TCP    -> 6
  | `UDP    -> 17

[%%cstruct
type icmpv6 = {
    ty:       uint8_t;
    code:     uint8_t;
    csum:     uint16_t;
    reserved: uint32_t;
  } [@@big_endian]
]

[%%cstruct
type pingv6 = {
    ty:   uint8_t;
    code: uint8_t;
    csum: uint16_t;
    id:   uint16_t;
    seq:  uint16_t;
  } [@@big_endian]
]
[%%cstruct
type ns = {
    ty:       uint8_t;
    code:     uint8_t;
    csum:     uint16_t;
    reserved: uint32_t;
    target:   uint8_t  [@len 16];
  } [@@big_endian]
]
[%%cstruct
type na = {
    ty: uint8_t;
    code: uint8_t;
    csum: uint16_t;
    reserved: uint32_t;
    target: uint8_t [@len 16];
  } [@@big_endian]
]
let get_na_router buf =
  (Cstruct.get_uint8 buf 4 land 0x80) <> 0

let get_na_solicited buf =
  (Cstruct.get_uint8 buf 4 land 0x40) <> 0

let get_na_override buf =
  (Cstruct.get_uint8 buf 4 land 0x20) <> 0

[%%cstruct
type rs = {
    ty:       uint8_t;
    code:     uint8_t;
    csum:     uint16_t;
    reserved: uint32_t;
  } [@@big_endian]
]
[%%cstruct
type opt_prefix = {
    ty:                 uint8_t;
    len:                uint8_t;
    prefix_len:         uint8_t;
    reserved1:          uint8_t;
    valid_lifetime:     uint32_t;
    preferred_lifetime: uint32_t;
    reserved2:          uint32_t;
    prefix:             uint8_t [@len 16];
  } [@@big_endian]
]
let get_opt_prefix_on_link buf =
  get_opt_prefix_reserved1 buf land 0x80 <> 0

let get_opt_prefix_autonomous buf =
  get_opt_prefix_reserved1 buf land 0x40 <> 0

[%%cstruct
type opt = {
    ty:  uint8_t;
    len: uint8_t;
  } [@@big_endian]
]
[%%cstruct
type llopt = {
    ty:   uint8_t;
    len:  uint8_t;
    addr: uint8_t [@len 6];
  } [@@big_endian]
]

[%%cstruct
type ra = {
    ty:              uint8_t;
    code:            uint8_t;
    csum:            uint16_t;
    cur_hop_limit:   uint8_t;
    reserved:        uint8_t;
    router_lifetime: uint16_t;
    reachable_time:  uint32_t;
    retrans_timer:   uint32_t;
  } [@@big_endian]
]
let sizeof_ipv6_pseudo_header = 16 + 16 + 4 + 4
OCaml

Innovation. Community. Security.