Home | History | Annotate | Download | only in tests
      1 #include <netlink/route/link/ip6tnl.h>
      2 #include <netlink-private/netlink.h>
      3 
      4 int main(int argc, char *argv[])
      5 {
      6 	struct nl_cache *link_cache;
      7 	struct rtnl_link *link;
      8         struct in6_addr addr;
      9 	struct nl_sock *sk;
     10 	int err, if_index;
     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 	err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache);
     19 	if ( err < 0) {
     20 		nl_perror(err, "Unable to allocate cache");
     21 		return err;
     22 	}
     23 
     24 	if_index = rtnl_link_name2i(link_cache, "ens33");
     25 	if (!if_index) {
     26 		fprintf(stderr, "Unable to lookup ens33");
     27 		return -1;
     28 	}
     29 
     30 	link = rtnl_link_ip6_tnl_alloc();
     31 	if(!link) {
     32 		nl_perror(err, "Unable to allocate link");
     33 		return -1;
     34 
     35 	}
     36 	rtnl_link_set_name(link, "ip6tnl-tun");
     37 	rtnl_link_ip6_tnl_set_link(link, if_index);
     38 
     39 	inet_pton(AF_INET6, "2607:f0d0:1002:51::4", &addr);
     40 	rtnl_link_ip6_tnl_set_local(link, &addr);
     41 
     42 	inet_pton(AF_INET6, "2607:f0d0:1002:52::5", &addr);
     43 	rtnl_link_ip6_tnl_set_remote(link, &addr);
     44 
     45 	err = rtnl_link_add(sk, link, NLM_F_CREATE);
     46 	if (err < 0) {
     47 		nl_perror(err, "Unable to add link");
     48 		return err;
     49 	}
     50 
     51 	rtnl_link_put(link);
     52 	nl_close(sk);
     53 
     54 	return 0;
     55 }
     56