2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* llc_sap.c - driver routines for SAP component.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997 by Procom Technology, Inc.
|
|
|
|
* 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
*
|
|
|
|
* This program can be redistributed or modified under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation.
|
|
|
|
* This program is distributed without any warranty or implied warranty
|
|
|
|
* of merchantability or fitness for a particular purpose.
|
|
|
|
*
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <net/llc.h>
|
|
|
|
#include <net/llc_if.h>
|
|
|
|
#include <net/llc_conn.h>
|
|
|
|
#include <net/llc_pdu.h>
|
|
|
|
#include <net/llc_sap.h>
|
|
|
|
#include <net/llc_s_ac.h>
|
|
|
|
#include <net/llc_s_ev.h>
|
|
|
|
#include <net/llc_s_st.h>
|
|
|
|
#include <net/sock.h>
|
2005-08-10 11:08:28 +08:00
|
|
|
#include <net/tcp_states.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-01 12:02:47 +08:00
|
|
|
static int llc_mac_header_len(unsigned short devtype)
|
|
|
|
{
|
|
|
|
switch (devtype) {
|
|
|
|
case ARPHRD_ETHER:
|
|
|
|
case ARPHRD_LOOPBACK:
|
|
|
|
return sizeof(struct ethhdr);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* llc_alloc_frame - allocates sk_buff for frame
|
2020-07-13 07:15:04 +08:00
|
|
|
* @sk: socket to allocate frame to
|
2005-09-22 14:27:56 +08:00
|
|
|
* @dev: network device this skb will be sent over
|
2008-04-01 12:02:47 +08:00
|
|
|
* @type: pdu type to allocate
|
|
|
|
* @data_size: data size to allocate
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Allocates an sk_buff for frame and initializes sk_buff fields.
|
|
|
|
* Returns allocated skb or %NULL when out of memory.
|
|
|
|
*/
|
2008-04-01 12:02:47 +08:00
|
|
|
struct sk_buff *llc_alloc_frame(struct sock *sk, struct net_device *dev,
|
|
|
|
u8 type, u32 data_size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-01 12:02:47 +08:00
|
|
|
int hlen = type == LLC_PDU_TYPE_U ? 3 : 4;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
hlen += llc_mac_header_len(dev->type);
|
|
|
|
skb = alloc_skb(hlen + data_size, GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (skb) {
|
2007-03-10 23:14:56 +08:00
|
|
|
skb_reset_mac_header(skb);
|
2008-04-01 12:02:47 +08:00
|
|
|
skb_reserve(skb, hlen);
|
2007-04-11 11:45:18 +08:00
|
|
|
skb_reset_network_header(skb);
|
2007-03-14 00:06:52 +08:00
|
|
|
skb_reset_transport_header(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
skb->protocol = htons(ETH_P_802_2);
|
2005-09-22 14:27:56 +08:00
|
|
|
skb->dev = dev;
|
2005-09-22 18:57:21 +08:00
|
|
|
if (sk != NULL)
|
|
|
|
skb_set_owner_w(skb, sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
2013-12-20 11:14:59 +08:00
|
|
|
void llc_save_primitive(struct sock *sk, struct sk_buff *skb, u8 prim)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-22 19:29:08 +08:00
|
|
|
struct sockaddr_llc *addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* save primitive for use by the user. */
|
2005-09-22 19:29:08 +08:00
|
|
|
addr = llc_ui_skb_cb(skb);
|
2006-08-04 07:38:49 +08:00
|
|
|
|
|
|
|
memset(addr, 0, sizeof(*addr));
|
2005-09-22 15:40:59 +08:00
|
|
|
addr->sllc_family = sk->sk_family;
|
2005-04-17 06:20:36 +08:00
|
|
|
addr->sllc_arphrd = skb->dev->type;
|
|
|
|
addr->sllc_test = prim == LLC_TEST_PRIM;
|
|
|
|
addr->sllc_xid = prim == LLC_XID_PRIM;
|
|
|
|
addr->sllc_ua = prim == LLC_DATAUNIT_PRIM;
|
|
|
|
llc_pdu_decode_sa(skb, addr->sllc_mac);
|
|
|
|
llc_pdu_decode_ssap(skb, &addr->sllc_sap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* llc_sap_rtn_pdu - Informs upper layer on rx of an UI, XID or TEST pdu.
|
|
|
|
* @sap: pointer to SAP
|
|
|
|
* @skb: received pdu
|
|
|
|
*/
|
|
|
|
void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct llc_sap_state_ev *ev = llc_sap_ev(skb);
|
|
|
|
struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
|
|
|
|
|
|
|
|
switch (LLC_U_PDU_RSP(pdu)) {
|
|
|
|
case LLC_1_PDU_CMD_TEST:
|
|
|
|
ev->prim = LLC_TEST_PRIM; break;
|
|
|
|
case LLC_1_PDU_CMD_XID:
|
|
|
|
ev->prim = LLC_XID_PRIM; break;
|
|
|
|
case LLC_1_PDU_CMD_UI:
|
|
|
|
ev->prim = LLC_DATAUNIT_PRIM; break;
|
|
|
|
}
|
|
|
|
ev->ind_cfm_flag = LLC_IND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* llc_find_sap_trans - finds transition for event
|
|
|
|
* @sap: pointer to SAP
|
|
|
|
* @skb: happened event
|
|
|
|
*
|
|
|
|
* This function finds transition that matches with happened event.
|
|
|
|
* Returns the pointer to found transition on success or %NULL for
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
static struct llc_sap_state_trans *llc_find_sap_trans(struct llc_sap *sap,
|
2013-12-20 11:14:59 +08:00
|
|
|
struct sk_buff *skb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
struct llc_sap_state_trans *rc = NULL;
|
|
|
|
struct llc_sap_state_trans **next_trans;
|
|
|
|
struct llc_sap_state *curr_state = &llc_sap_state_table[sap->state - 1];
|
|
|
|
/*
|
|
|
|
* Search thru events for this state until list exhausted or until
|
|
|
|
* its obvious the event is not valid for the current state
|
|
|
|
*/
|
|
|
|
for (next_trans = curr_state->transitions; next_trans[i]->ev; i++)
|
|
|
|
if (!next_trans[i]->ev(sap, skb)) {
|
|
|
|
rc = next_trans[i]; /* got event match; return it */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* llc_exec_sap_trans_actions - execute actions related to event
|
|
|
|
* @sap: pointer to SAP
|
|
|
|
* @trans: pointer to transition that it's actions must be performed
|
|
|
|
* @skb: happened event.
|
|
|
|
*
|
|
|
|
* This function executes actions that is related to happened event.
|
|
|
|
* Returns 0 for success and 1 for failure of at least one action.
|
|
|
|
*/
|
|
|
|
static int llc_exec_sap_trans_actions(struct llc_sap *sap,
|
|
|
|
struct llc_sap_state_trans *trans,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
2014-12-11 01:55:50 +08:00
|
|
|
const llc_sap_action_t *next_action = trans->ev_actions;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (; next_action && *next_action; next_action++)
|
|
|
|
if ((*next_action)(sap, skb))
|
|
|
|
rc = 1;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* llc_sap_next_state - finds transition, execs actions & change SAP state
|
|
|
|
* @sap: pointer to SAP
|
|
|
|
* @skb: happened event
|
|
|
|
*
|
|
|
|
* This function finds transition that matches with happened event, then
|
|
|
|
* executes related actions and finally changes state of SAP. It returns
|
|
|
|
* 0 on success and 1 for failure.
|
|
|
|
*/
|
|
|
|
static int llc_sap_next_state(struct llc_sap *sap, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int rc = 1;
|
|
|
|
struct llc_sap_state_trans *trans;
|
|
|
|
|
|
|
|
if (sap->state > LLC_NR_SAP_STATES)
|
|
|
|
goto out;
|
|
|
|
trans = llc_find_sap_trans(sap, skb);
|
|
|
|
if (!trans)
|
|
|
|
goto out;
|
|
|
|
/*
|
|
|
|
* Got the state to which we next transition; perform the actions
|
|
|
|
* associated with this transition before actually transitioning to the
|
|
|
|
* next state
|
|
|
|
*/
|
|
|
|
rc = llc_exec_sap_trans_actions(sap, trans, skb);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
/*
|
|
|
|
* Transition SAP to next state if all actions execute successfully
|
|
|
|
*/
|
|
|
|
sap->state = trans->next_state;
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* llc_sap_state_process - sends event to SAP state machine
|
|
|
|
* @sap: sap to use
|
|
|
|
* @skb: pointer to occurred event
|
|
|
|
*
|
|
|
|
* After executing actions of the event, upper layer will be indicated
|
|
|
|
* if needed(on receiving an UI frame). sk can be null for the
|
|
|
|
* datalink_proto case.
|
2019-10-07 05:24:24 +08:00
|
|
|
*
|
|
|
|
* This function always consumes a reference to the skb.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct llc_sap_state_ev *ev = llc_sap_ev(skb);
|
|
|
|
|
|
|
|
ev->ind_cfm_flag = 0;
|
|
|
|
llc_sap_next_state(sap, skb);
|
2019-10-07 05:24:24 +08:00
|
|
|
|
|
|
|
if (ev->ind_cfm_flag == LLC_IND && skb->sk->sk_state != TCP_LISTEN) {
|
|
|
|
llc_save_primitive(skb->sk, skb, ev->prim);
|
|
|
|
|
|
|
|
/* queue skb to the user. */
|
|
|
|
if (sock_queue_rcv_skb(skb->sk, skb) == 0)
|
|
|
|
return;
|
2007-02-09 22:25:01 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* llc_build_and_send_test_pkt - TEST interface for upper layers.
|
|
|
|
* @sap: sap to use
|
|
|
|
* @skb: packet to send
|
|
|
|
* @dmac: destination mac address
|
|
|
|
* @dsap: destination sap
|
|
|
|
*
|
|
|
|
* This function is called when upper layer wants to send a TEST pdu.
|
|
|
|
* Returns 0 for success, 1 otherwise.
|
|
|
|
*/
|
2007-02-09 22:25:01 +08:00
|
|
|
void llc_build_and_send_test_pkt(struct llc_sap *sap,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sk_buff *skb, u8 *dmac, u8 dsap)
|
|
|
|
{
|
|
|
|
struct llc_sap_state_ev *ev = llc_sap_ev(skb);
|
|
|
|
|
|
|
|
ev->saddr.lsap = sap->laddr.lsap;
|
|
|
|
ev->daddr.lsap = dsap;
|
|
|
|
memcpy(ev->saddr.mac, skb->dev->dev_addr, IFHWADDRLEN);
|
|
|
|
memcpy(ev->daddr.mac, dmac, IFHWADDRLEN);
|
2007-02-09 22:25:01 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ev->type = LLC_SAP_EV_TYPE_PRIM;
|
|
|
|
ev->prim = LLC_TEST_PRIM;
|
|
|
|
ev->prim_type = LLC_PRIM_TYPE_REQ;
|
|
|
|
llc_sap_state_process(sap, skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* llc_build_and_send_xid_pkt - XID interface for upper layers
|
|
|
|
* @sap: sap to use
|
|
|
|
* @skb: packet to send
|
|
|
|
* @dmac: destination mac address
|
|
|
|
* @dsap: destination sap
|
|
|
|
*
|
|
|
|
* This function is called when upper layer wants to send a XID pdu.
|
|
|
|
* Returns 0 for success, 1 otherwise.
|
|
|
|
*/
|
|
|
|
void llc_build_and_send_xid_pkt(struct llc_sap *sap, struct sk_buff *skb,
|
|
|
|
u8 *dmac, u8 dsap)
|
|
|
|
{
|
|
|
|
struct llc_sap_state_ev *ev = llc_sap_ev(skb);
|
|
|
|
|
|
|
|
ev->saddr.lsap = sap->laddr.lsap;
|
|
|
|
ev->daddr.lsap = dsap;
|
|
|
|
memcpy(ev->saddr.mac, skb->dev->dev_addr, IFHWADDRLEN);
|
|
|
|
memcpy(ev->daddr.mac, dmac, IFHWADDRLEN);
|
|
|
|
|
|
|
|
ev->type = LLC_SAP_EV_TYPE_PRIM;
|
|
|
|
ev->prim = LLC_XID_PRIM;
|
|
|
|
ev->prim_type = LLC_PRIM_TYPE_REQ;
|
|
|
|
llc_sap_state_process(sap, skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* llc_sap_rcv - sends received pdus to the sap state machine
|
|
|
|
* @sap: current sap component structure.
|
|
|
|
* @skb: received frame.
|
2020-07-13 07:15:04 +08:00
|
|
|
* @sk: socket to associate to frame
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Sends received pdus to the sap state machine.
|
|
|
|
*/
|
2008-05-30 17:57:29 +08:00
|
|
|
static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb,
|
|
|
|
struct sock *sk)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct llc_sap_state_ev *ev = llc_sap_ev(skb);
|
|
|
|
|
|
|
|
ev->type = LLC_SAP_EV_TYPE_PDU;
|
|
|
|
ev->reason = 0;
|
2017-02-13 06:03:52 +08:00
|
|
|
skb_orphan(skb);
|
|
|
|
sock_hold(sk);
|
2008-05-30 17:57:29 +08:00
|
|
|
skb->sk = sk;
|
2017-02-13 06:03:52 +08:00
|
|
|
skb->destructor = sock_efree;
|
2005-04-17 06:20:36 +08:00
|
|
|
llc_sap_state_process(sap, skb);
|
|
|
|
}
|
|
|
|
|
2009-12-26 19:51:02 +08:00
|
|
|
static inline bool llc_dgram_match(const struct llc_sap *sap,
|
|
|
|
const struct llc_addr *laddr,
|
llc: Check netns in llc_dgram_match().
We will remove this restriction in llc_rcv() soon, which means that the
protocol handler must be aware of netns.
if (!net_eq(dev_net(dev), &init_net))
goto drop;
llc_rcv() fetches llc_type_handlers[llc_pdu_type(skb) - 1] and calls it
if not NULL.
If the PDU type is LLC_DEST_SAP, llc_sap_handler() is called to pass skb
to corresponding sockets. Then, we must look up a proper socket in the
same netns with skb->dev.
If the destination is a multicast address, llc_sap_handler() calls
llc_sap_mcast(). It calculates a hash based on DSAP and skb->dev->ifindex,
iterates on a socket list, and calls llc_mcast_match() to check if the
socket is the correct destination. Then, llc_mcast_match() checks if
skb->dev matches with llc_sk(sk)->dev. So, we need not check netns here.
OTOH, if the destination is a unicast address, llc_sap_handler() calls
llc_lookup_dgram() to look up a socket, but it does not check the netns.
Therefore, we need to add netns check in llc_lookup_dgram().
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-07-19 01:41:49 +08:00
|
|
|
const struct sock *sk,
|
|
|
|
const struct net *net)
|
2009-12-26 19:51:02 +08:00
|
|
|
{
|
|
|
|
struct llc_sock *llc = llc_sk(sk);
|
|
|
|
|
|
|
|
return sk->sk_type == SOCK_DGRAM &&
|
llc: Check netns in llc_dgram_match().
We will remove this restriction in llc_rcv() soon, which means that the
protocol handler must be aware of netns.
if (!net_eq(dev_net(dev), &init_net))
goto drop;
llc_rcv() fetches llc_type_handlers[llc_pdu_type(skb) - 1] and calls it
if not NULL.
If the PDU type is LLC_DEST_SAP, llc_sap_handler() is called to pass skb
to corresponding sockets. Then, we must look up a proper socket in the
same netns with skb->dev.
If the destination is a multicast address, llc_sap_handler() calls
llc_sap_mcast(). It calculates a hash based on DSAP and skb->dev->ifindex,
iterates on a socket list, and calls llc_mcast_match() to check if the
socket is the correct destination. Then, llc_mcast_match() checks if
skb->dev matches with llc_sk(sk)->dev. So, we need not check netns here.
OTOH, if the destination is a unicast address, llc_sap_handler() calls
llc_lookup_dgram() to look up a socket, but it does not check the netns.
Therefore, we need to add netns check in llc_lookup_dgram().
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-07-19 01:41:49 +08:00
|
|
|
net_eq(sock_net(sk), net) &&
|
|
|
|
llc->laddr.lsap == laddr->lsap &&
|
|
|
|
ether_addr_equal(llc->laddr.mac, laddr->mac);
|
2009-12-26 19:51:02 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* llc_lookup_dgram - Finds dgram socket for the local sap/mac
|
|
|
|
* @sap: SAP
|
|
|
|
* @laddr: address of local LLC (MAC + SAP)
|
llc: Check netns in llc_dgram_match().
We will remove this restriction in llc_rcv() soon, which means that the
protocol handler must be aware of netns.
if (!net_eq(dev_net(dev), &init_net))
goto drop;
llc_rcv() fetches llc_type_handlers[llc_pdu_type(skb) - 1] and calls it
if not NULL.
If the PDU type is LLC_DEST_SAP, llc_sap_handler() is called to pass skb
to corresponding sockets. Then, we must look up a proper socket in the
same netns with skb->dev.
If the destination is a multicast address, llc_sap_handler() calls
llc_sap_mcast(). It calculates a hash based on DSAP and skb->dev->ifindex,
iterates on a socket list, and calls llc_mcast_match() to check if the
socket is the correct destination. Then, llc_mcast_match() checks if
skb->dev matches with llc_sk(sk)->dev. So, we need not check netns here.
OTOH, if the destination is a unicast address, llc_sap_handler() calls
llc_lookup_dgram() to look up a socket, but it does not check the netns.
Therefore, we need to add netns check in llc_lookup_dgram().
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-07-19 01:41:49 +08:00
|
|
|
* @net: netns to look up a socket in
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Search socket list of the SAP and finds connection using the local
|
|
|
|
* mac, and local sap. Returns pointer for socket found, %NULL otherwise.
|
|
|
|
*/
|
|
|
|
static struct sock *llc_lookup_dgram(struct llc_sap *sap,
|
llc: Check netns in llc_dgram_match().
We will remove this restriction in llc_rcv() soon, which means that the
protocol handler must be aware of netns.
if (!net_eq(dev_net(dev), &init_net))
goto drop;
llc_rcv() fetches llc_type_handlers[llc_pdu_type(skb) - 1] and calls it
if not NULL.
If the PDU type is LLC_DEST_SAP, llc_sap_handler() is called to pass skb
to corresponding sockets. Then, we must look up a proper socket in the
same netns with skb->dev.
If the destination is a multicast address, llc_sap_handler() calls
llc_sap_mcast(). It calculates a hash based on DSAP and skb->dev->ifindex,
iterates on a socket list, and calls llc_mcast_match() to check if the
socket is the correct destination. Then, llc_mcast_match() checks if
skb->dev matches with llc_sk(sk)->dev. So, we need not check netns here.
OTOH, if the destination is a unicast address, llc_sap_handler() calls
llc_lookup_dgram() to look up a socket, but it does not check the netns.
Therefore, we need to add netns check in llc_lookup_dgram().
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-07-19 01:41:49 +08:00
|
|
|
const struct llc_addr *laddr,
|
|
|
|
const struct net *net)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *rc;
|
2009-12-26 19:51:02 +08:00
|
|
|
struct hlist_nulls_node *node;
|
2009-12-26 19:51:05 +08:00
|
|
|
int slot = llc_sk_laddr_hashfn(sap, laddr);
|
|
|
|
struct hlist_nulls_head *laddr_hb = &sap->sk_laddr_hash[slot];
|
2009-12-26 19:51:02 +08:00
|
|
|
|
|
|
|
rcu_read_lock_bh();
|
|
|
|
again:
|
2009-12-26 19:51:05 +08:00
|
|
|
sk_nulls_for_each_rcu(rc, node, laddr_hb) {
|
llc: Check netns in llc_dgram_match().
We will remove this restriction in llc_rcv() soon, which means that the
protocol handler must be aware of netns.
if (!net_eq(dev_net(dev), &init_net))
goto drop;
llc_rcv() fetches llc_type_handlers[llc_pdu_type(skb) - 1] and calls it
if not NULL.
If the PDU type is LLC_DEST_SAP, llc_sap_handler() is called to pass skb
to corresponding sockets. Then, we must look up a proper socket in the
same netns with skb->dev.
If the destination is a multicast address, llc_sap_handler() calls
llc_sap_mcast(). It calculates a hash based on DSAP and skb->dev->ifindex,
iterates on a socket list, and calls llc_mcast_match() to check if the
socket is the correct destination. Then, llc_mcast_match() checks if
skb->dev matches with llc_sk(sk)->dev. So, we need not check netns here.
OTOH, if the destination is a unicast address, llc_sap_handler() calls
llc_lookup_dgram() to look up a socket, but it does not check the netns.
Therefore, we need to add netns check in llc_lookup_dgram().
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-07-19 01:41:49 +08:00
|
|
|
if (llc_dgram_match(sap, laddr, rc, net)) {
|
2017-01-18 18:53:44 +08:00
|
|
|
/* Extra checks required by SLAB_TYPESAFE_BY_RCU */
|
2017-06-30 18:08:01 +08:00
|
|
|
if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt)))
|
2009-12-26 19:51:02 +08:00
|
|
|
goto again;
|
|
|
|
if (unlikely(llc_sk(rc)->sap != sap ||
|
llc: Check netns in llc_dgram_match().
We will remove this restriction in llc_rcv() soon, which means that the
protocol handler must be aware of netns.
if (!net_eq(dev_net(dev), &init_net))
goto drop;
llc_rcv() fetches llc_type_handlers[llc_pdu_type(skb) - 1] and calls it
if not NULL.
If the PDU type is LLC_DEST_SAP, llc_sap_handler() is called to pass skb
to corresponding sockets. Then, we must look up a proper socket in the
same netns with skb->dev.
If the destination is a multicast address, llc_sap_handler() calls
llc_sap_mcast(). It calculates a hash based on DSAP and skb->dev->ifindex,
iterates on a socket list, and calls llc_mcast_match() to check if the
socket is the correct destination. Then, llc_mcast_match() checks if
skb->dev matches with llc_sk(sk)->dev. So, we need not check netns here.
OTOH, if the destination is a unicast address, llc_sap_handler() calls
llc_lookup_dgram() to look up a socket, but it does not check the netns.
Therefore, we need to add netns check in llc_lookup_dgram().
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-07-19 01:41:49 +08:00
|
|
|
!llc_dgram_match(sap, laddr, rc, net))) {
|
2009-12-26 19:51:02 +08:00
|
|
|
sock_put(rc);
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rc = NULL;
|
2009-12-26 19:51:05 +08:00
|
|
|
/*
|
|
|
|
* if the nulls value we got at the end of this lookup is
|
|
|
|
* not the expected one, we must restart lookup.
|
|
|
|
* We probably met an item that was moved to another chain.
|
|
|
|
*/
|
|
|
|
if (unlikely(get_nulls_value(node) != slot))
|
|
|
|
goto again;
|
2005-04-17 06:20:36 +08:00
|
|
|
found:
|
2009-12-26 19:51:02 +08:00
|
|
|
rcu_read_unlock_bh();
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-12-26 19:51:02 +08:00
|
|
|
static inline bool llc_mcast_match(const struct llc_sap *sap,
|
|
|
|
const struct llc_addr *laddr,
|
|
|
|
const struct sk_buff *skb,
|
|
|
|
const struct sock *sk)
|
|
|
|
{
|
|
|
|
struct llc_sock *llc = llc_sk(sk);
|
|
|
|
|
|
|
|
return sk->sk_type == SOCK_DGRAM &&
|
|
|
|
llc->laddr.lsap == laddr->lsap &&
|
|
|
|
llc->dev == skb->dev;
|
|
|
|
}
|
|
|
|
|
2009-12-26 19:51:03 +08:00
|
|
|
static void llc_do_mcast(struct llc_sap *sap, struct sk_buff *skb,
|
|
|
|
struct sock **stack, int count)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
skb1 = skb_clone(skb, GFP_ATOMIC);
|
|
|
|
if (!skb1) {
|
|
|
|
sock_put(stack[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
llc_sap_rcv(sap, skb1, stack[i]);
|
|
|
|
sock_put(stack[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-26 06:10:37 +08:00
|
|
|
/**
|
|
|
|
* llc_sap_mcast - Deliver multicast PDU's to all matching datagram sockets.
|
|
|
|
* @sap: SAP
|
|
|
|
* @laddr: address of local LLC (MAC + SAP)
|
2020-07-13 07:15:04 +08:00
|
|
|
* @skb: PDU to deliver
|
2006-05-26 06:10:37 +08:00
|
|
|
*
|
|
|
|
* Search socket list of the SAP and finds connections with same sap.
|
|
|
|
* Deliver clone to each.
|
|
|
|
*/
|
|
|
|
static void llc_sap_mcast(struct llc_sap *sap,
|
|
|
|
const struct llc_addr *laddr,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
2018-03-12 05:12:04 +08:00
|
|
|
int i = 0;
|
|
|
|
struct sock *sk;
|
|
|
|
struct sock *stack[256 / sizeof(struct sock *)];
|
2009-12-26 19:51:04 +08:00
|
|
|
struct llc_sock *llc;
|
|
|
|
struct hlist_head *dev_hb = llc_sk_dev_hash(sap, skb->dev->ifindex);
|
2006-05-26 06:10:37 +08:00
|
|
|
|
2009-12-26 19:51:02 +08:00
|
|
|
spin_lock_bh(&sap->sk_lock);
|
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 09:06:00 +08:00
|
|
|
hlist_for_each_entry(llc, dev_hb, dev_hash_node) {
|
2009-12-26 19:51:04 +08:00
|
|
|
|
|
|
|
sk = &llc->sk;
|
2006-05-26 06:10:37 +08:00
|
|
|
|
2009-12-26 19:51:02 +08:00
|
|
|
if (!llc_mcast_match(sap, laddr, skb, sk))
|
2006-08-14 09:56:26 +08:00
|
|
|
continue;
|
|
|
|
|
2006-05-26 06:10:37 +08:00
|
|
|
sock_hold(sk);
|
2018-03-12 05:12:04 +08:00
|
|
|
if (i < ARRAY_SIZE(stack))
|
2009-12-26 19:51:03 +08:00
|
|
|
stack[i++] = sk;
|
|
|
|
else {
|
|
|
|
llc_do_mcast(sap, skb, stack, i);
|
|
|
|
i = 0;
|
|
|
|
}
|
2006-05-26 06:10:37 +08:00
|
|
|
}
|
2009-12-26 19:51:02 +08:00
|
|
|
spin_unlock_bh(&sap->sk_lock);
|
2009-12-26 19:51:03 +08:00
|
|
|
|
|
|
|
llc_do_mcast(sap, skb, stack, i);
|
2006-05-26 06:10:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct llc_addr laddr;
|
|
|
|
|
|
|
|
llc_pdu_decode_da(skb, laddr.mac);
|
|
|
|
llc_pdu_decode_dsap(skb, &laddr.lsap);
|
|
|
|
|
2013-09-02 04:11:55 +08:00
|
|
|
if (is_multicast_ether_addr(laddr.mac)) {
|
2006-05-26 06:10:37 +08:00
|
|
|
llc_sap_mcast(sap, &laddr, skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree_skb(skb);
|
2006-05-26 06:10:37 +08:00
|
|
|
} else {
|
llc: Check netns in llc_dgram_match().
We will remove this restriction in llc_rcv() soon, which means that the
protocol handler must be aware of netns.
if (!net_eq(dev_net(dev), &init_net))
goto drop;
llc_rcv() fetches llc_type_handlers[llc_pdu_type(skb) - 1] and calls it
if not NULL.
If the PDU type is LLC_DEST_SAP, llc_sap_handler() is called to pass skb
to corresponding sockets. Then, we must look up a proper socket in the
same netns with skb->dev.
If the destination is a multicast address, llc_sap_handler() calls
llc_sap_mcast(). It calculates a hash based on DSAP and skb->dev->ifindex,
iterates on a socket list, and calls llc_mcast_match() to check if the
socket is the correct destination. Then, llc_mcast_match() checks if
skb->dev matches with llc_sk(sk)->dev. So, we need not check netns here.
OTOH, if the destination is a unicast address, llc_sap_handler() calls
llc_lookup_dgram() to look up a socket, but it does not check the netns.
Therefore, we need to add netns check in llc_lookup_dgram().
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-07-19 01:41:49 +08:00
|
|
|
struct sock *sk = llc_lookup_dgram(sap, &laddr, dev_net(skb->dev));
|
2006-05-26 06:10:37 +08:00
|
|
|
if (sk) {
|
2008-05-30 17:57:29 +08:00
|
|
|
llc_sap_rcv(sap, skb, sk);
|
2006-05-26 06:10:37 +08:00
|
|
|
sock_put(sk);
|
|
|
|
} else
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|