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