|
| 1 | +#!/bin/sh /etc/rc.common |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# Copyright (C) 2023 Linus Lüssing <[email protected]> |
| 4 | + |
| 5 | +USE_PROCD=1 |
| 6 | + |
| 7 | +START=19 |
| 8 | +STOP=90 |
| 9 | + |
| 10 | +brmldproxy_start() { |
| 11 | + local cfg="$1" |
| 12 | + local namespace="$2" |
| 13 | + local disabled |
| 14 | + |
| 15 | + local ifname |
| 16 | + local family |
| 17 | + local bridge |
| 18 | + local includedports |
| 19 | + local excludedports |
| 20 | + local proxiedports |
| 21 | + local includefilters |
| 22 | + local excludefilters |
| 23 | + |
| 24 | + config_get_bool disabled "$cfg" disabled 0 |
| 25 | + [ "$disabled" -gt 0 ] && return 0 |
| 26 | + |
| 27 | + config_get bridge "$cfg" "bridge" |
| 28 | + config_get family "$cfg" "family" |
| 29 | + config_get includedports "$cfg" "includedport" |
| 30 | + config_get excludedports "$cfg" "excludedport" |
| 31 | + config_get proxiedports "$cfg" "proxiedport" |
| 32 | + config_get includefilters "$cfg" "includefilter" |
| 33 | + config_get excludefilters "$cfg" "excludefilter" |
| 34 | + |
| 35 | + [ -z "$bridge" ] && { |
| 36 | + echo "Error: no bridge specified for $cfg" >&2 |
| 37 | + return 0 |
| 38 | + } |
| 39 | + |
| 40 | + . /lib/functions/network.sh |
| 41 | + |
| 42 | + if network_get_device ifname "$bridge" && [ -n "$ifname" ]; then |
| 43 | + bridge="$ifname" |
| 44 | + fi |
| 45 | + |
| 46 | + [ -n "$excludedports" ] && excludedports=$(echo "$excludedports" | sed 's/[^ ]* */-e &/g') |
| 47 | + [ -n "$includedports" ] && includedports=$(echo "$includedports" | sed 's/[^ ]* */-i &/g') |
| 48 | + [ -n "$proxiedports" ] && proxiedports=$(echo "$proxiedports" | sed 's/[^ ]* */-p &/g') |
| 49 | + [ -n "$includefilters" ] && includefilters=$(echo "$includefilters" | sed 's/[^ ]* */-I &/g') |
| 50 | + [ -n "$excludefilters" ] && excludefilters=$(echo "$excludefilters" | sed 's/[^ ]* */-E &/g') |
| 51 | + |
| 52 | + [ -z "$namespace" ] && namespace="brmldproxy" |
| 53 | + |
| 54 | + procd_open_instance "$namespace.$cfg" |
| 55 | + |
| 56 | + procd_set_param command /usr/sbin/brmldproxy |
| 57 | + [ "${family}" = "ipv4" ] && procd_append_param command -4 |
| 58 | + [ "${family}" = "ipv6" ] && procd_append_param command -6 |
| 59 | + procd_append_param command -b "$bridge" |
| 60 | + [ -n "$excludedports" ] && procd_append_param command $excludedports |
| 61 | + [ -n "$includedports" ] && procd_append_param command $includedports |
| 62 | + [ -n "$proxiedports" ] && procd_append_param command $proxiedports |
| 63 | + [ -n "$includefilters" ] && procd_append_param command $includefilters |
| 64 | + [ -n "$excludefilters" ] && procd_append_param command $excludefilters |
| 65 | + |
| 66 | + procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} |
| 67 | + |
| 68 | + procd_set_param stderr 1 |
| 69 | + procd_close_instance |
| 70 | +} |
| 71 | + |
| 72 | +start_service() { |
| 73 | + local cfg="$1" |
| 74 | + local namespace="$2" |
| 75 | + local instance_found=0 |
| 76 | + |
| 77 | + . /lib/functions/network.sh |
| 78 | + |
| 79 | + # no procd boot startup, via hotplug or manual only |
| 80 | + [ $PPID -eq 1 ] && return 0 |
| 81 | + |
| 82 | + config_cb() { |
| 83 | + local type="$1" |
| 84 | + local name="$2" |
| 85 | + if [ "$type" = "brmldproxy" ]; then |
| 86 | + if [ -n "$cfg" -a "$cfg" = "$name" ]; then |
| 87 | + instance_found=1 |
| 88 | + fi |
| 89 | + fi |
| 90 | + } |
| 91 | + |
| 92 | + config_load brmldproxy |
| 93 | + |
| 94 | + if [ -n "$cfg" ]; then |
| 95 | + [ "$instance_found" -gt 0 ] || return |
| 96 | + brmldproxy_start "$cfg" "$namespace" |
| 97 | + else |
| 98 | + config_foreach brmldproxy_start brmldproxy "$namespace" |
| 99 | + fi |
| 100 | +} |
| 101 | + |
| 102 | +stop_service() { |
| 103 | + local cfg="$1" |
| 104 | + local namespace="$2" |
| 105 | + |
| 106 | + [ -z "$namespace" ] && namespace="brmldproxy" |
| 107 | +} |
| 108 | + |
| 109 | +service_triggers() { |
| 110 | + procd_add_reload_trigger brmldproxy |
| 111 | +} |
0 commit comments