crosvm/net_util
Alexandre Courbot 993aa7fd49 crosvm: add option to use persistent TAP interface as network device
Currently we have two ways to enable networking on crosvm:

1) Pass all 3 of `--host_ip`, `--netmask` and `--mac` to have crosvm
create and configure a TAP device. This requires crosvm to either be run
as root, or to have the CAP_NET_ADMIN capability,

2) Have another process with the above privileges create and configure
the TAP device before exec'ing crosvm with the TAP FD still open and
passing it to crosvm with the `--tap-fd` argument.

None of these ways are very convenient for development as they either
require to get some privilege every time crosvm is invoked, or to use
another program (not distributed with crosvm) to do the setup.

This patch adds the `tap-name` command-line option which allows to
create a network device from a configured persistent TAP interface,
which doesn't require any kind of privilege.

A persistent TAP interface can be configured on the host as follows:

    # ip tuntap add mode tap user $USER vnet_hdr crosvm_tap
    # ip addr add 10.0.2.1/24 dev crosvm_tap
    # ip link set crosvm_tap up

Then after this one-time setup, $USER will be able to use the
`crosvm_tap` interface by simply passing `--tap-name crosvm_tap` to
crosvm, without any extra option or tool.

This is convenient for development setups as one just needs to
permanently configure the TAP interface using standard Linux tools on
the host once.

BUG=None
TEST=Check that networking works after passing `--tap-name` to crosvm.

Change-Id: Id053a97d69e47a6fefdbe7f3134841d2bfa1757b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3325827
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2021-12-10 07:31:03 +00:00
..
src crosvm: add option to use persistent TAP interface as network device 2021-12-10 07:31:03 +00:00
Cargo.toml Refactoring: Move various general purpose crates to common/ 2021-10-29 22:31:43 +00:00