2008-07-06 04:26:13 +00:00
|
|
|
/*
|
|
|
|
* IEEE 802.1D Generic Attribute Registration Protocol (GARP)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/llc.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2011-05-27 13:12:25 +00:00
|
|
|
#include <linux/module.h>
|
2008-07-06 04:26:13 +00:00
|
|
|
#include <net/llc.h>
|
|
|
|
#include <net/llc_pdu.h>
|
|
|
|
#include <net/garp.h>
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
|
|
|
static unsigned int garp_join_time __read_mostly = 200;
|
|
|
|
module_param(garp_join_time, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(garp_join_time, "Join time in ms (default 200ms)");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static const struct garp_state_trans {
|
|
|
|
u8 state;
|
|
|
|
u8 action;
|
|
|
|
} garp_applicant_state_table[GARP_APPLICANT_MAX + 1][GARP_EVENT_MAX + 1] = {
|
|
|
|
[GARP_APPLICANT_VA] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_AA,
|
|
|
|
.action = GARP_ACTION_S_JOIN_IN },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_AA },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_LA },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_AA] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_QA,
|
|
|
|
.action = GARP_ACTION_S_JOIN_IN },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_QA },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_LA },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_QA] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_QA },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_LA },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_LA] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_VO,
|
|
|
|
.action = GARP_ACTION_S_LEAVE_EMPTY },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_LA },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_LA },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_LA },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_VA },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_VP] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_AA,
|
|
|
|
.action = GARP_ACTION_S_JOIN_IN },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_AP },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_VO },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_AP] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_QA,
|
|
|
|
.action = GARP_ACTION_S_JOIN_IN },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_QP },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_AO },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_QP] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_QP },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_QO },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_VO] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_AO },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_VP },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_AO] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_QO },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_AP },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
},
|
|
|
|
[GARP_APPLICANT_QO] = {
|
|
|
|
[GARP_EVENT_TRANSMIT_PDU] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
[GARP_EVENT_R_JOIN_IN] = { .state = GARP_APPLICANT_QO },
|
|
|
|
[GARP_EVENT_R_JOIN_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_LEAVE_IN] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_R_LEAVE_EMPTY] = { .state = GARP_APPLICANT_VO },
|
|
|
|
[GARP_EVENT_REQ_JOIN] = { .state = GARP_APPLICANT_QP },
|
|
|
|
[GARP_EVENT_REQ_LEAVE] = { .state = GARP_APPLICANT_INVALID },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int garp_attr_cmp(const struct garp_attr *attr,
|
|
|
|
const void *data, u8 len, u8 type)
|
|
|
|
{
|
|
|
|
if (attr->type != type)
|
|
|
|
return attr->type - type;
|
|
|
|
if (attr->dlen != len)
|
|
|
|
return attr->dlen - len;
|
|
|
|
return memcmp(attr->data, data, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct garp_attr *garp_attr_lookup(const struct garp_applicant *app,
|
|
|
|
const void *data, u8 len, u8 type)
|
|
|
|
{
|
|
|
|
struct rb_node *parent = app->gid.rb_node;
|
|
|
|
struct garp_attr *attr;
|
|
|
|
int d;
|
|
|
|
|
|
|
|
while (parent) {
|
|
|
|
attr = rb_entry(parent, struct garp_attr, node);
|
|
|
|
d = garp_attr_cmp(attr, data, len, type);
|
2012-04-09 04:13:53 +00:00
|
|
|
if (d > 0)
|
2008-07-06 04:26:13 +00:00
|
|
|
parent = parent->rb_left;
|
2012-04-09 04:13:53 +00:00
|
|
|
else if (d < 0)
|
2008-07-06 04:26:13 +00:00
|
|
|
parent = parent->rb_right;
|
|
|
|
else
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 09:01:52 +00:00
|
|
|
static struct garp_attr *garp_attr_create(struct garp_applicant *app,
|
|
|
|
const void *data, u8 len, u8 type)
|
2008-07-06 04:26:13 +00:00
|
|
|
{
|
|
|
|
struct rb_node *parent = NULL, **p = &app->gid.rb_node;
|
|
|
|
struct garp_attr *attr;
|
|
|
|
int d;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
attr = rb_entry(parent, struct garp_attr, node);
|
2012-03-27 09:01:52 +00:00
|
|
|
d = garp_attr_cmp(attr, data, len, type);
|
2012-04-09 04:13:53 +00:00
|
|
|
if (d > 0)
|
2008-07-06 04:26:13 +00:00
|
|
|
p = &parent->rb_left;
|
2012-04-09 04:13:53 +00:00
|
|
|
else if (d < 0)
|
2008-07-06 04:26:13 +00:00
|
|
|
p = &parent->rb_right;
|
2012-03-27 09:01:52 +00:00
|
|
|
else {
|
|
|
|
/* The attribute already exists; re-use it. */
|
|
|
|
return attr;
|
|
|
|
}
|
2008-07-06 04:26:13 +00:00
|
|
|
}
|
|
|
|
attr = kmalloc(sizeof(*attr) + len, GFP_ATOMIC);
|
|
|
|
if (!attr)
|
|
|
|
return attr;
|
|
|
|
attr->state = GARP_APPLICANT_VO;
|
|
|
|
attr->type = type;
|
|
|
|
attr->dlen = len;
|
|
|
|
memcpy(attr->data, data, len);
|
2012-03-27 09:01:52 +00:00
|
|
|
|
|
|
|
rb_link_node(&attr->node, parent, p);
|
|
|
|
rb_insert_color(&attr->node, &app->gid);
|
2008-07-06 04:26:13 +00:00
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void garp_attr_destroy(struct garp_applicant *app, struct garp_attr *attr)
|
|
|
|
{
|
|
|
|
rb_erase(&attr->node, &app->gid);
|
|
|
|
kfree(attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int garp_pdu_init(struct garp_applicant *app)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct garp_pdu_hdr *gp;
|
|
|
|
|
|
|
|
#define LLC_RESERVE sizeof(struct llc_pdu_un)
|
|
|
|
skb = alloc_skb(app->dev->mtu + LL_RESERVED_SPACE(app->dev),
|
|
|
|
GFP_ATOMIC);
|
|
|
|
if (!skb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
skb->dev = app->dev;
|
|
|
|
skb->protocol = htons(ETH_P_802_2);
|
|
|
|
skb_reserve(skb, LL_RESERVED_SPACE(app->dev) + LLC_RESERVE);
|
|
|
|
|
networking: make skb_put & friends return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions (skb_put, __skb_put and pskb_put) return void *
and remove all the casts across the tree, adding a (u8 *) cast only
where the unsigned char pointer was used directly, all done with the
following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_put, __skb_put };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_put, __skb_put };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
which actually doesn't cover pskb_put since there are only three
users overall.
A handful of stragglers were converted manually, notably a macro in
drivers/isdn/i4l/isdn_bsdcomp.c and, oddly enough, one of the many
instances in net/bluetooth/hci_sock.c. In the former file, I also
had to fix one whitespace problem spatch introduced.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 12:29:21 +00:00
|
|
|
gp = __skb_put(skb, sizeof(*gp));
|
2008-07-06 04:26:13 +00:00
|
|
|
put_unaligned(htons(GARP_PROTOCOL_ID), &gp->protocol);
|
|
|
|
|
|
|
|
app->pdu = skb;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int garp_pdu_append_end_mark(struct garp_applicant *app)
|
|
|
|
{
|
|
|
|
if (skb_tailroom(app->pdu) < sizeof(u8))
|
|
|
|
return -1;
|
net: introduce __skb_put_[zero, data, u8]
follow Johannes Berg, semantic patch file as below,
@@
identifier p, p2;
expression len;
expression skb;
type t, t2;
@@
(
-p = __skb_put(skb, len);
+p = __skb_put_zero(skb, len);
|
-p = (t)__skb_put(skb, len);
+p = __skb_put_zero(skb, len);
)
... when != p
(
p2 = (t2)p;
-memset(p2, 0, len);
|
-memset(p, 0, len);
)
@@
identifier p;
expression len;
expression skb;
type t;
@@
(
-t p = __skb_put(skb, len);
+t p = __skb_put_zero(skb, len);
)
... when != p
(
-memset(p, 0, len);
)
@@
type t, t2;
identifier p, p2;
expression skb;
@@
t *p;
...
(
-p = __skb_put(skb, sizeof(t));
+p = __skb_put_zero(skb, sizeof(t));
|
-p = (t *)__skb_put(skb, sizeof(t));
+p = __skb_put_zero(skb, sizeof(t));
)
... when != p
(
p2 = (t2)p;
-memset(p2, 0, sizeof(*p));
|
-memset(p, 0, sizeof(*p));
)
@@
expression skb, len;
@@
-memset(__skb_put(skb, len), 0, len);
+__skb_put_zero(skb, len);
@@
expression skb, len, data;
@@
-memcpy(__skb_put(skb, len), data, len);
+__skb_put_data(skb, data, len);
@@
expression SKB, C, S;
typedef u8;
identifier fn = {__skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-18 14:48:17 +00:00
|
|
|
__skb_put_u8(app->pdu, GARP_END_MARK);
|
2008-07-06 04:26:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void garp_pdu_queue(struct garp_applicant *app)
|
|
|
|
{
|
|
|
|
if (!app->pdu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
garp_pdu_append_end_mark(app);
|
|
|
|
garp_pdu_append_end_mark(app);
|
|
|
|
|
|
|
|
llc_pdu_header_init(app->pdu, LLC_PDU_TYPE_U, LLC_SAP_BSPAN,
|
|
|
|
LLC_SAP_BSPAN, LLC_PDU_CMD);
|
|
|
|
llc_pdu_init_as_ui_cmd(app->pdu);
|
|
|
|
llc_mac_hdr_init(app->pdu, app->dev->dev_addr,
|
|
|
|
app->app->proto.group_address);
|
|
|
|
|
|
|
|
skb_queue_tail(&app->queue, app->pdu);
|
|
|
|
app->pdu = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void garp_queue_xmit(struct garp_applicant *app)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
while ((skb = skb_dequeue(&app->queue)))
|
|
|
|
dev_queue_xmit(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int garp_pdu_append_msg(struct garp_applicant *app, u8 attrtype)
|
|
|
|
{
|
|
|
|
struct garp_msg_hdr *gm;
|
|
|
|
|
|
|
|
if (skb_tailroom(app->pdu) < sizeof(*gm))
|
|
|
|
return -1;
|
networking: make skb_put & friends return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions (skb_put, __skb_put and pskb_put) return void *
and remove all the casts across the tree, adding a (u8 *) cast only
where the unsigned char pointer was used directly, all done with the
following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_put, __skb_put };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_put, __skb_put };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
which actually doesn't cover pskb_put since there are only three
users overall.
A handful of stragglers were converted manually, notably a macro in
drivers/isdn/i4l/isdn_bsdcomp.c and, oddly enough, one of the many
instances in net/bluetooth/hci_sock.c. In the former file, I also
had to fix one whitespace problem spatch introduced.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 12:29:21 +00:00
|
|
|
gm = __skb_put(app->pdu, sizeof(*gm));
|
2008-07-06 04:26:13 +00:00
|
|
|
gm->attrtype = attrtype;
|
|
|
|
garp_cb(app->pdu)->cur_type = attrtype;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int garp_pdu_append_attr(struct garp_applicant *app,
|
|
|
|
const struct garp_attr *attr,
|
|
|
|
enum garp_attr_event event)
|
|
|
|
{
|
|
|
|
struct garp_attr_hdr *ga;
|
|
|
|
unsigned int len;
|
|
|
|
int err;
|
|
|
|
again:
|
|
|
|
if (!app->pdu) {
|
|
|
|
err = garp_pdu_init(app);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (garp_cb(app->pdu)->cur_type != attr->type) {
|
|
|
|
if (garp_cb(app->pdu)->cur_type &&
|
|
|
|
garp_pdu_append_end_mark(app) < 0)
|
|
|
|
goto queue;
|
|
|
|
if (garp_pdu_append_msg(app, attr->type) < 0)
|
|
|
|
goto queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = sizeof(*ga) + attr->dlen;
|
|
|
|
if (skb_tailroom(app->pdu) < len)
|
|
|
|
goto queue;
|
networking: make skb_put & friends return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions (skb_put, __skb_put and pskb_put) return void *
and remove all the casts across the tree, adding a (u8 *) cast only
where the unsigned char pointer was used directly, all done with the
following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_put, __skb_put };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_put, __skb_put };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
which actually doesn't cover pskb_put since there are only three
users overall.
A handful of stragglers were converted manually, notably a macro in
drivers/isdn/i4l/isdn_bsdcomp.c and, oddly enough, one of the many
instances in net/bluetooth/hci_sock.c. In the former file, I also
had to fix one whitespace problem spatch introduced.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 12:29:21 +00:00
|
|
|
ga = __skb_put(app->pdu, len);
|
2008-07-06 04:26:13 +00:00
|
|
|
ga->len = len;
|
|
|
|
ga->event = event;
|
|
|
|
memcpy(ga->data, attr->data, attr->dlen);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
queue:
|
|
|
|
garp_pdu_queue(app);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void garp_attr_event(struct garp_applicant *app,
|
|
|
|
struct garp_attr *attr, enum garp_event event)
|
|
|
|
{
|
|
|
|
enum garp_applicant_state state;
|
|
|
|
|
|
|
|
state = garp_applicant_state_table[attr->state][event].state;
|
|
|
|
if (state == GARP_APPLICANT_INVALID)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (garp_applicant_state_table[attr->state][event].action) {
|
|
|
|
case GARP_ACTION_NONE:
|
|
|
|
break;
|
|
|
|
case GARP_ACTION_S_JOIN_IN:
|
2008-07-17 03:51:47 +00:00
|
|
|
/* When appending the attribute fails, don't update state in
|
|
|
|
* order to retry on next TRANSMIT_PDU event. */
|
|
|
|
if (garp_pdu_append_attr(app, attr, GARP_JOIN_IN) < 0)
|
|
|
|
return;
|
2008-07-06 04:26:13 +00:00
|
|
|
break;
|
|
|
|
case GARP_ACTION_S_LEAVE_EMPTY:
|
|
|
|
garp_pdu_append_attr(app, attr, GARP_LEAVE_EMPTY);
|
|
|
|
/* As a pure applicant, sending a leave message implies that
|
|
|
|
* the attribute was unregistered and can be destroyed. */
|
|
|
|
garp_attr_destroy(app, attr);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
int garp_request_join(const struct net_device *dev,
|
|
|
|
const struct garp_application *appl,
|
|
|
|
const void *data, u8 len, u8 type)
|
|
|
|
{
|
2010-10-24 21:32:36 +00:00
|
|
|
struct garp_port *port = rtnl_dereference(dev->garp_port);
|
|
|
|
struct garp_applicant *app = rtnl_dereference(port->applicants[appl->type]);
|
2008-07-06 04:26:13 +00:00
|
|
|
struct garp_attr *attr;
|
|
|
|
|
|
|
|
spin_lock_bh(&app->lock);
|
|
|
|
attr = garp_attr_create(app, data, len, type);
|
|
|
|
if (!attr) {
|
|
|
|
spin_unlock_bh(&app->lock);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
garp_attr_event(app, attr, GARP_EVENT_REQ_JOIN);
|
|
|
|
spin_unlock_bh(&app->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(garp_request_join);
|
|
|
|
|
|
|
|
void garp_request_leave(const struct net_device *dev,
|
|
|
|
const struct garp_application *appl,
|
|
|
|
const void *data, u8 len, u8 type)
|
|
|
|
{
|
2010-10-24 21:32:36 +00:00
|
|
|
struct garp_port *port = rtnl_dereference(dev->garp_port);
|
|
|
|
struct garp_applicant *app = rtnl_dereference(port->applicants[appl->type]);
|
2008-07-06 04:26:13 +00:00
|
|
|
struct garp_attr *attr;
|
|
|
|
|
|
|
|
spin_lock_bh(&app->lock);
|
|
|
|
attr = garp_attr_lookup(app, data, len, type);
|
|
|
|
if (!attr) {
|
|
|
|
spin_unlock_bh(&app->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
garp_attr_event(app, attr, GARP_EVENT_REQ_LEAVE);
|
|
|
|
spin_unlock_bh(&app->lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(garp_request_leave);
|
|
|
|
|
|
|
|
static void garp_gid_event(struct garp_applicant *app, enum garp_event event)
|
|
|
|
{
|
|
|
|
struct rb_node *node, *next;
|
|
|
|
struct garp_attr *attr;
|
|
|
|
|
|
|
|
for (node = rb_first(&app->gid);
|
|
|
|
next = node ? rb_next(node) : NULL, node != NULL;
|
|
|
|
node = next) {
|
|
|
|
attr = rb_entry(node, struct garp_attr, node);
|
|
|
|
garp_attr_event(app, attr, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void garp_join_timer_arm(struct garp_applicant *app)
|
|
|
|
{
|
|
|
|
unsigned long delay;
|
|
|
|
|
2014-01-11 12:15:59 +00:00
|
|
|
delay = (u64)msecs_to_jiffies(garp_join_time) * prandom_u32() >> 32;
|
2008-07-06 04:26:13 +00:00
|
|
|
mod_timer(&app->join_timer, jiffies + delay);
|
|
|
|
}
|
|
|
|
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
static void garp_join_timer(struct timer_list *t)
|
2008-07-06 04:26:13 +00:00
|
|
|
{
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
struct garp_applicant *app = from_timer(app, t, join_timer);
|
2008-07-06 04:26:13 +00:00
|
|
|
|
|
|
|
spin_lock(&app->lock);
|
|
|
|
garp_gid_event(app, GARP_EVENT_TRANSMIT_PDU);
|
|
|
|
garp_pdu_queue(app);
|
|
|
|
spin_unlock(&app->lock);
|
|
|
|
|
|
|
|
garp_queue_xmit(app);
|
|
|
|
garp_join_timer_arm(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int garp_pdu_parse_end_mark(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
if (!pskb_may_pull(skb, sizeof(u8)))
|
|
|
|
return -1;
|
|
|
|
if (*skb->data == GARP_END_MARK) {
|
|
|
|
skb_pull(skb, sizeof(u8));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int garp_pdu_parse_attr(struct garp_applicant *app, struct sk_buff *skb,
|
|
|
|
u8 attrtype)
|
|
|
|
{
|
|
|
|
const struct garp_attr_hdr *ga;
|
|
|
|
struct garp_attr *attr;
|
|
|
|
enum garp_event event;
|
|
|
|
unsigned int dlen;
|
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(*ga)))
|
|
|
|
return -1;
|
|
|
|
ga = (struct garp_attr_hdr *)skb->data;
|
|
|
|
if (ga->len < sizeof(*ga))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, ga->len))
|
|
|
|
return -1;
|
|
|
|
skb_pull(skb, ga->len);
|
|
|
|
dlen = sizeof(*ga) - ga->len;
|
|
|
|
|
|
|
|
if (attrtype > app->app->maxattr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (ga->event) {
|
|
|
|
case GARP_LEAVE_ALL:
|
|
|
|
if (dlen != 0)
|
|
|
|
return -1;
|
|
|
|
garp_gid_event(app, GARP_EVENT_R_LEAVE_EMPTY);
|
|
|
|
return 0;
|
|
|
|
case GARP_JOIN_EMPTY:
|
|
|
|
event = GARP_EVENT_R_JOIN_EMPTY;
|
|
|
|
break;
|
|
|
|
case GARP_JOIN_IN:
|
|
|
|
event = GARP_EVENT_R_JOIN_IN;
|
|
|
|
break;
|
|
|
|
case GARP_LEAVE_EMPTY:
|
|
|
|
event = GARP_EVENT_R_LEAVE_EMPTY;
|
|
|
|
break;
|
|
|
|
case GARP_EMPTY:
|
|
|
|
event = GARP_EVENT_R_EMPTY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dlen == 0)
|
|
|
|
return -1;
|
|
|
|
attr = garp_attr_lookup(app, ga->data, dlen, attrtype);
|
|
|
|
if (attr == NULL)
|
|
|
|
return 0;
|
|
|
|
garp_attr_event(app, attr, event);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int garp_pdu_parse_msg(struct garp_applicant *app, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
const struct garp_msg_hdr *gm;
|
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(*gm)))
|
|
|
|
return -1;
|
|
|
|
gm = (struct garp_msg_hdr *)skb->data;
|
|
|
|
if (gm->attrtype == 0)
|
|
|
|
return -1;
|
|
|
|
skb_pull(skb, sizeof(*gm));
|
|
|
|
|
|
|
|
while (skb->len > 0) {
|
|
|
|
if (garp_pdu_parse_attr(app, skb, gm->attrtype) < 0)
|
|
|
|
return -1;
|
|
|
|
if (garp_pdu_parse_end_mark(skb) < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void garp_pdu_rcv(const struct stp_proto *proto, struct sk_buff *skb,
|
|
|
|
struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct garp_application *appl = proto->data;
|
|
|
|
struct garp_port *port;
|
|
|
|
struct garp_applicant *app;
|
|
|
|
const struct garp_pdu_hdr *gp;
|
|
|
|
|
|
|
|
port = rcu_dereference(dev->garp_port);
|
|
|
|
if (!port)
|
|
|
|
goto err;
|
|
|
|
app = rcu_dereference(port->applicants[appl->type]);
|
|
|
|
if (!app)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(*gp)))
|
|
|
|
goto err;
|
|
|
|
gp = (struct garp_pdu_hdr *)skb->data;
|
|
|
|
if (get_unaligned(&gp->protocol) != htons(GARP_PROTOCOL_ID))
|
|
|
|
goto err;
|
|
|
|
skb_pull(skb, sizeof(*gp));
|
|
|
|
|
|
|
|
spin_lock(&app->lock);
|
|
|
|
while (skb->len > 0) {
|
|
|
|
if (garp_pdu_parse_msg(app, skb) < 0)
|
|
|
|
break;
|
|
|
|
if (garp_pdu_parse_end_mark(skb) < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock(&app->lock);
|
|
|
|
err:
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int garp_init_port(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct garp_port *port;
|
|
|
|
|
|
|
|
port = kzalloc(sizeof(*port), GFP_KERNEL);
|
|
|
|
if (!port)
|
|
|
|
return -ENOMEM;
|
|
|
|
rcu_assign_pointer(dev->garp_port, port);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void garp_release_port(struct net_device *dev)
|
|
|
|
{
|
2010-10-24 21:32:36 +00:00
|
|
|
struct garp_port *port = rtnl_dereference(dev->garp_port);
|
2008-07-06 04:26:13 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i <= GARP_APPLICATION_MAX; i++) {
|
2010-10-24 21:32:36 +00:00
|
|
|
if (rtnl_dereference(port->applicants[i]))
|
2008-07-06 04:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-08-01 16:19:00 +00:00
|
|
|
RCU_INIT_POINTER(dev->garp_port, NULL);
|
2011-05-20 18:31:30 +00:00
|
|
|
kfree_rcu(port, rcu);
|
2008-07-06 04:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int garp_init_applicant(struct net_device *dev, struct garp_application *appl)
|
|
|
|
{
|
|
|
|
struct garp_applicant *app;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
2010-10-24 21:32:36 +00:00
|
|
|
if (!rtnl_dereference(dev->garp_port)) {
|
2008-07-06 04:26:13 +00:00
|
|
|
err = garp_init_port(dev);
|
|
|
|
if (err < 0)
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
app = kzalloc(sizeof(*app), GFP_KERNEL);
|
|
|
|
if (!app)
|
|
|
|
goto err2;
|
|
|
|
|
2010-04-01 21:22:57 +00:00
|
|
|
err = dev_mc_add(dev, appl->proto.group_address);
|
2008-07-06 04:26:13 +00:00
|
|
|
if (err < 0)
|
|
|
|
goto err3;
|
|
|
|
|
|
|
|
app->dev = dev;
|
|
|
|
app->app = appl;
|
|
|
|
app->gid = RB_ROOT;
|
|
|
|
spin_lock_init(&app->lock);
|
|
|
|
skb_queue_head_init(&app->queue);
|
|
|
|
rcu_assign_pointer(dev->garp_port->applicants[appl->type], app);
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
timer_setup(&app->join_timer, garp_join_timer, 0);
|
2008-07-06 04:26:13 +00:00
|
|
|
garp_join_timer_arm(app);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err3:
|
|
|
|
kfree(app);
|
|
|
|
err2:
|
|
|
|
garp_release_port(dev);
|
|
|
|
err1:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(garp_init_applicant);
|
|
|
|
|
|
|
|
void garp_uninit_applicant(struct net_device *dev, struct garp_application *appl)
|
|
|
|
{
|
2010-10-24 21:32:36 +00:00
|
|
|
struct garp_port *port = rtnl_dereference(dev->garp_port);
|
|
|
|
struct garp_applicant *app = rtnl_dereference(port->applicants[appl->type]);
|
2008-07-06 04:26:13 +00:00
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
2011-08-01 16:19:00 +00:00
|
|
|
RCU_INIT_POINTER(port->applicants[appl->type], NULL);
|
2008-07-06 04:26:13 +00:00
|
|
|
|
|
|
|
/* Delete timer and generate a final TRANSMIT_PDU event to flush out
|
|
|
|
* all pending messages before the applicant is gone. */
|
|
|
|
del_timer_sync(&app->join_timer);
|
2013-04-02 21:52:40 +00:00
|
|
|
|
|
|
|
spin_lock_bh(&app->lock);
|
2008-07-06 04:26:13 +00:00
|
|
|
garp_gid_event(app, GARP_EVENT_TRANSMIT_PDU);
|
|
|
|
garp_pdu_queue(app);
|
2013-04-02 21:52:40 +00:00
|
|
|
spin_unlock_bh(&app->lock);
|
|
|
|
|
2008-07-06 04:26:13 +00:00
|
|
|
garp_queue_xmit(app);
|
|
|
|
|
2010-04-01 21:22:57 +00:00
|
|
|
dev_mc_del(dev, appl->proto.group_address);
|
2011-05-20 18:31:30 +00:00
|
|
|
kfree_rcu(app, rcu);
|
2008-07-06 04:26:13 +00:00
|
|
|
garp_release_port(dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(garp_uninit_applicant);
|
|
|
|
|
|
|
|
int garp_register_application(struct garp_application *appl)
|
|
|
|
{
|
|
|
|
appl->proto.rcv = garp_pdu_rcv;
|
|
|
|
appl->proto.data = appl;
|
|
|
|
return stp_proto_register(&appl->proto);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(garp_register_application);
|
|
|
|
|
|
|
|
void garp_unregister_application(struct garp_application *appl)
|
|
|
|
{
|
|
|
|
stp_proto_unregister(&appl->proto);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(garp_unregister_application);
|