Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brmldproxy: add package #264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions net/brmldproxy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2023 Linus Lüssing <linus.luessing@c0d3.blue>

include $(TOPDIR)/rules.mk

PKG_NAME:=brmldproxy
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_DATE:=2025-01-06
PKG_SOURCE_URL=https://github.com/T-X/brmldproxy.git
PKG_SOURCE_VERSION:=2b9ec1b64f7bffbbe01271894d53f1b371f48dfa
PKG_MIRROR_HASH:=3db998649cc99ec0e64d39f7b06319a1b6e2b0f50e68e3cbb8f48023c31f0e3d

PKG_MAINTAINER:=Linus Lüssing <linus.luessing@c0d3.blue>
PKG_LICENSE:=GPL-2.0-or-later
PKG_LICENSE_FILES:=LICENSE

include $(INCLUDE_DIR)/package.mk

define Package/brmldproxy
SECTION:=net
CATEGORY:=Network
TITLE:=Bridge MLD Proxy
DEPENDS:=+tc
endef

define Package/brmldproxy/description
A userspace controlled MLD proxy implementation for a Linux bridge.
The bridge itself will appear as a single multicast listening host
to any MLD querier on a configured proxy port, acting in deputy
for any other multicast listener behind adjacent bridge ports.
This potentially reduces MLD report overhead.
brmldproxy further allows to filter out specific multicast groups
and bridge ports from its combined MLD report.
endef

define Package/brmldproxy/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/brmldproxy $(1)/usr/sbin/
$(CP) ./files/* $(1)/
endef

$(eval $(call BuildPackage,brmldproxy))
20 changes: 20 additions & 0 deletions net/brmldproxy/files/etc/config/brmldproxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#config brmldproxy 'lan'
# option disabled '1'
# # The bridge to apply brmldproxy to. Either the
# # bridge interface name or the UCI network interface
# # section name.
# option bridge 'lan'
# # Currently only "ipv6" is supported, optional.
# option family 'ipv6'
# # bridge port to proxy to
# list proxiedport 'wan0'
# # bridge port to proxy from
# list includedport 'lan0'
# # bridge port to exclude from proxying
# list excludedport 'lan1'
# # multicast IP address (range) to exclude from proxying
# list excludefilter 'ff00::/ff0e::'
# list excludefilter 'ff0e::/64'
# # multicast IP address (range) to include in proxying
# # (includes ff0e::123 even though ff0e::/64 was excluded above)
# list includefilter 'ff0e::123'
37 changes: 37 additions & 0 deletions net/brmldproxy/files/etc/hotplug.d/iface/50-brmldproxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2023 Linus Lüssing <linus.luessing@c0d3.blue>

. /lib/functions.sh

[ -z "$INTERFACE" ] && exit 0
[ "$ACTION" != "ifup" ] && [ "$ACTION" != "ifdown" ] && exit 0

/etc/init.d/brmldproxy enabled || exit 0


brmldproxy_handle() {
local cfg="$1"
local disabled
local bridge

config_get_bool disabled "$cfg" disabled 0
[ "$disabled" -gt 0 ] && return 0

config_get bridge "$cfg" bridge

[ -z "$bridge" ] && return 0
[ "$bridge" != "$INTERFACE" ] && return 0

if [ "$ACTION" = "ifup" ]; then
/etc/init.d/brmldproxy start "$cfg" || return 0
else
/etc/init.d/brmldproxy stop "brmldproxy.$cfg" || return 0
fi

# success, stop
return 1
}

config_load brmldproxy

config_foreach brmldproxy_handle brmldproxy
111 changes: 111 additions & 0 deletions net/brmldproxy/files/etc/init.d/brmldproxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/sh /etc/rc.common
# SPDX-License-Identifier: MIT
# Copyright (C) 2023 Linus Lüssing <linus.luessing@c0d3.blue>

USE_PROCD=1

START=19
STOP=90

brmldproxy_start() {
local cfg="$1"
local namespace="$2"
local disabled

local ifname
local family
local bridge
local includedports
local excludedports
local proxiedports
local includefilters
local excludefilters

config_get_bool disabled "$cfg" disabled 0
[ "$disabled" -gt 0 ] && return 0

config_get bridge "$cfg" "bridge"
config_get family "$cfg" "family"
config_get includedports "$cfg" "includedport"
config_get excludedports "$cfg" "excludedport"
config_get proxiedports "$cfg" "proxiedport"
config_get includefilters "$cfg" "includefilter"
config_get excludefilters "$cfg" "excludefilter"

[ -z "$bridge" ] && {
echo "Error: no bridge specified for $cfg" >&2
return 0
}

. /lib/functions/network.sh

if network_get_device ifname "$bridge" && [ -n "$ifname" ]; then
bridge="$ifname"
fi

[ -n "$excludedports" ] && excludedports=$(echo "$excludedports" | sed 's/[^ ]* */-e &/g')
[ -n "$includedports" ] && includedports=$(echo "$includedports" | sed 's/[^ ]* */-i &/g')
[ -n "$proxiedports" ] && proxiedports=$(echo "$proxiedports" | sed 's/[^ ]* */-p &/g')
[ -n "$includefilters" ] && includefilters=$(echo "$includefilters" | sed 's/[^ ]* */-I &/g')
[ -n "$excludefilters" ] && excludefilters=$(echo "$excludefilters" | sed 's/[^ ]* */-E &/g')

[ -z "$namespace" ] && namespace="brmldproxy"

procd_open_instance "$namespace.$cfg"

procd_set_param command /usr/sbin/brmldproxy
[ "${family}" = "ipv4" ] && procd_append_param command -4
[ "${family}" = "ipv6" ] && procd_append_param command -6
procd_append_param command -b "$bridge"
[ -n "$excludedports" ] && procd_append_param command $excludedports
[ -n "$includedports" ] && procd_append_param command $includedports
[ -n "$proxiedports" ] && procd_append_param command $proxiedports
[ -n "$includefilters" ] && procd_append_param command $includefilters
[ -n "$excludefilters" ] && procd_append_param command $excludefilters

procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}

procd_set_param stderr 1
procd_close_instance
}

start_service() {
local cfg="$1"
local namespace="$2"
local instance_found=0

. /lib/functions/network.sh

# no procd boot startup, via hotplug or manual only
[ $PPID -eq 1 ] && return 0

config_cb() {
local type="$1"
local name="$2"
if [ "$type" = "brmldproxy" ]; then
if [ -n "$cfg" -a "$cfg" = "$name" ]; then
instance_found=1
fi
fi
}

config_load brmldproxy

if [ -n "$cfg" ]; then
[ "$instance_found" -gt 0 ] || return
brmldproxy_start "$cfg" "$namespace"
else
config_foreach brmldproxy_start brmldproxy "$namespace"
fi
}

stop_service() {
local cfg="$1"
local namespace="$2"

[ -z "$namespace" ] && namespace="brmldproxy"
}

service_triggers() {
procd_add_reload_trigger brmldproxy
}