HACKING.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. $Id$
  2. Guide to Hacking Tcpreplay
  3. [Note: Pay attention to the last update date at the top of this file. If it
  4. was significantly long ago, this document may be out of date.]
  5. 0. Contributing Code
  6. If you contribute code the following will happen:
  7. a) You will be given credit in the CREDITS file
  8. b) Your code will be licensed under the same license as that of tcpreplay
  9. c) You will be assigning your copyright to me
  10. I do this for a simple reason: keep things simple for me.
  11. 1. Introduction
  12. If you're reading this to find out how to add a new feature or fix a bug in
  13. tcpreplay or tcpprep, then you've come to the right place. This isn't the
  14. place to find answers regarding how to use tcpreplay, the meaning of life,
  15. etc.
  16. 2. File Layout
  17. The file layout is pretty simple:
  18. / - Code, header files, autoconf stuff
  19. /Docs - Where to find documentation
  20. /test - Test scripts and stuff which is used during 'make test'
  21. /man - Unix man pages which get copied to $MANPATH
  22. 3. Adding support for additional DLTs (Data Link Types)
  23. There are a number of files/functions that need to be touched to add support
  24. for a new DLT to tcpreplay and tcpprep. Note that for a patch to be
  25. accepted, BOTH tcpreplay and tcpprep need to be updated to support the new
  26. DLT.
  27. 3a) dlt.h
  28. Two things need to be added here:
  29. - A structure defining the header
  30. - A #define for the length of the header
  31. example for DLT_CHDLC (Cisco HDLC):
  32. /* Cisco HDLC has a simple 32 bit header */
  33. #define CISCO_HDLC_LEN 4
  34. struct cisco_hdlc_header {
  35. u_int16_t address;
  36. u_int16_t protocol;
  37. }
  38. 3b) tcpreplay.c
  39. You will need to edit validate_l2() to process the DLT type as defined by
  40. pcap-bpf.h which is included with libpcap. The key here is that tcpreplay
  41. needs to be able to generate a valid 802.3 ethernet frame. Basically
  42. validate_l2() has to make sure that between the existing Layer 2 header (if
  43. any) and the user supplied arguments (-2, -I, -J, -K and -k) that enough
  44. information is available. Generally this means one of:
  45. - The DLT already has a valid header
  46. - User specified their own complete header via -2
  47. - The existing header + user specified MAC addresses are enough
  48. validate_l2() also calcuates the 'maxpacket' which is the maximum size of a
  49. packet that we can send out of the interface. Generally this is the length
  50. of the Layer 2 header + MTU. You shouldn't need to change anything here.
  51. 3c) edit_packet.c
  52. Next, you'll have to edit rewrite_l2() to add support for rewriting the
  53. Layer 2 header from your DLT to a standard 802.3 header. Note that
  54. do_packets.c will automatically fill out the source/destination MAC address
  55. if the appropriate flag is used (-I, -J, -K and -k) so there is no need to
  56. copy those values over here.
  57. 3d) tcpprep.c
  58. Look at process_raw_packets(). Should be painfully obvious what do do here.
  59. 3e) dlt_names.h
  60. Look in dlt_names.h and make sure your DLT type is listed here. Note that
  61. this file is generated by scripts/dlt2name.pl. If it's not listed here,
  62. your best bet is to edit scripts/dlt2name.pl and list it in the %known hash
  63. and then run:
  64. make dlt_names
  65. Note that editing dlt_names.h is NOT going to work, since it will get
  66. overwritten the next time it is regenerated.
  67. 4. Hacking tcprewrite
  68. tcprewrite order of execution:
  69. Figure out if input file's DLT is supported
  70. foreach (packet) {
  71. Update packet timestamp based on modifier
  72. Decide packet path via cache or CIDR lookup
  73. if (a Layer 2 header is specified) {
  74. if (existing Layer 2 header) {
  75. strip existing Layer 2 header
  76. }
  77. prepend specified Layer 2 header
  78. }
  79. if (primary path or single path) {
  80. re-write MAC addresses
  81. re-write IP addresses
  82. re-write Ports
  83. } else if (secondary path) {
  84. re-write MAC addresses
  85. re-write IP addresses
  86. re-write Ports
  87. }
  88. pad or truncate packet
  89. fix checksums
  90. write packet to outfile
  91. }