^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* L2TP netlink layer, for management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2008,2009,2010 Katalix Systems Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Partly based on the IrDA nelink implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * (see net/irda/irnetlink.c) which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (c) 2007 Samuel Ortiz <samuel@sortiz.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * which is in turn partly based on the wireless netlink code:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <net/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/l2tp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "l2tp_core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static struct genl_family l2tp_nl_family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static const struct genl_multicast_group l2tp_multicast_group[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .name = L2TP_GENL_MCGROUP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int flags, struct l2tp_tunnel *tunnel, u8 cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int flags, struct l2tp_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u8 cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* Accessed under genl lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct l2tp_nl_cmd_ops *l2tp_nl_cmd_ops[__L2TP_PWTYPE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static struct l2tp_session *l2tp_nl_session_get(struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u32 tunnel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u32 session_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) char *ifname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct l2tp_tunnel *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct l2tp_session *session = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct net *net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (info->attrs[L2TP_ATTR_IFNAME]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ifname = nla_data(info->attrs[L2TP_ATTR_IFNAME]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) session = l2tp_session_get_by_ifname(net, ifname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) } else if ((info->attrs[L2TP_ATTR_SESSION_ID]) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) (info->attrs[L2TP_ATTR_CONN_ID])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) session_id = nla_get_u32(info->attrs[L2TP_ATTR_SESSION_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) tunnel = l2tp_tunnel_get(net, tunnel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) session = l2tp_tunnel_get_session(tunnel, session_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static int l2tp_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int ret = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (!msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) &l2tp_nl_family, 0, L2TP_CMD_NOOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (!hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ret = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) genlmsg_end(msg, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return genlmsg_unicast(genl_info_net(info), msg, info->snd_portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int l2tp_tunnel_notify(struct genl_family *family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct genl_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct l2tp_tunnel *tunnel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ret = l2tp_nl_tunnel_send(msg, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) NLM_F_ACK, tunnel, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ret = genlmsg_multicast_allns(family, msg, 0, 0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* We don't care if no one is listening */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (ret == -ESRCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int l2tp_session_notify(struct genl_family *family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct genl_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct l2tp_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ret = l2tp_nl_session_send(msg, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) NLM_F_ACK, session, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ret = genlmsg_multicast_allns(family, msg, 0, 0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* We don't care if no one is listening */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (ret == -ESRCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int l2tp_nl_cmd_tunnel_create_get_addr(struct nlattr **attrs, struct l2tp_tunnel_cfg *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (attrs[L2TP_ATTR_UDP_SPORT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) cfg->local_udp_port = nla_get_u16(attrs[L2TP_ATTR_UDP_SPORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (attrs[L2TP_ATTR_UDP_DPORT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) cfg->peer_udp_port = nla_get_u16(attrs[L2TP_ATTR_UDP_DPORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) cfg->use_udp_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_CSUM]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* Must have either AF_INET or AF_INET6 address for source and destination */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (attrs[L2TP_ATTR_IP6_SADDR] && attrs[L2TP_ATTR_IP6_DADDR]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) cfg->local_ip6 = nla_data(attrs[L2TP_ATTR_IP6_SADDR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) cfg->peer_ip6 = nla_data(attrs[L2TP_ATTR_IP6_DADDR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) cfg->udp6_zero_tx_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_ZERO_CSUM6_TX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) cfg->udp6_zero_rx_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_ZERO_CSUM6_RX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (attrs[L2TP_ATTR_IP_SADDR] && attrs[L2TP_ATTR_IP_DADDR]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) cfg->local_ip.s_addr = nla_get_in_addr(attrs[L2TP_ATTR_IP_SADDR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) cfg->peer_ip.s_addr = nla_get_in_addr(attrs[L2TP_ATTR_IP_DADDR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) u32 tunnel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) u32 peer_tunnel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int proto_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int fd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct l2tp_tunnel_cfg cfg = { 0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct l2tp_tunnel *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct net *net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct nlattr **attrs = info->attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!attrs[L2TP_ATTR_CONN_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) tunnel_id = nla_get_u32(attrs[L2TP_ATTR_CONN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (!attrs[L2TP_ATTR_PEER_CONN_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) peer_tunnel_id = nla_get_u32(attrs[L2TP_ATTR_PEER_CONN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (!attrs[L2TP_ATTR_PROTO_VERSION]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) proto_version = nla_get_u8(attrs[L2TP_ATTR_PROTO_VERSION]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!attrs[L2TP_ATTR_ENCAP_TYPE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) cfg.encap = nla_get_u16(attrs[L2TP_ATTR_ENCAP_TYPE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* Managed tunnels take the tunnel socket from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * Unmanaged tunnels must call out the source and destination addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * for the kernel to create the tunnel socket itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (attrs[L2TP_ATTR_FD]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) fd = nla_get_u32(attrs[L2TP_ATTR_FD]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ret = l2tp_nl_cmd_tunnel_create_get_addr(attrs, &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) switch (cfg.encap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) case L2TP_ENCAPTYPE_UDP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) case L2TP_ENCAPTYPE_IP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ret = l2tp_tunnel_create(fd, proto_version, tunnel_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) peer_tunnel_id, &cfg, &tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) l2tp_tunnel_inc_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ret = l2tp_tunnel_register(tunnel, net, &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) kfree(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) ret = l2tp_tunnel_notify(&l2tp_nl_family, info, tunnel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) L2TP_CMD_TUNNEL_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static int l2tp_nl_cmd_tunnel_delete(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct l2tp_tunnel *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) u32 tunnel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct net *net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (!info->attrs[L2TP_ATTR_CONN_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) tunnel = l2tp_tunnel_get(net, tunnel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) l2tp_tunnel_notify(&l2tp_nl_family, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) tunnel, L2TP_CMD_TUNNEL_DELETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) l2tp_tunnel_delete(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int l2tp_nl_cmd_tunnel_modify(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct l2tp_tunnel *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) u32 tunnel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct net *net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (!info->attrs[L2TP_ATTR_CONN_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) tunnel = l2tp_tunnel_get(net, tunnel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (!tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) ret = l2tp_tunnel_notify(&l2tp_nl_family, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) tunnel, L2TP_CMD_TUNNEL_MODIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static int l2tp_nl_tunnel_send_addr6(struct sk_buff *skb, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) enum l2tp_encap_type encap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) switch (encap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) case L2TP_ENCAPTYPE_UDP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (udp_get_no_check6_tx(sk) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) nla_put_flag(skb, L2TP_ATTR_UDP_ZERO_CSUM6_TX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (udp_get_no_check6_rx(sk) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) nla_put_flag(skb, L2TP_ATTR_UDP_ZERO_CSUM6_RX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (nla_put_u16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) nla_put_u16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) case L2TP_ENCAPTYPE_IP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (nla_put_in6_addr(skb, L2TP_ATTR_IP6_SADDR, &np->saddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) nla_put_in6_addr(skb, L2TP_ATTR_IP6_DADDR, &sk->sk_v6_daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static int l2tp_nl_tunnel_send_addr4(struct sk_buff *skb, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) enum l2tp_encap_type encap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) switch (encap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) case L2TP_ENCAPTYPE_UDP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (nla_put_u8(skb, L2TP_ATTR_UDP_CSUM, !sk->sk_no_check_tx) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) nla_put_u16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) nla_put_u16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) case L2TP_ENCAPTYPE_IP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (nla_put_in_addr(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) nla_put_in_addr(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /* Append attributes for the tunnel address, handling the different attribute types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * used for different tunnel encapsulation and AF_INET v.s. AF_INET6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static int l2tp_nl_tunnel_send_addr(struct sk_buff *skb, struct l2tp_tunnel *tunnel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct sock *sk = tunnel->sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (sk->sk_family == AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return l2tp_nl_tunnel_send_addr6(skb, sk, tunnel->encap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return l2tp_nl_tunnel_send_addr4(skb, sk, tunnel->encap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct l2tp_tunnel *tunnel, u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (!hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) nla_put_u32(skb, L2TP_ATTR_DEBUG, 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) nla_put_u16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (!nest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) atomic_long_read(&tunnel->stats.tx_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) nla_put_u64_64bit(skb, L2TP_ATTR_TX_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) atomic_long_read(&tunnel->stats.tx_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) nla_put_u64_64bit(skb, L2TP_ATTR_TX_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) atomic_long_read(&tunnel->stats.tx_errors),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) nla_put_u64_64bit(skb, L2TP_ATTR_RX_PACKETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) atomic_long_read(&tunnel->stats.rx_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) nla_put_u64_64bit(skb, L2TP_ATTR_RX_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) atomic_long_read(&tunnel->stats.rx_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) nla_put_u64_64bit(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) atomic_long_read(&tunnel->stats.rx_seq_discards),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) nla_put_u64_64bit(skb, L2TP_ATTR_RX_COOKIE_DISCARDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) atomic_long_read(&tunnel->stats.rx_cookie_discards),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) nla_put_u64_64bit(skb, L2TP_ATTR_RX_OOS_PACKETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) atomic_long_read(&tunnel->stats.rx_oos_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) nla_put_u64_64bit(skb, L2TP_ATTR_RX_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) atomic_long_read(&tunnel->stats.rx_errors),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) nla_put_u64_64bit(skb, L2TP_ATTR_RX_INVALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) atomic_long_read(&tunnel->stats.rx_invalid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) L2TP_ATTR_STATS_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (l2tp_nl_tunnel_send_addr(skb, tunnel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) genlmsg_end(skb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) genlmsg_cancel(skb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static int l2tp_nl_cmd_tunnel_get(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct l2tp_tunnel *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) u32 tunnel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) int ret = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct net *net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (!info->attrs[L2TP_ATTR_CONN_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (!msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) tunnel = l2tp_tunnel_get(net, tunnel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (!tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) goto err_nlmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) ret = l2tp_nl_tunnel_send(msg, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) NLM_F_ACK, tunnel, L2TP_CMD_TUNNEL_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) goto err_nlmsg_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return genlmsg_unicast(net, msg, info->snd_portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) err_nlmsg_tunnel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) err_nlmsg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static int l2tp_nl_cmd_tunnel_dump(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) int ti = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct l2tp_tunnel *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) tunnel = l2tp_tunnel_get_nth(net, ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (!tunnel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (l2tp_nl_tunnel_send(skb, NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) cb->nlh->nlmsg_seq, NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) tunnel, L2TP_CMD_TUNNEL_GET) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) ti++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) cb->args[0] = ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) u32 tunnel_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) u32 session_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) u32 peer_session_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct l2tp_tunnel *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct l2tp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct l2tp_session_cfg cfg = { 0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct net *net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (!info->attrs[L2TP_ATTR_CONN_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) tunnel = l2tp_tunnel_get(net, tunnel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (!tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (!info->attrs[L2TP_ATTR_SESSION_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) session_id = nla_get_u32(info->attrs[L2TP_ATTR_SESSION_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (!info->attrs[L2TP_ATTR_PEER_SESSION_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) peer_session_id = nla_get_u32(info->attrs[L2TP_ATTR_PEER_SESSION_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (!info->attrs[L2TP_ATTR_PW_TYPE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) cfg.pw_type = nla_get_u16(info->attrs[L2TP_ATTR_PW_TYPE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (cfg.pw_type >= __L2TP_PWTYPE_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /* L2TPv2 only accepts PPP pseudo-wires */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (tunnel->version == 2 && cfg.pw_type != L2TP_PWTYPE_PPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) ret = -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (tunnel->version > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (info->attrs[L2TP_ATTR_L2SPEC_TYPE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) cfg.l2specific_type = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_TYPE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (cfg.l2specific_type != L2TP_L2SPECTYPE_DEFAULT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) cfg.l2specific_type != L2TP_L2SPECTYPE_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (info->attrs[L2TP_ATTR_COOKIE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (len > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) cfg.cookie_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) memcpy(&cfg.cookie[0], nla_data(info->attrs[L2TP_ATTR_COOKIE]), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (info->attrs[L2TP_ATTR_PEER_COOKIE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) u16 len = nla_len(info->attrs[L2TP_ATTR_PEER_COOKIE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (len > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) cfg.peer_cookie_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) memcpy(&cfg.peer_cookie[0], nla_data(info->attrs[L2TP_ATTR_PEER_COOKIE]), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (info->attrs[L2TP_ATTR_IFNAME])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) cfg.ifname = nla_data(info->attrs[L2TP_ATTR_IFNAME]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (info->attrs[L2TP_ATTR_RECV_SEQ])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) cfg.recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (info->attrs[L2TP_ATTR_SEND_SEQ])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) cfg.send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (info->attrs[L2TP_ATTR_LNS_MODE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) cfg.lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (info->attrs[L2TP_ATTR_RECV_TIMEOUT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) #ifdef CONFIG_MODULES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (!l2tp_nl_cmd_ops[cfg.pw_type]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) genl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) request_module("net-l2tp-type-%u", cfg.pw_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) genl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (!l2tp_nl_cmd_ops[cfg.pw_type] || !l2tp_nl_cmd_ops[cfg.pw_type]->session_create) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) ret = -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) goto out_tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ret = l2tp_nl_cmd_ops[cfg.pw_type]->session_create(net, tunnel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) session_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) peer_session_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) session = l2tp_tunnel_get_session(tunnel, session_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) ret = l2tp_session_notify(&l2tp_nl_family, info, session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) L2TP_CMD_SESSION_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) l2tp_session_dec_refcount(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) out_tunnel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static int l2tp_nl_cmd_session_delete(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct l2tp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) u16 pw_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) session = l2tp_nl_session_get(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (!session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) l2tp_session_notify(&l2tp_nl_family, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) session, L2TP_CMD_SESSION_DELETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) pw_type = session->pwtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (pw_type < __L2TP_PWTYPE_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (l2tp_nl_cmd_ops[pw_type] && l2tp_nl_cmd_ops[pw_type]->session_delete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) l2tp_nl_cmd_ops[pw_type]->session_delete(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) l2tp_session_dec_refcount(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct l2tp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) session = l2tp_nl_session_get(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (!session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (info->attrs[L2TP_ATTR_RECV_SEQ])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (info->attrs[L2TP_ATTR_SEND_SEQ]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) session->send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) l2tp_session_set_header_len(session, session->tunnel->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (info->attrs[L2TP_ATTR_LNS_MODE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) session->lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (info->attrs[L2TP_ATTR_RECV_TIMEOUT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) session->reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) ret = l2tp_session_notify(&l2tp_nl_family, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) session, L2TP_CMD_SESSION_MODIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) l2tp_session_dec_refcount(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) struct l2tp_session *session, u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) struct l2tp_tunnel *tunnel = session->tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (!hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) nla_put_u32(skb, L2TP_ATTR_PEER_SESSION_ID, session->peer_session_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) nla_put_u32(skb, L2TP_ATTR_DEBUG, 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) nla_put_u16(skb, L2TP_ATTR_PW_TYPE, session->pwtype))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if ((session->ifname[0] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) nla_put_string(skb, L2TP_ATTR_IFNAME, session->ifname)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) (session->cookie_len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) nla_put(skb, L2TP_ATTR_COOKIE, session->cookie_len, session->cookie)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) (session->peer_cookie_len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len, session->peer_cookie)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) (l2tp_tunnel_uses_xfrm(tunnel) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) nla_put_u8(skb, L2TP_ATTR_USING_IPSEC, 1)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) (session->reorder_timeout &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) nla_put_msecs(skb, L2TP_ATTR_RECV_TIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) session->reorder_timeout, L2TP_ATTR_PAD)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (!nest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (nla_put_u64_64bit(skb, L2TP_ATTR_TX_PACKETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) atomic_long_read(&session->stats.tx_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) nla_put_u64_64bit(skb, L2TP_ATTR_TX_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) atomic_long_read(&session->stats.tx_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) nla_put_u64_64bit(skb, L2TP_ATTR_TX_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) atomic_long_read(&session->stats.tx_errors),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) nla_put_u64_64bit(skb, L2TP_ATTR_RX_PACKETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) atomic_long_read(&session->stats.rx_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) nla_put_u64_64bit(skb, L2TP_ATTR_RX_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) atomic_long_read(&session->stats.rx_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) nla_put_u64_64bit(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) atomic_long_read(&session->stats.rx_seq_discards),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) nla_put_u64_64bit(skb, L2TP_ATTR_RX_COOKIE_DISCARDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) atomic_long_read(&session->stats.rx_cookie_discards),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) nla_put_u64_64bit(skb, L2TP_ATTR_RX_OOS_PACKETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) atomic_long_read(&session->stats.rx_oos_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) nla_put_u64_64bit(skb, L2TP_ATTR_RX_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) atomic_long_read(&session->stats.rx_errors),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) L2TP_ATTR_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) nla_put_u64_64bit(skb, L2TP_ATTR_RX_INVALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) atomic_long_read(&session->stats.rx_invalid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) L2TP_ATTR_STATS_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) genlmsg_end(skb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) genlmsg_cancel(skb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) static int l2tp_nl_cmd_session_get(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct l2tp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct sk_buff *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) session = l2tp_nl_session_get(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) if (!session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (!msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) goto err_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) ret = l2tp_nl_session_send(msg, info->snd_portid, info->snd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 0, session, L2TP_CMD_SESSION_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) goto err_ref_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) ret = genlmsg_unicast(genl_info_net(info), msg, info->snd_portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) l2tp_session_dec_refcount(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) err_ref_msg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) nlmsg_free(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) err_ref:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) l2tp_session_dec_refcount(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) static int l2tp_nl_cmd_session_dump(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct l2tp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) struct l2tp_tunnel *tunnel = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) int ti = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) int si = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (!tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) tunnel = l2tp_tunnel_get_nth(net, ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (!tunnel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) session = l2tp_session_get_nth(tunnel, si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (!session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) ti++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) tunnel = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) si = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) if (l2tp_nl_session_send(skb, NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) cb->nlh->nlmsg_seq, NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) session, L2TP_CMD_SESSION_GET) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) l2tp_session_dec_refcount(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) l2tp_tunnel_dec_refcount(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) l2tp_session_dec_refcount(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) si++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) cb->args[0] = ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) cb->args[1] = si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) static const struct nla_policy l2tp_nl_policy[L2TP_ATTR_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) [L2TP_ATTR_NONE] = { .type = NLA_UNSPEC, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) [L2TP_ATTR_PW_TYPE] = { .type = NLA_U16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) [L2TP_ATTR_ENCAP_TYPE] = { .type = NLA_U16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) [L2TP_ATTR_OFFSET] = { .type = NLA_U16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) [L2TP_ATTR_DATA_SEQ] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) [L2TP_ATTR_L2SPEC_TYPE] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) [L2TP_ATTR_L2SPEC_LEN] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) [L2TP_ATTR_PROTO_VERSION] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) [L2TP_ATTR_CONN_ID] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) [L2TP_ATTR_PEER_CONN_ID] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) [L2TP_ATTR_SESSION_ID] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) [L2TP_ATTR_PEER_SESSION_ID] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) [L2TP_ATTR_UDP_CSUM] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) [L2TP_ATTR_VLAN_ID] = { .type = NLA_U16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) [L2TP_ATTR_DEBUG] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) [L2TP_ATTR_RECV_SEQ] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) [L2TP_ATTR_SEND_SEQ] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) [L2TP_ATTR_LNS_MODE] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) [L2TP_ATTR_USING_IPSEC] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) [L2TP_ATTR_RECV_TIMEOUT] = { .type = NLA_MSECS, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) [L2TP_ATTR_FD] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) [L2TP_ATTR_IP_SADDR] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) [L2TP_ATTR_IP_DADDR] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) [L2TP_ATTR_UDP_SPORT] = { .type = NLA_U16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) [L2TP_ATTR_UDP_DPORT] = { .type = NLA_U16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) [L2TP_ATTR_MTU] = { .type = NLA_U16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) [L2TP_ATTR_MRU] = { .type = NLA_U16, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) [L2TP_ATTR_STATS] = { .type = NLA_NESTED, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) [L2TP_ATTR_IP6_SADDR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) .type = NLA_BINARY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) .len = sizeof(struct in6_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) [L2TP_ATTR_IP6_DADDR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) .type = NLA_BINARY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) .len = sizeof(struct in6_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) [L2TP_ATTR_IFNAME] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) .type = NLA_NUL_STRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) .len = IFNAMSIZ - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) [L2TP_ATTR_COOKIE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) .type = NLA_BINARY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) .len = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) [L2TP_ATTR_PEER_COOKIE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) .type = NLA_BINARY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) .len = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) static const struct genl_small_ops l2tp_nl_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) .cmd = L2TP_CMD_NOOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) .doit = l2tp_nl_cmd_noop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) /* can be retrieved by unprivileged users */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) .cmd = L2TP_CMD_TUNNEL_CREATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) .doit = l2tp_nl_cmd_tunnel_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) .flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) .cmd = L2TP_CMD_TUNNEL_DELETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) .doit = l2tp_nl_cmd_tunnel_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) .flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) .cmd = L2TP_CMD_TUNNEL_MODIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) .doit = l2tp_nl_cmd_tunnel_modify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) .flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) .cmd = L2TP_CMD_TUNNEL_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) .doit = l2tp_nl_cmd_tunnel_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) .dumpit = l2tp_nl_cmd_tunnel_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) .flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) .cmd = L2TP_CMD_SESSION_CREATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) .doit = l2tp_nl_cmd_session_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) .flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) .cmd = L2TP_CMD_SESSION_DELETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) .doit = l2tp_nl_cmd_session_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) .flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) .cmd = L2TP_CMD_SESSION_MODIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) .doit = l2tp_nl_cmd_session_modify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) .flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) .cmd = L2TP_CMD_SESSION_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) .doit = l2tp_nl_cmd_session_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) .dumpit = l2tp_nl_cmd_session_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) .flags = GENL_UNS_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) static struct genl_family l2tp_nl_family __ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) .name = L2TP_GENL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) .version = L2TP_GENL_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) .hdrsize = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) .maxattr = L2TP_ATTR_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) .policy = l2tp_nl_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) .netnsok = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) .small_ops = l2tp_nl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) .n_small_ops = ARRAY_SIZE(l2tp_nl_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) .mcgrps = l2tp_multicast_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) .n_mcgrps = ARRAY_SIZE(l2tp_multicast_group),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) int l2tp_nl_register_ops(enum l2tp_pwtype pw_type, const struct l2tp_nl_cmd_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) if (pw_type >= __L2TP_PWTYPE_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) genl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (l2tp_nl_cmd_ops[pw_type])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) l2tp_nl_cmd_ops[pw_type] = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) genl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) EXPORT_SYMBOL_GPL(l2tp_nl_register_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) void l2tp_nl_unregister_ops(enum l2tp_pwtype pw_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (pw_type < __L2TP_PWTYPE_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) genl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) l2tp_nl_cmd_ops[pw_type] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) genl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) EXPORT_SYMBOL_GPL(l2tp_nl_unregister_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) static int __init l2tp_nl_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) pr_info("L2TP netlink interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) return genl_register_family(&l2tp_nl_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) static void l2tp_nl_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) genl_unregister_family(&l2tp_nl_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) module_init(l2tp_nl_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) module_exit(l2tp_nl_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) MODULE_DESCRIPTION("L2TP netlink");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) MODULE_VERSION("1.0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) MODULE_ALIAS_GENL_FAMILY("l2tp");