aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChangli Gao <xiaosuo@gmail.com>2011-02-23 19:19:57 -0500
committerSimon Horman <horms@verge.net.au>2011-02-23 19:45:36 -0500
commit17a8f8e3734920cf2f030f2fa521a0b940ef6f90 (patch)
treeba67c5fbd286aeb0d078f644a9e31d2e51bcacb1
parent731109e78415b4cc6c2f8de6c11b37f0e40741f8 (diff)
ipvs: use enum to instead of magic numbers
Signed-off-by: Changli Gao <xiaosuo@gmail.com> Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r--net/netfilter/ipvs/ip_vs_xmit.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index 1f2a4e35fb11..a48239aba33b 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -43,6 +43,13 @@
43 43
44#include <net/ip_vs.h> 44#include <net/ip_vs.h>
45 45
46enum {
47 IP_VS_RT_MODE_LOCAL = 1, /* Allow local dest */
48 IP_VS_RT_MODE_NON_LOCAL = 2, /* Allow non-local dest */
49 IP_VS_RT_MODE_RDR = 4, /* Allow redirect from remote daddr to
50 * local
51 */
52};
46 53
47/* 54/*
48 * Destination cache to speed up outgoing route lookup 55 * Destination cache to speed up outgoing route lookup
@@ -77,11 +84,7 @@ __ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos)
77 return dst; 84 return dst;
78} 85}
79 86
80/* 87/* Get route to destination or remote server */
81 * Get route to destination or remote server
82 * rt_mode: flags, &1=Allow local dest, &2=Allow non-local dest,
83 * &4=Allow redirect from remote daddr to local
84 */
85static struct rtable * 88static struct rtable *
86__ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest, 89__ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest,
87 __be32 daddr, u32 rtos, int rt_mode) 90 __be32 daddr, u32 rtos, int rt_mode)
@@ -126,15 +129,16 @@ __ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest,
126 } 129 }
127 130
128 local = rt->rt_flags & RTCF_LOCAL; 131 local = rt->rt_flags & RTCF_LOCAL;
129 if (!((local ? 1 : 2) & rt_mode)) { 132 if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) &
133 rt_mode)) {
130 IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI4\n", 134 IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI4\n",
131 (rt->rt_flags & RTCF_LOCAL) ? 135 (rt->rt_flags & RTCF_LOCAL) ?
132 "local":"non-local", &rt->rt_dst); 136 "local":"non-local", &rt->rt_dst);
133 ip_rt_put(rt); 137 ip_rt_put(rt);
134 return NULL; 138 return NULL;
135 } 139 }
136 if (local && !(rt_mode & 4) && !((ort = skb_rtable(skb)) && 140 if (local && !(rt_mode & IP_VS_RT_MODE_RDR) &&
137 ort->rt_flags & RTCF_LOCAL)) { 141 !((ort = skb_rtable(skb)) && ort->rt_flags & RTCF_LOCAL)) {
138 IP_VS_DBG_RL("Redirect from non-local address %pI4 to local " 142 IP_VS_DBG_RL("Redirect from non-local address %pI4 to local "
139 "requires NAT method, dest: %pI4\n", 143 "requires NAT method, dest: %pI4\n",
140 &ip_hdr(skb)->daddr, &rt->rt_dst); 144 &ip_hdr(skb)->daddr, &rt->rt_dst);
@@ -383,8 +387,8 @@ ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
383 387
384 EnterFunction(10); 388 EnterFunction(10);
385 389
386 if (!(rt = __ip_vs_get_out_rt(skb, NULL, iph->daddr, 390 if (!(rt = __ip_vs_get_out_rt(skb, NULL, iph->daddr, RT_TOS(iph->tos),
387 RT_TOS(iph->tos), 2))) 391 IP_VS_RT_MODE_NON_LOCAL)))
388 goto tx_error_icmp; 392 goto tx_error_icmp;
389 393
390 /* MTU checking */ 394 /* MTU checking */
@@ -512,7 +516,10 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
512 } 516 }
513 517
514 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, 518 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
515 RT_TOS(iph->tos), 1|2|4))) 519 RT_TOS(iph->tos),
520 IP_VS_RT_MODE_LOCAL |
521 IP_VS_RT_MODE_NON_LOCAL |
522 IP_VS_RT_MODE_RDR)))
516 goto tx_error_icmp; 523 goto tx_error_icmp;
517 local = rt->rt_flags & RTCF_LOCAL; 524 local = rt->rt_flags & RTCF_LOCAL;
518 /* 525 /*
@@ -755,7 +762,8 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
755 EnterFunction(10); 762 EnterFunction(10);
756 763
757 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, 764 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
758 RT_TOS(tos), 1|2))) 765 RT_TOS(tos), IP_VS_RT_MODE_LOCAL |
766 IP_VS_RT_MODE_NON_LOCAL)))
759 goto tx_error_icmp; 767 goto tx_error_icmp;
760 if (rt->rt_flags & RTCF_LOCAL) { 768 if (rt->rt_flags & RTCF_LOCAL) {
761 ip_rt_put(rt); 769 ip_rt_put(rt);
@@ -984,7 +992,9 @@ ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
984 EnterFunction(10); 992 EnterFunction(10);
985 993
986 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, 994 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
987 RT_TOS(iph->tos), 1|2))) 995 RT_TOS(iph->tos),
996 IP_VS_RT_MODE_LOCAL |
997 IP_VS_RT_MODE_NON_LOCAL)))
988 goto tx_error_icmp; 998 goto tx_error_icmp;
989 if (rt->rt_flags & RTCF_LOCAL) { 999 if (rt->rt_flags & RTCF_LOCAL) {
990 ip_rt_put(rt); 1000 ip_rt_put(rt);
@@ -1128,7 +1138,10 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1128 */ 1138 */
1129 1139
1130 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, 1140 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip,
1131 RT_TOS(ip_hdr(skb)->tos), 1|2|4))) 1141 RT_TOS(ip_hdr(skb)->tos),
1142 IP_VS_RT_MODE_LOCAL |
1143 IP_VS_RT_MODE_NON_LOCAL |
1144 IP_VS_RT_MODE_RDR)))
1132 goto tx_error_icmp; 1145 goto tx_error_icmp;
1133 local = rt->rt_flags & RTCF_LOCAL; 1146 local = rt->rt_flags & RTCF_LOCAL;
1134 1147