Merge tag 'soc-ep93xx-dt-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-block.git] / net / hsr / hsr_netlink.c
CommitLineData
0e7623bd 1// SPDX-License-Identifier: GPL-2.0
70ebe4a4 2/* Copyright 2011-2014 Autronica Fire and Security AS
f421436a
AB
3 *
4 * Author(s):
70ebe4a4 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
f421436a 6 *
8f4c0e01 7 * Routines for handling Netlink messages for HSR and PRP.
f421436a
AB
8 */
9
10#include "hsr_netlink.h"
11#include <linux/kernel.h>
12#include <net/rtnetlink.h>
13#include <net/genetlink.h>
14#include "hsr_main.h"
15#include "hsr_device.h"
16#include "hsr_framereg.h"
17
18static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = {
19 [IFLA_HSR_SLAVE1] = { .type = NLA_U32 },
20 [IFLA_HSR_SLAVE2] = { .type = NLA_U32 },
21 [IFLA_HSR_MULTICAST_SPEC] = { .type = NLA_U8 },
ee1c2797 22 [IFLA_HSR_VERSION] = { .type = NLA_U8 },
f9375729 23 [IFLA_HSR_SUPERVISION_ADDR] = { .len = ETH_ALEN },
98bf8362 24 [IFLA_HSR_SEQ_NR] = { .type = NLA_U16 },
8f4c0e01 25 [IFLA_HSR_PROTOCOL] = { .type = NLA_U8 },
5055cccf 26 [IFLA_HSR_INTERLINK] = { .type = NLA_U32 },
f421436a
AB
27};
28
f421436a
AB
29/* Here, it seems a netdevice has already been allocated for us, and the
30 * hsr_dev_setup routine has been executed. Nice!
31 */
32static int hsr_newlink(struct net *src_net, struct net_device *dev,
7a3f4a18
MS
33 struct nlattr *tb[], struct nlattr *data[],
34 struct netlink_ext_ack *extack)
f421436a 35{
8f4c0e01
MK
36 enum hsr_version proto_version;
37 unsigned char multicast_spec;
38 u8 proto = HSR_PROTOCOL_HSR;
f421436a 39
5055cccf 40 struct net_device *link[2], *interlink = NULL;
a718dcc5 41 if (!data) {
13eeb5fe 42 NL_SET_ERR_MSG_MOD(extack, "No slave devices specified");
a718dcc5
AB
43 return -EINVAL;
44 }
f421436a 45 if (!data[IFLA_HSR_SLAVE1]) {
13eeb5fe 46 NL_SET_ERR_MSG_MOD(extack, "Slave1 device not specified");
f421436a
AB
47 return -EINVAL;
48 }
d595b85a
MK
49 link[0] = __dev_get_by_index(src_net,
50 nla_get_u32(data[IFLA_HSR_SLAVE1]));
13eeb5fe
TY
51 if (!link[0]) {
52 NL_SET_ERR_MSG_MOD(extack, "Slave1 does not exist");
53 return -EINVAL;
54 }
f421436a 55 if (!data[IFLA_HSR_SLAVE2]) {
13eeb5fe 56 NL_SET_ERR_MSG_MOD(extack, "Slave2 device not specified");
f421436a
AB
57 return -EINVAL;
58 }
d595b85a
MK
59 link[1] = __dev_get_by_index(src_net,
60 nla_get_u32(data[IFLA_HSR_SLAVE2]));
13eeb5fe
TY
61 if (!link[1]) {
62 NL_SET_ERR_MSG_MOD(extack, "Slave2 does not exist");
63 return -EINVAL;
64 }
f421436a 65
13eeb5fe
TY
66 if (link[0] == link[1]) {
67 NL_SET_ERR_MSG_MOD(extack, "Slave1 and Slave2 are same");
f421436a 68 return -EINVAL;
13eeb5fe 69 }
f421436a 70
5055cccf
LM
71 if (data[IFLA_HSR_INTERLINK])
72 interlink = __dev_get_by_index(src_net,
73 nla_get_u32(data[IFLA_HSR_INTERLINK]));
74
75 if (interlink && interlink == link[0]) {
76 NL_SET_ERR_MSG_MOD(extack, "Interlink and Slave1 are the same");
77 return -EINVAL;
78 }
79
80 if (interlink && interlink == link[1]) {
81 NL_SET_ERR_MSG_MOD(extack, "Interlink and Slave2 are the same");
82 return -EINVAL;
83 }
84
f421436a
AB
85 if (!data[IFLA_HSR_MULTICAST_SPEC])
86 multicast_spec = 0;
87 else
88 multicast_spec = nla_get_u8(data[IFLA_HSR_MULTICAST_SPEC]);
89
8f4c0e01
MK
90 if (data[IFLA_HSR_PROTOCOL])
91 proto = nla_get_u8(data[IFLA_HSR_PROTOCOL]);
92
93 if (proto >= HSR_PROTOCOL_MAX) {
b87f9fe1 94 NL_SET_ERR_MSG_MOD(extack, "Unsupported protocol");
8f4c0e01
MK
95 return -EINVAL;
96 }
97
4faab8c4 98 if (!data[IFLA_HSR_VERSION]) {
8f4c0e01 99 proto_version = HSR_V0;
4faab8c4 100 } else {
8f4c0e01 101 if (proto == HSR_PROTOCOL_PRP) {
b87f9fe1 102 NL_SET_ERR_MSG_MOD(extack, "PRP version unsupported");
8f4c0e01
MK
103 return -EINVAL;
104 }
105
106 proto_version = nla_get_u8(data[IFLA_HSR_VERSION]);
107 if (proto_version > HSR_V1) {
4faab8c4 108 NL_SET_ERR_MSG_MOD(extack,
b87f9fe1 109 "Only HSR version 0/1 supported");
4faab8c4
TY
110 return -EINVAL;
111 }
112 }
ee1c2797 113
5055cccf 114 if (proto == HSR_PROTOCOL_PRP) {
8f4c0e01 115 proto_version = PRP_V1;
5055cccf
LM
116 if (interlink) {
117 NL_SET_ERR_MSG_MOD(extack,
118 "Interlink only works with HSR");
119 return -EINVAL;
120 }
121 }
8f4c0e01 122
5055cccf
LM
123 return hsr_dev_finalize(dev, link, interlink, multicast_spec,
124 proto_version, extack);
f421436a
AB
125}
126
de0083c7
TY
127static void hsr_dellink(struct net_device *dev, struct list_head *head)
128{
129 struct hsr_priv *hsr = netdev_priv(dev);
130
131 del_timer_sync(&hsr->prune_timer);
5055cccf 132 del_timer_sync(&hsr->prune_proxy_timer);
de0083c7 133 del_timer_sync(&hsr->announce_timer);
5f703ce5 134 timer_delete_sync(&hsr->announce_proxy_timer);
de0083c7
TY
135
136 hsr_debugfs_term(hsr);
137 hsr_del_ports(hsr);
138
139 hsr_del_self_node(hsr);
e012764c 140 hsr_del_nodes(&hsr->node_db);
5055cccf 141 hsr_del_nodes(&hsr->proxy_node_db);
de0083c7
TY
142
143 unregister_netdevice_queue(dev, head);
144}
145
98bf8362
AB
146static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
147{
81390d0c 148 struct hsr_priv *hsr = netdev_priv(dev);
8f4c0e01 149 u8 proto = HSR_PROTOCOL_HSR;
c5a75911 150 struct hsr_port *port;
98bf8362 151
c5a75911 152 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
81390d0c
TY
153 if (port) {
154 if (nla_put_u32(skb, IFLA_HSR_SLAVE1, port->dev->ifindex))
155 goto nla_put_failure;
156 }
51f3c605 157
c5a75911 158 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
81390d0c
TY
159 if (port) {
160 if (nla_put_u32(skb, IFLA_HSR_SLAVE2, port->dev->ifindex))
161 goto nla_put_failure;
162 }
98bf8362
AB
163
164 if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN,
70ebe4a4
AB
165 hsr->sup_multicast_addr) ||
166 nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr))
98bf8362 167 goto nla_put_failure;
8f4c0e01
MK
168 if (hsr->prot_version == PRP_V1)
169 proto = HSR_PROTOCOL_PRP;
170 if (nla_put_u8(skb, IFLA_HSR_PROTOCOL, proto))
171 goto nla_put_failure;
98bf8362
AB
172
173 return 0;
174
175nla_put_failure:
176 return -EMSGSIZE;
177}
178
f421436a
AB
179static struct rtnl_link_ops hsr_link_ops __read_mostly = {
180 .kind = "hsr",
181 .maxtype = IFLA_HSR_MAX,
182 .policy = hsr_policy,
183 .priv_size = sizeof(struct hsr_priv),
184 .setup = hsr_dev_setup,
185 .newlink = hsr_newlink,
de0083c7 186 .dellink = hsr_dellink,
98bf8362 187 .fill_info = hsr_fill_info,
f421436a
AB
188};
189
f421436a 190/* attribute policy */
f421436a 191static const struct nla_policy hsr_genl_policy[HSR_A_MAX + 1] = {
f9375729
PH
192 [HSR_A_NODE_ADDR] = { .len = ETH_ALEN },
193 [HSR_A_NODE_ADDR_B] = { .len = ETH_ALEN },
f421436a
AB
194 [HSR_A_IFINDEX] = { .type = NLA_U32 },
195 [HSR_A_IF1_AGE] = { .type = NLA_U32 },
196 [HSR_A_IF2_AGE] = { .type = NLA_U32 },
197 [HSR_A_IF1_SEQ] = { .type = NLA_U16 },
198 [HSR_A_IF2_SEQ] = { .type = NLA_U16 },
199};
200
489111e5 201static struct genl_family hsr_genl_family;
f421436a 202
2a94fe48
JB
203static const struct genl_multicast_group hsr_mcgrps[] = {
204 { .name = "hsr-network", },
f421436a
AB
205};
206
f421436a
AB
207/* This is called if for some node with MAC address addr, we only get frames
208 * over one of the slave interfaces. This would indicate an open network ring
209 * (i.e. a link has failed somewhere).
210 */
70ebe4a4 211void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN],
c5a75911 212 struct hsr_port *port)
f421436a
AB
213{
214 struct sk_buff *skb;
215 void *msg_head;
c5a75911 216 struct hsr_port *master;
f421436a 217 int res;
f421436a
AB
218
219 skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
220 if (!skb)
221 goto fail;
222
d595b85a
MK
223 msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0,
224 HSR_C_RING_ERROR);
f421436a
AB
225 if (!msg_head)
226 goto nla_put_failure;
227
228 res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr);
229 if (res < 0)
230 goto nla_put_failure;
231
c5a75911 232 res = nla_put_u32(skb, HSR_A_IFINDEX, port->dev->ifindex);
f421436a
AB
233 if (res < 0)
234 goto nla_put_failure;
235
236 genlmsg_end(skb, msg_head);
2a94fe48 237 genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
f421436a
AB
238
239 return;
240
241nla_put_failure:
242 kfree_skb(skb);
243
244fail:
c5a75911
AB
245 rcu_read_lock();
246 master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
247 netdev_warn(master->dev, "Could not send HSR ring error message\n");
248 rcu_read_unlock();
f421436a
AB
249}
250
251/* This is called when we haven't heard from the node with MAC address addr for
252 * some time (just before the node is removed from the node table/list).
253 */
70ebe4a4 254void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN])
f421436a
AB
255{
256 struct sk_buff *skb;
257 void *msg_head;
c5a75911 258 struct hsr_port *master;
f421436a
AB
259 int res;
260
261 skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
262 if (!skb)
263 goto fail;
264
265 msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, HSR_C_NODE_DOWN);
266 if (!msg_head)
267 goto nla_put_failure;
268
f421436a
AB
269 res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr);
270 if (res < 0)
271 goto nla_put_failure;
272
273 genlmsg_end(skb, msg_head);
2a94fe48 274 genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
f421436a
AB
275
276 return;
277
278nla_put_failure:
279 kfree_skb(skb);
280
281fail:
c5a75911
AB
282 rcu_read_lock();
283 master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
284 netdev_warn(master->dev, "Could not send HSR node down\n");
285 rcu_read_unlock();
f421436a
AB
286}
287
f421436a
AB
288/* HSR_C_GET_NODE_STATUS lets userspace query the internal HSR node table
289 * about the status of a specific node in the network, defined by its MAC
290 * address.
291 *
292 * Input: hsr ifindex, node mac address
293 * Output: hsr ifindex, node mac address (copied from request),
294 * age of latest frame from node over slave 1, slave 2 [ms]
295 */
296static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
297{
298 /* For receiving */
299 struct nlattr *na;
c5a75911 300 struct net_device *hsr_dev;
f421436a
AB
301
302 /* For sending */
303 struct sk_buff *skb_out;
304 void *msg_head;
70ebe4a4 305 struct hsr_priv *hsr;
c5a75911 306 struct hsr_port *port;
f421436a
AB
307 unsigned char hsr_node_addr_b[ETH_ALEN];
308 int hsr_node_if1_age;
309 u16 hsr_node_if1_seq;
310 int hsr_node_if2_age;
311 u16 hsr_node_if2_seq;
312 int addr_b_ifindex;
313 int res;
314
315 if (!info)
316 goto invalid;
317
318 na = info->attrs[HSR_A_IFINDEX];
319 if (!na)
320 goto invalid;
321 na = info->attrs[HSR_A_NODE_ADDR];
322 if (!na)
323 goto invalid;
324
173756b8
TY
325 rcu_read_lock();
326 hsr_dev = dev_get_by_index_rcu(genl_info_net(info),
327 nla_get_u32(info->attrs[HSR_A_IFINDEX]));
f421436a 328 if (!hsr_dev)
173756b8 329 goto rcu_unlock;
f421436a 330 if (!is_hsr_master(hsr_dev))
173756b8 331 goto rcu_unlock;
f421436a 332
f421436a 333 /* Send reply */
173756b8 334 skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
f421436a
AB
335 if (!skb_out) {
336 res = -ENOMEM;
337 goto fail;
338 }
339
340 msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
4fe25bd8
MK
341 info->snd_seq, &hsr_genl_family, 0,
342 HSR_C_SET_NODE_STATUS);
f421436a
AB
343 if (!msg_head) {
344 res = -ENOMEM;
345 goto nla_put_failure;
346 }
347
348 res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex);
349 if (res < 0)
350 goto nla_put_failure;
351
70ebe4a4
AB
352 hsr = netdev_priv(hsr_dev);
353 res = hsr_get_node_data(hsr,
d595b85a
MK
354 (unsigned char *)
355 nla_data(info->attrs[HSR_A_NODE_ADDR]),
356 hsr_node_addr_b,
357 &addr_b_ifindex,
358 &hsr_node_if1_age,
359 &hsr_node_if1_seq,
360 &hsr_node_if2_age,
361 &hsr_node_if2_seq);
f421436a 362 if (res < 0)
84a035f6 363 goto nla_put_failure;
f421436a
AB
364
365 res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN,
4fe25bd8 366 nla_data(info->attrs[HSR_A_NODE_ADDR]));
f421436a
AB
367 if (res < 0)
368 goto nla_put_failure;
369
370 if (addr_b_ifindex > -1) {
371 res = nla_put(skb_out, HSR_A_NODE_ADDR_B, ETH_ALEN,
d595b85a 372 hsr_node_addr_b);
f421436a
AB
373 if (res < 0)
374 goto nla_put_failure;
375
d595b85a
MK
376 res = nla_put_u32(skb_out, HSR_A_ADDR_B_IFINDEX,
377 addr_b_ifindex);
f421436a
AB
378 if (res < 0)
379 goto nla_put_failure;
380 }
381
382 res = nla_put_u32(skb_out, HSR_A_IF1_AGE, hsr_node_if1_age);
383 if (res < 0)
384 goto nla_put_failure;
385 res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq);
386 if (res < 0)
387 goto nla_put_failure;
c5a75911
AB
388 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
389 if (port)
390 res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX,
391 port->dev->ifindex);
f421436a
AB
392 if (res < 0)
393 goto nla_put_failure;
394
395 res = nla_put_u32(skb_out, HSR_A_IF2_AGE, hsr_node_if2_age);
396 if (res < 0)
397 goto nla_put_failure;
398 res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq);
399 if (res < 0)
400 goto nla_put_failure;
c5a75911
AB
401 port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
402 if (port)
403 res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX,
404 port->dev->ifindex);
51f3c605
AB
405 if (res < 0)
406 goto nla_put_failure;
f421436a 407
173756b8
TY
408 rcu_read_unlock();
409
f421436a
AB
410 genlmsg_end(skb_out, msg_head);
411 genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
412
413 return 0;
414
173756b8
TY
415rcu_unlock:
416 rcu_read_unlock();
f421436a 417invalid:
2d4bc933 418 netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL, NULL);
f421436a
AB
419 return 0;
420
421nla_put_failure:
422 kfree_skb(skb_out);
423 /* Fall through */
424
425fail:
173756b8 426 rcu_read_unlock();
f421436a
AB
427 return res;
428}
429
f266a683 430/* Get a list of MacAddressA of all nodes known to this node (including self).
f421436a
AB
431 */
432static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
433{
ca19c70f 434 unsigned char addr[ETH_ALEN];
f421436a 435 struct net_device *hsr_dev;
f421436a 436 struct sk_buff *skb_out;
70ebe4a4 437 struct hsr_priv *hsr;
ca19c70f
TY
438 bool restart = false;
439 struct nlattr *na;
440 void *pos = NULL;
441 void *msg_head;
f421436a
AB
442 int res;
443
444 if (!info)
445 goto invalid;
446
447 na = info->attrs[HSR_A_IFINDEX];
448 if (!na)
449 goto invalid;
450
173756b8
TY
451 rcu_read_lock();
452 hsr_dev = dev_get_by_index_rcu(genl_info_net(info),
453 nla_get_u32(info->attrs[HSR_A_IFINDEX]));
f421436a 454 if (!hsr_dev)
173756b8 455 goto rcu_unlock;
f421436a 456 if (!is_hsr_master(hsr_dev))
173756b8 457 goto rcu_unlock;
f421436a 458
ca19c70f 459restart:
f421436a 460 /* Send reply */
ca19c70f 461 skb_out = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
f421436a
AB
462 if (!skb_out) {
463 res = -ENOMEM;
464 goto fail;
465 }
466
467 msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
4fe25bd8
MK
468 info->snd_seq, &hsr_genl_family, 0,
469 HSR_C_SET_NODE_LIST);
f421436a
AB
470 if (!msg_head) {
471 res = -ENOMEM;
472 goto nla_put_failure;
473 }
474
ca19c70f
TY
475 if (!restart) {
476 res = nla_put_u32(skb_out, HSR_A_IFINDEX, hsr_dev->ifindex);
477 if (res < 0)
478 goto nla_put_failure;
479 }
f421436a 480
70ebe4a4 481 hsr = netdev_priv(hsr_dev);
f421436a 482
ca19c70f
TY
483 if (!pos)
484 pos = hsr_get_next_node(hsr, NULL, addr);
f421436a
AB
485 while (pos) {
486 res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr);
487 if (res < 0) {
ca19c70f
TY
488 if (res == -EMSGSIZE) {
489 genlmsg_end(skb_out, msg_head);
490 genlmsg_unicast(genl_info_net(info), skb_out,
491 info->snd_portid);
492 restart = true;
493 goto restart;
494 }
f421436a
AB
495 goto nla_put_failure;
496 }
70ebe4a4 497 pos = hsr_get_next_node(hsr, pos, addr);
f421436a
AB
498 }
499 rcu_read_unlock();
500
501 genlmsg_end(skb_out, msg_head);
502 genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
503
504 return 0;
505
173756b8
TY
506rcu_unlock:
507 rcu_read_unlock();
f421436a 508invalid:
2d4bc933 509 netlink_ack(skb_in, nlmsg_hdr(skb_in), -EINVAL, NULL);
f421436a
AB
510 return 0;
511
512nla_put_failure:
ca19c70f 513 nlmsg_free(skb_out);
f421436a
AB
514 /* Fall through */
515
516fail:
173756b8 517 rcu_read_unlock();
f421436a
AB
518 return res;
519}
520
66a9b928 521static const struct genl_small_ops hsr_ops[] = {
9504b3ee
JB
522 {
523 .cmd = HSR_C_GET_NODE_STATUS,
ef6243ac 524 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
9504b3ee 525 .flags = 0,
9504b3ee
JB
526 .doit = hsr_get_node_status,
527 .dumpit = NULL,
528 },
529 {
530 .cmd = HSR_C_GET_NODE_LIST,
ef6243ac 531 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
9504b3ee 532 .flags = 0,
9504b3ee
JB
533 .doit = hsr_get_node_list,
534 .dumpit = NULL,
535 },
f421436a
AB
536};
537
56989f6d 538static struct genl_family hsr_genl_family __ro_after_init = {
489111e5
JB
539 .hdrsize = 0,
540 .name = "HSR",
541 .version = 1,
542 .maxattr = HSR_A_MAX,
3b0f31f2 543 .policy = hsr_genl_policy,
09e91dbe 544 .netnsok = true,
489111e5 545 .module = THIS_MODULE,
66a9b928
JK
546 .small_ops = hsr_ops,
547 .n_small_ops = ARRAY_SIZE(hsr_ops),
9c5d03d3 548 .resv_start_op = HSR_C_SET_NODE_LIST + 1,
489111e5
JB
549 .mcgrps = hsr_mcgrps,
550 .n_mcgrps = ARRAY_SIZE(hsr_mcgrps),
551};
552
f421436a
AB
553int __init hsr_netlink_init(void)
554{
555 int rc;
556
557 rc = rtnl_link_register(&hsr_link_ops);
558 if (rc)
559 goto fail_rtnl_link_register;
560
489111e5 561 rc = genl_register_family(&hsr_genl_family);
f421436a
AB
562 if (rc)
563 goto fail_genl_register_family;
564
c6c4ccd7 565 hsr_debugfs_create_root();
f421436a
AB
566 return 0;
567
f421436a
AB
568fail_genl_register_family:
569 rtnl_link_unregister(&hsr_link_ops);
570fail_rtnl_link_register:
571
572 return rc;
573}
574
575void __exit hsr_netlink_exit(void)
576{
f421436a 577 genl_unregister_family(&hsr_genl_family);
f421436a
AB
578 rtnl_link_unregister(&hsr_link_ops);
579}
580
581MODULE_ALIAS_RTNL_LINK("hsr");