Home | History | Annotate | Download | only in tests
      1 #include <netlink/route/link/ipvti.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 in_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_ipvti_alloc();
     31 	if(!link) {
     32 		nl_perror(err, "Unable to allocate link");
     33 		return -1;
     34 
     35 	}
     36 	rtnl_link_set_name(link, "ipvti-tun");
     37 	rtnl_link_ipvti_set_link(link, if_index);
     38 
     39 	inet_pton(AF_INET, "192.168.254.12", &addr.s_addr);
     40 	rtnl_link_ipvti_set_local(link, addr.s_addr);
     41 
     42 	inet_pton(AF_INET, "192.168.254.13", &addr.s_addr);
     43 	rtnl_link_ipvti_set_remote(link, addr.s_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