00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef DNET_FW_H
00012 #define DNET_FW_H
00013
00014 struct fw_rule {
00015 char fw_device[INTF_NAME_LEN];
00016 uint8_t fw_op;
00017 uint8_t fw_dir;
00018 uint8_t fw_proto;
00019 struct addr fw_src;
00020 struct addr fw_dst;
00021 uint16_t fw_sport[2];
00022 uint16_t fw_dport[2];
00023 };
00024
00025 #define FW_OP_ALLOW 1
00026 #define FW_OP_BLOCK 2
00027
00028 #define FW_DIR_IN 1
00029 #define FW_DIR_OUT 2
00030
00031 #define fw_pack_rule(rule, dev, op, dir, p, s, d, sp1, sp2, dp1, dp2) \
00032 do { \
00033 strlcpy((rule)->fw_device, dev, sizeof((rule)->fw_device)); \
00034 (rule)->fw_op = op; (rule)->fw_dir = dir; \
00035 (rule)->fw_proto = p; \
00036 memmove(&(rule)->fw_src, &(s), sizeof((rule)->fw_src)); \
00037 memmove(&(rule)->fw_dst, &(d), sizeof((rule)->fw_dst)); \
00038 (rule)->fw_sport[0] = sp1; (rule)->fw_sport[1] = sp2; \
00039 (rule)->fw_dport[0] = dp1; (rule)->fw_dport[1] = dp2; \
00040 } while (0)
00041
00042 typedef struct fw_handle fw_t;
00043
00044 typedef int (*fw_handler)(const struct fw_rule *rule, void *arg);
00045
00046 __BEGIN_DECLS
00047 fw_t *fw_open(void);
00048 int fw_add(fw_t *f, const struct fw_rule *rule);
00049 int fw_delete(fw_t *f, const struct fw_rule *rule);
00050 int fw_loop(fw_t *f, fw_handler callback, void *arg);
00051 fw_t *fw_close(fw_t *f);
00052 __END_DECLS
00053
00054 #endif