Skip to content

Commit

Permalink
Merge pull request #10 from Shirkanesi/ipv6_support
Browse files Browse the repository at this point in the history
ADD support for ipv6-console access
  • Loading branch information
dmachard authored Sep 10, 2024
2 parents dba91be + 0796456 commit 4564165
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
8 changes: 7 additions & 1 deletion dnsdist_console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import struct
import base64

from dnsdist_console import util


class Console:
def __init__(self, key, host="127.0.0.1", port=5199):
"""authenticator class"""
Expand Down Expand Up @@ -46,7 +49,10 @@ def disconnect(self):
def connect_to(self):
"""connect to console"""
# prepare socket
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if util.is_ipv4_address(self.console_host):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
else:
self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.sock.settimeout(self.sock_timeout)

Expand Down
9 changes: 9 additions & 0 deletions dnsdist_console/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ipaddress import IPv4Address


def is_ipv4_address(addr: str) -> bool:
try:
IPv4Address(addr)
return True
except ValueError:
return False
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
libnacl==2.1.0
scrypt==0.8.24
scrypt==0.8.24
ipaddress==1.0.23
5 changes: 3 additions & 2 deletions tests/dnsdist.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
setLocal('0.0.0.0:5553')

controlSocket('0.0.0.0:5199')
controlSocket('[::]:5199')
setConsoleACL('0.0.0.0/0')
addConsoleACL('::/0')

setKey('GQpEpQoIuzA6kzgwDokX9JcXPXFvO1Emg1wAXToJ0ag=')

Expand All @@ -10,4 +11,4 @@ newServer({address='1.1.1.1:53', pool='apoolwithoutspaces', name='name with spac
newServer({address='9.9.9.9:53', pool='shortpool', name='namewithoutspaces'})
newServer({address='8.8.4.4:53', pool='a long long long long pool', name='and a long long long long name'})

addAction(AllRule(),PoolAction("apoolwithoutspaces"))
addAction(AllRule(),PoolAction("apoolwithoutspaces"))
15 changes: 15 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ def test_show_version(self):

o = self.console.send_command(cmd="showVersion()")
self.assertRegex(o, ".*dnsdist.*")


class TestConnectV6(unittest.TestCase):
def setUp(self):
self.console = Console(host="::1", port=5199,
key="GQpEpQoIuzA6kzgwDokX9JcXPXFvO1Emg1wAXToJ0ag=")

def tearDown(self):
self.console.disconnect()

def test_show_version(self):
"""connect and get version"""

o = self.console.send_command(cmd="showVersion()")
self.assertRegex(o, ".*dnsdist.*")

0 comments on commit 4564165

Please sign in to comment.