oops
[libnl.git] / src / nl-qdisc-delete.c
1 /*
2  * src/nl-qdisc-delete.c     Delete Qdiscs
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("Usage: nl-qdisc-delete <ifindex> <parent> <handle>\n");
17         exit(1);
18 }
19
20 int main(int argc, char *argv[])
21 {
22         struct nl_handle *nlh;
23         struct rtnl_qdisc *qdisc;
24         uint32_t handle, parent;
25         int err = 1;
26
27         if (nltool_init(argc, argv) < 0)
28                 return -1;
29
30         if (argc < 3 || !strcmp(argv[1], "-h"))
31                 print_usage();
32
33         nlh = nl_handle_alloc_nondefault(nltool_cbset);
34         if (!nlh)
35                 goto errout;
36
37         qdisc = rtnl_qdisc_alloc();
38         if (!qdisc)
39                 goto errout_free_handle;
40
41         rtnl_qdisc_set_ifindex(qdisc, strtoul(argv[1], NULL, 0));
42
43         if (rtnl_tc_str2handle(argv[2], &parent) < 0) {
44                 fprintf(stderr, "%s\n", nl_geterror());
45                 goto errout_free_qdisc;
46         }
47
48         if (argc > 3) {
49                 if (rtnl_tc_str2handle(argv[3], &handle) < 0) {
50                         fprintf(stderr, "%s\n", nl_geterror());
51                         goto errout_free_qdisc;
52                 }
53
54                 rtnl_qdisc_set_handle(qdisc, handle);
55         }
56
57         rtnl_qdisc_set_parent(qdisc, parent);
58
59         if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
60                 goto errout_free_qdisc;
61
62         if (rtnl_qdisc_delete(nlh, qdisc) < 0) {
63                 fprintf(stderr, "Unable to delete Qdisc: %s\n", nl_geterror());
64                 goto errout_close;
65         }
66
67         err = 0;
68 errout_close:
69         nl_close(nlh);
70 errout_free_qdisc:
71         rtnl_qdisc_put(qdisc);
72 errout_free_handle:
73         nl_handle_destroy(nlh);
74 errout:
75         return err;
76 }