Skip to content

Commit 0444cdb

Browse files
Ensure autogen6fwd only handles addresses inside the configured v6prefix
1 parent ed6739a commit 0444cdb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pymdsautogen6fwd.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@
3232
from utils import *
3333

3434
import ipaddr
35-
import string
36-
import re
3735

3836
class Source(object):
3937
def __init__(self, basedomain, v6prefix):
4038
self._answers = {}
4139
self.basedomain = basedomain.split('.')
40+
# Note: The v6prefix as a string is awkward, because the config file doesn't allow literal ":"
41+
# Thus, we end up doing string mangling where we might otherwise do address parsing.
4242
self.v6prefix = v6prefix
4343

4444
def get_response(self, query, domain, qtype, qclass, src_addr):
4545
if qtype == 28 or qtype == 255: # 'AAAA' or 'ANY':
4646
try:
47-
# We SHOULD make sure this matches our v6prefix, but currently
48-
# we don't...
47+
# Turn the address string into an address object
4948
addr = ipaddr.IPv6Address(query.replace('-',':'))
49+
# Make sure it's one of ours; else just bail with NXDOMAIN
50+
if not addr.exploded.replace(':','').startswith(self.v6prefix):
51+
return 3, []
52+
# All OK, return the data!
5053
return 0, [{
5154
'qtype': 28, # Hard-coded to 'AAAA', in case we're from an ANY query
5255
'qclass': qclass,

pymdsautogen6rev.py

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Source(object):
3939
def __init__(self, basedomain, v6prefix):
4040
self._answers = {}
4141
self.basedomain = basedomain.split('.')
42+
# Note: The v6prefix as a string is awkward, because the config file doesn't allow literal ":"
43+
# Thus, we end up doing string mangling where we might otherwise do address parsing.
4244
self.v6prefix = v6prefix
4345

4446
def get_response(self, query, domain, qtype, qclass, src_addr):

0 commit comments

Comments
 (0)