Commit aa5e17e1 authored by James Chapman's avatar James Chapman Committed by David S. Miller

l2tp: store l2tpv3 sessions in per-net IDR

L2TPv3 sessions are currently held in one of two fixed-size hash
lists: either a per-net hashlist (IP-encap), or a per-tunnel hashlist
(UDP-encap), keyed by the L2TPv3 32-bit session_id.

In order to lookup L2TPv3 sessions in UDP-encap tunnels efficiently
without finding the tunnel first via sk_user_data, UDP sessions are
now kept in a per-net session list, keyed by session ID. Convert the
existing per-net hashlist to use an IDR for better performance when
there are many sessions and have L2TPv3 UDP sessions use the same IDR.

Although the L2TPv3 RFC states that the session ID alone identifies
the session, our implementation has allowed the same session ID to be
used in different L2TP UDP tunnels. To retain support for this, a new
per-net session hashtable is used, keyed by the sock and session
ID. If on creating a new session, a session already exists with that
ID in the IDR, the colliding sessions are added to the new hashtable
and the existing IDR entry is flagged. When looking up sessions, the
approach is to first check the IDR and if no unflagged match is found,
check the new hashtable. The sock is made available to session getters
where session ID collisions are to be considered. In this way, the new
hashtable is used only for session ID collisions so can be kept small.

For managing session removal, we need a list of colliding sessions
matching a given ID in order to update or remove the IDR entry of the
ID. This is necessary to detect session ID collisions when future
sessions are created. The list head is allocated on first collision
of a given ID and refcounted.
Signed-off-by: default avatarJames Chapman <jchapman@katalix.com>
Reviewed-by: default avatarTom Parkin <tparkin@katalix.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a744e2d0
This diff is collapsed.
...@@ -23,10 +23,6 @@ ...@@ -23,10 +23,6 @@
#define L2TP_HASH_BITS 4 #define L2TP_HASH_BITS 4
#define L2TP_HASH_SIZE BIT(L2TP_HASH_BITS) #define L2TP_HASH_SIZE BIT(L2TP_HASH_BITS)
/* System-wide session hash table size */
#define L2TP_HASH_BITS_2 8
#define L2TP_HASH_SIZE_2 BIT(L2TP_HASH_BITS_2)
struct sk_buff; struct sk_buff;
struct l2tp_stats { struct l2tp_stats {
...@@ -61,6 +57,12 @@ struct l2tp_session_cfg { ...@@ -61,6 +57,12 @@ struct l2tp_session_cfg {
char *ifname; char *ifname;
}; };
struct l2tp_session_coll_list {
spinlock_t lock; /* for access to list */
struct list_head list;
refcount_t ref_count;
};
/* Represents a session (pseudowire) instance. /* Represents a session (pseudowire) instance.
* Tracks runtime state including cookies, dataplane packet sequencing, and IO statistics. * Tracks runtime state including cookies, dataplane packet sequencing, and IO statistics.
* Is linked into a per-tunnel session hashlist; and in the case of an L2TPv3 session into * Is linked into a per-tunnel session hashlist; and in the case of an L2TPv3 session into
...@@ -88,8 +90,11 @@ struct l2tp_session { ...@@ -88,8 +90,11 @@ struct l2tp_session {
u32 nr_oos; /* NR of last OOS packet */ u32 nr_oos; /* NR of last OOS packet */
int nr_oos_count; /* for OOS recovery */ int nr_oos_count; /* for OOS recovery */
int nr_oos_count_max; int nr_oos_count_max;
struct hlist_node hlist; /* hash list node */
refcount_t ref_count; refcount_t ref_count;
struct hlist_node hlist; /* per-net session hlist */
unsigned long hlist_key; /* key for session hlist */
struct l2tp_session_coll_list *coll_list; /* session collision list */
struct list_head clist; /* for coll_list */
char name[L2TP_SESSION_NAME_MAX]; /* for logging */ char name[L2TP_SESSION_NAME_MAX]; /* for logging */
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
...@@ -102,7 +107,6 @@ struct l2tp_session { ...@@ -102,7 +107,6 @@ struct l2tp_session {
int reorder_skip; /* set if skip to next nr */ int reorder_skip; /* set if skip to next nr */
enum l2tp_pwtype pwtype; enum l2tp_pwtype pwtype;
struct l2tp_stats stats; struct l2tp_stats stats;
struct hlist_node global_hlist; /* global hash list node */
/* Session receive handler for data packets. /* Session receive handler for data packets.
* Each pseudowire implementation should implement this callback in order to * Each pseudowire implementation should implement this callback in order to
...@@ -226,7 +230,7 @@ struct l2tp_tunnel *l2tp_tunnel_get_nth(const struct net *net, int nth); ...@@ -226,7 +230,7 @@ struct l2tp_tunnel *l2tp_tunnel_get_nth(const struct net *net, int nth);
struct l2tp_session *l2tp_tunnel_get_session(struct l2tp_tunnel *tunnel, struct l2tp_session *l2tp_tunnel_get_session(struct l2tp_tunnel *tunnel,
u32 session_id); u32 session_id);
struct l2tp_session *l2tp_session_get(const struct net *net, u32 session_id); struct l2tp_session *l2tp_v3_session_get(const struct net *net, struct sock *sk, u32 session_id);
struct l2tp_session *l2tp_session_get_nth(struct l2tp_tunnel *tunnel, int nth); 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, struct l2tp_session *l2tp_session_get_by_ifname(const struct net *net,
const char *ifname); const char *ifname);
......
...@@ -140,7 +140,7 @@ static int l2tp_ip_recv(struct sk_buff *skb) ...@@ -140,7 +140,7 @@ static int l2tp_ip_recv(struct sk_buff *skb)
} }
/* Ok, this is a data packet. Lookup the session. */ /* Ok, this is a data packet. Lookup the session. */
session = l2tp_session_get(net, session_id); session = l2tp_v3_session_get(net, NULL, session_id);
if (!session) if (!session)
goto discard; goto discard;
......
...@@ -150,7 +150,7 @@ static int l2tp_ip6_recv(struct sk_buff *skb) ...@@ -150,7 +150,7 @@ static int l2tp_ip6_recv(struct sk_buff *skb)
} }
/* Ok, this is a data packet. Lookup the session. */ /* Ok, this is a data packet. Lookup the session. */
session = l2tp_session_get(net, session_id); session = l2tp_v3_session_get(net, NULL, session_id);
if (!session) if (!session)
goto discard; goto discard;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment