Skip to content

Commit 073b04e

Browse files
bigcloudsummakynes
authored andcommitted
ipvs: inspect reply packets from DR/TUN real servers
Just like for MASQ, inspect the reply packets coming from DR/TUN real servers and alter the connection's state and timeout according to the protocol. It's ipvs's duty to do traffic statistic if packets get hit, no matter what mode it is. Signed-off-by: longguang.yue <bigclouds@163.com> Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent bc081a6 commit 073b04e

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

net/netfilter/ipvs/ip_vs_conn.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
402402
{
403403
unsigned int hash;
404404
struct ip_vs_conn *cp, *ret=NULL;
405+
const union nf_inet_addr *saddr;
406+
__be16 sport;
405407

406408
/*
407409
* Check for "full" addressed entries
@@ -411,10 +413,20 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
411413
rcu_read_lock();
412414

413415
hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
414-
if (p->vport == cp->cport && p->cport == cp->dport &&
415-
cp->af == p->af &&
416+
if (p->vport != cp->cport)
417+
continue;
418+
419+
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
420+
sport = cp->vport;
421+
saddr = &cp->vaddr;
422+
} else {
423+
sport = cp->dport;
424+
saddr = &cp->daddr;
425+
}
426+
427+
if (p->cport == sport && cp->af == p->af &&
416428
ip_vs_addr_equal(p->af, p->vaddr, &cp->caddr) &&
417-
ip_vs_addr_equal(p->af, p->caddr, &cp->daddr) &&
429+
ip_vs_addr_equal(p->af, p->caddr, saddr) &&
418430
p->protocol == cp->protocol &&
419431
cp->ipvs == p->ipvs) {
420432
if (!__ip_vs_conn_get(cp))

net/netfilter/ipvs/ip_vs_core.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ static int handle_response_icmp(int af, struct sk_buff *skb,
875875
unsigned int verdict = NF_DROP;
876876

877877
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
878-
goto ignore_cp;
878+
goto after_nat;
879879

880880
/* Ensure the checksum is correct */
881881
if (!skb_csum_unnecessary(skb) && ip_vs_checksum_complete(skb, ihl)) {
@@ -901,6 +901,7 @@ static int handle_response_icmp(int af, struct sk_buff *skb,
901901
if (ip_vs_route_me_harder(cp->ipvs, af, skb, hooknum))
902902
goto out;
903903

904+
after_nat:
904905
/* do the statistics and put it back */
905906
ip_vs_out_stats(cp, skb);
906907

@@ -909,8 +910,6 @@ static int handle_response_icmp(int af, struct sk_buff *skb,
909910
ip_vs_notrack(skb);
910911
else
911912
ip_vs_update_conntrack(skb, cp, 0);
912-
913-
ignore_cp:
914913
verdict = NF_ACCEPT;
915914

916915
out:
@@ -1276,6 +1275,9 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
12761275
{
12771276
struct ip_vs_protocol *pp = pd->pp;
12781277

1278+
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
1279+
goto after_nat;
1280+
12791281
IP_VS_DBG_PKT(11, af, pp, skb, iph->off, "Outgoing packet");
12801282

12811283
if (skb_ensure_writable(skb, iph->len))
@@ -1316,6 +1318,7 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
13161318

13171319
IP_VS_DBG_PKT(10, af, pp, skb, iph->off, "After SNAT");
13181320

1321+
after_nat:
13191322
ip_vs_out_stats(cp, skb);
13201323
ip_vs_set_state(cp, IP_VS_DIR_OUTPUT, skb, pd);
13211324
skb->ipvs_property = 1;
@@ -1412,11 +1415,8 @@ ip_vs_out(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, in
14121415
cp = INDIRECT_CALL_1(pp->conn_out_get, ip_vs_conn_out_get_proto,
14131416
ipvs, af, skb, &iph);
14141417

1415-
if (likely(cp)) {
1416-
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
1417-
goto ignore_cp;
1418+
if (likely(cp))
14181419
return handle_response(af, skb, pd, cp, &iph, hooknum);
1419-
}
14201420

14211421
/* Check for real-server-started requests */
14221422
if (atomic_read(&ipvs->conn_out_counter)) {
@@ -1475,14 +1475,9 @@ ip_vs_out(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, in
14751475
}
14761476
}
14771477

1478-
out:
14791478
IP_VS_DBG_PKT(12, af, pp, skb, iph.off,
14801479
"ip_vs_out: packet continues traversal as normal");
14811480
return NF_ACCEPT;
1482-
1483-
ignore_cp:
1484-
__ip_vs_conn_put(cp);
1485-
goto out;
14861481
}
14871482

14881483
/*

0 commit comments

Comments
 (0)