William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 1 | SUMMARY = "Configures the gbmc bridge and filter rules" |
| 2 | PR = "r1" |
| 3 | LICENSE = "Apache-2.0" |
| 4 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10" |
| 5 | |
| 6 | inherit systemd |
| 7 | |
Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 8 | FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 9 | SRC_URI += " \ |
William A. Kennington III | eda6f00 | 2021-05-11 03:09:54 -0700 | [diff] [blame] | 10 | file://-bmc-gbmcbr.netdev \ |
| 11 | file://-bmc-gbmcbr.network.in \ |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 12 | file://-bmc-gbmcbrdummy.netdev \ |
| 13 | file://-bmc-gbmcbrdummy.network \ |
| 14 | file://+-bmc-gbmcbrusb.network \ |
| 15 | file://ipmi.service.in \ |
| 16 | file://50-gbmc-br.rules \ |
William A. Kennington III | b08a9e6 | 2021-04-26 12:43:43 -0700 | [diff] [blame] | 17 | file://gbmc-br-ula.sh \ |
William A. Kennington III | 2461556 | 2021-04-26 14:10:52 -0700 | [diff] [blame] | 18 | file://gbmc-br-from-ra.sh \ |
| 19 | file://gbmc-br-ensure-ra.sh \ |
| 20 | file://gbmc-br-ensure-ra.service \ |
William A. Kennington III | cd40c7e | 2021-05-05 14:44:41 -0700 | [diff] [blame] | 21 | file://gbmc-br-gw-src.sh \ |
William A. Kennington III | 53527f3 | 2021-04-27 13:05:45 -0700 | [diff] [blame] | 22 | file://gbmc-br-nft.sh \ |
William A. Kennington III | b174c18 | 2021-11-03 14:54:51 -0700 | [diff] [blame] | 23 | file://gbmc-br-dhcp.sh \ |
William A. Kennington III | d230e86 | 2022-05-09 15:24:22 -0700 | [diff] [blame] | 24 | file://50-gbmc-psu-hardreset.sh \ |
William A. Kennington III | b174c18 | 2021-11-03 14:54:51 -0700 | [diff] [blame] | 25 | file://gbmc-br-dhcp.service \ |
William A. Kennington III | bef990f | 2022-02-08 16:50:30 -0800 | [diff] [blame] | 26 | file://gbmc-br-dhcp-term.sh \ |
| 27 | file://gbmc-br-dhcp-term.service \ |
William A. Kennington III | 37e6f39 | 2022-05-16 16:19:11 -0700 | [diff] [blame] | 28 | file://gbmc-br-lib.sh \ |
| 29 | file://gbmc-br-load-ip.service \ |
Yuxiao Zhang | 66f1e12 | 2023-03-07 13:51:25 -0800 | [diff] [blame] | 30 | file://gbmc-start-dhcp.sh \ |
Yuxiao Zhang | cb56ec3 | 2023-05-12 10:55:26 -0700 | [diff] [blame] | 31 | file://50-gbmc-br-cn-redirect.rules \ |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 32 | " |
| 33 | |
Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 34 | FILES:${PN}:append = " \ |
William A. Kennington III | b08a9e6 | 2021-04-26 12:43:43 -0700 | [diff] [blame] | 35 | ${datadir}/gbmc-ip-monitor \ |
William A. Kennington III | d230e86 | 2022-05-09 15:24:22 -0700 | [diff] [blame] | 36 | ${datadir}/gbmc-br-dhcp \ |
William A. Kennington III | 37e6f39 | 2022-05-16 16:19:11 -0700 | [diff] [blame] | 37 | ${datadir}/gbmc-br-lib.sh \ |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 38 | ${systemd_unitdir}/network \ |
| 39 | ${sysconfdir}/nftables \ |
| 40 | ${sysconfdir}/avahi/services \ |
| 41 | " |
| 42 | |
Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 43 | RDEPENDS:${PN}:append = " \ |
William A. Kennington III | 2461556 | 2021-04-26 14:10:52 -0700 | [diff] [blame] | 44 | bash \ |
William A. Kennington III | 7e2d05d | 2022-02-12 15:36:05 -0800 | [diff] [blame] | 45 | dhcp-done \ |
William A. Kennington III | b08a9e6 | 2021-04-26 12:43:43 -0700 | [diff] [blame] | 46 | gbmc-ip-monitor \ |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 47 | mstpd-mstpd \ |
William A. Kennington III | b08a9e6 | 2021-04-26 12:43:43 -0700 | [diff] [blame] | 48 | network-sh \ |
William A. Kennington III | 2461556 | 2021-04-26 14:10:52 -0700 | [diff] [blame] | 49 | ndisc6-rdisc6 \ |
William A. Kennington III | 08e263a | 2023-04-04 13:19:39 -0700 | [diff] [blame] | 50 | nftables-systemd \ |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 51 | " |
| 52 | |
William A. Kennington III | b174c18 | 2021-11-03 14:54:51 -0700 | [diff] [blame] | 53 | SYSTEMD_SERVICE:${PN} += " \ |
| 54 | gbmc-br-ensure-ra.service \ |
| 55 | gbmc-br-dhcp.service \ |
William A. Kennington III | bef990f | 2022-02-08 16:50:30 -0800 | [diff] [blame] | 56 | gbmc-br-dhcp-term.service \ |
William A. Kennington III | 37e6f39 | 2022-05-16 16:19:11 -0700 | [diff] [blame] | 57 | gbmc-br-load-ip.service \ |
William A. Kennington III | b174c18 | 2021-11-03 14:54:51 -0700 | [diff] [blame] | 58 | " |
William A. Kennington III | 2461556 | 2021-04-26 14:10:52 -0700 | [diff] [blame] | 59 | |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 60 | GBMC_BR_MAC_ADDR ?= "" |
| 61 | |
| 62 | # Generated via https://cd34.com/rfc4193/ based on a MAC from a machine I own |
| 63 | # and we allocated it downstream. Intended to only be used within a complete |
| 64 | # system of multiple network endpoints. |
| 65 | GBMC_ULA_PREFIX = "fdb5:0481:10ce:0" |
| 66 | |
| 67 | def mac_to_eui64(mac): |
| 68 | if not mac: |
| 69 | return '' |
| 70 | b = [int(c, 16) for c in mac.split(':')] |
| 71 | b[0] ^= 2 |
| 72 | b.insert(3, 0xfe) |
| 73 | b.insert(3, 0xff) |
| 74 | idx = range(0, len(b)-1, 2) |
| 75 | return ':'.join([format((b[i] << 8) + b[i+1], '04x') for i in idx]) |
| 76 | |
Yuxiao Zhang | ed7346e | 2023-04-05 15:01:46 -0700 | [diff] [blame] | 77 | GBMC_BRIDGE_INTFS ?= "" |
| 78 | |
| 79 | ethernet_bridge_install() { |
| 80 | # install udev rules if any |
| 81 | if [ -z "${GBMC_BRIDGE_INTFS}"]; then |
| 82 | return |
| 83 | fi |
| 84 | cat /dev/null > ${WORKDIR}/-ether-bridge.network |
| 85 | echo "[Match]" >> ${WORKDIR}/-ether-bridge.network |
| 86 | echo "Name=${GBMC_BRIDGE_INTFS}" >> ${WORKDIR}/-ether-bridge.network |
| 87 | echo "[Network]" >> ${WORKDIR}/-ether-bridge.network |
| 88 | echo "Bridge=gbmcbr" >> ${WORKDIR}/-ether-bridge.network |
| 89 | |
| 90 | install -d ${D}/${sysconfdir}/systemd/network |
| 91 | install -m 0644 ${WORKDIR}/-ether-bridge.network ${D}/${sysconfdir}/systemd/network/ |
| 92 | } |
| 93 | |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 94 | do_install() { |
| 95 | netdir=${D}${systemd_unitdir}/network |
| 96 | install -d -m0755 $netdir |
| 97 | |
| 98 | if [ ! -z "${GBMC_BR_MAC_ADDR}" ]; then |
William A. Kennington III | 8a5853a | 2021-05-12 18:01:22 -0700 | [diff] [blame] | 99 | sfx='${@mac_to_eui64(GBMC_BR_MAC_ADDR)}' |
William A. Kennington III | bf4e27c | 2023-08-28 13:05:57 -0700 | [diff] [blame] | 100 | addr="[Address]\nAddress=${GBMC_ULA_PREFIX}:$sfx/64\nPreferredLifetime=0\n" |
William A. Kennington III | 3f9c98d | 2023-08-28 17:26:02 -0700 | [diff] [blame] | 101 | addr="$addr[Address]\nAddress=fe80::$sfx/64\nPreferredLifetime=0" |
William A. Kennington III | eda6f00 | 2021-05-11 03:09:54 -0700 | [diff] [blame] | 102 | sed -i "s,@ADDR@,$addr," ${WORKDIR}/-bmc-gbmcbr.network.in |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 103 | else |
William A. Kennington III | eda6f00 | 2021-05-11 03:09:54 -0700 | [diff] [blame] | 104 | sed -i '/@ADDR@/d' ${WORKDIR}/-bmc-gbmcbr.network.in |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 105 | fi |
| 106 | |
Yuxiao Zhang | ed7346e | 2023-04-05 15:01:46 -0700 | [diff] [blame] | 107 | ethernet_bridge_install |
| 108 | |
William A. Kennington III | eda6f00 | 2021-05-11 03:09:54 -0700 | [diff] [blame] | 109 | install -m0644 ${WORKDIR}/-bmc-gbmcbr.netdev $netdir/ |
| 110 | install -m0644 ${WORKDIR}/-bmc-gbmcbr.network.in $netdir/-bmc-gbmcbr.network |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 111 | install -m0644 ${WORKDIR}/-bmc-gbmcbrdummy.netdev $netdir/ |
| 112 | install -m0644 ${WORKDIR}/-bmc-gbmcbrdummy.network $netdir/ |
| 113 | install -m0644 ${WORKDIR}/+-bmc-gbmcbrusb.network $netdir/ |
| 114 | |
| 115 | nftables_dir=${D}${sysconfdir}/nftables |
| 116 | install -d -m0755 "$nftables_dir" |
| 117 | install -m0644 ${WORKDIR}/50-gbmc-br.rules $nftables_dir/ |
Yuxiao Zhang | cb56ec3 | 2023-05-12 10:55:26 -0700 | [diff] [blame] | 118 | install -m0644 ${WORKDIR}/50-gbmc-br-cn-redirect.rules $nftables_dir/ |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 119 | |
| 120 | avahi_dir=${D}${sysconfdir}/avahi/services |
| 121 | install -d -m 0755 "$avahi_dir" |
| 122 | sed -i 's,@MACHINE@,${MACHINE},g' ${WORKDIR}/ipmi.service.in |
| 123 | sed -i 's,@EXTRA_ATTRS@,,g' ${WORKDIR}/ipmi.service.in |
| 124 | sed 's,@NAME@,bmc,g' ${WORKDIR}/ipmi.service.in >${avahi_dir}/bmc.ipmi.service |
| 125 | sed 's,@NAME@,${MACHINE}-bmc,g' ${WORKDIR}/ipmi.service.in >${avahi_dir}/${MACHINE}-bmc.ipmi.service |
William A. Kennington III | b08a9e6 | 2021-04-26 12:43:43 -0700 | [diff] [blame] | 126 | |
| 127 | mondir=${D}${datadir}/gbmc-ip-monitor |
| 128 | install -d -m0755 "$mondir" |
| 129 | install -m0644 ${WORKDIR}/gbmc-br-ula.sh "$mondir"/ |
William A. Kennington III | 2461556 | 2021-04-26 14:10:52 -0700 | [diff] [blame] | 130 | install -m0644 ${WORKDIR}/gbmc-br-from-ra.sh "$mondir"/ |
William A. Kennington III | cd40c7e | 2021-05-05 14:44:41 -0700 | [diff] [blame] | 131 | install -m0644 ${WORKDIR}/gbmc-br-gw-src.sh "$mondir"/ |
William A. Kennington III | 53527f3 | 2021-04-27 13:05:45 -0700 | [diff] [blame] | 132 | install -m0644 ${WORKDIR}/gbmc-br-nft.sh "$mondir"/ |
William A. Kennington III | 2461556 | 2021-04-26 14:10:52 -0700 | [diff] [blame] | 133 | |
| 134 | install -d -m0755 ${D}${libexecdir} |
| 135 | install -m0755 ${WORKDIR}/gbmc-br-ensure-ra.sh ${D}${libexecdir}/ |
William A. Kennington III | b174c18 | 2021-11-03 14:54:51 -0700 | [diff] [blame] | 136 | install -m0755 ${WORKDIR}/gbmc-br-dhcp.sh ${D}${libexecdir}/ |
William A. Kennington III | bef990f | 2022-02-08 16:50:30 -0800 | [diff] [blame] | 137 | install -m0755 ${WORKDIR}/gbmc-br-dhcp-term.sh ${D}${libexecdir}/ |
William A. Kennington III | 2461556 | 2021-04-26 14:10:52 -0700 | [diff] [blame] | 138 | install -d -m0755 ${D}${systemd_system_unitdir} |
William A. Kennington III | bdccd86 | 2021-12-15 13:51:55 -0800 | [diff] [blame] | 139 | install -m0644 ${WORKDIR}/gbmc-br-ensure-ra.service ${D}${systemd_system_unitdir}/ |
| 140 | install -m0644 ${WORKDIR}/gbmc-br-dhcp.service ${D}${systemd_system_unitdir}/ |
William A. Kennington III | bef990f | 2022-02-08 16:50:30 -0800 | [diff] [blame] | 141 | install -m0644 ${WORKDIR}/gbmc-br-dhcp-term.service ${D}${systemd_system_unitdir}/ |
William A. Kennington III | 37e6f39 | 2022-05-16 16:19:11 -0700 | [diff] [blame] | 142 | install -m0644 ${WORKDIR}/gbmc-br-load-ip.service ${D}${systemd_system_unitdir}/ |
William A. Kennington III | d230e86 | 2022-05-09 15:24:22 -0700 | [diff] [blame] | 143 | install -d -m0755 ${D}${datadir}/gbmc-br-dhcp |
| 144 | install -m0644 ${WORKDIR}/50-gbmc-psu-hardreset.sh ${D}${datadir}/gbmc-br-dhcp/ |
William A. Kennington III | 37e6f39 | 2022-05-16 16:19:11 -0700 | [diff] [blame] | 145 | |
| 146 | install -m0644 ${WORKDIR}/gbmc-br-lib.sh ${D}${datadir}/ |
Yuxiao Zhang | 66f1e12 | 2023-03-07 13:51:25 -0800 | [diff] [blame] | 147 | |
| 148 | install -d ${D}/${bindir} |
| 149 | install -m0755 ${WORKDIR}/gbmc-start-dhcp.sh ${D}${bindir}/ |
William A. Kennington III | 832f02b | 2021-04-23 12:53:36 -0700 | [diff] [blame] | 150 | } |
William A. Kennington III | 16fcffb | 2021-05-12 18:52:20 -0700 | [diff] [blame] | 151 | |
Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 152 | do_rm_work:prepend() { |
William A. Kennington III | 16fcffb | 2021-05-12 18:52:20 -0700 | [diff] [blame] | 153 | # HACK: Work around broken do_rm_work not properly calling rm with `--` |
| 154 | # It doesn't like filenames that start with `-` |
William A. Kennington III | 67f5063 | 2021-05-13 11:19:25 -0700 | [diff] [blame] | 155 | rm -rf -- ${WORKDIR}/-* |
William A. Kennington III | 16fcffb | 2021-05-12 18:52:20 -0700 | [diff] [blame] | 156 | } |