2019-05-27 09:55:21 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2009-06-08 16:18:49 +04:00
/*
2014-11-25 07:34:57 +03:00
* Netlink interface for IEEE 802.15 .4 stack
2009-06-08 16:18:49 +04:00
*
* Copyright 2007 , 2008 Siemens AG
*
* Written by :
* Sergey Lapin < slapin @ ossfans . org >
* Dmitry Eremin - Solenikov < dbaryshkov @ gmail . com >
2009-08-07 06:58:40 +04:00
* Maxim Osipov < maxim . osipov @ siemens . com >
2009-06-08 16:18:49 +04:00
*/
# include <linux/kernel.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/gfp.h>
2009-06-08 16:18:49 +04:00
# include <net/genetlink.h>
# include <linux/nl802154.h>
2009-09-14 18:17:36 +04:00
# include "ieee802154.h"
2009-06-08 16:18:49 +04:00
static unsigned int ieee802154_seq_num ;
2009-09-10 18:02:30 +04:00
static DEFINE_SPINLOCK ( ieee802154_seq_lock ) ;
2009-06-08 16:18:49 +04:00
/* Requests to userspace */
2009-09-14 18:17:36 +04:00
struct sk_buff * ieee802154_nl_create ( int flags , u8 req )
2009-06-08 16:18:49 +04:00
{
void * hdr ;
2012-06-28 07:57:45 +04:00
struct sk_buff * msg = nlmsg_new ( NLMSG_DEFAULT_SIZE , GFP_ATOMIC ) ;
2009-09-10 18:02:30 +04:00
unsigned long f ;
2009-06-08 16:18:49 +04:00
if ( ! msg )
return NULL ;
2009-09-10 18:02:30 +04:00
spin_lock_irqsave ( & ieee802154_seq_lock , f ) ;
2009-06-08 16:18:49 +04:00
hdr = genlmsg_put ( msg , 0 , ieee802154_seq_num + + ,
2014-07-02 07:31:09 +04:00
& nl802154_family , flags , req ) ;
2009-09-10 18:02:30 +04:00
spin_unlock_irqrestore ( & ieee802154_seq_lock , f ) ;
2009-06-08 16:18:49 +04:00
if ( ! hdr ) {
nlmsg_free ( msg ) ;
return NULL ;
}
return msg ;
}
2009-09-14 18:17:36 +04:00
int ieee802154_nl_mcast ( struct sk_buff * msg , unsigned int group )
2009-06-08 16:18:49 +04:00
{
2013-03-29 09:09:35 +04:00
struct nlmsghdr * nlh = nlmsg_hdr ( msg ) ;
void * hdr = genlmsg_data ( nlmsg_data ( nlh ) ) ;
2009-06-08 16:18:49 +04:00
2015-01-17 00:09:00 +03:00
genlmsg_end ( msg , hdr ) ;
2009-06-08 16:18:49 +04:00
2013-11-19 18:19:38 +04:00
return genlmsg_multicast ( & nl802154_family , msg , 0 , group , GFP_ATOMIC ) ;
2009-06-08 16:18:49 +04:00
}
2009-11-04 18:05:38 +03:00
struct sk_buff * ieee802154_nl_new_reply ( struct genl_info * info ,
2014-12-04 13:51:58 +03:00
int flags , u8 req )
2009-11-04 18:05:38 +03:00
{
void * hdr ;
2012-06-28 07:57:45 +04:00
struct sk_buff * msg = nlmsg_new ( NLMSG_DEFAULT_SIZE , GFP_ATOMIC ) ;
2009-11-04 18:05:38 +03:00
if ( ! msg )
return NULL ;
hdr = genlmsg_put_reply ( msg , info ,
2014-07-02 07:31:09 +04:00
& nl802154_family , flags , req ) ;
2009-11-04 18:05:38 +03:00
if ( ! hdr ) {
nlmsg_free ( msg ) ;
return NULL ;
}
return msg ;
}
int ieee802154_nl_reply ( struct sk_buff * msg , struct genl_info * info )
{
2013-03-29 09:09:35 +04:00
struct nlmsghdr * nlh = nlmsg_hdr ( msg ) ;
void * hdr = genlmsg_data ( nlmsg_data ( nlh ) ) ;
2009-11-04 18:05:38 +03:00
2015-01-17 00:09:00 +03:00
genlmsg_end ( msg , hdr ) ;
2009-11-04 18:05:38 +03:00
return genlmsg_reply ( msg , info ) ;
}
2020-10-03 00:49:54 +03:00
static const struct genl_small_ops ieee802154_ops [ ] = {
2013-11-14 20:14:41 +04:00
/* 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 ) ,
2014-03-31 23:37:46 +04:00
IEEE802154_OP ( IEEE802154_SET_MACPARAMS , ieee802154_set_macparams ) ,
2014-05-16 19:46:44 +04:00
IEEE802154_OP ( IEEE802154_LLSEC_GETPARAMS , ieee802154_llsec_getparams ) ,
IEEE802154_OP ( IEEE802154_LLSEC_SETPARAMS , ieee802154_llsec_setparams ) ,
IEEE802154_DUMP ( IEEE802154_LLSEC_LIST_KEY , NULL ,
ieee802154_llsec_dump_keys ) ,
IEEE802154_OP ( IEEE802154_LLSEC_ADD_KEY , ieee802154_llsec_add_key ) ,
IEEE802154_OP ( IEEE802154_LLSEC_DEL_KEY , ieee802154_llsec_del_key ) ,
IEEE802154_DUMP ( IEEE802154_LLSEC_LIST_DEV , NULL ,
ieee802154_llsec_dump_devs ) ,
IEEE802154_OP ( IEEE802154_LLSEC_ADD_DEV , ieee802154_llsec_add_dev ) ,
IEEE802154_OP ( IEEE802154_LLSEC_DEL_DEV , ieee802154_llsec_del_dev ) ,
IEEE802154_DUMP ( IEEE802154_LLSEC_LIST_DEVKEY , NULL ,
ieee802154_llsec_dump_devkeys ) ,
IEEE802154_OP ( IEEE802154_LLSEC_ADD_DEVKEY , ieee802154_llsec_add_devkey ) ,
IEEE802154_OP ( IEEE802154_LLSEC_DEL_DEVKEY , ieee802154_llsec_del_devkey ) ,
IEEE802154_DUMP ( IEEE802154_LLSEC_LIST_SECLEVEL , NULL ,
ieee802154_llsec_dump_seclevels ) ,
IEEE802154_OP ( IEEE802154_LLSEC_ADD_SECLEVEL ,
ieee802154_llsec_add_seclevel ) ,
IEEE802154_OP ( IEEE802154_LLSEC_DEL_SECLEVEL ,
ieee802154_llsec_del_seclevel ) ,
2013-11-14 20:14:41 +04:00
} ;
2013-11-19 18:19:39 +04:00
static const struct genl_multicast_group ieee802154_mcgrps [ ] = {
[ IEEE802154_COORD_MCGRP ] = { . name = IEEE802154_MCAST_COORD_NAME , } ,
[ IEEE802154_BEACON_MCGRP ] = { . name = IEEE802154_MCAST_BEACON_NAME , } ,
} ;
2009-06-08 16:18:49 +04:00
2016-10-24 15:40:05 +03:00
struct genl_family nl802154_family __ro_after_init = {
2016-10-24 15:40:03 +03:00
. hdrsize = 0 ,
. name = IEEE802154_NL_NAME ,
. version = 1 ,
. maxattr = IEEE802154_ATTR_MAX ,
genetlink: make policy common to family
Since maxattr is common, the policy can't really differ sanely,
so make it common as well.
The only user that did in fact manage to make a non-common policy
is taskstats, which has to be really careful about it (since it's
still using a common maxattr!). This is no longer supported, but
we can fake it using pre_doit.
This reduces the size of e.g. nl80211.o (which has lots of commands):
text data bss dec hex filename
398745 14323 2240 415308 6564c net/wireless/nl80211.o (before)
397913 14331 2240 414484 65314 net/wireless/nl80211.o (after)
--------------------------------
-832 +8 0 -824
Which is obviously just 8 bytes for each command, and an added 8
bytes for the new policy pointer. I'm not sure why the ops list is
counted as .text though.
Most of the code transformations were done using the following spatch:
@ops@
identifier OPS;
expression POLICY;
@@
struct genl_ops OPS[] = {
...,
{
- .policy = POLICY,
},
...
};
@@
identifier ops.OPS;
expression ops.POLICY;
identifier fam;
expression M;
@@
struct genl_family fam = {
.ops = OPS,
.maxattr = M,
+ .policy = POLICY,
...
};
This also gets rid of devlink_nl_cmd_region_read_dumpit() accessing
the cb->data as ops, which we want to change in a later genl patch.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-03-22 00:51:02 +03:00
. policy = ieee802154_policy ,
2016-10-24 15:40:03 +03:00
. module = THIS_MODULE ,
2020-10-03 00:49:54 +03:00
. small_ops = ieee802154_ops ,
. n_small_ops = ARRAY_SIZE ( ieee802154_ops ) ,
2022-08-25 03:18:30 +03:00
. resv_start_op = IEEE802154_LLSEC_DEL_SECLEVEL + 1 ,
2016-10-24 15:40:03 +03:00
. mcgrps = ieee802154_mcgrps ,
. n_mcgrps = ARRAY_SIZE ( ieee802154_mcgrps ) ,
} ;
2013-11-19 18:19:39 +04:00
int __init ieee802154_nl_init ( void )
{
2016-10-24 15:40:03 +03:00
return genl_register_family ( & nl802154_family ) ;
2009-06-08 16:18:49 +04:00
}
2014-11-09 10:36:53 +03:00
void ieee802154_nl_exit ( void )
2009-06-08 16:18:49 +04:00
{
2009-09-14 18:17:36 +04:00
genl_unregister_family ( & nl802154_family ) ;
2009-06-08 16:18:49 +04:00
}