]>
Commit | Line | Data |
---|---|---|
d8921c6d TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright (C) 2013 Tom Gundersen <teg@jklm.no> | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include <netinet/ether.h> | |
23 | ||
24 | #include "sd-rtnl.h" | |
25 | ||
26 | #include "rtnl-util.h" | |
27 | ||
28 | int rtnl_set_link_properties(sd_rtnl *rtnl, int ifindex, const char *name, const struct ether_addr *mac, unsigned mtu) { | |
29 | _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message; | |
30 | bool need_update = false; | |
31 | int r; | |
32 | ||
33 | assert(rtnl); | |
34 | assert(ifindex > 0); | |
35 | ||
36 | r = sd_rtnl_message_link_new(RTM_NEWLINK, ifindex, 0, 0, &message); | |
37 | if (r < 0) | |
38 | return r; | |
39 | ||
40 | if (name) { | |
41 | r = sd_rtnl_message_append(message, IFLA_IFNAME, name); | |
42 | if (r < 0) | |
43 | return r; | |
44 | ||
45 | need_update = true; | |
46 | } | |
47 | ||
48 | if (mac) { | |
49 | r = sd_rtnl_message_append(message, IFLA_ADDRESS, mac); | |
50 | if (r < 0) | |
51 | return r; | |
52 | ||
53 | need_update = true; | |
54 | } | |
55 | ||
56 | if (mtu > 0) { | |
57 | r = sd_rtnl_message_append(message, IFLA_MTU, &mtu); | |
58 | if (r < 0) | |
59 | return r; | |
60 | ||
61 | need_update = true; | |
62 | } | |
63 | ||
64 | if (need_update) { | |
65 | r = sd_rtnl_send_with_reply_and_block(rtnl, message, 0, NULL); | |
66 | if (r < 0) | |
67 | return r; | |
68 | } | |
69 | ||
70 | return 0; | |
71 | } |