miniupnpd/netfilter_nft: fix get_redirect_rule_by_index()

should fix #462
This commit is contained in:
Thomas Bernard 2020-06-02 09:55:25 +02:00
parent c8cbf9f6ce
commit e1f3478519
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 4 additions and 12 deletions

View File

@ -449,12 +449,13 @@ get_peer_rule_by_index(int index,
u_int64_t * packets, u_int64_t * bytes)
{
rule_t *r;
int i = 0;
d_printf(("get_peer_rule_by_index()\n"));
refresh_nft_cache_peer();
LIST_FOREACH(r, &head_peer, entry) {
if (r->index == index) {
if (i++ == index) {
if (ifname != NULL) {
if_indextoname(r->ingress_ifidx, ifname);
}
@ -551,12 +552,13 @@ get_redirect_rule_by_index(int index,
u_int64_t * packets, u_int64_t * bytes)
{
rule_t *r;
int i = 0;
d_printf(("get_redirect_rule_by_index()\n"));
refresh_nft_cache_redirect();
LIST_FOREACH(r, &head_redirect, entry) {
if (r->index == index) {
if (i++ == index) {
if (ifname != NULL) {
if_indextoname(r->ingress_ifidx, ifname);
}

View File

@ -483,11 +483,8 @@ table_cb(const struct nlmsghdr *nlh, void *data)
struct nftnl_expr_iter *itr;
rule_t *r;
char *chain;
int index_filter, index_peer, index_redirect;
UNUSED(data);
index_filter = index_peer = index_redirect = 0;
r = malloc(sizeof(rule_t));
if (r == NULL) {
@ -547,22 +544,16 @@ table_cb(const struct nlmsghdr *nlh, void *data)
case RULE_NAT:
switch (r->nat_type) {
case NFT_NAT_SNAT:
r->index = index_peer;
LIST_INSERT_HEAD(&head_peer, r, entry);
index_peer++;
break;
case NFT_NAT_DNAT:
r->index = index_redirect;
LIST_INSERT_HEAD(&head_redirect, r, entry);
index_redirect++;
break;
}
break;
case RULE_FILTER:
r->index = index_filter;
LIST_INSERT_HEAD(&head_filter, r, entry);
index_filter++;
break;
default:

View File

@ -75,7 +75,6 @@ typedef struct rule_t {
uint64_t bytes;
char * desc;
uint32_t desc_len;
int index;
} rule_t;
LIST_HEAD(rule_list, rule_t);