mt_racket 1.0.12a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/README +76 -0
  3. data/examples/arp-send +24 -0
  4. data/examples/arp-send2 +30 -0
  5. data/examples/cdp +39 -0
  6. data/examples/cdp-spew +52 -0
  7. data/examples/dhcp +42 -0
  8. data/examples/dhcp-spew +48 -0
  9. data/examples/dns +38 -0
  10. data/examples/egp +30 -0
  11. data/examples/hsrp +43 -0
  12. data/examples/hsrp_takeover +69 -0
  13. data/examples/icmp-recv +34 -0
  14. data/examples/icmp-spew +50 -0
  15. data/examples/icmpv6 +84 -0
  16. data/examples/icmpv6-spew +50 -0
  17. data/examples/igmpv1 +27 -0
  18. data/examples/igmpv2 +27 -0
  19. data/examples/igrp-send +25 -0
  20. data/examples/ipv6 +35 -0
  21. data/examples/nat-pimp +32 -0
  22. data/examples/ntp +38 -0
  23. data/examples/ntp2 +42 -0
  24. data/examples/sctp +32 -0
  25. data/examples/stp-send +21 -0
  26. data/examples/synflood +147 -0
  27. data/examples/tcp +43 -0
  28. data/examples/tcp2udp +65 -0
  29. data/examples/udp +46 -0
  30. data/examples/vrrp +34 -0
  31. data/examples/vtp +28 -0
  32. data/lib/racket/l2/eightotwodotthree.rb +48 -0
  33. data/lib/racket/l2/ethernet.rb +62 -0
  34. data/lib/racket/l2/llc.rb +50 -0
  35. data/lib/racket/l2/misc.rb +67 -0
  36. data/lib/racket/l2/snap.rb +40 -0
  37. data/lib/racket/l2/vlan.rb +61 -0
  38. data/lib/racket/l2/vtp.rb +124 -0
  39. data/lib/racket/l2.rb +30 -0
  40. data/lib/racket/l3/arp.rb +63 -0
  41. data/lib/racket/l3/cdp.rb +85 -0
  42. data/lib/racket/l3/egp.rb +53 -0
  43. data/lib/racket/l3/ipv4.rb +132 -0
  44. data/lib/racket/l3/ipv6.rb +66 -0
  45. data/lib/racket/l3/misc.rb +159 -0
  46. data/lib/racket/l3/stp.rb +81 -0
  47. data/lib/racket/l3.rb +30 -0
  48. data/lib/racket/l4/gre.rb +65 -0
  49. data/lib/racket/l4/icmp.rb +295 -0
  50. data/lib/racket/l4/icmpv6.rb +446 -0
  51. data/lib/racket/l4/igmpv1.rb +79 -0
  52. data/lib/racket/l4/igmpv2.rb +76 -0
  53. data/lib/racket/l4/igrp.rb +138 -0
  54. data/lib/racket/l4/misc.rb +35 -0
  55. data/lib/racket/l4/sctp.rb +163 -0
  56. data/lib/racket/l4/tcp.rb +152 -0
  57. data/lib/racket/l4/udp.rb +81 -0
  58. data/lib/racket/l4/vrrp.rb +95 -0
  59. data/lib/racket/l4.rb +30 -0
  60. data/lib/racket/l5/bootp.rb +106 -0
  61. data/lib/racket/l5/dns.rb +110 -0
  62. data/lib/racket/l5/hsrp.rb +73 -0
  63. data/lib/racket/l5/misc.rb +35 -0
  64. data/lib/racket/l5/nat-pmp.rb +41 -0
  65. data/lib/racket/l5/ntp.rb +59 -0
  66. data/lib/racket/l5.rb +30 -0
  67. data/lib/racket/misc/lv.rb +108 -0
  68. data/lib/racket/misc/misc.rb +62 -0
  69. data/lib/racket/misc/orderedhash.rb +63 -0
  70. data/lib/racket/misc/raw.rb +35 -0
  71. data/lib/racket/misc/tlv.rb +103 -0
  72. data/lib/racket/misc/vt.rb +114 -0
  73. data/lib/racket/misc.rb +30 -0
  74. data/lib/racket/racket.rb +166 -0
  75. data/lib/racket/racketpart.rb +66 -0
  76. data/lib/racket.rb +4 -0
  77. data/test/l2/ts_ethernet.rb +22 -0
  78. data/test/l2/ts_misc.rb +23 -0
  79. data/test/l2/ts_vlan.rb +15 -0
  80. data/test/l3/ts_ipv4.rb +44 -0
  81. data/test/l3/ts_ipv6.rb +26 -0
  82. data/test/l3/ts_misc.rb +31 -0
  83. data/test/l4/ts_icmp.rb +38 -0
  84. data/test/l4/ts_tcp.rb +55 -0
  85. data/test/l4/ts_udp.rb +40 -0
  86. data/test/misc/ts_lv.rb +59 -0
  87. data/test/misc/ts_orderedhash.rb +33 -0
  88. data/test/misc/ts_tlv.rb +47 -0
  89. data/test/misc/ts_vt.rb +56 -0
  90. data/test/ts_all.rb +14 -0
  91. metadata +153 -0
