chiark / gitweb /
networkd: fix colud typo
[elogind.git] / src / network / networkd-netdev-bond.c
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
23 #include <netinet/ether.h>
24 #include <arpa/inet.h>
25 #include <linux/if_bonding.h>
26
27 #include "conf-parser.h"
28 #include "sd-rtnl.h"
29 #include "networkd-netdev-bond.h"
30 #include "missing.h"
31
32 static const char* const bond_mode_table[_NETDEV_BOND_MODE_MAX] = {
33         [NETDEV_BOND_MODE_BALANCE_RR] = "balance-rr",
34         [NETDEV_BOND_MODE_ACTIVE_BACKUP] = "active-backup",
35         [NETDEV_BOND_MODE_BALANCE_XOR] = "balance-xor",
36         [NETDEV_BOND_MODE_BROADCAST] = "broadcast",
37         [NETDEV_BOND_MODE_802_3AD] = "802.3ad",
38         [NETDEV_BOND_MODE_BALANCE_TLB] = "balance-tlb",
39         [NETDEV_BOND_MODE_BALANCE_ALB] = "balance-alb",
40 };
41
42 DEFINE_STRING_TABLE_LOOKUP(bond_mode, BondMode);
43 DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_mode, bond_mode, BondMode, "Failed to parse bond mode");
44
45 static uint8_t bond_mode_to_kernel(BondMode mode) {
46         switch (mode) {
47         case NETDEV_BOND_MODE_BALANCE_RR:
48                 return BOND_MODE_ROUNDROBIN;
49         case NETDEV_BOND_MODE_ACTIVE_BACKUP:
50                 return BOND_MODE_ACTIVEBACKUP;
51         case NETDEV_BOND_MODE_BALANCE_XOR:
52                 return BOND_MODE_XOR;
53         case NETDEV_BOND_MODE_BROADCAST:
54                 return BOND_MODE_BROADCAST;
55         case NETDEV_BOND_MODE_802_3AD:
56                 return BOND_MODE_8023AD;
57         case NETDEV_BOND_MODE_BALANCE_TLB:
58                 return BOND_MODE_TLB;
59         case NETDEV_BOND_MODE_BALANCE_ALB:
60                 return BOND_MODE_ALB;
61         default:
62                 return (uint8_t) -1;
63         }
64 }
65
66 static int netdev_bond_fill_message_create(NetDev *netdev, sd_rtnl_message *m) {
67         int r;
68
69         assert(m);
70
71         r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
72         if (r < 0) {
73                 log_error_netdev(netdev,
74                                  "Could not append IFLA_IFNAME, attribute: %s",
75                                  strerror(-r));
76                 return r;
77         }
78
79         if (netdev->mac) {
80                 r = sd_rtnl_message_append_ether_addr(m, IFLA_ADDRESS, netdev->mac);
81                 if (r < 0) {
82                         log_error_netdev(netdev,
83                                          "Could not append IFLA_ADDRESS attribute: %s",
84                                          strerror(-r));
85                     return r;
86                 }
87         }
88
89         r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
90         if (r < 0) {
91                 log_error_netdev(netdev,
92                                  "Could not append IFLA_LINKINFO attribute: %s",
93                                  strerror(-r));
94                 return r;
95         }
96
97         r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA,
98                                                  netdev_kind_to_string(netdev->kind));
99         if (r < 0) {
100                 log_error_netdev(netdev,
101                                  "Could not append IFLA_INFO_DATA attribute: %s",
102                                  strerror(-r));
103                 return r;
104         }
105
106         if (netdev->bond_mode != _NETDEV_BOND_MODE_INVALID) {
107                 r = sd_rtnl_message_append_u8(m, IFLA_BOND_MODE,
108                                               bond_mode_to_kernel(netdev->bond_mode));
109                 if (r < 0) {
110                         log_error_netdev(netdev,
111                                          "Could not append IFLA_BOND_MODE attribute: %s",
112                                          strerror(-r));
113                         return r;
114                 }
115         }
116
117         r = sd_rtnl_message_close_container(m);
118         if (r < 0) {
119                 log_error_netdev(netdev,
120                                  "Could not append IFLA_LINKINFO attribute: %s",
121                                  strerror(-r));
122                 return r;
123         }
124
125         r = sd_rtnl_message_close_container(m);
126         if (r < 0) {
127                 log_error_netdev(netdev,
128                                  "Could not append IFLA_LINKINFO attribute: %s",
129                                  strerror(-r));
130                 return r;
131         }
132
133         return r;
134 }
135
136 const NetDevVTable bond_vtable = {
137         .fill_message_create = netdev_bond_fill_message_create,
138         .enslave = netdev_enslave,
139 };