Skip to content

Commit

Permalink
Reorganize code
Browse files Browse the repository at this point in the history
  • Loading branch information
llccd committed Apr 4, 2020
1 parent e145998 commit 2ca0c68
Showing 1 changed file with 45 additions and 42 deletions.
87 changes: 45 additions & 42 deletions xt_FULLCONENAT.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,48 +740,7 @@ static void handle_dying_tuples(void) {
/* we dont know the conntrack direction for now so we try in both ways. */
ct_tuple = &(item->tuple_original);
#if IS_ENABLED(CONFIG_IPV6)
if (ct_tuple->src.l3num == PF_INET) {
#endif
ip = (ct_tuple->src).u3.ip;
port = be16_to_cpu((ct_tuple->src).u.udp.port);
mapping = get_mapping_by_int_src(ip, port);
if (mapping == NULL) {
ct_tuple = &(item->tuple_reply);
ip = (ct_tuple->src).u3.ip;
port = be16_to_cpu((ct_tuple->src).u.udp.port);
mapping = get_mapping_by_int_src(ip, port);
if (mapping != NULL) {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): INBOUND dying conntrack at ext port %d\n", mapping->port);
}
} else {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): OUTBOUND dying conntrack at ext port %d\n", mapping->port);
}

if (mapping == NULL) {
goto next;
}

/* look for the corresponding out-dated tuple and free it */
list_for_each_safe(iter_2, tmp_2, &mapping->original_tuple_list) {
original_tuple_item = list_entry(iter_2, struct nat_mapping_original_tuple, node);

if (nf_ct_tuple_equal(&original_tuple_item->tuple, &(item->tuple_original))) {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): tuple %s expired. free this tuple.\n",
nf_ct_stringify_tuple(&original_tuple_item->tuple));
list_del(&original_tuple_item->node);
kfree(original_tuple_item);
(mapping->refer_count)--;
}
}

/* then kill the mapping if needed*/
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): refer_count for mapping at ext_port %d is now %d\n", mapping->port, mapping->refer_count);
if (mapping->refer_count <= 0) {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): kill expired mapping at ext port %d\n", mapping->port);
kill_mapping(mapping);
}
#if IS_ENABLED(CONFIG_IPV6)
} else if (likely(ct_tuple->src.l3num == PF_INET6)) {
if (ct_tuple->src.l3num == PF_INET6) {
ip6 = &(ct_tuple->src).u3;
port = be16_to_cpu((ct_tuple->src).u.udp.port);
ext_ip6 = &item->tuple_reply.dst.u3;
Expand Down Expand Up @@ -822,8 +781,52 @@ static void handle_dying_tuples(void) {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): kill expired mapping at ext port %d\n", mapping6->port);
kill_mapping6(mapping6);
}
goto next;
}
if (unlikely(ct_tuple->src.l3num != PF_INET))
#else
if (ct_tuple->src.l3num != PF_INET)
#endif
goto next;

ip = (ct_tuple->src).u3.ip;
port = be16_to_cpu((ct_tuple->src).u.udp.port);
mapping = get_mapping_by_int_src(ip, port);
if (mapping == NULL) {
ct_tuple = &(item->tuple_reply);
ip = (ct_tuple->src).u3.ip;
port = be16_to_cpu((ct_tuple->src).u.udp.port);
mapping = get_mapping_by_int_src(ip, port);
if (mapping != NULL) {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): INBOUND dying conntrack at ext port %d\n", mapping->port);
}
} else {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): OUTBOUND dying conntrack at ext port %d\n", mapping->port);
}

if (mapping == NULL) {
goto next;
}

/* look for the corresponding out-dated tuple and free it */
list_for_each_safe(iter_2, tmp_2, &mapping->original_tuple_list) {
original_tuple_item = list_entry(iter_2, struct nat_mapping_original_tuple, node);

if (nf_ct_tuple_equal(&original_tuple_item->tuple, &(item->tuple_original))) {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): tuple %s expired. free this tuple.\n",
nf_ct_stringify_tuple(&original_tuple_item->tuple));
list_del(&original_tuple_item->node);
kfree(original_tuple_item);
(mapping->refer_count)--;
}
}

/* then kill the mapping if needed*/
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): refer_count for mapping at ext_port %d is now %d\n", mapping->port, mapping->refer_count);
if (mapping->refer_count <= 0) {
pr_debug("xt_FULLCONENAT: handle_dying_tuples(): kill expired mapping at ext port %d\n", mapping->port);
kill_mapping(mapping);
}

next:
list_del(&item->list);
Expand Down

0 comments on commit 2ca0c68

Please sign in to comment.