Added bootipv6 command

This commit is contained in:
Dmitri Dolguikh 2017-06-23 14:49:43 +01:00 committed by Dave Anderson
parent 3a5808cb30
commit cb79b8eaa4
5 changed files with 88 additions and 20 deletions

View File

@ -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)
//}
}

View File

@ -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
}

View File

@ -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")
}

View 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)
}

View File

@ -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
}