Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Changli Gao and committed by
Simon Horman
17a8f8e3 731109e7

+27 -14
+27 -14
net/netfilter/ipvs/ip_vs_xmit.c
··· 43 43 44 44 #include <net/ip_vs.h> 45 45 46 + enum { 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 55 * Destination cache to speed up outgoing route lookup ··· 84 77 return dst; 85 78 } 86 79 87 - /* 88 - * Get route to destination or remote server 89 - * rt_mode: flags, &1=Allow local dest, &2=Allow non-local dest, 90 - * &4=Allow redirect from remote daddr to local 91 - */ 80 + /* Get route to destination or remote server */ 92 81 static struct rtable * 93 82 __ip_vs_get_out_rt(struct sk_buff *skb, struct ip_vs_dest *dest, 94 83 __be32 daddr, u32 rtos, int rt_mode) ··· 129 126 } 130 127 131 128 local = rt->rt_flags & RTCF_LOCAL; 132 - if (!((local ? 1 : 2) & rt_mode)) { 129 + if (!((local ? IP_VS_RT_MODE_LOCAL : IP_VS_RT_MODE_NON_LOCAL) & 130 + rt_mode)) { 133 131 IP_VS_DBG_RL("Stopping traffic to %s address, dest: %pI4\n", 134 132 (rt->rt_flags & RTCF_LOCAL) ? 135 133 "local":"non-local", &rt->rt_dst); 136 134 ip_rt_put(rt); 137 135 return NULL; 138 136 } 139 - if (local && !(rt_mode & 4) && !((ort = skb_rtable(skb)) && 140 - ort->rt_flags & RTCF_LOCAL)) { 137 + if (local && !(rt_mode & IP_VS_RT_MODE_RDR) && 138 + !((ort = skb_rtable(skb)) && ort->rt_flags & RTCF_LOCAL)) { 141 139 IP_VS_DBG_RL("Redirect from non-local address %pI4 to local " 142 140 "requires NAT method, dest: %pI4\n", 143 141 &ip_hdr(skb)->daddr, &rt->rt_dst); ··· 387 383 388 384 EnterFunction(10); 389 385 390 - if (!(rt = __ip_vs_get_out_rt(skb, NULL, iph->daddr, 391 - RT_TOS(iph->tos), 2))) 386 + if (!(rt = __ip_vs_get_out_rt(skb, NULL, iph->daddr, RT_TOS(iph->tos), 387 + IP_VS_RT_MODE_NON_LOCAL))) 392 388 goto tx_error_icmp; 393 389 394 390 /* MTU checking */ ··· 516 512 } 517 513 518 514 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, 519 - RT_TOS(iph->tos), 1|2|4))) 515 + RT_TOS(iph->tos), 516 + IP_VS_RT_MODE_LOCAL | 517 + IP_VS_RT_MODE_NON_LOCAL | 518 + IP_VS_RT_MODE_RDR))) 520 519 goto tx_error_icmp; 521 520 local = rt->rt_flags & RTCF_LOCAL; 522 521 /* ··· 762 755 EnterFunction(10); 763 756 764 757 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, 765 - RT_TOS(tos), 1|2))) 758 + RT_TOS(tos), IP_VS_RT_MODE_LOCAL | 759 + IP_VS_RT_MODE_NON_LOCAL))) 766 760 goto tx_error_icmp; 767 761 if (rt->rt_flags & RTCF_LOCAL) { 768 762 ip_rt_put(rt); ··· 992 984 EnterFunction(10); 993 985 994 986 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, 995 - RT_TOS(iph->tos), 1|2))) 987 + RT_TOS(iph->tos), 988 + IP_VS_RT_MODE_LOCAL | 989 + IP_VS_RT_MODE_NON_LOCAL))) 996 990 goto tx_error_icmp; 997 991 if (rt->rt_flags & RTCF_LOCAL) { 998 992 ip_rt_put(rt); ··· 1138 1128 */ 1139 1129 1140 1130 if (!(rt = __ip_vs_get_out_rt(skb, cp->dest, cp->daddr.ip, 1141 - RT_TOS(ip_hdr(skb)->tos), 1|2|4))) 1131 + RT_TOS(ip_hdr(skb)->tos), 1132 + IP_VS_RT_MODE_LOCAL | 1133 + IP_VS_RT_MODE_NON_LOCAL | 1134 + IP_VS_RT_MODE_RDR))) 1142 1135 goto tx_error_icmp; 1143 1136 local = rt->rt_flags & RTCF_LOCAL; 1144 1137