17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/udp.h>
24 #include <linux/socket.h>
25 #include <linux/module.h>
26 #include <linux/list.h>
29 #include <linux/l2tp.h>
52 struct net *
net = genl_info_net(info);
88 genlmsg_end(msg, hdr);
90 return genlmsg_unicast(genl_info_net(info), msg, info->
snd_portid);
99 static int l2tp_nl_cmd_tunnel_create(
struct sk_buff *skb,
struct genl_info *info)
108 struct net *net = genl_info_net(info);
138 #if IS_ENABLED(CONFIG_IPV6)
141 cfg.local_ip6 = nla_data(
143 cfg.peer_ip6 = nla_data(
151 cfg.
peer_ip.s_addr = nla_get_be32(
169 if (tunnel !=
NULL) {
179 peer_tunnel_id, &cfg, &tunnel);
187 static int l2tp_nl_cmd_tunnel_delete(
struct sk_buff *skb,
struct genl_info *info)
192 struct net *net = genl_info_net(info);
201 if (tunnel ==
NULL) {
212 static int l2tp_nl_cmd_tunnel_modify(
struct sk_buff *skb,
struct genl_info *info)
217 struct net *net = genl_info_net(info);
226 if (tunnel ==
NULL) {
245 #if IS_ENABLED(CONFIG_IPV6)
251 hdr =
genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags,
261 goto nla_put_failure;
265 goto nla_put_failure;
268 start = u64_stats_fetch_begin(&tunnel->
stats.syncp);
275 stats.rx_seq_discards = tunnel->
stats.rx_seq_discards;
276 stats.rx_oos_packets = tunnel->
stats.rx_oos_packets;
277 }
while (u64_stats_fetch_retry(&tunnel->
stats.syncp, start));
285 stats.rx_seq_discards) ||
287 stats.rx_oos_packets) ||
289 goto nla_put_failure;
290 nla_nest_end(skb, nest);
296 #if IS_ENABLED(CONFIG_IPV6)
303 switch (tunnel->
encap) {
309 goto nla_put_failure;
312 #if IS_ENABLED(CONFIG_IPV6)
318 goto nla_put_failure;
323 goto nla_put_failure;
328 return genlmsg_end(skb, hdr);
331 genlmsg_cancel(skb, hdr);
335 static int l2tp_nl_cmd_tunnel_get(
struct sk_buff *skb,
struct genl_info *info)
341 struct net *net = genl_info_net(info);
351 if (tunnel ==
NULL) {
367 return genlmsg_unicast(net, msg, info->
snd_portid);
378 int ti = cb->
args[0];
380 struct net *net = sock_net(skb->
sk);
401 static int l2tp_nl_cmd_session_create(
struct sk_buff *skb,
struct genl_info *info)
410 struct net *net = genl_info_net(info);
541 session_id, peer_session_id, &cfg);
547 static int l2tp_nl_cmd_session_delete(
struct sk_buff *skb,
struct genl_info *info)
553 session = l2tp_nl_session_find(info);
554 if (session ==
NULL) {
559 pw_type = session->
pwtype;
561 if (l2tp_nl_cmd_ops[pw_type] && l2tp_nl_cmd_ops[pw_type]->session_delete)
568 static int l2tp_nl_cmd_session_modify(
struct sk_buff *skb,
struct genl_info *info)
573 session = l2tp_nl_session_find(info);
574 if (session ==
NULL) {
607 static int l2tp_nl_session_send(
struct sk_buff *skb,
u32 portid,
u32 seq,
int flags,
633 goto nla_put_failure;
647 (((sk) && (sk->sk_policy[0] || sk->sk_policy[1])) &&
652 goto nla_put_failure;
656 goto nla_put_failure;
659 start = u64_stats_fetch_begin(&session->
stats.syncp);
666 stats.rx_seq_discards = session->
stats.rx_seq_discards;
667 stats.rx_oos_packets = session->
stats.rx_oos_packets;
668 }
while (u64_stats_fetch_retry(&session->
stats.syncp, start));
676 stats.rx_seq_discards) ||
678 stats.rx_oos_packets) ||
680 goto nla_put_failure;
681 nla_nest_end(skb, nest);
683 return genlmsg_end(skb, hdr);
686 genlmsg_cancel(skb, hdr);
690 static int l2tp_nl_cmd_session_get(
struct sk_buff *skb,
struct genl_info *info)
696 session = l2tp_nl_session_find(info);
697 if (session ==
NULL) {
713 return genlmsg_unicast(genl_info_net(info), msg, info->
snd_portid);
724 struct net *net = sock_net(skb->
sk);
727 int ti = cb->
args[0];
728 int si = cb->
args[1];
731 if (tunnel ==
NULL) {
738 if (session ==
NULL) {
811 static struct genl_ops l2tp_nl_ops[] = {
814 .doit = l2tp_nl_cmd_noop,
815 .policy = l2tp_nl_policy,
820 .doit = l2tp_nl_cmd_tunnel_create,
821 .policy = l2tp_nl_policy,
826 .doit = l2tp_nl_cmd_tunnel_delete,
827 .policy = l2tp_nl_policy,
832 .doit = l2tp_nl_cmd_tunnel_modify,
833 .policy = l2tp_nl_policy,
838 .doit = l2tp_nl_cmd_tunnel_get,
839 .dumpit = l2tp_nl_cmd_tunnel_dump,
840 .policy = l2tp_nl_policy,
845 .doit = l2tp_nl_cmd_session_create,
846 .policy = l2tp_nl_policy,
851 .doit = l2tp_nl_cmd_session_delete,
852 .policy = l2tp_nl_policy,
857 .doit = l2tp_nl_cmd_session_modify,
858 .policy = l2tp_nl_policy,
863 .doit = l2tp_nl_cmd_session_get,
864 .dumpit = l2tp_nl_cmd_session_dump,
865 .policy = l2tp_nl_policy,
880 if (l2tp_nl_cmd_ops[pw_type])
883 l2tp_nl_cmd_ops[pw_type] = ops;
897 l2tp_nl_cmd_ops[pw_type] =
NULL;
903 static int l2tp_nl_init(
void)
907 pr_info(
"L2TP netlink interface\n");
914 static void l2tp_nl_cleanup(
void)