patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: Cole Helbling <cole.e.helbling@outlook.com>
Cc: devel@spectrum-os.org
Subject: Re: [PATCH crosvm v2] crosvm: support setting guest MAC from tap-fd
Date: Tue, 18 May 2021 08:36:36 +0000	[thread overview]
Message-ID: <87wnrwtp4b.fsf@alyssa.is> (raw)
In-Reply-To: <SJ0PR03MB5581D43B6795522391EE6CE4B32D9@SJ0PR03MB5581.namprd03.prod.outlook.com>

[-- Attachment #1: Type: text/plain, Size: 3106 bytes --]

"Cole Helbling" <cole.e.helbling@outlook.com> writes:

>> @@ -1319,17 +1319,52 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
>>          }
>>          "vhost-net" => cfg.vhost_net = true,
>>          "tap-fd" => {
>> -            cfg.tap_fd.push(
>> -                value
>> -                    .unwrap()
>> -                    .parse()
>> -                    .map_err(|_| argument::Error::InvalidValue {
>> -                        value: value.unwrap().to_owned(),
>> -                        expected: String::from(
>> -                            "this value for `tap-fd` must be an unsigned integer",
>> -                        ),
>> -                    })?,
>> -            );
>> +            let mut components = value.unwrap().split(',');
>> +
>> +            let fd: RawDescriptor = components
>> +                .next()
>> +                .and_then(|x| x.parse().ok())
>> +                .ok_or_else(|| argument::Error::InvalidValue {
>> +                    value: value.unwrap().to_owned(),
>> +                    expected: String::from("this value for `tap-fd` must be an unsigned integer"),
>> +                })?;
>> +
>> +            let mut mac = None;
>> +            for c in components {
>> +                let mut kv = c.splitn(2, '=');
>> +                let (kind, value) = match (kv.next(), kv.next()) {
>> +                    (Some(kind), Some(value)) => (kind, value),
>> +                    _ => {
>> +                        return Err(argument::Error::InvalidValue {
>> +                            value: c.to_owned(),
>> +                            expected: String::from("option must be of the form `kind=value`"),
>> +                        })
>> +                    }
>> +                };
>> +                match kind {
>> +                    "mac" => {
>> +                        mac = Some(value.parse().map_err(|_| argument::Error::InvalidValue {
>> +                            value: value.to_owned(),
>> +                            expected: String::from(
>> +                                "`mac` needs to be in the form \"XX:XX:XX:XX:XX:XX\"",
>> +                            ),
>> +                        })?)
>> +                    }
>> +                    _ => {
>> +                        return Err(argument::Error::InvalidValue {
>> +                            value: kind.to_owned(),
>> +                            expected: String::from("unrecognized option"),
>> +                        })
>> +                    }
>> +                }
>> +            }
>> +            if cfg.tap_fd.contains_key(&fd) {
>> +                return Err(argument::Error::TooManyArguments(format!(
>
> Is there a better Error variant for this? `TooManyArguments` seems not-
> completely-accurate when specifying an already-in-use FD.

Here are all the variants.  Do you think there's a better one?

https://chromium.googlesource.com/chromiumos/platform/crosvm/+/f35d2c43ff19520855cffee761dc8899c5a439a1/src/argument.rs#49

The only other one I can see that might be applicable would be
InvalidValue...

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2021-05-18  8:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17 18:57 Alyssa Ross
2021-05-17 19:20 ` Cole Helbling
2021-05-18  8:36   ` Alyssa Ross [this message]
2021-05-18 15:43     ` Cole Helbling
2021-05-29 14:08       ` Alyssa Ross
2021-05-30  2:20         ` Cole Helbling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wnrwtp4b.fsf@alyssa.is \
    --to=hi@alyssa.is \
    --cc=cole.e.helbling@outlook.com \
    --cc=devel@spectrum-os.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).