]> www.infradead.org Git - users/hch/configfs.git/commitdiff
l2tp: use IDR for all session lookups
authorJames Chapman <jchapman@katalix.com>
Thu, 20 Jun 2024 11:22:42 +0000 (12:22 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 21 Jun 2024 10:33:34 +0000 (11:33 +0100)
Add generic session getter which uses IDR. Replace all users of
l2tp_tunnel_get_session which uses the per-tunnel session list to use
the generic getter.

Signed-off-by: James Chapman <jchapman@katalix.com>
Reviewed-by: Tom Parkin <tparkin@katalix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/l2tp/l2tp_core.c
net/l2tp/l2tp_core.h
net/l2tp/l2tp_netlink.c
net/l2tp/l2tp_ppp.c

index cbc5de1373cd7c5316b9e945d7dd94b2ea47bb19..0e826a0260feeae5e316e0feaa000e83b5727927 100644 (file)
@@ -316,6 +316,16 @@ struct l2tp_session *l2tp_v2_session_get(const struct net *net, u16 tunnel_id, u
 }
 EXPORT_SYMBOL_GPL(l2tp_v2_session_get);
 
+struct l2tp_session *l2tp_session_get(const struct net *net, struct sock *sk, int pver,
+                                     u32 tunnel_id, u32 session_id)
+{
+       if (pver == L2TP_HDR_VER_2)
+               return l2tp_v2_session_get(net, tunnel_id, session_id);
+       else
+               return l2tp_v3_session_get(net, sk, session_id);
+}
+EXPORT_SYMBOL_GPL(l2tp_session_get);
+
 struct l2tp_session *l2tp_session_get_nth(struct l2tp_tunnel *tunnel, int nth)
 {
        int hash;
index d80f15f5b9fc7ce6e4bbf502a1cbb1381b43c638..0e7c9b0bcc1ed5fe14cb48cb26fe57f12e532921 100644 (file)
@@ -232,6 +232,8 @@ struct l2tp_session *l2tp_tunnel_get_session(struct l2tp_tunnel *tunnel,
 
 struct l2tp_session *l2tp_v3_session_get(const struct net *net, struct sock *sk, u32 session_id);
 struct l2tp_session *l2tp_v2_session_get(const struct net *net, u16 tunnel_id, u16 session_id);
+struct l2tp_session *l2tp_session_get(const struct net *net, struct sock *sk, int pver,
+                                     u32 tunnel_id, u32 session_id);
 struct l2tp_session *l2tp_session_get_nth(struct l2tp_tunnel *tunnel, int nth);
 struct l2tp_session *l2tp_session_get_by_ifname(const struct net *net,
                                                const char *ifname);
index a901fd14fe3bfe320951475f5f8a0880c3bdf865..d105030520f9541022d8ccb6af6f0b7887a59e45 100644 (file)
@@ -61,7 +61,8 @@ static struct l2tp_session *l2tp_nl_session_get(struct genl_info *info)
                session_id = nla_get_u32(info->attrs[L2TP_ATTR_SESSION_ID]);
                tunnel = l2tp_tunnel_get(net, tunnel_id);
                if (tunnel) {
-                       session = l2tp_tunnel_get_session(tunnel, session_id);
+                       session = l2tp_session_get(net, tunnel->sock, tunnel->version,
+                                                  tunnel_id, session_id);
                        l2tp_tunnel_dec_refcount(tunnel);
                }
        }
@@ -635,7 +636,8 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf
                                                           &cfg);
 
        if (ret >= 0) {
-               session = l2tp_tunnel_get_session(tunnel, session_id);
+               session = l2tp_session_get(net, tunnel->sock, tunnel->version,
+                                          tunnel_id, session_id);
                if (session) {
                        ret = l2tp_session_notify(&l2tp_nl_family, info, session,
                                                  L2TP_CMD_SESSION_CREATE);
index 6146e4e67bbb5438ebe9eb0046b1e5dbfce6f7ca..3596290047b28e65e56eec0a511e0a1263ec44c9 100644 (file)
@@ -753,7 +753,8 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
        if (tunnel->peer_tunnel_id == 0)
                tunnel->peer_tunnel_id = info.peer_tunnel_id;
 
-       session = l2tp_tunnel_get_session(tunnel, info.session_id);
+       session = l2tp_session_get(sock_net(sk), tunnel->sock, tunnel->version,
+                                  info.tunnel_id, info.session_id);
        if (session) {
                drop_refcnt = true;
 
@@ -1045,7 +1046,8 @@ static int pppol2tp_tunnel_copy_stats(struct pppol2tp_ioc_stats *stats,
        /* If session_id is set, search the corresponding session in the
         * context of this tunnel and record the session's statistics.
         */
-       session = l2tp_tunnel_get_session(tunnel, stats->session_id);
+       session = l2tp_session_get(tunnel->l2tp_net, tunnel->sock, tunnel->version,
+                                  tunnel->tunnel_id, stats->session_id);
        if (!session)
                return -EBADR;