]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/iplink_bridge.c
Merge branch 'net-next'
[mirror_iproute2.git] / ip / iplink_bridge.c
1 /*
2 * iplink_bridge.c Bridge device support
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Jiri Pirko <jiri@resnulli.us>
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <linux/if_link.h>
16
17 #include "utils.h"
18 #include "ip_common.h"
19
20 static void explain(void)
21 {
22 fprintf(stderr,
23 "Usage: ... bridge [ forward_delay FORWARD_DELAY ]\n"
24 " [ hello_time HELLO_TIME ]\n"
25 " [ max_age MAX_AGE ]\n"
26 );
27 }
28
29 static int bridge_parse_opt(struct link_util *lu, int argc, char **argv,
30 struct nlmsghdr *n)
31 {
32 __u32 val;
33
34 while (argc > 0) {
35 if (matches(*argv, "forward_delay") == 0) {
36 NEXT_ARG();
37 if (get_u32(&val, *argv, 0)) {
38 invarg("invalid forward_delay", *argv);
39 return -1;
40 }
41 addattr32(n, 1024, IFLA_BR_FORWARD_DELAY, val);
42 } else if (matches(*argv, "hello_time") == 0) {
43 NEXT_ARG();
44 if (get_u32(&val, *argv, 0)) {
45 invarg("invalid hello_time", *argv);
46 return -1;
47 }
48 addattr32(n, 1024, IFLA_BR_HELLO_TIME, val);
49 } else if (matches(*argv, "max_age") == 0) {
50 NEXT_ARG();
51 if (get_u32(&val, *argv, 0)) {
52 invarg("invalid max_age", *argv);
53 return -1;
54 }
55 addattr32(n, 1024, IFLA_BR_MAX_AGE, val);
56 } else if (matches(*argv, "help") == 0) {
57 explain();
58 return -1;
59 } else {
60 fprintf(stderr, "bridge: unknown command \"%s\"?\n", *argv);
61 explain();
62 return -1;
63 }
64 argc--, argv++;
65 }
66
67 return 0;
68 }
69
70 static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
71 {
72 if (!tb)
73 return;
74
75 if (tb[IFLA_BR_FORWARD_DELAY])
76 fprintf(f, "forward_delay %u ",
77 rta_getattr_u32(tb[IFLA_BR_FORWARD_DELAY]));
78
79 if (tb[IFLA_BR_HELLO_TIME])
80 fprintf(f, "hello_time %u ",
81 rta_getattr_u32(tb[IFLA_BR_HELLO_TIME]));
82
83 if (tb[IFLA_BR_MAX_AGE])
84 fprintf(f, "max_age %u ",
85 rta_getattr_u32(tb[IFLA_BR_MAX_AGE]));
86 }
87
88 struct link_util bridge_link_util = {
89 .id = "bridge",
90 .maxattr = IFLA_BR_MAX,
91 .parse_opt = bridge_parse_opt,
92 .print_opt = bridge_print_opt,
93 };