diff --git a/cmd/pixiecore/main.go b/cmd/pixiecore/main.go index 1ebeb26..1ae419b 100644 --- a/cmd/pixiecore/main.go +++ b/cmd/pixiecore/main.go @@ -16,30 +16,28 @@ package main import ( "go.universe.tf/netboot/pixiecore" -// "go.universe.tf/netboot/pixiecore/cli" -// "go.universe.tf/netboot/third_party/ipxe" - "fmt" + "go.universe.tf/netboot/pixiecore/cli" + "go.universe.tf/netboot/third_party/ipxe" ) // qemu-system-x86_64 -L . --bios /usr/share/edk2-firmware/ipv6/OVMF.fd -netdev bridge,br=br1,id=net0 -device virtio-net-pci,netdev=net0 func main() { - /*cli.Ipxe[pixiecore.FirmwareX86PC] = ipxe.MustAsset("undionly.kpxe") + cli.Ipxe[pixiecore.FirmwareX86PC] = ipxe.MustAsset("undionly.kpxe") cli.Ipxe[pixiecore.FirmwareEFI32] = ipxe.MustAsset("ipxe-i386.efi") cli.Ipxe[pixiecore.FirmwareEFI64] = ipxe.MustAsset("ipxe-x86_64.efi") cli.Ipxe[pixiecore.FirmwareEFIBC] = ipxe.MustAsset("ipxe-x86_64.efi") cli.Ipxe[pixiecore.FirmwareX86Ipxe] = ipxe.MustAsset("ipxe.pxe") cli.CLI() -*/ - log := func(subsystem, msg string) { fmt.Printf("[%s] %s", subsystem, msg) } - s := pixiecore.ServerV6{ - Address: "2001:db8:f00f:cafe::4/64", - Log: log, - Debug: log, - } - - err := s.Serve() - if err != nil { - fmt.Printf("Error: %s", err) - } + //log := func(subsystem, msg string) { fmt.Printf("[%s] %s", subsystem, msg) } + //s := pixiecore.ServerV6{ + // Address: "2001:db8:f00f:cafe::4/64", + // Log: log, + // Debug: log, + //} + // + //err := s.Serve() + //if err != nil { + // fmt.Printf("Error: %s", err) + //} } diff --git a/dhcp6/conn.go b/dhcp6/conn.go index 9251d43..2ca37fc 100644 --- a/dhcp6/conn.go +++ b/dhcp6/conn.go @@ -24,14 +24,14 @@ type Conn struct { listenPort string } -func NewConn(addr string) (*Conn, error) { +func NewConn(addr, port string) (*Conn, error) { ifi, err := InterfaceIndexByAddress(addr) if err != nil { return nil, err } group := net.ParseIP("ff02::1:2") - c, err := net.ListenPacket("udp6", "[::]:547") + c, err := net.ListenPacket("udp6", "[::]:" + port) if err != nil { return nil, err } @@ -51,7 +51,7 @@ func NewConn(addr string) (*Conn, error) { group: group, ifi: ifi, listenAddress: addr, - listenPort: "547", + listenPort: port, }, nil } diff --git a/dhcp6/packet.go b/dhcp6/packet.go index fbedb6e..c01d07c 100644 --- a/dhcp6/packet.go +++ b/dhcp6/packet.go @@ -164,6 +164,8 @@ func (p *Packet) ShouldDiscard(serverDuid []byte) error { return ShouldDiscardRequest(p, serverDuid) case MsgInformationRequest: return ShouldDiscardInformationRequest(p, serverDuid) + case MsgRelease: + return nil // FIX ME! default: return fmt.Errorf("Unknown packet") } diff --git a/pixiecore/cli/bootipv6cmd.go b/pixiecore/cli/bootipv6cmd.go new file mode 100644 index 0000000..af79161 --- /dev/null +++ b/pixiecore/cli/bootipv6cmd.go @@ -0,0 +1,56 @@ +package cli + +import ( + "github.com/spf13/cobra" + "go.universe.tf/netboot/pixiecore" + "fmt" +) + +var bootIPv6Cmd = &cobra.Command{ + Use: "bootipv6", + Short: "Boot a kernel and optional init ramdisks over IPv6", + Run: func(cmd *cobra.Command, args []string) { + addr, err := cmd.Flags().GetString("listen-addr") + if err != nil { + fatalf("Error reading flag: %s", err) + } + ipxeUrl, err := cmd.Flags().GetString("ipxe-url") + if err != nil { + fatalf("Error reading flag: %s", err) + } + httpBootUrl, err := cmd.Flags().GetString("httpboot-url") + if err != nil { + fatalf("Error reading flag: %s", err) + } + + s := pixiecore.NewServerV6() + + if addr == "" { + fatalf("Please specify address to listen on") + } else { + } + if ipxeUrl == "" { + fatalf("Please specify ipxe config file url") + } + if httpBootUrl == "" { + fatalf("Please specify httpboot url") + } + + s.Address = addr + s.IPxeUrl = ipxeUrl + s.HttpbootUrl = httpBootUrl + + fmt.Println(s.Serve()) + }, +} + +func serverv6ConfigFlags(cmd *cobra.Command) { + cmd.Flags().StringP("listen-addr", "", "", "IPv6 address to listen on") + cmd.Flags().StringP("ipxe-url", "", "", "IPXE config file url, e.g. http://[2001:db8:f00f:cafe::4]/script.ipxe") + cmd.Flags().StringP("httpboot-url", "", "", "HTTPBoot url, e.g. http://[2001:db8:f00f:cafe::4]/bootx64.efi") +} + +func init() { + rootCmd.AddCommand(bootIPv6Cmd) + serverv6ConfigFlags(bootIPv6Cmd) +} diff --git a/pixiecore/pixicorev6.go b/pixiecore/pixicorev6.go index b7bb466..918926d 100644 --- a/pixiecore/pixicorev6.go +++ b/pixiecore/pixicorev6.go @@ -13,6 +13,8 @@ type ServerV6 struct { Address string Port string Duid []byte + IPxeUrl string + HttpbootUrl string errs chan error @@ -23,10 +25,20 @@ type ServerV6 struct { Debug func(subsystem, msg string) } +func NewServerV6() *ServerV6 { + log := func(subsystem, msg string) { fmt.Printf("[%s] %s", subsystem, msg) } + ret := &ServerV6{ + Port: "547", + Log: log, + Debug: log, + } + return ret +} + func (s *ServerV6) Serve() error { s.log("dhcp", "starting...") - dhcp, err := dhcp6.NewConn(s.Address) + dhcp, err := dhcp6.NewConn(s.Address, s.Port) if err != nil { return err }