racket 1.0.10
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.
- data/README +76 -0
- data/examples/arp-send +24 -0
- data/examples/arp-send2 +30 -0
- data/examples/cdp +39 -0
- data/examples/cdp-spew +52 -0
- data/examples/dhcp +42 -0
- data/examples/dhcp-spew +48 -0
- data/examples/dns +38 -0
- data/examples/egp +30 -0
- data/examples/hsrp +43 -0
- data/examples/hsrp_takeover +69 -0
- data/examples/icmp-recv +34 -0
- data/examples/icmp-spew +50 -0
- data/examples/icmpv6 +84 -0
- data/examples/icmpv6-spew +50 -0
- data/examples/igmpv1 +27 -0
- data/examples/igmpv2 +27 -0
- data/examples/igrp-send +25 -0
- data/examples/ipv6 +35 -0
- data/examples/ntp +38 -0
- data/examples/ntp2 +42 -0
- data/examples/sctp +32 -0
- data/examples/stp-send +21 -0
- data/examples/synflood +147 -0
- data/examples/tcp +43 -0
- data/examples/tcp2udp +65 -0
- data/examples/udp +46 -0
- data/examples/vrrp +34 -0
- data/examples/vtp +28 -0
- data/lib/racket.rb +4 -0
- data/lib/racket/l2.rb +30 -0
- data/lib/racket/l2/eightotwodotthree.rb +48 -0
- data/lib/racket/l2/ethernet.rb +62 -0
- data/lib/racket/l2/llc.rb +50 -0
- data/lib/racket/l2/misc.rb +67 -0
- data/lib/racket/l2/snap.rb +40 -0
- data/lib/racket/l2/vlan.rb +61 -0
- data/lib/racket/l2/vtp.rb +124 -0
- data/lib/racket/l3.rb +30 -0
- data/lib/racket/l3/arp.rb +63 -0
- data/lib/racket/l3/cdp.rb +85 -0
- data/lib/racket/l3/egp.rb +53 -0
- data/lib/racket/l3/ipv4.rb +132 -0
- data/lib/racket/l3/ipv6.rb +66 -0
- data/lib/racket/l3/misc.rb +165 -0
- data/lib/racket/l3/stp.rb +81 -0
- data/lib/racket/l4.rb +30 -0
- data/lib/racket/l4/gre.rb +65 -0
- data/lib/racket/l4/icmp.rb +295 -0
- data/lib/racket/l4/icmpv6.rb +446 -0
- data/lib/racket/l4/igmpv1.rb +79 -0
- data/lib/racket/l4/igmpv2.rb +76 -0
- data/lib/racket/l4/igrp.rb +138 -0
- data/lib/racket/l4/misc.rb +35 -0
- data/lib/racket/l4/sctp.rb +163 -0
- data/lib/racket/l4/tcp.rb +152 -0
- data/lib/racket/l4/udp.rb +81 -0
- data/lib/racket/l4/vrrp.rb +95 -0
- data/lib/racket/l5.rb +30 -0
- data/lib/racket/l5/bootp.rb +106 -0
- data/lib/racket/l5/dns.rb +110 -0
- data/lib/racket/l5/hsrp.rb +73 -0
- data/lib/racket/l5/misc.rb +35 -0
- data/lib/racket/l5/ntp.rb +59 -0
- data/lib/racket/misc.rb +30 -0
- data/lib/racket/misc/lv.rb +108 -0
- data/lib/racket/misc/misc.rb +61 -0
- data/lib/racket/misc/orderedhash.rb +63 -0
- data/lib/racket/misc/raw.rb +35 -0
- data/lib/racket/misc/tlv.rb +103 -0
- data/lib/racket/misc/vt.rb +114 -0
- data/lib/racket/racket.rb +164 -0
- data/lib/racket/racketpart.rb +66 -0
- data/test/l2/ts_ethernet.rb +22 -0
- data/test/l2/ts_misc.rb +23 -0
- data/test/l2/ts_vlan.rb +15 -0
- data/test/l3/ts_ipv4.rb +44 -0
- data/test/l3/ts_ipv6.rb +26 -0
- data/test/l3/ts_misc.rb +31 -0
- data/test/l4/ts_icmp.rb +38 -0
- data/test/l4/ts_tcp.rb +55 -0
- data/test/l4/ts_udp.rb +40 -0
- data/test/misc/ts_lv.rb +59 -0
- data/test/misc/ts_orderedhash.rb +33 -0
- data/test/misc/ts_tlv.rb +47 -0
- data/test/misc/ts_vt.rb +56 -0
- data/test/ts_all.rb +14 -0
- metadata +182 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
# $Id: udp.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 L4
|
30
|
+
# User Datagram Protocol: UDP
|
31
|
+
#
|
32
|
+
# RFC768 (http://www.faqs.org/rfcs/rfc768.html)
|
33
|
+
class UDP < RacketPart
|
34
|
+
# Source Port
|
35
|
+
unsigned :src_port, 16
|
36
|
+
# Destination Port
|
37
|
+
unsigned :dst_port, 16
|
38
|
+
# Datagram Length
|
39
|
+
unsigned :len, 16
|
40
|
+
# Checksum
|
41
|
+
unsigned :checksum, 16
|
42
|
+
# Payload
|
43
|
+
rest :payload
|
44
|
+
|
45
|
+
# Check the checksum for this UDP datagram
|
46
|
+
def checksum?(src_ip, dst_ip)
|
47
|
+
self.checksum == 0 || (self.checksum == compute_checksum(src_ip, dst_ip))
|
48
|
+
end
|
49
|
+
|
50
|
+
# Compute and set the checksum for this UDP datagram
|
51
|
+
def checksum!(src_ip, dst_ip)
|
52
|
+
# set the checksum to 0 for usage in the pseudo header...
|
53
|
+
self.checksum = 0
|
54
|
+
self.checksum = compute_checksum(src_ip, dst_ip)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Fix this packet up for proper sending. Sets the length
|
58
|
+
# and checksum properly.
|
59
|
+
def fix!(src_ip, dst_ip)
|
60
|
+
self.len = self.class.bit_length/8 + self.payload.length
|
61
|
+
self.checksum!(src_ip, dst_ip)
|
62
|
+
end
|
63
|
+
|
64
|
+
def initialize(*args)
|
65
|
+
super
|
66
|
+
@autofix = false
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
# Compute the checksum for this UDP datagram
|
71
|
+
def compute_checksum(src_ip, dst_ip)
|
72
|
+
# pseudo header used for checksum calculation as per RFC 768
|
73
|
+
pseudo = [L3::Misc.ipv42long(src_ip), L3::Misc.ipv42long(dst_ip), 17, self.payload.length + self.class.bit_length/8 ]
|
74
|
+
header = [self.src_port, self.dst_port, self.payload.length + self.class.bit_length/8, 0, self.payload]
|
75
|
+
L3::Misc.checksum((pseudo << header).flatten.pack("NNnnnnnna*"))
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# $Id: vrrp.rb 127 2009-11-29 01:30:46Z jhart $
|
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 L4
|
30
|
+
# Virtual Router Redundancy Protocol (VRRP)
|
31
|
+
# http://tools.ietf.org/html/rfc2338
|
32
|
+
# http://tools.ietf.org/html/rfc3768
|
33
|
+
class VRRP < RacketPart
|
34
|
+
# Version
|
35
|
+
unsigned :version, 4
|
36
|
+
# VRRP packet type
|
37
|
+
unsigned :type, 4
|
38
|
+
# Virtual Router Identifier (VRID)
|
39
|
+
unsigned :id, 8
|
40
|
+
# the sending VRRP router's priority for the virtual router.
|
41
|
+
# Higher values equal higher priority.
|
42
|
+
unsigned :priority, 8
|
43
|
+
# Total number of IPs contained in this VRRP message
|
44
|
+
unsigned :num_ips, 8
|
45
|
+
# Authentication type (0, 1, 2)
|
46
|
+
unsigned :auth_type, 8
|
47
|
+
# Advertisement interval
|
48
|
+
unsigned :interval, 8
|
49
|
+
# Checksum
|
50
|
+
unsigned :checksum, 16
|
51
|
+
rest :payload
|
52
|
+
|
53
|
+
# Add a new IP to this message
|
54
|
+
def add_ip(ip)
|
55
|
+
@ips << L3::Misc.ipv42long(ip)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Add authentication data
|
59
|
+
def add_auth(authdata)
|
60
|
+
@authdata = authdata[0,8].ljust(32, "\x00")
|
61
|
+
end
|
62
|
+
|
63
|
+
# Validate the checksum
|
64
|
+
def checksum?
|
65
|
+
self.checksum == compute_checksum
|
66
|
+
end
|
67
|
+
|
68
|
+
# compute and set the checksum
|
69
|
+
def checksum!
|
70
|
+
self.checksum = compute_checksum
|
71
|
+
end
|
72
|
+
|
73
|
+
# (really, just set the checksum)
|
74
|
+
def fix!
|
75
|
+
self.payload = [@ips, @authdata].flatten.pack("N#{@ips.size}a*")
|
76
|
+
self.num_ips = @ips.size
|
77
|
+
self.checksum!
|
78
|
+
end
|
79
|
+
|
80
|
+
def initialize(*args)
|
81
|
+
@ips = []
|
82
|
+
@authdata = ""
|
83
|
+
super
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def compute_checksum
|
88
|
+
# pseudo header used for checksum calculation as per RFC 768
|
89
|
+
pseudo = [ ((self.version << 4) | self.type), self.id, self.priority, self.num_ips, self.auth_type, self.interval, 0, self.payload ]
|
90
|
+
L3::Misc.checksum(pseudo.pack("CCCCCCna*"))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
# vim: set ts=2 et sw=2:
|
data/lib/racket/l5.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# $Id: l5.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__), 'l5/*.rb')).each { |f| require f }
|
29
|
+
|
30
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# $Id: bootp.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 L5
|
30
|
+
# Bootstrap Protocol -- BOOTP
|
31
|
+
#
|
32
|
+
# RFC951 (http://www.faqs.org/rfcs/rfc951.html)
|
33
|
+
class BOOTP < RacketPart
|
34
|
+
BOOTP_REQUEST = 1
|
35
|
+
BOOTP_REPLY = 2
|
36
|
+
|
37
|
+
# Message type
|
38
|
+
unsigned :type, 8
|
39
|
+
# Hardware address type
|
40
|
+
unsigned :hwtype, 8, { :default => 1 }
|
41
|
+
# Hardware adddress length
|
42
|
+
unsigned :hwlen, 8, { :default => 6 }
|
43
|
+
# Hops between client and server
|
44
|
+
unsigned :hops, 8
|
45
|
+
# Transaction ID
|
46
|
+
unsigned :id, 32
|
47
|
+
# Seceonds elapsed since client started trying to boot
|
48
|
+
unsigned :secs, 16
|
49
|
+
# Flags. Generally unused
|
50
|
+
unsigned :flags, 16
|
51
|
+
# Client IP address
|
52
|
+
octets :cip, 32
|
53
|
+
# "Your" (client) IP address.
|
54
|
+
octets :yip, 32
|
55
|
+
# Server IP address
|
56
|
+
octets :sip, 32
|
57
|
+
# Gateway IP address
|
58
|
+
octets :gip, 32
|
59
|
+
# Client hardware address
|
60
|
+
hex_octets :chaddr, 128
|
61
|
+
# Optional server host name
|
62
|
+
text :server, 512
|
63
|
+
# Boot file name
|
64
|
+
text :file, 1024
|
65
|
+
# Payload
|
66
|
+
rest :payload
|
67
|
+
|
68
|
+
def add_option(number, value)
|
69
|
+
o = Racket::Misc::TLV.new(1,1)
|
70
|
+
o.type = number
|
71
|
+
o.value = value
|
72
|
+
o.length = value.length
|
73
|
+
@options << o.encode
|
74
|
+
end
|
75
|
+
|
76
|
+
def fix!
|
77
|
+
# tack on an EOL to the options
|
78
|
+
newpayload = @options.join + "\xff"
|
79
|
+
|
80
|
+
# pad out to 64 bytes
|
81
|
+
while (newpayload.length != 64)
|
82
|
+
newpayload += "\x00"
|
83
|
+
end
|
84
|
+
|
85
|
+
self.payload = newpayload + self.payload
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_s
|
89
|
+
puts "to_s"
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_str
|
93
|
+
puts to_str
|
94
|
+
end
|
95
|
+
|
96
|
+
def initialize(*args)
|
97
|
+
@options = []
|
98
|
+
@options << "\x63\x82\x53\x63" # magic
|
99
|
+
super
|
100
|
+
@autofix = false
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# $Id: dns.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 L5
|
30
|
+
# Domain Name System
|
31
|
+
class DNS < RacketPart
|
32
|
+
# Transaction ID
|
33
|
+
unsigned :tx_id, 16
|
34
|
+
# Response
|
35
|
+
unsigned :response, 1
|
36
|
+
# Opcode
|
37
|
+
unsigned :opcode, 4
|
38
|
+
# Authoritative?
|
39
|
+
unsigned :authoritative, 1
|
40
|
+
# Truncated?
|
41
|
+
unsigned :truncated, 1
|
42
|
+
# Recursion Desired?
|
43
|
+
unsigned :recursion_d, 1
|
44
|
+
# Recursion Available?
|
45
|
+
unsigned :recursion_a, 1
|
46
|
+
# Reserved
|
47
|
+
unsigned :reserved, 1
|
48
|
+
# Answer authenticated?
|
49
|
+
unsigned :auth, 1
|
50
|
+
# Non-authenticated data OK?
|
51
|
+
unsigned :nonauth, 1
|
52
|
+
# Reply Code
|
53
|
+
unsigned :reply_code, 4
|
54
|
+
# Number of questions
|
55
|
+
unsigned :question_rr, 16
|
56
|
+
# Number of answer RR
|
57
|
+
unsigned :answer_rr, 16
|
58
|
+
# Number of authority RR
|
59
|
+
unsigned :authority_rr, 16
|
60
|
+
# Number of additional RR
|
61
|
+
unsigned :additional_rr, 16
|
62
|
+
rest :payload
|
63
|
+
|
64
|
+
def initialize(*args)
|
65
|
+
super
|
66
|
+
end
|
67
|
+
|
68
|
+
# Add an additional record. Automatically increases +additional_rr+
|
69
|
+
def add_additional(name, type, klass)
|
70
|
+
self.payload += self.add_record(name, type, klass).encode
|
71
|
+
self.additional_rr += 1
|
72
|
+
end
|
73
|
+
|
74
|
+
# Add an answer record. Automatically increases +answer_rr+
|
75
|
+
def add_answer(name, type, klass)
|
76
|
+
self.payload += self.add_record(name, type, klass).encode
|
77
|
+
self.answer_rr += 1
|
78
|
+
end
|
79
|
+
|
80
|
+
# Add an authority record. Automatically increases +authority_rr+
|
81
|
+
# XXX: broken. authns records are much more complicated than this.
|
82
|
+
def add_authority(name, type, klass)
|
83
|
+
self.payload += self.add_record(name, type, klass).encode
|
84
|
+
self.authority_rr += 1
|
85
|
+
end
|
86
|
+
|
87
|
+
# Add a question record. Automatically increases +question_rr+
|
88
|
+
def add_question(name, type, klass)
|
89
|
+
self.payload += add_record(name, type, klass).encode
|
90
|
+
self.question_rr += 1
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
def add_record(name, type, klass)
|
95
|
+
q = Racket::Misc::VT.new(2,2)
|
96
|
+
name.split(/\./).each do |p|
|
97
|
+
lv = Racket::Misc::LV.new(1)
|
98
|
+
lv.values << p
|
99
|
+
lv.lengths << p.length
|
100
|
+
q.value << lv.encode
|
101
|
+
end
|
102
|
+
q.types << type
|
103
|
+
q.types << klass
|
104
|
+
q
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
# vim: set ts=2 et sw=2:
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# $Id: hsrp.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 L5
|
30
|
+
# Hot Standby Router Protocol: HSRP
|
31
|
+
#
|
32
|
+
# RFC2281 (http://www.faqs.org/rfcs/rfc2281.html)
|
33
|
+
class HSRP < RacketPart
|
34
|
+
HSRP_HELLO = 0
|
35
|
+
HSRP_COUP = 1
|
36
|
+
HSRP_RESIGN = 2
|
37
|
+
|
38
|
+
HSRP_INITIAL = 0
|
39
|
+
HSRP_LEARN = 1
|
40
|
+
HSRP_LISTEN = 2
|
41
|
+
HSRP_SPEAK = 4
|
42
|
+
HSRP_STANDBY = 8
|
43
|
+
HSRP_ACTIVE = 16
|
44
|
+
|
45
|
+
# Version of the HSRP message contained in this packet. Defaults to 0
|
46
|
+
unsigned :version, 8
|
47
|
+
# Type of the HSRP message contained in this packet.
|
48
|
+
unsigned :opcode, 8
|
49
|
+
# Current state of the router sending the message
|
50
|
+
unsigned :state, 8
|
51
|
+
# Time between the hello messages that this router sends. Obviously only
|
52
|
+
# useful in hello messages
|
53
|
+
unsigned :hellotime, 8
|
54
|
+
# Length of time that this hello message should be considered valid.
|
55
|
+
# Obviously only useful in hello messages.
|
56
|
+
unsigned :holdtime, 8, { :default => 10 }
|
57
|
+
# Priority used to determine active and standby routers. Higher priorities
|
58
|
+
# win, but a higher IP address wins in the event of a tie.
|
59
|
+
unsigned :priority, 8
|
60
|
+
# Standby group
|
61
|
+
unsigned :group, 8
|
62
|
+
# reserved, never used, should be 0
|
63
|
+
unsigned :reserved, 8
|
64
|
+
# Clear-text, 8-character reused password. Defaults to 'cisco'
|
65
|
+
text :password, 64, { :default => 'cisco' }
|
66
|
+
# Virtual IP address used by this group
|
67
|
+
octets :vip, 32
|
68
|
+
# Payload. Generally unused.
|
69
|
+
rest :payload
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
# vim: set ts=2 et sw=2:
|