Skip to content

Commit 71ae4fe

Browse files
Split the autogen plugin into separate forward/reverse plugins
1 parent 1e9405f commit 71ae4fe

File tree

5 files changed

+81
-28
lines changed

5 files changed

+81
-28
lines changed

debian/changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
pymds (0.4) precise; urgency=low
2+
3+
* Split autogen plugin into separate forward/reverse plugins (REQUIRES CONFIG CHANGE!).
4+
5+
-- Robert Mibus <[email protected]> Thu, 14 Feb 2013 07:40:38 +1030
6+
17
pymds (0.3) precise; urgency=low
28

39
* Remove the hard-dependency on Python 2.7's os.initgroups()

examples/autogen.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[default]
22
domain=ipv6.example.com
3-
source=pymdsautogen:ipv6.example.com:20010db8
3+
source=pymdsautogen6fwd:ipv6.example.com:20010db8
44
name servers=localhost:127.0.0.1:86400

examples/autogenreverse.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[default]
22
domain=8.b.d.0.1.0.0.2.ip6.arpa
3-
source=pymdsautogen:ipv6.example.com:20010db8
3+
source=pymdsautogen6rev:ipv6.example.com:20010db8
44
filters=pymdsoverride:autogenreverse-override.txt
55
name servers=localhost:127.0.0.1:86400

pymdsautogen6fwd.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (c) 2011 Robert Mibus & Internode
2+
#
3+
# Permission is hereby granted, free of charge, to any person
4+
# obtaining a copy of this software and associated documentation
5+
# files (the "Software"), to deal in the Software without
6+
# restriction, including without limitation the rights to use,
7+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the
9+
# Software is furnished to do so, subject to the following
10+
# conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be
13+
# included in all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
20+
21+
#
22+
# A pymds source filter.
23+
#
24+
# pymdsautogen makes stuff up on the fly
25+
#
26+
# initializer: a "base domain" under which AAAA records go, and an IPv6 prefix
27+
# (for which PTR records work).
28+
#
29+
30+
import struct
31+
32+
from utils import *
33+
34+
import ipaddr
35+
import string
36+
import re
37+
38+
class Source(object):
39+
def __init__(self, basedomain, v6prefix):
40+
self._answers = {}
41+
self.basedomain = basedomain.split('.')
42+
self.v6prefix = v6prefix
43+
44+
def get_response(self, query, domain, qtype, qclass, src_addr):
45+
if qtype == 28 or qtype == 255: # 'AAAA' or 'ANY':
46+
print 'Responding to AAAA query for %s.%s' % (query, domain)
47+
try:
48+
# We SHOULD make sure this matches our v6prefix, but currently
49+
# we don't...
50+
addr = ipaddr.IPv6Address(query.replace('-',':'))
51+
return 0, [{
52+
'qtype': 28, # Hard-coded to 'AAAA', in case we're from an ANY query
53+
'qclass': qclass,
54+
'ttl': 86400,
55+
'rdata': addr.packed
56+
}]
57+
except:
58+
print "No AAAA available"
59+
return 3, []
60+
else: # NS, A, MX, etc. -- but don't return NXDOMAIN if there's a PTR or AAAA
61+
print "Responding to other query type..."
62+
print "Checking if we have a valid PTR or AAAA record:"
63+
rcode_aaaa, resp = self.get_response(query, domain, 28, qclass, src_addr)
64+
if rcode_aaaa == 0:
65+
print "AAAA found, returning for NS"
66+
return 0, []
67+
else:
68+
print "No AAAA found, no NS to return..."
69+
return 3, []

pymdsautogen.py pymdsautogen6rev.py

+4-26
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,13 @@ def get_response(self, query, domain, qtype, qclass, src_addr):
6868
'rdata': labels2str([data] + self.basedomain),
6969
}]
7070

71-
elif qtype == 28 or qtype == 255: # 'AAAA' or 'ANY':
72-
print 'Responding to AAAA query for %s.%s' % (query, domain)
73-
try:
74-
# We SHOULD make sure this matches our v6prefix, but currently
75-
# we don't...
76-
addr = ipaddr.IPv6Address(query.replace('-',':'))
77-
return 0, [{
78-
'qtype': 28, # Hard-coded to 'AAAA', in case we're from an ANY query
79-
'qclass': qclass,
80-
'ttl': 86400,
81-
'rdata': addr.packed
82-
}]
83-
except:
84-
# Could be a PTR record instead maybe?
85-
rcode_ptr, resp = self.get_response(query, domain, 12, qclass, src_addr)
86-
if rcode_ptr == 0:
87-
"Not an AAAA for this record, but there's a PTR"
88-
return 0, []
89-
# Guess not!
90-
print "No AAAA available"
91-
return 3, []
92-
else: # NS, A, MX, etc. -- but don't return NXDOMAIN if there's a PTR or AAAA
71+
else: # NS, A, MX, etc. -- but don't return NXDOMAIN if there's a PTR
9372
print "Responding to other query type..."
9473
print "Checking if we have a valid PTR or AAAA record:"
9574
rcode_ptr, resp = self.get_response(query, domain, 12, qclass, src_addr)
96-
rcode_aaaa, resp = self.get_response(query, domain, 28, qclass, src_addr)
97-
if rcode_ptr == 0 or rcode_aaaa == 0:
98-
print "PTR or AAAA found, returning for NS"
75+
if rcode_ptr == 0:
76+
print "PTR found, returning for NS"
9977
return 0, []
10078
else:
101-
print "No PTR or AAAA found, no NS to return..."
79+
print "No PTR found, no NS to return..."
10280
return 3, []

0 commit comments

Comments
 (0)