l2tp: define l2tp_tunnel_dst_mtu()
Consolidate retrieval of tunnel's socket mtu in order to simplify l2tp_eth and l2tp_ppp a bit. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
f3184645cb
commit
1f5cd2a010
|
@ -12,6 +12,9 @@
|
|||
#ifndef _L2TP_CORE_H_
|
||||
#define _L2TP_CORE_H_
|
||||
|
||||
#include <net/dst.h>
|
||||
#include <net/sock.h>
|
||||
|
||||
/* Just some random numbers */
|
||||
#define L2TP_TUNNEL_MAGIC 0x42114DDA
|
||||
#define L2TP_SESSION_MAGIC 0x0C04EB7D
|
||||
|
@ -268,6 +271,21 @@ static inline int l2tp_get_l2specific_len(struct l2tp_session *session)
|
|||
}
|
||||
}
|
||||
|
||||
static inline u32 l2tp_tunnel_dst_mtu(const struct l2tp_tunnel *tunnel)
|
||||
{
|
||||
struct dst_entry *dst;
|
||||
u32 mtu;
|
||||
|
||||
dst = sk_dst_get(tunnel->sock);
|
||||
if (!dst)
|
||||
return 0;
|
||||
|
||||
mtu = dst_mtu(dst);
|
||||
dst_release(dst);
|
||||
|
||||
return mtu;
|
||||
}
|
||||
|
||||
#define l2tp_printk(ptr, type, func, fmt, ...) \
|
||||
do { \
|
||||
if (((ptr)->debug) & (type)) \
|
||||
|
|
|
@ -226,8 +226,8 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel,
|
|||
struct net_device *dev)
|
||||
{
|
||||
unsigned int overhead = 0;
|
||||
struct dst_entry *dst;
|
||||
u32 l3_overhead = 0;
|
||||
u32 mtu;
|
||||
|
||||
/* if the encap is UDP, account for UDP header size */
|
||||
if (tunnel->encap == L2TP_ENCAPTYPE_UDP) {
|
||||
|
@ -256,15 +256,9 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel,
|
|||
overhead += session->hdr_len + ETH_HLEN + l3_overhead;
|
||||
|
||||
/* If PMTU discovery was enabled, use discovered MTU on L2TP device */
|
||||
dst = sk_dst_get(tunnel->sock);
|
||||
if (dst) {
|
||||
/* dst_mtu will use PMTU if found, else fallback to intf MTU */
|
||||
u32 pmtu = dst_mtu(dst);
|
||||
|
||||
if (pmtu != 0)
|
||||
dev->mtu = pmtu;
|
||||
dst_release(dst);
|
||||
}
|
||||
mtu = l2tp_tunnel_dst_mtu(tunnel);
|
||||
if (mtu)
|
||||
dev->mtu = mtu;
|
||||
session->mtu = dev->mtu - overhead;
|
||||
dev->mtu = session->mtu;
|
||||
dev->needed_headroom += session->hdr_len;
|
||||
|
|
|
@ -93,7 +93,6 @@
|
|||
#include <linux/nsproxy.h>
|
||||
#include <net/net_namespace.h>
|
||||
#include <net/netns/generic.h>
|
||||
#include <net/dst.h>
|
||||
#include <net/ip.h>
|
||||
#include <net/udp.h>
|
||||
#include <net/xfrm.h>
|
||||
|
@ -554,7 +553,7 @@ static void pppol2tp_show(struct seq_file *m, void *arg)
|
|||
static void pppol2tp_session_init(struct l2tp_session *session)
|
||||
{
|
||||
struct pppol2tp_session *ps;
|
||||
struct dst_entry *dst;
|
||||
u32 mtu;
|
||||
|
||||
session->recv_skb = pppol2tp_recv;
|
||||
#if IS_ENABLED(CONFIG_L2TP_DEBUGFS)
|
||||
|
@ -566,15 +565,9 @@ static void pppol2tp_session_init(struct l2tp_session *session)
|
|||
ps->owner = current->pid;
|
||||
|
||||
/* If PMTU discovery was enabled, use the MTU that was discovered */
|
||||
dst = sk_dst_get(session->tunnel->sock);
|
||||
if (dst) {
|
||||
u32 pmtu = dst_mtu(dst);
|
||||
|
||||
if (pmtu)
|
||||
session->mtu = pmtu - PPPOL2TP_HEADER_OVERHEAD;
|
||||
|
||||
dst_release(dst);
|
||||
}
|
||||
mtu = l2tp_tunnel_dst_mtu(session->tunnel);
|
||||
if (mtu)
|
||||
session->mtu = mtu - PPPOL2TP_HEADER_OVERHEAD;
|
||||
}
|
||||
|
||||
struct l2tp_connect_info {
|
||||
|
|
Loading…
Reference in New Issue