prevent adding fb it already exists
[ana-net.git] / src / xt_vlink.h
blobec945974a7c8bb253cda9641feb19355e2181926
1 /*
2 * Lightweight Autonomic Network Architecture
4 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL.
7 */
9 #ifndef XT_VLINK_H
10 #define XT_VLINK_H
12 #ifdef __KERNEL__
14 #include <linux/types.h>
15 #include <linux/rwsem.h>
16 #include <linux/netlink.h>
17 #include <linux/if.h>
19 #define NETLINK_VLINK_RX_OK 0 /* Receive went okay, notify next */
20 #define NETLINK_VLINK_RX_NXT 1 /* Receive is not for us, notify next */
21 #define NETLINK_VLINK_RX_BAD 2 /* Receive failed, notify next */
22 #define NETLINK_VLINK_RX_EMERG 3 /* Receive failed, do not notify next */
23 #define NETLINK_VLINK_RX_STOP 4 /* Receive went okay, but still stop */
25 #define NETLINK_VLINK_PRIO_LOW 0 /* Low priority callbacks */
26 #define NETLINK_VLINK_PRIO_NORM 1 /* Normal priority callbacks */
27 #define NETLINK_VLINK_PRIO_HIGH 2 /* High priority callbacks */
29 #endif /* __KERNEL__ */
31 #define NETLINK_VLINK 23 /* Netlink hook type */
33 enum vlink_groups {
34 VLINKNLGRP_NONE = NLMSG_MIN_TYPE, /* Reserved */
35 #define VLINKNLGRP_NONE VLINKNLGRP_NONE
36 VLINKNLGRP_ETHERNET, /* To vlink Ethernet type */
37 #define VLINKNLGRP_ETHERNET VLINKNLGRP_ETHERNET
38 VLINKNLGRP_BLUETOOTH, /* To vlink Bluetooth type */
39 #define VLINKNLGRP_BLUETOOTH VLINKNLGRP_BLUETOOTH
40 VLINKNLGRP_INFINIBAND, /* To vlink InfiniBand type */
41 #define VLINKNLGRP_INFINIBAND VLINKNLGRP_INFINIBAND
42 VLINKNLGRP_I2C, /* To vlink I^2C type */
43 #define VLINKNLGRP_I2C VLINKNLGRP_I2C
44 __VLINKNLGRP_MAX
46 #define VLINKNLGRP_MAX (__VLINKNLGRP_MAX - 1)
48 enum vlink_cmd {
49 VLINKNLCMD_ADD_DEVICE,
50 VLINKNLCMD_RM_DEVICE,
51 VLINKNLCMD_START_HOOK_DEVICE,
52 VLINKNLCMD_STOP_HOOK_DEVICE,
55 /* Generic vlinkmsg header, private data can be appended after the header */
56 struct vlinknlmsg {
57 uint32_t cmd:8,
58 flags:16,
59 reserved:8;
60 uint32_t type:16,
61 port:16; /* Actually 8 Bit, but for alignment reasons */
62 uint8_t virt_name[IFNAMSIZ];
63 uint8_t real_name[IFNAMSIZ];
66 #ifdef __KERNEL__
68 #define MAX_VLINK_SUBSYSTEMS 256
70 struct vlink_callback {
71 int priority;
72 int (*rx)(struct vlinknlmsg *vhdr, struct nlmsghdr *nlh);
73 struct vlink_callback *next;
76 #define VLINK_CALLBACK_INIT(fct, prio) { \
77 .rx = (fct), \
78 .priority = (prio), \
79 .next = NULL, }
81 struct vlink_subsys {
82 char *name;
83 u32 type:16,
84 id:16;
85 struct rw_semaphore rwsem;
86 struct vlink_callback *head;
89 #define VLINK_SUBSYS_INIT(varname, sysname, gtype) { \
90 .name = (sysname), \
91 .type = (gtype), \
92 .rwsem = __RWSEM_INITIALIZER((varname).rwsem), \
93 .head = NULL, }
95 extern int init_vlink_system(void);
96 extern void cleanup_vlink_system(void);
97 extern void vlink_lock(void);
98 extern void vlink_unlock(void);
99 extern int vlink_subsys_register(struct vlink_subsys *n);
100 extern void vlink_subsys_unregister(struct vlink_subsys *n);
101 extern void vlink_subsys_unregister_batch(struct vlink_subsys *n);
102 extern struct vlink_subsys *vlink_subsys_find(u16 type);
103 extern int vlink_add_callback(struct vlink_subsys *n,
104 struct vlink_callback *cb);
105 extern int vlink_add_callbacks(struct vlink_subsys *n,
106 struct vlink_callback *cb, ...);
107 extern int vlink_add_callbacks_va(struct vlink_subsys *n,
108 struct vlink_callback *cb,
109 va_list ap);
110 extern int vlink_rm_callback(struct vlink_subsys *n,
111 struct vlink_callback *cb);
113 #endif /* __KERNEL__ */
114 #endif /* XT_VLINK_H */