1SUMMARY = "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
8FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
9SRC_URI += " \
10  file://-bmc-gbmcbr.netdev \
11  file://-bmc-gbmcbr.network.in \
12  file://-bmc-gbmcbrdummy.netdev \
13  file://-bmc-gbmcbrdummy.network \
14  file://+-bmc-gbmcbrusb.network \
15  file://50-gbmc-br.rules \
16  file://gbmc-br-ula.sh \
17  file://gbmc-br-from-ra.sh \
18  file://gbmc-br-ensure-ra.sh \
19  file://gbmc-br-ensure-ra.service \
20  file://gbmc-br-hostname.sh \
21  file://gbmc-br-hostname.service \
22  file://gbmc-ip-from-ra.sh \
23  file://gbmc-br-ip-from-ra.sh.in \
24  file://gbmc-br-ip-from-ra.service \
25  file://gbmc-br-gw-src.sh \
26  file://gbmc-br-nft.sh \
27  file://gbmc-br-dhcp.sh \
28  file://50-gbmc-psu-hardreset.sh.in \
29  file://gbmc-br-dhcp.service \
30  file://gbmc-br-dhcp-term.sh \
31  file://gbmc-br-dhcp-term.service \
32  file://gbmc-br-lib.sh \
33  file://gbmc-br-load-ip.service \
34  file://gbmc-start-dhcp.sh \
35  file://50-gbmc-br-cn-redirect.rules \
36  "
37
38FILES:${PN}:append = " \
39  ${datadir}/gbmc-ip-monitor \
40  ${datadir}/gbmc-br-dhcp \
41  ${datadir}/gbmc-br-lib.sh \
42  ${datadir}/gbmc-ip-from-ra.sh \
43  ${systemd_unitdir}/network \
44  ${sysconfdir}/nftables \
45  "
46
47RDEPENDS:${PN}:append = " \
48  bash \
49  dhcp-done \
50  gbmc-ip-monitor \
51  network-sh \
52  ndisc6-rdisc6 \
53  nftables-systemd \
54  "
55
56SYSTEMD_SERVICE:${PN} += " \
57  gbmc-br-ensure-ra.service \
58  gbmc-br-hostname.service \
59  gbmc-br-dhcp.service \
60  gbmc-br-dhcp-term.service \
61  gbmc-br-load-ip.service \
62  ${@"gbmc-br-ip-from-ra.service" if d.getVar('GBMC_BR_FIXED_OFFSET') != "" else ""} \
63  "
64
65GBMC_BR_MAC_ADDR ?= ""
66
67# Enables the assignment of IP address and hostname by discovering the
68# machine name and BMC prefix from another BMC on the bridge network.
69# This is intended only to be used when there is a single expansion tray
70# on the BMC network. If more than one machine uses this feature with the
71# same offset in the same machine network, it will collide with others.
72GBMC_BR_FIXED_OFFSET ?= ""
73
74# Generated via https://cd34.com/rfc4193/ based on a MAC from a machine I own
75# and we allocated it downstream. Intended to only be used within a complete
76# system of multiple network endpoints.
77GBMC_ULA_PREFIX = "fdb5:0481:10ce:0"
78
79# coordinated powercycle
80GBMC_COORDINATED_POWERCYCLE ?= "true"
81
82def mac_to_eui64(mac):
83  if not mac:
84    return ''
85  b = [int(c, 16) for c in mac.split(':')]
86  b[0] ^= 2
87  b.insert(3, 0xfe)
88  b.insert(3, 0xff)
89  idx = range(0, len(b)-1, 2)
90  return ':'.join([format((b[i] << 8) + b[i+1], '04x') for i in idx])
91
92GBMC_BRIDGE_INTFS ?= ""
93
94ethernet_bridge_install() {
95  # install udev rules if any
96  if [ -z "${GBMC_BRIDGE_INTFS}"]; then
97    return
98  fi
99  cat /dev/null > ${WORKDIR}/-ether-bridge.network
100  echo "[Match]" >> ${WORKDIR}/-ether-bridge.network
101  echo "Name=${GBMC_BRIDGE_INTFS}" >>  ${WORKDIR}/-ether-bridge.network
102  echo "[Network]" >> ${WORKDIR}/-ether-bridge.network
103  echo "Bridge=gbmcbr" >> ${WORKDIR}/-ether-bridge.network
104
105  install -d ${D}/${sysconfdir}/systemd/network
106  install -m 0644 ${WORKDIR}/-ether-bridge.network ${D}/${sysconfdir}/systemd/network/
107}
108
109do_install() {
110  netdir=${D}${systemd_unitdir}/network
111  install -d -m0755 $netdir
112
113  if [ ! -z "${GBMC_BR_MAC_ADDR}" ]; then
114    sfx='${@mac_to_eui64(GBMC_BR_MAC_ADDR)}'
115    addr="[Address]\nAddress=${GBMC_ULA_PREFIX}:$sfx/64\nPreferredLifetime=0\n"
116    addr="$addr[Address]\nAddress=fe80::$sfx/64\nPreferredLifetime=0"
117    sed -i "s,@ADDR@,$addr," ${WORKDIR}/-bmc-gbmcbr.network.in
118  else
119    sed -i '/@ADDR@/d' ${WORKDIR}/-bmc-gbmcbr.network.in
120  fi
121
122  ethernet_bridge_install
123
124  install -m0644 ${WORKDIR}/-bmc-gbmcbr.netdev $netdir/
125  install -m0644 ${WORKDIR}/-bmc-gbmcbr.network.in $netdir/-bmc-gbmcbr.network
126  install -m0644 ${WORKDIR}/-bmc-gbmcbrdummy.netdev $netdir/
127  install -m0644 ${WORKDIR}/-bmc-gbmcbrdummy.network $netdir/
128  install -m0644 ${WORKDIR}/+-bmc-gbmcbrusb.network $netdir/
129
130  nftables_dir=${D}${sysconfdir}/nftables
131  install -d -m0755 "$nftables_dir"
132  install -m0644 ${WORKDIR}/50-gbmc-br.rules $nftables_dir/
133  install -m0644 ${WORKDIR}/50-gbmc-br-cn-redirect.rules $nftables_dir/
134
135  mondir=${D}${datadir}/gbmc-ip-monitor
136  install -d -m0755 "$mondir"
137  install -m0644 ${WORKDIR}/gbmc-br-ula.sh "$mondir"/
138  install -m0644 ${WORKDIR}/gbmc-br-from-ra.sh "$mondir"/
139  install -m0644 ${WORKDIR}/gbmc-br-gw-src.sh "$mondir"/
140  install -m0644 ${WORKDIR}/gbmc-br-nft.sh "$mondir"/
141
142  install -d -m0755 ${D}${libexecdir}
143  install -m0755 ${WORKDIR}/gbmc-br-ensure-ra.sh ${D}${libexecdir}/
144  install -m0755 ${WORKDIR}/gbmc-br-hostname.sh ${D}${libexecdir}/
145  install -m0755 ${WORKDIR}/gbmc-br-dhcp.sh ${D}${libexecdir}/
146  install -m0755 ${WORKDIR}/gbmc-br-dhcp-term.sh ${D}${libexecdir}/
147  install -d -m0755 ${D}${systemd_system_unitdir}
148  install -m0644 ${WORKDIR}/gbmc-br-ensure-ra.service ${D}${systemd_system_unitdir}/
149  install -m0644 ${WORKDIR}/gbmc-br-hostname.service ${D}${systemd_system_unitdir}/
150  install -m0644 ${WORKDIR}/gbmc-br-dhcp.service ${D}${systemd_system_unitdir}/
151  install -m0644 ${WORKDIR}/gbmc-br-dhcp-term.service ${D}${systemd_system_unitdir}/
152  install -m0644 ${WORKDIR}/gbmc-br-load-ip.service ${D}${systemd_system_unitdir}/
153  install -d -m0755 ${D}${datadir}/gbmc-br-dhcp
154
155  sed 's,@COORDINATED_POWERCYCLE@,${GBMC_COORDINATED_POWERCYCLE},' ${WORKDIR}/50-gbmc-psu-hardreset.sh.in >${WORKDIR}/50-gbmc-psu-hardreset.sh
156  install -m0644 ${WORKDIR}/50-gbmc-psu-hardreset.sh ${D}${datadir}/gbmc-br-dhcp/
157
158  install -m0644 ${WORKDIR}/gbmc-br-lib.sh ${D}${datadir}/
159  install -m0644 ${WORKDIR}/gbmc-ip-from-ra.sh ${D}${datadir}/
160
161  install -d ${D}/${bindir}
162  install -m0755 ${WORKDIR}/gbmc-start-dhcp.sh ${D}${bindir}/
163
164  if [ -n "${GBMC_BR_FIXED_OFFSET}" ]; then
165    sed 's,@IP_OFFSET@,${GBMC_BR_FIXED_OFFSET},' ${WORKDIR}/gbmc-br-ip-from-ra.sh.in >${WORKDIR}/gbmc-br-ip-from-ra.sh
166    install -m0755 ${WORKDIR}/gbmc-br-ip-from-ra.sh ${D}${libexecdir}/
167    install -m0644 ${WORKDIR}/gbmc-br-ip-from-ra.service ${D}${systemd_system_unitdir}/
168  fi
169}
170
171do_rm_work:prepend() {
172  # HACK: Work around broken do_rm_work not properly calling rm with `--`
173  # It doesn't like filenames that start with `-`
174  rm -rf -- ${WORKDIR}/-*
175}
176