ip.stencil 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. pragma version 1;
  2. struct ipv4_header {
  3. cluster u8 {
  4. field version b4;
  5. field ihl u4; // 32-bit words
  6. };
  7. cluster u8 {
  8. field dscp b6;
  9. field ecn b2;
  10. };
  11. field total_length u16;
  12. field identification u16;
  13. cluster u16 {
  14. field flags b3;
  15. field fragment_offset u13;
  16. }
  17. field ttl u8;
  18. field protocol u8;
  19. field header_checksum u16;
  20. field source_addr u32;
  21. field dest_addr u32;
  22. assert length == 4 * self.ihl;
  23. }
  24. struct udp_header {
  25. field source_port u16;
  26. field dest_port u16;
  27. field length u16;
  28. field checksum u16;
  29. }
  30. struct tcp_header {
  31. field source_port u16;
  32. field dest_port u16;
  33. field sequence_no u32;
  34. field ack_no u32;
  35. cluster u8 {
  36. field data_offset u4; // 32-bit words
  37. reserved b4;
  38. }
  39. field flags tcp_flags;
  40. field window_size u16;
  41. field checksum u16;
  42. field urgent_pointer u16;
  43. assert urgent_pointer == 0 || self.flags.urg; // is this actually checked?
  44. assert length == 4 * self.data_offset
  45. }
  46. flagmap tcp_flags u8 {
  47. cwr = 0;
  48. ece = 1;
  49. urg = 2;
  50. ack = 3;
  51. psh = 4;
  52. rst = 5;
  53. syn = 6;
  54. fin = 7;
  55. }
  56. struct ipv6_header {
  57. cluster u32 {
  58. field version u4;
  59. field traffic_class u8;
  60. field flow_label u20;
  61. }
  62. field payload_length u16;
  63. field next_header u8;
  64. field hop_limit u8;
  65. field source_address buf16;
  66. field dest_address buf16;
  67. }