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