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
|
2015-12-16 07:41:38 +08:00
|
|
|
#include <linux/jhash.h>
|
|
|
|
#include <linux/netfilter.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/rhashtable.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <net/genetlink.h>
|
|
|
|
#include <net/ila.h>
|
|
|
|
#include <net/netns/generic.h>
|
|
|
|
#include <uapi/linux/genetlink.h>
|
|
|
|
#include "ila.h"
|
|
|
|
|
|
|
|
struct ila_xlat_params {
|
|
|
|
struct ila_params ip;
|
|
|
|
int ifindex;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ila_map {
|
2016-04-24 02:46:55 +08:00
|
|
|
struct ila_xlat_params xp;
|
2015-12-16 07:41:38 +08:00
|
|
|
struct rhash_head node;
|
|
|
|
struct ila_map __rcu *next;
|
|
|
|
struct rcu_head rcu;
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned int ila_net_id;
|
|
|
|
|
|
|
|
struct ila_net {
|
|
|
|
struct rhashtable rhash_table;
|
|
|
|
spinlock_t *locks; /* Bucket locks for entry manipulation */
|
|
|
|
unsigned int locks_mask;
|
|
|
|
bool hooks_registered;
|
|
|
|
};
|
|
|
|
|
2018-06-28 05:39:00 +08:00
|
|
|
#define MAX_LOCKS 1024
|
2015-12-16 07:41:38 +08:00
|
|
|
#define LOCKS_PER_CPU 10
|
|
|
|
|
|
|
|
static int alloc_ila_locks(struct ila_net *ilan)
|
|
|
|
{
|
2018-06-28 05:39:00 +08:00
|
|
|
return alloc_bucket_spinlocks(&ilan->locks, &ilan->locks_mask,
|
|
|
|
MAX_LOCKS, LOCKS_PER_CPU,
|
|
|
|
GFP_KERNEL);
|
2015-12-16 07:41:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32 hashrnd __read_mostly;
|
|
|
|
static __always_inline void __ila_hash_secret_init(void)
|
|
|
|
{
|
|
|
|
net_get_random_once(&hashrnd, sizeof(hashrnd));
|
|
|
|
}
|
|
|
|
|
2016-04-24 02:46:56 +08:00
|
|
|
static inline u32 ila_locator_hash(struct ila_locator loc)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
2016-04-24 02:46:56 +08:00
|
|
|
u32 *v = (u32 *)loc.v32;
|
2015-12-16 07:41:38 +08:00
|
|
|
|
2017-06-08 15:54:24 +08:00
|
|
|
__ila_hash_secret_init();
|
2015-12-16 07:41:38 +08:00
|
|
|
return jhash_2words(v[0], v[1], hashrnd);
|
|
|
|
}
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
static inline spinlock_t *ila_get_lock(struct ila_net *ilan,
|
2016-04-24 02:46:56 +08:00
|
|
|
struct ila_locator loc)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
2016-04-24 02:46:56 +08:00
|
|
|
return &ilan->locks[ila_locator_hash(loc) & ilan->locks_mask];
|
2015-12-16 07:41:38 +08:00
|
|
|
}
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
static inline int ila_cmp_wildcards(struct ila_map *ila,
|
2016-04-24 02:46:56 +08:00
|
|
|
struct ila_addr *iaddr, int ifindex)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
2016-04-24 02:46:56 +08:00
|
|
|
return (ila->xp.ifindex && ila->xp.ifindex != ifindex);
|
2015-12-16 07:41:38 +08:00
|
|
|
}
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
static inline int ila_cmp_params(struct ila_map *ila,
|
|
|
|
struct ila_xlat_params *xp)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
2016-04-24 02:46:56 +08:00
|
|
|
return (ila->xp.ifindex != xp->ifindex);
|
2015-12-16 07:41:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ila_cmpfn(struct rhashtable_compare_arg *arg,
|
|
|
|
const void *obj)
|
|
|
|
{
|
|
|
|
const struct ila_map *ila = obj;
|
|
|
|
|
2016-04-24 02:46:56 +08:00
|
|
|
return (ila->xp.ip.locator_match.v64 != *(__be64 *)arg->key);
|
2015-12-16 07:41:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int ila_order(struct ila_map *ila)
|
|
|
|
{
|
|
|
|
int score = 0;
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
if (ila->xp.ifindex)
|
2015-12-16 07:41:38 +08:00
|
|
|
score += 1 << 1;
|
|
|
|
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rhashtable_params rht_params = {
|
|
|
|
.nelem_hint = 1024,
|
|
|
|
.head_offset = offsetof(struct ila_map, node),
|
2016-04-24 02:46:56 +08:00
|
|
|
.key_offset = offsetof(struct ila_map, xp.ip.locator_match),
|
2015-12-16 07:41:38 +08:00
|
|
|
.key_len = sizeof(u64), /* identifier */
|
|
|
|
.max_size = 1048576,
|
|
|
|
.min_size = 256,
|
|
|
|
.automatic_shrinking = true,
|
|
|
|
.obj_cmpfn = ila_cmpfn,
|
|
|
|
};
|
|
|
|
|
2016-10-24 20:40:03 +08:00
|
|
|
static struct genl_family ila_nl_family;
|
2015-12-16 07:41:38 +08:00
|
|
|
|
2016-09-01 06:20:51 +08:00
|
|
|
static const struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = {
|
2015-12-16 07:41:38 +08:00
|
|
|
[ILA_ATTR_LOCATOR] = { .type = NLA_U64, },
|
|
|
|
[ILA_ATTR_LOCATOR_MATCH] = { .type = NLA_U64, },
|
|
|
|
[ILA_ATTR_IFINDEX] = { .type = NLA_U32, },
|
2016-04-24 02:46:57 +08:00
|
|
|
[ILA_ATTR_CSUM_MODE] = { .type = NLA_U8, },
|
2017-11-06 07:58:24 +08:00
|
|
|
[ILA_ATTR_IDENT_TYPE] = { .type = NLA_U8, },
|
2015-12-16 07:41:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_nl_config(struct genl_info *info,
|
2016-04-24 02:46:55 +08:00
|
|
|
struct ila_xlat_params *xp)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
2016-04-24 02:46:55 +08:00
|
|
|
memset(xp, 0, sizeof(*xp));
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
if (info->attrs[ILA_ATTR_LOCATOR])
|
2016-04-24 02:46:55 +08:00
|
|
|
xp->ip.locator.v64 = (__force __be64)nla_get_u64(
|
2015-12-16 07:41:38 +08:00
|
|
|
info->attrs[ILA_ATTR_LOCATOR]);
|
|
|
|
|
|
|
|
if (info->attrs[ILA_ATTR_LOCATOR_MATCH])
|
2016-04-24 02:46:55 +08:00
|
|
|
xp->ip.locator_match.v64 = (__force __be64)nla_get_u64(
|
2015-12-16 07:41:38 +08:00
|
|
|
info->attrs[ILA_ATTR_LOCATOR_MATCH]);
|
|
|
|
|
2016-04-24 02:46:57 +08:00
|
|
|
if (info->attrs[ILA_ATTR_CSUM_MODE])
|
|
|
|
xp->ip.csum_mode = nla_get_u8(info->attrs[ILA_ATTR_CSUM_MODE]);
|
2017-11-06 07:58:23 +08:00
|
|
|
else
|
|
|
|
xp->ip.csum_mode = ILA_CSUM_NO_ACTION;
|
2016-04-24 02:46:57 +08:00
|
|
|
|
2017-11-06 07:58:24 +08:00
|
|
|
if (info->attrs[ILA_ATTR_IDENT_TYPE])
|
|
|
|
xp->ip.ident_type = nla_get_u8(
|
|
|
|
info->attrs[ILA_ATTR_IDENT_TYPE]);
|
|
|
|
else
|
|
|
|
xp->ip.ident_type = ILA_ATYPE_USE_FORMAT;
|
|
|
|
|
2015-12-16 07:41:38 +08:00
|
|
|
if (info->attrs[ILA_ATTR_IFINDEX])
|
2016-04-24 02:46:55 +08:00
|
|
|
xp->ifindex = nla_get_s32(info->attrs[ILA_ATTR_IFINDEX]);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called with rcu readlock */
|
2016-04-24 02:46:55 +08:00
|
|
|
static inline struct ila_map *ila_lookup_wildcards(struct ila_addr *iaddr,
|
2015-12-16 07:41:38 +08:00
|
|
|
int ifindex,
|
|
|
|
struct ila_net *ilan)
|
|
|
|
{
|
|
|
|
struct ila_map *ila;
|
|
|
|
|
2016-04-24 02:46:56 +08:00
|
|
|
ila = rhashtable_lookup_fast(&ilan->rhash_table, &iaddr->loc,
|
2016-04-24 02:46:55 +08:00
|
|
|
rht_params);
|
2015-12-16 07:41:38 +08:00
|
|
|
while (ila) {
|
2016-04-24 02:46:56 +08:00
|
|
|
if (!ila_cmp_wildcards(ila, iaddr, ifindex))
|
2015-12-16 07:41:38 +08:00
|
|
|
return ila;
|
|
|
|
ila = rcu_access_pointer(ila->next);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called with rcu readlock */
|
2016-04-24 02:46:55 +08:00
|
|
|
static inline struct ila_map *ila_lookup_by_params(struct ila_xlat_params *xp,
|
2015-12-16 07:41:38 +08:00
|
|
|
struct ila_net *ilan)
|
|
|
|
{
|
|
|
|
struct ila_map *ila;
|
|
|
|
|
2016-04-24 02:46:56 +08:00
|
|
|
ila = rhashtable_lookup_fast(&ilan->rhash_table,
|
|
|
|
&xp->ip.locator_match,
|
2015-12-16 07:41:38 +08:00
|
|
|
rht_params);
|
|
|
|
while (ila) {
|
2016-04-24 02:46:55 +08:00
|
|
|
if (!ila_cmp_params(ila, xp))
|
2015-12-16 07:41:38 +08:00
|
|
|
return ila;
|
|
|
|
ila = rcu_access_pointer(ila->next);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ila_release(struct ila_map *ila)
|
|
|
|
{
|
|
|
|
kfree_rcu(ila, rcu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ila_free_cb(void *ptr, void *arg)
|
|
|
|
{
|
|
|
|
struct ila_map *ila = (struct ila_map *)ptr, *next;
|
|
|
|
|
|
|
|
/* Assume rcu_readlock held */
|
|
|
|
while (ila) {
|
|
|
|
next = rcu_access_pointer(ila->next);
|
|
|
|
ila_release(ila);
|
|
|
|
ila = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 07:58:23 +08:00
|
|
|
static int ila_xlat_addr(struct sk_buff *skb, bool sir2ila);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
ila_nf_input(void *priv,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
const struct nf_hook_state *state)
|
|
|
|
{
|
2016-06-08 07:09:44 +08:00
|
|
|
ila_xlat_addr(skb, false);
|
2015-12-16 07:41:38 +08:00
|
|
|
return NF_ACCEPT;
|
|
|
|
}
|
|
|
|
|
2017-07-26 17:40:52 +08:00
|
|
|
static const struct nf_hook_ops ila_nf_hook_ops[] = {
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
|
|
|
.hook = ila_nf_input,
|
|
|
|
.pf = NFPROTO_IPV6,
|
|
|
|
.hooknum = NF_INET_PRE_ROUTING,
|
|
|
|
.priority = -1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
static int ila_add_mapping(struct net *net, struct ila_xlat_params *xp)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
|
|
|
struct ila_net *ilan = net_generic(net, ila_net_id);
|
|
|
|
struct ila_map *ila, *head;
|
2016-04-24 02:46:56 +08:00
|
|
|
spinlock_t *lock = ila_get_lock(ilan, xp->ip.locator_match);
|
2015-12-16 07:41:38 +08:00
|
|
|
int err = 0, order;
|
|
|
|
|
|
|
|
if (!ilan->hooks_registered) {
|
|
|
|
/* We defer registering net hooks in the namespace until the
|
|
|
|
* first mapping is added.
|
|
|
|
*/
|
|
|
|
err = nf_register_net_hooks(net, ila_nf_hook_ops,
|
|
|
|
ARRAY_SIZE(ila_nf_hook_ops));
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
ilan->hooks_registered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ila = kzalloc(sizeof(*ila), GFP_KERNEL);
|
|
|
|
if (!ila)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-04-24 02:46:57 +08:00
|
|
|
ila_init_saved_csum(&xp->ip);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
2016-04-24 02:46:57 +08:00
|
|
|
ila->xp = *xp;
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
order = ila_order(ila);
|
|
|
|
|
|
|
|
spin_lock(lock);
|
|
|
|
|
2016-04-24 02:46:56 +08:00
|
|
|
head = rhashtable_lookup_fast(&ilan->rhash_table,
|
|
|
|
&xp->ip.locator_match,
|
2015-12-16 07:41:38 +08:00
|
|
|
rht_params);
|
|
|
|
if (!head) {
|
|
|
|
/* New entry for the rhash_table */
|
|
|
|
err = rhashtable_lookup_insert_fast(&ilan->rhash_table,
|
|
|
|
&ila->node, rht_params);
|
|
|
|
} else {
|
|
|
|
struct ila_map *tila = head, *prev = NULL;
|
|
|
|
|
|
|
|
do {
|
2016-04-24 02:46:55 +08:00
|
|
|
if (!ila_cmp_params(tila, xp)) {
|
2015-12-16 07:41:38 +08:00
|
|
|
err = -EEXIST;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (order > ila_order(tila))
|
|
|
|
break;
|
|
|
|
|
|
|
|
prev = tila;
|
|
|
|
tila = rcu_dereference_protected(tila->next,
|
|
|
|
lockdep_is_held(lock));
|
|
|
|
} while (tila);
|
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
/* Insert in sub list of head */
|
|
|
|
RCU_INIT_POINTER(ila->next, tila);
|
|
|
|
rcu_assign_pointer(prev->next, ila);
|
|
|
|
} else {
|
|
|
|
/* Make this ila new head */
|
|
|
|
RCU_INIT_POINTER(ila->next, head);
|
|
|
|
err = rhashtable_replace_fast(&ilan->rhash_table,
|
|
|
|
&head->node,
|
|
|
|
&ila->node, rht_params);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock(lock);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
kfree(ila);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
static int ila_del_mapping(struct net *net, struct ila_xlat_params *xp)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
|
|
|
struct ila_net *ilan = net_generic(net, ila_net_id);
|
|
|
|
struct ila_map *ila, *head, *prev;
|
2016-04-24 02:46:56 +08:00
|
|
|
spinlock_t *lock = ila_get_lock(ilan, xp->ip.locator_match);
|
2015-12-16 07:41:38 +08:00
|
|
|
int err = -ENOENT;
|
|
|
|
|
|
|
|
spin_lock(lock);
|
|
|
|
|
|
|
|
head = rhashtable_lookup_fast(&ilan->rhash_table,
|
2016-04-24 02:46:56 +08:00
|
|
|
&xp->ip.locator_match, rht_params);
|
2015-12-16 07:41:38 +08:00
|
|
|
ila = head;
|
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
|
|
|
|
while (ila) {
|
2016-04-24 02:46:55 +08:00
|
|
|
if (ila_cmp_params(ila, xp)) {
|
2015-12-16 07:41:38 +08:00
|
|
|
prev = ila;
|
|
|
|
ila = rcu_dereference_protected(ila->next,
|
|
|
|
lockdep_is_held(lock));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
/* Not head, just delete from list */
|
|
|
|
rcu_assign_pointer(prev->next, ila->next);
|
|
|
|
} else {
|
|
|
|
/* It is the head. If there is something in the
|
|
|
|
* sublist we need to make a new head.
|
|
|
|
*/
|
|
|
|
head = rcu_dereference_protected(ila->next,
|
|
|
|
lockdep_is_held(lock));
|
|
|
|
if (head) {
|
|
|
|
/* Put first entry in the sublist into the
|
|
|
|
* table
|
|
|
|
*/
|
|
|
|
err = rhashtable_replace_fast(
|
|
|
|
&ilan->rhash_table, &ila->node,
|
|
|
|
&head->node, rht_params);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
/* Entry no longer used */
|
|
|
|
err = rhashtable_remove_fast(&ilan->rhash_table,
|
|
|
|
&ila->node,
|
|
|
|
rht_params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ila_release(ila);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock(lock);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ila_nl_cmd_add_mapping(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct net *net = genl_info_net(info);
|
|
|
|
struct ila_xlat_params p;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = parse_nl_config(info, &p);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return ila_add_mapping(net, &p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ila_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct net *net = genl_info_net(info);
|
2016-04-24 02:46:55 +08:00
|
|
|
struct ila_xlat_params xp;
|
2015-12-16 07:41:38 +08:00
|
|
|
int err;
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
err = parse_nl_config(info, &xp);
|
2015-12-16 07:41:38 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
ila_del_mapping(net, &xp);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ila_fill_info(struct ila_map *ila, struct sk_buff *msg)
|
|
|
|
{
|
2016-04-24 02:46:56 +08:00
|
|
|
if (nla_put_u64_64bit(msg, ILA_ATTR_LOCATOR,
|
2016-04-24 02:46:55 +08:00
|
|
|
(__force u64)ila->xp.ip.locator.v64,
|
2016-04-25 16:25:16 +08:00
|
|
|
ILA_ATTR_PAD) ||
|
|
|
|
nla_put_u64_64bit(msg, ILA_ATTR_LOCATOR_MATCH,
|
2016-04-24 02:46:55 +08:00
|
|
|
(__force u64)ila->xp.ip.locator_match.v64,
|
2016-04-25 16:25:16 +08:00
|
|
|
ILA_ATTR_PAD) ||
|
2016-04-24 02:46:57 +08:00
|
|
|
nla_put_s32(msg, ILA_ATTR_IFINDEX, ila->xp.ifindex) ||
|
2017-11-06 07:58:24 +08:00
|
|
|
nla_put_u8(msg, ILA_ATTR_CSUM_MODE, ila->xp.ip.csum_mode) ||
|
|
|
|
nla_put_u8(msg, ILA_ATTR_IDENT_TYPE, ila->xp.ip.ident_type))
|
2015-12-16 07:41:38 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ila_dump_info(struct ila_map *ila,
|
|
|
|
u32 portid, u32 seq, u32 flags,
|
|
|
|
struct sk_buff *skb, u8 cmd)
|
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(skb, portid, seq, &ila_nl_family, flags, cmd);
|
|
|
|
if (!hdr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (ila_fill_info(ila, skb) < 0)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
genlmsg_end(skb, hdr);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
genlmsg_cancel(skb, hdr);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ila_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct net *net = genl_info_net(info);
|
|
|
|
struct ila_net *ilan = net_generic(net, ila_net_id);
|
|
|
|
struct sk_buff *msg;
|
2016-04-24 02:46:55 +08:00
|
|
|
struct ila_xlat_params xp;
|
2015-12-16 07:41:38 +08:00
|
|
|
struct ila_map *ila;
|
|
|
|
int ret;
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
ret = parse_nl_config(info, &xp);
|
2015-12-16 07:41:38 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
ila = ila_lookup_by_params(&xp, ilan);
|
2015-12-16 07:41:38 +08:00
|
|
|
if (ila) {
|
|
|
|
ret = ila_dump_info(ila,
|
|
|
|
info->snd_portid,
|
|
|
|
info->snd_seq, 0, msg,
|
|
|
|
info->genlhdr->cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
return genlmsg_reply(msg, info);
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ila_dump_iter {
|
|
|
|
struct rhashtable_iter rhiter;
|
2018-06-28 05:38:59 +08:00
|
|
|
int skip;
|
2015-12-16 07:41:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ila_nl_dump_start(struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
struct net *net = sock_net(cb->skb->sk);
|
|
|
|
struct ila_net *ilan = net_generic(net, ila_net_id);
|
2018-06-28 05:38:59 +08:00
|
|
|
struct ila_dump_iter *iter;
|
|
|
|
int ret;
|
2016-11-02 05:55:25 +08:00
|
|
|
|
2018-06-28 05:38:59 +08:00
|
|
|
iter = kmalloc(sizeof(*iter), GFP_KERNEL);
|
|
|
|
if (!iter)
|
|
|
|
return -ENOMEM;
|
2016-11-02 05:55:25 +08:00
|
|
|
|
2018-06-28 05:38:59 +08:00
|
|
|
ret = rhashtable_walk_init(&ilan->rhash_table, &iter->rhiter,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (ret) {
|
|
|
|
kfree(iter);
|
|
|
|
return ret;
|
2016-11-02 05:55:25 +08:00
|
|
|
}
|
2015-12-16 07:41:38 +08:00
|
|
|
|
2018-06-28 05:38:59 +08:00
|
|
|
iter->skip = 0;
|
|
|
|
cb->args[0] = (long)iter;
|
|
|
|
|
|
|
|
return ret;
|
2015-12-16 07:41:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ila_nl_dump_done(struct netlink_callback *cb)
|
|
|
|
{
|
2016-11-02 05:55:25 +08:00
|
|
|
struct ila_dump_iter *iter = (struct ila_dump_iter *)cb->args[0];
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
rhashtable_walk_exit(&iter->rhiter);
|
|
|
|
|
2016-11-02 05:55:25 +08:00
|
|
|
kfree(iter);
|
|
|
|
|
2015-12-16 07:41:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ila_nl_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
2016-11-02 05:55:25 +08:00
|
|
|
struct ila_dump_iter *iter = (struct ila_dump_iter *)cb->args[0];
|
2015-12-16 07:41:38 +08:00
|
|
|
struct rhashtable_iter *rhiter = &iter->rhiter;
|
2018-06-28 05:38:59 +08:00
|
|
|
int skip = iter->skip;
|
2015-12-16 07:41:38 +08:00
|
|
|
struct ila_map *ila;
|
|
|
|
int ret;
|
|
|
|
|
2017-12-05 02:31:41 +08:00
|
|
|
rhashtable_walk_start(rhiter);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
2018-06-28 05:38:59 +08:00
|
|
|
/* Get first entry */
|
|
|
|
ila = rhashtable_walk_peek(rhiter);
|
|
|
|
|
|
|
|
if (ila && !IS_ERR(ila) && skip) {
|
|
|
|
/* Skip over visited entries */
|
|
|
|
|
|
|
|
while (ila && skip) {
|
|
|
|
/* Skip over any ila entries in this list that we
|
|
|
|
* have already dumped.
|
|
|
|
*/
|
|
|
|
ila = rcu_access_pointer(ila->next);
|
|
|
|
skip--;
|
|
|
|
}
|
|
|
|
}
|
2015-12-16 07:41:38 +08:00
|
|
|
|
2018-06-28 05:38:59 +08:00
|
|
|
skip = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
2015-12-16 07:41:38 +08:00
|
|
|
if (IS_ERR(ila)) {
|
|
|
|
ret = PTR_ERR(ila);
|
2018-06-28 05:38:59 +08:00
|
|
|
if (ret == -EAGAIN) {
|
|
|
|
/* Table has changed and iter has reset. Return
|
|
|
|
* -EAGAIN to the application even if we have
|
|
|
|
* written data to the skb. The application
|
|
|
|
* needs to deal with this.
|
|
|
|
*/
|
|
|
|
|
|
|
|
goto out_ret;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2015-12-16 07:41:38 +08:00
|
|
|
} else if (!ila) {
|
2018-06-28 05:38:59 +08:00
|
|
|
ret = 0;
|
2015-12-16 07:41:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ila) {
|
|
|
|
ret = ila_dump_info(ila, NETLINK_CB(cb->skb).portid,
|
|
|
|
cb->nlh->nlmsg_seq, NLM_F_MULTI,
|
|
|
|
skb, ILA_CMD_GET);
|
|
|
|
if (ret)
|
2018-06-28 05:38:59 +08:00
|
|
|
goto out;
|
2015-12-16 07:41:38 +08:00
|
|
|
|
2018-06-28 05:38:59 +08:00
|
|
|
skip++;
|
2015-12-16 07:41:38 +08:00
|
|
|
ila = rcu_access_pointer(ila->next);
|
|
|
|
}
|
2018-06-28 05:38:59 +08:00
|
|
|
|
|
|
|
skip = 0;
|
|
|
|
ila = rhashtable_walk_next(rhiter);
|
2015-12-16 07:41:38 +08:00
|
|
|
}
|
|
|
|
|
2018-06-28 05:38:59 +08:00
|
|
|
out:
|
|
|
|
iter->skip = skip;
|
|
|
|
ret = (skb->len ? : ret);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
2018-06-28 05:38:59 +08:00
|
|
|
out_ret:
|
2015-12-16 07:41:38 +08:00
|
|
|
rhashtable_walk_stop(rhiter);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct genl_ops ila_nl_ops[] = {
|
|
|
|
{
|
|
|
|
.cmd = ILA_CMD_ADD,
|
|
|
|
.doit = ila_nl_cmd_add_mapping,
|
|
|
|
.policy = ila_nl_policy,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = ILA_CMD_DEL,
|
|
|
|
.doit = ila_nl_cmd_del_mapping,
|
|
|
|
.policy = ila_nl_policy,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = ILA_CMD_GET,
|
|
|
|
.doit = ila_nl_cmd_get_mapping,
|
|
|
|
.start = ila_nl_dump_start,
|
|
|
|
.dumpit = ila_nl_dump,
|
|
|
|
.done = ila_nl_dump_done,
|
|
|
|
.policy = ila_nl_policy,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-10-24 20:40:05 +08:00
|
|
|
static struct genl_family ila_nl_family __ro_after_init = {
|
2016-10-24 20:40:03 +08:00
|
|
|
.hdrsize = 0,
|
|
|
|
.name = ILA_GENL_NAME,
|
|
|
|
.version = ILA_GENL_VERSION,
|
|
|
|
.maxattr = ILA_ATTR_MAX,
|
|
|
|
.netnsok = true,
|
|
|
|
.parallel_ops = true,
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
.ops = ila_nl_ops,
|
|
|
|
.n_ops = ARRAY_SIZE(ila_nl_ops),
|
|
|
|
};
|
|
|
|
|
2015-12-16 07:41:38 +08:00
|
|
|
#define ILA_HASH_TABLE_SIZE 1024
|
|
|
|
|
|
|
|
static __net_init int ila_init_net(struct net *net)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct ila_net *ilan = net_generic(net, ila_net_id);
|
|
|
|
|
|
|
|
err = alloc_ila_locks(ilan);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
rhashtable_init(&ilan->rhash_table, &rht_params);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __net_exit void ila_exit_net(struct net *net)
|
|
|
|
{
|
|
|
|
struct ila_net *ilan = net_generic(net, ila_net_id);
|
|
|
|
|
|
|
|
rhashtable_free_and_destroy(&ilan->rhash_table, ila_free_cb, NULL);
|
|
|
|
|
2018-06-28 05:39:00 +08:00
|
|
|
free_bucket_spinlocks(ilan->locks);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
if (ilan->hooks_registered)
|
|
|
|
nf_unregister_net_hooks(net, ila_nf_hook_ops,
|
|
|
|
ARRAY_SIZE(ila_nf_hook_ops));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations ila_net_ops = {
|
|
|
|
.init = ila_init_net,
|
|
|
|
.exit = ila_exit_net,
|
|
|
|
.id = &ila_net_id,
|
|
|
|
.size = sizeof(struct ila_net),
|
|
|
|
};
|
|
|
|
|
2017-11-06 07:58:23 +08:00
|
|
|
static int ila_xlat_addr(struct sk_buff *skb, bool sir2ila)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
|
|
|
struct ila_map *ila;
|
|
|
|
struct ipv6hdr *ip6h = ipv6_hdr(skb);
|
|
|
|
struct net *net = dev_net(skb->dev);
|
|
|
|
struct ila_net *ilan = net_generic(net, ila_net_id);
|
2016-04-24 02:46:55 +08:00
|
|
|
struct ila_addr *iaddr = ila_a2i(&ip6h->daddr);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
/* Assumes skb contains a valid IPv6 header that is pulled */
|
|
|
|
|
2017-11-06 07:58:24 +08:00
|
|
|
/* No check here that ILA type in the mapping matches what is in the
|
|
|
|
* address. We assume that whatever sender gaves us can be translated.
|
|
|
|
* The checksum mode however is relevant.
|
|
|
|
*/
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
2016-04-24 02:46:56 +08:00
|
|
|
ila = ila_lookup_wildcards(iaddr, skb->dev->ifindex, ilan);
|
2015-12-16 07:41:38 +08:00
|
|
|
if (ila)
|
2017-11-06 07:58:23 +08:00
|
|
|
ila_update_ipv6_locator(skb, &ila->xp.ip, sir2ila);
|
2015-12-16 07:41:38 +08:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-24 20:40:05 +08:00
|
|
|
int __init ila_xlat_init(void)
|
2015-12-16 07:41:38 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = register_pernet_device(&ila_net_ops);
|
|
|
|
if (ret)
|
|
|
|
goto exit;
|
|
|
|
|
2016-10-24 20:40:03 +08:00
|
|
|
ret = genl_register_family(&ila_nl_family);
|
2015-12-16 07:41:38 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto unregister;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unregister:
|
|
|
|
unregister_pernet_device(&ila_net_ops);
|
|
|
|
exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ila_xlat_fini(void)
|
|
|
|
{
|
|
|
|
genl_unregister_family(&ila_nl_family);
|
|
|
|
unregister_pernet_device(&ila_net_ops);
|
|
|
|
}
|