mirror of
https://github.com/danderson/netboot.git
synced 2025-08-09 08:07:11 +02:00
Added bootipv6 command
This commit is contained in:
parent
3a5808cb30
commit
cb79b8eaa4
@ -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)
|
||||
//}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
56
pixiecore/cli/bootipv6cmd.go
Normal file
56
pixiecore/cli/bootipv6cmd.go
Normal file
@ -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)
|
||||
}
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user