hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/l2tp/l2tp_ip6.c
....@@ -1,12 +1,7 @@
1
-/*
2
- * L2TPv3 IP encapsulation support for IPv6
1
+// SPDX-License-Identifier: GPL-2.0-or-later
2
+/* L2TPv3 IP encapsulation support for IPv6
33 *
44 * Copyright (c) 2012 Katalix Systems Ltd
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License
8
- * as published by the Free Software Foundation; either version
9
- * 2 of the License, or (at your option) any later version.
105 */
116
127 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -42,7 +37,8 @@
4237 u32 peer_conn_id;
4338
4439 /* ipv6_pinfo has to be the last member of l2tp_ip6_sock, see
45
- inet6_sk_generic */
40
+ * inet6_sk_generic
41
+ */
4642 struct ipv6_pinfo inet6;
4743 };
4844
....@@ -135,14 +131,14 @@
135131 struct l2tp_session *session;
136132 struct l2tp_tunnel *tunnel = NULL;
137133 struct ipv6hdr *iph;
138
- int length;
139134
140135 if (!pskb_may_pull(skb, 4))
141136 goto discard;
142137
143138 /* Point to L2TP header */
144
- optr = ptr = skb->data;
145
- session_id = ntohl(*((__be32 *) ptr));
139
+ optr = skb->data;
140
+ ptr = skb->data;
141
+ session_id = ntohl(*((__be32 *)ptr));
146142 ptr += 4;
147143
148144 /* RFC3931: L2TP/IP packets have the first 4 bytes containing
....@@ -163,19 +159,6 @@
163159 if (!tunnel)
164160 goto discard_sess;
165161
166
- /* Trace packet contents, if enabled */
167
- if (tunnel->debug & L2TP_MSG_DATA) {
168
- length = min(32u, skb->len);
169
- if (!pskb_may_pull(skb, length))
170
- goto discard_sess;
171
-
172
- /* Point to L2TP header */
173
- optr = ptr = skb->data;
174
- ptr += 4;
175
- pr_debug("%s: ip recv\n", tunnel->name);
176
- print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length);
177
- }
178
-
179162 if (l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr))
180163 goto discard_sess;
181164
....@@ -192,7 +175,7 @@
192175 if ((skb->data[0] & 0xc0) != 0xc0)
193176 goto discard;
194177
195
- tunnel_id = ntohl(*(__be32 *) &skb->data[4]);
178
+ tunnel_id = ntohl(*(__be32 *)&skb->data[4]);
196179 iph = ipv6_hdr(skb);
197180
198181 read_lock_bh(&l2tp_ip6_lock);
....@@ -208,7 +191,7 @@
208191 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
209192 goto discard_put;
210193
211
- nf_reset(skb);
194
+ nf_reset_ct(skb);
212195
213196 return sk_receive_skb(sk, skb, 1);
214197
....@@ -264,7 +247,7 @@
264247
265248 static void l2tp_ip6_destroy_sock(struct sock *sk)
266249 {
267
- struct l2tp_tunnel *tunnel = sk->sk_user_data;
250
+ struct l2tp_tunnel *tunnel = l2tp_sk_to_tunnel(sk);
268251
269252 lock_sock(sk);
270253 ip6_flush_pending_frames(sk);
....@@ -272,15 +255,13 @@
272255
273256 if (tunnel)
274257 l2tp_tunnel_delete(tunnel);
275
-
276
- inet6_destroy_sock(sk);
277258 }
278259
279260 static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
280261 {
281262 struct inet_sock *inet = inet_sk(sk);
282263 struct ipv6_pinfo *np = inet6_sk(sk);
283
- struct sockaddr_l2tpip6 *addr = (struct sockaddr_l2tpip6 *) uaddr;
264
+ struct sockaddr_l2tpip6 *addr = (struct sockaddr_l2tpip6 *)uaddr;
284265 struct net *net = sock_net(sk);
285266 __be32 v4addr = 0;
286267 int bound_dev_if;
....@@ -379,8 +360,8 @@
379360 static int l2tp_ip6_connect(struct sock *sk, struct sockaddr *uaddr,
380361 int addr_len)
381362 {
382
- struct sockaddr_l2tpip6 *lsa = (struct sockaddr_l2tpip6 *) uaddr;
383
- struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr;
363
+ struct sockaddr_l2tpip6 *lsa = (struct sockaddr_l2tpip6 *)uaddr;
364
+ struct sockaddr_in6 *usin = (struct sockaddr_in6 *)uaddr;
384365 struct in6_addr *daddr;
385366 int addr_type;
386367 int rc;
....@@ -490,7 +471,7 @@
490471 int err = 0;
491472
492473 skb = skb_peek(&sk->sk_write_queue);
493
- if (skb == NULL)
474
+ if (!skb)
494475 goto out;
495476
496477 transhdr = (__be32 *)skb_transport_header(skb);
....@@ -519,22 +500,20 @@
519500 struct ipcm6_cookie ipc6;
520501 int addr_len = msg->msg_namelen;
521502 int transhdrlen = 4; /* zero session-id */
522
- int ulen = len + transhdrlen;
503
+ int ulen;
523504 int err;
524505
525506 /* Rough check on arithmetic overflow,
526
- better check is made in ip6_append_data().
507
+ * better check is made in ip6_append_data().
527508 */
528
- if (len > INT_MAX)
509
+ if (len > INT_MAX - transhdrlen)
529510 return -EMSGSIZE;
530511
531512 /* Mirror BSD error message compatibility */
532513 if (msg->msg_flags & MSG_OOB)
533514 return -EOPNOTSUPP;
534515
535
- /*
536
- * Get and verify the address.
537
- */
516
+ /* Get and verify the address */
538517 memset(&fl6, 0, sizeof(fl6));
539518
540519 fl6.flowi6_mark = sk->sk_mark;
....@@ -552,15 +531,14 @@
552531 daddr = &lsa->l2tp_addr;
553532 if (np->sndflow) {
554533 fl6.flowlabel = lsa->l2tp_flowinfo & IPV6_FLOWINFO_MASK;
555
- if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) {
534
+ if (fl6.flowlabel & IPV6_FLOWLABEL_MASK) {
556535 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
557
- if (flowlabel == NULL)
536
+ if (IS_ERR(flowlabel))
558537 return -EINVAL;
559538 }
560539 }
561540
562
- /*
563
- * Otherwise it will be difficult to maintain
541
+ /* Otherwise it will be difficult to maintain
564542 * sk->sk_dst_cache.
565543 */
566544 if (sk->sk_state == TCP_ESTABLISHED &&
....@@ -595,10 +573,10 @@
595573 }
596574 if ((fl6.flowlabel & IPV6_FLOWLABEL_MASK) && !flowlabel) {
597575 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
598
- if (flowlabel == NULL)
576
+ if (IS_ERR(flowlabel))
599577 return -EINVAL;
600578 }
601
- if (!(opt->opt_nflen|opt->opt_flen))
579
+ if (!(opt->opt_nflen | opt->opt_flen))
602580 opt = NULL;
603581 }
604582
....@@ -626,7 +604,7 @@
626604 else if (!fl6.flowi6_oif)
627605 fl6.flowi6_oif = np->ucast_oif;
628606
629
- security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
607
+ security_sk_classify_flow(sk, flowi6_to_flowi_common(&fl6));
630608
631609 if (ipc6.tclass < 0)
632610 ipc6.tclass = np->tclass;
....@@ -650,6 +628,7 @@
650628
651629 back_from_confirm:
652630 lock_sock(sk);
631
+ ulen = len + skb_queue_empty(&sk->sk_write_queue) ? transhdrlen : 0;
653632 err = ip6_append_data(sk, ip_generic_getfrag, msg,
654633 ulen, transhdrlen, &ipc6,
655634 &fl6, (struct rt6_info *)dst,
....@@ -749,10 +728,6 @@
749728 .hash = l2tp_ip6_hash,
750729 .unhash = l2tp_ip6_unhash,
751730 .obj_size = sizeof(struct l2tp_ip6_sock),
752
-#ifdef CONFIG_COMPAT
753
- .compat_setsockopt = compat_ipv6_setsockopt,
754
- .compat_getsockopt = compat_ipv6_getsockopt,
755
-#endif
756731 };
757732
758733 static const struct proto_ops l2tp_ip6_ops = {
....@@ -766,6 +741,7 @@
766741 .getname = l2tp_ip6_getname,
767742 .poll = datagram_poll,
768743 .ioctl = inet6_ioctl,
744
+ .gettstamp = sock_gettstamp,
769745 .listen = sock_no_listen,
770746 .shutdown = inet_shutdown,
771747 .setsockopt = sock_common_setsockopt,
....@@ -775,8 +751,7 @@
775751 .mmap = sock_no_mmap,
776752 .sendpage = sock_no_sendpage,
777753 #ifdef CONFIG_COMPAT
778
- .compat_setsockopt = compat_sock_common_setsockopt,
779
- .compat_getsockopt = compat_sock_common_getsockopt,
754
+ .compat_ioctl = inet6_compat_ioctl,
780755 #endif
781756 };
782757