forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
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);
....@@ -280,7 +263,7 @@
280263 {
281264 struct inet_sock *inet = inet_sk(sk);
282265 struct ipv6_pinfo *np = inet6_sk(sk);
283
- struct sockaddr_l2tpip6 *addr = (struct sockaddr_l2tpip6 *) uaddr;
266
+ struct sockaddr_l2tpip6 *addr = (struct sockaddr_l2tpip6 *)uaddr;
284267 struct net *net = sock_net(sk);
285268 __be32 v4addr = 0;
286269 int bound_dev_if;
....@@ -379,8 +362,8 @@
379362 static int l2tp_ip6_connect(struct sock *sk, struct sockaddr *uaddr,
380363 int addr_len)
381364 {
382
- struct sockaddr_l2tpip6 *lsa = (struct sockaddr_l2tpip6 *) uaddr;
383
- struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr;
365
+ struct sockaddr_l2tpip6 *lsa = (struct sockaddr_l2tpip6 *)uaddr;
366
+ struct sockaddr_in6 *usin = (struct sockaddr_in6 *)uaddr;
384367 struct in6_addr *daddr;
385368 int addr_type;
386369 int rc;
....@@ -490,7 +473,7 @@
490473 int err = 0;
491474
492475 skb = skb_peek(&sk->sk_write_queue);
493
- if (skb == NULL)
476
+ if (!skb)
494477 goto out;
495478
496479 transhdr = (__be32 *)skb_transport_header(skb);
....@@ -519,22 +502,21 @@
519502 struct ipcm6_cookie ipc6;
520503 int addr_len = msg->msg_namelen;
521504 int transhdrlen = 4; /* zero session-id */
522
- int ulen = len + transhdrlen;
505
+ int ulen;
523506 int err;
524507
525508 /* Rough check on arithmetic overflow,
526
- better check is made in ip6_append_data().
509
+ * better check is made in ip6_append_data().
527510 */
528
- if (len > INT_MAX)
511
+ if (len > INT_MAX - transhdrlen)
529512 return -EMSGSIZE;
513
+ ulen = len + transhdrlen;
530514
531515 /* Mirror BSD error message compatibility */
532516 if (msg->msg_flags & MSG_OOB)
533517 return -EOPNOTSUPP;
534518
535
- /*
536
- * Get and verify the address.
537
- */
519
+ /* Get and verify the address */
538520 memset(&fl6, 0, sizeof(fl6));
539521
540522 fl6.flowi6_mark = sk->sk_mark;
....@@ -552,15 +534,14 @@
552534 daddr = &lsa->l2tp_addr;
553535 if (np->sndflow) {
554536 fl6.flowlabel = lsa->l2tp_flowinfo & IPV6_FLOWINFO_MASK;
555
- if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) {
537
+ if (fl6.flowlabel & IPV6_FLOWLABEL_MASK) {
556538 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
557
- if (flowlabel == NULL)
539
+ if (IS_ERR(flowlabel))
558540 return -EINVAL;
559541 }
560542 }
561543
562
- /*
563
- * Otherwise it will be difficult to maintain
544
+ /* Otherwise it will be difficult to maintain
564545 * sk->sk_dst_cache.
565546 */
566547 if (sk->sk_state == TCP_ESTABLISHED &&
....@@ -595,10 +576,10 @@
595576 }
596577 if ((fl6.flowlabel & IPV6_FLOWLABEL_MASK) && !flowlabel) {
597578 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
598
- if (flowlabel == NULL)
579
+ if (IS_ERR(flowlabel))
599580 return -EINVAL;
600581 }
601
- if (!(opt->opt_nflen|opt->opt_flen))
582
+ if (!(opt->opt_nflen | opt->opt_flen))
602583 opt = NULL;
603584 }
604585
....@@ -626,7 +607,7 @@
626607 else if (!fl6.flowi6_oif)
627608 fl6.flowi6_oif = np->ucast_oif;
628609
629
- security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
610
+ security_sk_classify_flow(sk, flowi6_to_flowi_common(&fl6));
630611
631612 if (ipc6.tclass < 0)
632613 ipc6.tclass = np->tclass;
....@@ -749,10 +730,6 @@
749730 .hash = l2tp_ip6_hash,
750731 .unhash = l2tp_ip6_unhash,
751732 .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
756733 };
757734
758735 static const struct proto_ops l2tp_ip6_ops = {
....@@ -766,6 +743,7 @@
766743 .getname = l2tp_ip6_getname,
767744 .poll = datagram_poll,
768745 .ioctl = inet6_ioctl,
746
+ .gettstamp = sock_gettstamp,
769747 .listen = sock_no_listen,
770748 .shutdown = inet_shutdown,
771749 .setsockopt = sock_common_setsockopt,
....@@ -775,8 +753,7 @@
775753 .mmap = sock_no_mmap,
776754 .sendpage = sock_no_sendpage,
777755 #ifdef CONFIG_COMPAT
778
- .compat_setsockopt = compat_sock_common_setsockopt,
779
- .compat_getsockopt = compat_sock_common_getsockopt,
756
+ .compat_ioctl = inet6_compat_ioctl,
780757 #endif
781758 };
782759