William A. Kennington III | 71fc189 | 2021-12-13 14:32:20 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2021 Google LLC |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | override=/run/systemd/system/gbmc-ncsi-dhcrelay.service.d/10-nosp.conf |
| 17 | mkdir -p "$(dirname "$override")" |
| 18 | echo '[Service]' >"$override" |
| 19 | echo 'ExecStart=' >>"$override" |
| 20 | # Remove the source relay port from the relay, bringing it back to run on |
| 21 | # the default port 547. Our relays don't support the source port option needed |
| 22 | # to run on 3967 for our legacy NICs. |
| 23 | systemctl cat gbmc-ncsi-dhcrelay | grep '^ExecStart=' | sed 's, -rp 3967,,' >>"$override" |
William A. Kennington III | a8d4047 | 2022-01-25 16:13:00 -0800 | [diff] [blame^] | 24 | |
| 25 | override=/run/systemd/system/gbmc-br-dhcp.service.d/10-direct.conf |
| 26 | mkdir -p "$(dirname "$override")" |
| 27 | echo '[Service]' >"$override" |
| 28 | echo 'ExecStart=' >>"$override" |
| 29 | # Switch the gbmcbr interface for the NCSI one to avoid passing the SOLICIT |
| 30 | # message through the BMC relay. |
| 31 | systemctl cat gbmc-br-dhcp | grep '^ExecStart=' | sed 's, -i gbmcbr, -i @NCSI_IF@,' >>"$override" |
| 32 | |
William A. Kennington III | 71fc189 | 2021-12-13 14:32:20 -0800 | [diff] [blame] | 33 | systemctl daemon-reload |
| 34 | systemctl reset-failed gbmc-ncsi-dhcrelay |
| 35 | systemctl restart --no-block gbmc-ncsi-dhcrelay |
William A. Kennington III | a8d4047 | 2022-01-25 16:13:00 -0800 | [diff] [blame^] | 36 | systemctl reset-failed gbmc-br-dhcp |
| 37 | systemctl restart --no-block gbmc-br-dhcp |
William A. Kennington III | 71fc189 | 2021-12-13 14:32:20 -0800 | [diff] [blame] | 38 | |
| 39 | read -r -d '' contents <<EOF |
| 40 | table inet filter { |
| 41 | chain ncsi_legacy_input { |
William A. Kennington III | a8d4047 | 2022-01-25 16:13:00 -0800 | [diff] [blame^] | 42 | udp dport {546,547} accept |
William A. Kennington III | 71fc189 | 2021-12-13 14:32:20 -0800 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | EOF |
| 46 | rfile=/run/nftables/60-gbmc-ncsi-ra.rules |
| 47 | mkdir -p "$(dirname "$rfile")" |
| 48 | printf '%s' "$contents" >"$rfile" |
| 49 | systemctl reset-failed nftables |
| 50 | systemctl --no-block reload-or-restart nftables |