summaryrefslogtreecommitdiff
path: root/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2023-06-06 02:31:37 +0300
committerWilliam A. Kennington III <wak@google.com>2023-06-06 10:21:41 +0300
commit5206f6616a393d856c2a4f929e3a454c6d9753ad (patch)
tree2bbc665c053ffe58a4d90e362db98cc34cffd281 /meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
parent7a612d4fa70fe6bfd39964c0191a82e6e4546188 (diff)
downloadopenbmc-5206f6616a393d856c2a4f929e3a454c6d9753ad.tar.xz
meta-google: gbmc-bridge: Fix shellcheck issues
Change-Id: Ib19746fffaad5f62293fc3479dee7d557a226734 Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh')
-rw-r--r--meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh22
1 files changed, 11 insertions, 11 deletions
diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
index ca4e15a1fb..7aa2158989 100644
--- a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,11 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-[ -z "${gbmc_br_nft_lib-}" ] || return
+[[ -n ${gbmc_br_nft_lib-} ]] && return
+# shellcheck source=meta-google/recipes-google/networking/network-sh/lib.sh
source /usr/share/network/lib.sh || exit
-gbmc_br_nft_init=
gbmc_br_nft_pfx=
gbmc_br_nft_update() {
@@ -26,7 +27,7 @@ gbmc_br_nft_update() {
local contents=
contents+='table inet filter {'$'\n'
contents+=' chain gbmc_br_int_input {'$'\n'
- if [ -n "${gbmc_br_nft_pfx-}" ]; then
+ if [[ -n ${gbmc_br_nft_pfx-} ]]; then
contents+=" ip6 saddr $gbmc_br_nft_pfx"
contents+=" ip6 daddr $gbmc_br_nft_pfx accept"$'\n'
fi
@@ -34,21 +35,20 @@ gbmc_br_nft_update() {
contents+='}'$'\n'
local rfile=/run/nftables/40-gbmc-br-int.rules
- mkdir -p -m 755 "$(dirname "$rfile")"
+ mkdir -p "$(dirname "$rfile")"
printf '%s' "$contents" >"$rfile"
+ # shellcheck disable=SC2015
systemctl reset-failed nftables && systemctl --no-block reload-or-restart nftables || true
}
gbmc_br_nft_hook() {
- if [ "$change" = 'init' ]; then
- gbmc_br_nft_init=1
- gbmc_br_nft_update
# Match only global IP addresses on the bridge that match the BMC prefix
# (<mpfx>:fdxx:). So 2002:af4:3480:2248:fd02:6345:3069:9186 would become
# a 2002:af4:3480:2248:fd00/76 rule.
- elif [ "$change" = 'addr' -a "$intf" = 'gbmcbr' -a "$scope" = 'global' ] &&
- [[ "$fam" == 'inet6' && "$flags" != *tentative* ]]; then
+ # shellcheck disable=SC2154
+ if [[ $change == addr && $intf == gbmcbr && $scope == global ]] &&
+ [[ $fam == inet6 && $flags != *tentative* ]]; then
local ip_bytes=()
if ! ip_to_bytes ip_bytes "$ip"; then
echo "gBMC Bridge NFT Invalid IP: $ip" >&2
@@ -59,10 +59,10 @@ gbmc_br_nft_hook() {
fi
local i
for (( i=9; i<16; i++ )); do
- ip_bytes[$i]=0
+ ip_bytes["$i"]=0
done
pfx="$(ip_bytes_to_str ip_bytes)/76"
- if [ "$action" = "add" -a "$pfx" != "$gbmc_br_nft_pfx" ]; then
+ if [[ $action == add && $pfx != "$gbmc_br_nft_pfx" ]]; then
gbmc_br_nft_pfx="$pfx"
gbmc_br_nft_update
fi