From patchwork Fri Dec 13 13:02:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13906994 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F2951E0081 for ; Fri, 13 Dec 2024 13:02:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734094942; cv=none; b=DOZbF/bJVdj+6FaRAiK5hlhDiHhMTf30LC9/mcfwDcSB9IiZsysoo5KTIU65YOOAaBPFf0hGrZ8qco3UuhVZEJZEl1PJnnK5SXo9yAiSA3gyOw184AIKRzptlvkqUFroiTn4csMkMBJxt2OiBNEBWZdIpdKpLnGssd5slUbQwPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734094942; c=relaxed/simple; bh=s3MI24GtlqQdp5wNS4PFx7F9BjHZqq3Vm25eZ/KSfcA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=g+eoOEBrYBv+oQePyXnPKL0UHTHlWR354K4RUqxU16nA9a/DahPOTevT541Fcm5gjX5vvUy5T3G1sExz2Ql+LksQL7ew9Zvz2NZPudGDuY2SyJiK/ffHoF+m8Mj4WKH2jHIcjYrx6d6IHj3Z3GZodZCE0r52jtf479VQYwIhQcY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QV0eFRUU; arc=none smtp.client-ip=209.85.219.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QV0eFRUU" Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-6d8edb40083so56234706d6.0 for ; Fri, 13 Dec 2024 05:02:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734094937; x=1734699737; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gxiE9o12jvQE0EhYg4DBIO0tfvhpWtc9/ACQybVd+3k=; b=QV0eFRUUdnKBUFWl1IGylWrb9M07LZ60edjpxSSWsJbinqu+mPddoFHdPwYeO5y95p SY7t92ymO9KEhthEjCcaVxfAnH2KiuIhbmgy5X1Ew5DpQIIcYq/J8oYpwWzMcoqP6zXG x450uVkhdqSMrYBdvf+BT4C2M/ZKYLaEdZ3iGIZwI6mY5bNMUIpuvfkpJi7vtM09aV+f Aw+FGzVrofcO41EsnkPJPENhoKXD/AzuQ9BI4rKP1djkkqvB9U5VxIkdcOXDfXKV5UuM n4QrKSj6z6GIb8ad3JxhJgyxMFanlv/KgzYpfLPogKgpXMWMYhgxypf1nM1J+n6UFn3O 5wvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734094937; x=1734699737; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gxiE9o12jvQE0EhYg4DBIO0tfvhpWtc9/ACQybVd+3k=; b=P0VoUVOQfUJy+mznBkgGJbdch6o2gyUMxYatiemNbxOFdr/pIn+Jea0z6d+FN2Lc/5 hib4WmQPtqV8J8kLnz6FpFfhMNeU/fSegBpCit8ZFJR1UkaAVD1tpSnx/dRVdOICOWB9 WP7dYNwJoz6HirlhQRKDuTr3lDPaYDDeTgnEO4ehplRRWwkWjoNFBW96w7XFgG0I1GZ9 UMafSUtjZAp3IgtRxohandKQ+XL+N3T4FZJg+olUI/sAmWnJyhrL7asXIvH3r/apTmsp 6KX5afFZED6K3lpxnIk637vDPBULvMXyhaXf5k+8UudQqTC4aUBw2cspuOIpUfXVAeoM rOsQ== X-Gm-Message-State: AOJu0YwS9HSW79gWRH1L71SERlR+LO6GvKzCnUZC/JXRm+aVt7ThexDE WPkrF9Rd1/irLUdvRWgREKaoVGAHw6uyGvc2mQYIDMkbjwa/uV0oosxRb7Pfn+tJ6LWGWGJRFw6 5q/qs4j2qJQ== X-Google-Smtp-Source: AGHT+IHmnov1Q8Nab5/AMD2rs5XW+BayrRvjm1HlW8ijRzQ4cXzEuy8OraRh8VaGmGX2XrNjM1Nn0+bOKcDMYg== X-Received: from qvab9.prod.google.com ([2002:a05:6214:6109:b0:6d8:9fb4:cdb9]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:ad4:5949:0:b0:6d9:15c3:42c9 with SMTP id 6a1803df08f44-6db0f3e0cadmr65467126d6.7.1734094937321; Fri, 13 Dec 2024 05:02:17 -0800 (PST) Date: Fri, 13 Dec 2024 13:02:09 +0000 In-Reply-To: <20241213130212.1783302-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213130212.1783302-1-edumazet@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241213130212.1783302-2-edumazet@google.com> Subject: [PATCH net-next 1/4] inetpeer: remove create argument of inet_getpeer_v[46]() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , David Ahern , Kuniyuki Iwashima , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org All callers of inet_getpeer_v4() and inet_getpeer_v6() want to create an inetpeer. Signed-off-by: Eric Dumazet --- include/net/inetpeer.h | 9 ++++----- net/ipv4/icmp.c | 2 +- net/ipv4/ip_fragment.c | 2 +- net/ipv4/route.c | 4 ++-- net/ipv6/icmp.c | 2 +- net/ipv6/ip6_output.c | 2 +- net/ipv6/ndisc.c | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h index 74ff688568a0c6559946a9ae763d5c9822f1d112..6f51f81d6cb19c623e9b347dbdbbd8d849848f6e 100644 --- a/include/net/inetpeer.h +++ b/include/net/inetpeer.h @@ -101,25 +101,24 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, static inline struct inet_peer *inet_getpeer_v4(struct inet_peer_base *base, __be32 v4daddr, - int vif, int create) + int vif) { struct inetpeer_addr daddr; daddr.a4.addr = v4daddr; daddr.a4.vif = vif; daddr.family = AF_INET; - return inet_getpeer(base, &daddr, create); + return inet_getpeer(base, &daddr, 1); } static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, - const struct in6_addr *v6daddr, - int create) + const struct in6_addr *v6daddr) { struct inetpeer_addr daddr; daddr.a6 = *v6daddr; daddr.family = AF_INET6; - return inet_getpeer(base, &daddr, create); + return inet_getpeer(base, &daddr, 1); } static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a, diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 963a89ae9c26e8b462de57e4af981c6c46061052..5eeb9f569a706cf2766d74bcf1a667c8930804f2 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -322,7 +322,7 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt, goto out; vif = l3mdev_master_ifindex(dst->dev); - peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, vif, 1); + peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, vif); rc = inet_peer_xrlim_allow(peer, READ_ONCE(net->ipv4.sysctl_icmp_ratelimit)); if (peer) diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 07036a2943c19f13f2d6d1d77cb8123867575b50..46e1171299f22ccf0b201eabbff5d3279a0703d8 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -89,7 +89,7 @@ static void ip4_frag_init(struct inet_frag_queue *q, const void *a) q->key.v4 = *key; qp->ecn = 0; qp->peer = q->fqdir->max_dist ? - inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif, 1) : + inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif) : NULL; } diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 0fbec350961862f76b7eab332539472fed5a5286..297a9939c6e74beffc592dbdd7266281fe842440 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -873,7 +873,7 @@ void ip_rt_send_redirect(struct sk_buff *skb) rcu_read_unlock(); net = dev_net(rt->dst.dev); - peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, vif, 1); + peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, vif); if (!peer) { icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, rt_nexthop(rt, ip_hdr(skb)->daddr)); @@ -976,7 +976,7 @@ static int ip_error(struct sk_buff *skb) } peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, - l3mdev_master_ifindex(skb->dev), 1); + l3mdev_master_ifindex(skb->dev)); send = true; if (peer) { diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index 071b0bc1179d81b18c340ce415cef21e02a30cd7..4593e3992c67b84e3a10f30be28762974094d21f 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -222,7 +222,7 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type, if (rt->rt6i_dst.plen < 128) tmo >>= ((128 - rt->rt6i_dst.plen)>>5); - peer = inet_getpeer_v6(net->ipv6.peers, &fl6->daddr, 1); + peer = inet_getpeer_v6(net->ipv6.peers, &fl6->daddr); res = inet_peer_xrlim_allow(peer, tmo); if (peer) inet_putpeer(peer); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 3d672dea9f56284e7a8ebabec037e04e7f3d19f4..2cbcfe70654b5cd90c433a24c47ef5496c604d0d 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -613,7 +613,7 @@ int ip6_forward(struct sk_buff *skb) else target = &hdr->daddr; - peer = inet_getpeer_v6(net->ipv6.peers, &hdr->daddr, 1); + peer = inet_getpeer_v6(net->ipv6.peers, &hdr->daddr); /* Limit redirects both by destination (here) and by source (inside ndisc_send_redirect) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index aba94a34867379000e958538d880799c2d0c1476..f113554d13325453cd04ce4e5686d837943e96ff 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1731,7 +1731,7 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) "Redirect: destination is not a neighbour\n"); goto release; } - peer = inet_getpeer_v6(net->ipv6.peers, &ipv6_hdr(skb)->saddr, 1); + peer = inet_getpeer_v6(net->ipv6.peers, &ipv6_hdr(skb)->saddr); ret = inet_peer_xrlim_allow(peer, 1*HZ); if (peer) inet_putpeer(peer); From patchwork Fri Dec 13 13:02:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13906993 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C583A1DFE39 for ; Fri, 13 Dec 2024 13:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734094941; cv=none; b=Pk93uZ7ccxj1+PCqscd6b2LA9i0wniDJ2yd/e55Kc3AIctd5BNzfAXB9X5+Dph2aFIJMmbGEw128pDu4RTL9Na/pIfTlU99LJ52loptAoW9defDTBzkvn6gyMA4sngpqYm9l+Yk9wPgS5QCbxXMP91fnncOfVQFb9jsmq49GPNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734094941; c=relaxed/simple; bh=mWG7wsebwSYYcIqh15+S7wil7C3IoKbNrM+dfseE5nA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=liBZcc747EBErwNXCx0IwDUDy1cNjRkLnhcZIqsigjvqZ3exsYMhblLOlPsiKyPKBzFk4xuNo5hQC77vNLxcFabKbq+J8SamosqyoZpCVsiA7CWX5mDIlzZjuQhJ8QTEG18sJMvnvinVOJuL4s0BtaE7T7CANjWshy+lvYidYJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=E/4sZRFl; arc=none smtp.client-ip=209.85.160.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="E/4sZRFl" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-467944446a0so31151441cf.1 for ; Fri, 13 Dec 2024 05:02:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734094939; x=1734699739; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+3ZcHiGrMQ0qikxpAt1j1kpn8wlaFfz3JKlP8c3UDe8=; b=E/4sZRFlLVJBoqZfl8F2220dqNB5vnv1bF6XBS5rx/kQ/4iptR5/lKlpHY8SAkeyUC LDEq7n6yA+NsuMdQaMuazZvMxRc1hpVkT4258PBJSFmvDeb+U7emW8crTZdAcZHjcLRB BGkVS/n9MrZiXfVMhuIt0IH3CS9y3Q4dTCmEEZTFsaXicGbem+bZgaW7zm+JSnXmMF5a cImgXxPGDMe0kGbaNwefSx/jSSKSnxHdwnMmeUqSI7plE/4CWKcyzIHUM6KYHE/ZfnPd gfeLYe/V+6bybrw/BVn4G+Jxhz8fHyCjhv9BzzC9hUjrV7VeJkhMPwGkfUGRRK9C9B6I VGrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734094939; x=1734699739; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+3ZcHiGrMQ0qikxpAt1j1kpn8wlaFfz3JKlP8c3UDe8=; b=Qgx+b8OLlqhdOflQF0elv7PU2JTiGr15DBNioT2UDGbZ0bEgqfTUbuKmrhkHES6mV9 DiG1l54e/PfWrfVHIoTg8emuX7R0EzeWqBg21/gJF5I0H6w2NCctVn0XtmW+35sSoEZt Lm0ZdAHmv3Ju9fLX3I+O4Dvbg4dzB/8z1ueWUa7bDmumoQkE5bmnv7ez/Ocahm/gLL9k OQBk9E919q5cpC6wBmbkqfd0I/Tkpy/j0ZaYFpfSuQoDUF4KvrqTpZO+6As6dgLDguGV 0KnS4P67/jyobLMNR/Z7BsScuc+ykQYtyanAM3FajfWJADbUnd8ZtCVTGZVXaSjgbKkd VRgQ== X-Gm-Message-State: AOJu0YxyKuP5R1EgBHqmwmBgcNZA+6k18j7r7Aemqsl3H3ALaD7QpdNO GxfYPYK6miIhPi8sS4prztnte301RJTHxaj6OxokHTUFBdiXSdWS31KTc84NtMRzb9QggBtPo8o OolCag8laYQ== X-Google-Smtp-Source: AGHT+IF5Ft0ySfZj0pWAtikyzIfYWmMCmSd5cixmCjDz8fyO7mWujWDBMtX8HQQpdg38gwlbwsm/BaOdOeWzHg== X-Received: from qtbbs15.prod.google.com ([2002:ac8:6f0f:0:b0:467:6227:451b]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:13d2:b0:467:84a7:5147 with SMTP id d75a77b69052e-467a5807dfdmr63435711cf.39.1734094938610; Fri, 13 Dec 2024 05:02:18 -0800 (PST) Date: Fri, 13 Dec 2024 13:02:10 +0000 In-Reply-To: <20241213130212.1783302-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213130212.1783302-1-edumazet@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241213130212.1783302-3-edumazet@google.com> Subject: [PATCH net-next 2/4] inetpeer: remove create argument of inet_getpeer() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , David Ahern , Kuniyuki Iwashima , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org All callers of inet_getpeer() want to create an inetpeer. Signed-off-by: Eric Dumazet --- include/net/inetpeer.h | 7 +++---- net/ipv4/inetpeer.c | 9 ++------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h index 6f51f81d6cb19c623e9b347dbdbbd8d849848f6e..f475757daafba998a10c815d0178c98d2bf1ae43 100644 --- a/include/net/inetpeer.h +++ b/include/net/inetpeer.h @@ -96,8 +96,7 @@ static inline struct in6_addr *inetpeer_get_addr_v6(struct inetpeer_addr *iaddr) /* can be called with or without local BH being disabled */ struct inet_peer *inet_getpeer(struct inet_peer_base *base, - const struct inetpeer_addr *daddr, - int create); + const struct inetpeer_addr *daddr); static inline struct inet_peer *inet_getpeer_v4(struct inet_peer_base *base, __be32 v4daddr, @@ -108,7 +107,7 @@ static inline struct inet_peer *inet_getpeer_v4(struct inet_peer_base *base, daddr.a4.addr = v4daddr; daddr.a4.vif = vif; daddr.family = AF_INET; - return inet_getpeer(base, &daddr, 1); + return inet_getpeer(base, &daddr); } static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, @@ -118,7 +117,7 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, daddr.a6 = *v6daddr; daddr.family = AF_INET6; - return inet_getpeer(base, &daddr, 1); + return inet_getpeer(base, &daddr); } static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a, diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index 5ab56f4cb529769d4edb07261c08d61ff96f0c0f..58d2805b046d00cd509e2d2343abfb8eacfbdde7 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -169,8 +169,7 @@ static void inet_peer_gc(struct inet_peer_base *base, } struct inet_peer *inet_getpeer(struct inet_peer_base *base, - const struct inetpeer_addr *daddr, - int create) + const struct inetpeer_addr *daddr) { struct inet_peer *p, *gc_stack[PEER_MAX_GC]; struct rb_node **pp, *parent; @@ -189,10 +188,6 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, if (p) return p; - /* If no writer did a change during our lookup, we can return early. */ - if (!create && !invalidated) - return NULL; - /* retry an exact lookup, taking the lock before. * At least, nodes should be hot in our cache. */ @@ -201,7 +196,7 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, gc_cnt = 0; p = lookup(daddr, base, seq, gc_stack, &gc_cnt, &parent, &pp); - if (!p && create) { + if (!p) { p = kmem_cache_alloc(peer_cachep, GFP_ATOMIC); if (p) { p->daddr = *daddr; From patchwork Fri Dec 13 13:02:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13906995 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26A981E00B4 for ; Fri, 13 Dec 2024 13:02:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734094943; cv=none; b=oE3k38zF4hXGLvAlYM/hmx/BWyc6ikGJ39B23q+87gAg7zyOk794D1+EEFd6D/yDtQRiWdt76+0vqny9wCcjqVxs+MxeQBu/rJMSZ2JAV8k0ui0nZjVy6J1qNLeelB5B26HZv6SzqIT6Um4XBfm3QPRLuZ2iaqvCl+bvPU06dIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734094943; c=relaxed/simple; bh=VWA96KoCajBnO8Bt9UhYsE6DvMaR8N7eLH58EmxQ9IQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jUgAkATq61sHmdHH2qXS7xHe87itXu1ZsYwIa8O9089AJLHBYXo4VbQbpbwd2HbJfjJwPmyDB/0nUS+8uWYibupsIX/IFKkj2K/gcPHs7XeoUYlkNxvDpSSDGHQgKPnnnd1HpCS6nQOu12bGIjGNFRBGinOjT80LKMQ/1ERf5Do= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QhaGOmlP; arc=none smtp.client-ip=209.85.160.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QhaGOmlP" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-4679becb47eso42072741cf.3 for ; Fri, 13 Dec 2024 05:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734094940; x=1734699740; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=uCFGl37tvk0Dx0wNhWAaFFkdhedhB8ygdRsgH6x2Q6Q=; b=QhaGOmlPsjIbfVMCj6dVG+kjVLhrGpvPWsooYDzFvKsacb7YtiIpicldgFxTFfCwX/ /g8+iER3AOFlkUvzlVAwTAAS4+gvIAUumCG0FrKpegWSvSyvvo8CcapnFDFdSzskaLKb sWTUP8Hgb6VabhduRwqnXUuIydvaPiTZSqcJzpJziMV+Fe1wv4OV5GW5CViGquUw3upo UiHlTITM2bsPI6ODnTSKtwB90eHWX+6uY+PkiHOBckEJgPwoFW0HaV9GIqD3Hg6ota75 2gR0dYWUo12BZOvfYo2D3mZiDneNTyVNlS+7aZ6pwIoDTZqjs4xhEwV2boMl/6GAQLWw 1wLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734094940; x=1734699740; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uCFGl37tvk0Dx0wNhWAaFFkdhedhB8ygdRsgH6x2Q6Q=; b=Pnjos7Q6viLAamrQmEVbCuCKK3tovP+vNfJv3xRyBk7A0shKwkeSx1kBWeOO1vF5kk lpkHxYltNwf9OaZAUbpAV8WC5hoLTFTUbWdt45bslA4ECakaD1o/TWJJD4j2yN1m2EV6 xT2bI1F4bwfAo2y3wMTyOso4ru3XSkxp7Tdd4Kgp+3lbpAu2PRNuwvgZ8EcavGvKyriQ BsGeB9ZMY8YB8Hgq/iEfrfBJGebXGQMUqdrjwLOz0XorLzvOnKQ5XK4yRvxfNH7hixsl u0MXoY8Z9BV1SWHfQdu8klBI4CpHlFf+sX72IcXgYUIOr18S/DACAWx4oiOa4leLIIwS Sqmw== X-Gm-Message-State: AOJu0YwqSzgpyHsIZFJWEHGutQx8oWyTNzLGqQvJ6nBMgvdTNewQkFp0 INj+gps9pNthsPAHrPGhDQmavbQaL0w7xtQl7Y0GFuMeHSz2PuuK44eDj13kmpzt0CRAeJq+27x t+8CkjAbKwQ== X-Google-Smtp-Source: AGHT+IFlXSNuiZIFYarNNwywlgQ1/d8IhHK+Cr4ktZZ3zrpQQADSgjTvYzYhHJxbQilhGDXFNLrXyaP3WxtoDA== X-Received: from qtbgb4.prod.google.com ([2002:a05:622a:5984:b0:466:928b:3b7c]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:4c8:b0:467:5836:a9b with SMTP id d75a77b69052e-467a5757da7mr47529261cf.15.1734094940025; Fri, 13 Dec 2024 05:02:20 -0800 (PST) Date: Fri, 13 Dec 2024 13:02:11 +0000 In-Reply-To: <20241213130212.1783302-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213130212.1783302-1-edumazet@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241213130212.1783302-4-edumazet@google.com> Subject: [PATCH net-next 3/4] inetpeer: update inetpeer timestamp in inet_getpeer() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , David Ahern , Kuniyuki Iwashima , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org inet_putpeer() will be removed in the following patch, because we will no longer use refcounts. Update inetpeer timetamp (p->dtime) at lookup time. Signed-off-by: Eric Dumazet --- net/ipv4/inetpeer.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index 58d2805b046d00cd509e2d2343abfb8eacfbdde7..67827c9bf2c8f3ba842ff1dc3b7e1fc2976e6ef1 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -95,6 +95,7 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr, { struct rb_node **pp, *parent, *next; struct inet_peer *p; + u32 now; pp = &base->rb_root.rb_node; parent = NULL; @@ -110,6 +111,9 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr, if (cmp == 0) { if (!refcount_inc_not_zero(&p->refcnt)) break; + now = jiffies; + if (READ_ONCE(p->dtime) != now) + WRITE_ONCE(p->dtime, now); return p; } if (gc_stack) { @@ -150,9 +154,6 @@ static void inet_peer_gc(struct inet_peer_base *base, for (i = 0; i < gc_cnt; i++) { p = gc_stack[i]; - /* The READ_ONCE() pairs with the WRITE_ONCE() - * in inet_putpeer() - */ delta = (__u32)jiffies - READ_ONCE(p->dtime); if (delta < ttl || !refcount_dec_if_one(&p->refcnt)) @@ -226,11 +227,6 @@ EXPORT_SYMBOL_GPL(inet_getpeer); void inet_putpeer(struct inet_peer *p) { - /* The WRITE_ONCE() pairs with itself (we run lockless) - * and the READ_ONCE() in inet_peer_gc() - */ - WRITE_ONCE(p->dtime, (__u32)jiffies); - if (refcount_dec_and_test(&p->refcnt)) kfree_rcu(p, rcu); } From patchwork Fri Dec 13 13:02:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13906996 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F38B1E048F for ; Fri, 13 Dec 2024 13:02:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734094944; cv=none; b=PaVeGPWLPdVr4MQX+AbwgpnhrcCVMpCxyvRWxVAVmozp6rJA/0X6ER3+ckwEdy6NjUPD3JtXMrGRfoafVuzB/vAicp8YIB4RWyosoTmkrMYWcTcW7oYcJ0U7dN84DlxFQwZS0EczgTF5GDx0aLpK/EZmPswQyauaHnxF7ausFoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734094944; c=relaxed/simple; bh=81qm+vACZPmWQqJRBWC75bkQgpMO9+63vWCxZtEAZmA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oGYzhw1if2aX6Kaj9VfpukkNofEKRBxEVFuhW+Koq6cdhIMcQjYhAMxNbFCajYCl08eun0MRGUwlHd2QvGPtTP05DrEp/QJthERtoPOkq+lhK+Tu3OCvo1TGEaIvdi2bo8yUTkkBAhTlM4V+/J0+ZB5PVN+hae9pO7as70kD6Yo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GeWDe/0x; arc=none smtp.client-ip=209.85.160.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GeWDe/0x" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-46686a1565bso38182711cf.0 for ; Fri, 13 Dec 2024 05:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734094941; x=1734699741; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dLyiExgbr99lB8vBG1tJUskBis7BB25OpVEzzbb6MxA=; b=GeWDe/0xn7aXVjmESSusEqsnA7/8YCCzr6+Z2RbDXXcyC9Pril7POfiIEQidlhqBGn QoQ82lwSuOfJQX49HonfXkK1+HkRQOH3qc0VofxmA0rfUOixeSPYT6NsymKwn38Xc664 m9maqDtZ83TGCOpf8vBFXoq5nPYvNuKddgsUazCyShMb4LgcKc9hY+J/iFDkYjW9CiJa k57x9lQRQqzb/JV13qwId+/v/nxqzkYY3EEl+NdWWzLgNJtUTPKP5ot3mk2xV4leDd/V MwneetqvCBfyij55Q1aO/dntH5RqUNVe54f+Hheco+Bel2PQTzxULiTdwNuVC2w+Pcf8 gWFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734094941; x=1734699741; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dLyiExgbr99lB8vBG1tJUskBis7BB25OpVEzzbb6MxA=; b=qp7OsOt4hu7WQifi37/gXpk7NUWuZ+UCWpCJhmgM5GNvNfxUSJAtq4tPZwxttybd7u VG3Vq2FTXQCEiTScQtXOENj0Itl6/cNHSbIDio2XNr2d48xfK+HDBiMLEYiZhy3D8AUn 9HS29CC5xOkXCyb/SbjhWvFxq6KJ9cjmkhbwEhJWeXhrRz9BJFyOvkdgK9BDrVXVDyIx Nl+ht65+lEuS0smMNq1KA9mktKa9zgRWCSHXgKLKq9S1DeXKRf+1M3rJbWnc68m3E7EW yhDiPf4Gxp2E16hJFBTpv7eBj2FTX+03J4FoqimLZ/25nFtdE96e6JzYeAFCOHxeNVjS p3ZQ== X-Gm-Message-State: AOJu0YxB/9DEXTLLA9DcwoxK6bG8w8iHva4sXEkdI+lKdPqwFqSs7TAW AFYYxUtrUxhpFfw9XYPIFAu6KAGDj3UAjFNXEzFULnHoygOnU5XWg/ITGiCh2ltazK7t48xr4FT p8GgHolUcyQ== X-Google-Smtp-Source: AGHT+IF22Xel41WYPlRCSta3J5yOmGybKDWWA5UmdBCpC3I4/kI3FTyGT31CCshOkTQubl1T/ZRdX+dh6yl9mg== X-Received: from qtbfe8.prod.google.com ([2002:a05:622a:4d48:b0:466:9f81:8c8c]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:c1:b0:466:8f68:a606 with SMTP id d75a77b69052e-467a581d9c9mr48510061cf.40.1734094941474; Fri, 13 Dec 2024 05:02:21 -0800 (PST) Date: Fri, 13 Dec 2024 13:02:12 +0000 In-Reply-To: <20241213130212.1783302-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213130212.1783302-1-edumazet@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241213130212.1783302-5-edumazet@google.com> Subject: [PATCH net-next 4/4] inetpeer: do not get a refcount in inet_getpeer() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , David Ahern , Kuniyuki Iwashima , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org All inet_getpeer() callers except ip4_frag_init() don't need to acquire a permanent refcount on the inetpeer. They can switch to full RCU protection. Move the refcount_inc_not_zero() into ip4_frag_init(), so that all the other callers no longer have to perform a pair of expensive atomic operations on a possibly contended cache line. inet_putpeer() no longer needs to be exported. After this patch, my DUT can receive 8,400,000 UDP packets per second targetting closed ports, using 50% cpu cycles less than before. Fixes: 8c2bd38b95f7 ("icmp: change the order of rate limits") Signed-off-by: Eric Dumazet --- net/ipv4/icmp.c | 4 ++-- net/ipv4/inetpeer.c | 8 ++------ net/ipv4/ip_fragment.c | 15 ++++++++++----- net/ipv4/route.c | 13 +++++++------ net/ipv6/icmp.c | 4 ++-- net/ipv6/ip6_output.c | 4 ++-- net/ipv6/ndisc.c | 6 ++++-- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 5eeb9f569a706cf2766d74bcf1a667c8930804f2..7a1b1af2edcae0b0648ef3c3411b4ef36e6d9b14 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -322,11 +322,11 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt, goto out; vif = l3mdev_master_ifindex(dst->dev); + rcu_read_lock(); peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, vif); rc = inet_peer_xrlim_allow(peer, READ_ONCE(net->ipv4.sysctl_icmp_ratelimit)); - if (peer) - inet_putpeer(peer); + rcu_read_unlock(); out: if (!rc) __ICMP_INC_STATS(net, ICMP_MIB_RATELIMITHOST); diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index 67827c9bf2c8f3ba842ff1dc3b7e1fc2976e6ef1..b025eaba501305635ae46672ff3c7de75c4fcc08 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -109,8 +109,6 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr, p = rb_entry(parent, struct inet_peer, rb_node); cmp = inetpeer_addr_cmp(daddr, &p->daddr); if (cmp == 0) { - if (!refcount_inc_not_zero(&p->refcnt)) - break; now = jiffies; if (READ_ONCE(p->dtime) != now) WRITE_ONCE(p->dtime, now); @@ -169,6 +167,7 @@ static void inet_peer_gc(struct inet_peer_base *base, } } +/* Must be called under RCU : No refcount change is done here. */ struct inet_peer *inet_getpeer(struct inet_peer_base *base, const struct inetpeer_addr *daddr) { @@ -180,11 +179,9 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, /* Attempt a lockless lookup first. * Because of a concurrent writer, we might not find an existing entry. */ - rcu_read_lock(); seq = read_seqbegin(&base->lock); p = lookup(daddr, base, seq, NULL, &gc_cnt, &parent, &pp); invalidated = read_seqretry(&base->lock, seq); - rcu_read_unlock(); if (p) return p; @@ -202,7 +199,7 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base, if (p) { p->daddr = *daddr; p->dtime = (__u32)jiffies; - refcount_set(&p->refcnt, 2); + refcount_set(&p->refcnt, 1); atomic_set(&p->rid, 0); p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW; p->rate_tokens = 0; @@ -230,7 +227,6 @@ void inet_putpeer(struct inet_peer *p) if (refcount_dec_and_test(&p->refcnt)) kfree_rcu(p, rcu); } -EXPORT_SYMBOL_GPL(inet_putpeer); /* * Check transmit rate limitation for given message. diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 46e1171299f22ccf0b201eabbff5d3279a0703d8..7a435746a22dee9f11c0dc732a8b5a7724f4eea3 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -82,15 +82,20 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *skb, static void ip4_frag_init(struct inet_frag_queue *q, const void *a) { struct ipq *qp = container_of(q, struct ipq, q); - struct net *net = q->fqdir->net; - const struct frag_v4_compare_key *key = a; + struct net *net = q->fqdir->net; + struct inet_peer *p = NULL; q->key.v4 = *key; qp->ecn = 0; - qp->peer = q->fqdir->max_dist ? - inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif) : - NULL; + if (q->fqdir->max_dist) { + rcu_read_lock(); + p = inet_getpeer_v4(net->ipv4.peers, key->saddr, key->vif); + if (p && !refcount_inc_not_zero(&p->refcnt)) + p = NULL; + rcu_read_unlock(); + } + qp->peer = p; } static void ip4_frag_free(struct inet_frag_queue *q) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 297a9939c6e74beffc592dbdd7266281fe842440..d2086648dcf180375c8d7981dfb72f87e50957f6 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -870,11 +870,11 @@ void ip_rt_send_redirect(struct sk_buff *skb) } log_martians = IN_DEV_LOG_MARTIANS(in_dev); vif = l3mdev_master_ifindex_rcu(rt->dst.dev); - rcu_read_unlock(); net = dev_net(rt->dst.dev); peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, vif); if (!peer) { + rcu_read_unlock(); icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, rt_nexthop(rt, ip_hdr(skb)->daddr)); return; @@ -893,7 +893,7 @@ void ip_rt_send_redirect(struct sk_buff *skb) */ if (peer->n_redirects >= ip_rt_redirect_number) { peer->rate_last = jiffies; - goto out_put_peer; + goto out_unlock; } /* Check for load limit; set rate_last to the latest sent @@ -914,8 +914,8 @@ void ip_rt_send_redirect(struct sk_buff *skb) &ip_hdr(skb)->saddr, inet_iif(skb), &ip_hdr(skb)->daddr, &gw); } -out_put_peer: - inet_putpeer(peer); +out_unlock: + rcu_read_unlock(); } static int ip_error(struct sk_buff *skb) @@ -975,9 +975,9 @@ static int ip_error(struct sk_buff *skb) break; } + rcu_read_lock(); peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, l3mdev_master_ifindex(skb->dev)); - send = true; if (peer) { now = jiffies; @@ -989,8 +989,9 @@ static int ip_error(struct sk_buff *skb) peer->rate_tokens -= ip_rt_error_cost; else send = false; - inet_putpeer(peer); } + rcu_read_unlock(); + if (send) icmp_send(skb, ICMP_DEST_UNREACH, code, 0); diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index 4593e3992c67b84e3a10f30be28762974094d21f..a6984a29fdb9dd972a11ca9f8d5e794c443bac6f 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -222,10 +222,10 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type, if (rt->rt6i_dst.plen < 128) tmo >>= ((128 - rt->rt6i_dst.plen)>>5); + rcu_read_lock(); peer = inet_getpeer_v6(net->ipv6.peers, &fl6->daddr); res = inet_peer_xrlim_allow(peer, tmo); - if (peer) - inet_putpeer(peer); + rcu_read_unlock(); } if (!res) __ICMP6_INC_STATS(net, ip6_dst_idev(dst), diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 2cbcfe70654b5cd90c433a24c47ef5496c604d0d..06cab008b8277f1b6e56541e91fc92f999221ac5 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -613,6 +613,7 @@ int ip6_forward(struct sk_buff *skb) else target = &hdr->daddr; + rcu_read_lock(); peer = inet_getpeer_v6(net->ipv6.peers, &hdr->daddr); /* Limit redirects both by destination (here) @@ -620,8 +621,7 @@ int ip6_forward(struct sk_buff *skb) */ if (inet_peer_xrlim_allow(peer, 1*HZ)) ndisc_send_redirect(skb, target); - if (peer) - inet_putpeer(peer); + rcu_read_unlock(); } else { int addrtype = ipv6_addr_type(&hdr->saddr); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index f113554d13325453cd04ce4e5686d837943e96ff..d044c67019de6da1eb29dee875cf8cda30210ceb 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1731,10 +1731,12 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) "Redirect: destination is not a neighbour\n"); goto release; } + + rcu_read_lock(); peer = inet_getpeer_v6(net->ipv6.peers, &ipv6_hdr(skb)->saddr); ret = inet_peer_xrlim_allow(peer, 1*HZ); - if (peer) - inet_putpeer(peer); + rcu_read_unlock(); + if (!ret) goto release;