3 * LTT control module over a netlink socket.
5 * Inspired from Relay Apps, by Tom Zanussi and iptables
8 * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/ltt-core.h>
14 #include <linux/netlink.h>
15 #include <linux/inet.h>
17 #include <linux/security.h>
18 #include <linux/skbuff.h>
19 #include <linux/types.h>
21 #include "ltt-control.h"
24 #define LTTCTLM_BASE 0x10
25 #define LTTCTLM_CONTROL (LTTCTLM_BASE + 1) /* LTT control message */
27 static struct sock
*socket
;
29 void ltt_control_input(struct sock
*sk
, int len
)
32 struct nlmsghdr
*nlh
= NULL
;
34 lttctl_peer_msg_t
*msg
;
37 printk(KERN_ALERT
"ltt-control ltt_control_input\n");
39 while ((skb
= skb_dequeue(&sk
->sk_receive_queue
))
42 nlh
= (struct nlmsghdr
*)skb
->data
;
44 if(security_netlink_recv(skb
)) {
45 netlink_ack(skb
, nlh
, EPERM
);
50 /* process netlink message pointed by skb->data */
52 payload
= NLMSG_DATA(nlh
);
53 /* process netlink message with header pointed by
54 * nlh and payload pointed by payload
56 if(nlh
->nlmsg_len
!= sizeof(lttctl_peer_msg_t
) + sizeof(struct nlmsghdr
)) {
57 printk(KERN_ALERT
"ltt-control bad message length\n");
58 netlink_ack(skb
, nlh
, EINVAL
);
62 msg
= (lttctl_peer_msg_t
*)payload
;
66 err
= ltt_control(LTT_CONTROL_CREATE_TRACE
, msg
->trace_name
,
70 err
= ltt_control(LTT_CONTROL_DESTROY_TRACE
, msg
->trace_name
,
74 err
= ltt_control(LTT_CONTROL_START
, msg
->trace_name
,
78 err
= ltt_control(LTT_CONTROL_STOP
, msg
->trace_name
,
83 printk(KERN_INFO
"ltt-control invalid operation\n");
85 netlink_ack(skb
, nlh
, err
);
91 static int ltt_control_init(void)
93 printk(KERN_ALERT
"ltt-control init\n");
95 socket
= netlink_kernel_create(NETLINK_LTT
, 1,
96 ltt_control_input
, THIS_MODULE
);
97 if(socket
== NULL
) return -EPERM
;
101 static void ltt_control_exit(void)
103 printk(KERN_ALERT
"ltt-control exit\n");
105 sock_release(socket
->sk_socket
);
109 module_init(ltt_control_init
)
110 module_exit(ltt_control_exit
)
112 MODULE_LICENSE("GPL");
113 MODULE_AUTHOR("Mathieu Desnoyers");
114 MODULE_DESCRIPTION("Linux Trace Toolkit Controller");