blob: 3f20530291b3d0bd4482499cd7078f3ba4cb46de [file] [log] [blame]
William A. Kennington III832f02b2021-04-23 12:53:36 -07001SUMMARY = "Configures the gbmc bridge and filter rules"
2PR = "r1"
3LICENSE = "Apache-2.0"
4LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
5
6inherit systemd
7
Willy Tu4dd03ca2021-08-06 09:37:35 -07008FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
William A. Kennington III832f02b2021-04-23 12:53:36 -07009SRC_URI += " \
William A. Kennington IIIeda6f002021-05-11 03:09:54 -070010 file://-bmc-gbmcbr.netdev \
11 file://-bmc-gbmcbr.network.in \
William A. Kennington III832f02b2021-04-23 12:53:36 -070012 file://-bmc-gbmcbrdummy.netdev \
13 file://-bmc-gbmcbrdummy.network \
14 file://+-bmc-gbmcbrusb.network \
William A. Kennington III832f02b2021-04-23 12:53:36 -070015 file://50-gbmc-br.rules \
William A. Kennington IIIb08a9e62021-04-26 12:43:43 -070016 file://gbmc-br-ula.sh \
William A. Kennington III24615562021-04-26 14:10:52 -070017 file://gbmc-br-from-ra.sh \
18 file://gbmc-br-ensure-ra.sh \
19 file://gbmc-br-ensure-ra.service \
William A. Kennington IIIcd40c7e2021-05-05 14:44:41 -070020 file://gbmc-br-gw-src.sh \
William A. Kennington III53527f32021-04-27 13:05:45 -070021 file://gbmc-br-nft.sh \
William A. Kennington IIIb174c182021-11-03 14:54:51 -070022 file://gbmc-br-dhcp.sh \
William A. Kennington IIId230e862022-05-09 15:24:22 -070023 file://50-gbmc-psu-hardreset.sh \
William A. Kennington IIIb174c182021-11-03 14:54:51 -070024 file://gbmc-br-dhcp.service \
William A. Kennington IIIbef990f2022-02-08 16:50:30 -080025 file://gbmc-br-dhcp-term.sh \
26 file://gbmc-br-dhcp-term.service \
William A. Kennington III37e6f392022-05-16 16:19:11 -070027 file://gbmc-br-lib.sh \
28 file://gbmc-br-load-ip.service \
Yuxiao Zhang66f1e122023-03-07 13:51:25 -080029 file://gbmc-start-dhcp.sh \
Yuxiao Zhangcb56ec32023-05-12 10:55:26 -070030 file://50-gbmc-br-cn-redirect.rules \
William A. Kennington III832f02b2021-04-23 12:53:36 -070031 "
32
Willy Tu4dd03ca2021-08-06 09:37:35 -070033FILES:${PN}:append = " \
William A. Kennington IIIb08a9e62021-04-26 12:43:43 -070034 ${datadir}/gbmc-ip-monitor \
William A. Kennington IIId230e862022-05-09 15:24:22 -070035 ${datadir}/gbmc-br-dhcp \
William A. Kennington III37e6f392022-05-16 16:19:11 -070036 ${datadir}/gbmc-br-lib.sh \
William A. Kennington III832f02b2021-04-23 12:53:36 -070037 ${systemd_unitdir}/network \
38 ${sysconfdir}/nftables \
William A. Kennington III832f02b2021-04-23 12:53:36 -070039 "
40
Willy Tu4dd03ca2021-08-06 09:37:35 -070041RDEPENDS:${PN}:append = " \
William A. Kennington III24615562021-04-26 14:10:52 -070042 bash \
William A. Kennington III7e2d05d2022-02-12 15:36:05 -080043 dhcp-done \
William A. Kennington IIIb08a9e62021-04-26 12:43:43 -070044 gbmc-ip-monitor \
William A. Kennington IIIb08a9e62021-04-26 12:43:43 -070045 network-sh \
William A. Kennington III24615562021-04-26 14:10:52 -070046 ndisc6-rdisc6 \
William A. Kennington III08e263a2023-04-04 13:19:39 -070047 nftables-systemd \
William A. Kennington III832f02b2021-04-23 12:53:36 -070048 "
49
William A. Kennington IIIb174c182021-11-03 14:54:51 -070050SYSTEMD_SERVICE:${PN} += " \
51 gbmc-br-ensure-ra.service \
52 gbmc-br-dhcp.service \
William A. Kennington IIIbef990f2022-02-08 16:50:30 -080053 gbmc-br-dhcp-term.service \
William A. Kennington III37e6f392022-05-16 16:19:11 -070054 gbmc-br-load-ip.service \
William A. Kennington IIIb174c182021-11-03 14:54:51 -070055 "
William A. Kennington III24615562021-04-26 14:10:52 -070056
William A. Kennington III832f02b2021-04-23 12:53:36 -070057GBMC_BR_MAC_ADDR ?= ""
58
59# Generated via https://cd34.com/rfc4193/ based on a MAC from a machine I own
60# and we allocated it downstream. Intended to only be used within a complete
61# system of multiple network endpoints.
62GBMC_ULA_PREFIX = "fdb5:0481:10ce:0"
63
64def mac_to_eui64(mac):
65 if not mac:
66 return ''
67 b = [int(c, 16) for c in mac.split(':')]
68 b[0] ^= 2
69 b.insert(3, 0xfe)
70 b.insert(3, 0xff)
71 idx = range(0, len(b)-1, 2)
72 return ':'.join([format((b[i] << 8) + b[i+1], '04x') for i in idx])
73
Yuxiao Zhanged7346e2023-04-05 15:01:46 -070074GBMC_BRIDGE_INTFS ?= ""
75
76ethernet_bridge_install() {
77 # install udev rules if any
78 if [ -z "${GBMC_BRIDGE_INTFS}"]; then
79 return
80 fi
81 cat /dev/null > ${WORKDIR}/-ether-bridge.network
82 echo "[Match]" >> ${WORKDIR}/-ether-bridge.network
83 echo "Name=${GBMC_BRIDGE_INTFS}" >> ${WORKDIR}/-ether-bridge.network
84 echo "[Network]" >> ${WORKDIR}/-ether-bridge.network
85 echo "Bridge=gbmcbr" >> ${WORKDIR}/-ether-bridge.network
86
87 install -d ${D}/${sysconfdir}/systemd/network
88 install -m 0644 ${WORKDIR}/-ether-bridge.network ${D}/${sysconfdir}/systemd/network/
89}
90
William A. Kennington III832f02b2021-04-23 12:53:36 -070091do_install() {
92 netdir=${D}${systemd_unitdir}/network
93 install -d -m0755 $netdir
94
95 if [ ! -z "${GBMC_BR_MAC_ADDR}" ]; then
William A. Kennington III8a5853a2021-05-12 18:01:22 -070096 sfx='${@mac_to_eui64(GBMC_BR_MAC_ADDR)}'
William A. Kennington IIIbf4e27c2023-08-28 13:05:57 -070097 addr="[Address]\nAddress=${GBMC_ULA_PREFIX}:$sfx/64\nPreferredLifetime=0\n"
William A. Kennington III3f9c98d2023-08-28 17:26:02 -070098 addr="$addr[Address]\nAddress=fe80::$sfx/64\nPreferredLifetime=0"
William A. Kennington IIIeda6f002021-05-11 03:09:54 -070099 sed -i "s,@ADDR@,$addr," ${WORKDIR}/-bmc-gbmcbr.network.in
William A. Kennington III832f02b2021-04-23 12:53:36 -0700100 else
William A. Kennington IIIeda6f002021-05-11 03:09:54 -0700101 sed -i '/@ADDR@/d' ${WORKDIR}/-bmc-gbmcbr.network.in
William A. Kennington III832f02b2021-04-23 12:53:36 -0700102 fi
103
Yuxiao Zhanged7346e2023-04-05 15:01:46 -0700104 ethernet_bridge_install
105
William A. Kennington IIIeda6f002021-05-11 03:09:54 -0700106 install -m0644 ${WORKDIR}/-bmc-gbmcbr.netdev $netdir/
107 install -m0644 ${WORKDIR}/-bmc-gbmcbr.network.in $netdir/-bmc-gbmcbr.network
William A. Kennington III832f02b2021-04-23 12:53:36 -0700108 install -m0644 ${WORKDIR}/-bmc-gbmcbrdummy.netdev $netdir/
109 install -m0644 ${WORKDIR}/-bmc-gbmcbrdummy.network $netdir/
110 install -m0644 ${WORKDIR}/+-bmc-gbmcbrusb.network $netdir/
111
112 nftables_dir=${D}${sysconfdir}/nftables
113 install -d -m0755 "$nftables_dir"
114 install -m0644 ${WORKDIR}/50-gbmc-br.rules $nftables_dir/
Yuxiao Zhangcb56ec32023-05-12 10:55:26 -0700115 install -m0644 ${WORKDIR}/50-gbmc-br-cn-redirect.rules $nftables_dir/
William A. Kennington III832f02b2021-04-23 12:53:36 -0700116
William A. Kennington IIIb08a9e62021-04-26 12:43:43 -0700117 mondir=${D}${datadir}/gbmc-ip-monitor
118 install -d -m0755 "$mondir"
119 install -m0644 ${WORKDIR}/gbmc-br-ula.sh "$mondir"/
William A. Kennington III24615562021-04-26 14:10:52 -0700120 install -m0644 ${WORKDIR}/gbmc-br-from-ra.sh "$mondir"/
William A. Kennington IIIcd40c7e2021-05-05 14:44:41 -0700121 install -m0644 ${WORKDIR}/gbmc-br-gw-src.sh "$mondir"/
William A. Kennington III53527f32021-04-27 13:05:45 -0700122 install -m0644 ${WORKDIR}/gbmc-br-nft.sh "$mondir"/
William A. Kennington III24615562021-04-26 14:10:52 -0700123
124 install -d -m0755 ${D}${libexecdir}
125 install -m0755 ${WORKDIR}/gbmc-br-ensure-ra.sh ${D}${libexecdir}/
William A. Kennington IIIb174c182021-11-03 14:54:51 -0700126 install -m0755 ${WORKDIR}/gbmc-br-dhcp.sh ${D}${libexecdir}/
William A. Kennington IIIbef990f2022-02-08 16:50:30 -0800127 install -m0755 ${WORKDIR}/gbmc-br-dhcp-term.sh ${D}${libexecdir}/
William A. Kennington III24615562021-04-26 14:10:52 -0700128 install -d -m0755 ${D}${systemd_system_unitdir}
William A. Kennington IIIbdccd862021-12-15 13:51:55 -0800129 install -m0644 ${WORKDIR}/gbmc-br-ensure-ra.service ${D}${systemd_system_unitdir}/
130 install -m0644 ${WORKDIR}/gbmc-br-dhcp.service ${D}${systemd_system_unitdir}/
William A. Kennington IIIbef990f2022-02-08 16:50:30 -0800131 install -m0644 ${WORKDIR}/gbmc-br-dhcp-term.service ${D}${systemd_system_unitdir}/
William A. Kennington III37e6f392022-05-16 16:19:11 -0700132 install -m0644 ${WORKDIR}/gbmc-br-load-ip.service ${D}${systemd_system_unitdir}/
William A. Kennington IIId230e862022-05-09 15:24:22 -0700133 install -d -m0755 ${D}${datadir}/gbmc-br-dhcp
134 install -m0644 ${WORKDIR}/50-gbmc-psu-hardreset.sh ${D}${datadir}/gbmc-br-dhcp/
William A. Kennington III37e6f392022-05-16 16:19:11 -0700135
136 install -m0644 ${WORKDIR}/gbmc-br-lib.sh ${D}${datadir}/
Yuxiao Zhang66f1e122023-03-07 13:51:25 -0800137
138 install -d ${D}/${bindir}
139 install -m0755 ${WORKDIR}/gbmc-start-dhcp.sh ${D}${bindir}/
William A. Kennington III832f02b2021-04-23 12:53:36 -0700140}
William A. Kennington III16fcffb2021-05-12 18:52:20 -0700141
Willy Tu4dd03ca2021-08-06 09:37:35 -0700142do_rm_work:prepend() {
William A. Kennington III16fcffb2021-05-12 18:52:20 -0700143 # HACK: Work around broken do_rm_work not properly calling rm with `--`
144 # It doesn't like filenames that start with `-`
William A. Kennington III67f50632021-05-13 11:19:25 -0700145 rm -rf -- ${WORKDIR}/-*
William A. Kennington III16fcffb2021-05-12 18:52:20 -0700146}