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