diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2018-08-03 06:38:34 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-08-03 13:03:57 -0400 |
commit | 1f5cd2a0107d4ed95cbd9118e6a5f7ccd3d4d12a (patch) | |
tree | 1ee06be60cafbb3e7c7df779677842c976d5716d /net/l2tp | |
parent | f3184645cb0409d4ab0e63d65a0adcb565f55df4 (diff) |
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>
Diffstat (limited to 'net/l2tp')
-rw-r--r-- | net/l2tp/l2tp_core.h | 18 | ||||
-rw-r--r-- | net/l2tp/l2tp_eth.c | 14 | ||||
-rw-r--r-- | net/l2tp/l2tp_ppp.c | 15 |
3 files changed, 26 insertions, 21 deletions
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h index fa5ae9432d38..1ca39629031b 100644 --- a/net/l2tp/l2tp_core.h +++ b/net/l2tp/l2tp_core.h | |||
@@ -12,6 +12,9 @@ | |||
12 | #ifndef _L2TP_CORE_H_ | 12 | #ifndef _L2TP_CORE_H_ |
13 | #define _L2TP_CORE_H_ | 13 | #define _L2TP_CORE_H_ |
14 | 14 | ||
15 | #include <net/dst.h> | ||
16 | #include <net/sock.h> | ||
17 | |||
15 | /* Just some random numbers */ | 18 | /* Just some random numbers */ |
16 | #define L2TP_TUNNEL_MAGIC 0x42114DDA | 19 | #define L2TP_TUNNEL_MAGIC 0x42114DDA |
17 | #define L2TP_SESSION_MAGIC 0x0C04EB7D | 20 | #define L2TP_SESSION_MAGIC 0x0C04EB7D |
@@ -268,6 +271,21 @@ static inline int l2tp_get_l2specific_len(struct l2tp_session *session) | |||
268 | } | 271 | } |
269 | } | 272 | } |
270 | 273 | ||
274 | static inline u32 l2tp_tunnel_dst_mtu(const struct l2tp_tunnel *tunnel) | ||
275 | { | ||
276 | struct dst_entry *dst; | ||
277 | u32 mtu; | ||
278 | |||
279 | dst = sk_dst_get(tunnel->sock); | ||
280 | if (!dst) | ||
281 | return 0; | ||
282 | |||
283 | mtu = dst_mtu(dst); | ||
284 | dst_release(dst); | ||
285 | |||
286 | return mtu; | ||
287 | } | ||
288 | |||
271 | #define l2tp_printk(ptr, type, func, fmt, ...) \ | 289 | #define l2tp_printk(ptr, type, func, fmt, ...) \ |
272 | do { \ | 290 | do { \ |
273 | if (((ptr)->debug) & (type)) \ | 291 | if (((ptr)->debug) & (type)) \ |
diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c index 5c366ecfa1cb..cfca5e63ae31 100644 --- a/net/l2tp/l2tp_eth.c +++ b/net/l2tp/l2tp_eth.c | |||
@@ -226,8 +226,8 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel, | |||
226 | struct net_device *dev) | 226 | struct net_device *dev) |
227 | { | 227 | { |
228 | unsigned int overhead = 0; | 228 | unsigned int overhead = 0; |
229 | struct dst_entry *dst; | ||
230 | u32 l3_overhead = 0; | 229 | u32 l3_overhead = 0; |
230 | u32 mtu; | ||
231 | 231 | ||
232 | /* if the encap is UDP, account for UDP header size */ | 232 | /* if the encap is UDP, account for UDP header size */ |
233 | if (tunnel->encap == L2TP_ENCAPTYPE_UDP) { | 233 | if (tunnel->encap == L2TP_ENCAPTYPE_UDP) { |
@@ -256,15 +256,9 @@ static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel, | |||
256 | overhead += session->hdr_len + ETH_HLEN + l3_overhead; | 256 | overhead += session->hdr_len + ETH_HLEN + l3_overhead; |
257 | 257 | ||
258 | /* If PMTU discovery was enabled, use discovered MTU on L2TP device */ | 258 | /* If PMTU discovery was enabled, use discovered MTU on L2TP device */ |
259 | dst = sk_dst_get(tunnel->sock); | 259 | mtu = l2tp_tunnel_dst_mtu(tunnel); |
260 | if (dst) { | 260 | if (mtu) |
261 | /* dst_mtu will use PMTU if found, else fallback to intf MTU */ | 261 | dev->mtu = mtu; |
262 | u32 pmtu = dst_mtu(dst); | ||
263 | |||
264 | if (pmtu != 0) | ||
265 | dev->mtu = pmtu; | ||
266 | dst_release(dst); | ||
267 | } | ||
268 | session->mtu = dev->mtu - overhead; | 262 | session->mtu = dev->mtu - overhead; |
269 | dev->mtu = session->mtu; | 263 | dev->mtu = session->mtu; |
270 | dev->needed_headroom += session->hdr_len; | 264 | dev->needed_headroom += session->hdr_len; |
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index 44cac66284a5..1c6da02f976a 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c | |||
@@ -93,7 +93,6 @@ | |||
93 | #include <linux/nsproxy.h> | 93 | #include <linux/nsproxy.h> |
94 | #include <net/net_namespace.h> | 94 | #include <net/net_namespace.h> |
95 | #include <net/netns/generic.h> | 95 | #include <net/netns/generic.h> |
96 | #include <net/dst.h> | ||
97 | #include <net/ip.h> | 96 | #include <net/ip.h> |
98 | #include <net/udp.h> | 97 | #include <net/udp.h> |
99 | #include <net/xfrm.h> | 98 | #include <net/xfrm.h> |
@@ -554,7 +553,7 @@ static void pppol2tp_show(struct seq_file *m, void *arg) | |||
554 | static void pppol2tp_session_init(struct l2tp_session *session) | 553 | static void pppol2tp_session_init(struct l2tp_session *session) |
555 | { | 554 | { |
556 | struct pppol2tp_session *ps; | 555 | struct pppol2tp_session *ps; |
557 | struct dst_entry *dst; | 556 | u32 mtu; |
558 | 557 | ||
559 | session->recv_skb = pppol2tp_recv; | 558 | session->recv_skb = pppol2tp_recv; |
560 | #if IS_ENABLED(CONFIG_L2TP_DEBUGFS) | 559 | #if IS_ENABLED(CONFIG_L2TP_DEBUGFS) |
@@ -566,15 +565,9 @@ static void pppol2tp_session_init(struct l2tp_session *session) | |||
566 | ps->owner = current->pid; | 565 | ps->owner = current->pid; |
567 | 566 | ||
568 | /* If PMTU discovery was enabled, use the MTU that was discovered */ | 567 | /* If PMTU discovery was enabled, use the MTU that was discovered */ |
569 | dst = sk_dst_get(session->tunnel->sock); | 568 | mtu = l2tp_tunnel_dst_mtu(session->tunnel); |
570 | if (dst) { | 569 | if (mtu) |
571 | u32 pmtu = dst_mtu(dst); | 570 | session->mtu = mtu - PPPOL2TP_HEADER_OVERHEAD; |
572 | |||
573 | if (pmtu) | ||
574 | session->mtu = pmtu - PPPOL2TP_HEADER_OVERHEAD; | ||
575 | |||
576 | dst_release(dst); | ||
577 | } | ||
578 | } | 571 | } |
579 | 572 | ||
580 | struct l2tp_connect_info { | 573 | struct l2tp_connect_info { |