]>
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" |
cf0fbc49 | 25 | #include "networkd-netdev-bridge.h" |
540eb5f0 SS |
26 | |
27 | /* callback for brige netdev's parameter set */ | |
28 | static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { | |
29 | _cleanup_netdev_unref_ NetDev *netdev = userdata; | |
30 | int r; | |
31 | ||
32 | assert(netdev); | |
33 | assert(m); | |
34 | ||
35 | r = sd_netlink_message_get_errno(m); | |
36 | if (r < 0) { | |
37 | log_netdev_warning_errno(netdev, r, "Bridge parameters could not be set: %m"); | |
38 | return 1; | |
39 | } | |
40 | ||
41 | log_netdev_debug(netdev, "Bridge parametres set success"); | |
42 | ||
43 | return 1; | |
44 | } | |
45 | ||
46 | static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_message *m) { | |
4afd3348 | 47 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; |
540eb5f0 SS |
48 | Bridge *b; |
49 | int r; | |
50 | ||
51 | assert(netdev); | |
52 | ||
53 | b = BRIDGE(netdev); | |
54 | ||
55 | assert(b); | |
56 | ||
57 | r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, netdev->ifindex); | |
58 | if (r < 0) | |
59 | return log_netdev_error_errno(netdev, r, "Could not allocate RTM_SETLINK message: %m"); | |
60 | ||
61 | r = sd_netlink_message_set_flags(req, NLM_F_REQUEST | NLM_F_ACK); | |
62 | if (r < 0) | |
63 | return log_link_error_errno(link, r, "Could not set netlink flags: %m"); | |
64 | ||
65 | r = sd_netlink_message_open_container(req, IFLA_LINKINFO); | |
66 | if (r < 0) | |
67 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_PROTINFO attribute: %m"); | |
68 | ||
69 | r = sd_netlink_message_open_container_union(req, IFLA_INFO_DATA, netdev_kind_to_string(netdev->kind)); | |
70 | if (r < 0) | |
71 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); | |
72 | ||
1a14863e | 73 | /* convert to jiffes */ |
540eb5f0 | 74 | if (b->forward_delay > 0) { |
1a14863e | 75 | r = sd_netlink_message_append_u32(req, IFLA_BR_FORWARD_DELAY, usec_to_jiffies(b->forward_delay)); |
540eb5f0 SS |
76 | if (r < 0) |
77 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_FORWARD_DELAY attribute: %m"); | |
78 | } | |
79 | ||
80 | if (b->hello_time > 0) { | |
1a14863e | 81 | r = sd_netlink_message_append_u32(req, IFLA_BR_HELLO_TIME, usec_to_jiffies(b->hello_time)); |
540eb5f0 SS |
82 | if (r < 0) |
83 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_HELLO_TIME attribute: %m"); | |
84 | } | |
85 | ||
86 | if (b->max_age > 0) { | |
1a14863e | 87 | r = sd_netlink_message_append_u32(req, IFLA_BR_MAX_AGE, usec_to_jiffies(b->max_age)); |
540eb5f0 SS |
88 | if (r < 0) |
89 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_MAX_AGE attribute: %m"); | |
90 | } | |
91 | ||
92 | r = sd_netlink_message_close_container(req); | |
93 | if (r < 0) | |
94 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); | |
95 | ||
96 | r = sd_netlink_message_close_container(req); | |
97 | if (r < 0) | |
98 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); | |
99 | ||
100 | r = sd_netlink_call_async(netdev->manager->rtnl, req, netdev_bridge_set_handler, netdev, 0, NULL); | |
101 | if (r < 0) | |
102 | return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); | |
103 | ||
104 | netdev_ref(netdev); | |
105 | ||
106 | return r; | |
107 | } | |
6235b3de | 108 | |
3be1d7e0 | 109 | const NetDevVTable bridge_vtable = { |
aa9f1140 | 110 | .object_size = sizeof(Bridge), |
540eb5f0 SS |
111 | .sections = "Match\0NetDev\0Bridge\0", |
112 | .post_create = netdev_bridge_post_create, | |
aa9f1140 | 113 | .create_type = NETDEV_CREATE_MASTER, |
3be1d7e0 | 114 | }; |