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>
This commit is contained in:
parent
9504b3ee1c
commit
1c582d915d
@ -47,7 +47,22 @@ struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
|
|||||||
int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info);
|
int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info);
|
||||||
|
|
||||||
extern struct genl_family nl802154_family;
|
extern struct genl_family nl802154_family;
|
||||||
int nl802154_mac_register(void);
|
|
||||||
int nl802154_phy_register(void);
|
/* genetlink ops/groups */
|
||||||
|
int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int ieee802154_dump_phy(struct sk_buff *skb, struct netlink_callback *cb);
|
||||||
|
int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
|
||||||
|
extern struct genl_multicast_group ieee802154_coord_mcgrp;
|
||||||
|
extern struct genl_multicast_group ieee802154_beacon_mcgrp;
|
||||||
|
|
||||||
|
int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -109,24 +109,39 @@ out:
|
|||||||
return -ENOBUFS;
|
return -ENOBUFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct genl_ops ieee8021154_ops[] = {
|
||||||
|
/* see nl-phy.c */
|
||||||
|
IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy,
|
||||||
|
ieee802154_dump_phy),
|
||||||
|
IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface),
|
||||||
|
IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface),
|
||||||
|
/* see nl-mac.c */
|
||||||
|
IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
|
||||||
|
IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
|
||||||
|
IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
|
||||||
|
IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
|
||||||
|
IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
|
||||||
|
IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
|
||||||
|
ieee802154_dump_iface),
|
||||||
|
};
|
||||||
|
|
||||||
int __init ieee802154_nl_init(void)
|
int __init ieee802154_nl_init(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = genl_register_family(&nl802154_family);
|
rc = genl_register_family_with_ops(&nl802154_family, ieee8021154_ops,
|
||||||
|
ARRAY_SIZE(ieee8021154_ops));
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
rc = genl_register_mc_group(&nl802154_family, &ieee802154_coord_mcgrp);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
rc = nl802154_mac_register();
|
rc = genl_register_mc_group(&nl802154_family, &ieee802154_beacon_mcgrp);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
rc = nl802154_phy_register();
|
|
||||||
if (rc)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
genl_unregister_family(&nl802154_family);
|
genl_unregister_family(&nl802154_family);
|
||||||
return rc;
|
return rc;
|
||||||
@ -136,4 +151,3 @@ void __exit ieee802154_nl_exit(void)
|
|||||||
{
|
{
|
||||||
genl_unregister_family(&nl802154_family);
|
genl_unregister_family(&nl802154_family);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@
|
|||||||
|
|
||||||
#include "ieee802154.h"
|
#include "ieee802154.h"
|
||||||
|
|
||||||
static struct genl_multicast_group ieee802154_coord_mcgrp = {
|
struct genl_multicast_group ieee802154_coord_mcgrp = {
|
||||||
.name = IEEE802154_MCAST_COORD_NAME,
|
.name = IEEE802154_MCAST_COORD_NAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct genl_multicast_group ieee802154_beacon_mcgrp = {
|
struct genl_multicast_group ieee802154_beacon_mcgrp = {
|
||||||
.name = IEEE802154_MCAST_BEACON_NAME,
|
.name = IEEE802154_MCAST_BEACON_NAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -309,8 +309,7 @@ static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
|
|||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_associate_req(struct sk_buff *skb,
|
int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info)
|
||||||
struct genl_info *info)
|
|
||||||
{
|
{
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
struct ieee802154_addr addr;
|
struct ieee802154_addr addr;
|
||||||
@ -357,8 +356,7 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_associate_resp(struct sk_buff *skb,
|
int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info)
|
||||||
struct genl_info *info)
|
|
||||||
{
|
{
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
struct ieee802154_addr addr;
|
struct ieee802154_addr addr;
|
||||||
@ -390,8 +388,7 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_disassociate_req(struct sk_buff *skb,
|
int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
|
||||||
struct genl_info *info)
|
|
||||||
{
|
{
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
struct ieee802154_addr addr;
|
struct ieee802154_addr addr;
|
||||||
@ -433,7 +430,7 @@ out:
|
|||||||
* PAN_coordinator, battery_life_extension = 0,
|
* PAN_coordinator, battery_life_extension = 0,
|
||||||
* coord_realignment = 0, security_enable = 0
|
* coord_realignment = 0, security_enable = 0
|
||||||
*/
|
*/
|
||||||
static int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
|
int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
|
||||||
{
|
{
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
struct ieee802154_addr addr;
|
struct ieee802154_addr addr;
|
||||||
@ -492,7 +489,7 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
|
int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
|
||||||
{
|
{
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
int ret = -EOPNOTSUPP;
|
int ret = -EOPNOTSUPP;
|
||||||
@ -530,8 +527,7 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_list_iface(struct sk_buff *skb,
|
int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info)
|
||||||
struct genl_info *info)
|
|
||||||
{
|
{
|
||||||
/* Request for interface name, index, type, IEEE address,
|
/* Request for interface name, index, type, IEEE address,
|
||||||
PAN Id, short address */
|
PAN Id, short address */
|
||||||
@ -565,8 +561,7 @@ out_dev:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_dump_iface(struct sk_buff *skb,
|
int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
|
||||||
struct netlink_callback *cb)
|
|
||||||
{
|
{
|
||||||
struct net *net = sock_net(skb->sk);
|
struct net *net = sock_net(skb->sk);
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
@ -590,41 +585,3 @@ cont:
|
|||||||
|
|
||||||
return skb->len;
|
return skb->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct genl_ops ieee802154_coordinator_ops[] = {
|
|
||||||
IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
|
|
||||||
IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
|
|
||||||
IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
|
|
||||||
IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
|
|
||||||
IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
|
|
||||||
IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
|
|
||||||
ieee802154_dump_iface),
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* No need to unregister as family unregistration will do it.
|
|
||||||
*/
|
|
||||||
int nl802154_mac_register(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = genl_register_mc_group(&nl802154_family,
|
|
||||||
&ieee802154_coord_mcgrp);
|
|
||||||
if (rc)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
rc = genl_register_mc_group(&nl802154_family,
|
|
||||||
&ieee802154_beacon_mcgrp);
|
|
||||||
if (rc)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(ieee802154_coordinator_ops); i++) {
|
|
||||||
rc = genl_register_ops(&nl802154_family,
|
|
||||||
&ieee802154_coordinator_ops[i]);
|
|
||||||
if (rc)
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
@ -77,8 +77,7 @@ out:
|
|||||||
return -EMSGSIZE;
|
return -EMSGSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_list_phy(struct sk_buff *skb,
|
int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info)
|
||||||
struct genl_info *info)
|
|
||||||
{
|
{
|
||||||
/* Request for interface name, index, type, IEEE address,
|
/* Request for interface name, index, type, IEEE address,
|
||||||
PAN Id, short address */
|
PAN Id, short address */
|
||||||
@ -151,8 +150,7 @@ static int ieee802154_dump_phy_iter(struct wpan_phy *phy, void *_data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_dump_phy(struct sk_buff *skb,
|
int ieee802154_dump_phy(struct sk_buff *skb, struct netlink_callback *cb)
|
||||||
struct netlink_callback *cb)
|
|
||||||
{
|
{
|
||||||
struct dump_phy_data data = {
|
struct dump_phy_data data = {
|
||||||
.cb = cb,
|
.cb = cb,
|
||||||
@ -170,8 +168,7 @@ static int ieee802154_dump_phy(struct sk_buff *skb,
|
|||||||
return skb->len;
|
return skb->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_add_iface(struct sk_buff *skb,
|
int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
|
||||||
struct genl_info *info)
|
|
||||||
{
|
{
|
||||||
struct sk_buff *msg;
|
struct sk_buff *msg;
|
||||||
struct wpan_phy *phy;
|
struct wpan_phy *phy;
|
||||||
@ -273,8 +270,7 @@ out_dev:
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ieee802154_del_iface(struct sk_buff *skb,
|
int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info)
|
||||||
struct genl_info *info)
|
|
||||||
{
|
{
|
||||||
struct sk_buff *msg;
|
struct sk_buff *msg;
|
||||||
struct wpan_phy *phy;
|
struct wpan_phy *phy;
|
||||||
@ -356,28 +352,3 @@ out_dev:
|
|||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct genl_ops ieee802154_phy_ops[] = {
|
|
||||||
IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy,
|
|
||||||
ieee802154_dump_phy),
|
|
||||||
IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface),
|
|
||||||
IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface),
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* No need to unregister as family unregistration will do it.
|
|
||||||
*/
|
|
||||||
int nl802154_phy_register(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(ieee802154_phy_ops); i++) {
|
|
||||||
rc = genl_register_ops(&nl802154_family,
|
|
||||||
&ieee802154_phy_ops[i]);
|
|
||||||
if (rc)
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user