.. | .. |
---|
1 | | -/* |
---|
2 | | - * L2TP netlink layer, for management |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
| 2 | +/* L2TP netlink layer, for management |
---|
3 | 3 | * |
---|
4 | 4 | * Copyright (c) 2008,2009,2010 Katalix Systems Ltd |
---|
5 | 5 | * |
---|
.. | .. |
---|
8 | 8 | * Copyright (c) 2007 Samuel Ortiz <samuel@sortiz.org> |
---|
9 | 9 | * which is in turn partly based on the wireless netlink code: |
---|
10 | 10 | * 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. |
---|
15 | 11 | */ |
---|
16 | 12 | |
---|
17 | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
.. | .. |
---|
29 | 25 | #include <linux/l2tp.h> |
---|
30 | 26 | |
---|
31 | 27 | #include "l2tp_core.h" |
---|
32 | | - |
---|
33 | 28 | |
---|
34 | 29 | static struct genl_family l2tp_nl_family; |
---|
35 | 30 | |
---|
.. | .. |
---|
160 | 155 | return ret; |
---|
161 | 156 | } |
---|
162 | 157 | |
---|
| 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 | + |
---|
163 | 184 | static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info) |
---|
164 | 185 | { |
---|
165 | 186 | u32 tunnel_id; |
---|
166 | 187 | u32 peer_tunnel_id; |
---|
167 | 188 | int proto_version; |
---|
168 | | - int fd; |
---|
| 189 | + int fd = -1; |
---|
169 | 190 | int ret = 0; |
---|
170 | 191 | struct l2tp_tunnel_cfg cfg = { 0, }; |
---|
171 | 192 | struct l2tp_tunnel *tunnel; |
---|
172 | 193 | struct net *net = genl_info_net(info); |
---|
| 194 | + struct nlattr **attrs = info->attrs; |
---|
173 | 195 | |
---|
174 | | - if (!info->attrs[L2TP_ATTR_CONN_ID]) { |
---|
| 196 | + if (!attrs[L2TP_ATTR_CONN_ID]) { |
---|
175 | 197 | ret = -EINVAL; |
---|
176 | 198 | goto out; |
---|
177 | 199 | } |
---|
178 | | - tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]); |
---|
| 200 | + tunnel_id = nla_get_u32(attrs[L2TP_ATTR_CONN_ID]); |
---|
179 | 201 | |
---|
180 | | - if (!info->attrs[L2TP_ATTR_PEER_CONN_ID]) { |
---|
| 202 | + if (!attrs[L2TP_ATTR_PEER_CONN_ID]) { |
---|
181 | 203 | ret = -EINVAL; |
---|
182 | 204 | goto out; |
---|
183 | 205 | } |
---|
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]); |
---|
185 | 207 | |
---|
186 | | - if (!info->attrs[L2TP_ATTR_PROTO_VERSION]) { |
---|
| 208 | + if (!attrs[L2TP_ATTR_PROTO_VERSION]) { |
---|
187 | 209 | ret = -EINVAL; |
---|
188 | 210 | goto out; |
---|
189 | 211 | } |
---|
190 | | - proto_version = nla_get_u8(info->attrs[L2TP_ATTR_PROTO_VERSION]); |
---|
| 212 | + proto_version = nla_get_u8(attrs[L2TP_ATTR_PROTO_VERSION]); |
---|
191 | 213 | |
---|
192 | | - if (!info->attrs[L2TP_ATTR_ENCAP_TYPE]) { |
---|
| 214 | + if (!attrs[L2TP_ATTR_ENCAP_TYPE]) { |
---|
193 | 215 | ret = -EINVAL; |
---|
194 | 216 | goto out; |
---|
195 | 217 | } |
---|
196 | | - cfg.encap = nla_get_u16(info->attrs[L2TP_ATTR_ENCAP_TYPE]); |
---|
| 218 | + cfg.encap = nla_get_u16(attrs[L2TP_ATTR_ENCAP_TYPE]); |
---|
197 | 219 | |
---|
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]); |
---|
201 | 226 | } 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) |
---|
219 | 229 | 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 |
---|
234 | 230 | } |
---|
235 | | - |
---|
236 | | - if (info->attrs[L2TP_ATTR_DEBUG]) |
---|
237 | | - cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); |
---|
238 | 231 | |
---|
239 | 232 | ret = -EINVAL; |
---|
240 | 233 | switch (cfg.encap) { |
---|
241 | 234 | case L2TP_ENCAPTYPE_UDP: |
---|
242 | 235 | 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, |
---|
244 | 237 | peer_tunnel_id, &cfg, &tunnel); |
---|
245 | 238 | break; |
---|
246 | 239 | } |
---|
.. | .. |
---|
311 | 304 | goto out; |
---|
312 | 305 | } |
---|
313 | 306 | |
---|
314 | | - if (info->attrs[L2TP_ATTR_DEBUG]) |
---|
315 | | - tunnel->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); |
---|
316 | | - |
---|
317 | 307 | ret = l2tp_tunnel_notify(&l2tp_nl_family, info, |
---|
318 | 308 | tunnel, L2TP_CMD_TUNNEL_MODIFY); |
---|
319 | 309 | |
---|
.. | .. |
---|
323 | 313 | return ret; |
---|
324 | 314 | } |
---|
325 | 315 | |
---|
| 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 | + |
---|
326 | 384 | static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int flags, |
---|
327 | 385 | struct l2tp_tunnel *tunnel, u8 cmd) |
---|
328 | 386 | { |
---|
329 | 387 | void *hdr; |
---|
330 | 388 | 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 |
---|
336 | 389 | |
---|
337 | 390 | hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, cmd); |
---|
338 | 391 | if (!hdr) |
---|
.. | .. |
---|
341 | 394 | if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) || |
---|
342 | 395 | nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) || |
---|
343 | 396 | 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) || |
---|
345 | 398 | nla_put_u16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap)) |
---|
346 | 399 | goto nla_put_failure; |
---|
347 | 400 | |
---|
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) |
---|
350 | 403 | goto nla_put_failure; |
---|
351 | 404 | |
---|
352 | 405 | if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS, |
---|
.. | .. |
---|
367 | 420 | nla_put_u64_64bit(skb, L2TP_ATTR_RX_SEQ_DISCARDS, |
---|
368 | 421 | atomic_long_read(&tunnel->stats.rx_seq_discards), |
---|
369 | 422 | 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) || |
---|
370 | 426 | nla_put_u64_64bit(skb, L2TP_ATTR_RX_OOS_PACKETS, |
---|
371 | 427 | atomic_long_read(&tunnel->stats.rx_oos_packets), |
---|
372 | 428 | L2TP_ATTR_STATS_PAD) || |
---|
373 | 429 | nla_put_u64_64bit(skb, L2TP_ATTR_RX_ERRORS, |
---|
374 | 430 | 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), |
---|
375 | 434 | L2TP_ATTR_STATS_PAD)) |
---|
376 | 435 | goto nla_put_failure; |
---|
377 | 436 | nla_nest_end(skb, nest); |
---|
378 | 437 | |
---|
379 | | - sk = tunnel->sock; |
---|
380 | | - if (!sk) |
---|
381 | | - goto out; |
---|
| 438 | + if (l2tp_nl_tunnel_send_addr(skb, tunnel)) |
---|
| 439 | + goto nla_put_failure; |
---|
382 | 440 | |
---|
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: |
---|
431 | 441 | genlmsg_end(skb, hdr); |
---|
432 | 442 | return 0; |
---|
433 | 443 | |
---|
.. | .. |
---|
488 | 498 | |
---|
489 | 499 | for (;;) { |
---|
490 | 500 | tunnel = l2tp_tunnel_get_nth(net, ti); |
---|
491 | | - if (tunnel == NULL) |
---|
| 501 | + if (!tunnel) |
---|
492 | 502 | goto out; |
---|
493 | 503 | |
---|
494 | 504 | if (l2tp_nl_tunnel_send(skb, NETLINK_CB(cb->skb).portid, |
---|
.. | .. |
---|
573 | 583 | |
---|
574 | 584 | if (info->attrs[L2TP_ATTR_COOKIE]) { |
---|
575 | 585 | u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]); |
---|
| 586 | + |
---|
576 | 587 | if (len > 8) { |
---|
577 | 588 | ret = -EINVAL; |
---|
578 | 589 | goto out_tunnel; |
---|
.. | .. |
---|
582 | 593 | } |
---|
583 | 594 | if (info->attrs[L2TP_ATTR_PEER_COOKIE]) { |
---|
584 | 595 | u16 len = nla_len(info->attrs[L2TP_ATTR_PEER_COOKIE]); |
---|
| 596 | + |
---|
585 | 597 | if (len > 8) { |
---|
586 | 598 | ret = -EINVAL; |
---|
587 | 599 | goto out_tunnel; |
---|
.. | .. |
---|
592 | 604 | if (info->attrs[L2TP_ATTR_IFNAME]) |
---|
593 | 605 | cfg.ifname = nla_data(info->attrs[L2TP_ATTR_IFNAME]); |
---|
594 | 606 | } |
---|
595 | | - |
---|
596 | | - if (info->attrs[L2TP_ATTR_DEBUG]) |
---|
597 | | - cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); |
---|
598 | 607 | |
---|
599 | 608 | if (info->attrs[L2TP_ATTR_RECV_SEQ]) |
---|
600 | 609 | cfg.recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]); |
---|
.. | .. |
---|
609 | 618 | cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]); |
---|
610 | 619 | |
---|
611 | 620 | #ifdef CONFIG_MODULES |
---|
612 | | - if (l2tp_nl_cmd_ops[cfg.pw_type] == NULL) { |
---|
| 621 | + if (!l2tp_nl_cmd_ops[cfg.pw_type]) { |
---|
613 | 622 | genl_unlock(); |
---|
614 | 623 | request_module("net-l2tp-type-%u", cfg.pw_type); |
---|
615 | 624 | genl_lock(); |
---|
616 | 625 | } |
---|
617 | 626 | #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) { |
---|
620 | 628 | ret = -EPROTONOSUPPORT; |
---|
621 | 629 | goto out_tunnel; |
---|
622 | 630 | } |
---|
.. | .. |
---|
648 | 656 | u16 pw_type; |
---|
649 | 657 | |
---|
650 | 658 | session = l2tp_nl_session_get(info); |
---|
651 | | - if (session == NULL) { |
---|
| 659 | + if (!session) { |
---|
652 | 660 | ret = -ENODEV; |
---|
653 | 661 | goto out; |
---|
654 | 662 | } |
---|
.. | .. |
---|
659 | 667 | pw_type = session->pwtype; |
---|
660 | 668 | if (pw_type < __L2TP_PWTYPE_MAX) |
---|
661 | 669 | 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); |
---|
663 | 671 | |
---|
664 | 672 | l2tp_session_dec_refcount(session); |
---|
665 | 673 | |
---|
.. | .. |
---|
673 | 681 | struct l2tp_session *session; |
---|
674 | 682 | |
---|
675 | 683 | session = l2tp_nl_session_get(info); |
---|
676 | | - if (session == NULL) { |
---|
| 684 | + if (!session) { |
---|
677 | 685 | ret = -ENODEV; |
---|
678 | 686 | goto out; |
---|
679 | 687 | } |
---|
680 | | - |
---|
681 | | - if (info->attrs[L2TP_ATTR_DEBUG]) |
---|
682 | | - session->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); |
---|
683 | 688 | |
---|
684 | 689 | if (info->attrs[L2TP_ATTR_RECV_SEQ]) |
---|
685 | 690 | session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]); |
---|
.. | .. |
---|
718 | 723 | if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) || |
---|
719 | 724 | nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) || |
---|
720 | 725 | 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) || |
---|
724 | 728 | nla_put_u16(skb, L2TP_ATTR_PW_TYPE, session->pwtype)) |
---|
725 | 729 | goto nla_put_failure; |
---|
726 | 730 | |
---|
727 | 731 | if ((session->ifname[0] && |
---|
728 | 732 | nla_put_string(skb, L2TP_ATTR_IFNAME, session->ifname)) || |
---|
729 | 733 | (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)) || |
---|
732 | 735 | (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)) || |
---|
735 | 737 | nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq) || |
---|
736 | 738 | nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq) || |
---|
737 | 739 | nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode) || |
---|
.. | .. |
---|
742 | 744 | session->reorder_timeout, L2TP_ATTR_PAD))) |
---|
743 | 745 | goto nla_put_failure; |
---|
744 | 746 | |
---|
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) |
---|
747 | 749 | goto nla_put_failure; |
---|
748 | 750 | |
---|
749 | 751 | if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS, |
---|
.. | .. |
---|
764 | 766 | nla_put_u64_64bit(skb, L2TP_ATTR_RX_SEQ_DISCARDS, |
---|
765 | 767 | atomic_long_read(&session->stats.rx_seq_discards), |
---|
766 | 768 | 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) || |
---|
767 | 772 | nla_put_u64_64bit(skb, L2TP_ATTR_RX_OOS_PACKETS, |
---|
768 | 773 | atomic_long_read(&session->stats.rx_oos_packets), |
---|
769 | 774 | L2TP_ATTR_STATS_PAD) || |
---|
770 | 775 | nla_put_u64_64bit(skb, L2TP_ATTR_RX_ERRORS, |
---|
771 | 776 | 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), |
---|
772 | 780 | L2TP_ATTR_STATS_PAD)) |
---|
773 | 781 | goto nla_put_failure; |
---|
774 | 782 | nla_nest_end(skb, nest); |
---|
.. | .. |
---|
788 | 796 | int ret; |
---|
789 | 797 | |
---|
790 | 798 | session = l2tp_nl_session_get(info); |
---|
791 | | - if (session == NULL) { |
---|
| 799 | + if (!session) { |
---|
792 | 800 | ret = -ENODEV; |
---|
793 | 801 | goto err; |
---|
794 | 802 | } |
---|
.. | .. |
---|
827 | 835 | int si = cb->args[1]; |
---|
828 | 836 | |
---|
829 | 837 | for (;;) { |
---|
830 | | - if (tunnel == NULL) { |
---|
| 838 | + if (!tunnel) { |
---|
831 | 839 | tunnel = l2tp_tunnel_get_nth(net, ti); |
---|
832 | | - if (tunnel == NULL) |
---|
| 840 | + if (!tunnel) |
---|
833 | 841 | goto out; |
---|
834 | 842 | } |
---|
835 | 843 | |
---|
836 | 844 | session = l2tp_session_get_nth(tunnel, si); |
---|
837 | | - if (session == NULL) { |
---|
| 845 | + if (!session) { |
---|
838 | 846 | ti++; |
---|
839 | 847 | l2tp_tunnel_dec_refcount(tunnel); |
---|
840 | 848 | tunnel = NULL; |
---|
.. | .. |
---|
912 | 920 | }, |
---|
913 | 921 | }; |
---|
914 | 922 | |
---|
915 | | -static const struct genl_ops l2tp_nl_ops[] = { |
---|
| 923 | +static const struct genl_small_ops l2tp_nl_ops[] = { |
---|
916 | 924 | { |
---|
917 | 925 | .cmd = L2TP_CMD_NOOP, |
---|
| 926 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
918 | 927 | .doit = l2tp_nl_cmd_noop, |
---|
919 | | - .policy = l2tp_nl_policy, |
---|
920 | 928 | /* can be retrieved by unprivileged users */ |
---|
921 | 929 | }, |
---|
922 | 930 | { |
---|
923 | 931 | .cmd = L2TP_CMD_TUNNEL_CREATE, |
---|
| 932 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
924 | 933 | .doit = l2tp_nl_cmd_tunnel_create, |
---|
925 | | - .policy = l2tp_nl_policy, |
---|
926 | | - .flags = GENL_ADMIN_PERM, |
---|
| 934 | + .flags = GENL_UNS_ADMIN_PERM, |
---|
927 | 935 | }, |
---|
928 | 936 | { |
---|
929 | 937 | .cmd = L2TP_CMD_TUNNEL_DELETE, |
---|
| 938 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
930 | 939 | .doit = l2tp_nl_cmd_tunnel_delete, |
---|
931 | | - .policy = l2tp_nl_policy, |
---|
932 | | - .flags = GENL_ADMIN_PERM, |
---|
| 940 | + .flags = GENL_UNS_ADMIN_PERM, |
---|
933 | 941 | }, |
---|
934 | 942 | { |
---|
935 | 943 | .cmd = L2TP_CMD_TUNNEL_MODIFY, |
---|
| 944 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
936 | 945 | .doit = l2tp_nl_cmd_tunnel_modify, |
---|
937 | | - .policy = l2tp_nl_policy, |
---|
938 | | - .flags = GENL_ADMIN_PERM, |
---|
| 946 | + .flags = GENL_UNS_ADMIN_PERM, |
---|
939 | 947 | }, |
---|
940 | 948 | { |
---|
941 | 949 | .cmd = L2TP_CMD_TUNNEL_GET, |
---|
| 950 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
942 | 951 | .doit = l2tp_nl_cmd_tunnel_get, |
---|
943 | 952 | .dumpit = l2tp_nl_cmd_tunnel_dump, |
---|
944 | | - .policy = l2tp_nl_policy, |
---|
945 | | - .flags = GENL_ADMIN_PERM, |
---|
| 953 | + .flags = GENL_UNS_ADMIN_PERM, |
---|
946 | 954 | }, |
---|
947 | 955 | { |
---|
948 | 956 | .cmd = L2TP_CMD_SESSION_CREATE, |
---|
| 957 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
949 | 958 | .doit = l2tp_nl_cmd_session_create, |
---|
950 | | - .policy = l2tp_nl_policy, |
---|
951 | | - .flags = GENL_ADMIN_PERM, |
---|
| 959 | + .flags = GENL_UNS_ADMIN_PERM, |
---|
952 | 960 | }, |
---|
953 | 961 | { |
---|
954 | 962 | .cmd = L2TP_CMD_SESSION_DELETE, |
---|
| 963 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
955 | 964 | .doit = l2tp_nl_cmd_session_delete, |
---|
956 | | - .policy = l2tp_nl_policy, |
---|
957 | | - .flags = GENL_ADMIN_PERM, |
---|
| 965 | + .flags = GENL_UNS_ADMIN_PERM, |
---|
958 | 966 | }, |
---|
959 | 967 | { |
---|
960 | 968 | .cmd = L2TP_CMD_SESSION_MODIFY, |
---|
| 969 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
961 | 970 | .doit = l2tp_nl_cmd_session_modify, |
---|
962 | | - .policy = l2tp_nl_policy, |
---|
963 | | - .flags = GENL_ADMIN_PERM, |
---|
| 971 | + .flags = GENL_UNS_ADMIN_PERM, |
---|
964 | 972 | }, |
---|
965 | 973 | { |
---|
966 | 974 | .cmd = L2TP_CMD_SESSION_GET, |
---|
| 975 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
967 | 976 | .doit = l2tp_nl_cmd_session_get, |
---|
968 | 977 | .dumpit = l2tp_nl_cmd_session_dump, |
---|
969 | | - .policy = l2tp_nl_policy, |
---|
970 | | - .flags = GENL_ADMIN_PERM, |
---|
| 978 | + .flags = GENL_UNS_ADMIN_PERM, |
---|
971 | 979 | }, |
---|
972 | 980 | }; |
---|
973 | 981 | |
---|
.. | .. |
---|
976 | 984 | .version = L2TP_GENL_VERSION, |
---|
977 | 985 | .hdrsize = 0, |
---|
978 | 986 | .maxattr = L2TP_ATTR_MAX, |
---|
| 987 | + .policy = l2tp_nl_policy, |
---|
979 | 988 | .netnsok = true, |
---|
980 | 989 | .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), |
---|
983 | 992 | .mcgrps = l2tp_multicast_group, |
---|
984 | 993 | .n_mcgrps = ARRAY_SIZE(l2tp_multicast_group), |
---|
985 | 994 | }; |
---|