Home | History | Annotate | Download | only in tests
      1 #include <netlink/route/link/ipip.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, "eno16777736");
     25 	if (!if_index) {
     26 		fprintf(stderr, "Unable to lookup eno16777736");
     27 		return -1;
     28 	}
     29 
     30 	link = rtnl_link_ipip_alloc();
     31 	if(!link) {
     32 		nl_perror(err, "Unable to allocate link");
     33 		return -1;
     34 	}
     35 
     36 	rtnl_link_set_name(link, "ipip-tun");
     37 	rtnl_link_ipip_set_link(link, if_index);
     38 
     39 	inet_pton(AF_INET, "192.168.254.12", &addr.s_addr);
     40 	rtnl_link_ipip_set_local(link, addr.s_addr);
     41 
     42 	inet_pton(AF_INET, "192.168.254.13", &addr.s_addr);
     43 	rtnl_link_ipip_set_remote(link, addr.s_addr);
     44 
     45 	rtnl_link_ipip_set_ttl(link, 64);
     46 	err = rtnl_link_add(sk, link, NLM_F_CREATE);
     47 	if (err < 0) {
     48 		nl_perror(err, "Unable to add link");
     49 		return err;
     50 	}
     51 
     52 	rtnl_link_put(link);
     53 	nl_close(sk);
     54 
     55 	return 0;
     56 }
     57