This commit was generated by cvs2svn to compensate for changes in r786,
[libnl.git] / src / nl-link-set.c
1 /*
2  * src/nl-link-set.c     Set link attributes
3  *
4  *      This library is free software; you can redistribute it and/or
5  *      modify it under the terms of the GNU Lesser General Public
6  *      License as published by the Free Software Foundation version 2.1
7  *      of the License.
8  *
9  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10  */
11
12 #include "utils.h"
13
14 static void print_usage(void)
15 {
16         printf(
17         "Usage: nl-link-set <ifindex> <changes>\n"
18         "  changes := [dev DEV] [mtu MTU] [txqlen TXQLEN] [weight WEIGHT] [link LINK]\n"
19         "             [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n"
20         "             [{ up | down }] [{ arp | noarp }] [{ promisc | nopromisc }]\n"
21         "             [{ dynamic | nodynamic }] [{ multicast | nomulticast }]\n"
22         "             [{ trailers | notrailers }] [{ allmulticast | noallmulticast }]\n");
23         exit(1);
24 }
25
26 #include "f_link.c"
27
28 int main(int argc, char *argv[])
29 {
30         struct nl_handle *nlh;
31         struct nl_cache *link_cache;
32         struct rtnl_link *link, *orig;
33         int err = 1, ifindex;
34
35         if (nltool_init(argc, argv) < 0)
36                 return -1;
37
38         if (argc < 2 || !strcmp(argv[1], "-h"))
39                 print_usage();
40
41         nlh = nl_handle_alloc_nondefault(nltool_cbset);
42         if (!nlh)
43                 return -1;
44
45         link = rtnl_link_alloc();
46         if (!link)
47                 goto errout;
48
49         if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
50                 goto errout_free;
51
52         link_cache = nltool_alloc_link_cache(nlh);
53         if (!link_cache)
54                 goto errout_close;
55
56         ifindex = strtoul(argv[1], NULL, 0);
57
58         if (!(orig = rtnl_link_get(link_cache, ifindex))) {
59                 fprintf(stderr, "Interface index %d does not exist\n", ifindex);
60                 goto errout_cache;
61         }
62
63         get_filter(link, argc, argv, 2, link_cache);
64
65         if (rtnl_link_change(nlh, orig, link, 0) < 0) {
66                 fprintf(stderr, "Unable to change link: %s\n", nl_geterror());
67                 goto errout_put;
68         }
69
70         err = 0;
71
72 errout_put:
73         rtnl_link_put(orig);
74 errout_cache:
75         nl_cache_free(link_cache);
76 errout_close:
77         nl_close(nlh);
78 errout_free:
79         rtnl_link_put(link);
80 errout:
81         nl_handle_destroy(nlh);
82         return err;
83 }