Fix service_name management and add pppoe_only_equal_svc_name parameter
[l2tpns.git] / autosnoop.c
1 #include <string.h>
2 #include "l2tpns.h"
3 #include "plugin.h"
4
5 /* set up intercept based on RADIUS reply */
6
7 int plugin_api_version = PLUGIN_API_VERSION;
8 static struct pluginfuncs *f = 0;
9
10 int plugin_radius_response(struct param_radius_response *data)
11 {
12 if (!strcmp(data->key, "intercept"))
13 {
14 char *p;
15 data->s->snoop_ip = 0;
16 data->s->snoop_port = 0;
17 if ((p = strchr(data->value, ':')))
18 {
19 *p++ = 0;
20 if (*data->value)
21 data->s->snoop_ip = inet_addr(data->value);
22
23 if (data->s->snoop_ip == INADDR_NONE)
24 data->s->snoop_ip = 0;
25
26 if (*p)
27 data->s->snoop_port = atoi(p);
28
29 f->log(3, f->get_id_by_session(data->s), data->s->tunnel,
30 " Intercepting user to %s:%d\n",
31 f->fmtaddr(data->s->snoop_ip, 0), data->s->snoop_port);
32 }
33 else
34 {
35 f->log(3, f->get_id_by_session(data->s), data->s->tunnel,
36 " Not Intercepting user (reply string should"
37 " be intercept=ip:port)\n");
38 }
39 }
40
41 return PLUGIN_RET_OK;
42 }
43
44 int plugin_radius_reset(struct param_radius_reset *data)
45 {
46 data->s->snoop_ip = 0;
47 data->s->snoop_port = 0;
48 return PLUGIN_RET_OK;
49 }
50
51 int plugin_radius_account(struct param_radius_account *data)
52 {
53 if (data->s->snoop_ip && data->s->snoop_port)
54 {
55 uint8_t *p = *data->packet;
56
57 *p = 26; // vendor-specific
58 *(uint32_t *) (p + 2) = htonl(9); // Cisco
59 p[6] = 1; // Cisco-AVPair
60 p[7] = 2 + sprintf((char *) p + 8, "intercept=%s:%d",
61 f->fmtaddr(data->s->snoop_ip, 0), data->s->snoop_port);
62
63 p[1] = p[7] + 6;
64 *data->packet += p[1];
65 }
66
67 return PLUGIN_RET_OK;
68 }
69
70 int plugin_init(struct pluginfuncs *funcs)
71 {
72 return ((f = funcs)) ? 1 : 0;
73 }