diff options
Diffstat (limited to 'lib/netfilter/exp_obj.c')
-rw-r--r-- | lib/netfilter/exp_obj.c | 744 |
1 files changed, 369 insertions, 375 deletions
diff --git a/lib/netfilter/exp_obj.c b/lib/netfilter/exp_obj.c index eeb05b31..182df235 100644 --- a/lib/netfilter/exp_obj.c +++ b/lib/netfilter/exp_obj.c @@ -29,36 +29,36 @@ // these parent attributes will include nested attributes. /** @cond SKIP */ -#define EXP_ATTR_FAMILY (1UL << 0) // 8-bit -#define EXP_ATTR_TIMEOUT (1UL << 1) // 32-bit -#define EXP_ATTR_ID (1UL << 2) // 32-bit -#define EXP_ATTR_HELPER_NAME (1UL << 3) // string (16 bytes max) -#define EXP_ATTR_ZONE (1UL << 4) // 16-bit -#define EXP_ATTR_FLAGS (1UL << 5) // 32-bit -#define EXP_ATTR_CLASS (1UL << 6) // 32-bit ??? -#define EXP_ATTR_FN (1UL << 7) // String ??? +#define EXP_ATTR_FAMILY (1UL << 0) // 8-bit +#define EXP_ATTR_TIMEOUT (1UL << 1) // 32-bit +#define EXP_ATTR_ID (1UL << 2) // 32-bit +#define EXP_ATTR_HELPER_NAME (1UL << 3) // string +#define EXP_ATTR_ZONE (1UL << 4) // 16-bit +#define EXP_ATTR_FLAGS (1UL << 5) // 32-bit +#define EXP_ATTR_CLASS (1UL << 6) // 32-bit +#define EXP_ATTR_FN (1UL << 7) // String // Tuples -#define EXP_ATTR_EXPECT_IP_SRC (1UL << 8) -#define EXP_ATTR_EXPECT_IP_DST (1UL << 9) -#define EXP_ATTR_EXPECT_L4PROTO_NUM (1UL << 10) // contains l4proto # + PORT attrs or ICMP attrs -#define EXP_ATTR_EXPECT_L4PROTO_PORTS (1UL << 11) -#define EXP_ATTR_EXPECT_L4PROTO_ICMP (1UL << 12) -#define EXP_ATTR_MASTER_IP_SRC (1UL << 13) -#define EXP_ATTR_MASTER_IP_DST (1UL << 14) -#define EXP_ATTR_MASTER_L4PROTO_NUM (1UL << 15) // contains l4proto # + PORT attrs or ICMP attrs -#define EXP_ATTR_MASTER_L4PROTO_PORTS (1UL << 16) -#define EXP_ATTR_MASTER_L4PROTO_ICMP (1UL << 17) -#define EXP_ATTR_MASK_IP_SRC (1UL << 18) -#define EXP_ATTR_MASK_IP_DST (1UL << 19) -#define EXP_ATTR_MASK_L4PROTO_NUM (1UL << 20) // contains l4proto # + PORT attrs or ICMP attrs -#define EXP_ATTR_MASK_L4PROTO_PORTS (1UL << 21) -#define EXP_ATTR_MASK_L4PROTO_ICMP (1UL << 22) -#define EXP_ATTR_NAT_IP_SRC (1UL << 23) -#define EXP_ATTR_NAT_IP_DST (1UL << 24) -#define EXP_ATTR_NAT_L4PROTO_NUM (1UL << 25) // contains l4proto # + PORT attrs or ICMP attrs -#define EXP_ATTR_NAT_L4PROTO_PORTS (1UL << 26) -#define EXP_ATTR_NAT_L4PROTO_ICMP (1UL << 27) -#define EXP_ATTR_NAT_DIR (1UL << 28) // 8-bit +#define EXP_ATTR_EXPECT_IP_SRC (1UL << 8) +#define EXP_ATTR_EXPECT_IP_DST (1UL << 9) +#define EXP_ATTR_EXPECT_L4PROTO_NUM (1UL << 10) +#define EXP_ATTR_EXPECT_L4PROTO_PORTS (1UL << 11) +#define EXP_ATTR_EXPECT_L4PROTO_ICMP (1UL << 12) +#define EXP_ATTR_MASTER_IP_SRC (1UL << 13) +#define EXP_ATTR_MASTER_IP_DST (1UL << 14) +#define EXP_ATTR_MASTER_L4PROTO_NUM (1UL << 15) +#define EXP_ATTR_MASTER_L4PROTO_PORTS (1UL << 16) +#define EXP_ATTR_MASTER_L4PROTO_ICMP (1UL << 17) +#define EXP_ATTR_MASK_IP_SRC (1UL << 18) +#define EXP_ATTR_MASK_IP_DST (1UL << 19) +#define EXP_ATTR_MASK_L4PROTO_NUM (1UL << 20) +#define EXP_ATTR_MASK_L4PROTO_PORTS (1UL << 21) +#define EXP_ATTR_MASK_L4PROTO_ICMP (1UL << 22) +#define EXP_ATTR_NAT_IP_SRC (1UL << 23) +#define EXP_ATTR_NAT_IP_DST (1UL << 24) +#define EXP_ATTR_NAT_L4PROTO_NUM (1UL << 25) +#define EXP_ATTR_NAT_L4PROTO_PORTS (1UL << 26) +#define EXP_ATTR_NAT_L4PROTO_ICMP (1UL << 27) +#define EXP_ATTR_NAT_DIR (1UL << 28) /** @endcond */ static void exp_free_data(struct nl_object *c) @@ -68,90 +68,90 @@ static void exp_free_data(struct nl_object *c) if (exp == NULL) return; - nl_addr_put(exp->exp_expect.src); - nl_addr_put(exp->exp_expect.dst); - nl_addr_put(exp->exp_master.src); - nl_addr_put(exp->exp_master.dst); - nl_addr_put(exp->exp_mask.src); - nl_addr_put(exp->exp_mask.dst); - nl_addr_put(exp->exp_nat.src); - nl_addr_put(exp->exp_nat.dst); + nl_addr_put(exp->exp_expect.src); + nl_addr_put(exp->exp_expect.dst); + nl_addr_put(exp->exp_master.src); + nl_addr_put(exp->exp_master.dst); + nl_addr_put(exp->exp_mask.src); + nl_addr_put(exp->exp_mask.dst); + nl_addr_put(exp->exp_nat.src); + nl_addr_put(exp->exp_nat.dst); - free(exp->exp_fn); - free(exp->exp_helper_name); + free(exp->exp_fn); + free(exp->exp_helper_name); } static int exp_clone(struct nl_object *_dst, struct nl_object *_src) { - struct nfnl_exp *dst = (struct nfnl_exp *) _dst; - struct nfnl_exp *src = (struct nfnl_exp *) _src; - struct nl_addr *addr; - - // Expectation - if (src->exp_expect.src) { - addr = nl_addr_clone(src->exp_expect.src); - if (!addr) - return -NLE_NOMEM; - dst->exp_expect.src = addr; - } - - if (src->exp_expect.dst) { - addr = nl_addr_clone(src->exp_expect.dst); - if (!addr) - return -NLE_NOMEM; - dst->exp_expect.dst = addr; - } - - // Master CT - if (src->exp_master.src) { - addr = nl_addr_clone(src->exp_master.src); - if (!addr) - return -NLE_NOMEM; - dst->exp_master.src = addr; - } - - if (src->exp_master.dst) { - addr = nl_addr_clone(src->exp_master.dst); - if (!addr) - return -NLE_NOMEM; - dst->exp_master.dst = addr; - } - - // Mask - if (src->exp_mask.src) { - addr = nl_addr_clone(src->exp_mask.src); - if (!addr) - return -NLE_NOMEM; - dst->exp_mask.src = addr; - } - - if (src->exp_mask.dst) { - addr = nl_addr_clone(src->exp_mask.dst); - if (!addr) - return -NLE_NOMEM; - dst->exp_mask.dst = addr; - } + struct nfnl_exp *dst = (struct nfnl_exp *) _dst; + struct nfnl_exp *src = (struct nfnl_exp *) _src; + struct nl_addr *addr; + + // Expectation + if (src->exp_expect.src) { + addr = nl_addr_clone(src->exp_expect.src); + if (!addr) + return -NLE_NOMEM; + dst->exp_expect.src = addr; + } + + if (src->exp_expect.dst) { + addr = nl_addr_clone(src->exp_expect.dst); + if (!addr) + return -NLE_NOMEM; + dst->exp_expect.dst = addr; + } + + // Master CT + if (src->exp_master.src) { + addr = nl_addr_clone(src->exp_master.src); + if (!addr) + return -NLE_NOMEM; + dst->exp_master.src = addr; + } + + if (src->exp_master.dst) { + addr = nl_addr_clone(src->exp_master.dst); + if (!addr) + return -NLE_NOMEM; + dst->exp_master.dst = addr; + } + + // Mask + if (src->exp_mask.src) { + addr = nl_addr_clone(src->exp_mask.src); + if (!addr) + return -NLE_NOMEM; + dst->exp_mask.src = addr; + } + + if (src->exp_mask.dst) { + addr = nl_addr_clone(src->exp_mask.dst); + if (!addr) + return -NLE_NOMEM; + dst->exp_mask.dst = addr; + } // NAT - if (src->exp_nat.src) { - addr = nl_addr_clone(src->exp_nat.src); - if (!addr) - return -NLE_NOMEM; - dst->exp_nat.src = addr; - } - - if (src->exp_nat.dst) { - addr = nl_addr_clone(src->exp_nat.dst); - if (!addr) - return -NLE_NOMEM; - dst->exp_nat.dst = addr; - } - - if (src->exp_fn) - dst->exp_fn = strdup(src->exp_fn); - - if (src->exp_helper_name) - dst->exp_helper_name = strdup(src->exp_helper_name); + if (src->exp_nat.src) { + addr = nl_addr_clone(src->exp_nat.src); + if (!addr) + return -NLE_NOMEM; + dst->exp_nat.src = addr; + } + + if (src->exp_nat.dst) { + addr = nl_addr_clone(src->exp_nat.dst); + if (!addr) + return -NLE_NOMEM; + dst->exp_nat.dst = addr; + } + + if (src->exp_fn) + dst->exp_fn = strdup(src->exp_fn); + + if (src->exp_helper_name) + dst->exp_helper_name = strdup(src->exp_helper_name); return 0; } @@ -173,12 +173,12 @@ static void dump_icmp(struct nl_dump_params *p, struct nfnl_exp *exp, int tuple) { if (nfnl_exp_test_icmp(exp, tuple)) { - nl_dump(p, "icmp type %d ", nfnl_exp_get_icmp_type(exp, tuple)); + nl_dump(p, "icmp type %d ", nfnl_exp_get_icmp_type(exp, tuple)); - nl_dump(p, "code %d ", nfnl_exp_get_icmp_code(exp, tuple)); + nl_dump(p, "code %d ", nfnl_exp_get_icmp_code(exp, tuple)); - nl_dump(p, "id %d ", nfnl_exp_get_icmp_id(exp, tuple)); - } + nl_dump(p, "id %d ", nfnl_exp_get_icmp_id(exp, tuple)); + } } static void exp_dump_tuples(struct nfnl_exp *exp, struct nl_dump_params *p) @@ -186,38 +186,38 @@ static void exp_dump_tuples(struct nfnl_exp *exp, struct nl_dump_params *p) struct nl_addr *tuple_src, *tuple_dst; int tuple_sport, tuple_dport; int i = 0; - char buf[64]; + char buf[64]; for (i = NFNL_EXP_TUPLE_EXPECT; i < NFNL_EXP_TUPLE_MAX; i++) { - tuple_src = NULL; - tuple_dst = NULL; - tuple_sport = 0; - tuple_dport = 0; + tuple_src = NULL; + tuple_dst = NULL; + tuple_sport = 0; + tuple_dport = 0; - // Test needed for NAT case - if (nfnl_exp_test_src(exp, i)) - tuple_src = nfnl_exp_get_src(exp, i); - if (nfnl_exp_test_dst(exp, i)) - tuple_dst = nfnl_exp_get_dst(exp, i); + // Test needed for NAT case + if (nfnl_exp_test_src(exp, i)) + tuple_src = nfnl_exp_get_src(exp, i); + if (nfnl_exp_test_dst(exp, i)) + tuple_dst = nfnl_exp_get_dst(exp, i); // Don't have tests for individual ports/types/codes/ids, - if (nfnl_exp_test_l4protonum(exp, i)) { - nl_dump(p, "%s ", - nl_ip_proto2str(nfnl_exp_get_l4protonum(exp, i), buf, sizeof(buf))); - } - - if (nfnl_exp_test_ports(exp, i)) { - tuple_sport = nfnl_exp_get_src_port(exp, i); - tuple_dport = nfnl_exp_get_dst_port(exp, i); - } - - dump_addr(p, tuple_src, tuple_sport); - dump_addr(p, tuple_dst, tuple_dport); - dump_icmp(p, exp, 0); - } + if (nfnl_exp_test_l4protonum(exp, i)) { + nl_dump(p, "%s ", + nl_ip_proto2str(nfnl_exp_get_l4protonum(exp, i), buf, sizeof(buf))); + } + + if (nfnl_exp_test_ports(exp, i)) { + tuple_sport = nfnl_exp_get_src_port(exp, i); + tuple_dport = nfnl_exp_get_dst_port(exp, i); + } + + dump_addr(p, tuple_src, tuple_sport); + dump_addr(p, tuple_dst, tuple_dport); + dump_icmp(p, exp, 0); + } - if (nfnl_exp_test_nat_dir(exp)) - nl_dump(p, "nat dir %s ", exp->exp_nat_dir); + if (nfnl_exp_test_nat_dir(exp)) + nl_dump(p, "nat dir %s ", exp->exp_nat_dir); } @@ -251,19 +251,19 @@ static void exp_dump_details(struct nl_object *a, struct nl_dump_params *p) nl_msec2str(timeout_ms, buf, sizeof(buf))); } - if (nfnl_exp_test_helper_name(exp)) - nl_dump(p, "helper %s ", exp->exp_helper_name); + if (nfnl_exp_test_helper_name(exp)) + nl_dump(p, "helper %s ", exp->exp_helper_name); - if (nfnl_exp_test_fn(exp)) - nl_dump(p, "fn %s ", exp->exp_fn); + if (nfnl_exp_test_fn(exp)) + nl_dump(p, "fn %s ", exp->exp_fn); - if (nfnl_exp_test_class(exp)) - nl_dump(p, "class %u ", nfnl_exp_get_class(exp)); + if (nfnl_exp_test_class(exp)) + nl_dump(p, "class %u ", nfnl_exp_get_class(exp)); - if (nfnl_exp_test_zone(exp)) - nl_dump(p, "zone %u ", nfnl_exp_get_zone(exp)); + if (nfnl_exp_test_zone(exp)) + nl_dump(p, "zone %u ", nfnl_exp_get_zone(exp)); - if (nfnl_exp_test_flags(exp)) + if (nfnl_exp_test_flags(exp)) nl_dump(p, "<"); #define PRINT_FLAG(str) \ { nl_dump(p, "%s%s", fp++ ? "," : "", (str)); } @@ -283,26 +283,26 @@ static void exp_dump_details(struct nl_object *a, struct nl_dump_params *p) } static int exp_cmp_l4proto_ports (union nfnl_exp_protodata *a, union nfnl_exp_protodata *b) { - // Must return 0 for match, 1 for mismatch - int d = 0; - d = ( (a->port.src != b->port.src) || - (a->port.dst != b->port.dst) ); + // Must return 0 for match, 1 for mismatch + int d = 0; + d = ( (a->port.src != b->port.src) || + (a->port.dst != b->port.dst) ); - return d; + return d; } static int exp_cmp_l4proto_icmp (union nfnl_exp_protodata *a, union nfnl_exp_protodata *b) { // Must return 0 for match, 1 for mismatch - int d = 0; - d = ( (a->icmp.code != b->icmp.code) || - (a->icmp.type != b->icmp.type) || - (a->icmp.id != b->icmp.id) ); + int d = 0; + d = ( (a->icmp.code != b->icmp.code) || + (a->icmp.type != b->icmp.type) || + (a->icmp.id != b->icmp.id) ); - return d; + return d; } static int exp_compare(struct nl_object *_a, struct nl_object *_b, - uint32_t attrs, int flags) + uint32_t attrs, int flags) { struct nfnl_exp *a = (struct nfnl_exp *) _a; struct nfnl_exp *b = (struct nfnl_exp *) _b; @@ -312,48 +312,48 @@ static int exp_compare(struct nl_object *_a, struct nl_object *_b, #define EXP_DIFF_VAL(ATTR, FIELD) EXP_DIFF(ATTR, a->FIELD != b->FIELD) #define EXP_DIFF_STRING(ATTR, FIELD) EXP_DIFF(ATTR, (strcmp(a->FIELD, b->FIELD) != 0)) #define EXP_DIFF_ADDR(ATTR, FIELD) \ - ((flags & LOOSE_COMPARISON) \ - ? EXP_DIFF(ATTR, nl_addr_cmp_prefix(a->FIELD, b->FIELD)) \ - : EXP_DIFF(ATTR, nl_addr_cmp(a->FIELD, b->FIELD))) + ((flags & LOOSE_COMPARISON) \ + ? EXP_DIFF(ATTR, nl_addr_cmp_prefix(a->FIELD, b->FIELD)) \ + : EXP_DIFF(ATTR, nl_addr_cmp(a->FIELD, b->FIELD))) #define EXP_DIFF_L4PROTO_PORTS(ATTR, FIELD) \ - EXP_DIFF(ATTR, exp_cmp_l4proto_ports(&(a->FIELD), &(b->FIELD))) + EXP_DIFF(ATTR, exp_cmp_l4proto_ports(&(a->FIELD), &(b->FIELD))) #define EXP_DIFF_L4PROTO_ICMP(ATTR, FIELD) \ - EXP_DIFF(ATTR, exp_cmp_l4proto_icmp(&(a->FIELD), &(b->FIELD))) - - diff |= EXP_DIFF_VAL(FAMILY, exp_family); - diff |= EXP_DIFF_VAL(TIMEOUT, exp_timeout); - diff |= EXP_DIFF_VAL(ID, exp_id); - diff |= EXP_DIFF_VAL(ZONE, exp_zone); - diff |= EXP_DIFF_VAL(CLASS, exp_class); - diff |= EXP_DIFF_VAL(FLAGS, exp_flags); - diff |= EXP_DIFF_VAL(NAT_DIR, exp_nat_dir); - - diff |= EXP_DIFF_STRING(FN, exp_fn); - diff |= EXP_DIFF_STRING(HELPER_NAME, exp_helper_name); - - diff |= EXP_DIFF_ADDR(EXPECT_IP_SRC, exp_expect.src); - diff |= EXP_DIFF_ADDR(EXPECT_IP_DST, exp_expect.dst); - diff |= EXP_DIFF_VAL(EXPECT_L4PROTO_NUM, exp_expect.proto.l4protonum); - diff |= EXP_DIFF_L4PROTO_PORTS(EXPECT_L4PROTO_PORTS, exp_expect.proto.l4protodata); - diff |= EXP_DIFF_L4PROTO_ICMP(EXPECT_L4PROTO_ICMP, exp_expect.proto.l4protodata); - - diff |= EXP_DIFF_ADDR(MASTER_IP_SRC, exp_master.src); - diff |= EXP_DIFF_ADDR(MASTER_IP_DST, exp_master.dst); - diff |= EXP_DIFF_VAL(MASTER_L4PROTO_NUM, exp_master.proto.l4protonum); - diff |= EXP_DIFF_L4PROTO_PORTS(MASTER_L4PROTO_PORTS, exp_master.proto.l4protodata); - diff |= EXP_DIFF_L4PROTO_ICMP(MASTER_L4PROTO_ICMP, exp_master.proto.l4protodata); - - diff |= EXP_DIFF_ADDR(MASK_IP_SRC, exp_mask.src); - diff |= EXP_DIFF_ADDR(MASK_IP_DST, exp_mask.dst); - diff |= EXP_DIFF_VAL(MASK_L4PROTO_NUM, exp_mask.proto.l4protonum); - diff |= EXP_DIFF_L4PROTO_PORTS(MASK_L4PROTO_PORTS, exp_mask.proto.l4protodata); - diff |= EXP_DIFF_L4PROTO_ICMP(MASK_L4PROTO_ICMP, exp_mask.proto.l4protodata); - - diff |= EXP_DIFF_ADDR(NAT_IP_SRC, exp_nat.src); - diff |= EXP_DIFF_ADDR(NAT_IP_DST, exp_nat.dst); - diff |= EXP_DIFF_VAL(NAT_L4PROTO_NUM, exp_nat.proto.l4protonum); - diff |= EXP_DIFF_L4PROTO_PORTS(NAT_L4PROTO_PORTS, exp_nat.proto.l4protodata); - diff |= EXP_DIFF_L4PROTO_ICMP(NAT_L4PROTO_ICMP, exp_nat.proto.l4protodata); + EXP_DIFF(ATTR, exp_cmp_l4proto_icmp(&(a->FIELD), &(b->FIELD))) + + diff |= EXP_DIFF_VAL(FAMILY, exp_family); + diff |= EXP_DIFF_VAL(TIMEOUT, exp_timeout); + diff |= EXP_DIFF_VAL(ID, exp_id); + diff |= EXP_DIFF_VAL(ZONE, exp_zone); + diff |= EXP_DIFF_VAL(CLASS, exp_class); + diff |= EXP_DIFF_VAL(FLAGS, exp_flags); + diff |= EXP_DIFF_VAL(NAT_DIR, exp_nat_dir); + + diff |= EXP_DIFF_STRING(FN, exp_fn); + diff |= EXP_DIFF_STRING(HELPER_NAME, exp_helper_name); + + diff |= EXP_DIFF_ADDR(EXPECT_IP_SRC, exp_expect.src); + diff |= EXP_DIFF_ADDR(EXPECT_IP_DST, exp_expect.dst); + diff |= EXP_DIFF_VAL(EXPECT_L4PROTO_NUM, exp_expect.proto.l4protonum); + diff |= EXP_DIFF_L4PROTO_PORTS(EXPECT_L4PROTO_PORTS, exp_expect.proto.l4protodata); + diff |= EXP_DIFF_L4PROTO_ICMP(EXPECT_L4PROTO_ICMP, exp_expect.proto.l4protodata); + + diff |= EXP_DIFF_ADDR(MASTER_IP_SRC, exp_master.src); + diff |= EXP_DIFF_ADDR(MASTER_IP_DST, exp_master.dst); + diff |= EXP_DIFF_VAL(MASTER_L4PROTO_NUM, exp_master.proto.l4protonum); + diff |= EXP_DIFF_L4PROTO_PORTS(MASTER_L4PROTO_PORTS, exp_master.proto.l4protodata); + diff |= EXP_DIFF_L4PROTO_ICMP(MASTER_L4PROTO_ICMP, exp_master.proto.l4protodata); + + diff |= EXP_DIFF_ADDR(MASK_IP_SRC, exp_mask.src); + diff |= EXP_DIFF_ADDR(MASK_IP_DST, exp_mask.dst); + diff |= EXP_DIFF_VAL(MASK_L4PROTO_NUM, exp_mask.proto.l4protonum); + diff |= EXP_DIFF_L4PROTO_PORTS(MASK_L4PROTO_PORTS, exp_mask.proto.l4protodata); + diff |= EXP_DIFF_L4PROTO_ICMP(MASK_L4PROTO_ICMP, exp_mask.proto.l4protodata); + + diff |= EXP_DIFF_ADDR(NAT_IP_SRC, exp_nat.src); + diff |= EXP_DIFF_ADDR(NAT_IP_DST, exp_nat.dst); + diff |= EXP_DIFF_VAL(NAT_L4PROTO_NUM, exp_nat.proto.l4protonum); + diff |= EXP_DIFF_L4PROTO_PORTS(NAT_L4PROTO_PORTS, exp_nat.proto.l4protodata); + diff |= EXP_DIFF_L4PROTO_ICMP(NAT_L4PROTO_ICMP, exp_nat.proto.l4protodata); #undef EXP_DIFF #undef EXP_DIFF_VAL @@ -362,40 +362,40 @@ static int exp_compare(struct nl_object *_a, struct nl_object *_b, #undef EXP_DIFF_L4PROTO_PORTS #undef EXP_DIFF_L4PROTO_ICMP - return diff; + return diff; } // CLI arguments? static const struct trans_tbl exp_attrs[] = { - __ADD(EXP_ATTR_FAMILY, family) - __ADD(EXP_ATTR_TIMEOUT, timeout) - __ADD(EXP_ATTR_ID, id) - __ADD(EXP_ATTR_HELPER_NAME, helpername) - __ADD(EXP_ATTR_ZONE, zone) - __ADD(EXP_ATTR_CLASS, class) - __ADD(EXP_ATTR_FLAGS, flags) - __ADD(EXP_ATTR_FN, function) - __ADD(EXP_ATTR_EXPECT_IP_SRC, expectipsrc) - __ADD(EXP_ATTR_EXPECT_IP_DST, expectipdst) - __ADD(EXP_ATTR_EXPECT_L4PROTO_NUM, expectprotonum) - __ADD(EXP_ATTR_EXPECT_L4PROTO_PORTS, expectports) - __ADD(EXP_ATTR_EXPECT_L4PROTO_ICMP , expecticmp) - __ADD(EXP_ATTR_MASTER_IP_SRC, masteripsrc) - __ADD(EXP_ATTR_MASTER_IP_DST, masteripdst) - __ADD(EXP_ATTR_MASTER_L4PROTO_NUM, masterprotonum) - __ADD(EXP_ATTR_MASTER_L4PROTO_PORTS, masterports) - __ADD(EXP_ATTR_MASTER_L4PROTO_ICMP , mastericmp) - __ADD(EXP_ATTR_MASK_IP_SRC, maskipsrc) - __ADD(EXP_ATTR_MASK_IP_DST, maskipdst) - __ADD(EXP_ATTR_MASK_L4PROTO_NUM, maskprotonum) - __ADD(EXP_ATTR_MASK_L4PROTO_PORTS, maskports) - __ADD(EXP_ATTR_MASK_L4PROTO_ICMP , maskicmp) - __ADD(EXP_ATTR_NAT_IP_SRC, natipsrc) - __ADD(EXP_ATTR_NAT_IP_DST, natipdst) - __ADD(EXP_ATTR_NAT_L4PROTO_NUM, natprotonum) - __ADD(EXP_ATTR_NAT_L4PROTO_PORTS, natports) - __ADD(EXP_ATTR_NAT_L4PROTO_ICMP, naticmp) - __ADD(EXP_ATTR_NAT_DIR, natdir) + __ADD(EXP_ATTR_FAMILY, family) + __ADD(EXP_ATTR_TIMEOUT, timeout) + __ADD(EXP_ATTR_ID, id) + __ADD(EXP_ATTR_HELPER_NAME, helpername) + __ADD(EXP_ATTR_ZONE, zone) + __ADD(EXP_ATTR_CLASS, class) + __ADD(EXP_ATTR_FLAGS, flags) + __ADD(EXP_ATTR_FN, function) + __ADD(EXP_ATTR_EXPECT_IP_SRC, expectipsrc) + __ADD(EXP_ATTR_EXPECT_IP_DST, expectipdst) + __ADD(EXP_ATTR_EXPECT_L4PROTO_NUM, expectprotonum) + __ADD(EXP_ATTR_EXPECT_L4PROTO_PORTS, expectports) + __ADD(EXP_ATTR_EXPECT_L4PROTO_ICMP, expecticmp) + __ADD(EXP_ATTR_MASTER_IP_SRC, masteripsrc) + __ADD(EXP_ATTR_MASTER_IP_DST, masteripdst) + __ADD(EXP_ATTR_MASTER_L4PROTO_NUM, masterprotonum) + __ADD(EXP_ATTR_MASTER_L4PROTO_PORTS, masterports) + __ADD(EXP_ATTR_MASTER_L4PROTO_ICMP, mastericmp) + __ADD(EXP_ATTR_MASK_IP_SRC, maskipsrc) + __ADD(EXP_ATTR_MASK_IP_DST, maskipdst) + __ADD(EXP_ATTR_MASK_L4PROTO_NUM, maskprotonum) + __ADD(EXP_ATTR_MASK_L4PROTO_PORTS, maskports) + __ADD(EXP_ATTR_MASK_L4PROTO_ICMP, maskicmp) + __ADD(EXP_ATTR_NAT_IP_SRC, natipsrc) + __ADD(EXP_ATTR_NAT_IP_DST, natipdst) + __ADD(EXP_ATTR_NAT_L4PROTO_NUM, natprotonum) + __ADD(EXP_ATTR_NAT_L4PROTO_PORTS, natports) + __ADD(EXP_ATTR_NAT_L4PROTO_ICMP, naticmp) + __ADD(EXP_ATTR_NAT_DIR, natdir) }; static char *exp_attrs2str(int attrs, char *buf, size_t len) @@ -452,7 +452,7 @@ void nfnl_exp_set_flags(struct nfnl_exp *exp, uint32_t flags) int nfnl_exp_test_flags(const struct nfnl_exp *exp) { - return !!(exp->ce_mask & EXP_ATTR_FLAGS); + return !!(exp->ce_mask & EXP_ATTR_FLAGS); } void nfnl_exp_unset_flags(struct nfnl_exp *exp, uint32_t flags) @@ -515,148 +515,146 @@ uint32_t nfnl_exp_get_id(const struct nfnl_exp *exp) return exp->exp_id; } -int nfnl_exp_set_helper_name(struct nfnl_exp *exp, void *name) +int nfnl_exp_set_helper_name(struct nfnl_exp *exp, void *name) { - free(exp->exp_helper_name); - exp->exp_helper_name = strdup(name); - if (!exp->exp_helper_name) - return -NLE_NOMEM; + free(exp->exp_helper_name); + exp->exp_helper_name = strdup(name); + if (!exp->exp_helper_name) + return -NLE_NOMEM; - exp->ce_mask |= EXP_ATTR_HELPER_NAME; - return 0; + exp->ce_mask |= EXP_ATTR_HELPER_NAME; + return 0; } int nfnl_exp_test_helper_name(const struct nfnl_exp *exp) { - return !!(exp->ce_mask & EXP_ATTR_HELPER_NAME); + return !!(exp->ce_mask & EXP_ATTR_HELPER_NAME); } const char * nfnl_exp_get_helper_name(const struct nfnl_exp *exp) { - return exp->exp_helper_name; + return exp->exp_helper_name; } void nfnl_exp_set_zone(struct nfnl_exp *exp, uint16_t zone) { - exp->exp_zone = zone; - exp->ce_mask |= EXP_ATTR_ZONE; + exp->exp_zone = zone; + exp->ce_mask |= EXP_ATTR_ZONE; } int nfnl_exp_test_zone(const struct nfnl_exp *exp) { - return !!(exp->ce_mask & EXP_ATTR_ZONE); + return !!(exp->ce_mask & EXP_ATTR_ZONE); } uint16_t nfnl_exp_get_zone(const struct nfnl_exp *exp) { - return exp->exp_zone; + return exp->exp_zone; } void nfnl_exp_set_class(struct nfnl_exp *exp, uint32_t class) { - exp->exp_class = class; - exp->ce_mask |= EXP_ATTR_CLASS; + exp->exp_class = class; + exp->ce_mask |= EXP_ATTR_CLASS; } int nfnl_exp_test_class(const struct nfnl_exp *exp) { - return !!(exp->ce_mask & EXP_ATTR_CLASS); + return !!(exp->ce_mask & EXP_ATTR_CLASS); } uint32_t nfnl_exp_get_class(const struct nfnl_exp *exp) { - return exp->exp_class; + return exp->exp_class; } int nfnl_exp_set_fn(struct nfnl_exp *exp, void *fn) { - free(exp->exp_fn); - exp->exp_fn = strdup(fn); - if (!exp->exp_fn) - return -NLE_NOMEM; + free(exp->exp_fn); + exp->exp_fn = strdup(fn); + if (!exp->exp_fn) + return -NLE_NOMEM; - exp->ce_mask |= EXP_ATTR_FN; - return 0; + exp->ce_mask |= EXP_ATTR_FN; + return 0; } int nfnl_exp_test_fn(const struct nfnl_exp *exp) { - return !!(exp->ce_mask & EXP_ATTR_FN); + return !!(exp->ce_mask & EXP_ATTR_FN); } const char * nfnl_exp_get_fn(const struct nfnl_exp *exp) { - return exp->exp_fn; + return exp->exp_fn; } void nfnl_exp_set_nat_dir(struct nfnl_exp *exp, uint8_t nat_dir) { - exp->exp_nat_dir = nat_dir; - exp->ce_mask |= EXP_ATTR_NAT_DIR; + exp->exp_nat_dir = nat_dir; + exp->ce_mask |= EXP_ATTR_NAT_DIR; } int nfnl_exp_test_nat_dir(const struct nfnl_exp *exp) { - return !!(exp->ce_mask & EXP_ATTR_NAT_DIR); + return !!(exp->ce_mask & EXP_ATTR_NAT_DIR); } uint8_t nfnl_exp_get_nat_dir(const struct nfnl_exp *exp) { - return exp->exp_nat_dir; + return exp->exp_nat_dir; } #define EXP_GET_TUPLE(e, t) \ - (t == NFNL_EXP_TUPLE_MASTER) ? \ - &(e->exp_master) : \ - (t == NFNL_EXP_TUPLE_MASK) ? \ - &(e->exp_mask) : \ - (t == NFNL_EXP_TUPLE_NAT) ? \ - &(e->exp_nat) : &(exp->exp_expect) + (t == NFNL_EXP_TUPLE_MASTER) ? \ + &(e->exp_master) : \ + (t == NFNL_EXP_TUPLE_MASK) ? \ + &(e->exp_mask) : \ + (t == NFNL_EXP_TUPLE_NAT) ? \ + &(e->exp_nat) : &(exp->exp_expect) static int exp_get_src_attr(int tuple) { - int attr = 0; - - switch (tuple) { - case NFNL_EXP_TUPLE_MASTER: - attr = EXP_ATTR_MASTER_IP_SRC; - break; - case NFNL_EXP_TUPLE_MASK: - attr = EXP_ATTR_MASK_IP_SRC; - break; - case NFNL_EXP_TUPLE_NAT: - attr = EXP_ATTR_NAT_IP_SRC; - break; - case NFNL_EXP_TUPLE_EXPECT: - default : - attr = EXP_ATTR_EXPECT_IP_SRC; - break; - } + int attr = 0; + + switch (tuple) { + case NFNL_EXP_TUPLE_MASTER: + attr = EXP_ATTR_MASTER_IP_SRC; + break; + case NFNL_EXP_TUPLE_MASK: + attr = EXP_ATTR_MASK_IP_SRC; + break; + case NFNL_EXP_TUPLE_NAT: + attr = EXP_ATTR_NAT_IP_SRC; + break; + case NFNL_EXP_TUPLE_EXPECT: + default : + attr = EXP_ATTR_EXPECT_IP_SRC; + } - return attr; + return attr; } static int exp_get_dst_attr(int tuple) { - int attr = 0; - - switch (tuple) { - case NFNL_EXP_TUPLE_MASTER: - attr = EXP_ATTR_MASTER_IP_DST; - break; - case NFNL_EXP_TUPLE_MASK: - attr = EXP_ATTR_MASK_IP_DST; - break; - case NFNL_EXP_TUPLE_NAT: - attr = EXP_ATTR_NAT_IP_DST; - break; - case NFNL_EXP_TUPLE_EXPECT: - default : - attr = EXP_ATTR_EXPECT_IP_DST; - break; - } + int attr = 0; + + switch (tuple) { + case NFNL_EXP_TUPLE_MASTER: + attr = EXP_ATTR_MASTER_IP_DST; + break; + case NFNL_EXP_TUPLE_MASK: + attr = EXP_ATTR_MASK_IP_DST; + break; + case NFNL_EXP_TUPLE_NAT: + attr = EXP_ATTR_NAT_IP_DST; + break; + case NFNL_EXP_TUPLE_EXPECT: + default : + attr = EXP_ATTR_EXPECT_IP_DST; + } - return attr; + return attr; } @@ -688,27 +686,26 @@ int nfnl_exp_set_src(struct nfnl_exp *exp, int tuple, struct nl_addr *addr) int nfnl_exp_set_dst(struct nfnl_exp *exp, int tuple, struct nl_addr *addr) { - struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); + struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); - return exp_set_addr(exp, addr, exp_get_dst_attr(tuple), &dir->dst); + return exp_set_addr(exp, addr, exp_get_dst_attr(tuple), &dir->dst); } int nfnl_exp_test_src(const struct nfnl_exp *exp, int tuple) { - return !!(exp->ce_mask & exp_get_src_attr(tuple)); + return !!(exp->ce_mask & exp_get_src_attr(tuple)); } int nfnl_exp_test_dst(const struct nfnl_exp *exp, int tuple) { - - return !!(exp->ce_mask & exp_get_dst_attr(tuple)); + return !!(exp->ce_mask & exp_get_dst_attr(tuple)); } struct nl_addr *nfnl_exp_get_src(const struct nfnl_exp *exp, int tuple) { - const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); + const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); - if (!(exp->ce_mask & exp_get_src_attr(tuple))) + if (!(exp->ce_mask & exp_get_src_attr(tuple))) return NULL; return dir->src; } @@ -724,67 +721,65 @@ struct nl_addr *nfnl_exp_get_dst(const struct nfnl_exp *exp, int tuple) static int exp_get_l4protonum_attr(int tuple) { - int attr = 0; - - switch (tuple) { - case NFNL_EXP_TUPLE_MASTER: - attr = EXP_ATTR_MASTER_L4PROTO_NUM; - break; - case NFNL_EXP_TUPLE_MASK: - attr = EXP_ATTR_MASK_L4PROTO_NUM; - break; - case NFNL_EXP_TUPLE_NAT: - attr = EXP_ATTR_NAT_L4PROTO_NUM; - break; - case NFNL_EXP_TUPLE_EXPECT: - default : - attr = EXP_ATTR_EXPECT_L4PROTO_NUM; - break; - } + int attr = 0; + + switch (tuple) { + case NFNL_EXP_TUPLE_MASTER: + attr = EXP_ATTR_MASTER_L4PROTO_NUM; + break; + case NFNL_EXP_TUPLE_MASK: + attr = EXP_ATTR_MASK_L4PROTO_NUM; + break; + case NFNL_EXP_TUPLE_NAT: + attr = EXP_ATTR_NAT_L4PROTO_NUM; + break; + case NFNL_EXP_TUPLE_EXPECT: + default : + attr = EXP_ATTR_EXPECT_L4PROTO_NUM; + } - return attr; + return attr; } void nfnl_exp_set_l4protonum(struct nfnl_exp *exp, int tuple, uint8_t l4protonum) { - struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); + struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); - dir->proto.l4protonum = l4protonum; - exp->ce_mask |= exp_get_l4protonum_attr(tuple); + dir->proto.l4protonum = l4protonum; + exp->ce_mask |= exp_get_l4protonum_attr(tuple); } int nfnl_exp_test_l4protonum(const struct nfnl_exp *exp, int tuple) { - return !!(exp->ce_mask & exp_get_l4protonum_attr(tuple)); + return !!(exp->ce_mask & exp_get_l4protonum_attr(tuple)); } uint8_t nfnl_exp_get_l4protonum(const struct nfnl_exp *exp, int tuple) { - const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); - return dir->proto.l4protonum; + const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); + return dir->proto.l4protonum; } static int exp_get_l4ports_attr(int tuple) { - int attr = 0; - - switch (tuple) { - case NFNL_EXP_TUPLE_MASTER: - attr = EXP_ATTR_MASTER_L4PROTO_PORTS; - break; - case NFNL_EXP_TUPLE_MASK: - attr = EXP_ATTR_MASK_L4PROTO_PORTS; - break; - case NFNL_EXP_TUPLE_NAT: - attr = EXP_ATTR_NAT_L4PROTO_PORTS; - break; - case NFNL_EXP_TUPLE_EXPECT: - default : - attr = EXP_ATTR_EXPECT_L4PROTO_PORTS; - break; - } + int attr = 0; + + switch (tuple) { + case NFNL_EXP_TUPLE_MASTER: + attr = EXP_ATTR_MASTER_L4PROTO_PORTS; + break; + case NFNL_EXP_TUPLE_MASK: + attr = EXP_ATTR_MASK_L4PROTO_PORTS; + break; + case NFNL_EXP_TUPLE_NAT: + attr = EXP_ATTR_NAT_L4PROTO_PORTS; + break; + case NFNL_EXP_TUPLE_EXPECT: + default : + attr = EXP_ATTR_EXPECT_L4PROTO_PORTS; + } - return attr; + return attr; } void nfnl_exp_set_ports(struct nfnl_exp *exp, int tuple, uint16_t srcport, uint16_t dstport) @@ -810,32 +805,31 @@ uint16_t nfnl_exp_get_src_port(const struct nfnl_exp *exp, int tuple) uint16_t nfnl_exp_get_dst_port(const struct nfnl_exp *exp, int tuple) { - const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); + const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); return dir->proto.l4protodata.port.dst; } static int exp_get_l4icmp_attr(int tuple) { - int attr = 0; - - switch (tuple) { - case NFNL_EXP_TUPLE_MASTER: - attr = EXP_ATTR_MASTER_L4PROTO_ICMP; - break; - case NFNL_EXP_TUPLE_MASK: - attr = EXP_ATTR_MASK_L4PROTO_ICMP; - break; - case NFNL_EXP_TUPLE_NAT: - attr = EXP_ATTR_NAT_L4PROTO_ICMP; - break; - case NFNL_EXP_TUPLE_EXPECT: - default : - attr = EXP_ATTR_EXPECT_L4PROTO_ICMP; - break; - } + int attr = 0; + + switch (tuple) { + case NFNL_EXP_TUPLE_MASTER: + attr = EXP_ATTR_MASTER_L4PROTO_ICMP; + break; + case NFNL_EXP_TUPLE_MASK: + attr = EXP_ATTR_MASK_L4PROTO_ICMP; + break; + case NFNL_EXP_TUPLE_NAT: + attr = EXP_ATTR_NAT_L4PROTO_ICMP; + break; + case NFNL_EXP_TUPLE_EXPECT: + default : + attr = EXP_ATTR_EXPECT_L4PROTO_ICMP; + } - return attr; + return attr; } void nfnl_exp_set_icmp(struct nfnl_exp *exp, int tuple, uint16_t id, uint8_t type, uint8_t code) @@ -844,7 +838,7 @@ void nfnl_exp_set_icmp(struct nfnl_exp *exp, int tuple, uint16_t id, uint8_t typ dir->proto.l4protodata.icmp.id = id; dir->proto.l4protodata.icmp.type = type; - dir->proto.l4protodata.icmp.code = code; + dir->proto.l4protodata.icmp.code = code; exp->ce_mask |= exp_get_l4icmp_attr(tuple); } @@ -864,14 +858,14 @@ uint16_t nfnl_exp_get_icmp_id(const struct nfnl_exp *exp, int tuple) uint8_t nfnl_exp_get_icmp_type(const struct nfnl_exp *exp, int tuple) { - const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); + const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); return dir->proto.l4protodata.icmp.type; } uint8_t nfnl_exp_get_icmp_code(const struct nfnl_exp *exp, int tuple) { - const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); + const struct nfnl_exp_dir *dir = EXP_GET_TUPLE(exp, tuple); return dir->proto.l4protodata.icmp.code; } @@ -879,15 +873,15 @@ uint8_t nfnl_exp_get_icmp_code(const struct nfnl_exp *exp, int tuple) /** @} */ struct nl_object_ops exp_obj_ops = { - .oo_name = "netfilter/exp", - .oo_size = sizeof(struct nfnl_exp), + .oo_name = "netfilter/exp", + .oo_size = sizeof(struct nfnl_exp), .oo_free_data = exp_free_data, - .oo_clone = exp_clone, + .oo_clone = exp_clone, .oo_dump = { - [NL_DUMP_LINE] = exp_dump_line, - [NL_DUMP_DETAILS] = exp_dump_details, + [NL_DUMP_LINE] = exp_dump_line, + [NL_DUMP_DETAILS] = exp_dump_details, }, - .oo_compare = exp_compare, + .oo_compare = exp_compare, .oo_attrs2str = exp_attrs2str, }; |