blob: 297160c490fdb1e463b1cb472605d6b175ec3640 [file] [log] [blame]
Jiri Pirko28d84b42014-09-28 16:33:29 -07001/*
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
20static 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"
Nikolay Aleksandrov6c99fb62015-06-16 13:38:47 +030026 " [ ageing_time AGEING_TIME ]\n"
Nikolay Aleksandrovdab04962015-06-16 13:38:48 +030027 " [ stp_state STP_STATE ]\n"
Nikolay Aleksandrovb0197a02015-06-16 13:38:49 +030028 " [ priority PRIORITY ]\n"
Jiri Pirko28d84b42014-09-28 16:33:29 -070029 );
30}
31
32static int bridge_parse_opt(struct link_util *lu, int argc, char **argv,
33 struct nlmsghdr *n)
34{
35 __u32 val;
36
37 while (argc > 0) {
38 if (matches(*argv, "forward_delay") == 0) {
39 NEXT_ARG();
40 if (get_u32(&val, *argv, 0)) {
41 invarg("invalid forward_delay", *argv);
42 return -1;
43 }
44 addattr32(n, 1024, IFLA_BR_FORWARD_DELAY, val);
45 } else if (matches(*argv, "hello_time") == 0) {
46 NEXT_ARG();
47 if (get_u32(&val, *argv, 0)) {
48 invarg("invalid hello_time", *argv);
49 return -1;
50 }
51 addattr32(n, 1024, IFLA_BR_HELLO_TIME, val);
52 } else if (matches(*argv, "max_age") == 0) {
53 NEXT_ARG();
54 if (get_u32(&val, *argv, 0)) {
55 invarg("invalid max_age", *argv);
56 return -1;
57 }
58 addattr32(n, 1024, IFLA_BR_MAX_AGE, val);
Nikolay Aleksandrov6c99fb62015-06-16 13:38:47 +030059 } else if (matches(*argv, "ageing_time") == 0) {
60 NEXT_ARG();
61 if (get_u32(&val, *argv, 0)) {
62 invarg("invalid ageing_time", *argv);
63 return -1;
64 }
65 addattr32(n, 1024, IFLA_BR_AGEING_TIME, val);
Nikolay Aleksandrovdab04962015-06-16 13:38:48 +030066 } else if (matches(*argv, "stp_state") == 0) {
67 NEXT_ARG();
68 if (get_u32(&val, *argv, 0)) {
69 invarg("invalid stp_state", *argv);
70 return -1;
71 }
72 addattr32(n, 1024, IFLA_BR_STP_STATE, val);
Nikolay Aleksandrovb0197a02015-06-16 13:38:49 +030073 } else if (matches(*argv, "priority") == 0) {
74 __u16 prio;
75
76 NEXT_ARG();
77 if (get_u16(&prio, *argv, 0)) {
78 invarg("invalid priority", *argv);
79 return -1;
80 }
81 addattr16(n, 1024, IFLA_BR_PRIORITY, prio);
Jiri Pirko28d84b42014-09-28 16:33:29 -070082 } else if (matches(*argv, "help") == 0) {
83 explain();
84 return -1;
85 } else {
86 fprintf(stderr, "bridge: unknown command \"%s\"?\n", *argv);
87 explain();
88 return -1;
89 }
90 argc--, argv++;
91 }
92
93 return 0;
94}
95
96static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
97{
98 if (!tb)
99 return;
100
101 if (tb[IFLA_BR_FORWARD_DELAY])
102 fprintf(f, "forward_delay %u ",
103 rta_getattr_u32(tb[IFLA_BR_FORWARD_DELAY]));
104
105 if (tb[IFLA_BR_HELLO_TIME])
106 fprintf(f, "hello_time %u ",
107 rta_getattr_u32(tb[IFLA_BR_HELLO_TIME]));
108
109 if (tb[IFLA_BR_MAX_AGE])
110 fprintf(f, "max_age %u ",
111 rta_getattr_u32(tb[IFLA_BR_MAX_AGE]));
112}
113
114struct link_util bridge_link_util = {
115 .id = "bridge",
116 .maxattr = IFLA_BR_MAX,
117 .parse_opt = bridge_parse_opt,
118 .print_opt = bridge_print_opt,
119};