]>
Commit | Line | Data |
---|---|---|
6235b3de TG |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2014 Tom Gundersen <teg@jklm.no> | |
5 | Copyright 2014 Susant Sahani | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
540eb5f0 | 21 | #include <net/if.h> |
6235b3de | 22 | |
6235b3de | 23 | #include "missing.h" |
540eb5f0 | 24 | #include "netlink-util.h" |
634f0f98 | 25 | #include "networkd.h" |
cf0fbc49 | 26 | #include "networkd-netdev-bridge.h" |
540eb5f0 SS |
27 | |
28 | /* callback for brige netdev's parameter set */ | |
29 | static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { | |
30 | _cleanup_netdev_unref_ NetDev *netdev = userdata; | |
31 | int r; | |
32 | ||
33 | assert(netdev); | |
34 | assert(m); | |
35 | ||
36 | r = sd_netlink_message_get_errno(m); | |
37 | if (r < 0) { | |
38 | log_netdev_warning_errno(netdev, r, "Bridge parameters could not be set: %m"); | |
39 | return 1; | |
40 | } | |
41 | ||
42 | log_netdev_debug(netdev, "Bridge parametres set success"); | |
43 | ||
44 | return 1; | |
45 | } | |
46 | ||
47 | static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_message *m) { | |
4afd3348 | 48 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; |
540eb5f0 SS |
49 | Bridge *b; |
50 | int r; | |
51 | ||
52 | assert(netdev); | |
53 | ||
54 | b = BRIDGE(netdev); | |
55 | ||
56 | assert(b); | |
57 | ||
58 | r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, netdev->ifindex); | |
59 | if (r < 0) | |
60 | return log_netdev_error_errno(netdev, r, "Could not allocate RTM_SETLINK message: %m"); | |
61 | ||
62 | r = sd_netlink_message_set_flags(req, NLM_F_REQUEST | NLM_F_ACK); | |
63 | if (r < 0) | |
64 | return log_link_error_errno(link, r, "Could not set netlink flags: %m"); | |
65 | ||
66 | r = sd_netlink_message_open_container(req, IFLA_LINKINFO); | |
67 | if (r < 0) | |
68 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_PROTINFO attribute: %m"); | |
69 | ||
70 | r = sd_netlink_message_open_container_union(req, IFLA_INFO_DATA, netdev_kind_to_string(netdev->kind)); | |
71 | if (r < 0) | |
72 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); | |
73 | ||
1a14863e | 74 | /* convert to jiffes */ |
540eb5f0 | 75 | if (b->forward_delay > 0) { |
1a14863e | 76 | r = sd_netlink_message_append_u32(req, IFLA_BR_FORWARD_DELAY, usec_to_jiffies(b->forward_delay)); |
540eb5f0 SS |
77 | if (r < 0) |
78 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_FORWARD_DELAY attribute: %m"); | |
79 | } | |
80 | ||
81 | if (b->hello_time > 0) { | |
1a14863e | 82 | r = sd_netlink_message_append_u32(req, IFLA_BR_HELLO_TIME, usec_to_jiffies(b->hello_time)); |
540eb5f0 SS |
83 | if (r < 0) |
84 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_HELLO_TIME attribute: %m"); | |
85 | } | |
86 | ||
87 | if (b->max_age > 0) { | |
1a14863e | 88 | r = sd_netlink_message_append_u32(req, IFLA_BR_MAX_AGE, usec_to_jiffies(b->max_age)); |
540eb5f0 SS |
89 | if (r < 0) |
90 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_MAX_AGE attribute: %m"); | |
91 | } | |
92 | ||
3fef7a3f SS |
93 | if (b->mcast_querier >= 0) { |
94 | r = sd_netlink_message_append_u8(req, IFLA_BR_MCAST_QUERIER, b->mcast_querier); | |
95 | if (r < 0) | |
96 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_MCAST_QUERIER attribute: %m"); | |
97 | } | |
98 | ||
540eb5f0 SS |
99 | r = sd_netlink_message_close_container(req); |
100 | if (r < 0) | |
101 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); | |
102 | ||
103 | r = sd_netlink_message_close_container(req); | |
104 | if (r < 0) | |
105 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); | |
106 | ||
107 | r = sd_netlink_call_async(netdev->manager->rtnl, req, netdev_bridge_set_handler, netdev, 0, NULL); | |
108 | if (r < 0) | |
109 | return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); | |
110 | ||
111 | netdev_ref(netdev); | |
112 | ||
113 | return r; | |
114 | } | |
6235b3de | 115 | |
3fef7a3f SS |
116 | static void bridge_init(NetDev *n) { |
117 | Bridge *b; | |
118 | ||
119 | b = BRIDGE(n); | |
120 | ||
121 | assert(b); | |
122 | ||
123 | b->mcast_querier = -1; | |
124 | } | |
125 | ||
3be1d7e0 | 126 | const NetDevVTable bridge_vtable = { |
aa9f1140 | 127 | .object_size = sizeof(Bridge), |
3fef7a3f | 128 | .init = bridge_init, |
540eb5f0 SS |
129 | .sections = "Match\0NetDev\0Bridge\0", |
130 | .post_create = netdev_bridge_post_create, | |
aa9f1140 | 131 | .create_type = NETDEV_CREATE_MASTER, |
3be1d7e0 | 132 | }; |