update docs
[l2tpns.git] / control.h
1 #ifndef __CONTROL_H__
2 #define __CONTROL_H__
3
4 #define NSCTL_PORT 1702
5 #define NSCTL_MAGIC 0x9013
6
7 /* builtin commands */
8 #define NSCTL_REQUEST (1 << 4)
9 #define NSCTL_REQ_LOAD (NSCTL_REQUEST | 1)
10 #define NSCTL_REQ_UNLOAD (NSCTL_REQUEST | 2)
11 #define NSCTL_REQ_HELP (NSCTL_REQUEST | 3)
12
13 /* general control message, passed to plugins */
14 #define NSCTL_REQ_CONTROL (NSCTL_REQUEST | 4)
15
16 /* response messages */
17 #define NSCTL_RESPONSE (1 << 5)
18 #define NSCTL_RES_OK (NSCTL_RESPONSE | 1)
19 #define NSCTL_RES_ERR (NSCTL_RESPONSE | 2)
20
21 /* unpack errors */
22 #define NSCTL_ERR_SHORT -1 // short packet
23 #define NSCTL_ERR_LONG -2 // packet exceeds max, or trailing cr*p
24 #define NSCTL_ERR_MAGIC -3 // invalid magic number
25 #define NSCTL_ERR_TYPE -4 // unrecognised type
26
27 #define NSCTL_MAX_PKT_SZ 4096
28
29 struct nsctl_packet {
30 uint16_t magic;
31 uint8_t type;
32 uint8_t argc;
33 char argv[NSCTL_MAX_PKT_SZ - 4];
34 } __attribute__ ((packed));
35
36 #define NSCTL_MAX_ARG_SZ 512
37
38 struct nsctl_args {
39 uint8_t len;
40 char value[NSCTL_MAX_ARG_SZ - 1];
41 } __attribute__ ((packed));
42
43 /* parsed packet */
44 struct nsctl {
45 uint8_t type;
46 uint8_t argc;
47 char *argv[0xff];
48 };
49
50 int pack_control(char *data, int len, uint8_t type, int argc, char *argv[]);
51 int unpack_control(struct nsctl *packet, char *data, int len);
52 void dump_control(struct nsctl *control, FILE *stream);
53
54 #endif /* __CONTROL_H__ */