Skip to content

API issue with UnknownOption #44

@leshow

Description

@leshow

We have a bit of an API issue with the UnknownOption

The fact that this doesn't work, is perhaps a little unexpected:

        let mut opts = DhcpOptions::new();
        opts.insert(DhcpOption::Unknown(UnknownOption {
            code: 1,
            data: vec![192, 168, 1, 1],
        }));
        let opt = opts.get(OptionCode::SubnetMask);
        dbg!(opt); // None

We can modify From<&DhcpOption> for OptionCode' so that the key in the map is a OptionCode::SubnetMask by changing the unknown branch from:

Unknown(n) => OptionCode::Unknown(n.code),

to

Unknown(n) => n.code.into(),

This way you don't need to retrieve the option value with OptionCode::Unknown(1) which feels pretty weird. But the value you will get back after making the above change for the original code will be:

[src/v4/options.rs:1950] opt = Some(
    Unknown(
        UnknownOption {
            code: 1,
            data: [
                192,
                168,
                1,
                1,
            ],
        },
    ),
)

Again, this feels a little strange. The Unknown option could have been inserted programmatically and unbeknownst to the programmer, if let Some(DhcpOption::SubnetMask(_)) = opts.get(OptionCode::SubnetMask) will not work.

We could decode UnknownOption on insert but that feels pretty icky and would likely require re-allocated to prefix the code u8 at the beginning of the data section.

If anyone has some better ideas, feel free to share

edit:

Another option, we could use the repr(u8) for OptionCode and store the keys as the u8 value. That would solve half of this problem. We may want to do this as part of more general option generating macros described in #43

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions