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
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* DECnet An implementation of the DECnet protocol suite for the LINUX
|
|
|
|
* operating system. DECnet is implemented using the BSD Socket
|
|
|
|
* interface as the means of communication with the user level.
|
|
|
|
*
|
|
|
|
* DECnet Device Layer
|
|
|
|
*
|
|
|
|
* Authors: Steve Whitehouse <SteveW@ACM.org>
|
|
|
|
* Eduardo Marcelo Serrat <emserrat@geocities.com>
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* Steve Whitehouse : Devices now see incoming frames so they
|
|
|
|
* can mark on who it came from.
|
|
|
|
* Steve Whitehouse : Fixed bug in creating neighbours. Each neighbour
|
|
|
|
* can now have a device specific setup func.
|
|
|
|
* Steve Whitehouse : Added /proc/sys/net/decnet/conf/<dev>/
|
|
|
|
* Steve Whitehouse : Fixed bug which sometimes killed timer
|
|
|
|
* Steve Whitehouse : Multiple ifaddr support
|
|
|
|
* Steve Whitehouse : SIOCGIFCONF is now a compile time option
|
|
|
|
* Steve Whitehouse : /proc/sys/net/decnet/conf/<sys>/forwarding
|
|
|
|
* Steve Whitehouse : Removed timer1 - it's a user space issue now
|
|
|
|
* Patrick Caulfield : Fixed router hello message format
|
|
|
|
* Steve Whitehouse : Got rid of constant sizes for blksize for
|
|
|
|
* devices. All mtu based now.
|
|
|
|
*/
|
|
|
|
|
2006-01-12 04:17:47 +08:00
|
|
|
#include <linux/capability.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/string.h>
|
2006-08-05 14:04:54 +08:00
|
|
|
#include <linux/if_addr.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/notifier.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>
|
2014-08-21 01:43:07 +08:00
|
|
|
#include <linux/jiffies.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2007-09-12 18:01:34 +08:00
|
|
|
#include <net/net_namespace.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/neighbour.h>
|
|
|
|
#include <net/dst.h>
|
|
|
|
#include <net/flow.h>
|
2006-08-10 06:56:46 +08:00
|
|
|
#include <net/fib_rules.h>
|
2006-11-25 09:14:07 +08:00
|
|
|
#include <net/netlink.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/dn.h>
|
|
|
|
#include <net/dn_dev.h>
|
|
|
|
#include <net/dn_route.h>
|
|
|
|
#include <net/dn_neigh.h>
|
|
|
|
#include <net/dn_fib.h>
|
|
|
|
|
2019-01-27 04:12:19 +08:00
|
|
|
#define DN_IFREQ_SIZE (offsetof(struct ifreq, ifr_ifru) + sizeof(struct sockaddr_dn))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static char dn_rt_all_end_mcast[ETH_ALEN] = {0xAB,0x00,0x00,0x04,0x00,0x00};
|
|
|
|
static char dn_rt_all_rt_mcast[ETH_ALEN] = {0xAB,0x00,0x00,0x03,0x00,0x00};
|
|
|
|
static char dn_hiord[ETH_ALEN] = {0xAA,0x00,0x04,0x00,0x00,0x00};
|
|
|
|
static unsigned char dn_eco_version[3] = {0x02,0x00,0x00};
|
|
|
|
|
|
|
|
extern struct neigh_table dn_neigh_table;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* decnet_address is kept in network order.
|
|
|
|
*/
|
2006-03-21 14:42:39 +08:00
|
|
|
__le16 decnet_address = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-11 15:40:36 +08:00
|
|
|
static DEFINE_SPINLOCK(dndev_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct net_device *decnet_default_device;
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 17:16:30 +08:00
|
|
|
static BLOCKING_NOTIFIER_HEAD(dnaddr_chain);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct dn_dev *dn_dev_create(struct net_device *dev, int *err);
|
|
|
|
static void dn_dev_delete(struct net_device *dev);
|
2006-11-25 09:14:31 +08:00
|
|
|
static void dn_ifaddr_notify(int event, struct dn_ifaddr *ifa);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int dn_eth_up(struct net_device *);
|
|
|
|
static void dn_eth_down(struct net_device *);
|
|
|
|
static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa);
|
|
|
|
static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa);
|
|
|
|
|
|
|
|
static struct dn_dev_parms dn_dev_list[] = {
|
|
|
|
{
|
|
|
|
.type = ARPHRD_ETHER, /* Ethernet */
|
|
|
|
.mode = DN_DEV_BCAST,
|
|
|
|
.state = DN_DEV_S_RU,
|
|
|
|
.t2 = 1,
|
|
|
|
.t3 = 10,
|
|
|
|
.name = "ethernet",
|
|
|
|
.up = dn_eth_up,
|
|
|
|
.down = dn_eth_down,
|
|
|
|
.timer3 = dn_send_brd_hello,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = ARPHRD_IPGRE, /* DECnet tunneled over GRE in IP */
|
|
|
|
.mode = DN_DEV_BCAST,
|
|
|
|
.state = DN_DEV_S_RU,
|
|
|
|
.t2 = 1,
|
|
|
|
.t3 = 10,
|
|
|
|
.name = "ipgre",
|
|
|
|
.timer3 = dn_send_brd_hello,
|
|
|
|
},
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
.type = ARPHRD_X25, /* Bog standard X.25 */
|
|
|
|
.mode = DN_DEV_UCAST,
|
|
|
|
.state = DN_DEV_S_DS,
|
|
|
|
.t2 = 1,
|
|
|
|
.t3 = 120,
|
|
|
|
.name = "x25",
|
|
|
|
.timer3 = dn_send_ptp_hello,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
.type = ARPHRD_PPP, /* DECnet over PPP */
|
|
|
|
.mode = DN_DEV_BCAST,
|
|
|
|
.state = DN_DEV_S_RU,
|
|
|
|
.t2 = 1,
|
|
|
|
.t3 = 10,
|
|
|
|
.name = "ppp",
|
|
|
|
.timer3 = dn_send_brd_hello,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
.type = ARPHRD_DDCMP, /* DECnet over DDCMP */
|
|
|
|
.mode = DN_DEV_UCAST,
|
|
|
|
.state = DN_DEV_S_DS,
|
|
|
|
.t2 = 1,
|
|
|
|
.t3 = 120,
|
|
|
|
.name = "ddcmp",
|
|
|
|
.timer3 = dn_send_ptp_hello,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = ARPHRD_LOOPBACK, /* Loopback interface - always last */
|
|
|
|
.mode = DN_DEV_BCAST,
|
|
|
|
.state = DN_DEV_S_RU,
|
|
|
|
.t2 = 1,
|
|
|
|
.t3 = 10,
|
|
|
|
.name = "loopback",
|
|
|
|
.timer3 = dn_send_brd_hello,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-09-17 07:41:29 +08:00
|
|
|
#define DN_DEV_LIST_SIZE ARRAY_SIZE(dn_dev_list)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-10-16 06:59:50 +08:00
|
|
|
#define DN_DEV_PARMS_OFFSET(x) offsetof(struct dn_dev_parms, x)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SYSCTL
|
|
|
|
|
|
|
|
static int min_t2[] = { 1 };
|
|
|
|
static int max_t2[] = { 60 }; /* No max specified, but this seems sensible */
|
|
|
|
static int min_t3[] = { 1 };
|
|
|
|
static int max_t3[] = { 8191 }; /* Must fit in 16 bits when multiplied by BCT3MULT or T3MULT */
|
|
|
|
|
|
|
|
static int min_priority[1];
|
|
|
|
static int max_priority[] = { 127 }; /* From DECnet spec */
|
|
|
|
|
2020-04-24 14:43:38 +08:00
|
|
|
static int dn_forwarding_proc(struct ctl_table *, int, void *, size_t *,
|
|
|
|
loff_t *);
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct dn_dev_sysctl_table {
|
|
|
|
struct ctl_table_header *sysctl_header;
|
2013-06-12 14:04:25 +08:00
|
|
|
struct ctl_table dn_dev_vars[5];
|
2005-04-17 06:20:36 +08:00
|
|
|
} dn_dev_sysctl = {
|
|
|
|
NULL,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.procname = "forwarding",
|
|
|
|
.data = (void *)DN_DEV_PARMS_OFFSET(forwarding),
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = dn_forwarding_proc,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "priority",
|
|
|
|
.data = (void *)DN_DEV_PARMS_OFFSET(priority),
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec_minmax,
|
|
|
|
.extra1 = &min_priority,
|
|
|
|
.extra2 = &max_priority
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "t2",
|
|
|
|
.data = (void *)DN_DEV_PARMS_OFFSET(t2),
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec_minmax,
|
|
|
|
.extra1 = &min_t2,
|
|
|
|
.extra2 = &max_t2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "t3",
|
|
|
|
.data = (void *)DN_DEV_PARMS_OFFSET(t3),
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec_minmax,
|
|
|
|
.extra1 = &min_t3,
|
|
|
|
.extra2 = &max_t3
|
|
|
|
},
|
2016-12-17 08:58:58 +08:00
|
|
|
{ }
|
2005-04-17 06:20:36 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *parms)
|
|
|
|
{
|
|
|
|
struct dn_dev_sysctl_table *t;
|
|
|
|
int i;
|
|
|
|
|
2012-04-19 21:40:37 +08:00
|
|
|
char path[sizeof("net/decnet/conf/") + IFNAMSIZ];
|
2008-01-09 16:31:49 +08:00
|
|
|
|
2006-11-17 22:29:21 +08:00
|
|
|
t = kmemdup(&dn_dev_sysctl, sizeof(*t), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (t == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
|
|
|
|
long offset = (long)t->dn_dev_vars[i].data;
|
|
|
|
t->dn_dev_vars[i].data = ((char *)parms) + offset;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:40:37 +08:00
|
|
|
snprintf(path, sizeof(path), "net/decnet/conf/%s",
|
|
|
|
dev? dev->name : parms->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
t->dn_dev_vars[0].extra1 = (void *)dev;
|
|
|
|
|
2012-04-19 21:40:37 +08:00
|
|
|
t->sysctl_header = register_net_sysctl(&init_net, path, t->dn_dev_vars);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (t->sysctl_header == NULL)
|
|
|
|
kfree(t);
|
|
|
|
else
|
|
|
|
parms->sysctl = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
|
|
|
|
{
|
|
|
|
if (parms->sysctl) {
|
|
|
|
struct dn_dev_sysctl_table *t = parms->sysctl;
|
|
|
|
parms->sysctl = NULL;
|
2012-04-19 21:24:33 +08:00
|
|
|
unregister_net_sysctl_table(t->sysctl_header);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 14:04:25 +08:00
|
|
|
static int dn_forwarding_proc(struct ctl_table *table, int write,
|
2020-04-24 14:43:38 +08:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_DECNET_ROUTER
|
|
|
|
struct net_device *dev = table->extra1;
|
|
|
|
struct dn_dev *dn_db;
|
|
|
|
int err;
|
|
|
|
int tmp, old;
|
|
|
|
|
|
|
|
if (table->extra1 == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-10-29 11:09:24 +08:00
|
|
|
dn_db = rcu_dereference_raw(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
old = dn_db->parms.forwarding;
|
|
|
|
|
2009-09-24 06:57:19 +08:00
|
|
|
err = proc_dointvec(table, write, buffer, lenp, ppos);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if ((err >= 0) && write) {
|
|
|
|
if (dn_db->parms.forwarding < 0)
|
|
|
|
dn_db->parms.forwarding = 0;
|
|
|
|
if (dn_db->parms.forwarding > 2)
|
|
|
|
dn_db->parms.forwarding = 2;
|
|
|
|
/*
|
|
|
|
* What an ugly hack this is... its works, just. It
|
|
|
|
* would be nice if sysctl/proc were just that little
|
|
|
|
* bit more flexible so I don't have to write a special
|
|
|
|
* routine, or suffer hacks like this - SJW
|
|
|
|
*/
|
|
|
|
tmp = dn_db->parms.forwarding;
|
|
|
|
dn_db->parms.forwarding = old;
|
|
|
|
if (dn_db->parms.down)
|
|
|
|
dn_db->parms.down(dev);
|
|
|
|
dn_db->parms.forwarding = tmp;
|
|
|
|
if (dn_db->parms.up)
|
|
|
|
dn_db->parms.up(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
#else
|
|
|
|
return -EINVAL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_SYSCTL */
|
|
|
|
static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *parms)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_SYSCTL */
|
|
|
|
|
|
|
|
static inline __u16 mtu2blksize(struct net_device *dev)
|
|
|
|
{
|
|
|
|
u32 blksize = dev->mtu;
|
|
|
|
if (blksize > 0xffff)
|
|
|
|
blksize = 0xffff;
|
|
|
|
|
|
|
|
if (dev->type == ARPHRD_ETHER ||
|
|
|
|
dev->type == ARPHRD_PPP ||
|
|
|
|
dev->type == ARPHRD_IPGRE ||
|
|
|
|
dev->type == ARPHRD_LOOPBACK)
|
|
|
|
blksize -= 2;
|
|
|
|
|
|
|
|
return (__u16)blksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dn_ifaddr *dn_dev_alloc_ifa(void)
|
|
|
|
{
|
|
|
|
struct dn_ifaddr *ifa;
|
|
|
|
|
2006-07-22 05:51:30 +08:00
|
|
|
ifa = kzalloc(sizeof(*ifa), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return ifa;
|
|
|
|
}
|
|
|
|
|
2010-10-29 11:09:24 +08:00
|
|
|
static void dn_dev_free_ifa(struct dn_ifaddr *ifa)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-03-15 18:10:12 +08:00
|
|
|
kfree_rcu(ifa, rcu);
|
2010-10-29 11:09:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_dev_del_ifa(struct dn_dev *dn_db, struct dn_ifaddr __rcu **ifap, int destroy)
|
|
|
|
{
|
|
|
|
struct dn_ifaddr *ifa1 = rtnl_dereference(*ifap);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char mac_addr[6];
|
|
|
|
struct net_device *dev = dn_db->dev;
|
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
|
|
*ifap = ifa1->ifa_next;
|
|
|
|
|
|
|
|
if (dn_db->dev->type == ARPHRD_ETHER) {
|
2006-03-21 14:42:39 +08:00
|
|
|
if (ifa1->ifa_local != dn_eth2dn(dev->dev_addr)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_dn2eth(mac_addr, ifa1->ifa_local);
|
2010-04-02 05:22:57 +08:00
|
|
|
dev_mc_del(dev, mac_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-25 09:14:31 +08:00
|
|
|
dn_ifaddr_notify(RTM_DELADDR, ifa1);
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 17:16:30 +08:00
|
|
|
blocking_notifier_call_chain(&dnaddr_chain, NETDEV_DOWN, ifa1);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (destroy) {
|
|
|
|
dn_dev_free_ifa(ifa1);
|
|
|
|
|
|
|
|
if (dn_db->ifa_list == NULL)
|
|
|
|
dn_dev_delete(dn_db->dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dn_dev_insert_ifa(struct dn_dev *dn_db, struct dn_ifaddr *ifa)
|
|
|
|
{
|
|
|
|
struct net_device *dev = dn_db->dev;
|
|
|
|
struct dn_ifaddr *ifa1;
|
|
|
|
unsigned char mac_addr[6];
|
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
/* Check for duplicates */
|
2010-10-29 11:09:24 +08:00
|
|
|
for (ifa1 = rtnl_dereference(dn_db->ifa_list);
|
|
|
|
ifa1 != NULL;
|
|
|
|
ifa1 = rtnl_dereference(ifa1->ifa_next)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ifa1->ifa_local == ifa->ifa_local)
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->type == ARPHRD_ETHER) {
|
2006-03-21 14:42:39 +08:00
|
|
|
if (ifa->ifa_local != dn_eth2dn(dev->dev_addr)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_dn2eth(mac_addr, ifa->ifa_local);
|
2010-04-02 05:22:57 +08:00
|
|
|
dev_mc_add(dev, mac_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ifa->ifa_next = dn_db->ifa_list;
|
2012-01-12 12:41:32 +08:00
|
|
|
rcu_assign_pointer(dn_db->ifa_list, ifa);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-11-25 09:14:31 +08:00
|
|
|
dn_ifaddr_notify(RTM_NEWADDR, ifa);
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 17:16:30 +08:00
|
|
|
blocking_notifier_call_chain(&dnaddr_chain, NETDEV_UP, ifa);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dn_dev_set_ifa(struct net_device *dev, struct dn_ifaddr *ifa)
|
|
|
|
{
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rtnl_dereference(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (dn_db == NULL) {
|
|
|
|
int err;
|
|
|
|
dn_db = dn_dev_create(dev, &err);
|
|
|
|
if (dn_db == NULL)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifa->ifa_dev = dn_db;
|
|
|
|
|
|
|
|
if (dev->flags & IFF_LOOPBACK)
|
|
|
|
ifa->ifa_scope = RT_SCOPE_HOST;
|
|
|
|
|
|
|
|
rv = dn_dev_insert_ifa(dn_db, ifa);
|
|
|
|
if (rv)
|
|
|
|
dn_dev_free_ifa(ifa);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int dn_dev_ioctl(unsigned int cmd, void __user *arg)
|
|
|
|
{
|
|
|
|
char buffer[DN_IFREQ_SIZE];
|
|
|
|
struct ifreq *ifr = (struct ifreq *)buffer;
|
|
|
|
struct sockaddr_dn *sdn = (struct sockaddr_dn *)&ifr->ifr_addr;
|
|
|
|
struct dn_dev *dn_db;
|
|
|
|
struct net_device *dev;
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_ifaddr *ifa = NULL;
|
|
|
|
struct dn_ifaddr __rcu **ifap = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (copy_from_user(ifr, arg, DN_IFREQ_SIZE))
|
|
|
|
return -EFAULT;
|
|
|
|
ifr->ifr_name[IFNAMSIZ-1] = 0;
|
|
|
|
|
2007-09-18 02:56:21 +08:00
|
|
|
dev_load(&init_net, ifr->ifr_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-01 17:43:03 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
break;
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
return -EACCES;
|
|
|
|
if (sdn->sdn_family != AF_DECnet)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
2011-07-01 17:43:03 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
|
2007-09-18 02:56:21 +08:00
|
|
|
if ((dev = __dev_get_by_name(&init_net, ifr->ifr_name)) == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-10-29 11:09:24 +08:00
|
|
|
if ((dn_db = rtnl_dereference(dev->dn_ptr)) != NULL) {
|
|
|
|
for (ifap = &dn_db->ifa_list;
|
|
|
|
(ifa = rtnl_dereference(*ifap)) != NULL;
|
|
|
|
ifap = &ifa->ifa_next)
|
2005-04-17 06:20:36 +08:00
|
|
|
if (strcmp(ifr->ifr_name, ifa->ifa_label) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifa == NULL && cmd != SIOCSIFADDR) {
|
|
|
|
ret = -EADDRNOTAVAIL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-07-01 17:43:03 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
*((__le16 *)sdn->sdn_nodeaddr) = ifa->ifa_local;
|
2020-07-14 22:23:28 +08:00
|
|
|
if (copy_to_user(arg, ifr, DN_IFREQ_SIZE))
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
2011-07-01 17:43:03 +08:00
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
if (!ifa) {
|
|
|
|
if ((ifa = dn_dev_alloc_ifa()) == NULL) {
|
|
|
|
ret = -ENOBUFS;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-07-01 17:43:03 +08:00
|
|
|
memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
|
|
|
|
} else {
|
|
|
|
if (ifa->ifa_local == dn_saddr2dn(sdn))
|
|
|
|
break;
|
|
|
|
dn_dev_del_ifa(dn_db, ifap, 0);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-01 17:43:03 +08:00
|
|
|
ifa->ifa_local = ifa->ifa_address = dn_saddr2dn(sdn);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-01 17:43:03 +08:00
|
|
|
ret = dn_dev_set_ifa(dev, ifa);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
done:
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct net_device *dn_dev_get_default(void)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
2009-11-11 15:40:36 +08:00
|
|
|
|
|
|
|
spin_lock(&dndev_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
dev = decnet_default_device;
|
|
|
|
if (dev) {
|
|
|
|
if (dev->dn_ptr)
|
|
|
|
dev_hold(dev);
|
|
|
|
else
|
|
|
|
dev = NULL;
|
|
|
|
}
|
2009-11-11 15:40:36 +08:00
|
|
|
spin_unlock(&dndev_lock);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dn_dev_set_default(struct net_device *dev, int force)
|
|
|
|
{
|
|
|
|
struct net_device *old = NULL;
|
|
|
|
int rv = -EBUSY;
|
|
|
|
if (!dev->dn_ptr)
|
|
|
|
return -ENODEV;
|
2009-11-11 15:40:36 +08:00
|
|
|
|
|
|
|
spin_lock(&dndev_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (force || decnet_default_device == NULL) {
|
|
|
|
old = decnet_default_device;
|
|
|
|
decnet_default_device = dev;
|
|
|
|
rv = 0;
|
|
|
|
}
|
2009-11-11 15:40:36 +08:00
|
|
|
spin_unlock(&dndev_lock);
|
|
|
|
|
2021-08-05 19:55:27 +08:00
|
|
|
dev_put(old);
|
2005-04-17 06:20:36 +08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_dev_check_default(struct net_device *dev)
|
|
|
|
{
|
2009-11-11 15:40:36 +08:00
|
|
|
spin_lock(&dndev_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dev == decnet_default_device) {
|
|
|
|
decnet_default_device = NULL;
|
|
|
|
} else {
|
|
|
|
dev = NULL;
|
|
|
|
}
|
2009-11-11 15:40:36 +08:00
|
|
|
spin_unlock(&dndev_lock);
|
|
|
|
|
2021-08-05 19:55:27 +08:00
|
|
|
dev_put(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-11-05 02:59:38 +08:00
|
|
|
/*
|
|
|
|
* Called with RTNL
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct dn_dev *dn_dev_by_index(int ifindex)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
struct dn_dev *dn_dev = NULL;
|
2009-11-05 02:59:38 +08:00
|
|
|
|
|
|
|
dev = __dev_get_by_index(&init_net, ifindex);
|
|
|
|
if (dev)
|
2010-10-29 11:09:24 +08:00
|
|
|
dn_dev = rtnl_dereference(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return dn_dev;
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:38:30 +08:00
|
|
|
static const struct nla_policy dn_ifa_policy[IFA_MAX+1] = {
|
2006-11-25 09:14:51 +08:00
|
|
|
[IFA_ADDRESS] = { .type = NLA_U16 },
|
|
|
|
[IFA_LOCAL] = { .type = NLA_U16 },
|
|
|
|
[IFA_LABEL] = { .type = NLA_STRING,
|
|
|
|
.len = IFNAMSIZ - 1 },
|
2013-12-08 19:16:09 +08:00
|
|
|
[IFA_FLAGS] = { .type = NLA_U32 },
|
2006-11-25 09:14:51 +08:00
|
|
|
};
|
|
|
|
|
2017-04-17 00:48:24 +08:00
|
|
|
static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-03-26 01:26:21 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2006-11-25 09:14:51 +08:00
|
|
|
struct nlattr *tb[IFA_MAX+1];
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_dev *dn_db;
|
2006-11-25 09:14:51 +08:00
|
|
|
struct ifaddrmsg *ifm;
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_ifaddr *ifa;
|
|
|
|
struct dn_ifaddr __rcu **ifap;
|
2007-11-30 21:21:31 +08:00
|
|
|
int err = -EINVAL;
|
|
|
|
|
2014-04-24 05:29:27 +08:00
|
|
|
if (!netlink_capable(skb, CAP_NET_ADMIN))
|
2012-11-16 11:03:00 +08:00
|
|
|
return -EPERM;
|
|
|
|
|
2009-11-26 07:14:13 +08:00
|
|
|
if (!net_eq(net, &init_net))
|
2007-11-30 21:21:31 +08:00
|
|
|
goto errout;
|
2006-11-25 09:14:51 +08:00
|
|
|
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 20:07:28 +08:00
|
|
|
err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
|
|
|
|
dn_ifa_policy, extack);
|
2006-11-25 09:14:51 +08:00
|
|
|
if (err < 0)
|
|
|
|
goto errout;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-30 20:43:31 +08:00
|
|
|
err = -ENODEV;
|
2006-11-25 09:14:51 +08:00
|
|
|
ifm = nlmsg_data(nlh);
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((dn_db = dn_dev_by_index(ifm->ifa_index)) == NULL)
|
2006-11-25 09:14:51 +08:00
|
|
|
goto errout;
|
|
|
|
|
2007-11-30 20:43:31 +08:00
|
|
|
err = -EADDRNOTAVAIL;
|
2010-10-29 11:09:24 +08:00
|
|
|
for (ifap = &dn_db->ifa_list;
|
|
|
|
(ifa = rtnl_dereference(*ifap)) != NULL;
|
|
|
|
ifap = &ifa->ifa_next) {
|
2006-11-25 09:14:51 +08:00
|
|
|
if (tb[IFA_LOCAL] &&
|
|
|
|
nla_memcmp(tb[IFA_LOCAL], &ifa->ifa_local, 2))
|
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
if (tb[IFA_LABEL] && nla_strcmp(tb[IFA_LABEL], ifa->ifa_label))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
dn_dev_del_ifa(dn_db, ifap, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
errout:
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-04-17 00:48:24 +08:00
|
|
|
static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-03-26 01:26:21 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2006-11-25 09:14:51 +08:00
|
|
|
struct nlattr *tb[IFA_MAX+1];
|
2005-04-17 06:20:36 +08:00
|
|
|
struct net_device *dev;
|
|
|
|
struct dn_dev *dn_db;
|
2006-11-25 09:14:51 +08:00
|
|
|
struct ifaddrmsg *ifm;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_ifaddr *ifa;
|
2006-11-25 09:14:51 +08:00
|
|
|
int err;
|
|
|
|
|
2014-04-24 05:29:27 +08:00
|
|
|
if (!netlink_capable(skb, CAP_NET_ADMIN))
|
2012-11-16 11:03:00 +08:00
|
|
|
return -EPERM;
|
|
|
|
|
2009-11-26 07:14:13 +08:00
|
|
|
if (!net_eq(net, &init_net))
|
2007-11-30 21:21:31 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 20:07:28 +08:00
|
|
|
err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
|
|
|
|
dn_ifa_policy, extack);
|
2006-11-25 09:14:51 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
if (tb[IFA_LOCAL] == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
ifm = nlmsg_data(nlh);
|
2007-09-18 02:56:21 +08:00
|
|
|
if ((dev = __dev_get_by_index(&init_net, ifm->ifa_index)) == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2010-10-29 11:09:24 +08:00
|
|
|
if ((dn_db = rtnl_dereference(dev->dn_ptr)) == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_db = dn_dev_create(dev, &err);
|
|
|
|
if (!dn_db)
|
|
|
|
return err;
|
|
|
|
}
|
2007-02-09 22:24:40 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((ifa = dn_dev_alloc_ifa()) == NULL)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
if (tb[IFA_ADDRESS] == NULL)
|
|
|
|
tb[IFA_ADDRESS] = tb[IFA_LOCAL];
|
|
|
|
|
|
|
|
ifa->ifa_local = nla_get_le16(tb[IFA_LOCAL]);
|
|
|
|
ifa->ifa_address = nla_get_le16(tb[IFA_ADDRESS]);
|
2013-12-08 19:16:09 +08:00
|
|
|
ifa->ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) :
|
|
|
|
ifm->ifa_flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
ifa->ifa_scope = ifm->ifa_scope;
|
|
|
|
ifa->ifa_dev = dn_db;
|
2006-11-25 09:14:51 +08:00
|
|
|
|
|
|
|
if (tb[IFA_LABEL])
|
2020-11-16 01:08:06 +08:00
|
|
|
nla_strscpy(ifa->ifa_label, tb[IFA_LABEL], IFNAMSIZ);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
|
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
err = dn_dev_insert_ifa(dn_db, ifa);
|
|
|
|
if (err)
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_dev_free_ifa(ifa);
|
2006-11-25 09:14:51 +08:00
|
|
|
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-11-25 09:14:07 +08:00
|
|
|
static inline size_t dn_ifaddr_nlmsg_size(void)
|
|
|
|
{
|
|
|
|
return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
|
|
|
|
+ nla_total_size(IFNAMSIZ) /* IFA_LABEL */
|
|
|
|
+ nla_total_size(2) /* IFA_ADDRESS */
|
2013-12-08 19:16:09 +08:00
|
|
|
+ nla_total_size(2) /* IFA_LOCAL */
|
|
|
|
+ nla_total_size(4); /* IFA_FLAGS */
|
2006-11-25 09:14:07 +08:00
|
|
|
}
|
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
static int dn_nl_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
|
2012-09-08 04:12:54 +08:00
|
|
|
u32 portid, u32 seq, int event, unsigned int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ifaddrmsg *ifm;
|
|
|
|
struct nlmsghdr *nlh;
|
2013-12-08 19:16:09 +08:00
|
|
|
u32 ifa_flags = ifa->ifa_flags | IFA_F_PERMANENT;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-08 04:12:54 +08:00
|
|
|
nlh = nlmsg_put(skb, portid, seq, event, sizeof(*ifm), flags);
|
2006-11-25 09:14:51 +08:00
|
|
|
if (nlh == NULL)
|
2007-02-01 15:16:40 +08:00
|
|
|
return -EMSGSIZE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
ifm = nlmsg_data(nlh);
|
2005-04-17 06:20:36 +08:00
|
|
|
ifm->ifa_family = AF_DECnet;
|
|
|
|
ifm->ifa_prefixlen = 16;
|
2013-12-08 19:16:09 +08:00
|
|
|
ifm->ifa_flags = ifa_flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
ifm->ifa_scope = ifa->ifa_scope;
|
|
|
|
ifm->ifa_index = ifa->ifa_dev->dev->ifindex;
|
2006-11-25 09:14:51 +08:00
|
|
|
|
2012-04-02 08:15:14 +08:00
|
|
|
if ((ifa->ifa_address &&
|
|
|
|
nla_put_le16(skb, IFA_ADDRESS, ifa->ifa_address)) ||
|
|
|
|
(ifa->ifa_local &&
|
|
|
|
nla_put_le16(skb, IFA_LOCAL, ifa->ifa_local)) ||
|
|
|
|
(ifa->ifa_label[0] &&
|
2013-12-08 19:16:09 +08:00
|
|
|
nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) ||
|
|
|
|
nla_put_u32(skb, IFA_FLAGS, ifa_flags))
|
2012-04-02 08:15:14 +08:00
|
|
|
goto nla_put_failure;
|
2015-01-17 05:09:00 +08:00
|
|
|
nlmsg_end(skb, nlh);
|
|
|
|
return 0;
|
2006-11-25 09:14:51 +08:00
|
|
|
|
|
|
|
nla_put_failure:
|
2007-02-01 15:16:40 +08:00
|
|
|
nlmsg_cancel(skb, nlh);
|
|
|
|
return -EMSGSIZE;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-11-25 09:14:31 +08:00
|
|
|
static void dn_ifaddr_notify(int event, struct dn_ifaddr *ifa)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
2006-08-15 15:33:35 +08:00
|
|
|
int err = -ENOBUFS;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-11-25 09:14:07 +08:00
|
|
|
skb = alloc_skb(dn_ifaddr_nlmsg_size(), GFP_KERNEL);
|
2006-08-15 15:33:35 +08:00
|
|
|
if (skb == NULL)
|
|
|
|
goto errout;
|
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
err = dn_nl_fill_ifaddr(skb, ifa, 0, 0, event, 0);
|
2007-02-01 15:16:40 +08:00
|
|
|
if (err < 0) {
|
|
|
|
/* -EMSGSIZE implies BUG in dn_ifaddr_nlmsg_size() */
|
|
|
|
WARN_ON(err == -EMSGSIZE);
|
|
|
|
kfree_skb(skb);
|
|
|
|
goto errout;
|
|
|
|
}
|
2009-02-25 15:18:28 +08:00
|
|
|
rtnl_notify(skb, &init_net, 0, RTNLGRP_DECnet_IFADDR, NULL, GFP_KERNEL);
|
|
|
|
return;
|
2006-08-15 15:33:35 +08:00
|
|
|
errout:
|
|
|
|
if (err < 0)
|
2007-11-20 14:26:51 +08:00
|
|
|
rtnl_set_sk_err(&init_net, RTNLGRP_DECnet_IFADDR, err);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
static int dn_nl_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-03-26 01:26:21 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2006-11-25 09:14:51 +08:00
|
|
|
int idx, dn_idx = 0, skip_ndevs, skip_naddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct net_device *dev;
|
|
|
|
struct dn_dev *dn_db;
|
|
|
|
struct dn_ifaddr *ifa;
|
|
|
|
|
2009-11-26 07:14:13 +08:00
|
|
|
if (!net_eq(net, &init_net))
|
2007-11-30 21:21:31 +08:00
|
|
|
return 0;
|
|
|
|
|
2006-11-25 09:14:51 +08:00
|
|
|
skip_ndevs = cb->args[0];
|
|
|
|
skip_naddr = cb->args[1];
|
|
|
|
|
2007-05-04 06:13:45 +08:00
|
|
|
idx = 0;
|
2011-04-28 06:56:07 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
for_each_netdev_rcu(&init_net, dev) {
|
2006-11-25 09:14:51 +08:00
|
|
|
if (idx < skip_ndevs)
|
2007-05-04 06:13:45 +08:00
|
|
|
goto cont;
|
2006-11-25 09:14:51 +08:00
|
|
|
else if (idx > skip_ndevs) {
|
|
|
|
/* Only skip over addresses for first dev dumped
|
|
|
|
* in this iteration (idx == skip_ndevs) */
|
|
|
|
skip_naddr = 0;
|
|
|
|
}
|
|
|
|
|
2011-04-28 06:56:07 +08:00
|
|
|
if ((dn_db = rcu_dereference(dev->dn_ptr)) == NULL)
|
2007-05-04 06:13:45 +08:00
|
|
|
goto cont;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-04-28 06:56:07 +08:00
|
|
|
for (ifa = rcu_dereference(dn_db->ifa_list), dn_idx = 0; ifa;
|
|
|
|
ifa = rcu_dereference(ifa->ifa_next), dn_idx++) {
|
2006-11-25 09:14:51 +08:00
|
|
|
if (dn_idx < skip_naddr)
|
2007-09-11 16:45:15 +08:00
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-08 04:12:54 +08:00
|
|
|
if (dn_nl_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).portid,
|
2006-11-25 09:14:51 +08:00
|
|
|
cb->nlh->nlmsg_seq, RTM_NEWADDR,
|
|
|
|
NLM_F_MULTI) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2007-05-04 06:13:45 +08:00
|
|
|
cont:
|
|
|
|
idx++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
done:
|
2011-04-28 06:56:07 +08:00
|
|
|
rcu_read_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
cb->args[0] = idx;
|
|
|
|
cb->args[1] = dn_idx;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2006-03-21 14:42:39 +08:00
|
|
|
static int dn_dev_get_first(struct net_device *dev, __le16 *addr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_ifaddr *ifa;
|
|
|
|
int rv = -ENODEV;
|
2009-11-11 15:39:27 +08:00
|
|
|
|
2010-10-29 11:09:24 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
dn_db = rcu_dereference(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dn_db == NULL)
|
|
|
|
goto out;
|
2009-11-11 15:39:27 +08:00
|
|
|
|
2010-10-29 11:09:24 +08:00
|
|
|
ifa = rcu_dereference(dn_db->ifa_list);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ifa != NULL) {
|
|
|
|
*addr = ifa->ifa_local;
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
out:
|
2010-10-29 11:09:24 +08:00
|
|
|
rcu_read_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Find a default address to bind to.
|
|
|
|
*
|
|
|
|
* This is one of those areas where the initial VMS concepts don't really
|
|
|
|
* map onto the Linux concepts, and since we introduced multiple addresses
|
|
|
|
* per interface we have to cope with slightly odd ways of finding out what
|
|
|
|
* "our address" really is. Mostly it's not a problem; for this we just guess
|
|
|
|
* a sensible default. Eventually the routing code will take care of all the
|
|
|
|
* nasties for us I hope.
|
|
|
|
*/
|
2006-03-21 14:42:39 +08:00
|
|
|
int dn_dev_bind_default(__le16 *addr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
int rv;
|
|
|
|
dev = dn_dev_get_default();
|
|
|
|
last_chance:
|
|
|
|
if (dev) {
|
|
|
|
rv = dn_dev_get_first(dev, addr);
|
|
|
|
dev_put(dev);
|
2007-09-27 13:10:56 +08:00
|
|
|
if (rv == 0 || dev == init_net.loopback_dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
return rv;
|
|
|
|
}
|
2007-09-27 13:10:56 +08:00
|
|
|
dev = init_net.loopback_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_hold(dev);
|
|
|
|
goto last_chance;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
|
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
struct endnode_hello_message *msg;
|
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
__le16 *pktlen;
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rcu_dereference_raw(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if ((skb = dn_alloc_skb(NULL, sizeof(*msg), GFP_ATOMIC)) == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
skb->dev = dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
networking: make skb_put & friends return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions (skb_put, __skb_put and pskb_put) return void *
and remove all the casts across the tree, adding a (u8 *) cast only
where the unsigned char pointer was used directly, all done with the
following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_put, __skb_put };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_put, __skb_put };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
which actually doesn't cover pskb_put since there are only three
users overall.
A handful of stragglers were converted manually, notably a macro in
drivers/isdn/i4l/isdn_bsdcomp.c and, oddly enough, one of the many
instances in net/bluetooth/hci_sock.c. In the former file, I also
had to fix one whitespace problem spatch introduced.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:21 +08:00
|
|
|
msg = skb_put(skb, sizeof(*msg));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
msg->msgflg = 0x0D;
|
|
|
|
memcpy(msg->tiver, dn_eco_version, 3);
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_dn2eth(msg->id, ifa->ifa_local);
|
2007-02-09 22:24:40 +08:00
|
|
|
msg->iinfo = DN_RT_INFO_ENDN;
|
2008-11-27 16:12:47 +08:00
|
|
|
msg->blksize = cpu_to_le16(mtu2blksize(dev));
|
2007-02-09 22:24:40 +08:00
|
|
|
msg->area = 0x00;
|
|
|
|
memset(msg->seed, 0, 8);
|
|
|
|
memcpy(msg->neighbor, dn_hiord, ETH_ALEN);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dn_db->router) {
|
|
|
|
struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
|
|
|
|
dn_dn2eth(msg->neighbor, dn->addr);
|
|
|
|
}
|
|
|
|
|
2008-11-27 16:12:47 +08:00
|
|
|
msg->timer = cpu_to_le16((unsigned short)dn_db->parms.t3);
|
2007-02-09 22:24:40 +08:00
|
|
|
msg->mpd = 0x00;
|
|
|
|
msg->datalen = 0x02;
|
|
|
|
memset(msg->data, 0xAA, 2);
|
|
|
|
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:23 +08:00
|
|
|
pktlen = skb_push(skb, 2);
|
2008-11-27 16:12:47 +08:00
|
|
|
*pktlen = cpu_to_le16(skb->len - 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-11 11:45:18 +08:00
|
|
|
skb_reset_network_header(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dn_rt_finish_output(skb, dn_rt_all_rt_mcast, msg->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define DRDELAY (5 * HZ)
|
|
|
|
|
|
|
|
static int dn_am_i_a_router(struct dn_neigh *dn, struct dn_dev *dn_db, struct dn_ifaddr *ifa)
|
|
|
|
{
|
|
|
|
/* First check time since device went up */
|
2014-08-21 01:43:07 +08:00
|
|
|
if (time_before(jiffies, dn_db->uptime + DRDELAY))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* If there is no router, then yes... */
|
|
|
|
if (!dn_db->router)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* otherwise only if we have a higher priority or.. */
|
|
|
|
if (dn->priority < dn_db->parms.priority)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* if we have equal priority and a higher node number */
|
|
|
|
if (dn->priority != dn_db->parms.priority)
|
|
|
|
return 0;
|
|
|
|
|
2008-11-27 16:12:47 +08:00
|
|
|
if (le16_to_cpu(dn->addr) < le16_to_cpu(ifa->ifa_local))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
|
|
|
|
{
|
|
|
|
int n;
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rcu_dereference_raw(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
size_t size;
|
|
|
|
unsigned char *ptr;
|
|
|
|
unsigned char *i1, *i2;
|
2006-03-21 14:42:39 +08:00
|
|
|
__le16 *pktlen;
|
2005-04-17 06:20:36 +08:00
|
|
|
char *src;
|
|
|
|
|
|
|
|
if (mtu2blksize(dev) < (26 + 7))
|
|
|
|
return;
|
|
|
|
|
|
|
|
n = mtu2blksize(dev) - 26;
|
|
|
|
n /= 7;
|
|
|
|
|
|
|
|
if (n > 32)
|
|
|
|
n = 32;
|
|
|
|
|
|
|
|
size = 2 + 26 + 7 * n;
|
|
|
|
|
|
|
|
if ((skb = dn_alloc_skb(NULL, size, GFP_ATOMIC)) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
skb->dev = dev;
|
|
|
|
ptr = skb_put(skb, size);
|
|
|
|
|
|
|
|
*ptr++ = DN_RT_PKT_CNTL | DN_RT_PKT_ERTH;
|
|
|
|
*ptr++ = 2; /* ECO */
|
|
|
|
*ptr++ = 0;
|
|
|
|
*ptr++ = 0;
|
|
|
|
dn_dn2eth(ptr, ifa->ifa_local);
|
|
|
|
src = ptr;
|
|
|
|
ptr += ETH_ALEN;
|
2007-02-09 22:24:40 +08:00
|
|
|
*ptr++ = dn_db->parms.forwarding == 1 ?
|
2005-04-17 06:20:36 +08:00
|
|
|
DN_RT_INFO_L1RT : DN_RT_INFO_L2RT;
|
2008-11-27 16:12:47 +08:00
|
|
|
*((__le16 *)ptr) = cpu_to_le16(mtu2blksize(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
ptr += 2;
|
2007-02-09 22:24:40 +08:00
|
|
|
*ptr++ = dn_db->parms.priority; /* Priority */
|
2005-04-17 06:20:36 +08:00
|
|
|
*ptr++ = 0; /* Area: Reserved */
|
2008-11-27 16:12:47 +08:00
|
|
|
*((__le16 *)ptr) = cpu_to_le16((unsigned short)dn_db->parms.t3);
|
2005-04-17 06:20:36 +08:00
|
|
|
ptr += 2;
|
|
|
|
*ptr++ = 0; /* MPD: Reserved */
|
|
|
|
i1 = ptr++;
|
|
|
|
memset(ptr, 0, 7); /* Name: Reserved */
|
|
|
|
ptr += 7;
|
|
|
|
i2 = ptr++;
|
|
|
|
|
|
|
|
n = dn_neigh_elist(dev, ptr, n);
|
|
|
|
|
|
|
|
*i2 = 7 * n;
|
|
|
|
*i1 = 8 + *i2;
|
|
|
|
|
|
|
|
skb_trim(skb, (27 + *i2));
|
|
|
|
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:23 +08:00
|
|
|
pktlen = skb_push(skb, 2);
|
2008-11-27 16:12:47 +08:00
|
|
|
*pktlen = cpu_to_le16(skb->len - 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-11 11:45:18 +08:00
|
|
|
skb_reset_network_header(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dn_am_i_a_router(dn, dn_db, ifa)) {
|
|
|
|
struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
|
|
|
|
if (skb2) {
|
|
|
|
dn_rt_finish_output(skb2, dn_rt_all_end_mcast, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa)
|
|
|
|
{
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rcu_dereference_raw(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dn_db->parms.forwarding == 0)
|
|
|
|
dn_send_endnode_hello(dev, ifa);
|
|
|
|
else
|
|
|
|
dn_send_router_hello(dev, ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa)
|
|
|
|
{
|
|
|
|
int tdlen = 16;
|
|
|
|
int size = dev->hard_header_len + 2 + 4 + tdlen;
|
|
|
|
struct sk_buff *skb = dn_alloc_skb(NULL, size, GFP_ATOMIC);
|
|
|
|
int i;
|
|
|
|
unsigned char *ptr;
|
|
|
|
char src[ETH_ALEN];
|
|
|
|
|
|
|
|
if (skb == NULL)
|
|
|
|
return ;
|
|
|
|
|
|
|
|
skb->dev = dev;
|
|
|
|
skb_push(skb, dev->hard_header_len);
|
|
|
|
ptr = skb_put(skb, 2 + 4 + tdlen);
|
|
|
|
|
|
|
|
*ptr++ = DN_RT_PKT_HELO;
|
2006-03-21 14:42:39 +08:00
|
|
|
*((__le16 *)ptr) = ifa->ifa_local;
|
2005-04-17 06:20:36 +08:00
|
|
|
ptr += 2;
|
|
|
|
*ptr++ = tdlen;
|
|
|
|
|
|
|
|
for(i = 0; i < tdlen; i++)
|
|
|
|
*ptr++ = 0252;
|
|
|
|
|
|
|
|
dn_dn2eth(src, ifa->ifa_local);
|
|
|
|
dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dn_eth_up(struct net_device *dev)
|
|
|
|
{
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rcu_dereference_raw(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dn_db->parms.forwarding == 0)
|
2010-04-02 05:22:57 +08:00
|
|
|
dev_mc_add(dev, dn_rt_all_end_mcast);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2010-04-02 05:22:57 +08:00
|
|
|
dev_mc_add(dev, dn_rt_all_rt_mcast);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dn_db->use_long = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_eth_down(struct net_device *dev)
|
|
|
|
{
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rcu_dereference_raw(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dn_db->parms.forwarding == 0)
|
2010-04-02 05:22:57 +08:00
|
|
|
dev_mc_del(dev, dn_rt_all_end_mcast);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2010-04-02 05:22:57 +08:00
|
|
|
dev_mc_del(dev, dn_rt_all_rt_mcast);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_dev_set_timer(struct net_device *dev);
|
|
|
|
|
2017-10-17 08:28:45 +08:00
|
|
|
static void dn_dev_timer_func(struct timer_list *t)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-10-17 08:28:45 +08:00
|
|
|
struct dn_dev *dn_db = from_timer(dn_db, t, timer);
|
|
|
|
struct net_device *dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_ifaddr *ifa;
|
|
|
|
|
2010-10-29 11:09:24 +08:00
|
|
|
rcu_read_lock();
|
2017-10-17 08:28:45 +08:00
|
|
|
dev = dn_db->dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dn_db->t3 <= dn_db->parms.t2) {
|
|
|
|
if (dn_db->parms.timer3) {
|
2010-10-29 11:09:24 +08:00
|
|
|
for (ifa = rcu_dereference(dn_db->ifa_list);
|
|
|
|
ifa;
|
|
|
|
ifa = rcu_dereference(ifa->ifa_next)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(ifa->ifa_flags & IFA_F_SECONDARY))
|
|
|
|
dn_db->parms.timer3(dev, ifa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dn_db->t3 = dn_db->parms.t3;
|
|
|
|
} else {
|
|
|
|
dn_db->t3 -= dn_db->parms.t2;
|
|
|
|
}
|
2010-10-29 11:09:24 +08:00
|
|
|
rcu_read_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_dev_set_timer(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_dev_set_timer(struct net_device *dev)
|
|
|
|
{
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rcu_dereference_raw(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dn_db->parms.t2 > dn_db->parms.t3)
|
|
|
|
dn_db->parms.t2 = dn_db->parms.t3;
|
|
|
|
|
|
|
|
dn_db->timer.expires = jiffies + (dn_db->parms.t2 * HZ);
|
|
|
|
|
|
|
|
add_timer(&dn_db->timer);
|
|
|
|
}
|
|
|
|
|
2008-12-11 07:18:31 +08:00
|
|
|
static struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct dn_dev_parms *p = dn_dev_list;
|
|
|
|
struct dn_dev *dn_db;
|
|
|
|
|
|
|
|
for(i = 0; i < DN_DEV_LIST_SIZE; i++, p++) {
|
|
|
|
if (p->type == dev->type)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*err = -ENODEV;
|
|
|
|
if (i == DN_DEV_LIST_SIZE)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*err = -ENOBUFS;
|
2006-07-22 05:51:30 +08:00
|
|
|
if ((dn_db = kzalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
|
2010-10-29 11:09:24 +08:00
|
|
|
|
2012-01-12 12:41:32 +08:00
|
|
|
rcu_assign_pointer(dev->dn_ptr, dn_db);
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_db->dev = dev;
|
2017-10-17 08:28:45 +08:00
|
|
|
timer_setup(&dn_db->timer, dn_dev_timer_func, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dn_db->uptime = jiffies;
|
2007-01-26 07:51:51 +08:00
|
|
|
|
|
|
|
dn_db->neigh_parms = neigh_parms_alloc(dev, &dn_neigh_table);
|
|
|
|
if (!dn_db->neigh_parms) {
|
2011-08-02 00:19:00 +08:00
|
|
|
RCU_INIT_POINTER(dev->dn_ptr, NULL);
|
2007-01-26 07:51:51 +08:00
|
|
|
kfree(dn_db);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dn_db->parms.up) {
|
|
|
|
if (dn_db->parms.up(dev) < 0) {
|
2007-01-26 07:51:51 +08:00
|
|
|
neigh_parms_release(&dn_neigh_table, dn_db->neigh_parms);
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->dn_ptr = NULL;
|
|
|
|
kfree(dn_db);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dn_dev_sysctl_register(dev, &dn_db->parms);
|
|
|
|
|
|
|
|
dn_dev_set_timer(dev);
|
|
|
|
|
|
|
|
*err = 0;
|
|
|
|
return dn_db;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This processes a device up event. We only start up
|
|
|
|
* the loopback device & ethernet devices with correct
|
tree-wide: fix comment/printk typos
"gadget", "through", "command", "maintain", "maintain", "controller", "address",
"between", "initiali[zs]e", "instead", "function", "select", "already",
"equal", "access", "management", "hierarchy", "registration", "interest",
"relative", "memory", "offset", "already",
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2010-11-02 03:38:34 +08:00
|
|
|
* MAC addresses automatically. Others must be started
|
2005-04-17 06:20:36 +08:00
|
|
|
* specifically.
|
|
|
|
*
|
|
|
|
* FIXME: How should we configure the loopback address ? If we could dispense
|
|
|
|
* with using decnet_address here and for autobind, it will be one less thing
|
|
|
|
* for users to worry about setting up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void dn_dev_up(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct dn_ifaddr *ifa;
|
2006-03-21 14:42:39 +08:00
|
|
|
__le16 addr = decnet_address;
|
2005-04-17 06:20:36 +08:00
|
|
|
int maybe_default = 0;
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rtnl_dereference(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Need to ensure that loopback device has a dn_db attached to it
|
|
|
|
* to allow creation of neighbours against it, even though it might
|
|
|
|
* not have a local address of its own. Might as well do the same for
|
|
|
|
* all autoconfigured interfaces.
|
|
|
|
*/
|
|
|
|
if (dn_db == NULL) {
|
|
|
|
int err;
|
|
|
|
dn_db = dn_dev_create(dev, &err);
|
|
|
|
if (dn_db == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->type == ARPHRD_ETHER) {
|
|
|
|
if (memcmp(dev->dev_addr, dn_hiord, 4) != 0)
|
|
|
|
return;
|
2006-03-21 14:42:39 +08:00
|
|
|
addr = dn_eth2dn(dev->dev_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
maybe_default = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((ifa = dn_dev_alloc_ifa()) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ifa->ifa_local = ifa->ifa_address = addr;
|
|
|
|
ifa->ifa_flags = 0;
|
|
|
|
ifa->ifa_scope = RT_SCOPE_UNIVERSE;
|
|
|
|
strcpy(ifa->ifa_label, dev->name);
|
|
|
|
|
|
|
|
dn_dev_set_ifa(dev, ifa);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Automagically set the default device to the first automatically
|
|
|
|
* configured ethernet card in the system.
|
|
|
|
*/
|
|
|
|
if (maybe_default) {
|
|
|
|
dev_hold(dev);
|
|
|
|
if (dn_dev_set_default(dev, 0))
|
|
|
|
dev_put(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_dev_delete(struct net_device *dev)
|
|
|
|
{
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rtnl_dereference(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dn_db == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
del_timer_sync(&dn_db->timer);
|
|
|
|
dn_dev_sysctl_unregister(&dn_db->parms);
|
|
|
|
dn_dev_check_default(dev);
|
|
|
|
neigh_ifdown(&dn_neigh_table, dev);
|
|
|
|
|
|
|
|
if (dn_db->parms.down)
|
|
|
|
dn_db->parms.down(dev);
|
|
|
|
|
|
|
|
dev->dn_ptr = NULL;
|
|
|
|
|
|
|
|
neigh_parms_release(&dn_neigh_table, dn_db->neigh_parms);
|
|
|
|
neigh_ifdown(&dn_neigh_table, dev);
|
|
|
|
|
|
|
|
if (dn_db->router)
|
|
|
|
neigh_release(dn_db->router);
|
|
|
|
if (dn_db->peer)
|
|
|
|
neigh_release(dn_db->peer);
|
|
|
|
|
|
|
|
kfree(dn_db);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dn_dev_down(struct net_device *dev)
|
|
|
|
{
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rtnl_dereference(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_ifaddr *ifa;
|
|
|
|
|
|
|
|
if (dn_db == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-10-29 11:09:24 +08:00
|
|
|
while ((ifa = rtnl_dereference(dn_db->ifa_list)) != NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_dev_del_ifa(dn_db, &dn_db->ifa_list, 0);
|
|
|
|
dn_dev_free_ifa(ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
dn_dev_delete(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dn_dev_init_pkt(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void dn_dev_veri_pkt(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void dn_dev_hello(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void dn_dev_devices_off(void)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
rtnl_lock();
|
2007-09-18 02:56:21 +08:00
|
|
|
for_each_netdev(&init_net, dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_dev_down(dev);
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void dn_dev_devices_on(void)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
rtnl_lock();
|
2007-09-18 02:56:21 +08:00
|
|
|
for_each_netdev(&init_net, dev) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dev->flags & IFF_UP)
|
|
|
|
dn_dev_up(dev);
|
|
|
|
}
|
|
|
|
rtnl_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
int register_dnaddr_notifier(struct notifier_block *nb)
|
|
|
|
{
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 17:16:30 +08:00
|
|
|
return blocking_notifier_chain_register(&dnaddr_chain, nb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int unregister_dnaddr_notifier(struct notifier_block *nb)
|
|
|
|
{
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 17:16:30 +08:00
|
|
|
return blocking_notifier_chain_unregister(&dnaddr_chain, nb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2007-05-04 06:13:45 +08:00
|
|
|
static inline int is_dn_dev(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-05-04 06:13:45 +08:00
|
|
|
return dev->dn_ptr != NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-05-04 06:13:45 +08:00
|
|
|
static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos)
|
2010-10-29 11:09:24 +08:00
|
|
|
__acquires(RCU)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-05-04 06:13:45 +08:00
|
|
|
int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct net_device *dev;
|
|
|
|
|
2009-11-10 15:54:53 +08:00
|
|
|
rcu_read_lock();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-04 06:13:45 +08:00
|
|
|
if (*pos == 0)
|
|
|
|
return SEQ_START_TOKEN;
|
|
|
|
|
|
|
|
i = 1;
|
2009-11-10 15:54:53 +08:00
|
|
|
for_each_netdev_rcu(&init_net, dev) {
|
2007-05-04 06:13:45 +08:00
|
|
|
if (!is_dn_dev(dev))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (i++ == *pos)
|
|
|
|
return dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-05-04 06:13:45 +08:00
|
|
|
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
{
|
2007-05-04 06:13:45 +08:00
|
|
|
struct net_device *dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
++*pos;
|
2007-05-04 06:13:45 +08:00
|
|
|
|
2011-06-14 00:21:26 +08:00
|
|
|
dev = v;
|
2007-05-04 06:13:45 +08:00
|
|
|
if (v == SEQ_START_TOKEN)
|
2007-09-18 02:56:21 +08:00
|
|
|
dev = net_device_entry(&init_net.dev_base_head);
|
2007-05-04 06:13:45 +08:00
|
|
|
|
2009-11-10 15:54:53 +08:00
|
|
|
for_each_netdev_continue_rcu(&init_net, dev) {
|
2007-05-04 06:13:45 +08:00
|
|
|
if (!is_dn_dev(dev))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_dev_seq_stop(struct seq_file *seq, void *v)
|
2010-10-29 11:09:24 +08:00
|
|
|
__releases(RCU)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-11-10 15:54:53 +08:00
|
|
|
rcu_read_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *dn_type2asc(char type)
|
|
|
|
{
|
2011-07-01 17:43:03 +08:00
|
|
|
switch (type) {
|
|
|
|
case DN_DEV_BCAST:
|
|
|
|
return "B";
|
|
|
|
case DN_DEV_UCAST:
|
|
|
|
return "U";
|
|
|
|
case DN_DEV_MPOINT:
|
|
|
|
return "M";
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return "?";
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dn_dev_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
if (v == SEQ_START_TOKEN)
|
2007-02-09 22:24:40 +08:00
|
|
|
seq_puts(seq, "Name Flags T1 Timer1 T3 Timer3 BlkSize Pri State DevType Router Peer\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
else {
|
|
|
|
struct net_device *dev = v;
|
|
|
|
char peer_buf[DN_ASCBUF_LEN];
|
|
|
|
char router_buf[DN_ASCBUF_LEN];
|
2010-10-29 11:09:24 +08:00
|
|
|
struct dn_dev *dn_db = rcu_dereference(dev->dn_ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
seq_printf(seq, "%-8s %1s %04u %04u %04lu %04lu"
|
2005-04-17 06:20:36 +08:00
|
|
|
" %04hu %03d %02x %-10s %-7s %-7s\n",
|
2018-09-22 03:30:34 +08:00
|
|
|
dev->name,
|
2007-02-09 22:24:40 +08:00
|
|
|
dn_type2asc(dn_db->parms.mode),
|
|
|
|
0, 0,
|
2005-04-17 06:20:36 +08:00
|
|
|
dn_db->t3, dn_db->parms.t3,
|
|
|
|
mtu2blksize(dev),
|
|
|
|
dn_db->parms.priority,
|
|
|
|
dn_db->parms.state, dn_db->parms.name,
|
2008-11-27 16:12:47 +08:00
|
|
|
dn_db->router ? dn_addr2asc(le16_to_cpu(*(__le16 *)dn_db->router->primary_key), router_buf) : "",
|
|
|
|
dn_db->peer ? dn_addr2asc(le16_to_cpu(*(__le16 *)dn_db->peer->primary_key), peer_buf) : "");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-11 14:07:31 +08:00
|
|
|
static const struct seq_operations dn_dev_seq_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.start = dn_dev_seq_start,
|
|
|
|
.next = dn_dev_seq_next,
|
|
|
|
.stop = dn_dev_seq_stop,
|
|
|
|
.show = dn_dev_seq_show,
|
|
|
|
};
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
2007-11-06 13:30:11 +08:00
|
|
|
static int addr[2];
|
2005-04-17 06:20:36 +08:00
|
|
|
module_param_array(addr, int, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(addr, "The DECnet address of this machine: area,node");
|
|
|
|
|
|
|
|
void __init dn_dev_init(void)
|
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
if (addr[0] > 63 || addr[0] < 0) {
|
|
|
|
printk(KERN_ERR "DECnet: Area must be between 0 and 63");
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (addr[1] > 1023 || addr[1] < 0) {
|
|
|
|
printk(KERN_ERR "DECnet: Node must be between 0 and 1023");
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-11-27 16:12:47 +08:00
|
|
|
decnet_address = cpu_to_le16((addr[0] << 10) | addr[1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dn_dev_devices_on();
|
|
|
|
|
2017-12-03 04:44:07 +08:00
|
|
|
rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_NEWADDR,
|
|
|
|
dn_nl_newaddr, NULL, 0);
|
|
|
|
rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_DELADDR,
|
|
|
|
dn_nl_deladdr, NULL, 0);
|
|
|
|
rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_GETADDR,
|
|
|
|
NULL, dn_nl_dump_ifaddr, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-04-14 01:44:18 +08:00
|
|
|
proc_create_seq("decnet_dev", 0444, init_net.proc_net, &dn_dev_seq_ops);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SYSCTL
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < DN_DEV_LIST_SIZE; i++)
|
|
|
|
dn_dev_sysctl_register(NULL, &dn_dev_list[i]);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SYSCTL */
|
|
|
|
}
|
|
|
|
|
|
|
|
void __exit dn_dev_cleanup(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYSCTL
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < DN_DEV_LIST_SIZE; i++)
|
|
|
|
dn_dev_sysctl_unregister(&dn_dev_list[i]);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SYSCTL */
|
|
|
|
|
2013-02-18 09:34:56 +08:00
|
|
|
remove_proc_entry("decnet_dev", init_net.proc_net);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dn_dev_devices_off();
|
|
|
|
}
|