aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2013-11-14 11:14:41 -0500
committerDavid S. Miller <davem@davemloft.net>2013-11-14 17:10:40 -0500
commit1c582d915da13ca21ad375ae04ec1bd6193418b2 (patch)
treecff9bbc495ad1fdf99999cf5643b2b4f51327511 /net
parent9504b3ee1c4490d669feb7622c828771d98b2c23 (diff)
ieee802154: use genl_register_family_with_ops()
This simplifies the code since there's no longer a need to have error handling in the registration. Unfortunately it means more extern function declarations are needed, but the overall goal would seem to justify this. While at it, also fix the registration error path - if the family registration failed then it shouldn't be unregistered. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/ieee802154/ieee802154.h19
-rw-r--r--net/ieee802154/netlink.c28
-rw-r--r--net/ieee802154/nl-mac.c61
-rw-r--r--net/ieee802154/nl-phy.c37
4 files changed, 51 insertions, 94 deletions
diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h
index aadec428e6ec..14d5dab4436f 100644
--- a/net/ieee802154/ieee802154.h
+++ b/net/ieee802154/ieee802154.h
@@ -47,7 +47,22 @@ struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
47int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info); 47int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info);
48 48
49extern struct genl_family nl802154_family; 49extern struct genl_family nl802154_family;
50int nl802154_mac_register(void); 50
51int nl802154_phy_register(void); 51/* genetlink ops/groups */
52int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info);
53int ieee802154_dump_phy(struct sk_buff *skb, struct netlink_callback *cb);
54int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info);
55int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info);
56
57extern struct genl_multicast_group ieee802154_coord_mcgrp;
58extern struct genl_multicast_group ieee802154_beacon_mcgrp;
59
60int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info);
61int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info);
62int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info);
63int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info);
64int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info);
65int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info);
66int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb);
52 67
53#endif 68#endif
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c
index 7e49bbcc6967..eb9faef6782a 100644
--- a/net/ieee802154/netlink.c
+++ b/net/ieee802154/netlink.c
@@ -109,24 +109,39 @@ out:
109 return -ENOBUFS; 109 return -ENOBUFS;
110} 110}
111 111
112static struct genl_ops ieee8021154_ops[] = {
113 /* see nl-phy.c */
114 IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy,
115 ieee802154_dump_phy),
116 IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface),
117 IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface),
118 /* see nl-mac.c */
119 IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
120 IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
121 IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
122 IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
123 IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
124 IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
125 ieee802154_dump_iface),
126};
127
112int __init ieee802154_nl_init(void) 128int __init ieee802154_nl_init(void)
113{ 129{
114 int rc; 130 int rc;
115 131
116 rc = genl_register_family(&nl802154_family); 132 rc = genl_register_family_with_ops(&nl802154_family, ieee8021154_ops,
133 ARRAY_SIZE(ieee8021154_ops));
117 if (rc) 134 if (rc)
118 goto fail; 135 return rc;
119 136
120 rc = nl802154_mac_register(); 137 rc = genl_register_mc_group(&nl802154_family, &ieee802154_coord_mcgrp);
121 if (rc) 138 if (rc)
122 goto fail; 139 goto fail;
123 140
124 rc = nl802154_phy_register(); 141 rc = genl_register_mc_group(&nl802154_family, &ieee802154_beacon_mcgrp);
125 if (rc) 142 if (rc)
126 goto fail; 143 goto fail;
127
128 return 0; 144 return 0;
129
130fail: 145fail:
131 genl_unregister_family(&nl802154_family); 146 genl_unregister_family(&nl802154_family);
132 return rc; 147 return rc;
@@ -136,4 +151,3 @@ void __exit ieee802154_nl_exit(void)
136{ 151{
137 genl_unregister_family(&nl802154_family); 152 genl_unregister_family(&nl802154_family);
138} 153}
139
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index b0bdd8c51e9c..28d493032132 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -39,11 +39,11 @@
39 39
40#include "ieee802154.h" 40#include "ieee802154.h"
41 41
42static struct genl_multicast_group ieee802154_coord_mcgrp = { 42struct genl_multicast_group ieee802154_coord_mcgrp = {
43 .name = IEEE802154_MCAST_COORD_NAME, 43 .name = IEEE802154_MCAST_COORD_NAME,
44}; 44};
45 45
46static struct genl_multicast_group ieee802154_beacon_mcgrp = { 46struct genl_multicast_group ieee802154_beacon_mcgrp = {
47 .name = IEEE802154_MCAST_BEACON_NAME, 47 .name = IEEE802154_MCAST_BEACON_NAME,
48}; 48};
49 49
@@ -309,8 +309,7 @@ static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
309 return dev; 309 return dev;
310} 310}
311 311
312static int ieee802154_associate_req(struct sk_buff *skb, 312int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info)
313 struct genl_info *info)
314{ 313{
315 struct net_device *dev; 314 struct net_device *dev;
316 struct ieee802154_addr addr; 315 struct ieee802154_addr addr;
@@ -357,8 +356,7 @@ out:
357 return ret; 356 return ret;
358} 357}
359 358
360static int ieee802154_associate_resp(struct sk_buff *skb, 359int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info)
361 struct genl_info *info)
362{ 360{
363 struct net_device *dev; 361 struct net_device *dev;
364 struct ieee802154_addr addr; 362 struct ieee802154_addr addr;
@@ -390,8 +388,7 @@ out:
390 return ret; 388 return ret;
391} 389}
392 390
393static int ieee802154_disassociate_req(struct sk_buff *skb, 391int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
394 struct genl_info *info)
395{ 392{
396 struct net_device *dev; 393 struct net_device *dev;
397 struct ieee802154_addr addr; 394 struct ieee802154_addr addr;
@@ -433,7 +430,7 @@ out:
433 * PAN_coordinator, battery_life_extension = 0, 430 * PAN_coordinator, battery_life_extension = 0,
434 * coord_realignment = 0, security_enable = 0 431 * coord_realignment = 0, security_enable = 0
435*/ 432*/
436static int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info) 433int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
437{ 434{
438 struct net_device *dev; 435 struct net_device *dev;
439 struct ieee802154_addr addr; 436 struct ieee802154_addr addr;
@@ -492,7 +489,7 @@ out:
492 return ret; 489 return ret;
493} 490}
494 491
495static int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info) 492int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
496{ 493{
497 struct net_device *dev; 494 struct net_device *dev;
498 int ret = -EOPNOTSUPP; 495 int ret = -EOPNOTSUPP;
@@ -530,8 +527,7 @@ out:
530 return ret; 527 return ret;
531} 528}
532 529
533static int ieee802154_list_iface(struct sk_buff *skb, 530int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info)
534 struct genl_info *info)
535{ 531{
536 /* Request for interface name, index, type, IEEE address, 532 /* Request for interface name, index, type, IEEE address,
537 PAN Id, short address */ 533 PAN Id, short address */
@@ -565,8 +561,7 @@ out_dev:
565 561
566} 562}
567 563
568static int ieee802154_dump_iface(struct sk_buff *skb, 564int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
569 struct netlink_callback *cb)
570{ 565{
571 struct net *net = sock_net(skb->sk); 566 struct net *net = sock_net(skb->sk);
572 struct net_device *dev; 567 struct net_device *dev;
@@ -590,41 +585,3 @@ cont:
590 585
591 return skb->len; 586 return skb->len;
592} 587}
593
594static struct genl_ops ieee802154_coordinator_ops[] = {
595 IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
596 IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
597 IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
598 IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
599 IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
600 IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
601 ieee802154_dump_iface),
602};
603
604/*
605 * No need to unregister as family unregistration will do it.
606 */
607int nl802154_mac_register(void)
608{
609 int i;
610 int rc;
611
612 rc = genl_register_mc_group(&nl802154_family,
613 &ieee802154_coord_mcgrp);
614 if (rc)
615 return rc;
616
617 rc = genl_register_mc_group(&nl802154_family,
618 &ieee802154_beacon_mcgrp);
619 if (rc)
620 return rc;
621
622 for (i = 0; i < ARRAY_SIZE(ieee802154_coordinator_ops); i++) {
623 rc = genl_register_ops(&nl802154_family,
624 &ieee802154_coordinator_ops[i]);
625 if (rc)
626 return rc;
627 }
628
629 return 0;
630}
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index 22b1a7058fd3..d08c7a43dcd1 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -77,8 +77,7 @@ out:
77 return -EMSGSIZE; 77 return -EMSGSIZE;
78} 78}
79 79
80static int ieee802154_list_phy(struct sk_buff *skb, 80int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info)
81 struct genl_info *info)
82{ 81{
83 /* Request for interface name, index, type, IEEE address, 82 /* Request for interface name, index, type, IEEE address,
84 PAN Id, short address */ 83 PAN Id, short address */
@@ -151,8 +150,7 @@ static int ieee802154_dump_phy_iter(struct wpan_phy *phy, void *_data)
151 return 0; 150 return 0;
152} 151}
153 152
154static int ieee802154_dump_phy(struct sk_buff *skb, 153int ieee802154_dump_phy(struct sk_buff *skb, struct netlink_callback *cb)
155 struct netlink_callback *cb)
156{ 154{
157 struct dump_phy_data data = { 155 struct dump_phy_data data = {
158 .cb = cb, 156 .cb = cb,
@@ -170,8 +168,7 @@ static int ieee802154_dump_phy(struct sk_buff *skb,
170 return skb->len; 168 return skb->len;
171} 169}
172 170
173static int ieee802154_add_iface(struct sk_buff *skb, 171int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
174 struct genl_info *info)
175{ 172{
176 struct sk_buff *msg; 173 struct sk_buff *msg;
177 struct wpan_phy *phy; 174 struct wpan_phy *phy;
@@ -273,8 +270,7 @@ out_dev:
273 return rc; 270 return rc;
274} 271}
275 272
276static int ieee802154_del_iface(struct sk_buff *skb, 273int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info)
277 struct genl_info *info)
278{ 274{
279 struct sk_buff *msg; 275 struct sk_buff *msg;
280 struct wpan_phy *phy; 276 struct wpan_phy *phy;
@@ -356,28 +352,3 @@ out_dev:
356 352
357 return rc; 353 return rc;
358} 354}
359
360static struct genl_ops ieee802154_phy_ops[] = {
361 IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy,
362 ieee802154_dump_phy),
363 IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface),
364 IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface),
365};
366
367/*
368 * No need to unregister as family unregistration will do it.
369 */
370int nl802154_phy_register(void)
371{
372 int i;
373 int rc;
374
375 for (i = 0; i < ARRAY_SIZE(ieee802154_phy_ops); i++) {
376 rc = genl_register_ops(&nl802154_family,
377 &ieee802154_phy_ops[i]);
378 if (rc)
379 return rc;
380 }
381
382 return 0;
383}