summaryrefslogtreecommitdiff
path: root/meta-google/recipes-google/ncsi/files
diff options
context:
space:
mode:
Diffstat (limited to 'meta-google/recipes-google/ncsi/files')
-rw-r--r--meta-google/recipes-google/ncsi/files/-bmc-gbmcbrncsidhcp.netdev5
-rw-r--r--meta-google/recipes-google/ncsi/files/-bmc-gbmcbrncsidhcp.network4
-rw-r--r--meta-google/recipes-google/ncsi/files/-bmc-gbmcncsidhcp.netdev5
-rw-r--r--meta-google/recipes-google/ncsi/files/-bmc-gbmcncsidhcp.network9
-rw-r--r--meta-google/recipes-google/ncsi/files/50-gbmc-ncsi.rules.in7
-rw-r--r--meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in27
-rw-r--r--meta-google/recipes-google/ncsi/files/gbmc-ncsi-dhcrelay.service.in13
-rw-r--r--meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.service.in15
-rwxr-xr-xmeta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in133
-rw-r--r--meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in9
10 files changed, 214 insertions, 13 deletions
diff --git a/meta-google/recipes-google/ncsi/files/-bmc-gbmcbrncsidhcp.netdev b/meta-google/recipes-google/ncsi/files/-bmc-gbmcbrncsidhcp.netdev
new file mode 100644
index 000000000..58f13bd46
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/-bmc-gbmcbrncsidhcp.netdev
@@ -0,0 +1,5 @@
+[NetDev]
+Name=gbmcbrncsidhcp
+Kind=veth
+[Peer]
+Name=gbmcncsidhcp
diff --git a/meta-google/recipes-google/ncsi/files/-bmc-gbmcbrncsidhcp.network b/meta-google/recipes-google/ncsi/files/-bmc-gbmcbrncsidhcp.network
new file mode 100644
index 000000000..5474bffab
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/-bmc-gbmcbrncsidhcp.network
@@ -0,0 +1,4 @@
+[Match]
+Name=gbmcbrncsidhcp
+[Network]
+Bridge=gbmcbr
diff --git a/meta-google/recipes-google/ncsi/files/-bmc-gbmcncsidhcp.netdev b/meta-google/recipes-google/ncsi/files/-bmc-gbmcncsidhcp.netdev
new file mode 100644
index 000000000..08235aac0
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/-bmc-gbmcncsidhcp.netdev
@@ -0,0 +1,5 @@
+[NetDev]
+Name=gbmcncsidhcp
+Kind=veth
+[Peer]
+Name=gbmcbrncsidhcp
diff --git a/meta-google/recipes-google/ncsi/files/-bmc-gbmcncsidhcp.network b/meta-google/recipes-google/ncsi/files/-bmc-gbmcncsidhcp.network
new file mode 100644
index 000000000..868d24b7e
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/-bmc-gbmcncsidhcp.network
@@ -0,0 +1,9 @@
+[Match]
+Name=gbmcncsidhcp
+[Network]
+DHCP=false
+IPv6AcceptRA=false
+LLMNR=false
+MulticastDNS=false
+LinkLocalAddressing=ipv6
+Address=fdb5:0481:10ce::1/64
diff --git a/meta-google/recipes-google/ncsi/files/50-gbmc-ncsi.rules.in b/meta-google/recipes-google/ncsi/files/50-gbmc-ncsi.rules.in
index 938dca34b..e2ade6e5b 100644
--- a/meta-google/recipes-google/ncsi/files/50-gbmc-ncsi.rules.in
+++ b/meta-google/recipes-google/ncsi/files/50-gbmc-ncsi.rules.in
@@ -8,6 +8,7 @@ table inet filter {
}
chain ncsi_gbmc_br_pub_input {
jump gbmc_br_pub_input
+ jump ncsi_legacy_input
reject
}
chain gbmc_br_pub_input {
@@ -31,4 +32,10 @@ table inet filter {
ip6 daddr fdb5:0481:10ce::/64 drop
ip6 saddr fdb5:0481:10ce::/64 drop
}
+ chain ncsi_dhcp_input {
+ type filter hook input priority 0; policy drop;
+ iifname != ncsigbmc accept
+ ip6 nexthdr icmpv6 accept
+ udp dport 547 accept
+ }
}
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in
index 961da5095..5adc41328 100644
--- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in
@@ -16,9 +16,12 @@
gbmc_ncsi_br_pub_addr_init=
gbmc_ncsi_br_pub_addr_lastip=
+gbmc_ncsi_br_pub_addr_confip=
gbmc_ncsi_br_pub_addr_update() {
[ -n "$gbmc_ncsi_br_pub_addr_init" ] || return
+ [ "$gbmc_ncsi_br_pub_addr_confip" != "$gbmc_ncsi_br_pub_addr_lastip" ] || return
+ gbmc_ncsi_br_pub_addr_confip="$gbmc_ncsi_br_pub_addr_lastip"
printf 'gBMC Bridge Pub Addr from NCSI: %s\n' \
"${gbmc_ncsi_br_pub_addr_lastip:-(deleted)}" >&2
@@ -36,14 +39,14 @@ gbmc_ncsi_br_pub_addr_update() {
done
fi
- local contents='[Network]'$'\n'
+ local contents=
if (( ${#pfx_bytes[@]} != 0 )); then
pfx_bytes[8]=0xfd
local stateless_pfx="$(ip_bytes_to_str pfx_bytes)"
pfx_bytes[9]=0x01
local ncsi_pfx="$(ip_bytes_to_str pfx_bytes)"
- local here=
- read -r -d '' here <<EOF
+ read -r -d '' contents <<EOF
+[Network]
Address=$ncsi_pfx/128
IPv6PrefixDelegation=yes
[IPv6PrefixDelegation]
@@ -56,17 +59,20 @@ ValidLifetimeSec=60
Route=$ncsi_pfx/80
LifetimeSec=60
[Route]
-Destination=$stateless_pfx/72
+Destination=$stateless_pfx/76
Type=unreachable
Metric=1024
EOF
- contents+="$here"$'\n'
fi
local file
for file in /run/systemd/network/{00,}-bmc-gbmcbr.network.d/50-public.conf; do
mkdir -p -m 755 "$(dirname "$file")"
- printf '%s' "$contents" >"$file"
+ if [ -z "$contents" ]; then
+ rm -f "$file"
+ else
+ printf '%s' "$contents" >"$file"
+ fi
done
# Ensure that systemd-networkd performs a reconfiguration as it doesn't
@@ -82,16 +88,19 @@ EOF
gbmc_ncsi_br_pub_addr_hook() {
if [ "$change" = 'init' ]; then
gbmc_ncsi_br_pub_addr_init=1
+ gbmc_ip_monitor_defer
+ elif [ "$change" = 'defer' ]; then
gbmc_ncsi_br_pub_addr_update
elif [ "$change" = 'addr' -a "$intf" = '@NCSI_IF@' ] &&
- [ "$scope" = 'global' -a "$fam" = 'inet6' ]; then
+ [ "$scope" = 'global' -a "$fam" = 'inet6' ] &&
+ [[ "$flags" != *deprecated* ]]; then
if [ "$action" = 'add' -a "$ip" != "$gbmc_ncsi_br_pub_addr_lastip" ]; then
gbmc_ncsi_br_pub_addr_lastip="$ip"
- gbmc_ncsi_br_pub_addr_update
+ gbmc_ip_monitor_defer
fi
if [ "$action" = 'del' -a "$ip" = "$gbmc_ncsi_br_pub_addr_lastip" ]; then
gbmc_ncsi_br_pub_addr_lastip=
- gbmc_ncsi_br_pub_addr_update
+ gbmc_ip_monitor_defer
fi
fi
}
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-dhcrelay.service.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-dhcrelay.service.in
new file mode 100644
index 000000000..5e0345542
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-dhcrelay.service.in
@@ -0,0 +1,13 @@
+[Unit]
+Description=gBMC DHCP Relay Agent Daemon
+After=network.target
+StartLimitIntervalSec=10
+StartLimitBurst=3
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=/usr/sbin/dhcrelay -d --no-pid -rp 3967 -l gbmcncsidhcp -u @NCSI_IF@
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.service.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.service.in
new file mode 100644
index 000000000..82972fffc
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.service.in
@@ -0,0 +1,15 @@
+[Unit]
+Description=gBMC NCSI RA Discovery
+After=network.target
+StartLimitIntervalSec=10
+StartLimitBurst=3
+Conflicts=nic-hostless@@NCSI_IF@.target
+Conflicts=nic-hostful@@NCSI_IF@.target
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=/usr/libexec/gbmc-ncsi-ip-from-ra.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in
new file mode 100755
index 000000000..80bd34f04
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in
@@ -0,0 +1,133 @@
+#!/bin/bash
+# Copyright 2021 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+source /usr/share/network/lib.sh || exit
+source /usr/libexec/ncsid_lib.sh || exit
+
+NCSI_IF='@NCSI_IF@'
+
+old_pfx=
+old_fqdn=
+old_rtr=
+
+set_host() {
+ [ -n "$host" -a -n "$domain" -a -n "$hextet" ] || return
+
+ local fqdn="$host-n$hextet.$domain"
+ [ "$fqdn" != "$old_fqdn" ] || return
+ old_fqdn="$fqdn"
+
+ echo "Found hostname $fqdn" >&2
+ hostnamectl set-hostname "$fqdn" || true
+}
+
+set_net() {
+ [ -n "$pfx" -a -n "$rtr" ] || return
+ [[ "$pfx" != "$old_pfx" || "$rtr" != "$old_rtr" ]] || return
+ old_pfx="$pfx"
+ old_rtr="$rtr"
+
+ echo "Found prefix $pfx from $rtr" >&2
+
+ # Delete any stale IP Addresses from the primary interface as we won't use them
+ UpdateIP xyz.openbmc_project.Network "$NCSI_IF" '0.0.0.0' '0' || true
+ UpdateIP xyz.openbmc_project.Network "$NCSI_IF" '::' '0' || true
+
+ read -r -d '' contents <<EOF
+[Network]
+Address=$pfx/128
+IPv6PrefixDelegation=yes
+[IPv6PrefixDelegation]
+RouterLifetimeSec=60
+[IPv6Prefix]
+Prefix=$stateless_pfx/80
+PreferredLifetimeSec=60
+ValidLifetimeSec=60
+[IPv6RoutePrefix]
+Route=$pfx/80
+LifetimeSec=60
+[Route]
+Destination=$stateless_pfx/76
+Type=unreachable
+Metric=1024
+EOF
+ for file in /run/systemd/network/{00,}-bmc-gbmcbr.network.d/49-public-ra.conf; do
+ mkdir -p -m 755 "$(dirname "$file")"
+ printf '%s' "$contents" >"$file"
+ done
+ touch -c /lib/systemd/network/*-bmc-gbmcbr.network || true
+
+ contents='[Network]'$'\n'
+ contents+="Address=$pfx/128"$'\n'
+ contents+="Gateway=$rtr"$'\n'
+ for file in /run/systemd/network/{00,}-bmc-"$NCSI_IF".network.d/49-public-ra.conf; do
+ mkdir -p -m 755 "$(dirname "$file")"
+ printf '%s' "$contents" >"$file"
+ done
+ touch -c /etc/systemd/network/*-bmc-"$NCSI_IF".network || true
+
+ if [ "$(systemctl is-active systemd-networkd)" != 'inactive' ]; then
+ networkctl reload && networkctl reconfigure gbmcbr "$NCSI_IF" || true
+ fi
+
+ read -r -d '' contents <<EOF
+table inet filter {
+ chain ncsi_input {
+ ip6 saddr != $pfx/76 ip6 daddr $pfx/76 goto ncsi_gbmc_br_pub_input
+ }
+ chain ncsi_forward {
+ ip6 saddr != $pfx/76 ip6 daddr $pfx/76 accept
+ }
+}
+EOF
+ rfile=/run/nftables/40-gbmc-ncsi-ra.rules
+ mkdir -p -m 755 "$(dirname "$rfile")"
+ printf '%s' "$contents" >"$rfile"
+ systemctl reset-failed nftables && systemctl --no-block restart nftables || true
+}
+
+w=60
+while true; do
+ start=$SECONDS
+ while read line; do
+ if [ -z "$line" ]; then
+ hextet=
+ pfx=
+ host=
+ domain=
+ elif [[ "$line" =~ ^Prefix' '*:' '*(.*)/([0-9]+)$ ]]; then
+ t_pfx="${BASH_REMATCH[1]}"
+ t_pfx_len="${BASH_REMATCH[2]}"
+ ip_to_bytes t_pfx_b "$t_pfx" || continue
+ (( t_pfx_len == 76 && t_pfx_b[8] & 0xfd == 0xfd )) || continue
+ (( t_pfx_b[9] |= 1 ))
+ hextet="fd$(printf '%02x' ${t_pfx_b[9]})"
+ pfx="$(ip_bytes_to_str t_pfx_b)"
+ (( t_pfx_b[9] &= 0xf0 ))
+ stateless_pfx="$(ip_bytes_to_str t_pfx_b)"
+ elif [[ "$line" =~ ^'DNS search list'' '*:' '*([^.-]*)[^.]*[.](.*.google.com)$ ]]; then
+ host="${BASH_REMATCH[1]}"
+ domain="${BASH_REMATCH[2]}"
+ elif [[ "$line" =~ ^from' '(.*)$ ]]; then
+ rtr="${BASH_REMATCH[1]}"
+ set_net || true
+ set_host || true
+ fi
+ done < <(rdisc6 -d -m "$NCSI_IF" -w $(( w * 1000 )) 2>/dev/null)
+ # If rdisc6 exits early we still want to wait the full `w` time before
+ # starting again.
+ (( timeout = start + w - SECONDS ))
+ sleep $(( timeout < 0 ? 0 : timeout ))
+done
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in
index d07b9e2f0..7a630f5fe 100644
--- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in
@@ -54,15 +54,15 @@ gbmc_ncsi_nft_update() {
if (( ${#ip_bytes[@]} != 0 )); then
ip_bytes[8]=0xfd
pfx="$(ip_bytes_to_str ip_bytes)"
- contents+=" ip6 saddr != $pfx/72 ip6 daddr"
- contents+=" $pfx/72 goto ncsi_gbmc_br_pub_input"$'\n'
+ contents+=" ip6 saddr != $pfx/76 ip6 daddr"
+ contents+=" $pfx/76 goto ncsi_gbmc_br_pub_input"$'\n'
fi
fi
contents+=' }'$'\n'
contents+=' chain ncsi_forward {'$'\n'
if [ -n "$pfx" ]; then
- contents+=" ip6 saddr != $pfx/72 ip6 daddr $pfx/72 accept"$'\n'
+ contents+=" ip6 saddr != $pfx/76 ip6 daddr $pfx/76 accept"$'\n'
fi
contents+=' }'$'\n'
contents+='}'$'\n'
@@ -80,7 +80,8 @@ gbmc_ncsi_nft_hook() {
if [ "$change" = 'init' ]; then
gbmc_ncsi_nft_init=1
gbmc_ncsi_nft_update
- elif [ "$change" = 'addr' -a "$intf" = '@NCSI_IF@' -a "$scope" = 'global' ]; then
+ elif [ "$change" = 'addr' -a "$intf" = '@NCSI_IF@' -a "$scope" = 'global' ] &&
+ [[ "$flags" != *deprecated* ]]; then
if [ "$fam" = 'inet6' ]; then
local -n lastip='gbmc_ncsi_nft_lastip6'
else