summaryrefslogtreecommitdiff
path: root/accel-pppd/ctrl/l2tp/netlink.c
blob: c8dce89944ec0e9f7f1ba22a7f5d67cdb4ce27b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>

#include "l2tp_kernel.h"
#include "triton.h"

static int family;

void l2tp_nl_delete_tunnel(int tid)
{
	struct nl_sock *nl_sock;
	struct nl_msg *msg;
	
	nl_sock = nl_socket_alloc();
	msg = nlmsg_alloc();

	genl_connect(nl_sock);

	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);
	nl_close(nl_sock);
	nl_socket_free(nl_sock);
}

void l2tp_nl_create_tunnel(int fd, int tid, int peer_tid)
{
	struct nl_sock *nl_sock;
	struct nl_msg *msg;
	
	nl_sock = nl_socket_alloc();
	msg = nlmsg_alloc();
	
	genl_connect(nl_sock);

	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);
	nl_close(nl_sock);
	nl_socket_free(nl_sock);
}

void l2tp_nl_create_session(int tid, int sid, int peer_sid)
{
	struct nl_sock *nl_sock;
	struct nl_msg *msg;
	
	nl_sock = nl_socket_alloc();
	msg = nlmsg_alloc();
	
	genl_connect(nl_sock);

	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);
	nl_close(nl_sock);
	nl_socket_free(nl_sock);
}

static void init(void)
{
	struct nl_sock *nl_sock = nl_socket_alloc();
	
	genl_connect(nl_sock);

	family = genl_ctrl_resolve(nl_sock, L2TP_GENL_NAME);
	
	nl_close(nl_sock);
	nl_socket_free(nl_sock);
}

DEFINE_INIT(21, init);