@@ -0,0 +1,48 @@
1
+ # $Id: eightotwodotthree.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L2
30
+ # 802.3 Ethernet. Should always be followed by an LLC header
31
+ class EightOTwoDotThree < RacketPart
32
+ # Destination MAC address
33
+ hex_octets :dst_mac, 48
34
+ # Source MAC address
35
+ hex_octets :src_mac, 48
36
+ # Length of the payload
37
+ unsigned :payload_length, 16
38
+ # Payload
39
+ rest :payload
40
+
41
+ # Fix this layer up prior to sending. For 802.3, just adjusts +length+
42
+ def fix!
43
+ self.payload_length = self.payload.length
44
+ end
45
+ end
46
+ end
47
+ end
48
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,62 @@
1
+ # $Id: ethernet.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L2
30
+ # Ethernet II (DIX v2.0)
31
+ #
32
+ # http://en.wikipedia.org/wiki/Ethernet_II_framing
33
+ class Ethernet < RacketPart
34
+ ETHERTYPE_IPV4 = 0x0800
35
+ ETHERTYPE_ARP = 0x0806
36
+ ETHERTYPE_RARP = 0x8035
37
+ ETHERTYPE_APPLETALK = 0x809b
38
+ ETHERTYPE_AARP = 0x80f3
39
+ ETHERTYPE_8021Q = 0x8100
40
+ ETHERTYPE_IPX = 0x8137
41
+ ETHERTYPE_NOVELL = 0x8138
42
+ ETHERTYPE_IPV6 = 0x86DD
43
+ ETHERTYPE_MPLS_UNICAST = 0x8847
44
+ ETHERTYPE_MPLS_MULTICAST = 0x8848
45
+ ETHERTYPE_PPPOE_DISCOVERY = 0x8863
46
+ ETHERTYPE_PPPOE_SESSION = 0x8864
47
+ ETHERTYPE_8021X = 0x888E
48
+ ETHERTYPE_ATAOE = 0x88A2
49
+ ETHERTYPE_8021AE = 0x88E5
50
+
51
+ # Destination MAC address
52
+ hex_octets :dst_mac, 48
53
+ # Source MAC address
54
+ hex_octets :src_mac, 48
55
+ # Protocol of payload send with this ethernet datagram. Defaults to IPV4
56
+ unsigned :ethertype, 16, { :default => ETHERTYPE_IPV4 }
57
+ # Payload
58
+ rest :payload
59
+ end
60
+ end
61
+ end
62
+ #set ts=2 et sw=2: vim
@@ -0,0 +1,50 @@
1
+ # $Id: llc.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L2
30
+ # Logical Link Control (http://en.wikipedia.org/wiki/Logical_Link_Control)
31
+ class LLC < RacketPart
32
+ LLC_IBM_SNA = 0x04
33
+ LLC_IP = 0x06
34
+ LLC_3COM = 0x80
35
+ LLC_SNAP = 0xAA
36
+ LLC_BANYAN = 0xBC
37
+ LLC_NOVELL = 0xE0
38
+ LLC_LANMAN = 0xF4
39
+ # Destination Service Access Point address
40
+ unsigned :dsap, 8, { :default => 0xaa }
41
+ # Source Service Access Point address
42
+ unsigned :ssap, 8, { :default => 0xaa }
43
+ # Control field
44
+ unsigned :control, 8
45
+ # Payload
46
+ rest :payload
47
+ end
48
+ end
49
+ end
50
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,67 @@
1
+ # $Id$
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L2
30
+ # Miscelaneous L2 helper methods
31
+ module Misc
32
+
33
+ # given a string representing a MAC address, return the
34
+ # human readable form
35
+ def Misc.string2mac(string)
36
+ string.unpack("C*").map { |i| i.to_s(16).ljust(2,"0") }.join(":")
37
+ end
38
+
39
+ # given a MAC address, return the string representation
40
+ def Misc.mac2string(mac)
41
+ mac.split(":").map { |i| i.hex.chr }.join
42
+ end
43
+
44
+ # given a MAC address, return the long representation
45
+ def Misc.mac2long(addr)
46
+ long = 0
47
+ addr.split(':').map { |s| s.to_i(16) }.each do |o|
48
+ long = (long << 8) ^ o
49
+ end
50
+ long
51
+ end
52
+
53
+ # given a long representing a MAC address
54
+ # print it out in human readable form of a given length,
55
+ # defaulting to 6 (ethernet)
56
+ def Misc.long2mac(long, len=6)
57
+ long.to_s(16).rjust(len*2, '0').unpack("a2"*len).join(":")
58
+ end
59
+
60
+ # Return a random MAC, defaults to 6 bytes (ethernet)
61
+ def Misc.randommac(len=6)
62
+ long2mac(rand(2**(8*len)), len)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,40 @@
1
+ # $Id: snap.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L2
30
+ # Subnetwork Access Protocl (http://en.wikipedia.org/wiki/Subnetwork_Access_Protocol)
31
+ class SNAP < RacketPart
32
+ # Organizational code
33
+ unsigned :org, 24, { :default => 0x00000c }
34
+ # Protocol ID
35
+ unsigned :pid, 16
36
+ rest :payload
37
+ end
38
+ end
39
+ end
40
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,61 @@
1
+ # $Id: vlan.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L2
30
+ # IEEE 802.1Q VLAN tag (http://en.wikipedia.org/wiki/IEEE_802.1Q)
31
+ class VLAN < RacketPart
32
+ ETHERTYPE_IPV4 = 0x0800
33
+ ETHERTYPE_ARP = 0x0806
34
+ ETHERTYPE_RARP = 0x8035
35
+ ETHERTYPE_APPLETALK = 0x809b
36
+ ETHERTYPE_AARP = 0x80f3
37
+ ETHERTYPE_8021Q = 0x8100
38
+ ETHERTYPE_IPX = 0x8137
39
+ ETHERTYPE_NOVELL = 0x8138
40
+ ETHERTYPE_IPV6 = 0x86DD
41
+ ETHERTYPE_MPLS_UNICAST = 0x8847
42
+ ETHERTYPE_MPLS_MULTICAST = 0x8848
43
+ ETHERTYPE_PPPOE_DISCOVERY = 0x8863
44
+ ETHERTYPE_PPPOE_SESSION = 0x8864
45
+ ETHERTYPE_8021X = 0x888E
46
+ ETHERTYPE_ATAOE = 0x88A2
47
+ ETHERTYPE_8021AE = 0x88E5
48
+
49
+ # Frame priority level
50
+ unsigned :priority, 3
51
+ # Canonical format indicator
52
+ unsigned :cfi, 1
53
+ # VLAN ID
54
+ unsigned :id, 12
55
+ # L3 protocol type. Defaults to IPV4
56
+ unsigned :type, 16, { :default => ETHERTYPE_IPV4 }
57
+ rest :payload
58
+ end
59
+ end
60
+ end
61
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,124 @@
1
+ # $Id$
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L2
30
+ # VLAN Trunking Protocol (VTP)
31
+ # http://en.wikipedia.org/wiki/VLAN_Trunking_Protocol
32
+ # http://www.cisco.com/en/US/tech/tk389/tk689/technologies_tech_note09186a0080094c52.shtml
33
+ # This is just a base class from which all VTP messages inherit and should never be used directly
34
+ class VTPGeneric < RacketPart
35
+ # VTP version (1-3)
36
+ unsigned :version, 8
37
+ # Message code (summary advertisement, subset advertisement, advertisement request, VTP join)
38
+ unsigned :code, 8
39
+ # Sometimes used, sometimes not, depends on the type
40
+ unsigned :reserved, 8
41
+ # Length of the management domain
42
+ unsigned :domain_length, 8
43
+ # management domain name, zero padded to 32 bytes
44
+ text :domain, 256
45
+
46
+ # Adjust +domain_length+ and +domain+ accordingly prior to sending
47
+ def fix!
48
+ self.domain_length = self.domain.length
49
+ self.domain = self.domain.ljust(32, "\x00")
50
+ end
51
+ end
52
+
53
+ # A raw VTP message
54
+ class VTPRaw < VTPGeneric
55
+ rest :payload
56
+ end
57
+
58
+ class VTPSubsetAdvertisement < VTPGeneric
59
+ # Configuration revision
60
+ unsigned :revision, 32
61
+ # all of the vlan info fields
62
+ rest :payload
63
+
64
+ def add_vlan_info(status, type, id, mtu, index, name)
65
+ name_length = name.length
66
+ # zero pad name to a multiple of 4 bytes
67
+ name = name.length % 4 == 0 ? name : name.ljust(name.length + (4 - (name.length % 4)), "\x00")
68
+ length = 12 + name.length
69
+ @vlan_info << [length, status, type, name_length, id, mtu, index, name]
70
+ end
71
+
72
+ def fix!
73
+ @vlan_info.each do |v|
74
+ self.payload += v.pack("CCCCnnNa*")
75
+ end
76
+ super
77
+ end
78
+
79
+ def initialize(*args)
80
+ @vlan_info = []
81
+ super(*args)
82
+ self.code = 2
83
+ end
84
+ end
85
+
86
+ class VTPSummaryAdvertisement < VTPGeneric
87
+ # Configuration revision number
88
+ unsigned :revision, 32
89
+ # Updater identity (IP)
90
+ octets :updater, 32
91
+ # update timestamp
92
+ unsigned :timestamp, 96
93
+ # MD5 digest of VTP password
94
+ text :md5, 128
95
+ rest :payload
96
+
97
+ def initialize(*args)
98
+ super(*args)
99
+ self.code = 1
100
+ end
101
+ end
102
+
103
+ class VTPAdvertisementRequest < VTPGeneric
104
+ # This is used in cases in which there are several subset advertisements. If the first (n) subset advertisement has been received and the subsequent one (n+1) has not been received, the Catalyst only requests advertisements from the (n+1)th one.
105
+ unsigned :start, 32
106
+ rest :payload
107
+ def initialize(*args)
108
+ super(*args)
109
+ self.code = 3
110
+ end
111
+
112
+ end
113
+
114
+
115
+ class VTPJoin < VTPGeneric
116
+ def initialize(*args)
117
+ super(*args)
118
+ self.code = 4
119
+ end
120
+ end
121
+
122
+ end
123
+ end
124
+ # vim: set ts=2 et sw=2:
data/lib/racket/l2.rb ADDED
@@ -0,0 +1,30 @@
1
+ # $Id: l2.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ Dir.glob(File.join(File.dirname(__FILE__), 'l2/*.rb')).each { |f| require f }
29
+
30
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,63 @@
1
+ # $Id: arp.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L3
30
+ # Address Resolution Protocol: ARP
31
+ # RFC826 (http://www.faqs.org/rfcs/rfc826.html)
32
+ class ARP < RacketPart
33
+ ARPOP_REQUEST = 0x0001
34
+ ARPOP_REPLY = 0x0002
35
+
36
+ # Hardware type
37
+ unsigned :htype, 16, { :default => 1 }
38
+ # Protocol type
39
+ unsigned :ptype, 16, { :default => 0x0800 }
40
+ # Hardware address length
41
+ unsigned :hlen, 8, { :default => 6 }
42
+ # Protocol address length
43
+ unsigned :plen, 8, { :default => 4 }
44
+ # Opcode
45
+ unsigned :opcode, 16
46
+ # XXX: This is not entirely correct. Technically, sha, spa, tha and
47
+ # tpa should be sized according to hlen and plen. This is good enough for
48
+ # Ethernet and IPv4.
49
+
50
+ # Source hardware address
51
+ hex_octets :sha, 48
52
+ # Source protocol address
53
+ octets :spa, 32
54
+ # Target hardware address
55
+ hex_octets :tha, 48
56
+ # Target protcol address
57
+ octets :tpa, 32
58
+ # Payload
59
+ rest :payload
60
+ end
61
+ end
62
+ end
63
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,85 @@
1
+ # $Id: cdp.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L3
30
+ # CDP -- Cisco Discovery Protocol
31
+ # http://www.cisco.biz/univercd/cc/td/doc/product/lan/trsrb/frames.htm#xtocid12
32
+ class CDP < RacketPart
33
+ # CDP Version (generally 1)
34
+ unsigned :version, 8, { :default => 1 }
35
+ # Time-to-live of the data in this message
36
+ unsigned :ttl, 8
37
+ # Checksum
38
+ unsigned :checksum, 16
39
+ # Payload of this CDP message. Generally untouched.
40
+ rest :payload
41
+
42
+
43
+ def initialize(*args)
44
+ super(*args)
45
+ end
46
+
47
+ # Add a new field to this CDP message.
48
+ def add_field(type, value)
49
+ t = Racket::Misc::TLV.new(2,2)
50
+ t.type = type
51
+ t.value = value
52
+ t.length = 4 + value.length
53
+ self.payload += t.encode
54
+ end
55
+
56
+ # Check the checksum for this IP datagram
57
+ def checksum?
58
+ self.checksum == compute_checksum
59
+ end
60
+
61
+ # Compute and set the checksum for this IP datagram
62
+ def checksum!
63
+ self.checksum = compute_checksum
64
+ end
65
+
66
+ # Fix this CDP message up for sending.
67
+ def fix!
68
+ self.checksum!
69
+ end
70
+
71
+ private
72
+
73
+ # Compute the checksum for this IP datagram
74
+ def compute_checksum
75
+ pseudo = []
76
+ pseudo << ((self.version << 8) | self.ttl)
77
+ pseudo << 0
78
+ pseudo << self.payload
79
+ L3::Misc.checksum(pseudo.pack("nna*"))
80
+ end
81
+
82
+ end
83
+ end
84
+ end
85
+ # vim: set ts=2 et sw=2: