commit 67b1a5a141ee9f6302416a34b45506372725b941
parent 233bdc8aaca2891fa3244677955593b4f7a278c2
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Sat, 30 Jul 2022 02:24:01 +0200
Add static routes, add various templates for s6-rc
Diffstat:
5 files changed, 126 insertions(+), 15 deletions(-)
diff --git a/Makefile b/Makefile
@@ -7,13 +7,13 @@ all: $(ALL_TARGETS)
clean:
rm -rf build $(ALL_TARGETS)
-build/%.awk: %.aat
+build/%.awk: %.aat common.aat
mkdir -p build
aat.awk "$<" >"$@.new"
aat_macros.sed -i "$@.new"
mv "$@.new" "$@"
-%.qawk: %.awk
+%.qawk: %.awk $(DATA_AWK)
cat $(DATA_AWK) >"$@.new"
query.awk "$<" >>"$@.new"
mv "$@.new" "$@"
diff --git a/common.aat b/common.aat
@@ -0,0 +1,15 @@
+|function nl_esc(str) {
+| gsub(/\n/, "\n\t", str)
+| return str
+|}
+|
+|function C(content) {
+| return "\nC\t"nl_esc(content)"\n"
+|}
+|
+|function content_or_rm(content) {
+| print "content_or_rm is broken and deprecated" >"/dev/stderr"
+| print "instead use: <variable|C:\"r\\n\">" >"/dev/stderr"
+| exit 3
+| # return content ? "\nC\t"nl_esc(content) : "\tr"
+|}
diff --git a/config.aat b/config.aat
@@ -1,3 +1,4 @@
+@include common.aat
|BEGIN{
# Login shell for root user in /etc/passwd
root_shell=/bin/zsh
@@ -12,4 +13,10 @@ static_ip=[
iface ip cidr
|#lo 127.0.0.1 8
eth0 192.168.16.23 24
+]
+
+static_route=[
+iface spec
+eth0 0.0.0.0/0 via 192.168.16.1
+]
|}
diff --git a/s6-rc.aat b/s6-rc.aat
@@ -1,3 +1,38 @@
+@include common.aat
+|function service(name, type, deps) {
+/{{name}} d m755
+/{{name}}/type cN {{type}} m644
+/{{name}}/{{ type == "bundle" ? "content" : "dependencies" }}{{ deps?C(deps):"\tr\t" }}m644
+| return name
+|}
+|function with_counter(base_name, suffix) {
+| suffix = svc_counter[base_name]++
+| if(suffix) { return base_name "-" suffix }
+| return base_name
+|}
+|function oneshot(name, deps) {
+| return service(name, "oneshot", deps)
+|}
+|function longrun(name, deps) {
+| return service(name, "longrun", deps)
+|}
+|function list_services_with_counter(base_name, suffix, list) {
+| for(suffix = 0; suffix < svc_counter[base_name]; suffix++) {
+| list = list base_name (suffix ? "-" suffix : "") "\n"
+| }
+| return list
+|}
+|function add_to_bundle(bundle_name, svc_name) {
+| if(already_in_bundle[bundle_name,svc_name]) { return }
+| already_in_bundle[bundle_name,svc_name] = 1
+| bundles[bundle_name] = bundles[bundle_name] svc_name "\n"
+|}
+|function print_bundles( bundle_name) {
+| for(bundle_name in bundles) {
+| service(bundle_name, "bundle", bundles[bundle_name])
+
+| }
+|}
|END{
/ d m755
@@ -37,8 +72,8 @@ CN ok-sysinit
m644
|### Networking ###
-/loopback d m755
-/loopback/type cN oneshot m644
+|add_to_bundle("net-all", "loopback")
+|oneshot("loopback")
/loopback/up
CN if { ip link set lo up }
if -nt { ip addr add 127.0.0.1/8 dev lo brd + }
@@ -46,16 +81,31 @@ CN if { ip link set lo up }
m755
@for i in static_ip
-|grep_re = <i.ip>
-/net-{<i.iface>}-static d m755
-/net-{<i.iface>}-static/type cN oneshot m644
-/net-{<i.iface>}-static/up
+|svc = oneshot(with_counter("net-" get("i.iface") "-ip"))
+|add_to_bundle("net-" get("i.iface"), svc)
+|add_to_bundle("net-all", "net-" get("i.iface"))
+/{{svc}}/up
+CN if { ip link set {<i.iface>} up }
+ if -nt { ip addr add {<i.ip>}/{<i.cidr>} dev {<i.iface>} }
+ pipeline { ip addr show dev {<i.iface>} } grep -qF 'inet {<i.ip>}/{<i.cidr>}'
+/{{svc}}/down
+CN ip addr del {<i.ip>} dev {<i.iface>}
+m755
+@endfor
+
+@for i in static_route
+|svc = oneshot(with_counter("net-" get("i.iface") "-route"), list_services_with_counter("net-" get("i.iface") "-ip"))
+|add_to_bundle("net-" get("i.iface"), svc)
+/{{svc}}/up
CN if { ip link set {<i.iface>} up }
- if -nt { ip addr add {<i.ip>}/{<i.cidr>} dev {<i.iface>} brd + }
- pipeline { ip addr show dev {<i.iface>} } grep -qF 'inet {<i.ip>}/'
+ if -nt { ip route add dev {<i.iface>} {<i.spec>} }
+ pipeline { ip route show dev {<i.iface>} {<i.spec>} } grep -q .'
+/{{svc}}/down
+CN ip route del dev {<i.iface>} {<i.spec>}
m755
@endfor
+|#add_to_bundle("net-all", "dhcpcd")
/dhcpcd d m755
/dhcpcd/type cN longrun m644
/dhcpcd/dependencies
@@ -78,6 +128,7 @@ CN #!/command/execlineb -P
dhcpcd --nobackground
m755
+|add_to_bundle("net-all", "unbound")
/unbound d m755
/unbound/type cN longrun m644
/unbound/dependencies
@@ -266,4 +317,6 @@ m644
/swap/type cN oneshot m644
/swap/up cN swapon -a m644
/swap/down cN swapoff -a m644
+
+|print_bundles()
|}
diff --git a/s6-rc.fileset b/s6-rc.fileset
@@ -147,18 +147,36 @@ m644
/loopback d m755
/loopback/type cN oneshot m644
+/loopback/dependencies r m644
/loopback/up
CN if { ip link set lo up }
if -nt { ip addr add 127.0.0.1/8 dev lo brd + }
pipeline { ip addr show dev lo } grep -q "inet 127\\.0\\.0\\.1"
m755
-/net-eth0-static d m755
-/net-eth0-static/type cN oneshot m644
-/net-eth0-static/up
+/net-eth0-ip d m755
+/net-eth0-ip/type cN oneshot m644
+/net-eth0-ip/dependencies r m644
+/net-eth0-ip/up
CN if { ip link set eth0 up }
- if -nt { ip addr add 192.168.16.23/24 dev eth0 brd + }
- pipeline { ip addr show dev eth0 } grep -qF 'inet 192.168.16.23/'
+ if -nt { ip addr add 192.168.16.23/24 dev eth0 }
+ pipeline { ip addr show dev eth0 } grep -qF 'inet 192.168.16.23/24'
+/net-eth0-ip/down
+CN ip addr del 192.168.16.23 dev eth0
+m755
+
+/net-eth0-route d m755
+/net-eth0-route/type cN oneshot m644
+/net-eth0-route/dependencies
+C net-eth0-ip
+
+m644
+/net-eth0-route/up
+CN if { ip link set eth0 up }
+ if -nt { ip route add dev eth0 0.0.0.0/0 via 192.168.16.1 }
+ pipeline { ip route show dev eth0 0.0.0.0/0 via 192.168.16.1 } grep -q .'
+/net-eth0-route/down
+CN ip route del dev eth0 0.0.0.0/0 via 192.168.16.1
m755
/dhcpcd d m755
@@ -517,3 +535,21 @@ m644
/swap/type cN oneshot m644
/swap/up cN swapon -a m644
/swap/down cN swapoff -a m644
+
+/net-eth0 d m755
+/net-eth0/type cN bundle m644
+/net-eth0/content
+C net-eth0-ip
+ net-eth0-route
+
+m644
+
+/net-all d m755
+/net-all/type cN bundle m644
+/net-all/content
+C loopback
+ net-eth0
+ unbound
+
+m644
+