summaryrefslogtreecommitdiff
path: root/accel-pptpd/ctrl/l2tp/netlink.c
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-10-12 16:16:04 +0400
committerKozlov Dmitry <dima@server>2010-10-12 16:19:00 +0400
commit805d4cdd48200d9bced3a5e41eed08f008d913f4 (patch)
treecd8248ba1995161bcaccecc36ed8703c7bf6ba8e /accel-pptpd/ctrl/l2tp/netlink.c
parent3313e8b52ab54c7e4a0dd8cd9cc6b3aa05b2019c (diff)
downloadaccel-ppp-805d4cdd48200d9bced3a5e41eed08f008d913f4.tar.gz
accel-ppp-805d4cdd48200d9bced3a5e41eed08f008d913f4.zip
ctrl: implemented L2TPv2 server (without IPsec)
Diffstat (limited to 'accel-pptpd/ctrl/l2tp/netlink.c')
-rw-r--r--accel-pptpd/ctrl/l2tp/netlink.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/accel-pptpd/ctrl/l2tp/netlink.c b/accel-pptpd/ctrl/l2tp/netlink.c
new file mode 100644
index 0000000..a50e9b2
--- /dev/null
+++ b/accel-pptpd/ctrl/l2tp/netlink.c
@@ -0,0 +1,70 @@
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+
+#include "l2tp_kernel.h"
+#include "triton.h"
+
+static struct nl_handle *nl_sock;
+static int family;
+
+void l2tp_nl_delete_tunnel(int tid)
+{
+ struct nl_msg *msg = nlmsg_alloc();
+
+ genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, L2TP_CMD_TUNNEL_DELETE, L2TP_GENL_VERSION);
+ nla_put_u32(msg, L2TP_ATTR_CONN_ID, tid);
+
+ nl_send_auto_complete(nl_sock, msg);
+ nl_recvmsgs_default(nl_sock);
+
+ nlmsg_free(msg);
+
+}
+
+void l2tp_nl_create_tunnel(int fd, int tid, int peer_tid)
+{
+ struct nl_msg *msg = nlmsg_alloc();
+
+ l2tp_nl_delete_tunnel(tid);
+
+ genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, L2TP_CMD_TUNNEL_CREATE, L2TP_GENL_VERSION);
+ nla_put_u16(msg, L2TP_ATTR_ENCAP_TYPE, L2TP_ENCAPTYPE_UDP);
+ nla_put_u8(msg, L2TP_ATTR_PROTO_VERSION, 2);
+ nla_put_u32(msg, L2TP_ATTR_CONN_ID, tid);
+ nla_put_u32(msg, L2TP_ATTR_PEER_CONN_ID, peer_tid);
+ nla_put_u32(msg, L2TP_ATTR_FD, fd);
+ //nla_put_u32(msg, L2TP_ATTR_DEBUG, 0xffffffff);
+
+ nl_send_auto_complete(nl_sock, msg);
+ nl_recvmsgs_default(nl_sock);
+
+ nlmsg_free(msg);
+}
+
+void l2tp_nl_create_session(int tid, int sid, int peer_sid)
+{
+ struct nl_msg *msg = nlmsg_alloc();
+
+ genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, L2TP_CMD_SESSION_CREATE, L2TP_GENL_VERSION);
+ nla_put_u32(msg, L2TP_ATTR_CONN_ID, tid);
+ nla_put_u32(msg, L2TP_ATTR_SESSION_ID, sid);
+ nla_put_u32(msg, L2TP_ATTR_PEER_SESSION_ID, peer_sid);
+ nla_put_u16(msg, L2TP_ATTR_PW_TYPE, L2TP_PWTYPE_PPP);
+ nla_put_u8(msg, L2TP_ATTR_LNS_MODE, 1);
+ //nla_put_u32(msg, L2TP_ATTR_DEBUG, 0xffffffff);
+
+ nl_send_auto_complete(nl_sock, msg);
+ nl_recvmsgs_default(nl_sock);
+
+ nlmsg_free(msg);
+}
+
+static void __init init(void)
+{
+ nl_sock = nl_handle_alloc();
+
+ genl_connect(nl_sock);
+
+ family = genl_ctrl_resolve(nl_sock, L2TP_GENL_NAME);
+}