package/mdns-alias: replace with lightweight C daemon

The replacement is a complete rewrite in C using the Avahi client API.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-04-15 15:36:41 +02:00
parent 34fa6a327d
commit 9605252be8
8 changed files with 13 additions and 142 deletions
+2 -4
View File
@@ -1,7 +1,5 @@
config BR2_PACKAGE_MDNS_ALIAS
bool mdns-alias
select BR2_PACKAGE_DBUS
select BR2_PACKAGE_DBUS_PYTHON
select BR2_PACKAGE_AVAHI
help
Advertises the initial $(HOSTNAME).local and network.local to
Avahi over D-Bus.
Advertises the initial $(HOSTNAME).local and network.local with Avahi.
+5
View File
@@ -0,0 +1,5 @@
# From GitHub release
sha256 fd7272e4e520418a4a1352b69df852d963adfa928afcfda8e82ce7953626efdd mdns-alias-1.0.tar.gz
# Locally generated
sha256 3d6f910b5e198f3daab48047b8ee6949040f7abee3927daf2e231f265faf7d91 LICENSE
+6 -6
View File
@@ -5,12 +5,12 @@
################################################################################
MDNS_ALIAS_VERSION = 1.0
MDNS_ALIAS_SITE_METHOD = local
MDNS_ALIAS_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/mdns-alias
MDNS_ALIAS_SETUP_TYPE = setuptools
MDNS_ALIAS_LICENSE = MIT
MDNS_ALIAS_SITE = https://github.com/troglobit/mdns-alias/releases/download/v$(MDNS_ALIAS_VERSION)
MDNS_ALIAS_LICENSE = ISC
MDNS_ALIAS_LICENSE_FILES = LICENSE
MDNS_ALIAS_REDISTRIBUTE = NO
MDNS_ALIAS_DEPENDENCIES = host-pkgconf avahi
#MDNS_ALIAS_AUTORECONF = YES
#MDNS_ALIAS_DEPENDENCIES += host-automake host-autoconf
define MDNS_ALIAS_INSTALL_EXTRA
$(INSTALL) -D -m 0644 $(MDNS_ALIAS_PKGDIR)/mdns-alias.svc \
@@ -22,4 +22,4 @@ define MDNS_ALIAS_INSTALL_EXTRA
endef
MDNS_ALIAS_POST_INSTALL_TARGET_HOOKS += MDNS_ALIAS_INSTALL_EXTRA
$(eval $(python-package))
$(eval $(autotools-package))
-21
View File
@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2024 Joachim Wiberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-11
View File
@@ -1,11 +0,0 @@
mDNS Alias
==========
This Python program both advertises CNAMEs (using D-Bus to Avahi).
To start the program:
mdns-alias $hostname.local network.local
The latter CNAME can be used with nginx and netbrowse to provide
a basic mDNS service browser.
-24
View File
@@ -1,24 +0,0 @@
"""
Avahi CNAME service over D-Bus advertiser
"""
import sys
import time
from .mdns_alias import MdnsAlias
__all__ = ['MdnsAlias']
def main():
"""Advertises aliases from command line."""
mdns_aliases = MdnsAlias()
for arg in sys.argv[1:]:
mdns_aliases.publish_cname(str(arg).encode("utf-8", "strict"))
while True:
time.sleep(3600)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("Exiting")
-56
View File
@@ -1,56 +0,0 @@
"""Avahi CNAME publisher class"""
from encodings.idna import ToASCII
import dbus
class MdnsAlias:
"""Import to your project and use publish_cname() for each name."""
DBUS_NAME = 'org.freedesktop.Avahi'
CLASS_IN = 0x01
TYPE_CNAME = 0x05
TTL = 60
DBUS_PATH_SERVER = '/'
DBUS_INTERFACE_SERVER = DBUS_NAME + '.Server'
DBUS_INTERFACE_ENTRY_GROUP = DBUS_NAME + '.EntryGroup'
IF_UNSPEC = -1
PROTO_UNSPEC = -1
def publish_cname(self, cname):
"""Call this method for each alias to publish as a CNAME record."""
bus = dbus.SystemBus()
server = dbus.Interface(bus.get_object(self.DBUS_NAME, self.DBUS_PATH_SERVER),
self.DBUS_INTERFACE_SERVER)
group = dbus.Interface(bus.get_object(self.DBUS_NAME, server.EntryGroupNew()),
self.DBUS_INTERFACE_ENTRY_GROUP)
rdata = self.create_rr(server.GetHostNameFqdn())
cname = self.encode_dns(cname)
group.AddRecord(self.IF_UNSPEC, self.PROTO_UNSPEC, dbus.UInt32(0),
cname, self.CLASS_IN, self.TYPE_CNAME, self.TTL, rdata)
group.Commit()
print("Published " + cname.decode())
@staticmethod
def encode_dns(name):
"""Internal"""
out = []
name = name.decode()
for part in str(name).split('.'):
if len(part) == 0:
continue
out.append(ToASCII(part))
return b'.'.join(out)
@staticmethod
def create_rr(name):
"""Internal"""
out = []
for part in name.split('.'):
if len(part) == 0:
continue
out.append(chr(len(part)).encode())
out.append(ToASCII(part))
out.append(b'\0')
return b''.join(out)
-20
View File
@@ -1,20 +0,0 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
#build-backend = "setuptools.build_meta"
[project]
name = "mdns-alias"
version = "1.0"
description = "Request mDNS-SD CNAME over D-Bus to Avahi."
authors = [{name = "Joachim Wiberg", email = "troglobit@gmail.com"}]
license = {file = "LICENSE"}
readme = "README.md"
dependencies = [
"dbus",
]
#[tool.setuptools.packages.find]
#where = ["mdns_alias"]
[project.scripts]
mdns-alias = "mdns_alias:main"