License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2007-11-14 14:56:23 +08:00
|
|
|
/*
|
|
|
|
* IPv6 Address Label subsystem
|
|
|
|
* for the IPv6 "Default" Source Address Selection
|
|
|
|
*
|
|
|
|
* Copyright (C)2007 USAGI/WIDE Project
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Author:
|
2014-02-17 16:53:34 +08:00
|
|
|
* YOSHIFUJI Hideaki @ USAGI/WIDE Project <yoshfuji@linux-ipv6.org>
|
2007-11-14 14:56:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/in6.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2007-11-14 14:56:23 +08:00
|
|
|
#include <net/addrconf.h>
|
|
|
|
#include <linux/if_addrlabel.h>
|
|
|
|
#include <linux/netlink.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define ADDRLABEL(x...) printk(x)
|
|
|
|
#else
|
2014-02-17 16:53:34 +08:00
|
|
|
#define ADDRLABEL(x...) do { ; } while (0)
|
2007-11-14 14:56:23 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Policy Table
|
|
|
|
*/
|
2014-02-17 16:53:33 +08:00
|
|
|
struct ip6addrlbl_entry {
|
2007-11-14 14:56:23 +08:00
|
|
|
struct in6_addr prefix;
|
|
|
|
int prefixlen;
|
|
|
|
int ifindex;
|
|
|
|
int addrtype;
|
|
|
|
u32 label;
|
|
|
|
struct hlist_node list;
|
|
|
|
struct rcu_head rcu;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2012-09-11 02:16:49 +08:00
|
|
|
* Default policy table (RFC6724 + extensions)
|
2007-11-14 14:56:23 +08:00
|
|
|
*
|
|
|
|
* prefix addr_type label
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
* ::1/128 LOOPBACK 0
|
|
|
|
* ::/0 N/A 1
|
|
|
|
* 2002::/16 N/A 2
|
|
|
|
* ::/96 COMPATv4 3
|
|
|
|
* ::ffff:0:0/96 V4MAPPED 4
|
|
|
|
* fc00::/7 N/A 5 ULA (RFC 4193)
|
|
|
|
* 2001::/32 N/A 6 Teredo (RFC 4380)
|
2008-02-29 12:55:02 +08:00
|
|
|
* 2001:10::/28 N/A 7 ORCHID (RFC 4843)
|
2012-09-11 02:16:49 +08:00
|
|
|
* fec0::/10 N/A 11 Site-local
|
|
|
|
* (deprecated by RFC3879)
|
|
|
|
* 3ffe::/16 N/A 12 6bone
|
2007-11-14 14:56:23 +08:00
|
|
|
*
|
|
|
|
* Note: 0xffffffff is used if we do not have any policies.
|
2012-09-11 02:16:49 +08:00
|
|
|
* Note: Labels for ULA and 6to4 are different from labels listed in RFC6724.
|
2007-11-14 14:56:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define IPV6_ADDR_LABEL_DEFAULT 0xffffffffUL
|
|
|
|
|
2012-10-05 08:12:11 +08:00
|
|
|
static const __net_initconst struct ip6addrlbl_init_table
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
const struct in6_addr *prefix;
|
|
|
|
int prefixlen;
|
|
|
|
u32 label;
|
|
|
|
} ip6addrlbl_init_table[] = {
|
|
|
|
{ /* ::/0 */
|
|
|
|
.prefix = &in6addr_any,
|
|
|
|
.label = 1,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* fc00::/7 */
|
|
|
|
.prefix = &(struct in6_addr){ { { 0xfc } } } ,
|
2007-11-14 14:56:23 +08:00
|
|
|
.prefixlen = 7,
|
|
|
|
.label = 5,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* fec0::/10 */
|
|
|
|
.prefix = &(struct in6_addr){ { { 0xfe, 0xc0 } } },
|
2012-09-11 02:16:49 +08:00
|
|
|
.prefixlen = 10,
|
|
|
|
.label = 11,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* 2002::/16 */
|
|
|
|
.prefix = &(struct in6_addr){ { { 0x20, 0x02 } } },
|
2007-11-14 14:56:23 +08:00
|
|
|
.prefixlen = 16,
|
|
|
|
.label = 2,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* 3ffe::/16 */
|
|
|
|
.prefix = &(struct in6_addr){ { { 0x3f, 0xfe } } },
|
2012-09-11 02:16:49 +08:00
|
|
|
.prefixlen = 16,
|
|
|
|
.label = 12,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* 2001::/32 */
|
|
|
|
.prefix = &(struct in6_addr){ { { 0x20, 0x01 } } },
|
2007-11-14 14:56:23 +08:00
|
|
|
.prefixlen = 32,
|
|
|
|
.label = 6,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* 2001:10::/28 */
|
|
|
|
.prefix = &(struct in6_addr){ { { 0x20, 0x01, 0x00, 0x10 } } },
|
2008-02-29 12:55:02 +08:00
|
|
|
.prefixlen = 28,
|
|
|
|
.label = 7,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* ::ffff:0:0 */
|
|
|
|
.prefix = &(struct in6_addr){ { { [10] = 0xff, [11] = 0xff } } },
|
2007-11-14 14:56:23 +08:00
|
|
|
.prefixlen = 96,
|
|
|
|
.label = 4,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* ::/96 */
|
2007-11-14 14:56:23 +08:00
|
|
|
.prefix = &in6addr_any,
|
|
|
|
.prefixlen = 96,
|
|
|
|
.label = 3,
|
2014-02-17 16:53:34 +08:00
|
|
|
}, { /* ::1/128 */
|
2007-11-14 14:56:23 +08:00
|
|
|
.prefix = &in6addr_loopback,
|
|
|
|
.prefixlen = 128,
|
|
|
|
.label = 0,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Find label */
|
2017-09-20 07:27:06 +08:00
|
|
|
static bool __ip6addrlbl_match(const struct ip6addrlbl_entry *p,
|
2012-05-19 02:57:34 +08:00
|
|
|
const struct in6_addr *addr,
|
|
|
|
int addrtype, int ifindex)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
if (p->ifindex && p->ifindex != ifindex)
|
2012-05-19 02:57:34 +08:00
|
|
|
return false;
|
2007-11-14 14:56:23 +08:00
|
|
|
if (p->addrtype && p->addrtype != addrtype)
|
2012-05-19 02:57:34 +08:00
|
|
|
return false;
|
2007-11-14 14:56:23 +08:00
|
|
|
if (!ipv6_prefix_equal(addr, &p->prefix, p->prefixlen))
|
2012-05-19 02:57:34 +08:00
|
|
|
return false;
|
|
|
|
return true;
|
2007-11-14 14:56:23 +08:00
|
|
|
}
|
|
|
|
|
2008-05-28 20:51:24 +08:00
|
|
|
static struct ip6addrlbl_entry *__ipv6_addr_label(struct net *net,
|
|
|
|
const struct in6_addr *addr,
|
2007-11-14 14:56:23 +08:00
|
|
|
int type, int ifindex)
|
|
|
|
{
|
|
|
|
struct ip6addrlbl_entry *p;
|
2017-09-20 07:27:06 +08:00
|
|
|
|
|
|
|
hlist_for_each_entry_rcu(p, &net->ipv6.ip6addrlbl_table.head, list) {
|
|
|
|
if (__ip6addrlbl_match(p, addr, type, ifindex))
|
2007-11-14 14:56:23 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-28 20:51:24 +08:00
|
|
|
u32 ipv6_addr_label(struct net *net,
|
|
|
|
const struct in6_addr *addr, int type, int ifindex)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
u32 label;
|
|
|
|
struct ip6addrlbl_entry *p;
|
|
|
|
|
|
|
|
type &= IPV6_ADDR_MAPPED | IPV6_ADDR_COMPATv4 | IPV6_ADDR_LOOPBACK;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2008-05-28 20:51:24 +08:00
|
|
|
p = __ipv6_addr_label(net, addr, type, ifindex);
|
2007-11-14 14:56:23 +08:00
|
|
|
label = p ? p->label : IPV6_ADDR_LABEL_DEFAULT;
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
2008-10-30 03:52:50 +08:00
|
|
|
ADDRLABEL(KERN_DEBUG "%s(addr=%pI6, type=%d, ifindex=%d) => %08x\n",
|
2008-10-29 07:09:23 +08:00
|
|
|
__func__, addr, type, ifindex, label);
|
2007-11-14 14:56:23 +08:00
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate one entry */
|
2017-09-20 07:27:06 +08:00
|
|
|
static struct ip6addrlbl_entry *ip6addrlbl_alloc(const struct in6_addr *prefix,
|
2008-01-22 16:12:50 +08:00
|
|
|
int prefixlen, int ifindex,
|
|
|
|
u32 label)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
struct ip6addrlbl_entry *newp;
|
|
|
|
int addrtype;
|
|
|
|
|
2008-10-30 03:52:50 +08:00
|
|
|
ADDRLABEL(KERN_DEBUG "%s(prefix=%pI6, prefixlen=%d, ifindex=%d, label=%u)\n",
|
2008-10-29 07:09:23 +08:00
|
|
|
__func__, prefix, prefixlen, ifindex, (unsigned int)label);
|
2007-11-14 14:56:23 +08:00
|
|
|
|
|
|
|
addrtype = ipv6_addr_type(prefix) & (IPV6_ADDR_MAPPED | IPV6_ADDR_COMPATv4 | IPV6_ADDR_LOOPBACK);
|
|
|
|
|
|
|
|
switch (addrtype) {
|
|
|
|
case IPV6_ADDR_MAPPED:
|
|
|
|
if (prefixlen > 96)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
if (prefixlen < 96)
|
|
|
|
addrtype = 0;
|
|
|
|
break;
|
|
|
|
case IPV6_ADDR_COMPATv4:
|
|
|
|
if (prefixlen != 96)
|
|
|
|
addrtype = 0;
|
|
|
|
break;
|
|
|
|
case IPV6_ADDR_LOOPBACK:
|
|
|
|
if (prefixlen != 128)
|
|
|
|
addrtype = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
newp = kmalloc(sizeof(*newp), GFP_KERNEL);
|
|
|
|
if (!newp)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
ipv6_addr_prefix(&newp->prefix, prefix, prefixlen);
|
|
|
|
newp->prefixlen = prefixlen;
|
|
|
|
newp->ifindex = ifindex;
|
|
|
|
newp->addrtype = addrtype;
|
|
|
|
newp->label = label;
|
|
|
|
INIT_HLIST_NODE(&newp->list);
|
|
|
|
return newp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add a label */
|
2017-09-20 07:27:06 +08:00
|
|
|
static int __ip6addrlbl_add(struct net *net, struct ip6addrlbl_entry *newp,
|
|
|
|
int replace)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
2013-09-03 08:13:31 +08:00
|
|
|
struct ip6addrlbl_entry *last = NULL, *p = NULL;
|
2017-09-20 07:27:06 +08:00
|
|
|
struct hlist_node *n;
|
2007-11-14 14:56:23 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2013-09-03 08:13:31 +08:00
|
|
|
ADDRLABEL(KERN_DEBUG "%s(newp=%p, replace=%d)\n", __func__, newp,
|
|
|
|
replace);
|
2007-11-14 14:56:23 +08:00
|
|
|
|
2017-09-20 07:27:06 +08:00
|
|
|
hlist_for_each_entry_safe(p, n, &net->ipv6.ip6addrlbl_table.head, list) {
|
2013-09-03 08:13:31 +08:00
|
|
|
if (p->prefixlen == newp->prefixlen &&
|
|
|
|
p->ifindex == newp->ifindex &&
|
|
|
|
ipv6_addr_equal(&p->prefix, &newp->prefix)) {
|
|
|
|
if (!replace) {
|
|
|
|
ret = -EEXIST;
|
2007-11-14 14:56:23 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2013-09-03 08:13:31 +08:00
|
|
|
hlist_replace_rcu(&p->list, &newp->list);
|
2017-10-10 00:52:25 +08:00
|
|
|
kfree_rcu(p, rcu);
|
2013-09-03 08:13:31 +08:00
|
|
|
goto out;
|
|
|
|
} else if ((p->prefixlen == newp->prefixlen && !p->ifindex) ||
|
|
|
|
(p->prefixlen < newp->prefixlen)) {
|
|
|
|
hlist_add_before_rcu(&newp->list, &p->list);
|
|
|
|
goto out;
|
2007-11-14 14:56:23 +08:00
|
|
|
}
|
2013-09-03 08:13:31 +08:00
|
|
|
last = p;
|
2007-11-14 14:56:23 +08:00
|
|
|
}
|
2013-09-03 08:13:31 +08:00
|
|
|
if (last)
|
2014-08-07 07:09:16 +08:00
|
|
|
hlist_add_behind_rcu(&newp->list, &last->list);
|
2013-09-03 08:13:31 +08:00
|
|
|
else
|
2017-09-20 07:27:06 +08:00
|
|
|
hlist_add_head_rcu(&newp->list, &net->ipv6.ip6addrlbl_table.head);
|
2007-11-14 14:56:23 +08:00
|
|
|
out:
|
|
|
|
if (!ret)
|
2017-09-20 07:27:06 +08:00
|
|
|
net->ipv6.ip6addrlbl_table.seq++;
|
2007-11-14 14:56:23 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add a label */
|
2008-05-28 20:51:24 +08:00
|
|
|
static int ip6addrlbl_add(struct net *net,
|
|
|
|
const struct in6_addr *prefix, int prefixlen,
|
2008-01-22 16:12:50 +08:00
|
|
|
int ifindex, u32 label, int replace)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
struct ip6addrlbl_entry *newp;
|
|
|
|
int ret = 0;
|
|
|
|
|
2008-10-30 03:52:50 +08:00
|
|
|
ADDRLABEL(KERN_DEBUG "%s(prefix=%pI6, prefixlen=%d, ifindex=%d, label=%u, replace=%d)\n",
|
2008-10-29 07:09:23 +08:00
|
|
|
__func__, prefix, prefixlen, ifindex, (unsigned int)label,
|
|
|
|
replace);
|
2007-11-14 14:56:23 +08:00
|
|
|
|
2017-09-20 07:27:06 +08:00
|
|
|
newp = ip6addrlbl_alloc(prefix, prefixlen, ifindex, label);
|
2007-11-14 14:56:23 +08:00
|
|
|
if (IS_ERR(newp))
|
|
|
|
return PTR_ERR(newp);
|
2017-09-20 07:27:06 +08:00
|
|
|
spin_lock(&net->ipv6.ip6addrlbl_table.lock);
|
|
|
|
ret = __ip6addrlbl_add(net, newp, replace);
|
|
|
|
spin_unlock(&net->ipv6.ip6addrlbl_table.lock);
|
2007-11-14 14:56:23 +08:00
|
|
|
if (ret)
|
2017-10-10 00:52:25 +08:00
|
|
|
kfree(newp);
|
2007-11-14 14:56:23 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove a label */
|
2008-05-28 20:51:24 +08:00
|
|
|
static int __ip6addrlbl_del(struct net *net,
|
|
|
|
const struct in6_addr *prefix, int prefixlen,
|
2008-01-22 16:12:50 +08:00
|
|
|
int ifindex)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
struct ip6addrlbl_entry *p = NULL;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
struct hlist_node *n;
|
2007-11-14 14:56:23 +08:00
|
|
|
int ret = -ESRCH;
|
|
|
|
|
2008-10-30 03:52:50 +08:00
|
|
|
ADDRLABEL(KERN_DEBUG "%s(prefix=%pI6, prefixlen=%d, ifindex=%d)\n",
|
2008-10-29 07:09:23 +08:00
|
|
|
__func__, prefix, prefixlen, ifindex);
|
2007-11-14 14:56:23 +08:00
|
|
|
|
2017-09-20 07:27:06 +08:00
|
|
|
hlist_for_each_entry_safe(p, n, &net->ipv6.ip6addrlbl_table.head, list) {
|
2007-11-14 14:56:23 +08:00
|
|
|
if (p->prefixlen == prefixlen &&
|
|
|
|
p->ifindex == ifindex &&
|
|
|
|
ipv6_addr_equal(&p->prefix, prefix)) {
|
|
|
|
hlist_del_rcu(&p->list);
|
2017-10-10 00:52:25 +08:00
|
|
|
kfree_rcu(p, rcu);
|
2007-11-14 14:56:23 +08:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-28 20:51:24 +08:00
|
|
|
static int ip6addrlbl_del(struct net *net,
|
|
|
|
const struct in6_addr *prefix, int prefixlen,
|
2008-01-22 16:12:50 +08:00
|
|
|
int ifindex)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
struct in6_addr prefix_buf;
|
|
|
|
int ret;
|
|
|
|
|
2008-10-30 03:52:50 +08:00
|
|
|
ADDRLABEL(KERN_DEBUG "%s(prefix=%pI6, prefixlen=%d, ifindex=%d)\n",
|
2008-10-29 07:09:23 +08:00
|
|
|
__func__, prefix, prefixlen, ifindex);
|
2007-11-14 14:56:23 +08:00
|
|
|
|
|
|
|
ipv6_addr_prefix(&prefix_buf, prefix, prefixlen);
|
2017-09-20 07:27:06 +08:00
|
|
|
spin_lock(&net->ipv6.ip6addrlbl_table.lock);
|
2008-05-28 20:51:24 +08:00
|
|
|
ret = __ip6addrlbl_del(net, &prefix_buf, prefixlen, ifindex);
|
2017-09-20 07:27:06 +08:00
|
|
|
spin_unlock(&net->ipv6.ip6addrlbl_table.lock);
|
2007-11-14 14:56:23 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add default label */
|
2008-05-28 20:51:24 +08:00
|
|
|
static int __net_init ip6addrlbl_net_init(struct net *net)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int i;
|
|
|
|
|
2012-05-15 22:11:53 +08:00
|
|
|
ADDRLABEL(KERN_DEBUG "%s\n", __func__);
|
2007-11-14 14:56:23 +08:00
|
|
|
|
2017-09-20 07:27:06 +08:00
|
|
|
spin_lock_init(&net->ipv6.ip6addrlbl_table.lock);
|
|
|
|
INIT_HLIST_HEAD(&net->ipv6.ip6addrlbl_table.head);
|
|
|
|
|
2007-11-14 14:56:23 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ip6addrlbl_init_table); i++) {
|
2008-05-28 20:51:24 +08:00
|
|
|
int ret = ip6addrlbl_add(net,
|
|
|
|
ip6addrlbl_init_table[i].prefix,
|
2007-11-14 14:56:23 +08:00
|
|
|
ip6addrlbl_init_table[i].prefixlen,
|
|
|
|
0,
|
|
|
|
ip6addrlbl_init_table[i].label, 0);
|
|
|
|
/* XXX: should we free all rules when we catch an error? */
|
|
|
|
if (ret && (!err || err != -ENOMEM))
|
|
|
|
err = ret;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-05-28 20:51:24 +08:00
|
|
|
static void __net_exit ip6addrlbl_net_exit(struct net *net)
|
|
|
|
{
|
|
|
|
struct ip6addrlbl_entry *p = NULL;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
struct hlist_node *n;
|
2008-05-28 20:51:24 +08:00
|
|
|
|
|
|
|
/* Remove all labels belonging to the exiting net */
|
2017-09-20 07:27:06 +08:00
|
|
|
spin_lock(&net->ipv6.ip6addrlbl_table.lock);
|
|
|
|
hlist_for_each_entry_safe(p, n, &net->ipv6.ip6addrlbl_table.head, list) {
|
|
|
|
hlist_del_rcu(&p->list);
|
2017-10-10 00:52:25 +08:00
|
|
|
kfree_rcu(p, rcu);
|
2008-05-28 20:51:24 +08:00
|
|
|
}
|
2017-09-20 07:27:06 +08:00
|
|
|
spin_unlock(&net->ipv6.ip6addrlbl_table.lock);
|
2008-05-28 20:51:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations ipv6_addr_label_ops = {
|
|
|
|
.init = ip6addrlbl_net_init,
|
|
|
|
.exit = ip6addrlbl_net_exit,
|
|
|
|
};
|
|
|
|
|
2007-11-14 14:56:23 +08:00
|
|
|
int __init ipv6_addr_label_init(void)
|
|
|
|
{
|
2008-05-28 20:51:24 +08:00
|
|
|
return register_pernet_subsys(&ipv6_addr_label_ops);
|
2007-11-14 14:56:23 +08:00
|
|
|
}
|
|
|
|
|
2010-09-24 17:55:52 +08:00
|
|
|
void ipv6_addr_label_cleanup(void)
|
|
|
|
{
|
|
|
|
unregister_pernet_subsys(&ipv6_addr_label_ops);
|
|
|
|
}
|
|
|
|
|
2007-11-14 14:56:23 +08:00
|
|
|
static const struct nla_policy ifal_policy[IFAL_MAX+1] = {
|
|
|
|
[IFAL_ADDRESS] = { .len = sizeof(struct in6_addr), },
|
|
|
|
[IFAL_LABEL] = { .len = sizeof(u32), },
|
|
|
|
};
|
|
|
|
|
2017-08-29 19:29:42 +08:00
|
|
|
static bool addrlbl_ifindex_exists(struct net *net, int ifindex)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
dev = dev_get_by_index_rcu(net, ifindex);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return dev != NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-17 00:48:24 +08:00
|
|
|
static int ip6addrlbl_newdel(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|
|
|
struct netlink_ext_ack *extack)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
2008-03-26 01:26:21 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2007-11-14 14:56:23 +08:00
|
|
|
struct ifaddrlblmsg *ifal;
|
|
|
|
struct nlattr *tb[IFAL_MAX+1];
|
|
|
|
struct in6_addr *pfx;
|
|
|
|
u32 label;
|
|
|
|
int err = 0;
|
|
|
|
|
2017-04-17 00:48:24 +08:00
|
|
|
err = nlmsg_parse(nlh, sizeof(*ifal), tb, IFAL_MAX, ifal_policy,
|
|
|
|
extack);
|
2007-11-14 14:56:23 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
ifal = nlmsg_data(nlh);
|
|
|
|
|
|
|
|
if (ifal->ifal_family != AF_INET6 ||
|
|
|
|
ifal->ifal_prefixlen > 128)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!tb[IFAL_ADDRESS])
|
|
|
|
return -EINVAL;
|
|
|
|
pfx = nla_data(tb[IFAL_ADDRESS]);
|
|
|
|
|
|
|
|
if (!tb[IFAL_LABEL])
|
|
|
|
return -EINVAL;
|
|
|
|
label = nla_get_u32(tb[IFAL_LABEL]);
|
|
|
|
if (label == IPV6_ADDR_LABEL_DEFAULT)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-02-17 16:53:34 +08:00
|
|
|
switch (nlh->nlmsg_type) {
|
2007-11-14 14:56:23 +08:00
|
|
|
case RTM_NEWADDRLABEL:
|
2010-05-07 19:31:33 +08:00
|
|
|
if (ifal->ifal_index &&
|
2017-08-29 19:29:42 +08:00
|
|
|
!addrlbl_ifindex_exists(net, ifal->ifal_index))
|
2010-05-07 19:31:33 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2008-05-28 20:51:24 +08:00
|
|
|
err = ip6addrlbl_add(net, pfx, ifal->ifal_prefixlen,
|
2007-11-14 14:56:23 +08:00
|
|
|
ifal->ifal_index, label,
|
|
|
|
nlh->nlmsg_flags & NLM_F_REPLACE);
|
|
|
|
break;
|
|
|
|
case RTM_DELADDRLABEL:
|
2008-05-28 20:51:24 +08:00
|
|
|
err = ip6addrlbl_del(net, pfx, ifal->ifal_prefixlen,
|
2007-11-14 14:56:23 +08:00
|
|
|
ifal->ifal_index);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-05-19 02:57:34 +08:00
|
|
|
static void ip6addrlbl_putmsg(struct nlmsghdr *nlh,
|
|
|
|
int prefixlen, int ifindex, u32 lseq)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
|
|
|
struct ifaddrlblmsg *ifal = nlmsg_data(nlh);
|
|
|
|
ifal->ifal_family = AF_INET6;
|
|
|
|
ifal->ifal_prefixlen = prefixlen;
|
|
|
|
ifal->ifal_flags = 0;
|
|
|
|
ifal->ifal_index = ifindex;
|
|
|
|
ifal->ifal_seq = lseq;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ip6addrlbl_fill(struct sk_buff *skb,
|
|
|
|
struct ip6addrlbl_entry *p,
|
|
|
|
u32 lseq,
|
2012-09-08 04:12:54 +08:00
|
|
|
u32 portid, u32 seq, int event,
|
2007-11-14 14:56:23 +08:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2012-09-08 04:12:54 +08:00
|
|
|
struct nlmsghdr *nlh = nlmsg_put(skb, portid, seq, event,
|
2007-11-14 14:56:23 +08:00
|
|
|
sizeof(struct ifaddrlblmsg), flags);
|
|
|
|
if (!nlh)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
ip6addrlbl_putmsg(nlh, p->prefixlen, p->ifindex, lseq);
|
|
|
|
|
2015-03-29 22:59:25 +08:00
|
|
|
if (nla_put_in6_addr(skb, IFAL_ADDRESS, &p->prefix) < 0 ||
|
2007-11-14 14:56:23 +08:00
|
|
|
nla_put_u32(skb, IFAL_LABEL, p->label) < 0) {
|
|
|
|
nlmsg_cancel(skb, nlh);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:09:00 +08:00
|
|
|
nlmsg_end(skb, nlh);
|
|
|
|
return 0;
|
2007-11-14 14:56:23 +08:00
|
|
|
}
|
|
|
|
|
2018-10-08 11:16:40 +08:00
|
|
|
static int ip6addrlbl_valid_dump_req(const struct nlmsghdr *nlh,
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
{
|
|
|
|
struct ifaddrlblmsg *ifal;
|
|
|
|
|
|
|
|
if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifal))) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid header for address label dump request");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifal = nlmsg_data(nlh);
|
|
|
|
if (ifal->__ifal_reserved || ifal->ifal_prefixlen ||
|
|
|
|
ifal->ifal_flags || ifal->ifal_index || ifal->ifal_seq) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for address label dump request");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nlmsg_attrlen(nlh, sizeof(*ifal))) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid data after header for address label dump requewst");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-14 14:56:23 +08:00
|
|
|
static int ip6addrlbl_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
2018-10-08 11:16:40 +08:00
|
|
|
const struct nlmsghdr *nlh = cb->nlh;
|
2008-03-26 01:26:21 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2007-11-14 14:56:23 +08:00
|
|
|
struct ip6addrlbl_entry *p;
|
|
|
|
int idx = 0, s_idx = cb->args[0];
|
|
|
|
int err;
|
|
|
|
|
2018-10-08 11:16:40 +08:00
|
|
|
if (cb->strict_check) {
|
|
|
|
err = ip6addrlbl_valid_dump_req(nlh, cb->extack);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-11-14 14:56:23 +08:00
|
|
|
rcu_read_lock();
|
2017-09-20 07:27:06 +08:00
|
|
|
hlist_for_each_entry_rcu(p, &net->ipv6.ip6addrlbl_table.head, list) {
|
|
|
|
if (idx >= s_idx) {
|
2014-02-17 16:53:35 +08:00
|
|
|
err = ip6addrlbl_fill(skb, p,
|
2017-09-20 07:27:06 +08:00
|
|
|
net->ipv6.ip6addrlbl_table.seq,
|
2014-02-17 16:53:35 +08:00
|
|
|
NETLINK_CB(cb->skb).portid,
|
2018-10-08 11:16:40 +08:00
|
|
|
nlh->nlmsg_seq,
|
2014-02-17 16:53:35 +08:00
|
|
|
RTM_NEWADDRLABEL,
|
|
|
|
NLM_F_MULTI);
|
2015-01-17 05:09:00 +08:00
|
|
|
if (err < 0)
|
2007-11-14 14:56:23 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
cb->args[0] = idx;
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ip6addrlbl_msgsize(void)
|
|
|
|
{
|
2010-09-23 04:43:57 +08:00
|
|
|
return NLMSG_ALIGN(sizeof(struct ifaddrlblmsg))
|
2007-11-14 14:56:23 +08:00
|
|
|
+ nla_total_size(16) /* IFAL_ADDRESS */
|
2010-09-23 04:43:57 +08:00
|
|
|
+ nla_total_size(4); /* IFAL_LABEL */
|
2007-11-14 14:56:23 +08:00
|
|
|
}
|
|
|
|
|
2019-01-19 02:46:23 +08:00
|
|
|
static int ip6addrlbl_valid_get_req(struct sk_buff *skb,
|
|
|
|
const struct nlmsghdr *nlh,
|
|
|
|
struct nlattr **tb,
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
{
|
|
|
|
struct ifaddrlblmsg *ifal;
|
|
|
|
int i, err;
|
|
|
|
|
|
|
|
if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifal))) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid header for addrlabel get request");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!netlink_strict_get_check(skb))
|
|
|
|
return nlmsg_parse(nlh, sizeof(*ifal), tb, IFAL_MAX,
|
|
|
|
ifal_policy, extack);
|
|
|
|
|
|
|
|
ifal = nlmsg_data(nlh);
|
|
|
|
if (ifal->__ifal_reserved || ifal->ifal_flags || ifal->ifal_seq) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for addrlabel get request");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = nlmsg_parse_strict(nlh, sizeof(*ifal), tb, IFAL_MAX,
|
|
|
|
ifal_policy, extack);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
for (i = 0; i <= IFAL_MAX; i++) {
|
|
|
|
if (!tb[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case IFAL_ADDRESS:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Unsupported attribute in addrlabel get request");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-17 00:48:24 +08:00
|
|
|
static int ip6addrlbl_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
|
|
|
|
struct netlink_ext_ack *extack)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
2008-03-26 01:26:21 +08:00
|
|
|
struct net *net = sock_net(in_skb->sk);
|
2007-11-14 14:56:23 +08:00
|
|
|
struct ifaddrlblmsg *ifal;
|
|
|
|
struct nlattr *tb[IFAL_MAX+1];
|
|
|
|
struct in6_addr *addr;
|
|
|
|
u32 lseq;
|
|
|
|
int err = 0;
|
|
|
|
struct ip6addrlbl_entry *p;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
2019-01-19 02:46:23 +08:00
|
|
|
err = ip6addrlbl_valid_get_req(in_skb, nlh, tb, extack);
|
2007-11-14 14:56:23 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
ifal = nlmsg_data(nlh);
|
|
|
|
|
|
|
|
if (ifal->ifal_family != AF_INET6 ||
|
|
|
|
ifal->ifal_prefixlen != 128)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (ifal->ifal_index &&
|
2017-08-29 19:29:42 +08:00
|
|
|
!addrlbl_ifindex_exists(net, ifal->ifal_index))
|
2007-11-14 14:56:23 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!tb[IFAL_ADDRESS])
|
|
|
|
return -EINVAL;
|
|
|
|
addr = nla_data(tb[IFAL_ADDRESS]);
|
|
|
|
|
2014-02-17 16:53:35 +08:00
|
|
|
skb = nlmsg_new(ip6addrlbl_msgsize(), GFP_KERNEL);
|
2017-10-10 00:52:24 +08:00
|
|
|
if (!skb)
|
2007-11-14 14:56:23 +08:00
|
|
|
return -ENOBUFS;
|
|
|
|
|
2017-10-10 00:52:24 +08:00
|
|
|
err = -ESRCH;
|
2007-11-14 14:56:23 +08:00
|
|
|
|
2017-10-10 00:52:24 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
p = __ipv6_addr_label(net, addr, ipv6_addr_type(addr), ifal->ifal_index);
|
|
|
|
lseq = net->ipv6.ip6addrlbl_table.seq;
|
|
|
|
if (p)
|
|
|
|
err = ip6addrlbl_fill(skb, p, lseq,
|
|
|
|
NETLINK_CB(in_skb).portid,
|
|
|
|
nlh->nlmsg_seq,
|
|
|
|
RTM_NEWADDRLABEL, 0);
|
|
|
|
rcu_read_unlock();
|
2007-11-14 14:56:23 +08:00
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
WARN_ON(err == -EMSGSIZE);
|
|
|
|
kfree_skb(skb);
|
2017-10-10 00:52:24 +08:00
|
|
|
} else {
|
|
|
|
err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid);
|
2007-11-14 14:56:23 +08:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-12-05 02:19:18 +08:00
|
|
|
int __init ipv6_addr_label_rtnl_register(void)
|
2007-11-14 14:56:23 +08:00
|
|
|
{
|
2017-12-05 02:19:18 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_NEWADDRLABEL,
|
|
|
|
ip6addrlbl_newdel,
|
|
|
|
NULL, RTNL_FLAG_DOIT_UNLOCKED);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_DELADDRLABEL,
|
|
|
|
ip6addrlbl_newdel,
|
|
|
|
NULL, RTNL_FLAG_DOIT_UNLOCKED);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETADDRLABEL,
|
|
|
|
ip6addrlbl_get,
|
|
|
|
ip6addrlbl_dump, RTNL_FLAG_DOIT_UNLOCKED);
|
|
|
|
return ret;
|
2007-11-14 14:56:23 +08:00
|
|
|
}
|