1 #include <netlink/netlink.h>
2 #include <netlink/route/link.h>
3 #include <netlink/route/link/vxlan.h>
4
main(int argc,char * argv[])5 int main(int argc, char *argv[])
6 {
7 struct rtnl_link *link;
8 struct nl_addr *addr;
9 struct nl_sock *sk;
10 int err;
11
12 sk = nl_socket_alloc();
13 if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
14 nl_perror(err, "Unable to connect socket");
15 return err;
16 }
17
18 link = rtnl_link_vxlan_alloc();
19
20 rtnl_link_set_name(link, "vxlan128");
21
22 if ((err = rtnl_link_vxlan_set_id(link, 128)) < 0) {
23 nl_perror(err, "Unable to set VXLAN network identifier");
24 return err;
25 }
26
27 if ((err = nl_addr_parse("239.0.0.1", AF_INET, &addr)) < 0) {
28 nl_perror(err, "Unable to parse IP address");
29 return err;
30 }
31
32 if ((err = rtnl_link_vxlan_set_group(link, addr)) < 0) {
33 nl_perror(err, "Unable to set multicast IP address");
34 return err;
35 }
36 nl_addr_put(addr);
37
38 if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) {
39 nl_perror(err, "Unable to add link");
40 return err;
41 }
42
43 rtnl_link_put(link);
44 nl_close(sk);
45
46 return 0;
47 }
48