Index: src/proxy.c =================================================================== --- src/proxy.c (revisión: 48) +++ src/proxy.c (copia de trabajo) @@ -25,7 +25,42 @@ #define dprintf #endif -int nlh_payload_host2network(struct nfattr *nfa, int len) +struct nested_attr { + struct nested_attr *next; +}; + +static struct nested_attr is_nested_tuple_ip[CTA_IP_MAX] = {}; +static struct nested_attr is_nested_tuple_proto[CTA_PROTO_MAX] = {}; +static struct nested_attr is_nested_protoinfo_tcp[CTA_PROTOINFO_TCP_MAX] = {}; +static struct nested_attr is_nested_nat_proto[CTA_PROTONAT_MAX] = {}; + +static struct nested_attr is_nested_tuple[CTA_TUPLE_MAX] = { + [CTA_TUPLE_IP-1] = { .next = is_nested_tuple_ip }, + [CTA_TUPLE_PROTO-1] = { .next = is_nested_tuple_proto }, +}; +static struct nested_attr is_nested_protoinfo[CTA_PROTOINFO_MAX] = { + [CTA_PROTOINFO_TCP-1] = { .next = is_nested_protoinfo_tcp }, +}; +static struct nested_attr is_nested_counters[CTA_COUNTERS_MAX] = {}; +static struct nested_attr is_nested_nat[CTA_NAT_MAX] = { + [CTA_NAT_PROTO-1] = { .next = is_nested_nat_proto }, +}; +static struct nested_attr is_nested_help[CTA_HELP_MAX] = {}; + +struct nested_attr is_nested[CTA_MAX] = { + [CTA_TUPLE_ORIG-1] = { .next = is_nested_tuple }, + [CTA_TUPLE_REPLY-1] = { .next = is_nested_tuple }, + [CTA_PROTOINFO-1] = { .next = is_nested_protoinfo }, + [CTA_HELP-1] = { .next = is_nested_help }, + [CTA_NAT_SRC-1] = { .next = is_nested_nat }, + [CTA_COUNTERS_ORIG-1] = { .next = is_nested_counters }, + [CTA_COUNTERS_REPLY-1] = { .next = is_nested_counters }, + [CTA_NAT_DST-1] = { .next = is_nested_nat }, +}; + +static int payload_hton(struct nfattr *nfa, + int len, + struct nested_attr *is_nested) { struct nfattr *__nfa; @@ -36,12 +71,13 @@ nfa->nfa_len, len, nfa->nfa_type & NFNL_NFA_NEST ? "NEST":""); - if (nfa->nfa_type & NFNL_NFA_NEST) { + if (is_nested[NFA_TYPE(nfa)-1].next) { if (NFA_PAYLOAD(nfa) > len) return -1; - if (nlh_payload_host2network(NFA_DATA(nfa), - NFA_PAYLOAD(nfa)) == -1) + if (payload_hton(NFA_DATA(nfa), + NFA_PAYLOAD(nfa), + is_nested[NFA_TYPE(nfa)-1].next) == -1) return -1; } @@ -70,10 +106,10 @@ nfhdr->res_id = htons(nfhdr->res_id); - return nlh_payload_host2network(NFM_NFA(NLMSG_DATA(nlh)), len); + return payload_hton(NFM_NFA(NLMSG_DATA(nlh)), len, is_nested); } -int nlh_payload_network2host(struct nfattr *nfa, int len) +int payload_ntoh(struct nfattr *nfa, int len, struct nested_attr *is_nested) { nfa->nfa_type = ntohs(nfa->nfa_type); nfa->nfa_len = ntohs(nfa->nfa_len); @@ -85,12 +121,13 @@ nfa->nfa_len, len, nfa->nfa_type & NFNL_NFA_NEST ? "NEST":""); - if (nfa->nfa_type & NFNL_NFA_NEST) { + if (is_nested[NFA_TYPE(nfa)-1].next) { if (NFA_PAYLOAD(nfa) > len) return -1; - if (nlh_payload_network2host(NFA_DATA(nfa), - NFA_PAYLOAD(nfa)) == -1) + if (payload_ntoh(NFA_DATA(nfa), + NFA_PAYLOAD(nfa), + is_nested[NFA_TYPE(nfa)-1].next) == -1) return -1; } @@ -120,5 +157,5 @@ nfhdr->res_id = ntohs(nfhdr->res_id); - return nlh_payload_network2host(NFM_NFA(NLMSG_DATA(nlh)), len); + return payload_ntoh(NFM_NFA(NLMSG_DATA(nlh)), len, is_nested); }