Skip to content

Commit

Permalink
update readme for v6 inforeq
Browse files Browse the repository at this point in the history
  • Loading branch information
leshow committed Aug 19, 2022
1 parent fa1b526 commit 2255a03
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ ex dhcpv4:
dhcpm 192.168.0.1 dora (unicast DORA to 192.168.0.1)
dhcpm 192.168.0.1 dora -o 118,C0A80001 (unicast DORA, incl opt 118:192.168.0.1)
dhcpv6:
dhcpm ::0 -p 9901 solicit (unicast solicit to [::0]:9901)
dhcpm ff02::1:2 solicit (multicast solicit to default port)
dhcpm ::0 -p 9901 inforeq (unicast inforeq to [::0]:9901)
dhcpm ff02::1:2 inforeq (multicast inforeq to default port)
Positional Arguments:
target ip address to send to
Expand All @@ -54,9 +54,6 @@ Options:
-t, --timeout query timeout in seconds [default: 5]
--output select the log output format (json|pretty|debug) [default:
pretty]
--script pass in a path to a rhai script
(https://github.com/rhaiscript/rhai) NOTE: must compile
dhcpm with `script` feature
--no-retry setting to "true" will prevent re-sending if we don't get a
response [default: false]
--help display usage information
Expand All @@ -68,7 +65,7 @@ Commands:
inform Send an INFORM msg
decline Send a DECLINE msg
dora Sends Discover then Request
solicit Send a SOLICIT msg (dhcpv6)
inforeq Send a INFORMATION-REQUEST msg (dhcpv6)
```

### Sending DHCP over arbitrary ports
Expand Down Expand Up @@ -125,6 +122,26 @@ Each sub-command (`discover`/`request`/`release`, etc) has sub-options. For exam
dhcpm 255.255.255.255 discover --chaddr "80:FA:5B:41:10:6B"
```

### dhcpv6

With DHCPv6, many messages are sent on the multicast group `ff02::1:2` but responses are often unicast back on link-local addresses (starting with `fe80`). `dhcpm` won't be able to receive this data if you've got another dhcpv6 client listening on `[::0]:546`, the dhcpv6 client port. The other process is will likely read the datagram first.

For example, my box has:

```
> sudo lsof -Pi UDP
...
NetworkMa 711 root 20u IPv6 12173080 0t0 UDP leshowbox:546
```

Listening on this `[::0]:546`, so that process would need to be killed before `dhcpm` could print a reply. Still, I have often found it enough to use `dhpcm` to generate a message, then look at the response in wireshark or tcpdump to inspect its validity.

Specify an interface with v6, it is necessary to join the multicast group.

```
> sudo dhcpm ff02::1:2 -i enp6s0 inforeq
```

### Scripting

Scripting support with [rhai](https://github.com/rhaiscript/rhai). Compile `dhcpm` with the `script` feature and give it a path with `--script`:
Expand Down
2 changes: 1 addition & 1 deletion src/inforeq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mac_address::MacAddress;
use crate::opts::{self, parse_mac, v6::parse_params};

#[derive(FromArgs, PartialEq, Eq, Debug, Clone)]
/// Send a INFORMATION-REQUEST msg
/// Send a INFORMATION-REQUEST msg (dhcpv6)
#[argh(subcommand, name = "inforeq")]
pub struct InformationReqArgs {
/// supply a mac address for DHCPv6 (use "random" for a random mac) [default: first interface mac]
Expand Down
18 changes: 7 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ use crate::{
release::ReleaseArgs, request::RequestArgs, util::Msg,
};

const V6_MULTICAST: Ipv6Addr = Ipv6Addr::new(0xff02, 0, 0, 0, 0, 0, 1, 2);

#[allow(clippy::collapsible_else_if)]
fn main() -> Result<()> {
let mut args: Args = argh::from_env();
Expand Down Expand Up @@ -119,9 +121,9 @@ fn main() -> Result<()> {
socket
.bind_device(Some(int.name.as_bytes()))
.context("SO_BINDTODEVICE failed")?;
if bind_addr.is_ipv6() {
if bind_addr.is_ipv6() && bind_addr.ip() == V6_MULTICAST {
socket
.join_multicast_v6(&"ff02::1:2".parse::<Ipv6Addr>().unwrap(), int.index)
.join_multicast_v6(&V6_MULTICAST, int.index)
.context("join v6 multicast")?;
socket
.set_multicast_if_v6(int.index)
Expand Down Expand Up @@ -259,14 +261,14 @@ ex dhcpv4:
dhcpm 192.168.0.1 dora (unicast DORA to 192.168.0.1)
dhcpm 192.168.0.1 dora -o 118,C0A80001 (unicast DORA, incl opt 118:192.168.0.1)
dhcpv6:
dhcpm ::0 -p 9901 solicit (unicast solicit to [::0]:9901)
dhcpm ff02::1:2 solicit (multicast solicit to default port)
dhcpm ::0 -p 9901 inforeq (unicast inforeq to [::0]:9901)
dhcpm ff02::1:2 inforeq (multicast inforeq to default port)
")]
pub struct Args {
/// ip address to send to
#[argh(positional)]
pub target: IpAddr,
/// select a msg type (can't use solicit with v4, or discover with v6)
/// select a msg type (make sure msg type is consistent with ip type, i.e. v4 or v6)
#[argh(subcommand)]
pub msg: Option<MsgType>,
/// address to bind to [default: INADDR_ANY:0]
Expand Down Expand Up @@ -321,7 +323,6 @@ pub enum MsgType {
Inform(InformArgs),
Decline(DeclineArgs),
Dora(DoraArgs),
Solicit(SolicitArgs),
InformationReq(InformationReqArgs),
}

Expand Down Expand Up @@ -397,11 +398,6 @@ impl DoraArgs {
}
}

#[derive(FromArgs, PartialEq, Eq, Debug, Clone, Copy)]
/// Send a SOLICIT msg (dhcpv6)
#[argh(subcommand, name = "solicit")]
pub struct SolicitArgs {}

pub mod util {
use std::{fmt, time::Duration};

Expand Down

0 comments on commit 2255a03

Please sign in to comment.