pkt_captures6.cc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. // Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <dhcp/pkt6.h>
  16. #include <util/encode/hex.h>
  17. #include <dhcp/tests/pkt_captures.h>
  18. #include <string>
  19. /// @file pkt_captures6.cc
  20. ///
  21. /// @brief contains packet captures imported from Wireshark
  22. ///
  23. /// These are actual packets captured over wire. They are used in various
  24. /// tests.
  25. ///
  26. /// The procedure to export Wireshark -> unit-tests is manual, but rather
  27. /// easy to follow:
  28. /// 1. Open a file in wireshark
  29. /// 2. Find the packet you want to export
  30. /// 3. There's a protocol stack (Frame, Ethernet, IPv6, UDP, DHCPv6, ...)
  31. /// 4. Right click on DHCPv6 -> Copy -> Bytes -> Hex Stream
  32. /// 5. Paste it as: string hex_string="[paste here]";
  33. /// 6. Coding guidelines line restrictions apply, so wrap your code as necessary
  34. /// 7. Make sure you decribe the capture appropriately
  35. /// 8. Follow whatever rest of the methods are doing (set ports, ifaces etc.)
  36. /// 9. To easily copy packet description, click File... -> Extract packet
  37. /// dissections -> as plain text file...
  38. /// (Make sure that the packet is expanded in the view. The text file will
  39. /// contain whatever expansion level you have in the graphical tree.)
  40. using namespace isc::dhcp;
  41. using namespace isc::asiolink;
  42. using namespace std;
  43. namespace isc {
  44. namespace test {
  45. void PktCaptures::captureSetDefaultFields(const Pkt6Ptr& pkt) {
  46. pkt->setRemotePort(546);
  47. pkt->setRemoteAddr(IOAddress("fe80::1"));
  48. pkt->setLocalPort(0);
  49. pkt->setLocalAddr(IOAddress("ff02::1:2"));
  50. pkt->setIndex(2);
  51. pkt->setIface("eth0");
  52. }
  53. // This function returns buffer for very simple Solicit
  54. Pkt6Ptr PktCaptures::captureSimpleSolicit() {
  55. uint8_t data[] = {
  56. 1, // type 1 = SOLICIT
  57. 0xca, 0xfe, 0x01, // trans-id = 0xcafe01
  58. 0, 1, // option type 1 (client-id)
  59. 0, 10, // option lenth 10
  60. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // DUID
  61. 0, 3, // option type 3 (IA_NA)
  62. 0, 12, // option length 12
  63. 0, 0, 0, 1, // iaid = 1
  64. 0, 0, 0, 0, // T1 = 0
  65. 0, 0, 0, 0 // T2 = 0
  66. };
  67. Pkt6Ptr pkt(new Pkt6(data, sizeof(data)));
  68. captureSetDefaultFields(pkt);
  69. return (pkt);
  70. }
  71. Pkt6Ptr PktCaptures::captureRelayedSolicit() {
  72. // This is a very simple relayed SOLICIT message:
  73. // RELAY-FORW
  74. // - interface-id
  75. // - relay-message
  76. // - SOLICIT
  77. // - client-id
  78. // - IA_NA (iaid=1, t1=0, t2=0)
  79. // - ORO (7)
  80. // string exported from Wireshark
  81. string hex_string =
  82. "0c0500000000000000000000000000000000fc00000000000000000000000000000900"
  83. "12000231350009002c010517100001000e0001000151b5e46208002758f1e80003000c"
  84. "000000010000000000000000000600020007";
  85. std::vector<uint8_t> bin;
  86. // Decode the hex string and store it in bin (which happens
  87. // to be OptionBuffer format)
  88. isc::util::encode::decodeHex(hex_string, bin);
  89. Pkt6Ptr pkt(new Pkt6(&bin[0], bin.size()));
  90. captureSetDefaultFields(pkt);
  91. return (pkt);
  92. }
  93. /// returns a buffer with relayed SOLICIT (from DOCSIS3.0 cable modem)
  94. Pkt6Ptr isc::test::PktCaptures::captureDocsisRelayedSolicit() {
  95. // This is an actual DOCSIS packet
  96. // RELAY-FORW (12)
  97. // - Relay Message
  98. // - SOLICIT (1)
  99. // - client-id
  100. // - IA_NA (iaid=7f000788, t2=0, t2=0)
  101. // - IAAddress (::, pref=0,valid=0)
  102. // - rapid-commit
  103. // - elapsed
  104. // - ORO
  105. // - Reconfigure-accept
  106. // - Vendor-Class ("docsis3.0")
  107. // - Vendor-specific Info
  108. // - subopt 1: Option request = 32,33,34,37,38
  109. // - subopt 36: Device identifier
  110. // - subopt 35: TLV5
  111. // - subopt 2: Device type = ECM
  112. // - subopt 3: Embedded components
  113. // - subopt 4: Serial Number
  114. // - subopt 5: Hardware version
  115. // - subopt 6: Software version
  116. // - subopt 7: Boot ROM Version
  117. // - subopt 8: Organization Unique Identifier
  118. // - subopt 9: Model Number
  119. // - subopt 10: Vendor Name (Netgear)
  120. // - subopt 15: unknown
  121. // - Interface-Id
  122. // - Vendor-specific Information
  123. // - Suboption 1025: CMTS capabilities
  124. // - Suboption 1026: Cable Modem MAC addr = 10:0d:7f:00:07:88
  125. // string exported from Wireshark
  126. string hex_string =
  127. "0c002a0288fe00fe00015a8d09fffe7af955fe80000000000000120d7ffffe00078800"
  128. "090189010d397f0001000a00030001100d7f000788000300287f000788000000000000"
  129. "000000050018000000000000000000000000000000000000000000000000000e000000"
  130. "0800020000000600020011001400000010000f0000118b0009646f63736973332e3000"
  131. "1101200000118b0001000a0020002100220025002600240006100d7f00078800230081"
  132. "0101010201030301010401010501010601010701180801080901000a01010b01180c01"
  133. "010d0200400e0200100f01011004000000021101011301011401001501381601011701"
  134. "011801041901041a01041b01281c01021d01081e01201f011020011821010222010123"
  135. "010124011825010126020040270101120701100d7f00078a0002000345434d0003000b"
  136. "45434d3a45524f555445520004000d3335463132395550303030353200050004332e31"
  137. "310006000956312e30312e31315400070013505350552d426f6f7420312e302e31362e"
  138. "323200080006303030393542000900084347343030305444000a00074e657467656172"
  139. "000f000745524f5554455200120012427531264361312f3000100d7f00078800000011"
  140. "00160000118b040100040102030004020006100d7f000788";
  141. std::vector<uint8_t> bin;
  142. // Decode the hex string and store it in bin (which happens
  143. // to be OptionBuffer format)
  144. isc::util::encode::decodeHex(hex_string, bin);
  145. Pkt6Ptr pkt(new Pkt6(&bin[0], bin.size()));
  146. captureSetDefaultFields(pkt);
  147. return (pkt);
  148. }
  149. /// returns a buffer with relayed SOLICIT (from DOCSIS3.0 eRouter)
  150. Pkt6Ptr isc::test::PktCaptures::captureeRouterRelayedSolicit() {
  151. /* Packet description exported from wireshark:
  152. DHCPv6
  153. Message type: Relay-forw (12)
  154. Hopcount: 0
  155. Link address: 2001:558:ffa8::1 (2001:558:ffa8::1)
  156. Peer address: fe80::22e5:2aff:feb8:1515 (fe80::22e5:2aff:feb8:1515)
  157. Relay Message
  158. Option: Relay Message (9)
  159. Length: 241
  160. Value: 01a90044000e000000140000000600080011001700180019...
  161. DHCPv6
  162. Message type: Solicit (1)
  163. Transaction ID: 0xa90044
  164. Rapid Commit
  165. Option: Rapid Commit (14)
  166. Length: 0
  167. Reconfigure Accept
  168. Option: Reconfigure Accept (20)
  169. Length: 0
  170. Option Request
  171. Option: Option Request (6)
  172. Length: 8
  173. Value: 0011001700180019
  174. Requested Option code: Vendor-specific Information (17)
  175. Requested Option code: DNS recursive name server (23)
  176. Requested Option code: Domain Search List (24)
  177. Requested Option code: Identity Association for Prefix Delegation (25)
  178. Vendor Class
  179. Option: Vendor Class (16)
  180. Length: 16
  181. Value: 0000118b000a65526f75746572312e30
  182. Enterprise ID: Cable Television Laboratories, Inc. (4491)
  183. vendor-class-data: eRouter1.0
  184. Vendor-specific Information
  185. Option: Vendor-specific Information (17)
  186. Length: 112
  187. Value: 0000118b0002000745524f555445520003000b45434d3a45...
  188. Enterprise ID: Cable Television Laboratories, Inc. (4491)
  189. Suboption: Device Type = (2)"EROUTER"
  190. Suboption: Embedded Components = (3)"ECM:EROUTER"
  191. Suboption: Serial Number = (4)"2BR229U40044C"
  192. Suboption: Hardware Version = (5)"1.04"
  193. Suboption: Software Version = (6)"V1.33.03"
  194. Suboption: Boot ROM Version = (7)"2.3.0R2"
  195. Suboption: Organization Unique Identifier = (8)"00095B"
  196. Suboption: Model Number = (9)"CG3000DCR"
  197. Suboption: Vendor Name = (10)"Netgear"
  198. Client Identifier
  199. Option: Client Identifier (1)
  200. Length: 10
  201. Value: 0003000120e52ab81515
  202. DUID: 0003000120e52ab81515
  203. DUID Type: link-layer address (3)
  204. Hardware type: Ethernet (1)
  205. Link-layer address: 20:e5:2a:b8:15:15
  206. Identity Association for Prefix Delegation
  207. Option: Identity Association for Prefix Delegation (25)
  208. Length: 41
  209. Value: 2ab815150000000000000000001a00190000000000000000...
  210. IAID: 2ab81515
  211. T1: 0
  212. T2: 0
  213. IA Prefix
  214. Option: IA Prefix (26)
  215. Length: 25
  216. Value: 000000000000000038000000000000000000000000000000...
  217. Preferred lifetime: 0
  218. Valid lifetime: 0
  219. Prefix length: 56
  220. Prefix address: :: (::)
  221. Identity Association for Non-temporary Address
  222. Option: Identity Association for Non-temporary Address (3)
  223. Length: 12
  224. Value: 2ab815150000000000000000
  225. IAID: 2ab81515
  226. T1: 0
  227. T2: 0
  228. Elapsed time
  229. Option: Elapsed time (8)
  230. Length: 2
  231. Value: 0000
  232. Elapsed time: 0 ms
  233. Vendor-specific Information
  234. Option: Vendor-specific Information (17)
  235. Length: 22
  236. Value: 0000118b0402000620e52ab815140401000401020300
  237. Enterprise ID: Cable Television Laboratories, Inc. (4491)
  238. Suboption: CM MAC Address Option = (1026)20:e5:2a:b8:15:14
  239. Suboption: CMTS Capabilities Option : (1025)
  240. Interface-Id
  241. Option: Interface-Id (18)
  242. Length: 4
  243. Value: 00000022
  244. Interface-ID:
  245. Remote Identifier
  246. Option: Remote Identifier (37)
  247. Length: 14
  248. Value: 0000101300015c228d4110000122
  249. Enterprise ID: Arris Interactive LLC (4115)
  250. Remote-ID: 00015c228d4110000122
  251. DHCP option 53
  252. Option: Unknown (53)
  253. Length: 10
  254. Value: 0003000100015c228d3d
  255. DUID: 0003000100015c228d3d
  256. DUID Type: link-layer address (3)
  257. Hardware type: Ethernet (1)
  258. Link-layer address: 00:01:5c:22:8d:3d */
  259. // string exported from Wireshark
  260. string hex_string =
  261. "0c0020010558ffa800000000000000000001fe8000000000000022e52afffeb8151500"
  262. "0900f101a90044000e000000140000000600080011001700180019001000100000118b"
  263. "000a65526f75746572312e30001100700000118b0002000745524f555445520003000b"
  264. "45434d3a45524f555445520004000d3242523232395534303034344300050004312e30"
  265. "340006000856312e33332e303300070007322e332e3052320008000630303039354200"
  266. "090009434733303030444352000a00074e6574676561720001000a0003000120e52ab8"
  267. "1515001900292ab815150000000000000000001a001900000000000000003800000000"
  268. "0000000000000000000000000003000c2ab81515000000000000000000080002000000"
  269. "1100160000118b0402000620e52ab81514040100040102030000120004000000220025"
  270. "000e0000101300015c228d41100001220035000a0003000100015c228d3d";
  271. std::vector<uint8_t> bin;
  272. // Decode the hex string and store it in bin (which happens
  273. // to be OptionBuffer format)
  274. isc::util::encode::decodeHex(hex_string, bin);
  275. Pkt6Ptr pkt(new Pkt6(&bin[0], bin.size()));
  276. captureSetDefaultFields(pkt);
  277. return (pkt);
  278. }
  279. Pkt6Ptr isc::test::PktCaptures::captureCableLabsShortVendorClass() {
  280. // This is a simple non-relayed Solicit:
  281. // - client-identifier
  282. // - IA_NA
  283. // - Vendor Class (4 bytes)
  284. // - enterprise-id 4491
  285. // - Vendor-specific Information
  286. // - enterprise-id 4491
  287. std::string hex_string =
  288. "01671cb90001000e0001000152ea903a08002758f1e80003000c00004bd10000000000"
  289. "000000001000040000118b0011000a0000118b000100020020";
  290. std::vector<uint8_t> bin;
  291. // Decode the hex string and store it in bin (which happens
  292. // to be OptionBuffer format)
  293. isc::util::encode::decodeHex(hex_string, bin);
  294. Pkt6Ptr pkt(new Pkt6(&bin[0], bin.size()));
  295. captureSetDefaultFields(pkt);
  296. return (pkt);
  297. }
  298. /// @brief creates doubly relayed solicit message
  299. ///
  300. /// This is a traffic capture exported from wireshark and manually modified
  301. /// to include necessary options (RSOO). It includes a SOLICIT message
  302. /// that passed through two relays. It is especially interesting,
  303. /// because of the following properties:
  304. /// - double encapsulation
  305. /// - first relay inserts relay-msg before extra options
  306. /// - second relay inserts relay-msg after extra options
  307. /// - both relays are from different vendors
  308. /// - interface-id are different for each relay
  309. /// - first relay inserts valid remote-id
  310. /// - second relay inserts remote-id with empty vendor data
  311. /// - the solicit message requests for custom options in ORO
  312. /// - there are option types in RELAY-FORW that do not appear in SOLICIT
  313. /// - there are option types in SOLICT that do not appear in RELAY-FORW
  314. ///
  315. /// RELAY-FORW
  316. /// - relay message option
  317. /// - RELAY-FORW
  318. /// - rsoo (66)
  319. /// - option 255 (len 4)
  320. /// - option 256 (len 9)
  321. /// - remote-id option (37)
  322. /// - relay message option
  323. /// - SOLICIT
  324. /// - client-id option
  325. /// - ia_na option
  326. /// - elapsed time
  327. /// - ORO
  328. /// - interface-id option (18)
  329. /// - remote-id option (37)
  330. ///
  331. /// The original capture was posted to dibbler users mailing list.
  332. ///
  333. /// @return created double relayed SOLICIT message
  334. isc::dhcp::Pkt6Ptr isc::test::PktCaptures::captureRelayed2xRSOO() {
  335. // string exported from Wireshark
  336. string hex_string =
  337. "0c01200108880db800010000000000000000fe80000000000000020021fffe5c18a9"
  338. "0009007d0c0000000000000000000000000000000000fe80000000000000020021fffe5c18a9"
  339. "00420015" // RSOO (includes ...
  340. "00ff000401020304" // ... option 255, len 4, content 0x01020304
  341. "01000009010203040506070809" // ... option 256, len 9, content 0x010203040506070809
  342. "0025000400000de9" // remote-id
  343. "00090036" // relay-msg, len 54
  344. "016b4fe2" // solicit"
  345. "0001000e0001000118b033410000215c18a9" // client-id
  346. "0003000c00000001ffffffffffffffff" // ia-na
  347. "000800020000"
  348. "00060006001700f200f3"
  349. "0012001c4953414d3134347c3239397c697076367c6e743a76703a313a" // vendor-class
  350. "313130002500120000197f0001000118b033410000215c18a9";
  351. std::vector<uint8_t> bin;
  352. // Decode the hex string and store it in bin (which happens
  353. // to be OptionBuffer format)
  354. isc::util::encode::decodeHex(hex_string, bin);
  355. Pkt6Ptr pkt(new Pkt6(&bin[0], bin.size()));
  356. pkt->setRemotePort(547);
  357. pkt->setRemoteAddr(IOAddress("fe80::1234"));
  358. pkt->setLocalPort(547);
  359. pkt->setLocalAddr(IOAddress("ff05::1:3"));
  360. pkt->setIndex(2);
  361. pkt->setIface("eth0");
  362. return (pkt);
  363. }
  364. }; // end of isc::test namespace
  365. }; // end of isc namespace