blob: 0d8f1b2ed7b8b3137ae61b1bd56b5152abb7bf3a [file] [log] [blame]
Arvid Brodin70ebe4a2014-07-04 23:34:38 +02001/* Copyright 2011-2014 Autronica Fire and Security AS
Arvid Brodinf4214362013-10-30 21:10:47 +01002 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s):
Arvid Brodin70ebe4a2014-07-04 23:34:38 +02009 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
Arvid Brodinf4214362013-10-30 21:10:47 +010010 *
11 * Routines for handling Netlink messages for HSR.
12 */
13
14#include "hsr_netlink.h"
15#include <linux/kernel.h>
16#include <net/rtnetlink.h>
17#include <net/genetlink.h>
18#include "hsr_main.h"
19#include "hsr_device.h"
20#include "hsr_framereg.h"
21
22static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = {
23 [IFLA_HSR_SLAVE1] = { .type = NLA_U32 },
24 [IFLA_HSR_SLAVE2] = { .type = NLA_U32 },
25 [IFLA_HSR_MULTICAST_SPEC] = { .type = NLA_U8 },
Peter Heiseee1c2792016-04-13 13:52:22 +020026 [IFLA_HSR_VERSION] = { .type = NLA_U8 },
Peter Heisef9375722016-04-19 13:34:28 +020027 [IFLA_HSR_SUPERVISION_ADDR] = { .len = ETH_ALEN },
Arvid Brodin98bf8362013-11-29 23:38:16 +010028 [IFLA_HSR_SEQ_NR] = { .type = NLA_U16 },
Arvid Brodinf4214362013-10-30 21:10:47 +010029};
30
31
32/* Here, it seems a netdevice has already been allocated for us, and the
33 * hsr_dev_setup routine has been executed. Nice!
34 */
35static int hsr_newlink(struct net *src_net, struct net_device *dev,
36 struct nlattr *tb[], struct nlattr *data[])
37{
38 struct net_device *link[2];
Peter Heiseee1c2792016-04-13 13:52:22 +020039 unsigned char multicast_spec, hsr_version;
Arvid Brodinf4214362013-10-30 21:10:47 +010040
Arvid Brodina718dcc2014-07-04 23:42:00 +020041 if (!data) {
42 netdev_info(dev, "HSR: No slave devices specified\n");
43 return -EINVAL;
44 }
Arvid Brodinf4214362013-10-30 21:10:47 +010045 if (!data[IFLA_HSR_SLAVE1]) {
Arvid Brodina718dcc2014-07-04 23:42:00 +020046 netdev_info(dev, "HSR: Slave1 device not specified\n");
Arvid Brodinf4214362013-10-30 21:10:47 +010047 return -EINVAL;
48 }
49 link[0] = __dev_get_by_index(src_net, nla_get_u32(data[IFLA_HSR_SLAVE1]));
50 if (!data[IFLA_HSR_SLAVE2]) {
Arvid Brodina718dcc2014-07-04 23:42:00 +020051 netdev_info(dev, "HSR: Slave2 device not specified\n");
Arvid Brodinf4214362013-10-30 21:10:47 +010052 return -EINVAL;
53 }
54 link[1] = __dev_get_by_index(src_net, nla_get_u32(data[IFLA_HSR_SLAVE2]));
55
56 if (!link[0] || !link[1])
57 return -ENODEV;
58 if (link[0] == link[1])
59 return -EINVAL;
60
61 if (!data[IFLA_HSR_MULTICAST_SPEC])
62 multicast_spec = 0;
63 else
64 multicast_spec = nla_get_u8(data[IFLA_HSR_MULTICAST_SPEC]);
65
Peter Heiseee1c2792016-04-13 13:52:22 +020066 if (!data[IFLA_HSR_VERSION])
67 hsr_version = 0;
68 else
69 hsr_version = nla_get_u8(data[IFLA_HSR_VERSION]);
70
71 return hsr_dev_finalize(dev, link, multicast_spec, hsr_version);
Arvid Brodinf4214362013-10-30 21:10:47 +010072}
73
Arvid Brodin98bf8362013-11-29 23:38:16 +010074static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
75{
Arvid Brodin70ebe4a2014-07-04 23:34:38 +020076 struct hsr_priv *hsr;
Arvid Brodinc5a75912014-07-04 23:38:05 +020077 struct hsr_port *port;
Arvid Brodin51f3c602014-07-04 23:37:27 +020078 int res;
Arvid Brodin98bf8362013-11-29 23:38:16 +010079
Arvid Brodin70ebe4a2014-07-04 23:34:38 +020080 hsr = netdev_priv(dev);
Arvid Brodin98bf8362013-11-29 23:38:16 +010081
Arvid Brodin51f3c602014-07-04 23:37:27 +020082 res = 0;
Arvid Brodin98bf8362013-11-29 23:38:16 +010083
Arvid Brodin51f3c602014-07-04 23:37:27 +020084 rcu_read_lock();
Arvid Brodinc5a75912014-07-04 23:38:05 +020085 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
86 if (port)
87 res = nla_put_u32(skb, IFLA_HSR_SLAVE1, port->dev->ifindex);
Arvid Brodin51f3c602014-07-04 23:37:27 +020088 rcu_read_unlock();
89 if (res)
90 goto nla_put_failure;
91
92 rcu_read_lock();
Arvid Brodinc5a75912014-07-04 23:38:05 +020093 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
94 if (port)
95 res = nla_put_u32(skb, IFLA_HSR_SLAVE2, port->dev->ifindex);
Arvid Brodin51f3c602014-07-04 23:37:27 +020096 rcu_read_unlock();
97 if (res)
98 goto nla_put_failure;
Arvid Brodin98bf8362013-11-29 23:38:16 +010099
100 if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN,
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200101 hsr->sup_multicast_addr) ||
102 nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr))
Arvid Brodin98bf8362013-11-29 23:38:16 +0100103 goto nla_put_failure;
104
105 return 0;
106
107nla_put_failure:
108 return -EMSGSIZE;
109}
110
Arvid Brodinf4214362013-10-30 21:10:47 +0100111static struct rtnl_link_ops hsr_link_ops __read_mostly = {
112 .kind = "hsr",
113 .maxtype = IFLA_HSR_MAX,
114 .policy = hsr_policy,
115 .priv_size = sizeof(struct hsr_priv),
116 .setup = hsr_dev_setup,
117 .newlink = hsr_newlink,
Arvid Brodin98bf8362013-11-29 23:38:16 +0100118 .fill_info = hsr_fill_info,
Arvid Brodinf4214362013-10-30 21:10:47 +0100119};
120
121
122
123/* attribute policy */
Arvid Brodinf4214362013-10-30 21:10:47 +0100124static const struct nla_policy hsr_genl_policy[HSR_A_MAX + 1] = {
Peter Heisef9375722016-04-19 13:34:28 +0200125 [HSR_A_NODE_ADDR] = { .len = ETH_ALEN },
126 [HSR_A_NODE_ADDR_B] = { .len = ETH_ALEN },
Arvid Brodinf4214362013-10-30 21:10:47 +0100127 [HSR_A_IFINDEX] = { .type = NLA_U32 },
128 [HSR_A_IF1_AGE] = { .type = NLA_U32 },
129 [HSR_A_IF2_AGE] = { .type = NLA_U32 },
130 [HSR_A_IF1_SEQ] = { .type = NLA_U16 },
131 [HSR_A_IF2_SEQ] = { .type = NLA_U16 },
132};
133
134static struct genl_family hsr_genl_family = {
135 .id = GENL_ID_GENERATE,
136 .hdrsize = 0,
137 .name = "HSR",
138 .version = 1,
139 .maxattr = HSR_A_MAX,
140};
141
Johannes Berg2a94fe42013-11-19 15:19:39 +0100142static const struct genl_multicast_group hsr_mcgrps[] = {
143 { .name = "hsr-network", },
Arvid Brodinf4214362013-10-30 21:10:47 +0100144};
145
146
147
148/* This is called if for some node with MAC address addr, we only get frames
149 * over one of the slave interfaces. This would indicate an open network ring
150 * (i.e. a link has failed somewhere).
151 */
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200152void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN],
Arvid Brodinc5a75912014-07-04 23:38:05 +0200153 struct hsr_port *port)
Arvid Brodinf4214362013-10-30 21:10:47 +0100154{
155 struct sk_buff *skb;
156 void *msg_head;
Arvid Brodinc5a75912014-07-04 23:38:05 +0200157 struct hsr_port *master;
Arvid Brodinf4214362013-10-30 21:10:47 +0100158 int res;
Arvid Brodinf4214362013-10-30 21:10:47 +0100159
160 skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
161 if (!skb)
162 goto fail;
163
164 msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, HSR_C_RING_ERROR);
165 if (!msg_head)
166 goto nla_put_failure;
167
168 res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr);
169 if (res < 0)
170 goto nla_put_failure;
171
Arvid Brodinc5a75912014-07-04 23:38:05 +0200172 res = nla_put_u32(skb, HSR_A_IFINDEX, port->dev->ifindex);
Arvid Brodinf4214362013-10-30 21:10:47 +0100173 if (res < 0)
174 goto nla_put_failure;
175
176 genlmsg_end(skb, msg_head);
Johannes Berg2a94fe42013-11-19 15:19:39 +0100177 genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
Arvid Brodinf4214362013-10-30 21:10:47 +0100178
179 return;
180
181nla_put_failure:
182 kfree_skb(skb);
183
184fail:
Arvid Brodinc5a75912014-07-04 23:38:05 +0200185 rcu_read_lock();
186 master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
187 netdev_warn(master->dev, "Could not send HSR ring error message\n");
188 rcu_read_unlock();
Arvid Brodinf4214362013-10-30 21:10:47 +0100189}
190
191/* This is called when we haven't heard from the node with MAC address addr for
192 * some time (just before the node is removed from the node table/list).
193 */
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200194void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN])
Arvid Brodinf4214362013-10-30 21:10:47 +0100195{
196 struct sk_buff *skb;
197 void *msg_head;
Arvid Brodinc5a75912014-07-04 23:38:05 +0200198 struct hsr_port *master;
Arvid Brodinf4214362013-10-30 21:10:47 +0100199 int res;
200
201 skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
202 if (!skb)
203 goto fail;
204
205 msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, HSR_C_NODE_DOWN);
206 if (!msg_head)
207 goto nla_put_failure;
208
209
210 res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr);
211 if (res < 0)
212 goto nla_put_failure;
213
214 genlmsg_end(skb, msg_head);
Johannes Berg2a94fe42013-11-19 15:19:39 +0100215 genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
Arvid Brodinf4214362013-10-30 21:10:47 +0100216
217 return;
218
219nla_put_failure:
220 kfree_skb(skb);
221
222fail:
Arvid Brodinc5a75912014-07-04 23:38:05 +0200223 rcu_read_lock();
224 master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
225 netdev_warn(master->dev, "Could not send HSR node down\n");
226 rcu_read_unlock();
Arvid Brodinf4214362013-10-30 21:10:47 +0100227}
228
229
230/* HSR_C_GET_NODE_STATUS lets userspace query the internal HSR node table
231 * about the status of a specific node in the network, defined by its MAC
232 * address.
233 *
234 * Input: hsr ifindex, node mac address
235 * Output: hsr ifindex, node mac address (copied from request),
236 * age of latest frame from node over slave 1, slave 2 [ms]
237 */
238static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
239{
240 /* For receiving */
241 struct nlattr *na;
Arvid Brodinc5a75912014-07-04 23:38:05 +0200242 struct net_device *hsr_dev;
Arvid Brodinf4214362013-10-30 21:10:47 +0100243
244 /* For sending */
245 struct sk_buff *skb_out;
246 void *msg_head;
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200247 struct hsr_priv *hsr;
Arvid Brodinc5a75912014-07-04 23:38:05 +0200248 struct hsr_port *port;
Arvid Brodinf4214362013-10-30 21:10:47 +0100249 unsigned char hsr_node_addr_b[ETH_ALEN];
250 int hsr_node_if1_age;
251 u16 hsr_node_if1_seq;
252 int hsr_node_if2_age;
253 u16 hsr_node_if2_seq;
254 int addr_b_ifindex;
255 int res;
256
257 if (!info)
258 goto invalid;
259
260 na = info->attrs[HSR_A_IFINDEX];
261 if (!na)
262 goto invalid;
263 na = info->attrs[HSR_A_NODE_ADDR];
264 if (!na)
265 goto invalid;
266
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000267 rcu_read_lock();
268 hsr_dev = dev_get_by_index_rcu(genl_info_net(info),
269 nla_get_u32(info->attrs[HSR_A_IFINDEX]));
Arvid Brodinf4214362013-10-30 21:10:47 +0100270 if (!hsr_dev)
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000271 goto rcu_unlock;
Arvid Brodinf4214362013-10-30 21:10:47 +0100272 if (!is_hsr_master(hsr_dev))
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000273 goto rcu_unlock;
Arvid Brodinf4214362013-10-30 21:10:47 +0100274
275 /* Send reply */
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000276 skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
Arvid Brodinf4214362013-10-30 21:10:47 +0100277 if (!skb_out) {
278 res = -ENOMEM;
279 goto fail;
280 }
281
282 msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
283 info->snd_seq, &hsr_genl_family, 0,
284 HSR_C_SET_NODE_STATUS);
285 if (!msg_head) {
286 res = -ENOMEM;
287 goto nla_put_failure;
288 }
289
290 res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex);
291 if (res < 0)
292 goto nla_put_failure;
293
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200294 hsr = netdev_priv(hsr_dev);
295 res = hsr_get_node_data(hsr,
Arvid Brodinf4214362013-10-30 21:10:47 +0100296 (unsigned char *) nla_data(info->attrs[HSR_A_NODE_ADDR]),
297 hsr_node_addr_b,
298 &addr_b_ifindex,
299 &hsr_node_if1_age,
300 &hsr_node_if1_seq,
301 &hsr_node_if2_age,
302 &hsr_node_if2_seq);
303 if (res < 0)
Geyslan G. Bem84a035f2013-11-14 16:12:54 -0300304 goto nla_put_failure;
Arvid Brodinf4214362013-10-30 21:10:47 +0100305
306 res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN,
307 nla_data(info->attrs[HSR_A_NODE_ADDR]));
308 if (res < 0)
309 goto nla_put_failure;
310
311 if (addr_b_ifindex > -1) {
312 res = nla_put(skb_out, HSR_A_NODE_ADDR_B, ETH_ALEN,
313 hsr_node_addr_b);
314 if (res < 0)
315 goto nla_put_failure;
316
317 res = nla_put_u32(skb_out, HSR_A_ADDR_B_IFINDEX, addr_b_ifindex);
318 if (res < 0)
319 goto nla_put_failure;
320 }
321
322 res = nla_put_u32(skb_out, HSR_A_IF1_AGE, hsr_node_if1_age);
323 if (res < 0)
324 goto nla_put_failure;
325 res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq);
326 if (res < 0)
327 goto nla_put_failure;
Arvid Brodinc5a75912014-07-04 23:38:05 +0200328 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
329 if (port)
330 res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX,
331 port->dev->ifindex);
Arvid Brodinf4214362013-10-30 21:10:47 +0100332 if (res < 0)
333 goto nla_put_failure;
334
335 res = nla_put_u32(skb_out, HSR_A_IF2_AGE, hsr_node_if2_age);
336 if (res < 0)
337 goto nla_put_failure;
338 res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq);
339 if (res < 0)
340 goto nla_put_failure;
Arvid Brodinc5a75912014-07-04 23:38:05 +0200341 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
342 if (port)
343 res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX,
344 port->dev->ifindex);
Arvid Brodin51f3c602014-07-04 23:37:27 +0200345 if (res < 0)
346 goto nla_put_failure;
Arvid Brodinf4214362013-10-30 21:10:47 +0100347
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000348 rcu_read_unlock();
349
Arvid Brodinf4214362013-10-30 21:10:47 +0100350 genlmsg_end(skb_out, msg_head);
351 genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
352
353 return 0;
354
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000355rcu_unlock:
356 rcu_read_unlock();
Arvid Brodinf4214362013-10-30 21:10:47 +0100357invalid:
358 netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL);
359 return 0;
360
361nla_put_failure:
362 kfree_skb(skb_out);
363 /* Fall through */
364
365fail:
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000366 rcu_read_unlock();
Arvid Brodinf4214362013-10-30 21:10:47 +0100367 return res;
368}
369
Arvid Brodinf266a682014-07-04 23:41:03 +0200370/* Get a list of MacAddressA of all nodes known to this node (including self).
Arvid Brodinf4214362013-10-30 21:10:47 +0100371 */
372static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
373{
374 /* For receiving */
375 struct nlattr *na;
376 struct net_device *hsr_dev;
377
378 /* For sending */
379 struct sk_buff *skb_out;
380 void *msg_head;
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200381 struct hsr_priv *hsr;
Arvid Brodinf4214362013-10-30 21:10:47 +0100382 void *pos;
383 unsigned char addr[ETH_ALEN];
384 int res;
385
386 if (!info)
387 goto invalid;
388
389 na = info->attrs[HSR_A_IFINDEX];
390 if (!na)
391 goto invalid;
392
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000393 rcu_read_lock();
394 hsr_dev = dev_get_by_index_rcu(genl_info_net(info),
395 nla_get_u32(info->attrs[HSR_A_IFINDEX]));
Arvid Brodinf4214362013-10-30 21:10:47 +0100396 if (!hsr_dev)
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000397 goto rcu_unlock;
Arvid Brodinf4214362013-10-30 21:10:47 +0100398 if (!is_hsr_master(hsr_dev))
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000399 goto rcu_unlock;
Arvid Brodinf4214362013-10-30 21:10:47 +0100400
401 /* Send reply */
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000402 skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
Arvid Brodinf4214362013-10-30 21:10:47 +0100403 if (!skb_out) {
404 res = -ENOMEM;
405 goto fail;
406 }
407
408 msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
409 info->snd_seq, &hsr_genl_family, 0,
410 HSR_C_SET_NODE_LIST);
411 if (!msg_head) {
412 res = -ENOMEM;
413 goto nla_put_failure;
414 }
415
416 res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex);
417 if (res < 0)
418 goto nla_put_failure;
419
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200420 hsr = netdev_priv(hsr_dev);
Arvid Brodinf4214362013-10-30 21:10:47 +0100421
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200422 pos = hsr_get_next_node(hsr, NULL, addr);
Arvid Brodinf4214362013-10-30 21:10:47 +0100423 while (pos) {
424 res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr);
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000425 if (res < 0)
Arvid Brodinf4214362013-10-30 21:10:47 +0100426 goto nla_put_failure;
Arvid Brodin70ebe4a2014-07-04 23:34:38 +0200427 pos = hsr_get_next_node(hsr, pos, addr);
Arvid Brodinf4214362013-10-30 21:10:47 +0100428 }
429 rcu_read_unlock();
430
431 genlmsg_end(skb_out, msg_head);
432 genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
433
434 return 0;
435
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000436rcu_unlock:
437 rcu_read_unlock();
Arvid Brodinf4214362013-10-30 21:10:47 +0100438invalid:
439 netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL);
440 return 0;
441
442nla_put_failure:
443 kfree_skb(skb_out);
444 /* Fall through */
445
446fail:
Taehee Yoo9bc97bc2020-03-13 06:50:14 +0000447 rcu_read_unlock();
Arvid Brodinf4214362013-10-30 21:10:47 +0100448 return res;
449}
450
451
Johannes Berg4534de82013-11-14 17:14:46 +0100452static const struct genl_ops hsr_ops[] = {
Johannes Berg9504b3e2013-11-14 17:14:40 +0100453 {
454 .cmd = HSR_C_GET_NODE_STATUS,
455 .flags = 0,
456 .policy = hsr_genl_policy,
457 .doit = hsr_get_node_status,
458 .dumpit = NULL,
459 },
460 {
461 .cmd = HSR_C_GET_NODE_LIST,
462 .flags = 0,
463 .policy = hsr_genl_policy,
464 .doit = hsr_get_node_list,
465 .dumpit = NULL,
466 },
Arvid Brodinf4214362013-10-30 21:10:47 +0100467};
468
469int __init hsr_netlink_init(void)
470{
471 int rc;
472
473 rc = rtnl_link_register(&hsr_link_ops);
474 if (rc)
475 goto fail_rtnl_link_register;
476
Johannes Berg2a94fe42013-11-19 15:19:39 +0100477 rc = genl_register_family_with_ops_groups(&hsr_genl_family, hsr_ops,
478 hsr_mcgrps);
Arvid Brodinf4214362013-10-30 21:10:47 +0100479 if (rc)
480 goto fail_genl_register_family;
481
Arvid Brodinf4214362013-10-30 21:10:47 +0100482 return 0;
483
Arvid Brodinf4214362013-10-30 21:10:47 +0100484fail_genl_register_family:
485 rtnl_link_unregister(&hsr_link_ops);
486fail_rtnl_link_register:
487
488 return rc;
489}
490
491void __exit hsr_netlink_exit(void)
492{
Arvid Brodinf4214362013-10-30 21:10:47 +0100493 genl_unregister_family(&hsr_genl_family);
Arvid Brodinf4214362013-10-30 21:10:47 +0100494 rtnl_link_unregister(&hsr_link_ops);
495}
496
497MODULE_ALIAS_RTNL_LINK("hsr");