diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2015-10-05 08:55:38 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-11-19 16:20:28 (GMT) |
commit | 3f231213c7c586b5a5e8ce6b1ea9c1d3b24d74c0 (patch) | |
tree | c617e155435b2d95abf27eb59070c105975fd242 /tests | |
parent | e6b39c9e2355febfe16555b738ccdcf945497245 (diff) | |
download | libnl-3f231213c7c586b5a5e8ce6b1ea9c1d3b24d74c0.zip libnl-3f231213c7c586b5a5e8ce6b1ea9c1d3b24d74c0.tar.gz libnl-3f231213c7c586b5a5e8ce6b1ea9c1d3b24d74c0.tar.bz2 |
route/link: add macvtap support
This adds support for MAC-VLAN based tap interfaces (macvtap).
http://lists.infradead.org/pipermail/libnl/2015-October/001976.html
Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/test-create-macvtap.c | 50 |
3 files changed, 52 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 0e6006c..d11450b 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -14,6 +14,7 @@ /test-create-ipvlan /test-create-ipvti /test-create-macvlan +/test-create-macvtap /test-create-sit /test-create-veth /test-create-vlan diff --git a/tests/Makefile.am b/tests/Makefile.am index 3a8256c..e764635 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,6 +35,7 @@ check_PROGRAMS = \ test-create-ipip \ test-create-ipvti \ test-create-macvlan \ + test-create-macvtap \ test-create-ipvlan \ test-create-vrf \ test-create-sit \ diff --git a/tests/test-create-macvtap.c b/tests/test-create-macvtap.c new file mode 100644 index 0000000..dc7df95 --- /dev/null +++ b/tests/test-create-macvtap.c @@ -0,0 +1,50 @@ +#include <netinet/ether.h> + +#include <netlink/netlink.h> +#include <netlink/route/link.h> +#include <netlink/route/link/macvtap.h> + +int main(int argc, char *argv[]) +{ + struct rtnl_link *link; + struct nl_cache *link_cache; + struct nl_sock *sk; + struct nl_addr* addr; + int err, master_index; + + sk = nl_socket_alloc(); + if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { + nl_perror(err, "Unable to connect socket"); + return err; + } + + if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) { + nl_perror(err, "Unable to allocate cache"); + return err; + } + + if (!(master_index = rtnl_link_name2i(link_cache, "eth0"))) { + fprintf(stderr, "Unable to lookup eth0"); + return -1; + } + + link = rtnl_link_macvtap_alloc(); + + rtnl_link_set_link(link, master_index); + + addr = nl_addr_build(AF_LLC, ether_aton("00:11:22:33:44:55"), ETH_ALEN); + rtnl_link_set_addr(link, addr); + nl_addr_put(addr); + + rtnl_link_macvtap_set_mode(link, rtnl_link_macvtap_str2mode("bridge")); + + if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { + nl_perror(err, "Unable to add link"); + return err; + } + + rtnl_link_put(link); + nl_close(sk); + + return 0; +} |