Skip to content

Commit

Permalink
-l flag replaced with -p flag (prefix+length)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgersen committed Apr 13, 2023
1 parent 04467c4 commit 180f1ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ Sends a DHCPv6-PD solicit message and displays the response (no request is done)
````
testdhcpv6pd [options] [interface name or index]
available options:
-a string
anonymize ip addresses (format = list nibble indexes to show) (default "12345678")
-l int
prefix length (default 64)
-s dont print debug messages
-v display version
Available options:
-a string
anonymize ip addresses (format = list word indexes to show) (default "12345678")
-p string
ask for a specific prefix and/or length (default "::/64")
-s dont print debug messages
-v display version
````
Without argument, `testdhcpv6pd` will display the available interfaces

Use `-s` to suppress packet debugging

Use `-a format` to anonymize the prefix where format is a list of indexes. Each index, from 1 to 8, is the part number of the address to keep. For instance `-a "18"` only keeps the first and last part of the address.

Use `-p ::/60` to request a /60 prefix or even `-p 2a01:xxx:xxxx:xxxx::/64,` to request a specific prefix

### notes
Not tested on *bsd, plan9

Linux systems require *at least* `cap_net_bind_service` capability to bind to port 546 (see `man 7 capabilities`) or just use `sudo`

Darwin/MacOS: use `sudo`
20 changes: 11 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log"
"net"
"net/netip"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -55,10 +56,10 @@ func parseInterface(name string) (*net.Interface, error) {
}

var (
optPrefixLength = flag.Int("l", 64, "prefix length")
optNoDebug = flag.Bool("s", false, "dont print debug messages")
optVersion = flag.Bool("v", false, "display version")
optAnonymize = flag.String("a", utils.FormatV6Full, "anonymize ip addresses (format = list word indexes to show)")
optNoDebug = flag.Bool("s", false, "dont print debug messages")
optVersion = flag.Bool("v", false, "display version")
optAnonymize = flag.String("a", utils.FormatV6Full, "anonymize ip addresses (format = list word indexes to show)")
optPrefix = flag.String("p", "::/64", "ask for a specific prefix and/or length")
)

func main() {
Expand All @@ -69,9 +70,6 @@ func main() {
fmt.Println("version", version)
os.Exit(0)
}
if *optPrefixLength < 1 || *optPrefixLength > 128 {
log.Fatal("prefix length")
}
if len(flag.Args()) != 1 {
fmt.Printf("Usage: %s [options] [interface name] or [interface index]\n", os.Args[0])
displayInterfaces()
Expand All @@ -80,6 +78,10 @@ func main() {
os.Exit(0)
}

prefix, err := netip.ParsePrefix(*optPrefix)
if err != nil {
log.Fatal(err)
}
iface, err := parseInterface(flag.Args()[0])
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -116,8 +118,8 @@ func main() {
PreferredLifetime: 0,
ValidLifetime: 0,
Prefix: &net.IPNet{
Mask: net.CIDRMask(*optPrefixLength, 128),
IP: net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Mask: net.CIDRMask(prefix.Bits(), 128),
IP: prefix.Addr().AsSlice(),
},
Options: dhcpv6.PrefixOptions{Options: dhcpv6.Options{}},
},
Expand Down

0 comments on commit 180f1ee

Please sign in to comment.