2019-07-23 16:17:55 +03:00
|
|
|
// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
|
2019-07-24 15:16:29 +03:00
|
|
|
/* gw.c - CAN frame Gateway/Router/Bridge with netlink interface
|
2011-09-01 08:23:23 +04:00
|
|
|
*
|
2019-08-10 22:18:10 +03:00
|
|
|
* Copyright (c) 2019 Volkswagen Group Electronic Research
|
2011-09-01 08:23:23 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of Volkswagen nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, provided that this notice is retained in full, this
|
|
|
|
* software may be distributed under the terms of the GNU General
|
|
|
|
* Public License ("GPL") version 2, in which case the provisions of the
|
|
|
|
* GPL apply INSTEAD OF those given above.
|
|
|
|
*
|
|
|
|
* The provided data structures and external interfaces from this code
|
|
|
|
* are not restricted to be used by modules with a GPL compatible license.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/types.h>
|
2013-01-17 21:43:44 +04:00
|
|
|
#include <linux/kernel.h>
|
2011-09-01 08:23:23 +04:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/rculist.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/can.h>
|
|
|
|
#include <linux/can/core.h>
|
2013-01-17 21:43:41 +04:00
|
|
|
#include <linux/can/skb.h>
|
2011-09-01 08:23:23 +04:00
|
|
|
#include <linux/can/gw.h>
|
|
|
|
#include <net/rtnetlink.h>
|
|
|
|
#include <net/net_namespace.h>
|
|
|
|
#include <net/sock.h>
|
|
|
|
|
2019-08-10 22:18:10 +03:00
|
|
|
#define CAN_GW_VERSION "20190810"
|
2013-01-17 21:43:44 +04:00
|
|
|
#define CAN_GW_NAME "can-gw"
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("PF_CAN netlink gateway");
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
|
MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
|
2013-01-17 21:43:44 +04:00
|
|
|
MODULE_ALIAS(CAN_GW_NAME);
|
|
|
|
|
|
|
|
#define CGW_MIN_HOPS 1
|
|
|
|
#define CGW_MAX_HOPS 6
|
|
|
|
#define CGW_DEFAULT_HOPS 1
|
|
|
|
|
|
|
|
static unsigned int max_hops __read_mostly = CGW_DEFAULT_HOPS;
|
2018-03-24 01:54:38 +03:00
|
|
|
module_param(max_hops, uint, 0444);
|
2013-01-17 21:43:44 +04:00
|
|
|
MODULE_PARM_DESC(max_hops,
|
|
|
|
"maximum " CAN_GW_NAME " routing hops for CAN frames "
|
|
|
|
"(valid values: " __stringify(CGW_MIN_HOPS) "-"
|
|
|
|
__stringify(CGW_MAX_HOPS) " hops, "
|
|
|
|
"default: " __stringify(CGW_DEFAULT_HOPS) ")");
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
static struct notifier_block notifier;
|
|
|
|
static struct kmem_cache *cgw_cache __read_mostly;
|
|
|
|
|
|
|
|
/* structure that contains the (on-the-fly) CAN frame modifications */
|
|
|
|
struct cf_mod {
|
|
|
|
struct {
|
2019-08-10 22:18:09 +03:00
|
|
|
struct canfd_frame and;
|
|
|
|
struct canfd_frame or;
|
|
|
|
struct canfd_frame xor;
|
|
|
|
struct canfd_frame set;
|
2011-09-01 08:23:23 +04:00
|
|
|
} modframe;
|
|
|
|
struct {
|
|
|
|
u8 and;
|
|
|
|
u8 or;
|
|
|
|
u8 xor;
|
|
|
|
u8 set;
|
|
|
|
} modtype;
|
2019-08-10 22:18:09 +03:00
|
|
|
void (*modfunc[MAX_MODFUNCTIONS])(struct canfd_frame *cf,
|
2011-09-01 08:23:23 +04:00
|
|
|
struct cf_mod *mod);
|
|
|
|
|
|
|
|
/* CAN frame checksum calculation after CAN frame modifications */
|
|
|
|
struct {
|
|
|
|
struct cgw_csum_xor xor;
|
|
|
|
struct cgw_csum_crc8 crc8;
|
|
|
|
} csum;
|
|
|
|
struct {
|
2019-08-10 22:18:09 +03:00
|
|
|
void (*xor)(struct canfd_frame *cf,
|
|
|
|
struct cgw_csum_xor *xor);
|
|
|
|
void (*crc8)(struct canfd_frame *cf,
|
|
|
|
struct cgw_csum_crc8 *crc8);
|
2011-09-01 08:23:23 +04:00
|
|
|
} csumfunc;
|
2015-06-09 09:05:10 +03:00
|
|
|
u32 uid;
|
2011-09-01 08:23:23 +04:00
|
|
|
};
|
|
|
|
|
2019-07-24 15:16:29 +03:00
|
|
|
/* So far we just support CAN -> CAN routing and frame modifications.
|
2011-09-01 08:23:23 +04:00
|
|
|
*
|
|
|
|
* The internal can_can_gw structure contains data and attributes for
|
|
|
|
* a CAN -> CAN gateway job.
|
|
|
|
*/
|
|
|
|
struct can_can_gw {
|
|
|
|
struct can_filter filter;
|
|
|
|
int src_idx;
|
|
|
|
int dst_idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* list entry for CAN gateways jobs */
|
|
|
|
struct cgw_job {
|
|
|
|
struct hlist_node list;
|
|
|
|
struct rcu_head rcu;
|
|
|
|
u32 handled_frames;
|
|
|
|
u32 dropped_frames;
|
2013-01-17 21:43:46 +04:00
|
|
|
u32 deleted_frames;
|
2011-09-01 08:23:23 +04:00
|
|
|
struct cf_mod mod;
|
|
|
|
union {
|
|
|
|
/* CAN frame data source */
|
|
|
|
struct net_device *dev;
|
|
|
|
} src;
|
|
|
|
union {
|
|
|
|
/* CAN frame data destination */
|
|
|
|
struct net_device *dev;
|
|
|
|
} dst;
|
|
|
|
union {
|
|
|
|
struct can_can_gw ccgw;
|
|
|
|
/* tbc */
|
|
|
|
};
|
|
|
|
u8 gwtype;
|
2013-08-26 17:05:36 +04:00
|
|
|
u8 limit_hops;
|
2011-09-01 08:23:23 +04:00
|
|
|
u16 flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* modification functions that are invoked in the hot path in can_can_gw_rcv */
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
#define MODFUNC(func, op) static void func(struct canfd_frame *cf, \
|
2011-09-01 08:23:23 +04:00
|
|
|
struct cf_mod *mod) { op ; }
|
|
|
|
|
|
|
|
MODFUNC(mod_and_id, cf->can_id &= mod->modframe.and.can_id)
|
2019-08-10 22:18:09 +03:00
|
|
|
MODFUNC(mod_and_len, cf->len &= mod->modframe.and.len)
|
2019-08-10 22:18:10 +03:00
|
|
|
MODFUNC(mod_and_flags, cf->flags &= mod->modframe.and.flags)
|
2011-09-01 08:23:23 +04:00
|
|
|
MODFUNC(mod_and_data, *(u64 *)cf->data &= *(u64 *)mod->modframe.and.data)
|
|
|
|
MODFUNC(mod_or_id, cf->can_id |= mod->modframe.or.can_id)
|
2019-08-10 22:18:09 +03:00
|
|
|
MODFUNC(mod_or_len, cf->len |= mod->modframe.or.len)
|
2019-08-10 22:18:10 +03:00
|
|
|
MODFUNC(mod_or_flags, cf->flags |= mod->modframe.or.flags)
|
2011-09-01 08:23:23 +04:00
|
|
|
MODFUNC(mod_or_data, *(u64 *)cf->data |= *(u64 *)mod->modframe.or.data)
|
|
|
|
MODFUNC(mod_xor_id, cf->can_id ^= mod->modframe.xor.can_id)
|
2019-08-10 22:18:09 +03:00
|
|
|
MODFUNC(mod_xor_len, cf->len ^= mod->modframe.xor.len)
|
2019-08-10 22:18:10 +03:00
|
|
|
MODFUNC(mod_xor_flags, cf->flags ^= mod->modframe.xor.flags)
|
2011-09-01 08:23:23 +04:00
|
|
|
MODFUNC(mod_xor_data, *(u64 *)cf->data ^= *(u64 *)mod->modframe.xor.data)
|
|
|
|
MODFUNC(mod_set_id, cf->can_id = mod->modframe.set.can_id)
|
2019-08-10 22:18:09 +03:00
|
|
|
MODFUNC(mod_set_len, cf->len = mod->modframe.set.len)
|
2019-08-10 22:18:10 +03:00
|
|
|
MODFUNC(mod_set_flags, cf->flags = mod->modframe.set.flags)
|
2011-09-01 08:23:23 +04:00
|
|
|
MODFUNC(mod_set_data, *(u64 *)cf->data = *(u64 *)mod->modframe.set.data)
|
|
|
|
|
2019-08-10 22:18:10 +03:00
|
|
|
static void mod_and_fddata(struct canfd_frame *cf, struct cf_mod *mod)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < CANFD_MAX_DLEN; i += 8)
|
|
|
|
*(u64 *)(cf->data + i) &= *(u64 *)(mod->modframe.and.data + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mod_or_fddata(struct canfd_frame *cf, struct cf_mod *mod)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < CANFD_MAX_DLEN; i += 8)
|
|
|
|
*(u64 *)(cf->data + i) |= *(u64 *)(mod->modframe.or.data + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mod_xor_fddata(struct canfd_frame *cf, struct cf_mod *mod)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < CANFD_MAX_DLEN; i += 8)
|
|
|
|
*(u64 *)(cf->data + i) ^= *(u64 *)(mod->modframe.xor.data + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mod_set_fddata(struct canfd_frame *cf, struct cf_mod *mod)
|
|
|
|
{
|
|
|
|
memcpy(cf->data, mod->modframe.set.data, CANFD_MAX_DLEN);
|
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
static void canframecpy(struct canfd_frame *dst, struct can_frame *src)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2019-07-24 15:16:29 +03:00
|
|
|
/* Copy the struct members separately to ensure that no uninitialized
|
2011-09-01 08:23:23 +04:00
|
|
|
* data are copied in the 3 bytes hole of the struct. This is needed
|
|
|
|
* to make easy compares of the data in the struct cf_mod.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dst->can_id = src->can_id;
|
2019-08-10 22:18:09 +03:00
|
|
|
dst->len = src->can_dlc;
|
2011-09-01 08:23:23 +04:00
|
|
|
*(u64 *)dst->data = *(u64 *)src->data;
|
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:10 +03:00
|
|
|
static void canfdframecpy(struct canfd_frame *dst, struct canfd_frame *src)
|
|
|
|
{
|
|
|
|
/* Copy the struct members separately to ensure that no uninitialized
|
|
|
|
* data are copied in the 2 bytes hole of the struct. This is needed
|
|
|
|
* to make easy compares of the data in the struct cf_mod.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dst->can_id = src->can_id;
|
|
|
|
dst->flags = src->flags;
|
|
|
|
dst->len = src->len;
|
|
|
|
memcpy(dst->data, src->data, CANFD_MAX_DLEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cgw_chk_csum_parms(s8 fr, s8 to, s8 re, struct rtcanmsg *r)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2019-08-10 22:18:09 +03:00
|
|
|
s8 dlen = CAN_MAX_DLEN;
|
|
|
|
|
2019-08-10 22:18:10 +03:00
|
|
|
if (r->flags & CGW_FLAGS_CAN_FD)
|
|
|
|
dlen = CANFD_MAX_DLEN;
|
|
|
|
|
2019-07-24 15:16:29 +03:00
|
|
|
/* absolute dlc values 0 .. 7 => 0 .. 7, e.g. data [0]
|
2011-09-01 08:23:23 +04:00
|
|
|
* relative to received dlc -1 .. -8 :
|
|
|
|
* e.g. for received dlc = 8
|
|
|
|
* -1 => index = 7 (data[7])
|
|
|
|
* -3 => index = 5 (data[5])
|
|
|
|
* -8 => index = 0 (data[0])
|
|
|
|
*/
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (fr >= -dlen && fr < dlen &&
|
|
|
|
to >= -dlen && to < dlen &&
|
|
|
|
re >= -dlen && re < dlen)
|
2011-09-01 08:23:23 +04:00
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
static inline int calc_idx(int idx, int rx_len)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
|
|
|
if (idx < 0)
|
2019-08-10 22:18:09 +03:00
|
|
|
return rx_len + idx;
|
2011-09-01 08:23:23 +04:00
|
|
|
else
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
static void cgw_csum_xor_rel(struct canfd_frame *cf, struct cgw_csum_xor *xor)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2019-08-10 22:18:09 +03:00
|
|
|
int from = calc_idx(xor->from_idx, cf->len);
|
|
|
|
int to = calc_idx(xor->to_idx, cf->len);
|
|
|
|
int res = calc_idx(xor->result_idx, cf->len);
|
2011-09-01 08:23:23 +04:00
|
|
|
u8 val = xor->init_xor_val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (from < 0 || to < 0 || res < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (from <= to) {
|
|
|
|
for (i = from; i <= to; i++)
|
|
|
|
val ^= cf->data[i];
|
|
|
|
} else {
|
|
|
|
for (i = from; i >= to; i--)
|
|
|
|
val ^= cf->data[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
cf->data[res] = val;
|
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
static void cgw_csum_xor_pos(struct canfd_frame *cf, struct cgw_csum_xor *xor)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
|
|
|
u8 val = xor->init_xor_val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = xor->from_idx; i <= xor->to_idx; i++)
|
|
|
|
val ^= cf->data[i];
|
|
|
|
|
|
|
|
cf->data[xor->result_idx] = val;
|
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
static void cgw_csum_xor_neg(struct canfd_frame *cf, struct cgw_csum_xor *xor)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
|
|
|
u8 val = xor->init_xor_val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = xor->from_idx; i >= xor->to_idx; i--)
|
|
|
|
val ^= cf->data[i];
|
|
|
|
|
|
|
|
cf->data[xor->result_idx] = val;
|
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
static void cgw_csum_crc8_rel(struct canfd_frame *cf,
|
|
|
|
struct cgw_csum_crc8 *crc8)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2019-08-10 22:18:09 +03:00
|
|
|
int from = calc_idx(crc8->from_idx, cf->len);
|
|
|
|
int to = calc_idx(crc8->to_idx, cf->len);
|
|
|
|
int res = calc_idx(crc8->result_idx, cf->len);
|
2011-09-01 08:23:23 +04:00
|
|
|
u8 crc = crc8->init_crc_val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (from < 0 || to < 0 || res < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (from <= to) {
|
|
|
|
for (i = crc8->from_idx; i <= crc8->to_idx; i++)
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ cf->data[i]];
|
2011-09-01 08:23:23 +04:00
|
|
|
} else {
|
|
|
|
for (i = crc8->from_idx; i >= crc8->to_idx; i--)
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ cf->data[i]];
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (crc8->profile) {
|
|
|
|
case CGW_CRC8PRF_1U8:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ crc8->profile_data[0]];
|
2011-09-01 08:23:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CGW_CRC8PRF_16U8:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ crc8->profile_data[cf->data[1] & 0xF]];
|
2011-09-01 08:23:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CGW_CRC8PRF_SFFID_XOR:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ (cf->can_id & 0xFF) ^
|
2011-09-01 08:23:23 +04:00
|
|
|
(cf->can_id >> 8 & 0xFF)];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-24 15:31:48 +03:00
|
|
|
cf->data[crc8->result_idx] = crc ^ crc8->final_xor_val;
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
static void cgw_csum_crc8_pos(struct canfd_frame *cf,
|
|
|
|
struct cgw_csum_crc8 *crc8)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
|
|
|
u8 crc = crc8->init_crc_val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = crc8->from_idx; i <= crc8->to_idx; i++)
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ cf->data[i]];
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
switch (crc8->profile) {
|
|
|
|
case CGW_CRC8PRF_1U8:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ crc8->profile_data[0]];
|
2011-09-01 08:23:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CGW_CRC8PRF_16U8:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ crc8->profile_data[cf->data[1] & 0xF]];
|
2011-09-01 08:23:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CGW_CRC8PRF_SFFID_XOR:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ (cf->can_id & 0xFF) ^
|
2011-09-01 08:23:23 +04:00
|
|
|
(cf->can_id >> 8 & 0xFF)];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-24 15:31:48 +03:00
|
|
|
cf->data[crc8->result_idx] = crc ^ crc8->final_xor_val;
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
static void cgw_csum_crc8_neg(struct canfd_frame *cf,
|
|
|
|
struct cgw_csum_crc8 *crc8)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
|
|
|
u8 crc = crc8->init_crc_val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = crc8->from_idx; i >= crc8->to_idx; i--)
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ cf->data[i]];
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
switch (crc8->profile) {
|
|
|
|
case CGW_CRC8PRF_1U8:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ crc8->profile_data[0]];
|
2011-09-01 08:23:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CGW_CRC8PRF_16U8:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ crc8->profile_data[cf->data[1] & 0xF]];
|
2011-09-01 08:23:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CGW_CRC8PRF_SFFID_XOR:
|
2019-07-24 15:31:48 +03:00
|
|
|
crc = crc8->crctab[crc ^ (cf->can_id & 0xFF) ^
|
2011-09-01 08:23:23 +04:00
|
|
|
(cf->can_id >> 8 & 0xFF)];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-24 15:31:48 +03:00
|
|
|
cf->data[crc8->result_idx] = crc ^ crc8->final_xor_val;
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the receive & process & send function */
|
|
|
|
static void can_can_gw_rcv(struct sk_buff *skb, void *data)
|
|
|
|
{
|
|
|
|
struct cgw_job *gwj = (struct cgw_job *)data;
|
2019-08-10 22:18:09 +03:00
|
|
|
struct canfd_frame *cf;
|
2011-09-01 08:23:23 +04:00
|
|
|
struct sk_buff *nskb;
|
|
|
|
int modidx = 0;
|
|
|
|
|
2019-08-10 22:18:10 +03:00
|
|
|
/* process strictly Classic CAN or CAN FD frames */
|
|
|
|
if (gwj->flags & CGW_FLAGS_CAN_FD) {
|
|
|
|
if (skb->len != CANFD_MTU)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (skb->len != CAN_MTU)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-24 15:16:29 +03:00
|
|
|
/* Do not handle CAN frames routed more than 'max_hops' times.
|
2013-01-17 21:43:44 +04:00
|
|
|
* In general we should never catch this delimiter which is intended
|
|
|
|
* to cover a misconfiguration protection (e.g. circular CAN routes).
|
|
|
|
*
|
|
|
|
* The Controller Area Network controllers only accept CAN frames with
|
|
|
|
* correct CRCs - which are not visible in the controller registers.
|
|
|
|
* According to skbuff.h documentation the csum_start element for IP
|
2014-12-05 20:54:38 +03:00
|
|
|
* checksums is undefined/unused when ip_summed == CHECKSUM_UNNECESSARY.
|
2013-01-17 21:43:44 +04:00
|
|
|
* Only CAN skbs can be processed here which already have this property.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define cgw_hops(skb) ((skb)->csum_start)
|
|
|
|
|
|
|
|
BUG_ON(skb->ip_summed != CHECKSUM_UNNECESSARY);
|
|
|
|
|
2013-01-17 21:43:46 +04:00
|
|
|
if (cgw_hops(skb) >= max_hops) {
|
|
|
|
/* indicate deleted frames due to misconfiguration */
|
|
|
|
gwj->deleted_frames++;
|
2011-09-01 08:23:23 +04:00
|
|
|
return;
|
2013-01-17 21:43:46 +04:00
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
if (!(gwj->dst.dev->flags & IFF_UP)) {
|
|
|
|
gwj->dropped_frames++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-17 21:43:41 +04:00
|
|
|
/* is sending the skb back to the incoming interface not allowed? */
|
|
|
|
if (!(gwj->flags & CGW_FLAGS_CAN_IIF_TX_OK) &&
|
2013-01-28 12:33:33 +04:00
|
|
|
can_skb_prv(skb)->ifindex == gwj->dst.dev->ifindex)
|
2013-01-17 21:43:41 +04:00
|
|
|
return;
|
|
|
|
|
2019-07-24 15:16:29 +03:00
|
|
|
/* clone the given skb, which has not been done in can_rcv()
|
2011-09-01 08:23:23 +04:00
|
|
|
*
|
|
|
|
* When there is at least one modification function activated,
|
|
|
|
* we need to copy the skb as we want to modify skb->data.
|
|
|
|
*/
|
|
|
|
if (gwj->mod.modfunc[0])
|
|
|
|
nskb = skb_copy(skb, GFP_ATOMIC);
|
|
|
|
else
|
|
|
|
nskb = skb_clone(skb, GFP_ATOMIC);
|
|
|
|
|
|
|
|
if (!nskb) {
|
|
|
|
gwj->dropped_frames++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-17 21:43:44 +04:00
|
|
|
/* put the incremented hop counter in the cloned skb */
|
|
|
|
cgw_hops(nskb) = cgw_hops(skb) + 1;
|
2013-08-26 17:05:36 +04:00
|
|
|
|
|
|
|
/* first processing of this CAN frame -> adjust to private hop limit */
|
|
|
|
if (gwj->limit_hops && cgw_hops(nskb) == 1)
|
|
|
|
cgw_hops(nskb) = max_hops - gwj->limit_hops + 1;
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
nskb->dev = gwj->dst.dev;
|
|
|
|
|
|
|
|
/* pointer to modifiable CAN frame */
|
2019-08-10 22:18:09 +03:00
|
|
|
cf = (struct canfd_frame *)nskb->data;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
/* perform preprocessed modification functions if there are any */
|
|
|
|
while (modidx < MAX_MODFUNCTIONS && gwj->mod.modfunc[modidx])
|
|
|
|
(*gwj->mod.modfunc[modidx++])(cf, &gwj->mod);
|
|
|
|
|
2019-01-04 17:55:26 +03:00
|
|
|
/* Has the CAN frame been modified? */
|
2011-09-01 08:23:23 +04:00
|
|
|
if (modidx) {
|
2019-01-04 17:55:26 +03:00
|
|
|
/* get available space for the processed CAN frame type */
|
2019-08-10 22:18:09 +03:00
|
|
|
int max_len = nskb->len - offsetof(struct canfd_frame, data);
|
2019-01-04 17:55:26 +03:00
|
|
|
|
|
|
|
/* dlc may have changed, make sure it fits to the CAN frame */
|
2019-08-10 22:18:10 +03:00
|
|
|
if (cf->len > max_len) {
|
|
|
|
/* delete frame due to misconfiguration */
|
|
|
|
gwj->deleted_frames++;
|
|
|
|
kfree_skb(nskb);
|
|
|
|
return;
|
2019-01-04 17:55:26 +03:00
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:10 +03:00
|
|
|
/* check for checksum updates */
|
|
|
|
if (gwj->mod.csumfunc.crc8)
|
|
|
|
(*gwj->mod.csumfunc.crc8)(cf, &gwj->mod.csum.crc8);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:10 +03:00
|
|
|
if (gwj->mod.csumfunc.xor)
|
2011-09-01 08:23:23 +04:00
|
|
|
(*gwj->mod.csumfunc.xor)(cf, &gwj->mod.csum.xor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear the skb timestamp if not configured the other way */
|
|
|
|
if (!(gwj->flags & CGW_FLAGS_CAN_SRC_TSTAMP))
|
2016-12-25 13:38:40 +03:00
|
|
|
nskb->tstamp = 0;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
/* send to netdevice */
|
|
|
|
if (can_send(nskb, gwj->flags & CGW_FLAGS_CAN_ECHO))
|
|
|
|
gwj->dropped_frames++;
|
|
|
|
else
|
|
|
|
gwj->handled_frames++;
|
|
|
|
}
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
static inline int cgw_register_filter(struct net *net, struct cgw_job *gwj)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2017-04-25 09:19:43 +03:00
|
|
|
return can_rx_register(net, gwj->src.dev, gwj->ccgw.filter.can_id,
|
2011-09-01 08:23:23 +04:00
|
|
|
gwj->ccgw.filter.can_mask, can_can_gw_rcv,
|
2017-01-27 19:11:44 +03:00
|
|
|
gwj, "gw", NULL);
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
static inline void cgw_unregister_filter(struct net *net, struct cgw_job *gwj)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2017-04-25 09:19:43 +03:00
|
|
|
can_rx_unregister(net, gwj->src.dev, gwj->ccgw.filter.can_id,
|
2011-09-01 08:23:23 +04:00
|
|
|
gwj->ccgw.filter.can_mask, can_can_gw_rcv, gwj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cgw_notifier(struct notifier_block *nb,
|
2013-05-28 05:30:21 +04:00
|
|
|
unsigned long msg, void *ptr)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2013-05-28 05:30:21 +04:00
|
|
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
2017-04-25 09:19:43 +03:00
|
|
|
struct net *net = dev_net(dev);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
if (dev->type != ARPHRD_CAN)
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
if (msg == NETDEV_UNREGISTER) {
|
|
|
|
struct cgw_job *gwj = NULL;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
struct hlist_node *nx;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
hlist_for_each_entry_safe(gwj, nx, &net->can.cgw_list, list) {
|
2011-09-01 08:23:23 +04:00
|
|
|
if (gwj->src.dev == dev || gwj->dst.dev == dev) {
|
|
|
|
hlist_del(&gwj->list);
|
2017-04-25 09:19:43 +03:00
|
|
|
cgw_unregister_filter(net, gwj);
|
2013-04-09 10:16:04 +04:00
|
|
|
kmem_cache_free(cgw_cache, gwj);
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
2012-07-05 16:19:57 +04:00
|
|
|
static int cgw_put_job(struct sk_buff *skb, struct cgw_job *gwj, int type,
|
|
|
|
u32 pid, u32 seq, int flags)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
|
|
|
struct rtcanmsg *rtcan;
|
2012-07-05 16:19:57 +04:00
|
|
|
struct nlmsghdr *nlh;
|
|
|
|
|
|
|
|
nlh = nlmsg_put(skb, pid, seq, type, sizeof(*rtcan), flags);
|
2011-09-01 08:23:23 +04:00
|
|
|
if (!nlh)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
rtcan = nlmsg_data(nlh);
|
|
|
|
rtcan->can_family = AF_CAN;
|
|
|
|
rtcan->gwtype = gwj->gwtype;
|
|
|
|
rtcan->flags = gwj->flags;
|
|
|
|
|
|
|
|
/* add statistics if available */
|
|
|
|
|
|
|
|
if (gwj->handled_frames) {
|
|
|
|
if (nla_put_u32(skb, CGW_HANDLED, gwj->handled_frames) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gwj->dropped_frames) {
|
|
|
|
if (nla_put_u32(skb, CGW_DROPPED, gwj->dropped_frames) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
2013-01-17 21:43:46 +04:00
|
|
|
if (gwj->deleted_frames) {
|
|
|
|
if (nla_put_u32(skb, CGW_DELETED, gwj->deleted_frames) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
/* check non default settings of attributes */
|
|
|
|
|
2013-08-26 17:05:36 +04:00
|
|
|
if (gwj->limit_hops) {
|
|
|
|
if (nla_put_u8(skb, CGW_LIM_HOPS, gwj->limit_hops) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
2019-08-10 22:18:10 +03:00
|
|
|
if (gwj->flags & CGW_FLAGS_CAN_FD) {
|
|
|
|
struct cgw_fdframe_mod mb;
|
|
|
|
|
|
|
|
if (gwj->mod.modtype.and) {
|
|
|
|
memcpy(&mb.cf, &gwj->mod.modframe.and, sizeof(mb.cf));
|
|
|
|
mb.modtype = gwj->mod.modtype.and;
|
|
|
|
if (nla_put(skb, CGW_FDMOD_AND, sizeof(mb), &mb) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gwj->mod.modtype.or) {
|
|
|
|
memcpy(&mb.cf, &gwj->mod.modframe.or, sizeof(mb.cf));
|
|
|
|
mb.modtype = gwj->mod.modtype.or;
|
|
|
|
if (nla_put(skb, CGW_FDMOD_OR, sizeof(mb), &mb) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gwj->mod.modtype.xor) {
|
|
|
|
memcpy(&mb.cf, &gwj->mod.modframe.xor, sizeof(mb.cf));
|
|
|
|
mb.modtype = gwj->mod.modtype.xor;
|
|
|
|
if (nla_put(skb, CGW_FDMOD_XOR, sizeof(mb), &mb) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gwj->mod.modtype.set) {
|
|
|
|
memcpy(&mb.cf, &gwj->mod.modframe.set, sizeof(mb.cf));
|
|
|
|
mb.modtype = gwj->mod.modtype.set;
|
|
|
|
if (nla_put(skb, CGW_FDMOD_SET, sizeof(mb), &mb) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
} else {
|
2019-08-10 22:18:09 +03:00
|
|
|
struct cgw_frame_mod mb;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (gwj->mod.modtype.and) {
|
|
|
|
memcpy(&mb.cf, &gwj->mod.modframe.and, sizeof(mb.cf));
|
|
|
|
mb.modtype = gwj->mod.modtype.and;
|
|
|
|
if (nla_put(skb, CGW_MOD_AND, sizeof(mb), &mb) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (gwj->mod.modtype.or) {
|
|
|
|
memcpy(&mb.cf, &gwj->mod.modframe.or, sizeof(mb.cf));
|
|
|
|
mb.modtype = gwj->mod.modtype.or;
|
|
|
|
if (nla_put(skb, CGW_MOD_OR, sizeof(mb), &mb) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (gwj->mod.modtype.xor) {
|
|
|
|
memcpy(&mb.cf, &gwj->mod.modframe.xor, sizeof(mb.cf));
|
|
|
|
mb.modtype = gwj->mod.modtype.xor;
|
|
|
|
if (nla_put(skb, CGW_MOD_XOR, sizeof(mb), &mb) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gwj->mod.modtype.set) {
|
|
|
|
memcpy(&mb.cf, &gwj->mod.modframe.set, sizeof(mb.cf));
|
|
|
|
mb.modtype = gwj->mod.modtype.set;
|
|
|
|
if (nla_put(skb, CGW_MOD_SET, sizeof(mb), &mb) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
2015-06-09 09:05:10 +03:00
|
|
|
if (gwj->mod.uid) {
|
|
|
|
if (nla_put_u32(skb, CGW_MOD_UID, gwj->mod.uid) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
if (gwj->mod.csumfunc.crc8) {
|
|
|
|
if (nla_put(skb, CGW_CS_CRC8, CGW_CS_CRC8_LEN,
|
|
|
|
&gwj->mod.csum.crc8) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gwj->mod.csumfunc.xor) {
|
|
|
|
if (nla_put(skb, CGW_CS_XOR, CGW_CS_XOR_LEN,
|
|
|
|
&gwj->mod.csum.xor) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gwj->gwtype == CGW_TYPE_CAN_CAN) {
|
|
|
|
if (gwj->ccgw.filter.can_id || gwj->ccgw.filter.can_mask) {
|
|
|
|
if (nla_put(skb, CGW_FILTER, sizeof(struct can_filter),
|
|
|
|
&gwj->ccgw.filter) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nla_put_u32(skb, CGW_SRC_IF, gwj->ccgw.src_idx) < 0)
|
|
|
|
goto cancel;
|
|
|
|
|
|
|
|
if (nla_put_u32(skb, CGW_DST_IF, gwj->ccgw.dst_idx) < 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
2015-01-17 00:09:00 +03:00
|
|
|
nlmsg_end(skb, nlh);
|
|
|
|
return 0;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
cancel:
|
|
|
|
nlmsg_cancel(skb, nlh);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dump information about all CAN gateway jobs, in response to RTM_GETROUTE */
|
|
|
|
static int cgw_dump_jobs(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
2017-04-25 09:19:43 +03:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2011-09-01 08:23:23 +04:00
|
|
|
struct cgw_job *gwj = NULL;
|
|
|
|
int idx = 0;
|
|
|
|
int s_idx = cb->args[0];
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2017-04-25 09:19:43 +03:00
|
|
|
hlist_for_each_entry_rcu(gwj, &net->can.cgw_list, list) {
|
2011-09-01 08:23:23 +04:00
|
|
|
if (idx < s_idx)
|
|
|
|
goto cont;
|
|
|
|
|
2019-07-24 15:34:42 +03:00
|
|
|
if (cgw_put_job(skb, gwj, RTM_NEWROUTE,
|
|
|
|
NETLINK_CB(cb->skb).portid,
|
|
|
|
cb->nlh->nlmsg_seq, NLM_F_MULTI) < 0)
|
2011-09-01 08:23:23 +04:00
|
|
|
break;
|
|
|
|
cont:
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
cb->args[0] = idx;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2019-07-24 15:31:48 +03:00
|
|
|
static const struct nla_policy cgw_policy[CGW_MAX + 1] = {
|
2012-07-05 16:19:56 +04:00
|
|
|
[CGW_MOD_AND] = { .len = sizeof(struct cgw_frame_mod) },
|
|
|
|
[CGW_MOD_OR] = { .len = sizeof(struct cgw_frame_mod) },
|
|
|
|
[CGW_MOD_XOR] = { .len = sizeof(struct cgw_frame_mod) },
|
|
|
|
[CGW_MOD_SET] = { .len = sizeof(struct cgw_frame_mod) },
|
|
|
|
[CGW_CS_XOR] = { .len = sizeof(struct cgw_csum_xor) },
|
|
|
|
[CGW_CS_CRC8] = { .len = sizeof(struct cgw_csum_crc8) },
|
|
|
|
[CGW_SRC_IF] = { .type = NLA_U32 },
|
|
|
|
[CGW_DST_IF] = { .type = NLA_U32 },
|
|
|
|
[CGW_FILTER] = { .len = sizeof(struct can_filter) },
|
2013-08-26 17:05:36 +04:00
|
|
|
[CGW_LIM_HOPS] = { .type = NLA_U8 },
|
2015-06-09 09:05:10 +03:00
|
|
|
[CGW_MOD_UID] = { .type = NLA_U32 },
|
2019-08-10 22:18:10 +03:00
|
|
|
[CGW_FDMOD_AND] = { .len = sizeof(struct cgw_fdframe_mod) },
|
|
|
|
[CGW_FDMOD_OR] = { .len = sizeof(struct cgw_fdframe_mod) },
|
|
|
|
[CGW_FDMOD_XOR] = { .len = sizeof(struct cgw_fdframe_mod) },
|
|
|
|
[CGW_FDMOD_SET] = { .len = sizeof(struct cgw_fdframe_mod) },
|
2012-07-05 16:19:56 +04:00
|
|
|
};
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
/* check for common and gwtype specific attributes */
|
|
|
|
static int cgw_parse_attr(struct nlmsghdr *nlh, struct cf_mod *mod,
|
2013-08-26 17:05:36 +04:00
|
|
|
u8 gwtype, void *gwtypeattr, u8 *limhops)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2019-07-24 15:31:48 +03:00
|
|
|
struct nlattr *tb[CGW_MAX + 1];
|
2019-08-10 22:18:10 +03:00
|
|
|
struct rtcanmsg *r = nlmsg_data(nlh);
|
2011-09-01 08:23:23 +04:00
|
|
|
int modidx = 0;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
/* initialize modification & checksum data space */
|
|
|
|
memset(mod, 0, sizeof(*mod));
|
|
|
|
|
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 15:07:28 +03:00
|
|
|
err = nlmsg_parse_deprecated(nlh, sizeof(struct rtcanmsg), tb,
|
|
|
|
CGW_MAX, cgw_policy, NULL);
|
2011-09-01 08:23:23 +04:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2013-08-26 17:05:36 +04:00
|
|
|
if (tb[CGW_LIM_HOPS]) {
|
|
|
|
*limhops = nla_get_u8(tb[CGW_LIM_HOPS]);
|
|
|
|
|
|
|
|
if (*limhops < 1 || *limhops > max_hops)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
/* check for AND/OR/XOR/SET modifications */
|
2019-08-10 22:18:10 +03:00
|
|
|
if (r->flags & CGW_FLAGS_CAN_FD) {
|
|
|
|
struct cgw_fdframe_mod mb;
|
|
|
|
|
|
|
|
if (tb[CGW_FDMOD_AND]) {
|
|
|
|
nla_memcpy(&mb, tb[CGW_FDMOD_AND], CGW_FDMODATTR_LEN);
|
|
|
|
|
|
|
|
canfdframecpy(&mod->modframe.and, &mb.cf);
|
|
|
|
mod->modtype.and = mb.modtype;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_ID)
|
|
|
|
mod->modfunc[modidx++] = mod_and_id;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_LEN)
|
|
|
|
mod->modfunc[modidx++] = mod_and_len;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_FLAGS)
|
|
|
|
mod->modfunc[modidx++] = mod_and_flags;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_DATA)
|
|
|
|
mod->modfunc[modidx++] = mod_and_fddata;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[CGW_FDMOD_OR]) {
|
|
|
|
nla_memcpy(&mb, tb[CGW_FDMOD_OR], CGW_FDMODATTR_LEN);
|
|
|
|
|
|
|
|
canfdframecpy(&mod->modframe.or, &mb.cf);
|
|
|
|
mod->modtype.or = mb.modtype;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_ID)
|
|
|
|
mod->modfunc[modidx++] = mod_or_id;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_LEN)
|
|
|
|
mod->modfunc[modidx++] = mod_or_len;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_FLAGS)
|
|
|
|
mod->modfunc[modidx++] = mod_or_flags;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_DATA)
|
|
|
|
mod->modfunc[modidx++] = mod_or_fddata;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[CGW_FDMOD_XOR]) {
|
|
|
|
nla_memcpy(&mb, tb[CGW_FDMOD_XOR], CGW_FDMODATTR_LEN);
|
|
|
|
|
|
|
|
canfdframecpy(&mod->modframe.xor, &mb.cf);
|
|
|
|
mod->modtype.xor = mb.modtype;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_ID)
|
|
|
|
mod->modfunc[modidx++] = mod_xor_id;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_LEN)
|
|
|
|
mod->modfunc[modidx++] = mod_xor_len;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_FLAGS)
|
|
|
|
mod->modfunc[modidx++] = mod_xor_flags;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_DATA)
|
|
|
|
mod->modfunc[modidx++] = mod_xor_fddata;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[CGW_FDMOD_SET]) {
|
|
|
|
nla_memcpy(&mb, tb[CGW_FDMOD_SET], CGW_FDMODATTR_LEN);
|
|
|
|
|
|
|
|
canfdframecpy(&mod->modframe.set, &mb.cf);
|
|
|
|
mod->modtype.set = mb.modtype;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_ID)
|
|
|
|
mod->modfunc[modidx++] = mod_set_id;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_LEN)
|
|
|
|
mod->modfunc[modidx++] = mod_set_len;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_FLAGS)
|
|
|
|
mod->modfunc[modidx++] = mod_set_flags;
|
|
|
|
|
|
|
|
if (mb.modtype & CGW_MOD_DATA)
|
|
|
|
mod->modfunc[modidx++] = mod_set_fddata;
|
|
|
|
}
|
|
|
|
} else {
|
2019-08-10 22:18:09 +03:00
|
|
|
struct cgw_frame_mod mb;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (tb[CGW_MOD_AND]) {
|
|
|
|
nla_memcpy(&mb, tb[CGW_MOD_AND], CGW_MODATTR_LEN);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
canframecpy(&mod->modframe.and, &mb.cf);
|
|
|
|
mod->modtype.and = mb.modtype;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_ID)
|
|
|
|
mod->modfunc[modidx++] = mod_and_id;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_LEN)
|
|
|
|
mod->modfunc[modidx++] = mod_and_len;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_DATA)
|
|
|
|
mod->modfunc[modidx++] = mod_and_data;
|
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (tb[CGW_MOD_OR]) {
|
|
|
|
nla_memcpy(&mb, tb[CGW_MOD_OR], CGW_MODATTR_LEN);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
canframecpy(&mod->modframe.or, &mb.cf);
|
|
|
|
mod->modtype.or = mb.modtype;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_ID)
|
|
|
|
mod->modfunc[modidx++] = mod_or_id;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_LEN)
|
|
|
|
mod->modfunc[modidx++] = mod_or_len;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_DATA)
|
|
|
|
mod->modfunc[modidx++] = mod_or_data;
|
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (tb[CGW_MOD_XOR]) {
|
|
|
|
nla_memcpy(&mb, tb[CGW_MOD_XOR], CGW_MODATTR_LEN);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
canframecpy(&mod->modframe.xor, &mb.cf);
|
|
|
|
mod->modtype.xor = mb.modtype;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_ID)
|
|
|
|
mod->modfunc[modidx++] = mod_xor_id;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_LEN)
|
|
|
|
mod->modfunc[modidx++] = mod_xor_len;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_DATA)
|
|
|
|
mod->modfunc[modidx++] = mod_xor_data;
|
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (tb[CGW_MOD_SET]) {
|
|
|
|
nla_memcpy(&mb, tb[CGW_MOD_SET], CGW_MODATTR_LEN);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
canframecpy(&mod->modframe.set, &mb.cf);
|
|
|
|
mod->modtype.set = mb.modtype;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_ID)
|
|
|
|
mod->modfunc[modidx++] = mod_set_id;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_LEN)
|
|
|
|
mod->modfunc[modidx++] = mod_set_len;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-08-10 22:18:09 +03:00
|
|
|
if (mb.modtype & CGW_MOD_DATA)
|
|
|
|
mod->modfunc[modidx++] = mod_set_data;
|
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for checksum operations after CAN frame modifications */
|
|
|
|
if (modidx) {
|
2012-07-05 16:19:56 +04:00
|
|
|
if (tb[CGW_CS_CRC8]) {
|
2012-07-05 16:19:58 +04:00
|
|
|
struct cgw_csum_crc8 *c = nla_data(tb[CGW_CS_CRC8]);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
err = cgw_chk_csum_parms(c->from_idx, c->to_idx,
|
2019-08-10 22:18:10 +03:00
|
|
|
c->result_idx, r);
|
2011-09-01 08:23:23 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
nla_memcpy(&mod->csum.crc8, tb[CGW_CS_CRC8],
|
|
|
|
CGW_CS_CRC8_LEN);
|
|
|
|
|
2019-07-24 15:16:29 +03:00
|
|
|
/* select dedicated processing function to reduce
|
2011-09-01 08:23:23 +04:00
|
|
|
* runtime operations in receive hot path.
|
|
|
|
*/
|
|
|
|
if (c->from_idx < 0 || c->to_idx < 0 ||
|
|
|
|
c->result_idx < 0)
|
|
|
|
mod->csumfunc.crc8 = cgw_csum_crc8_rel;
|
|
|
|
else if (c->from_idx <= c->to_idx)
|
|
|
|
mod->csumfunc.crc8 = cgw_csum_crc8_pos;
|
|
|
|
else
|
|
|
|
mod->csumfunc.crc8 = cgw_csum_crc8_neg;
|
|
|
|
}
|
|
|
|
|
2012-07-05 16:19:56 +04:00
|
|
|
if (tb[CGW_CS_XOR]) {
|
2012-07-05 16:19:58 +04:00
|
|
|
struct cgw_csum_xor *c = nla_data(tb[CGW_CS_XOR]);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
err = cgw_chk_csum_parms(c->from_idx, c->to_idx,
|
2019-08-10 22:18:10 +03:00
|
|
|
c->result_idx, r);
|
2011-09-01 08:23:23 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
nla_memcpy(&mod->csum.xor, tb[CGW_CS_XOR],
|
|
|
|
CGW_CS_XOR_LEN);
|
|
|
|
|
2019-07-24 15:16:29 +03:00
|
|
|
/* select dedicated processing function to reduce
|
2011-09-01 08:23:23 +04:00
|
|
|
* runtime operations in receive hot path.
|
|
|
|
*/
|
|
|
|
if (c->from_idx < 0 || c->to_idx < 0 ||
|
|
|
|
c->result_idx < 0)
|
|
|
|
mod->csumfunc.xor = cgw_csum_xor_rel;
|
|
|
|
else if (c->from_idx <= c->to_idx)
|
|
|
|
mod->csumfunc.xor = cgw_csum_xor_pos;
|
|
|
|
else
|
|
|
|
mod->csumfunc.xor = cgw_csum_xor_neg;
|
|
|
|
}
|
2015-06-09 09:05:10 +03:00
|
|
|
|
2019-07-24 15:48:14 +03:00
|
|
|
if (tb[CGW_MOD_UID])
|
2015-06-09 09:05:10 +03:00
|
|
|
nla_memcpy(&mod->uid, tb[CGW_MOD_UID], sizeof(u32));
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gwtype == CGW_TYPE_CAN_CAN) {
|
|
|
|
/* check CGW_TYPE_CAN_CAN specific attributes */
|
|
|
|
struct can_can_gw *ccgw = (struct can_can_gw *)gwtypeattr;
|
2019-07-24 15:28:21 +03:00
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
memset(ccgw, 0, sizeof(*ccgw));
|
|
|
|
|
|
|
|
/* check for can_filter in attributes */
|
2012-07-05 16:19:56 +04:00
|
|
|
if (tb[CGW_FILTER])
|
2011-09-01 08:23:23 +04:00
|
|
|
nla_memcpy(&ccgw->filter, tb[CGW_FILTER],
|
|
|
|
sizeof(struct can_filter));
|
|
|
|
|
|
|
|
err = -ENODEV;
|
|
|
|
|
|
|
|
/* specifying two interfaces is mandatory */
|
|
|
|
if (!tb[CGW_SRC_IF] || !tb[CGW_DST_IF])
|
|
|
|
return err;
|
|
|
|
|
2012-07-05 16:19:56 +04:00
|
|
|
ccgw->src_idx = nla_get_u32(tb[CGW_SRC_IF]);
|
|
|
|
ccgw->dst_idx = nla_get_u32(tb[CGW_DST_IF]);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
/* both indices set to 0 for flushing all routing entries */
|
|
|
|
if (!ccgw->src_idx && !ccgw->dst_idx)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* only one index set to 0 is an error */
|
|
|
|
if (!ccgw->src_idx || !ccgw->dst_idx)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the checks for other gwtypes here */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-16 19:48:24 +03:00
|
|
|
static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|
|
|
struct netlink_ext_ack *extack)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2017-04-25 09:19:43 +03:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2011-09-01 08:23:23 +04:00
|
|
|
struct rtcanmsg *r;
|
|
|
|
struct cgw_job *gwj;
|
2015-06-09 09:05:10 +03:00
|
|
|
struct cf_mod mod;
|
|
|
|
struct can_can_gw ccgw;
|
2013-08-26 17:05:36 +04:00
|
|
|
u8 limhops = 0;
|
2011-09-01 08:23:23 +04:00
|
|
|
int err = 0;
|
|
|
|
|
2014-04-24 01:29:27 +04:00
|
|
|
if (!netlink_capable(skb, CAP_NET_ADMIN))
|
2012-11-16 07:03:00 +04:00
|
|
|
return -EPERM;
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
if (nlmsg_len(nlh) < sizeof(*r))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
r = nlmsg_data(nlh);
|
|
|
|
if (r->can_family != AF_CAN)
|
|
|
|
return -EPFNOSUPPORT;
|
|
|
|
|
|
|
|
/* so far we only support CAN -> CAN routings */
|
|
|
|
if (r->gwtype != CGW_TYPE_CAN_CAN)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-06-09 09:05:10 +03:00
|
|
|
err = cgw_parse_attr(nlh, &mod, CGW_TYPE_CAN_CAN, &ccgw, &limhops);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (mod.uid) {
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
|
|
/* check for updating an existing job with identical uid */
|
2017-04-25 09:19:43 +03:00
|
|
|
hlist_for_each_entry(gwj, &net->can.cgw_list, list) {
|
2015-06-09 09:05:10 +03:00
|
|
|
if (gwj->mod.uid != mod.uid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* interfaces & filters must be identical */
|
|
|
|
if (memcmp(&gwj->ccgw, &ccgw, sizeof(ccgw)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* update modifications with disabled softirq & quit */
|
|
|
|
local_bh_disable();
|
|
|
|
memcpy(&gwj->mod, &mod, sizeof(mod));
|
|
|
|
local_bh_enable();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ifindex == 0 is not allowed for job creation */
|
|
|
|
if (!ccgw.src_idx || !ccgw.dst_idx)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
gwj = kmem_cache_alloc(cgw_cache, GFP_KERNEL);
|
|
|
|
if (!gwj)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
gwj->handled_frames = 0;
|
|
|
|
gwj->dropped_frames = 0;
|
2013-01-17 21:43:46 +04:00
|
|
|
gwj->deleted_frames = 0;
|
2011-09-01 08:23:23 +04:00
|
|
|
gwj->flags = r->flags;
|
|
|
|
gwj->gwtype = r->gwtype;
|
2015-06-09 09:05:10 +03:00
|
|
|
gwj->limit_hops = limhops;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2015-06-09 09:05:10 +03:00
|
|
|
/* insert already parsed information */
|
|
|
|
memcpy(&gwj->mod, &mod, sizeof(mod));
|
|
|
|
memcpy(&gwj->ccgw, &ccgw, sizeof(ccgw));
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
err = -ENODEV;
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
gwj->src.dev = __dev_get_by_index(net, gwj->ccgw.src_idx);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
if (!gwj->src.dev)
|
|
|
|
goto out;
|
|
|
|
|
2013-12-04 22:52:36 +04:00
|
|
|
if (gwj->src.dev->type != ARPHRD_CAN)
|
2014-01-15 06:23:44 +04:00
|
|
|
goto out;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
gwj->dst.dev = __dev_get_by_index(net, gwj->ccgw.dst_idx);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
if (!gwj->dst.dev)
|
2014-01-15 06:23:44 +04:00
|
|
|
goto out;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2013-12-04 22:52:36 +04:00
|
|
|
if (gwj->dst.dev->type != ARPHRD_CAN)
|
2014-01-15 06:23:44 +04:00
|
|
|
goto out;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
err = cgw_register_filter(net, gwj);
|
2011-09-01 08:23:23 +04:00
|
|
|
if (!err)
|
2017-04-25 09:19:43 +03:00
|
|
|
hlist_add_head_rcu(&gwj->list, &net->can.cgw_list);
|
2011-09-01 08:23:23 +04:00
|
|
|
out:
|
|
|
|
if (err)
|
|
|
|
kmem_cache_free(cgw_cache, gwj);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
static void cgw_remove_all_jobs(struct net *net)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
|
|
|
struct cgw_job *gwj = NULL;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
struct hlist_node *nx;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
hlist_for_each_entry_safe(gwj, nx, &net->can.cgw_list, list) {
|
2011-09-01 08:23:23 +04:00
|
|
|
hlist_del(&gwj->list);
|
2017-04-25 09:19:43 +03:00
|
|
|
cgw_unregister_filter(net, gwj);
|
2013-04-09 10:16:04 +04:00
|
|
|
kmem_cache_free(cgw_cache, gwj);
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-16 19:48:24 +03:00
|
|
|
static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|
|
|
struct netlink_ext_ack *extack)
|
2011-09-01 08:23:23 +04:00
|
|
|
{
|
2017-04-25 09:19:43 +03:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2011-09-01 08:23:23 +04:00
|
|
|
struct cgw_job *gwj = NULL;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
struct hlist_node *nx;
|
2011-09-01 08:23:23 +04:00
|
|
|
struct rtcanmsg *r;
|
|
|
|
struct cf_mod mod;
|
|
|
|
struct can_can_gw ccgw;
|
2013-08-26 17:05:36 +04:00
|
|
|
u8 limhops = 0;
|
2011-09-01 08:23:23 +04:00
|
|
|
int err = 0;
|
|
|
|
|
2014-04-24 01:29:27 +04:00
|
|
|
if (!netlink_capable(skb, CAP_NET_ADMIN))
|
2012-11-16 07:03:00 +04:00
|
|
|
return -EPERM;
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
if (nlmsg_len(nlh) < sizeof(*r))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
r = nlmsg_data(nlh);
|
|
|
|
if (r->can_family != AF_CAN)
|
|
|
|
return -EPFNOSUPPORT;
|
|
|
|
|
|
|
|
/* so far we only support CAN -> CAN routings */
|
|
|
|
if (r->gwtype != CGW_TYPE_CAN_CAN)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-08-26 17:05:36 +04:00
|
|
|
err = cgw_parse_attr(nlh, &mod, CGW_TYPE_CAN_CAN, &ccgw, &limhops);
|
2011-09-01 08:23:23 +04:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* two interface indices both set to 0 => remove all entries */
|
|
|
|
if (!ccgw.src_idx && !ccgw.dst_idx) {
|
2017-04-25 09:19:43 +03:00
|
|
|
cgw_remove_all_jobs(net);
|
2011-09-01 08:23:23 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = -EINVAL;
|
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
|
|
/* remove only the first matching entry */
|
2017-04-25 09:19:43 +03:00
|
|
|
hlist_for_each_entry_safe(gwj, nx, &net->can.cgw_list, list) {
|
2011-09-01 08:23:23 +04:00
|
|
|
if (gwj->flags != r->flags)
|
|
|
|
continue;
|
|
|
|
|
2013-08-26 17:05:36 +04:00
|
|
|
if (gwj->limit_hops != limhops)
|
|
|
|
continue;
|
|
|
|
|
2015-06-09 09:05:10 +03:00
|
|
|
/* we have a match when uid is enabled and identical */
|
|
|
|
if (gwj->mod.uid || mod.uid) {
|
|
|
|
if (gwj->mod.uid != mod.uid)
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* no uid => check for identical modifications */
|
|
|
|
if (memcmp(&gwj->mod, &mod, sizeof(mod)))
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
/* if (r->gwtype == CGW_TYPE_CAN_CAN) - is made sure here */
|
|
|
|
if (memcmp(&gwj->ccgw, &ccgw, sizeof(ccgw)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hlist_del(&gwj->list);
|
2017-04-25 09:19:43 +03:00
|
|
|
cgw_unregister_filter(net, gwj);
|
2013-04-09 10:16:04 +04:00
|
|
|
kmem_cache_free(cgw_cache, gwj);
|
2011-09-01 08:23:23 +04:00
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
static int __net_init cangw_pernet_init(struct net *net)
|
|
|
|
{
|
|
|
|
INIT_HLIST_HEAD(&net->can.cgw_list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit cangw_pernet_exit(struct net *net)
|
|
|
|
{
|
|
|
|
rtnl_lock();
|
|
|
|
cgw_remove_all_jobs(net);
|
|
|
|
rtnl_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations cangw_pernet_ops = {
|
|
|
|
.init = cangw_pernet_init,
|
|
|
|
.exit = cangw_pernet_exit,
|
|
|
|
};
|
|
|
|
|
2011-09-01 08:23:23 +04:00
|
|
|
static __init int cgw_module_init(void)
|
|
|
|
{
|
2017-12-02 23:44:07 +03:00
|
|
|
int ret;
|
|
|
|
|
2013-01-17 21:43:44 +04:00
|
|
|
/* sanitize given module parameter */
|
|
|
|
max_hops = clamp_t(unsigned int, max_hops, CGW_MIN_HOPS, CGW_MAX_HOPS);
|
|
|
|
|
|
|
|
pr_info("can: netlink gateway (rev " CAN_GW_VERSION ") max_hops=%d\n",
|
|
|
|
max_hops);
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2019-05-18 12:35:43 +03:00
|
|
|
ret = register_pernet_subsys(&cangw_pernet_ops);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = -ENOMEM;
|
2011-09-01 08:23:23 +04:00
|
|
|
cgw_cache = kmem_cache_create("can_gw", sizeof(struct cgw_job),
|
|
|
|
0, 0, NULL);
|
|
|
|
if (!cgw_cache)
|
2019-05-18 12:35:43 +03:00
|
|
|
goto out_cache_create;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
/* set notifier */
|
|
|
|
notifier.notifier_call = cgw_notifier;
|
2019-05-18 12:35:43 +03:00
|
|
|
ret = register_netdevice_notifier(¬ifier);
|
|
|
|
if (ret)
|
|
|
|
goto out_register_notifier;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
2017-12-02 23:44:07 +03:00
|
|
|
ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_GETROUTE,
|
|
|
|
NULL, cgw_dump_jobs, 0);
|
2019-05-18 12:35:43 +03:00
|
|
|
if (ret)
|
|
|
|
goto out_rtnl_register1;
|
|
|
|
|
|
|
|
ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_NEWROUTE,
|
|
|
|
cgw_create_job, NULL, 0);
|
|
|
|
if (ret)
|
|
|
|
goto out_rtnl_register2;
|
|
|
|
ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_DELROUTE,
|
|
|
|
cgw_remove_job, NULL, 0);
|
|
|
|
if (ret)
|
|
|
|
goto out_rtnl_register3;
|
2011-09-01 08:23:23 +04:00
|
|
|
|
|
|
|
return 0;
|
2019-05-18 12:35:43 +03:00
|
|
|
|
|
|
|
out_rtnl_register3:
|
|
|
|
rtnl_unregister(PF_CAN, RTM_NEWROUTE);
|
|
|
|
out_rtnl_register2:
|
|
|
|
rtnl_unregister(PF_CAN, RTM_GETROUTE);
|
|
|
|
out_rtnl_register1:
|
|
|
|
unregister_netdevice_notifier(¬ifier);
|
|
|
|
out_register_notifier:
|
|
|
|
kmem_cache_destroy(cgw_cache);
|
|
|
|
out_cache_create:
|
|
|
|
unregister_pernet_subsys(&cangw_pernet_ops);
|
|
|
|
|
|
|
|
return ret;
|
2011-09-01 08:23:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static __exit void cgw_module_exit(void)
|
|
|
|
{
|
|
|
|
rtnl_unregister_all(PF_CAN);
|
|
|
|
|
|
|
|
unregister_netdevice_notifier(¬ifier);
|
|
|
|
|
2017-04-25 09:19:43 +03:00
|
|
|
unregister_pernet_subsys(&cangw_pernet_ops);
|
2011-09-01 08:23:23 +04:00
|
|
|
rcu_barrier(); /* Wait for completion of call_rcu()'s */
|
|
|
|
|
|
|
|
kmem_cache_destroy(cgw_cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(cgw_module_init);
|
|
|
|
module_exit(cgw_module_exit);
|