2019-05-21 01:08:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* G8BPQ compatible "AX.25 via ethernet" driver release 004
|
|
|
|
*
|
|
|
|
* This code REQUIRES 2.0.0 or higher/ NET3.029
|
|
|
|
*
|
|
|
|
* This is a "pseudo" network driver to allow AX.25 over Ethernet
|
|
|
|
* using G8BPQ encapsulation. It has been extracted from the protocol
|
|
|
|
* implementation because
|
|
|
|
*
|
|
|
|
* - things got unreadable within the protocol stack
|
|
|
|
* - to cure the protocol stack from "feature-ism"
|
|
|
|
* - a protocol implementation shouldn't need to know on
|
|
|
|
* which hardware it is running
|
|
|
|
* - user-level programs like the AX.25 utilities shouldn't
|
|
|
|
* need to know about the hardware.
|
|
|
|
* - IP over ethernet encapsulated AX.25 was impossible
|
|
|
|
* - rxecho.c did not work
|
|
|
|
* - to have room for extensions
|
|
|
|
* - it just deserves to "live" as an own driver
|
|
|
|
*
|
|
|
|
* This driver can use any ethernet destination address, and can be
|
|
|
|
* limited to accept frames from one dedicated ethernet card only.
|
|
|
|
*
|
|
|
|
* Note that the driver sets up the BPQ devices automagically on
|
|
|
|
* startup or (if started before the "insmod" of an ethernet device)
|
|
|
|
* on "ifconfig up". It hopefully will remove the BPQ on "rmmod"ing
|
|
|
|
* the ethernet device (in fact: as soon as another ethernet or bpq
|
|
|
|
* device gets "ifconfig"ured).
|
|
|
|
*
|
|
|
|
* I have heard that several people are thinking of experiments
|
|
|
|
* with highspeed packet radio using existing ethernet cards.
|
|
|
|
* Well, this driver is prepared for this purpose, just add
|
|
|
|
* your tx key control and a txdelay / tailtime algorithm,
|
|
|
|
* probably some buffering, and /voila/...
|
|
|
|
*
|
|
|
|
* History
|
|
|
|
* BPQ 001 Joerg(DL1BKE) Extracted BPQ code from AX.25
|
|
|
|
* protocol stack and added my own
|
|
|
|
* yet existing patches
|
|
|
|
* BPQ 002 Joerg(DL1BKE) Scan network device list on
|
|
|
|
* startup.
|
|
|
|
* BPQ 003 Joerg(DL1BKE) Ethernet destination address
|
|
|
|
* and accepted source address
|
|
|
|
* can be configured by an ioctl()
|
|
|
|
* call.
|
|
|
|
* Fixed to match Linux networking
|
|
|
|
* changes - 2.1.15.
|
|
|
|
* BPQ 004 Joerg(DL1BKE) Fixed to not lock up on ifconfig.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/net.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>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/ax25.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/netdevice.h>
|
2007-10-04 08:59:30 +08:00
|
|
|
#include <linux/etherdevice.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <net/sock.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
|
|
|
|
#include <net/ip.h>
|
|
|
|
#include <net/arp.h>
|
2007-09-12 18:01:34 +08:00
|
|
|
#include <net/net_namespace.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <linux/bpqether.h>
|
|
|
|
|
2012-10-05 08:11:58 +08:00
|
|
|
static const char banner[] __initconst = KERN_INFO \
|
2009-02-14 19:33:21 +08:00
|
|
|
"AX.25: bpqether driver version 004\n";
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-08-10 10:34:12 +08:00
|
|
|
static int bpq_rcv(struct sk_buff *, struct net_device *, struct packet_type *, struct net_device *);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int bpq_device_event(struct notifier_block *, unsigned long, void *);
|
|
|
|
|
2009-03-09 16:18:29 +08:00
|
|
|
static struct packet_type bpq_packet_type __read_mostly = {
|
2009-02-01 16:45:17 +08:00
|
|
|
.type = cpu_to_be16(ETH_P_BPQ),
|
2005-04-17 06:20:36 +08:00
|
|
|
.func = bpq_rcv,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct notifier_block bpq_dev_notifier = {
|
2013-05-28 09:30:21 +08:00
|
|
|
.notifier_call = bpq_device_event,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct bpqdev {
|
|
|
|
struct list_head bpq_list; /* list of bpq devices chain */
|
|
|
|
struct net_device *ethdev; /* link to ethernet device */
|
|
|
|
struct net_device *axdev; /* bpq device (bpq#) */
|
|
|
|
char dest_addr[6]; /* ether destination address */
|
|
|
|
char acpt_addr[6]; /* accept ether frames from this address only */
|
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(bpq_devices);
|
|
|
|
|
2020-05-03 13:22:19 +08:00
|
|
|
/*
|
|
|
|
* bpqether network devices are paired with ethernet devices below them, so
|
|
|
|
* form a special "super class" of normal ethernet devices; split their locks
|
|
|
|
* off into a separate class since they always nest.
|
|
|
|
*/
|
|
|
|
static struct lock_class_key bpq_netdev_xmit_lock_key;
|
2020-06-09 05:53:01 +08:00
|
|
|
static struct lock_class_key bpq_netdev_addr_lock_key;
|
2020-05-03 13:22:19 +08:00
|
|
|
|
|
|
|
static void bpq_set_lockdep_class_one(struct net_device *dev,
|
|
|
|
struct netdev_queue *txq,
|
|
|
|
void *_unused)
|
|
|
|
{
|
|
|
|
lockdep_set_class(&txq->_xmit_lock, &bpq_netdev_xmit_lock_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bpq_set_lockdep_class(struct net_device *dev)
|
|
|
|
{
|
2020-06-09 05:53:01 +08:00
|
|
|
lockdep_set_class(&dev->addr_list_lock, &bpq_netdev_addr_lock_key);
|
2020-05-03 13:22:19 +08:00
|
|
|
netdev_for_each_tx_queue(dev, bpq_set_lockdep_class_one, NULL);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the ethernet device for a BPQ device
|
|
|
|
*/
|
|
|
|
static inline struct net_device *bpq_get_ether_dev(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct bpqdev *bpq = netdev_priv(dev);
|
|
|
|
|
|
|
|
return bpq ? bpq->ethdev : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the BPQ device for the ethernet device
|
|
|
|
*/
|
|
|
|
static inline struct net_device *bpq_get_ax25_dev(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct bpqdev *bpq;
|
|
|
|
|
2020-05-14 22:11:15 +08:00
|
|
|
list_for_each_entry_rcu(bpq, &bpq_devices, bpq_list,
|
|
|
|
lockdep_rtnl_is_held()) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (bpq->ethdev == dev)
|
|
|
|
return bpq->axdev;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int dev_is_ethdev(struct net_device *dev)
|
|
|
|
{
|
2010-09-23 13:40:09 +08:00
|
|
|
return dev->type == ARPHRD_ETHER && strncmp(dev->name, "dummy", 5);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive an AX.25 frame via an ethernet interface.
|
|
|
|
*/
|
2005-08-10 10:34:12 +08:00
|
|
|
static int bpq_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *ptype, struct net_device *orig_dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char * ptr;
|
|
|
|
struct ethhdr *eth;
|
|
|
|
struct bpqdev *bpq;
|
|
|
|
|
2009-11-26 07:14:13 +08:00
|
|
|
if (!net_eq(dev_net(dev), &init_net))
|
2007-09-18 02:53:39 +08:00
|
|
|
goto drop;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
|
|
|
|
return NET_RX_DROP;
|
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(struct ethhdr)))
|
|
|
|
goto drop;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
dev = bpq_get_ax25_dev(dev);
|
|
|
|
|
|
|
|
if (dev == NULL || !netif_running(dev))
|
|
|
|
goto drop_unlock;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we want to accept frames from just one ethernet device
|
|
|
|
* we check the source address of the sender.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bpq = netdev_priv(dev);
|
|
|
|
|
|
|
|
eth = eth_hdr(skb);
|
|
|
|
|
|
|
|
if (!(bpq->acpt_addr[0] & 0x01) &&
|
2013-12-26 19:40:31 +08:00
|
|
|
!ether_addr_equal(eth->h_source, bpq->acpt_addr))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto drop_unlock;
|
|
|
|
|
|
|
|
if (skb_cow(skb, sizeof(struct ethhdr)))
|
|
|
|
goto drop_unlock;
|
|
|
|
|
|
|
|
len = skb->data[0] + skb->data[1] * 256 - 5;
|
|
|
|
|
|
|
|
skb_pull(skb, 2); /* Remove the length bytes */
|
|
|
|
skb_trim(skb, len); /* Set the length of the data */
|
|
|
|
|
2009-01-09 21:01:31 +08:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ptr = skb_push(skb, 1);
|
|
|
|
*ptr = 0;
|
|
|
|
|
2005-04-25 09:53:06 +08:00
|
|
|
skb->protocol = ax25_type_trans(skb, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
netif_rx(skb);
|
|
|
|
unlock:
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
drop_unlock:
|
|
|
|
kfree_skb(skb);
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
drop:
|
|
|
|
kfree_skb(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send an AX.25 frame via an ethernet interface
|
|
|
|
*/
|
2009-09-01 03:50:43 +08:00
|
|
|
static netdev_tx_t bpq_xmit(struct sk_buff *skb, struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char *ptr;
|
|
|
|
struct bpqdev *bpq;
|
2009-12-28 14:54:55 +08:00
|
|
|
struct net_device *orig_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
int size;
|
|
|
|
|
2015-03-03 23:41:47 +08:00
|
|
|
if (skb->protocol == htons(ETH_P_IP))
|
|
|
|
return ax25_ip_xmit(skb);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Just to be *really* sure not to send anything if the interface
|
|
|
|
* is down, the ethernet device may have gone.
|
|
|
|
*/
|
|
|
|
if (!netif_running(dev)) {
|
|
|
|
kfree_skb(skb);
|
2009-06-16 07:33:24 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-03 14:09:29 +08:00
|
|
|
skb_pull(skb, 1); /* Drop KISS byte */
|
2005-04-17 06:20:36 +08:00
|
|
|
size = skb->len;
|
|
|
|
|
|
|
|
/*
|
2009-09-03 14:09:29 +08:00
|
|
|
* We're about to mess with the skb which may still shared with the
|
|
|
|
* generic networking code so unshare and ensure it's got enough
|
|
|
|
* space for the BPQ headers.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-09-03 14:09:29 +08:00
|
|
|
if (skb_cow(skb, AX25_BPQ_HEADER_LEN)) {
|
|
|
|
if (net_ratelimit())
|
|
|
|
pr_err("bpqether: out of memory\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree_skb(skb);
|
2009-09-03 14:09:29 +08:00
|
|
|
|
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-03 14:09:29 +08:00
|
|
|
ptr = skb_push(skb, 2); /* Make space for length */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
*ptr++ = (size + 5) % 256;
|
|
|
|
*ptr++ = (size + 5) / 256;
|
|
|
|
|
|
|
|
bpq = netdev_priv(dev);
|
|
|
|
|
2009-12-28 14:54:55 +08:00
|
|
|
orig_dev = dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((dev = bpq_get_ether_dev(dev)) == NULL) {
|
2009-12-28 14:54:55 +08:00
|
|
|
orig_dev->stats.tx_dropped++;
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree_skb(skb);
|
2009-06-12 13:20:01 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-25 09:53:06 +08:00
|
|
|
skb->protocol = ax25_type_trans(skb, dev);
|
2007-04-11 11:45:18 +08:00
|
|
|
skb_reset_network_header(skb);
|
2007-10-09 16:36:32 +08:00
|
|
|
dev_hard_header(skb, dev, ETH_P_BPQ, bpq->dest_addr, NULL, 0);
|
2009-01-09 21:01:31 +08:00
|
|
|
dev->stats.tx_packets++;
|
|
|
|
dev->stats.tx_bytes+=skb->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dev_queue_xmit(skb);
|
|
|
|
netif_wake_queue(dev);
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set AX.25 callsign
|
|
|
|
*/
|
|
|
|
static int bpq_set_mac_address(struct net_device *dev, void *addr)
|
|
|
|
{
|
|
|
|
struct sockaddr *sa = (struct sockaddr *)addr;
|
|
|
|
|
2021-10-09 01:53:39 +08:00
|
|
|
dev_addr_set(dev, sa->sa_data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ioctl commands
|
|
|
|
*
|
|
|
|
* SIOCSBPQETHOPT reserved for enhancements
|
|
|
|
* SIOCSBPQETHADDR set the destination and accepted
|
|
|
|
* source ethernet address (broadcast
|
|
|
|
* or multicast: accept all)
|
|
|
|
*/
|
2021-07-27 21:45:04 +08:00
|
|
|
static int bpq_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
|
|
|
|
void __user *data, int cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2021-07-27 21:45:04 +08:00
|
|
|
struct bpq_ethaddr __user *ethaddr = data;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct bpqdev *bpq = netdev_priv(dev);
|
|
|
|
struct bpq_req req;
|
|
|
|
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSBPQETHOPT:
|
2021-07-27 21:45:04 +08:00
|
|
|
if (copy_from_user(&req, data, sizeof(struct bpq_req)))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
switch (req.cmd) {
|
|
|
|
case SIOCGBPQETHPARAM:
|
|
|
|
case SIOCSBPQETHPARAM:
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSBPQETHADDR:
|
|
|
|
if (copy_from_user(bpq->dest_addr, ethaddr->destination, ETH_ALEN))
|
|
|
|
return -EFAULT;
|
|
|
|
if (copy_from_user(bpq->acpt_addr, ethaddr->accept, ETH_ALEN))
|
|
|
|
return -EFAULT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open/close a device
|
|
|
|
*/
|
|
|
|
static int bpq_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
netif_start_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bpq_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2021-06-01 22:00:52 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Proc filesystem
|
|
|
|
*/
|
|
|
|
static void *bpq_seq_start(struct seq_file *seq, loff_t *pos)
|
2009-02-14 19:34:52 +08:00
|
|
|
__acquires(RCU)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
struct bpqdev *bpqdev;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
if (*pos == 0)
|
|
|
|
return SEQ_START_TOKEN;
|
|
|
|
|
2005-10-17 19:42:32 +08:00
|
|
|
list_for_each_entry_rcu(bpqdev, &bpq_devices, bpq_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (i == *pos)
|
|
|
|
return bpqdev;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *bpq_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct list_head *p;
|
2011-01-27 03:28:23 +08:00
|
|
|
struct bpqdev *bpqdev = v;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
++*pos;
|
|
|
|
|
|
|
|
if (v == SEQ_START_TOKEN)
|
2011-01-27 03:28:23 +08:00
|
|
|
p = rcu_dereference(list_next_rcu(&bpq_devices));
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2011-01-27 03:28:23 +08:00
|
|
|
p = rcu_dereference(list_next_rcu(&bpqdev->bpq_list));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return (p == &bpq_devices) ? NULL
|
2007-07-31 15:38:48 +08:00
|
|
|
: list_entry(p, struct bpqdev, bpq_list);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bpq_seq_stop(struct seq_file *seq, void *v)
|
2009-02-14 19:34:52 +08:00
|
|
|
__releases(RCU)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int bpq_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
if (v == SEQ_START_TOKEN)
|
|
|
|
seq_puts(seq,
|
|
|
|
"dev ether destination accept from\n");
|
|
|
|
else {
|
|
|
|
const struct bpqdev *bpqdev = v;
|
|
|
|
|
2008-10-28 06:59:26 +08:00
|
|
|
seq_printf(seq, "%-5s %-10s %pM ",
|
2005-04-17 06:20:36 +08:00
|
|
|
bpqdev->axdev->name, bpqdev->ethdev->name,
|
2008-10-28 06:59:26 +08:00
|
|
|
bpqdev->dest_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-04 08:59:30 +08:00
|
|
|
if (is_multicast_ether_addr(bpqdev->acpt_addr))
|
|
|
|
seq_printf(seq, "*\n");
|
|
|
|
else
|
2008-10-28 06:59:26 +08:00
|
|
|
seq_printf(seq, "%pM\n", bpqdev->acpt_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-15 05:52:18 +08:00
|
|
|
static const struct seq_operations bpq_seqops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.start = bpq_seq_start,
|
|
|
|
.next = bpq_seq_next,
|
|
|
|
.stop = bpq_seq_stop,
|
|
|
|
.show = bpq_seq_show,
|
|
|
|
};
|
2021-06-01 22:00:52 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2009-01-09 21:01:32 +08:00
|
|
|
static const struct net_device_ops bpq_netdev_ops = {
|
|
|
|
.ndo_open = bpq_open,
|
|
|
|
.ndo_stop = bpq_close,
|
|
|
|
.ndo_start_xmit = bpq_xmit,
|
|
|
|
.ndo_set_mac_address = bpq_set_mac_address,
|
2021-07-27 21:45:04 +08:00
|
|
|
.ndo_siocdevprivate = bpq_siocdevprivate,
|
2009-01-09 21:01:32 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void bpq_setup(struct net_device *dev)
|
|
|
|
{
|
2009-01-09 21:01:32 +08:00
|
|
|
dev->netdev_ops = &bpq_netdev_ops;
|
net: Fix inconsistent teardown and release of private netdev state.
Network devices can allocate reasources and private memory using
netdev_ops->ndo_init(). However, the release of these resources
can occur in one of two different places.
Either netdev_ops->ndo_uninit() or netdev->destructor().
The decision of which operation frees the resources depends upon
whether it is necessary for all netdev refs to be released before it
is safe to perform the freeing.
netdev_ops->ndo_uninit() presumably can occur right after the
NETDEV_UNREGISTER notifier completes and the unicast and multicast
address lists are flushed.
netdev->destructor(), on the other hand, does not run until the
netdev references all go away.
Further complicating the situation is that netdev->destructor()
almost universally does also a free_netdev().
This creates a problem for the logic in register_netdevice().
Because all callers of register_netdevice() manage the freeing
of the netdev, and invoke free_netdev(dev) if register_netdevice()
fails.
If netdev_ops->ndo_init() succeeds, but something else fails inside
of register_netdevice(), it does call ndo_ops->ndo_uninit(). But
it is not able to invoke netdev->destructor().
This is because netdev->destructor() will do a free_netdev() and
then the caller of register_netdevice() will do the same.
However, this means that the resources that would normally be released
by netdev->destructor() will not be.
Over the years drivers have added local hacks to deal with this, by
invoking their destructor parts by hand when register_netdevice()
fails.
Many drivers do not try to deal with this, and instead we have leaks.
Let's close this hole by formalizing the distinction between what
private things need to be freed up by netdev->destructor() and whether
the driver needs unregister_netdevice() to perform the free_netdev().
netdev->priv_destructor() performs all actions to free up the private
resources that used to be freed by netdev->destructor(), except for
free_netdev().
netdev->needs_free_netdev is a boolean that indicates whether
free_netdev() should be done at the end of unregister_netdevice().
Now, register_netdevice() can sanely release all resources after
ndo_ops->ndo_init() succeeds, by invoking both ndo_ops->ndo_uninit()
and netdev->priv_destructor().
And at the end of unregister_netdevice(), we invoke
netdev->priv_destructor() and optionally call free_netdev().
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-05-09 00:52:56 +08:00
|
|
|
dev->needs_free_netdev = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dev->flags = 0;
|
2015-07-04 17:22:30 +08:00
|
|
|
dev->features = NETIF_F_LLTX; /* Allow recursion */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-09-12 22:03:45 +08:00
|
|
|
#if IS_ENABLED(CONFIG_AX25)
|
2007-10-09 16:40:57 +08:00
|
|
|
dev->header_ops = &ax25_header_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
dev->type = ARPHRD_AX25;
|
|
|
|
dev->hard_header_len = AX25_MAX_HEADER_LEN + AX25_BPQ_HEADER_LEN;
|
|
|
|
dev->mtu = AX25_DEF_PACLEN;
|
|
|
|
dev->addr_len = AX25_ADDR_LEN;
|
|
|
|
|
2021-10-13 00:06:33 +08:00
|
|
|
memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
|
|
|
|
dev_addr_set(dev, (u8 *)&ax25_defaddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup a new device.
|
|
|
|
*/
|
|
|
|
static int bpq_new_device(struct net_device *edev)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct net_device *ndev;
|
|
|
|
struct bpqdev *bpq;
|
|
|
|
|
net: set name_assign_type in alloc_netdev()
Extend alloc_netdev{,_mq{,s}}() to take name_assign_type as argument, and convert
all users to pass NET_NAME_UNKNOWN.
Coccinelle patch:
@@
expression sizeof_priv, name, setup, txqs, rxqs, count;
@@
(
-alloc_netdev_mqs(sizeof_priv, name, setup, txqs, rxqs)
+alloc_netdev_mqs(sizeof_priv, name, NET_NAME_UNKNOWN, setup, txqs, rxqs)
|
-alloc_netdev_mq(sizeof_priv, name, setup, count)
+alloc_netdev_mq(sizeof_priv, name, NET_NAME_UNKNOWN, setup, count)
|
-alloc_netdev(sizeof_priv, name, setup)
+alloc_netdev(sizeof_priv, name, NET_NAME_UNKNOWN, setup)
)
v9: move comments here from the wrong commit
Signed-off-by: Tom Gundersen <teg@jklm.no>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-07-14 22:37:24 +08:00
|
|
|
ndev = alloc_netdev(sizeof(struct bpqdev), "bpq%d", NET_NAME_UNKNOWN,
|
|
|
|
bpq_setup);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ndev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
|
|
bpq = netdev_priv(ndev);
|
|
|
|
dev_hold(edev);
|
|
|
|
bpq->ethdev = edev;
|
|
|
|
bpq->axdev = ndev;
|
|
|
|
|
2018-06-18 05:40:53 +08:00
|
|
|
eth_broadcast_addr(bpq->dest_addr);
|
|
|
|
eth_broadcast_addr(bpq->acpt_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = register_netdevice(ndev);
|
|
|
|
if (err)
|
|
|
|
goto error;
|
2020-05-03 13:22:19 +08:00
|
|
|
bpq_set_lockdep_class(ndev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* List protected by RTNL */
|
|
|
|
list_add_rcu(&bpq->bpq_list, &bpq_devices);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
dev_put(edev);
|
|
|
|
free_netdev(ndev);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bpq_free_device(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct bpqdev *bpq = netdev_priv(ndev);
|
|
|
|
|
|
|
|
dev_put(bpq->ethdev);
|
|
|
|
list_del_rcu(&bpq->bpq_list);
|
|
|
|
|
|
|
|
unregister_netdevice(ndev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle device status changes.
|
|
|
|
*/
|
2013-05-28 09:30:21 +08:00
|
|
|
static int bpq_device_event(struct notifier_block *this,
|
|
|
|
unsigned long event, void *ptr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-05-28 09:30:21 +08:00
|
|
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-26 07:14:13 +08:00
|
|
|
if (!net_eq(dev_net(dev), &init_net))
|
2007-09-12 19:02:17 +08:00
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
2022-11-03 17:09:05 +08:00
|
|
|
if (!dev_is_ethdev(dev) && !bpq_get_ax25_dev(dev))
|
2005-04-17 06:20:36 +08:00
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case NETDEV_UP: /* new ethernet device -> new BPQ interface */
|
|
|
|
if (bpq_get_ax25_dev(dev) == NULL)
|
|
|
|
bpq_new_device(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NETDEV_DOWN: /* ethernet device closed -> close BPQ interface */
|
|
|
|
if ((dev = bpq_get_ax25_dev(dev)) != NULL)
|
|
|
|
dev_close(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NETDEV_UNREGISTER: /* ethernet device removed -> free BPQ interface */
|
|
|
|
if ((dev = bpq_get_ax25_dev(dev)) != NULL)
|
|
|
|
bpq_free_device(dev);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize driver. To be called from af_ax25 if not compiled as a
|
|
|
|
* module
|
|
|
|
*/
|
|
|
|
static int __init bpq_init_driver(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2018-04-14 01:44:18 +08:00
|
|
|
if (!proc_create_seq("bpqether", 0444, init_net.proc_net, &bpq_seqops)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR
|
|
|
|
"bpq: cannot create /proc/net/bpqether entry.\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
|
|
|
dev_add_pack(&bpq_packet_type);
|
|
|
|
|
|
|
|
register_netdevice_notifier(&bpq_dev_notifier);
|
|
|
|
|
|
|
|
printk(banner);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit bpq_cleanup_driver(void)
|
|
|
|
{
|
|
|
|
struct bpqdev *bpq;
|
|
|
|
|
|
|
|
dev_remove_pack(&bpq_packet_type);
|
|
|
|
|
|
|
|
unregister_netdevice_notifier(&bpq_dev_notifier);
|
|
|
|
|
2013-02-18 09:34:56 +08:00
|
|
|
remove_proc_entry("bpqether", init_net.proc_net);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
while (!list_empty(&bpq_devices)) {
|
|
|
|
bpq = list_entry(bpq_devices.next, struct bpqdev, bpq_list);
|
|
|
|
bpq_free_device(bpq->axdev);
|
|
|
|
}
|
|
|
|
rtnl_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Joerg Reuter DL1BKE <jreuter@yaina.de>");
|
|
|
|
MODULE_DESCRIPTION("Transmit and receive AX.25 packets over Ethernet");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
module_init(bpq_init_driver);
|
|
|
|
module_exit(bpq_cleanup_driver);
|