2 #include <linux/rtnetlink.h>
3 #include <netinet/ip6.h>
12 int plugin_api_version
= PLUGIN_API_VERSION
;
13 static struct pluginfuncs
*f
= 0;
15 char *plugin_control_help
[] = {
16 " snoop USER|SID IP PORT Intercept user traffic",
17 " unsnoop USER|SID Stop intercepting user",
21 int plugin_control(struct param_control
*data
)
31 if (strcmp(data
->argv
[0], "snoop") && strcmp(data
->argv
[0], "unsnoop"))
32 return PLUGIN_RET_OK
; // not for us
34 if (!data
->iam_master
)
35 return PLUGIN_RET_NOTMASTER
;
37 flag
= data
->argv
[0][0] != 'u';
43 data
->response
= NSCTL_RES_ERR
;
44 data
->additional
= "requires username or session id and host, port";
45 return PLUGIN_RET_STOP
;
52 data
->response
= NSCTL_RES_ERR
;
53 data
->additional
= "requires username or session id";
54 return PLUGIN_RET_STOP
;
58 if (!(session
= strtol(data
->argv
[1], &end
, 10)) || *end
)
59 session
= f
->get_session_by_username(data
->argv
[1]);
62 s
= f
->get_session_by_id(session
);
66 data
->response
= NSCTL_RES_ERR
;
67 data
->additional
= "session not found";
68 return PLUGIN_RET_STOP
;
73 in_addr_t ip
= inet_addr(data
->argv
[2]);
74 uint16_t port
= atoi(data
->argv
[3]);
76 if (!ip
|| ip
== INADDR_NONE
)
78 data
->response
= NSCTL_RES_ERR
;
79 data
->additional
= "invalid ip address";
80 return PLUGIN_RET_STOP
;
85 data
->response
= NSCTL_RES_ERR
;
86 data
->additional
= "invalid port";
87 return PLUGIN_RET_STOP
;
90 if (ip
== s
->snoop_ip
&& port
== s
->snoop_port
)
92 data
->response
= NSCTL_RES_ERR
;
93 data
->additional
= "already intercepted";
94 return PLUGIN_RET_STOP
;
104 data
->response
= NSCTL_RES_ERR
;
105 data
->additional
= "not intercepted";
106 return PLUGIN_RET_STOP
;
113 f
->session_changed(session
);
115 data
->response
= NSCTL_RES_OK
;
116 data
->additional
= 0;
118 return PLUGIN_RET_STOP
;
121 int plugin_init(struct pluginfuncs
*funcs
)
123 return ((f
= funcs
)) ? 1 : 0;