File: control.h

package info (click to toggle)
l2tpns 2.1.21-1.1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 820 kB
  • ctags: 1,621
  • sloc: ansic: 16,737; makefile: 160; sh: 142; perl: 139
file content (54 lines) | stat: -rw-r--r-- 1,397 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef __CONTROL_H__
#define __CONTROL_H__

#define NSCTL_PORT		1702
#define NSCTL_MAGIC		0x9013

/* builtin commands */
#define NSCTL_REQUEST		(1 << 4)
#define NSCTL_REQ_LOAD		(NSCTL_REQUEST | 1)
#define NSCTL_REQ_UNLOAD	(NSCTL_REQUEST | 2)
#define NSCTL_REQ_HELP		(NSCTL_REQUEST | 3)

/* general control message, passed to plugins */
#define NSCTL_REQ_CONTROL	(NSCTL_REQUEST | 4)

/* response messages */
#define NSCTL_RESPONSE		(1 << 5)
#define NSCTL_RES_OK		(NSCTL_RESPONSE | 1)
#define NSCTL_RES_ERR		(NSCTL_RESPONSE | 2)

/* unpack errors */
#define NSCTL_ERR_SHORT		-1	// short packet
#define NSCTL_ERR_LONG		-2	// packet exceeds max, or trailing cr*p
#define NSCTL_ERR_MAGIC		-3	// invalid magic number
#define NSCTL_ERR_TYPE		-4	// unrecognised type

#define NSCTL_MAX_PKT_SZ	4096

struct nsctl_packet {
    uint16_t magic;
    uint8_t type;
    uint8_t argc;
    char argv[NSCTL_MAX_PKT_SZ - 4];
} __attribute__ ((packed));

#define NSCTL_MAX_ARG_SZ	512

struct nsctl_args {
    uint8_t len;
    char value[NSCTL_MAX_ARG_SZ - 1];
} __attribute__ ((packed));

/* parsed packet */
struct nsctl {
    uint8_t type;
    uint8_t argc;
    char *argv[0xff];
};

int pack_control(uint8_t *data, int len, uint8_t type, int argc, char *argv[]);
int unpack_control(struct nsctl *packet, uint8_t *data, int len);
void dump_control(struct nsctl *control, FILE *stream);

#endif /* __CONTROL_H__ */