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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#ifndef INTF_H
#define INTF_H
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/tsnif.h>
#include "list.h"
#include "trans.h"
enum {
/* no state - notify state */
TSNIF_INTF_STATE_NONE = 0,
/* created, added to the list */
TSNIF_INTF_STATE_NEW = 1,
/* attach is sent, waiting for TGROUP msg */
TSNIF_INTF_STATE_ATTACH,
/* detach is sent, waiting for ack */
TSNIF_INTF_STATE_DETACH,
/* got TGROUP msg, receiving DATA msg */
TSNIF_INTF_STATE_DATA,
/* got detach ack, released */
TSNIF_INTF_STATE_DONE,
};
struct tsnif_term {
int type;
int idx;
int state;
struct list_head list;
struct tsnif_handle *handle;
};
struct tsnif_data {
void *ptr;
int len;
uint flags;
struct timespec time;
struct winsize ws;
};
typedef int(*cb_data_t)(struct tsnif_term *term, struct tsnif_data *data);
typedef int(*cb_err_t)(struct tsnif_term *term, int err);
typedef int(*cb_release_t)(struct tsnif_term *term);
typedef int(*cb_notify_t)(struct tsnif_term *term, int action);
struct tsnif_ops {
cb_data_t cb_data;
cb_err_t cb_err;
cb_release_t cb_release;
cb_notify_t cb_notify;
};
struct tsnif_handle {
struct list_head terms;
struct tsnif_ops *ops;
struct trans_handle trans;
};
typedef int(*cb_tsnif_enum_t)(struct tsnif_term *term);
/* handle functions */
int tsnif_init(struct tsnif_handle *h, struct tsnif_ops *ops);
int tsnif_close(struct tsnif_handle *h);
int tsnif_process(struct tsnif_handle *h);
int tsnif_fd(struct tsnif_handle *h);
int tsnif_list(struct tsnif_handle *h);
/* term functions */
int tsnif_term_add(struct tsnif_handle *h, struct tsnif_term *term,
int type, int idx);
int tsnif_term_del(struct tsnif_handle *h, struct tsnif_term *term);
int tsnif_attach(struct tsnif_term *term);
int tsnif_detach(struct tsnif_term *term);
#define tsnif_for_each(term, t, handle) \
list_for_each_entry_safe(term, t, (&handle->terms), list)
extern int tsnif_debug;
#define TSNIF_DEBUG(fmt, args...) \
do { \
if (tsnif_debug) { \
char lpbuf[256]; \
snprintf(lpbuf, sizeof(lpbuf)-1, "USER [%3d:%s:%05d %s] %s", \
(pid_t) syscall(SYS_gettid), \
__FILE__, \
__LINE__, \
__FUNCTION__, \
fmt); \
printf(lpbuf, ## args); \
} \
} while(0)
#endif /* !INTF_H */
|