this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(network): build WoL magic packet

Khue Doan 9159098f cbb3853e

+70
+2
README.md
··· 119 119 - [NixOS netboot with pixiecore](https://nixos.wiki/wiki/Netboot) 120 120 - [The Pixiecore library](https://github.com/danderson/netboot/tree/main/pixiecore) 121 121 - Custom agent for the installation process inspired by [OpenStack ironic-python-agent](https://opendev.org/openstack/ironic-python-agent) and [Tinkerbell Worker](https://tinkerbell.org/docs/services/tink-worker) 122 + - Wireshark's [WakeOnLAN wiki page](https://wiki.wireshark.org/WakeOnLAN) 123 + - AMD's [Magic Packet Technology](https://www.amd.com/content/dam/amd/en/documents/archived-tech-docs/white-papers/20213.pdf) white paper
+30
internal/network/wol.go
··· 1 + package network 2 + 3 + import "net" 4 + 5 + func buildMacicPacket(mac net.HardwareAddr) []byte { 6 + // A physical WakeOnLAN (Magic Packet) will look like this: 7 + // 8 + // | Synchronization Stream | Target MAC | Password (optional) | 9 + // | 6 | 96 | 0, 4 or 6 | 10 + // 11 + // See also https://wiki.wireshark.org/WakeOnLAN 12 + packet := make([]byte, 0) 13 + 14 + const ( 15 + // The synchronization stream is defined as 6 bytes of FFh 16 + syncStreamLength = 6 17 + // The Target MAC block contains 16 duplications of the IEEE address of the target 18 + macRepeat = 16 19 + // We don't support passwords, at least not yet 20 + ) 21 + 22 + for range syncStreamLength { 23 + packet = append(packet, 0xFF) 24 + } 25 + for range macRepeat { 26 + packet = append(packet, mac...) 27 + } 28 + 29 + return packet 30 + }
+38
internal/network/wol_test.go
··· 1 + package network 2 + 3 + import ( 4 + "bytes" 5 + "net" 6 + "testing" 7 + ) 8 + 9 + func TestBuildMagicPacket(t *testing.T) { 10 + in := net.HardwareAddr{ 11 + // bc:24:11:d0:28:34 12 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 13 + } 14 + want := []byte{ 15 + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 16 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 17 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 18 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 19 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 20 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 21 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 22 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 23 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 24 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 25 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 26 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 27 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 28 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 29 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 30 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 31 + 0xBC, 0x24, 0x11, 0xd0, 0x28, 0x34, 32 + } 33 + got := buildMacicPacket(in) 34 + 35 + if !bytes.Equal(got, want) { 36 + t.Errorf("buildMagicPacket(%v) = %v; want %v", in, got, want) 37 + } 38 + }