Jiri Pirko | 28d84b4 | 2014-09-28 16:33:29 -0700 | [diff] [blame] | 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 | |
Zhang Shengju | 43367ef | 2015-08-12 06:03:23 +0000 | [diff] [blame^] | 20 | static void print_explain(FILE *f) |
Jiri Pirko | 28d84b4 | 2014-09-28 16:33:29 -0700 | [diff] [blame] | 21 | { |
Zhang Shengju | 43367ef | 2015-08-12 06:03:23 +0000 | [diff] [blame^] | 22 | fprintf(f, |
Jiri Pirko | 28d84b4 | 2014-09-28 16:33:29 -0700 | [diff] [blame] | 23 | "Usage: ... bridge [ forward_delay FORWARD_DELAY ]\n" |
| 24 | " [ hello_time HELLO_TIME ]\n" |
| 25 | " [ max_age MAX_AGE ]\n" |
Nikolay Aleksandrov | 6c99fb6 | 2015-06-16 13:38:47 +0300 | [diff] [blame] | 26 | " [ ageing_time AGEING_TIME ]\n" |
Nikolay Aleksandrov | dab0496 | 2015-06-16 13:38:48 +0300 | [diff] [blame] | 27 | " [ stp_state STP_STATE ]\n" |
Nikolay Aleksandrov | b0197a0 | 2015-06-16 13:38:49 +0300 | [diff] [blame] | 28 | " [ priority PRIORITY ]\n" |
Jiri Pirko | 28d84b4 | 2014-09-28 16:33:29 -0700 | [diff] [blame] | 29 | ); |
| 30 | } |
| 31 | |
Zhang Shengju | 43367ef | 2015-08-12 06:03:23 +0000 | [diff] [blame^] | 32 | static void explain(void) |
| 33 | { |
| 34 | print_explain(stderr); |
| 35 | } |
| 36 | |
Jiri Pirko | 28d84b4 | 2014-09-28 16:33:29 -0700 | [diff] [blame] | 37 | static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, |
| 38 | struct nlmsghdr *n) |
| 39 | { |
| 40 | __u32 val; |
| 41 | |
| 42 | while (argc > 0) { |
| 43 | if (matches(*argv, "forward_delay") == 0) { |
| 44 | NEXT_ARG(); |
| 45 | if (get_u32(&val, *argv, 0)) { |
| 46 | invarg("invalid forward_delay", *argv); |
| 47 | return -1; |
| 48 | } |
| 49 | addattr32(n, 1024, IFLA_BR_FORWARD_DELAY, val); |
| 50 | } else if (matches(*argv, "hello_time") == 0) { |
| 51 | NEXT_ARG(); |
| 52 | if (get_u32(&val, *argv, 0)) { |
| 53 | invarg("invalid hello_time", *argv); |
| 54 | return -1; |
| 55 | } |
| 56 | addattr32(n, 1024, IFLA_BR_HELLO_TIME, val); |
| 57 | } else if (matches(*argv, "max_age") == 0) { |
| 58 | NEXT_ARG(); |
| 59 | if (get_u32(&val, *argv, 0)) { |
| 60 | invarg("invalid max_age", *argv); |
| 61 | return -1; |
| 62 | } |
| 63 | addattr32(n, 1024, IFLA_BR_MAX_AGE, val); |
Nikolay Aleksandrov | 6c99fb6 | 2015-06-16 13:38:47 +0300 | [diff] [blame] | 64 | } else if (matches(*argv, "ageing_time") == 0) { |
| 65 | NEXT_ARG(); |
| 66 | if (get_u32(&val, *argv, 0)) { |
| 67 | invarg("invalid ageing_time", *argv); |
| 68 | return -1; |
| 69 | } |
| 70 | addattr32(n, 1024, IFLA_BR_AGEING_TIME, val); |
Nikolay Aleksandrov | dab0496 | 2015-06-16 13:38:48 +0300 | [diff] [blame] | 71 | } else if (matches(*argv, "stp_state") == 0) { |
| 72 | NEXT_ARG(); |
| 73 | if (get_u32(&val, *argv, 0)) { |
| 74 | invarg("invalid stp_state", *argv); |
| 75 | return -1; |
| 76 | } |
| 77 | addattr32(n, 1024, IFLA_BR_STP_STATE, val); |
Nikolay Aleksandrov | b0197a0 | 2015-06-16 13:38:49 +0300 | [diff] [blame] | 78 | } else if (matches(*argv, "priority") == 0) { |
| 79 | __u16 prio; |
| 80 | |
| 81 | NEXT_ARG(); |
| 82 | if (get_u16(&prio, *argv, 0)) { |
| 83 | invarg("invalid priority", *argv); |
| 84 | return -1; |
| 85 | } |
| 86 | addattr16(n, 1024, IFLA_BR_PRIORITY, prio); |
Jiri Pirko | 28d84b4 | 2014-09-28 16:33:29 -0700 | [diff] [blame] | 87 | } else if (matches(*argv, "help") == 0) { |
| 88 | explain(); |
| 89 | return -1; |
| 90 | } else { |
| 91 | fprintf(stderr, "bridge: unknown command \"%s\"?\n", *argv); |
| 92 | explain(); |
| 93 | return -1; |
| 94 | } |
| 95 | argc--, argv++; |
| 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) |
| 102 | { |
| 103 | if (!tb) |
| 104 | return; |
| 105 | |
| 106 | if (tb[IFLA_BR_FORWARD_DELAY]) |
| 107 | fprintf(f, "forward_delay %u ", |
| 108 | rta_getattr_u32(tb[IFLA_BR_FORWARD_DELAY])); |
| 109 | |
| 110 | if (tb[IFLA_BR_HELLO_TIME]) |
| 111 | fprintf(f, "hello_time %u ", |
| 112 | rta_getattr_u32(tb[IFLA_BR_HELLO_TIME])); |
| 113 | |
| 114 | if (tb[IFLA_BR_MAX_AGE]) |
| 115 | fprintf(f, "max_age %u ", |
| 116 | rta_getattr_u32(tb[IFLA_BR_MAX_AGE])); |
| 117 | } |
| 118 | |
Zhang Shengju | 43367ef | 2015-08-12 06:03:23 +0000 | [diff] [blame^] | 119 | static void bridge_print_help(struct link_util *lu, int argc, char **argv, |
| 120 | FILE *f) |
| 121 | { |
| 122 | print_explain(f); |
| 123 | } |
| 124 | |
Jiri Pirko | 28d84b4 | 2014-09-28 16:33:29 -0700 | [diff] [blame] | 125 | struct link_util bridge_link_util = { |
| 126 | .id = "bridge", |
| 127 | .maxattr = IFLA_BR_MAX, |
| 128 | .parse_opt = bridge_parse_opt, |
| 129 | .print_opt = bridge_print_opt, |
Zhang Shengju | 43367ef | 2015-08-12 06:03:23 +0000 | [diff] [blame^] | 130 | .print_help = bridge_print_help, |
Jiri Pirko | 28d84b4 | 2014-09-28 16:33:29 -0700 | [diff] [blame] | 131 | }; |