1 #include <netlink/netlink.h>
2 #include <netlink/route/link.h>
3
4 #include <linux/netlink.h>
5 #include <linux/if_link.h>
6
7 #include <netlink/route/link/macsec.h>
8
main(int argc,char * argv[])9 int main(int argc, char *argv[])
10 {
11 struct rtnl_link *link;
12 struct nl_cache *link_cache;
13 struct nl_sock *sk;
14 int err, master_index;
15
16 sk = nl_socket_alloc();
17 if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
18 nl_perror(err, "Unable to connect socket");
19 return err;
20 }
21
22 if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) {
23 nl_perror(err, "Unable to allocate cache");
24 return err;
25 }
26
27 if (!(master_index = rtnl_link_name2i(link_cache, "eth0"))) {
28 fprintf(stderr, "Unable to lookup eth0");
29 return -1;
30 }
31
32
33 link = rtnl_link_macsec_alloc();
34
35 rtnl_link_set_link(link, master_index);
36
37 rtnl_link_macsec_set_port(link, 10);
38 rtnl_link_macsec_set_encrypt(link, 1);
39 rtnl_link_macsec_set_replay_protect(link, 1);
40 rtnl_link_macsec_set_window(link, 200);
41
42 if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) {
43 nl_perror(err, "Unable to add link");
44 return err;
45 }
46
47 rtnl_link_put(link);
48 nl_close(sk);
49
50 return 0;
51 }
52