2 * L2TP netlink layer, for management
4 * Copyright (c) 2008,2009,2010 Katalix Systems Ltd
6 * Partly based on the IrDA nelink implementation
7 * (see net/irda/irnetlink.c) which is:
8 * Copyright (c) 2007 Samuel Ortiz <samuel@sortiz.org>
9 * which is in turn partly based on the wireless netlink code:
10 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
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.
18 #include <net/genetlink.h>
21 #include <linux/udp.h>
22 #include <linux/socket.h>
23 #include <linux/module.h>
24 #include <linux/list.h>
25 #include <net/net_namespace.h>
27 #include <linux/l2tp.h>
29 #include "l2tp_core.h"
32 static struct genl_family l2tp_nl_family = {
33 .id = GENL_ID_GENERATE,
34 .name = L2TP_GENL_NAME,
35 .version = L2TP_GENL_VERSION,
37 .maxattr = L2TP_ATTR_MAX,
40 /* Accessed under genl lock */
41 static const struct l2tp_nl_cmd_ops *l2tp_nl_cmd_ops[__L2TP_PWTYPE_MAX];
43 static struct l2tp_session *l2tp_nl_session_find(struct genl_info *info)
48 struct l2tp_tunnel *tunnel;
49 struct l2tp_session *session = NULL;
50 struct net *net = genl_info_net(info);
52 if (info->attrs[L2TP_ATTR_IFNAME]) {
53 ifname = nla_data(info->attrs[L2TP_ATTR_IFNAME]);
54 session = l2tp_session_find_by_ifname(net, ifname);
55 } else if ((info->attrs[L2TP_ATTR_SESSION_ID]) &&
56 (info->attrs[L2TP_ATTR_CONN_ID])) {
57 tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
58 session_id = nla_get_u32(info->attrs[L2TP_ATTR_SESSION_ID]);
59 tunnel = l2tp_tunnel_find(net, tunnel_id);
61 session = l2tp_session_find(net, tunnel, session_id);
67 static int l2tp_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
73 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
79 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
80 &l2tp_nl_family, 0, L2TP_CMD_NOOP);
86 genlmsg_end(msg, hdr);
88 return genlmsg_unicast(genl_info_net(info), msg, info->snd_pid);
97 static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info)
104 struct l2tp_tunnel_cfg cfg = { 0, };
105 struct l2tp_tunnel *tunnel;
106 struct net *net = genl_info_net(info);
108 if (!info->attrs[L2TP_ATTR_CONN_ID]) {
112 tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
114 if (!info->attrs[L2TP_ATTR_PEER_CONN_ID]) {
118 peer_tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_PEER_CONN_ID]);
120 if (!info->attrs[L2TP_ATTR_PROTO_VERSION]) {
124 proto_version = nla_get_u8(info->attrs[L2TP_ATTR_PROTO_VERSION]);
126 if (!info->attrs[L2TP_ATTR_ENCAP_TYPE]) {
130 cfg.encap = nla_get_u16(info->attrs[L2TP_ATTR_ENCAP_TYPE]);
133 if (info->attrs[L2TP_ATTR_FD]) {
134 fd = nla_get_u32(info->attrs[L2TP_ATTR_FD]);
136 if (info->attrs[L2TP_ATTR_IP_SADDR])
137 cfg.local_ip.s_addr = nla_get_be32(info->attrs[L2TP_ATTR_IP_SADDR]);
138 if (info->attrs[L2TP_ATTR_IP_DADDR])
139 cfg.peer_ip.s_addr = nla_get_be32(info->attrs[L2TP_ATTR_IP_DADDR]);
140 if (info->attrs[L2TP_ATTR_UDP_SPORT])
141 cfg.local_udp_port = nla_get_u16(info->attrs[L2TP_ATTR_UDP_SPORT]);
142 if (info->attrs[L2TP_ATTR_UDP_DPORT])
143 cfg.peer_udp_port = nla_get_u16(info->attrs[L2TP_ATTR_UDP_DPORT]);
144 if (info->attrs[L2TP_ATTR_UDP_CSUM])
145 cfg.use_udp_checksums = nla_get_flag(info->attrs[L2TP_ATTR_UDP_CSUM]);
148 if (info->attrs[L2TP_ATTR_DEBUG])
149 cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]);
151 tunnel = l2tp_tunnel_find(net, tunnel_id);
152 if (tunnel != NULL) {
159 case L2TP_ENCAPTYPE_UDP:
160 case L2TP_ENCAPTYPE_IP:
161 ret = l2tp_tunnel_create(net, fd, proto_version, tunnel_id,
162 peer_tunnel_id, &cfg, &tunnel);
170 static int l2tp_nl_cmd_tunnel_delete(struct sk_buff *skb, struct genl_info *info)
172 struct l2tp_tunnel *tunnel;
175 struct net *net = genl_info_net(info);
177 if (!info->attrs[L2TP_ATTR_CONN_ID]) {
181 tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
183 tunnel = l2tp_tunnel_find(net, tunnel_id);
184 if (tunnel == NULL) {
189 (void) l2tp_tunnel_delete(tunnel);
195 static int l2tp_nl_cmd_tunnel_modify(struct sk_buff *skb, struct genl_info *info)
197 struct l2tp_tunnel *tunnel;
200 struct net *net = genl_info_net(info);
202 if (!info->attrs[L2TP_ATTR_CONN_ID]) {
206 tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
208 tunnel = l2tp_tunnel_find(net, tunnel_id);
209 if (tunnel == NULL) {
214 if (info->attrs[L2TP_ATTR_DEBUG])
215 tunnel->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]);
221 static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
222 struct l2tp_tunnel *tunnel)
226 struct sock *sk = NULL;
227 struct inet_sock *inet;
228 struct l2tp_stats stats;
231 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags,
232 L2TP_CMD_TUNNEL_GET);
236 if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) ||
237 nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
238 nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
239 nla_put_u32(skb, L2TP_ATTR_DEBUG, tunnel->debug) ||
240 nla_put_u16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap))
241 goto nla_put_failure;
243 nest = nla_nest_start(skb, L2TP_ATTR_STATS);
245 goto nla_put_failure;
248 start = u64_stats_fetch_begin(&tunnel->stats.syncp);
249 stats.tx_packets = tunnel->stats.tx_packets;
250 stats.tx_bytes = tunnel->stats.tx_bytes;
251 stats.tx_errors = tunnel->stats.tx_errors;
252 stats.rx_packets = tunnel->stats.rx_packets;
253 stats.rx_bytes = tunnel->stats.rx_bytes;
254 stats.rx_errors = tunnel->stats.rx_errors;
255 stats.rx_seq_discards = tunnel->stats.rx_seq_discards;
256 stats.rx_oos_packets = tunnel->stats.rx_oos_packets;
257 } while (u64_stats_fetch_retry(&tunnel->stats.syncp, start));
259 if (nla_put_u64(skb, L2TP_ATTR_TX_PACKETS, stats.tx_packets) ||
260 nla_put_u64(skb, L2TP_ATTR_TX_BYTES, stats.tx_bytes) ||
261 nla_put_u64(skb, L2TP_ATTR_TX_ERRORS, stats.tx_errors) ||
262 nla_put_u64(skb, L2TP_ATTR_RX_PACKETS, stats.rx_packets) ||
263 nla_put_u64(skb, L2TP_ATTR_RX_BYTES, stats.rx_bytes) ||
264 nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
265 stats.rx_seq_discards) ||
266 nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS,
267 stats.rx_oos_packets) ||
268 nla_put_u64(skb, L2TP_ATTR_RX_ERRORS, stats.rx_errors))
269 goto nla_put_failure;
270 nla_nest_end(skb, nest);
278 switch (tunnel->encap) {
279 case L2TP_ENCAPTYPE_UDP:
280 if (nla_put_u16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)) ||
281 nla_put_u16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)) ||
282 nla_put_u8(skb, L2TP_ATTR_UDP_CSUM,
283 (sk->sk_no_check != UDP_CSUM_NOXMIT)))
284 goto nla_put_failure;
286 case L2TP_ENCAPTYPE_IP:
287 if (nla_put_be32(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr) ||
288 nla_put_be32(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr))
289 goto nla_put_failure;
294 return genlmsg_end(skb, hdr);
297 genlmsg_cancel(skb, hdr);
301 static int l2tp_nl_cmd_tunnel_get(struct sk_buff *skb, struct genl_info *info)
303 struct l2tp_tunnel *tunnel;
307 struct net *net = genl_info_net(info);
309 if (!info->attrs[L2TP_ATTR_CONN_ID]) {
314 tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
316 tunnel = l2tp_tunnel_find(net, tunnel_id);
317 if (tunnel == NULL) {
322 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
328 ret = l2tp_nl_tunnel_send(msg, info->snd_pid, info->snd_seq,
333 return genlmsg_unicast(net, msg, info->snd_pid);
342 static int l2tp_nl_cmd_tunnel_dump(struct sk_buff *skb, struct netlink_callback *cb)
344 int ti = cb->args[0];
345 struct l2tp_tunnel *tunnel;
346 struct net *net = sock_net(skb->sk);
349 tunnel = l2tp_tunnel_find_nth(net, ti);
353 if (l2tp_nl_tunnel_send(skb, NETLINK_CB(cb->skb).pid,
354 cb->nlh->nlmsg_seq, NLM_F_MULTI,
367 static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *info)
373 struct l2tp_tunnel *tunnel;
374 struct l2tp_session *session;
375 struct l2tp_session_cfg cfg = { 0, };
376 struct net *net = genl_info_net(info);
378 if (!info->attrs[L2TP_ATTR_CONN_ID]) {
382 tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]);
383 tunnel = l2tp_tunnel_find(net, tunnel_id);
389 if (!info->attrs[L2TP_ATTR_SESSION_ID]) {
393 session_id = nla_get_u32(info->attrs[L2TP_ATTR_SESSION_ID]);
394 session = l2tp_session_find(net, tunnel, session_id);
400 if (!info->attrs[L2TP_ATTR_PEER_SESSION_ID]) {
404 peer_session_id = nla_get_u32(info->attrs[L2TP_ATTR_PEER_SESSION_ID]);
406 if (!info->attrs[L2TP_ATTR_PW_TYPE]) {
410 cfg.pw_type = nla_get_u16(info->attrs[L2TP_ATTR_PW_TYPE]);
411 if (cfg.pw_type >= __L2TP_PWTYPE_MAX) {
416 if (tunnel->version > 2) {
417 if (info->attrs[L2TP_ATTR_OFFSET])
418 cfg.offset = nla_get_u16(info->attrs[L2TP_ATTR_OFFSET]);
420 if (info->attrs[L2TP_ATTR_DATA_SEQ])
421 cfg.data_seq = nla_get_u8(info->attrs[L2TP_ATTR_DATA_SEQ]);
423 cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT;
424 if (info->attrs[L2TP_ATTR_L2SPEC_TYPE])
425 cfg.l2specific_type = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_TYPE]);
427 cfg.l2specific_len = 4;
428 if (info->attrs[L2TP_ATTR_L2SPEC_LEN])
429 cfg.l2specific_len = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_LEN]);
431 if (info->attrs[L2TP_ATTR_COOKIE]) {
432 u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]);
437 cfg.cookie_len = len;
438 memcpy(&cfg.cookie[0], nla_data(info->attrs[L2TP_ATTR_COOKIE]), len);
440 if (info->attrs[L2TP_ATTR_PEER_COOKIE]) {
441 u16 len = nla_len(info->attrs[L2TP_ATTR_PEER_COOKIE]);
446 cfg.peer_cookie_len = len;
447 memcpy(&cfg.peer_cookie[0], nla_data(info->attrs[L2TP_ATTR_PEER_COOKIE]), len);
449 if (info->attrs[L2TP_ATTR_IFNAME])
450 cfg.ifname = nla_data(info->attrs[L2TP_ATTR_IFNAME]);
452 if (info->attrs[L2TP_ATTR_VLAN_ID])
453 cfg.vlan_id = nla_get_u16(info->attrs[L2TP_ATTR_VLAN_ID]);
456 if (info->attrs[L2TP_ATTR_DEBUG])
457 cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]);
459 if (info->attrs[L2TP_ATTR_RECV_SEQ])
460 cfg.recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]);
462 if (info->attrs[L2TP_ATTR_SEND_SEQ])
463 cfg.send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]);
465 if (info->attrs[L2TP_ATTR_LNS_MODE])
466 cfg.lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]);
468 if (info->attrs[L2TP_ATTR_RECV_TIMEOUT])
469 cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);
471 if (info->attrs[L2TP_ATTR_MTU])
472 cfg.mtu = nla_get_u16(info->attrs[L2TP_ATTR_MTU]);
474 if (info->attrs[L2TP_ATTR_MRU])
475 cfg.mru = nla_get_u16(info->attrs[L2TP_ATTR_MRU]);
477 if ((l2tp_nl_cmd_ops[cfg.pw_type] == NULL) ||
478 (l2tp_nl_cmd_ops[cfg.pw_type]->session_create == NULL)) {
479 ret = -EPROTONOSUPPORT;
483 /* Check that pseudowire-specific params are present */
484 switch (cfg.pw_type) {
485 case L2TP_PWTYPE_NONE:
487 case L2TP_PWTYPE_ETH_VLAN:
488 if (!info->attrs[L2TP_ATTR_VLAN_ID]) {
493 case L2TP_PWTYPE_ETH:
495 case L2TP_PWTYPE_PPP:
496 case L2TP_PWTYPE_PPP_AC:
500 ret = -EPROTONOSUPPORT;
504 ret = -EPROTONOSUPPORT;
505 if (l2tp_nl_cmd_ops[cfg.pw_type]->session_create)
506 ret = (*l2tp_nl_cmd_ops[cfg.pw_type]->session_create)(net, tunnel_id,
507 session_id, peer_session_id, &cfg);
513 static int l2tp_nl_cmd_session_delete(struct sk_buff *skb, struct genl_info *info)
516 struct l2tp_session *session;
519 session = l2tp_nl_session_find(info);
520 if (session == NULL) {
525 pw_type = session->pwtype;
526 if (pw_type < __L2TP_PWTYPE_MAX)
527 if (l2tp_nl_cmd_ops[pw_type] && l2tp_nl_cmd_ops[pw_type]->session_delete)
528 ret = (*l2tp_nl_cmd_ops[pw_type]->session_delete)(session);
534 static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *info)
537 struct l2tp_session *session;
539 session = l2tp_nl_session_find(info);
540 if (session == NULL) {
545 if (info->attrs[L2TP_ATTR_DEBUG])
546 session->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]);
548 if (info->attrs[L2TP_ATTR_DATA_SEQ])
549 session->data_seq = nla_get_u8(info->attrs[L2TP_ATTR_DATA_SEQ]);
551 if (info->attrs[L2TP_ATTR_RECV_SEQ])
552 session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]);
554 if (info->attrs[L2TP_ATTR_SEND_SEQ])
555 session->send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]);
557 if (info->attrs[L2TP_ATTR_LNS_MODE])
558 session->lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]);
560 if (info->attrs[L2TP_ATTR_RECV_TIMEOUT])
561 session->reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]);
563 if (info->attrs[L2TP_ATTR_MTU])
564 session->mtu = nla_get_u16(info->attrs[L2TP_ATTR_MTU]);
566 if (info->attrs[L2TP_ATTR_MRU])
567 session->mru = nla_get_u16(info->attrs[L2TP_ATTR_MRU]);
573 static int l2tp_nl_session_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
574 struct l2tp_session *session)
578 struct l2tp_tunnel *tunnel = session->tunnel;
579 struct sock *sk = NULL;
580 struct l2tp_stats stats;
585 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, L2TP_CMD_SESSION_GET);
589 if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
590 nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) ||
591 nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
592 nla_put_u32(skb, L2TP_ATTR_PEER_SESSION_ID,
593 session->peer_session_id) ||
594 nla_put_u32(skb, L2TP_ATTR_DEBUG, session->debug) ||
595 nla_put_u16(skb, L2TP_ATTR_PW_TYPE, session->pwtype) ||
596 nla_put_u16(skb, L2TP_ATTR_MTU, session->mtu) ||
598 nla_put_u16(skb, L2TP_ATTR_MRU, session->mru)))
599 goto nla_put_failure;
601 if ((session->ifname && session->ifname[0] &&
602 nla_put_string(skb, L2TP_ATTR_IFNAME, session->ifname)) ||
603 (session->cookie_len &&
604 nla_put(skb, L2TP_ATTR_COOKIE, session->cookie_len,
605 &session->cookie[0])) ||
606 (session->peer_cookie_len &&
607 nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len,
608 &session->peer_cookie[0])) ||
609 nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq) ||
610 nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq) ||
611 nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode) ||
613 (((sk) && (sk->sk_policy[0] || sk->sk_policy[1])) &&
614 nla_put_u8(skb, L2TP_ATTR_USING_IPSEC, 1)) ||
616 (session->reorder_timeout &&
617 nla_put_msecs(skb, L2TP_ATTR_RECV_TIMEOUT, session->reorder_timeout)))
618 goto nla_put_failure;
620 nest = nla_nest_start(skb, L2TP_ATTR_STATS);
622 goto nla_put_failure;
625 start = u64_stats_fetch_begin(&session->stats.syncp);
626 stats.tx_packets = session->stats.tx_packets;
627 stats.tx_bytes = session->stats.tx_bytes;
628 stats.tx_errors = session->stats.tx_errors;
629 stats.rx_packets = session->stats.rx_packets;
630 stats.rx_bytes = session->stats.rx_bytes;
631 stats.rx_errors = session->stats.rx_errors;
632 stats.rx_seq_discards = session->stats.rx_seq_discards;
633 stats.rx_oos_packets = session->stats.rx_oos_packets;
634 } while (u64_stats_fetch_retry(&session->stats.syncp, start));
636 if (nla_put_u64(skb, L2TP_ATTR_TX_PACKETS, stats.tx_packets) ||
637 nla_put_u64(skb, L2TP_ATTR_TX_BYTES, stats.tx_bytes) ||
638 nla_put_u64(skb, L2TP_ATTR_TX_ERRORS, stats.tx_errors) ||
639 nla_put_u64(skb, L2TP_ATTR_RX_PACKETS, stats.rx_packets) ||
640 nla_put_u64(skb, L2TP_ATTR_RX_BYTES, stats.rx_bytes) ||
641 nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
642 stats.rx_seq_discards) ||
643 nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS,
644 stats.rx_oos_packets) ||
645 nla_put_u64(skb, L2TP_ATTR_RX_ERRORS, stats.rx_errors))
646 goto nla_put_failure;
647 nla_nest_end(skb, nest);
649 return genlmsg_end(skb, hdr);
652 genlmsg_cancel(skb, hdr);
656 static int l2tp_nl_cmd_session_get(struct sk_buff *skb, struct genl_info *info)
658 struct l2tp_session *session;
662 session = l2tp_nl_session_find(info);
663 if (session == NULL) {
668 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
674 ret = l2tp_nl_session_send(msg, info->snd_pid, info->snd_seq,
679 return genlmsg_unicast(genl_info_net(info), msg, info->snd_pid);
688 static int l2tp_nl_cmd_session_dump(struct sk_buff *skb, struct netlink_callback *cb)
690 struct net *net = sock_net(skb->sk);
691 struct l2tp_session *session;
692 struct l2tp_tunnel *tunnel = NULL;
693 int ti = cb->args[0];
694 int si = cb->args[1];
697 if (tunnel == NULL) {
698 tunnel = l2tp_tunnel_find_nth(net, ti);
703 session = l2tp_session_find_nth(tunnel, si);
704 if (session == NULL) {
711 if (l2tp_nl_session_send(skb, NETLINK_CB(cb->skb).pid,
712 cb->nlh->nlmsg_seq, NLM_F_MULTI,
726 static struct nla_policy l2tp_nl_policy[L2TP_ATTR_MAX + 1] = {
727 [L2TP_ATTR_NONE] = { .type = NLA_UNSPEC, },
728 [L2TP_ATTR_PW_TYPE] = { .type = NLA_U16, },
729 [L2TP_ATTR_ENCAP_TYPE] = { .type = NLA_U16, },
730 [L2TP_ATTR_OFFSET] = { .type = NLA_U16, },
731 [L2TP_ATTR_DATA_SEQ] = { .type = NLA_U8, },
732 [L2TP_ATTR_L2SPEC_TYPE] = { .type = NLA_U8, },
733 [L2TP_ATTR_L2SPEC_LEN] = { .type = NLA_U8, },
734 [L2TP_ATTR_PROTO_VERSION] = { .type = NLA_U8, },
735 [L2TP_ATTR_CONN_ID] = { .type = NLA_U32, },
736 [L2TP_ATTR_PEER_CONN_ID] = { .type = NLA_U32, },
737 [L2TP_ATTR_SESSION_ID] = { .type = NLA_U32, },
738 [L2TP_ATTR_PEER_SESSION_ID] = { .type = NLA_U32, },
739 [L2TP_ATTR_UDP_CSUM] = { .type = NLA_U8, },
740 [L2TP_ATTR_VLAN_ID] = { .type = NLA_U16, },
741 [L2TP_ATTR_DEBUG] = { .type = NLA_U32, },
742 [L2TP_ATTR_RECV_SEQ] = { .type = NLA_U8, },
743 [L2TP_ATTR_SEND_SEQ] = { .type = NLA_U8, },
744 [L2TP_ATTR_LNS_MODE] = { .type = NLA_U8, },
745 [L2TP_ATTR_USING_IPSEC] = { .type = NLA_U8, },
746 [L2TP_ATTR_RECV_TIMEOUT] = { .type = NLA_MSECS, },
747 [L2TP_ATTR_FD] = { .type = NLA_U32, },
748 [L2TP_ATTR_IP_SADDR] = { .type = NLA_U32, },
749 [L2TP_ATTR_IP_DADDR] = { .type = NLA_U32, },
750 [L2TP_ATTR_UDP_SPORT] = { .type = NLA_U16, },
751 [L2TP_ATTR_UDP_DPORT] = { .type = NLA_U16, },
752 [L2TP_ATTR_MTU] = { .type = NLA_U16, },
753 [L2TP_ATTR_MRU] = { .type = NLA_U16, },
754 [L2TP_ATTR_STATS] = { .type = NLA_NESTED, },
755 [L2TP_ATTR_IFNAME] = {
756 .type = NLA_NUL_STRING,
759 [L2TP_ATTR_COOKIE] = {
763 [L2TP_ATTR_PEER_COOKIE] = {
769 static struct genl_ops l2tp_nl_ops[] = {
771 .cmd = L2TP_CMD_NOOP,
772 .doit = l2tp_nl_cmd_noop,
773 .policy = l2tp_nl_policy,
774 /* can be retrieved by unprivileged users */
777 .cmd = L2TP_CMD_TUNNEL_CREATE,
778 .doit = l2tp_nl_cmd_tunnel_create,
779 .policy = l2tp_nl_policy,
780 .flags = GENL_ADMIN_PERM,
783 .cmd = L2TP_CMD_TUNNEL_DELETE,
784 .doit = l2tp_nl_cmd_tunnel_delete,
785 .policy = l2tp_nl_policy,
786 .flags = GENL_ADMIN_PERM,
789 .cmd = L2TP_CMD_TUNNEL_MODIFY,
790 .doit = l2tp_nl_cmd_tunnel_modify,
791 .policy = l2tp_nl_policy,
792 .flags = GENL_ADMIN_PERM,
795 .cmd = L2TP_CMD_TUNNEL_GET,
796 .doit = l2tp_nl_cmd_tunnel_get,
797 .dumpit = l2tp_nl_cmd_tunnel_dump,
798 .policy = l2tp_nl_policy,
799 .flags = GENL_ADMIN_PERM,
802 .cmd = L2TP_CMD_SESSION_CREATE,
803 .doit = l2tp_nl_cmd_session_create,
804 .policy = l2tp_nl_policy,
805 .flags = GENL_ADMIN_PERM,
808 .cmd = L2TP_CMD_SESSION_DELETE,
809 .doit = l2tp_nl_cmd_session_delete,
810 .policy = l2tp_nl_policy,
811 .flags = GENL_ADMIN_PERM,
814 .cmd = L2TP_CMD_SESSION_MODIFY,
815 .doit = l2tp_nl_cmd_session_modify,
816 .policy = l2tp_nl_policy,
817 .flags = GENL_ADMIN_PERM,
820 .cmd = L2TP_CMD_SESSION_GET,
821 .doit = l2tp_nl_cmd_session_get,
822 .dumpit = l2tp_nl_cmd_session_dump,
823 .policy = l2tp_nl_policy,
824 .flags = GENL_ADMIN_PERM,
828 int l2tp_nl_register_ops(enum l2tp_pwtype pw_type, const struct l2tp_nl_cmd_ops *ops)
833 if (pw_type >= __L2TP_PWTYPE_MAX)
838 if (l2tp_nl_cmd_ops[pw_type])
841 l2tp_nl_cmd_ops[pw_type] = ops;
849 EXPORT_SYMBOL_GPL(l2tp_nl_register_ops);
851 void l2tp_nl_unregister_ops(enum l2tp_pwtype pw_type)
853 if (pw_type < __L2TP_PWTYPE_MAX) {
855 l2tp_nl_cmd_ops[pw_type] = NULL;
859 EXPORT_SYMBOL_GPL(l2tp_nl_unregister_ops);
861 static int l2tp_nl_init(void)
865 printk(KERN_INFO "L2TP netlink interface\n");
866 err = genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops,
867 ARRAY_SIZE(l2tp_nl_ops));
872 static void l2tp_nl_cleanup(void)
874 genl_unregister_family(&l2tp_nl_family);
877 module_init(l2tp_nl_init);
878 module_exit(l2tp_nl_cleanup);
880 MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
881 MODULE_DESCRIPTION("L2TP netlink");
882 MODULE_LICENSE("GPL");
883 MODULE_VERSION("1.0");
884 MODULE_ALIAS("net-pf-" __stringify(PF_NETLINK) "-proto-" \
885 __stringify(NETLINK_GENERIC) "-type-" "l2tp");