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