hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/l2tp/l2tp_netlink.c
....@@ -1,5 +1,5 @@
1
-/*
2
- * L2TP netlink layer, for management
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+/* L2TP netlink layer, for management
33 *
44 * Copyright (c) 2008,2009,2010 Katalix Systems Ltd
55 *
....@@ -8,10 +8,6 @@
88 * Copyright (c) 2007 Samuel Ortiz <samuel@sortiz.org>
99 * which is in turn partly based on the wireless netlink code:
1010 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License version 2 as
14
- * published by the Free Software Foundation.
1511 */
1612
1713 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -29,7 +25,6 @@
2925 #include <linux/l2tp.h>
3026
3127 #include "l2tp_core.h"
32
-
3328
3429 static struct genl_family l2tp_nl_family;
3530
....@@ -160,87 +155,85 @@
160155 return ret;
161156 }
162157
158
+static int l2tp_nl_cmd_tunnel_create_get_addr(struct nlattr **attrs, struct l2tp_tunnel_cfg *cfg)
159
+{
160
+ if (attrs[L2TP_ATTR_UDP_SPORT])
161
+ cfg->local_udp_port = nla_get_u16(attrs[L2TP_ATTR_UDP_SPORT]);
162
+ if (attrs[L2TP_ATTR_UDP_DPORT])
163
+ cfg->peer_udp_port = nla_get_u16(attrs[L2TP_ATTR_UDP_DPORT]);
164
+ cfg->use_udp_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_CSUM]);
165
+
166
+ /* Must have either AF_INET or AF_INET6 address for source and destination */
167
+#if IS_ENABLED(CONFIG_IPV6)
168
+ if (attrs[L2TP_ATTR_IP6_SADDR] && attrs[L2TP_ATTR_IP6_DADDR]) {
169
+ cfg->local_ip6 = nla_data(attrs[L2TP_ATTR_IP6_SADDR]);
170
+ cfg->peer_ip6 = nla_data(attrs[L2TP_ATTR_IP6_DADDR]);
171
+ cfg->udp6_zero_tx_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_ZERO_CSUM6_TX]);
172
+ cfg->udp6_zero_rx_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_ZERO_CSUM6_RX]);
173
+ return 0;
174
+ }
175
+#endif
176
+ if (attrs[L2TP_ATTR_IP_SADDR] && attrs[L2TP_ATTR_IP_DADDR]) {
177
+ cfg->local_ip.s_addr = nla_get_in_addr(attrs[L2TP_ATTR_IP_SADDR]);
178
+ cfg->peer_ip.s_addr = nla_get_in_addr(attrs[L2TP_ATTR_IP_DADDR]);
179
+ return 0;
180
+ }
181
+ return -EINVAL;
182
+}
183
+
163184 static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info)
164185 {
165186 u32 tunnel_id;
166187 u32 peer_tunnel_id;
167188 int proto_version;
168
- int fd;
189
+ int fd = -1;
169190 int ret = 0;
170191 struct l2tp_tunnel_cfg cfg = { 0, };
171192 struct l2tp_tunnel *tunnel;
172193 struct net *net = genl_info_net(info);
194
+ struct nlattr **attrs = info->attrs;
173195
174
- if (!info->attrs[L2TP_ATTR_CONN_ID]) {
196
+ if (!attrs[L2TP_ATTR_CONN_ID]) {
175197 ret = -EINVAL;
176198 goto out;
177199 }
178
- tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
200
+ tunnel_id = nla_get_u32(attrs[L2TP_ATTR_CONN_ID]);
179201
180
- if (!info->attrs[L2TP_ATTR_PEER_CONN_ID]) {
202
+ if (!attrs[L2TP_ATTR_PEER_CONN_ID]) {
181203 ret = -EINVAL;
182204 goto out;
183205 }
184
- peer_tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_PEER_CONN_ID]);
206
+ peer_tunnel_id = nla_get_u32(attrs[L2TP_ATTR_PEER_CONN_ID]);
185207
186
- if (!info->attrs[L2TP_ATTR_PROTO_VERSION]) {
208
+ if (!attrs[L2TP_ATTR_PROTO_VERSION]) {
187209 ret = -EINVAL;
188210 goto out;
189211 }
190
- proto_version = nla_get_u8(info->attrs[L2TP_ATTR_PROTO_VERSION]);
212
+ proto_version = nla_get_u8(attrs[L2TP_ATTR_PROTO_VERSION]);
191213
192
- if (!info->attrs[L2TP_ATTR_ENCAP_TYPE]) {
214
+ if (!attrs[L2TP_ATTR_ENCAP_TYPE]) {
193215 ret = -EINVAL;
194216 goto out;
195217 }
196
- cfg.encap = nla_get_u16(info->attrs[L2TP_ATTR_ENCAP_TYPE]);
218
+ cfg.encap = nla_get_u16(attrs[L2TP_ATTR_ENCAP_TYPE]);
197219
198
- fd = -1;
199
- if (info->attrs[L2TP_ATTR_FD]) {
200
- fd = nla_get_u32(info->attrs[L2TP_ATTR_FD]);
220
+ /* Managed tunnels take the tunnel socket from userspace.
221
+ * Unmanaged tunnels must call out the source and destination addresses
222
+ * for the kernel to create the tunnel socket itself.
223
+ */
224
+ if (attrs[L2TP_ATTR_FD]) {
225
+ fd = nla_get_u32(attrs[L2TP_ATTR_FD]);
201226 } else {
202
-#if IS_ENABLED(CONFIG_IPV6)
203
- if (info->attrs[L2TP_ATTR_IP6_SADDR] &&
204
- info->attrs[L2TP_ATTR_IP6_DADDR]) {
205
- cfg.local_ip6 = nla_data(
206
- info->attrs[L2TP_ATTR_IP6_SADDR]);
207
- cfg.peer_ip6 = nla_data(
208
- info->attrs[L2TP_ATTR_IP6_DADDR]);
209
- } else
210
-#endif
211
- if (info->attrs[L2TP_ATTR_IP_SADDR] &&
212
- info->attrs[L2TP_ATTR_IP_DADDR]) {
213
- cfg.local_ip.s_addr = nla_get_in_addr(
214
- info->attrs[L2TP_ATTR_IP_SADDR]);
215
- cfg.peer_ip.s_addr = nla_get_in_addr(
216
- info->attrs[L2TP_ATTR_IP_DADDR]);
217
- } else {
218
- ret = -EINVAL;
227
+ ret = l2tp_nl_cmd_tunnel_create_get_addr(attrs, &cfg);
228
+ if (ret < 0)
219229 goto out;
220
- }
221
- if (info->attrs[L2TP_ATTR_UDP_SPORT])
222
- cfg.local_udp_port = nla_get_u16(info->attrs[L2TP_ATTR_UDP_SPORT]);
223
- if (info->attrs[L2TP_ATTR_UDP_DPORT])
224
- cfg.peer_udp_port = nla_get_u16(info->attrs[L2TP_ATTR_UDP_DPORT]);
225
- cfg.use_udp_checksums = nla_get_flag(
226
- info->attrs[L2TP_ATTR_UDP_CSUM]);
227
-
228
-#if IS_ENABLED(CONFIG_IPV6)
229
- cfg.udp6_zero_tx_checksums = nla_get_flag(
230
- info->attrs[L2TP_ATTR_UDP_ZERO_CSUM6_TX]);
231
- cfg.udp6_zero_rx_checksums = nla_get_flag(
232
- info->attrs[L2TP_ATTR_UDP_ZERO_CSUM6_RX]);
233
-#endif
234230 }
235
-
236
- if (info->attrs[L2TP_ATTR_DEBUG])
237
- cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]);
238231
239232 ret = -EINVAL;
240233 switch (cfg.encap) {
241234 case L2TP_ENCAPTYPE_UDP:
242235 case L2TP_ENCAPTYPE_IP:
243
- ret = l2tp_tunnel_create(net, fd, proto_version, tunnel_id,
236
+ ret = l2tp_tunnel_create(fd, proto_version, tunnel_id,
244237 peer_tunnel_id, &cfg, &tunnel);
245238 break;
246239 }
....@@ -311,9 +304,6 @@
311304 goto out;
312305 }
313306
314
- if (info->attrs[L2TP_ATTR_DEBUG])
315
- tunnel->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]);
316
-
317307 ret = l2tp_tunnel_notify(&l2tp_nl_family, info,
318308 tunnel, L2TP_CMD_TUNNEL_MODIFY);
319309
....@@ -323,16 +313,79 @@
323313 return ret;
324314 }
325315
316
+#if IS_ENABLED(CONFIG_IPV6)
317
+static int l2tp_nl_tunnel_send_addr6(struct sk_buff *skb, struct sock *sk,
318
+ enum l2tp_encap_type encap)
319
+{
320
+ struct inet_sock *inet = inet_sk(sk);
321
+ struct ipv6_pinfo *np = inet6_sk(sk);
322
+
323
+ switch (encap) {
324
+ case L2TP_ENCAPTYPE_UDP:
325
+ if (udp_get_no_check6_tx(sk) &&
326
+ nla_put_flag(skb, L2TP_ATTR_UDP_ZERO_CSUM6_TX))
327
+ return -1;
328
+ if (udp_get_no_check6_rx(sk) &&
329
+ nla_put_flag(skb, L2TP_ATTR_UDP_ZERO_CSUM6_RX))
330
+ return -1;
331
+ if (nla_put_u16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)) ||
332
+ nla_put_u16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)))
333
+ return -1;
334
+ fallthrough;
335
+ case L2TP_ENCAPTYPE_IP:
336
+ if (nla_put_in6_addr(skb, L2TP_ATTR_IP6_SADDR, &np->saddr) ||
337
+ nla_put_in6_addr(skb, L2TP_ATTR_IP6_DADDR, &sk->sk_v6_daddr))
338
+ return -1;
339
+ break;
340
+ }
341
+ return 0;
342
+}
343
+#endif
344
+
345
+static int l2tp_nl_tunnel_send_addr4(struct sk_buff *skb, struct sock *sk,
346
+ enum l2tp_encap_type encap)
347
+{
348
+ struct inet_sock *inet = inet_sk(sk);
349
+
350
+ switch (encap) {
351
+ case L2TP_ENCAPTYPE_UDP:
352
+ if (nla_put_u8(skb, L2TP_ATTR_UDP_CSUM, !sk->sk_no_check_tx) ||
353
+ nla_put_u16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)) ||
354
+ nla_put_u16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)))
355
+ return -1;
356
+ fallthrough;
357
+ case L2TP_ENCAPTYPE_IP:
358
+ if (nla_put_in_addr(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr) ||
359
+ nla_put_in_addr(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr))
360
+ return -1;
361
+ break;
362
+ }
363
+
364
+ return 0;
365
+}
366
+
367
+/* Append attributes for the tunnel address, handling the different attribute types
368
+ * used for different tunnel encapsulation and AF_INET v.s. AF_INET6.
369
+ */
370
+static int l2tp_nl_tunnel_send_addr(struct sk_buff *skb, struct l2tp_tunnel *tunnel)
371
+{
372
+ struct sock *sk = tunnel->sock;
373
+
374
+ if (!sk)
375
+ return 0;
376
+
377
+#if IS_ENABLED(CONFIG_IPV6)
378
+ if (sk->sk_family == AF_INET6)
379
+ return l2tp_nl_tunnel_send_addr6(skb, sk, tunnel->encap);
380
+#endif
381
+ return l2tp_nl_tunnel_send_addr4(skb, sk, tunnel->encap);
382
+}
383
+
326384 static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int flags,
327385 struct l2tp_tunnel *tunnel, u8 cmd)
328386 {
329387 void *hdr;
330388 struct nlattr *nest;
331
- struct sock *sk = NULL;
332
- struct inet_sock *inet;
333
-#if IS_ENABLED(CONFIG_IPV6)
334
- struct ipv6_pinfo *np = NULL;
335
-#endif
336389
337390 hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, cmd);
338391 if (!hdr)
....@@ -341,12 +394,12 @@
341394 if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) ||
342395 nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
343396 nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
344
- nla_put_u32(skb, L2TP_ATTR_DEBUG, tunnel->debug) ||
397
+ nla_put_u32(skb, L2TP_ATTR_DEBUG, 0) ||
345398 nla_put_u16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap))
346399 goto nla_put_failure;
347400
348
- nest = nla_nest_start(skb, L2TP_ATTR_STATS);
349
- if (nest == NULL)
401
+ nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
402
+ if (!nest)
350403 goto nla_put_failure;
351404
352405 if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS,
....@@ -367,67 +420,24 @@
367420 nla_put_u64_64bit(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
368421 atomic_long_read(&tunnel->stats.rx_seq_discards),
369422 L2TP_ATTR_STATS_PAD) ||
423
+ nla_put_u64_64bit(skb, L2TP_ATTR_RX_COOKIE_DISCARDS,
424
+ atomic_long_read(&tunnel->stats.rx_cookie_discards),
425
+ L2TP_ATTR_STATS_PAD) ||
370426 nla_put_u64_64bit(skb, L2TP_ATTR_RX_OOS_PACKETS,
371427 atomic_long_read(&tunnel->stats.rx_oos_packets),
372428 L2TP_ATTR_STATS_PAD) ||
373429 nla_put_u64_64bit(skb, L2TP_ATTR_RX_ERRORS,
374430 atomic_long_read(&tunnel->stats.rx_errors),
431
+ L2TP_ATTR_STATS_PAD) ||
432
+ nla_put_u64_64bit(skb, L2TP_ATTR_RX_INVALID,
433
+ atomic_long_read(&tunnel->stats.rx_invalid),
375434 L2TP_ATTR_STATS_PAD))
376435 goto nla_put_failure;
377436 nla_nest_end(skb, nest);
378437
379
- sk = tunnel->sock;
380
- if (!sk)
381
- goto out;
438
+ if (l2tp_nl_tunnel_send_addr(skb, tunnel))
439
+ goto nla_put_failure;
382440
383
-#if IS_ENABLED(CONFIG_IPV6)
384
- if (sk->sk_family == AF_INET6)
385
- np = inet6_sk(sk);
386
-#endif
387
-
388
- inet = inet_sk(sk);
389
-
390
- switch (tunnel->encap) {
391
- case L2TP_ENCAPTYPE_UDP:
392
- switch (sk->sk_family) {
393
- case AF_INET:
394
- if (nla_put_u8(skb, L2TP_ATTR_UDP_CSUM, !sk->sk_no_check_tx))
395
- goto nla_put_failure;
396
- break;
397
-#if IS_ENABLED(CONFIG_IPV6)
398
- case AF_INET6:
399
- if (udp_get_no_check6_tx(sk) &&
400
- nla_put_flag(skb, L2TP_ATTR_UDP_ZERO_CSUM6_TX))
401
- goto nla_put_failure;
402
- if (udp_get_no_check6_rx(sk) &&
403
- nla_put_flag(skb, L2TP_ATTR_UDP_ZERO_CSUM6_RX))
404
- goto nla_put_failure;
405
- break;
406
-#endif
407
- }
408
- if (nla_put_u16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)) ||
409
- nla_put_u16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)))
410
- goto nla_put_failure;
411
- /* fall through */
412
- case L2TP_ENCAPTYPE_IP:
413
-#if IS_ENABLED(CONFIG_IPV6)
414
- if (np) {
415
- if (nla_put_in6_addr(skb, L2TP_ATTR_IP6_SADDR,
416
- &np->saddr) ||
417
- nla_put_in6_addr(skb, L2TP_ATTR_IP6_DADDR,
418
- &sk->sk_v6_daddr))
419
- goto nla_put_failure;
420
- } else
421
-#endif
422
- if (nla_put_in_addr(skb, L2TP_ATTR_IP_SADDR,
423
- inet->inet_saddr) ||
424
- nla_put_in_addr(skb, L2TP_ATTR_IP_DADDR,
425
- inet->inet_daddr))
426
- goto nla_put_failure;
427
- break;
428
- }
429
-
430
-out:
431441 genlmsg_end(skb, hdr);
432442 return 0;
433443
....@@ -488,7 +498,7 @@
488498
489499 for (;;) {
490500 tunnel = l2tp_tunnel_get_nth(net, ti);
491
- if (tunnel == NULL)
501
+ if (!tunnel)
492502 goto out;
493503
494504 if (l2tp_nl_tunnel_send(skb, NETLINK_CB(cb->skb).portid,
....@@ -573,6 +583,7 @@
573583
574584 if (info->attrs[L2TP_ATTR_COOKIE]) {
575585 u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]);
586
+
576587 if (len > 8) {
577588 ret = -EINVAL;
578589 goto out_tunnel;
....@@ -582,6 +593,7 @@
582593 }
583594 if (info->attrs[L2TP_ATTR_PEER_COOKIE]) {
584595 u16 len = nla_len(info->attrs[L2TP_ATTR_PEER_COOKIE]);
596
+
585597 if (len > 8) {
586598 ret = -EINVAL;
587599 goto out_tunnel;
....@@ -592,9 +604,6 @@
592604 if (info->attrs[L2TP_ATTR_IFNAME])
593605 cfg.ifname = nla_data(info->attrs[L2TP_ATTR_IFNAME]);
594606 }
595
-
596
- if (info->attrs[L2TP_ATTR_DEBUG])
597
- cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]);
598607
599608 if (info->attrs[L2TP_ATTR_RECV_SEQ])
600609 cfg.recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]);
....@@ -609,14 +618,13 @@
609618 cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);
610619
611620 #ifdef CONFIG_MODULES
612
- if (l2tp_nl_cmd_ops[cfg.pw_type] == NULL) {
621
+ if (!l2tp_nl_cmd_ops[cfg.pw_type]) {
613622 genl_unlock();
614623 request_module("net-l2tp-type-%u", cfg.pw_type);
615624 genl_lock();
616625 }
617626 #endif
618
- if ((l2tp_nl_cmd_ops[cfg.pw_type] == NULL) ||
619
- (l2tp_nl_cmd_ops[cfg.pw_type]->session_create == NULL)) {
627
+ if (!l2tp_nl_cmd_ops[cfg.pw_type] || !l2tp_nl_cmd_ops[cfg.pw_type]->session_create) {
620628 ret = -EPROTONOSUPPORT;
621629 goto out_tunnel;
622630 }
....@@ -648,7 +656,7 @@
648656 u16 pw_type;
649657
650658 session = l2tp_nl_session_get(info);
651
- if (session == NULL) {
659
+ if (!session) {
652660 ret = -ENODEV;
653661 goto out;
654662 }
....@@ -659,7 +667,7 @@
659667 pw_type = session->pwtype;
660668 if (pw_type < __L2TP_PWTYPE_MAX)
661669 if (l2tp_nl_cmd_ops[pw_type] && l2tp_nl_cmd_ops[pw_type]->session_delete)
662
- ret = (*l2tp_nl_cmd_ops[pw_type]->session_delete)(session);
670
+ l2tp_nl_cmd_ops[pw_type]->session_delete(session);
663671
664672 l2tp_session_dec_refcount(session);
665673
....@@ -673,13 +681,10 @@
673681 struct l2tp_session *session;
674682
675683 session = l2tp_nl_session_get(info);
676
- if (session == NULL) {
684
+ if (!session) {
677685 ret = -ENODEV;
678686 goto out;
679687 }
680
-
681
- if (info->attrs[L2TP_ATTR_DEBUG])
682
- session->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]);
683688
684689 if (info->attrs[L2TP_ATTR_RECV_SEQ])
685690 session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]);
....@@ -718,20 +723,17 @@
718723 if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
719724 nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) ||
720725 nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
721
- nla_put_u32(skb, L2TP_ATTR_PEER_SESSION_ID,
722
- session->peer_session_id) ||
723
- nla_put_u32(skb, L2TP_ATTR_DEBUG, session->debug) ||
726
+ nla_put_u32(skb, L2TP_ATTR_PEER_SESSION_ID, session->peer_session_id) ||
727
+ nla_put_u32(skb, L2TP_ATTR_DEBUG, 0) ||
724728 nla_put_u16(skb, L2TP_ATTR_PW_TYPE, session->pwtype))
725729 goto nla_put_failure;
726730
727731 if ((session->ifname[0] &&
728732 nla_put_string(skb, L2TP_ATTR_IFNAME, session->ifname)) ||
729733 (session->cookie_len &&
730
- nla_put(skb, L2TP_ATTR_COOKIE, session->cookie_len,
731
- &session->cookie[0])) ||
734
+ nla_put(skb, L2TP_ATTR_COOKIE, session->cookie_len, session->cookie)) ||
732735 (session->peer_cookie_len &&
733
- nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len,
734
- &session->peer_cookie[0])) ||
736
+ nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len, session->peer_cookie)) ||
735737 nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq) ||
736738 nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq) ||
737739 nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode) ||
....@@ -742,8 +744,8 @@
742744 session->reorder_timeout, L2TP_ATTR_PAD)))
743745 goto nla_put_failure;
744746
745
- nest = nla_nest_start(skb, L2TP_ATTR_STATS);
746
- if (nest == NULL)
747
+ nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
748
+ if (!nest)
747749 goto nla_put_failure;
748750
749751 if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS,
....@@ -764,11 +766,17 @@
764766 nla_put_u64_64bit(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
765767 atomic_long_read(&session->stats.rx_seq_discards),
766768 L2TP_ATTR_STATS_PAD) ||
769
+ nla_put_u64_64bit(skb, L2TP_ATTR_RX_COOKIE_DISCARDS,
770
+ atomic_long_read(&session->stats.rx_cookie_discards),
771
+ L2TP_ATTR_STATS_PAD) ||
767772 nla_put_u64_64bit(skb, L2TP_ATTR_RX_OOS_PACKETS,
768773 atomic_long_read(&session->stats.rx_oos_packets),
769774 L2TP_ATTR_STATS_PAD) ||
770775 nla_put_u64_64bit(skb, L2TP_ATTR_RX_ERRORS,
771776 atomic_long_read(&session->stats.rx_errors),
777
+ L2TP_ATTR_STATS_PAD) ||
778
+ nla_put_u64_64bit(skb, L2TP_ATTR_RX_INVALID,
779
+ atomic_long_read(&session->stats.rx_invalid),
772780 L2TP_ATTR_STATS_PAD))
773781 goto nla_put_failure;
774782 nla_nest_end(skb, nest);
....@@ -788,7 +796,7 @@
788796 int ret;
789797
790798 session = l2tp_nl_session_get(info);
791
- if (session == NULL) {
799
+ if (!session) {
792800 ret = -ENODEV;
793801 goto err;
794802 }
....@@ -827,14 +835,14 @@
827835 int si = cb->args[1];
828836
829837 for (;;) {
830
- if (tunnel == NULL) {
838
+ if (!tunnel) {
831839 tunnel = l2tp_tunnel_get_nth(net, ti);
832
- if (tunnel == NULL)
840
+ if (!tunnel)
833841 goto out;
834842 }
835843
836844 session = l2tp_session_get_nth(tunnel, si);
837
- if (session == NULL) {
845
+ if (!session) {
838846 ti++;
839847 l2tp_tunnel_dec_refcount(tunnel);
840848 tunnel = NULL;
....@@ -912,62 +920,62 @@
912920 },
913921 };
914922
915
-static const struct genl_ops l2tp_nl_ops[] = {
923
+static const struct genl_small_ops l2tp_nl_ops[] = {
916924 {
917925 .cmd = L2TP_CMD_NOOP,
926
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
918927 .doit = l2tp_nl_cmd_noop,
919
- .policy = l2tp_nl_policy,
920928 /* can be retrieved by unprivileged users */
921929 },
922930 {
923931 .cmd = L2TP_CMD_TUNNEL_CREATE,
932
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
924933 .doit = l2tp_nl_cmd_tunnel_create,
925
- .policy = l2tp_nl_policy,
926
- .flags = GENL_ADMIN_PERM,
934
+ .flags = GENL_UNS_ADMIN_PERM,
927935 },
928936 {
929937 .cmd = L2TP_CMD_TUNNEL_DELETE,
938
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
930939 .doit = l2tp_nl_cmd_tunnel_delete,
931
- .policy = l2tp_nl_policy,
932
- .flags = GENL_ADMIN_PERM,
940
+ .flags = GENL_UNS_ADMIN_PERM,
933941 },
934942 {
935943 .cmd = L2TP_CMD_TUNNEL_MODIFY,
944
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
936945 .doit = l2tp_nl_cmd_tunnel_modify,
937
- .policy = l2tp_nl_policy,
938
- .flags = GENL_ADMIN_PERM,
946
+ .flags = GENL_UNS_ADMIN_PERM,
939947 },
940948 {
941949 .cmd = L2TP_CMD_TUNNEL_GET,
950
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
942951 .doit = l2tp_nl_cmd_tunnel_get,
943952 .dumpit = l2tp_nl_cmd_tunnel_dump,
944
- .policy = l2tp_nl_policy,
945
- .flags = GENL_ADMIN_PERM,
953
+ .flags = GENL_UNS_ADMIN_PERM,
946954 },
947955 {
948956 .cmd = L2TP_CMD_SESSION_CREATE,
957
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
949958 .doit = l2tp_nl_cmd_session_create,
950
- .policy = l2tp_nl_policy,
951
- .flags = GENL_ADMIN_PERM,
959
+ .flags = GENL_UNS_ADMIN_PERM,
952960 },
953961 {
954962 .cmd = L2TP_CMD_SESSION_DELETE,
963
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
955964 .doit = l2tp_nl_cmd_session_delete,
956
- .policy = l2tp_nl_policy,
957
- .flags = GENL_ADMIN_PERM,
965
+ .flags = GENL_UNS_ADMIN_PERM,
958966 },
959967 {
960968 .cmd = L2TP_CMD_SESSION_MODIFY,
969
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
961970 .doit = l2tp_nl_cmd_session_modify,
962
- .policy = l2tp_nl_policy,
963
- .flags = GENL_ADMIN_PERM,
971
+ .flags = GENL_UNS_ADMIN_PERM,
964972 },
965973 {
966974 .cmd = L2TP_CMD_SESSION_GET,
975
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
967976 .doit = l2tp_nl_cmd_session_get,
968977 .dumpit = l2tp_nl_cmd_session_dump,
969
- .policy = l2tp_nl_policy,
970
- .flags = GENL_ADMIN_PERM,
978
+ .flags = GENL_UNS_ADMIN_PERM,
971979 },
972980 };
973981
....@@ -976,10 +984,11 @@
976984 .version = L2TP_GENL_VERSION,
977985 .hdrsize = 0,
978986 .maxattr = L2TP_ATTR_MAX,
987
+ .policy = l2tp_nl_policy,
979988 .netnsok = true,
980989 .module = THIS_MODULE,
981
- .ops = l2tp_nl_ops,
982
- .n_ops = ARRAY_SIZE(l2tp_nl_ops),
990
+ .small_ops = l2tp_nl_ops,
991
+ .n_small_ops = ARRAY_SIZE(l2tp_nl_ops),
983992 .mcgrps = l2tp_multicast_group,
984993 .n_mcgrps = ARRAY_SIZE(l2tp_multicast_group),
985994 };