Merge branch 'net-support-stp-on-bridge-in-non-root-netns'
Kuniyuki Iwashima says: ==================== net: Support STP on bridge in non-root netns. Currently, STP does not work in non-root netns as llc_rcv() drops packets from non-root netns. This series fixes it by making some protocol handlers netns-aware, which are called from llc_rcv() as follows: llc_rcv() | |- sap->rcv_func : registered by llc_sap_open() | | * functions : regsitered by register_8022_client() | -> No in-kernel user call register_8022_client() | | * snap_rcv() | | | `- proto->rcvfunc() : registered by register_snap_client() | | * aarp_rcv() : drop packets from non-root netns | * atalk_rcv() : drop packets from non-root netns | | * stp_pdu_rcv() | | | `- garp_protos[]->rcv() : registered by stp_proto_register() | | * garp_pdu_rcv() : netns-aware | * br_stp_rcv() : netns-aware | |- llc_type_handlers[llc_pdu_type(skb) - 1] | | * llc_sap_handler() : NOT netns-aware (Patch 1) | * llc_conn_handler() : NOT netns-aware (Patch 2) | `- llc_station_handler * llc_station_rcv() : netns-aware Patch 1 & 2 convert not-netns-aware functions and Patch 3 remove the netns restriction in llc_rcv(). Note this series does not namespacify AF_LLC so that these patches can be backported to stable without conflicts (at least to 4.14.y). Another series that adds netns support for AF_LLC will be targeted to net-next later. ==================== Link: https://lore.kernel.org/r/20230718174152.57408-1-kuniyu@amazon.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Коммит
ac528649f7
|
@ -111,7 +111,7 @@ void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit);
|
|||
void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit);
|
||||
int llc_conn_remove_acked_pdus(struct sock *conn, u8 nr, u16 *how_many_unacked);
|
||||
struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *daddr,
|
||||
struct llc_addr *laddr);
|
||||
struct llc_addr *laddr, const struct net *net);
|
||||
void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk);
|
||||
void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk);
|
||||
|
||||
|
|
|
@ -201,9 +201,6 @@ int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
|
|||
{
|
||||
ASSERT_RTNL();
|
||||
|
||||
if (!net_eq(dev_net(br->dev), &init_net))
|
||||
NL_SET_ERR_MSG_MOD(extack, "STP does not work in non-root netns");
|
||||
|
||||
if (br_mrp_enabled(br)) {
|
||||
NL_SET_ERR_MSG_MOD(extack,
|
||||
"STP can't be enabled if MRP is already enabled");
|
||||
|
|
|
@ -402,7 +402,7 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
|
|||
memcpy(laddr.mac, addr->sllc_mac, IFHWADDRLEN);
|
||||
laddr.lsap = addr->sllc_sap;
|
||||
rc = -EADDRINUSE; /* mac + sap clash. */
|
||||
ask = llc_lookup_established(sap, &daddr, &laddr);
|
||||
ask = llc_lookup_established(sap, &daddr, &laddr, &init_net);
|
||||
if (ask) {
|
||||
sock_put(ask);
|
||||
goto out_put;
|
||||
|
|
|
@ -453,11 +453,13 @@ static int llc_exec_conn_trans_actions(struct sock *sk,
|
|||
static inline bool llc_estab_match(const struct llc_sap *sap,
|
||||
const struct llc_addr *daddr,
|
||||
const struct llc_addr *laddr,
|
||||
const struct sock *sk)
|
||||
const struct sock *sk,
|
||||
const struct net *net)
|
||||
{
|
||||
struct llc_sock *llc = llc_sk(sk);
|
||||
|
||||
return llc->laddr.lsap == laddr->lsap &&
|
||||
return net_eq(sock_net(sk), net) &&
|
||||
llc->laddr.lsap == laddr->lsap &&
|
||||
llc->daddr.lsap == daddr->lsap &&
|
||||
ether_addr_equal(llc->laddr.mac, laddr->mac) &&
|
||||
ether_addr_equal(llc->daddr.mac, daddr->mac);
|
||||
|
@ -468,6 +470,7 @@ static inline bool llc_estab_match(const struct llc_sap *sap,
|
|||
* @sap: SAP
|
||||
* @daddr: address of remote LLC (MAC + SAP)
|
||||
* @laddr: address of local LLC (MAC + SAP)
|
||||
* @net: netns to look up a socket in
|
||||
*
|
||||
* Search connection list of the SAP and finds connection using the remote
|
||||
* mac, remote sap, local mac, and local sap. Returns pointer for
|
||||
|
@ -476,7 +479,8 @@ static inline bool llc_estab_match(const struct llc_sap *sap,
|
|||
*/
|
||||
static struct sock *__llc_lookup_established(struct llc_sap *sap,
|
||||
struct llc_addr *daddr,
|
||||
struct llc_addr *laddr)
|
||||
struct llc_addr *laddr,
|
||||
const struct net *net)
|
||||
{
|
||||
struct sock *rc;
|
||||
struct hlist_nulls_node *node;
|
||||
|
@ -486,12 +490,12 @@ static struct sock *__llc_lookup_established(struct llc_sap *sap,
|
|||
rcu_read_lock();
|
||||
again:
|
||||
sk_nulls_for_each_rcu(rc, node, laddr_hb) {
|
||||
if (llc_estab_match(sap, daddr, laddr, rc)) {
|
||||
if (llc_estab_match(sap, daddr, laddr, rc, net)) {
|
||||
/* Extra checks required by SLAB_TYPESAFE_BY_RCU */
|
||||
if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt)))
|
||||
goto again;
|
||||
if (unlikely(llc_sk(rc)->sap != sap ||
|
||||
!llc_estab_match(sap, daddr, laddr, rc))) {
|
||||
!llc_estab_match(sap, daddr, laddr, rc, net))) {
|
||||
sock_put(rc);
|
||||
continue;
|
||||
}
|
||||
|
@ -513,29 +517,33 @@ found:
|
|||
|
||||
struct sock *llc_lookup_established(struct llc_sap *sap,
|
||||
struct llc_addr *daddr,
|
||||
struct llc_addr *laddr)
|
||||
struct llc_addr *laddr,
|
||||
const struct net *net)
|
||||
{
|
||||
struct sock *sk;
|
||||
|
||||
local_bh_disable();
|
||||
sk = __llc_lookup_established(sap, daddr, laddr);
|
||||
sk = __llc_lookup_established(sap, daddr, laddr, net);
|
||||
local_bh_enable();
|
||||
return sk;
|
||||
}
|
||||
|
||||
static inline bool llc_listener_match(const struct llc_sap *sap,
|
||||
const struct llc_addr *laddr,
|
||||
const struct sock *sk)
|
||||
const struct sock *sk,
|
||||
const struct net *net)
|
||||
{
|
||||
struct llc_sock *llc = llc_sk(sk);
|
||||
|
||||
return sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN &&
|
||||
return net_eq(sock_net(sk), net) &&
|
||||
sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN &&
|
||||
llc->laddr.lsap == laddr->lsap &&
|
||||
ether_addr_equal(llc->laddr.mac, laddr->mac);
|
||||
}
|
||||
|
||||
static struct sock *__llc_lookup_listener(struct llc_sap *sap,
|
||||
struct llc_addr *laddr)
|
||||
struct llc_addr *laddr,
|
||||
const struct net *net)
|
||||
{
|
||||
struct sock *rc;
|
||||
struct hlist_nulls_node *node;
|
||||
|
@ -545,12 +553,12 @@ static struct sock *__llc_lookup_listener(struct llc_sap *sap,
|
|||
rcu_read_lock();
|
||||
again:
|
||||
sk_nulls_for_each_rcu(rc, node, laddr_hb) {
|
||||
if (llc_listener_match(sap, laddr, rc)) {
|
||||
if (llc_listener_match(sap, laddr, rc, net)) {
|
||||
/* Extra checks required by SLAB_TYPESAFE_BY_RCU */
|
||||
if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt)))
|
||||
goto again;
|
||||
if (unlikely(llc_sk(rc)->sap != sap ||
|
||||
!llc_listener_match(sap, laddr, rc))) {
|
||||
!llc_listener_match(sap, laddr, rc, net))) {
|
||||
sock_put(rc);
|
||||
continue;
|
||||
}
|
||||
|
@ -574,6 +582,7 @@ found:
|
|||
* llc_lookup_listener - Finds listener for local MAC + SAP
|
||||
* @sap: SAP
|
||||
* @laddr: address of local LLC (MAC + SAP)
|
||||
* @net: netns to look up a socket in
|
||||
*
|
||||
* Search connection list of the SAP and finds connection listening on
|
||||
* local mac, and local sap. Returns pointer for parent socket found,
|
||||
|
@ -581,24 +590,26 @@ found:
|
|||
* Caller has to make sure local_bh is disabled.
|
||||
*/
|
||||
static struct sock *llc_lookup_listener(struct llc_sap *sap,
|
||||
struct llc_addr *laddr)
|
||||
struct llc_addr *laddr,
|
||||
const struct net *net)
|
||||
{
|
||||
struct sock *rc = __llc_lookup_listener(sap, laddr, net);
|
||||
static struct llc_addr null_addr;
|
||||
struct sock *rc = __llc_lookup_listener(sap, laddr);
|
||||
|
||||
if (!rc)
|
||||
rc = __llc_lookup_listener(sap, &null_addr);
|
||||
rc = __llc_lookup_listener(sap, &null_addr, net);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static struct sock *__llc_lookup(struct llc_sap *sap,
|
||||
struct llc_addr *daddr,
|
||||
struct llc_addr *laddr)
|
||||
struct llc_addr *laddr,
|
||||
const struct net *net)
|
||||
{
|
||||
struct sock *sk = __llc_lookup_established(sap, daddr, laddr);
|
||||
struct sock *sk = __llc_lookup_established(sap, daddr, laddr, net);
|
||||
|
||||
return sk ? : llc_lookup_listener(sap, laddr);
|
||||
return sk ? : llc_lookup_listener(sap, laddr, net);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -776,7 +787,7 @@ void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
|
|||
llc_pdu_decode_da(skb, daddr.mac);
|
||||
llc_pdu_decode_dsap(skb, &daddr.lsap);
|
||||
|
||||
sk = __llc_lookup(sap, &saddr, &daddr);
|
||||
sk = __llc_lookup(sap, &saddr, &daddr, dev_net(skb->dev));
|
||||
if (!sk)
|
||||
goto drop;
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ int llc_establish_connection(struct sock *sk, const u8 *lmac, u8 *dmac, u8 dsap)
|
|||
daddr.lsap = dsap;
|
||||
memcpy(daddr.mac, dmac, sizeof(daddr.mac));
|
||||
memcpy(laddr.mac, lmac, sizeof(laddr.mac));
|
||||
existing = llc_lookup_established(llc->sap, &daddr, &laddr);
|
||||
existing = llc_lookup_established(llc->sap, &daddr, &laddr, sock_net(sk));
|
||||
if (existing) {
|
||||
if (existing->sk_state == TCP_ESTABLISHED) {
|
||||
sk = existing;
|
||||
|
|
|
@ -163,9 +163,6 @@ int llc_rcv(struct sk_buff *skb, struct net_device *dev,
|
|||
void (*sta_handler)(struct sk_buff *skb);
|
||||
void (*sap_handler)(struct llc_sap *sap, struct sk_buff *skb);
|
||||
|
||||
if (!net_eq(dev_net(dev), &init_net))
|
||||
goto drop;
|
||||
|
||||
/*
|
||||
* When the interface is in promisc. mode, drop all the crap that it
|
||||
* receives, do not try to analyse it.
|
||||
|
|
|
@ -294,25 +294,29 @@ static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb,
|
|||
|
||||
static inline bool llc_dgram_match(const struct llc_sap *sap,
|
||||
const struct llc_addr *laddr,
|
||||
const struct sock *sk)
|
||||
const struct sock *sk,
|
||||
const struct net *net)
|
||||
{
|
||||
struct llc_sock *llc = llc_sk(sk);
|
||||
|
||||
return sk->sk_type == SOCK_DGRAM &&
|
||||
llc->laddr.lsap == laddr->lsap &&
|
||||
ether_addr_equal(llc->laddr.mac, laddr->mac);
|
||||
net_eq(sock_net(sk), net) &&
|
||||
llc->laddr.lsap == laddr->lsap &&
|
||||
ether_addr_equal(llc->laddr.mac, laddr->mac);
|
||||
}
|
||||
|
||||
/**
|
||||
* llc_lookup_dgram - Finds dgram socket for the local sap/mac
|
||||
* @sap: SAP
|
||||
* @laddr: address of local LLC (MAC + SAP)
|
||||
* @net: netns to look up a socket in
|
||||
*
|
||||
* 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,
|
||||
const struct llc_addr *laddr)
|
||||
const struct llc_addr *laddr,
|
||||
const struct net *net)
|
||||
{
|
||||
struct sock *rc;
|
||||
struct hlist_nulls_node *node;
|
||||
|
@ -322,12 +326,12 @@ static struct sock *llc_lookup_dgram(struct llc_sap *sap,
|
|||
rcu_read_lock_bh();
|
||||
again:
|
||||
sk_nulls_for_each_rcu(rc, node, laddr_hb) {
|
||||
if (llc_dgram_match(sap, laddr, rc)) {
|
||||
if (llc_dgram_match(sap, laddr, rc, net)) {
|
||||
/* Extra checks required by SLAB_TYPESAFE_BY_RCU */
|
||||
if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt)))
|
||||
goto again;
|
||||
if (unlikely(llc_sk(rc)->sap != sap ||
|
||||
!llc_dgram_match(sap, laddr, rc))) {
|
||||
!llc_dgram_match(sap, laddr, rc, net))) {
|
||||
sock_put(rc);
|
||||
continue;
|
||||
}
|
||||
|
@ -429,7 +433,7 @@ void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb)
|
|||
llc_sap_mcast(sap, &laddr, skb);
|
||||
kfree_skb(skb);
|
||||
} else {
|
||||
struct sock *sk = llc_lookup_dgram(sap, &laddr);
|
||||
struct sock *sk = llc_lookup_dgram(sap, &laddr, dev_net(skb->dev));
|
||||
if (sk) {
|
||||
llc_sap_rcv(sap, skb, sk);
|
||||
sock_put(sk);
|
||||
|
|
Загрузка…
Ссылка в новой задаче