11 #include <asm/types.h>
13 #include <linux/list.h>
16 #include <linux/compiler.h>
21 #include <linux/netfilter.h>
23 #include <linux/ipv6.h>
25 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
44 #ifdef CONFIG_IP_VS_DEBUG
51 return dev_net(skb->
dev);
52 if (skb_dst(skb) && skb_dst(skb)->
dev)
53 return dev_net(skb_dst(skb)->
dev);
54 WARN(skb->
sk,
"Maybe skb_sknet should be used in %s() at line:%d\n",
57 return sock_net(skb->
sk);
58 pr_err(
"There is no net ptr to find in the skb in %s() line:%d\n",
62 return dev_net(skb->
dev ? : skb_dst(skb)->
dev);
69 static inline struct net *skb_sknet(
const struct sk_buff *skb)
72 #ifdef CONFIG_IP_VS_DEBUG
75 return sock_net(skb->
sk);
76 WARN(skb->
dev,
"Maybe skb_net should be used instead in %s() line:%d\n",
79 return dev_net(skb->
dev);
80 pr_err(
"There is no net ptr to find in the skb in %s() line:%d\n",
84 return sock_net(skb->
sk);
94 static inline struct net *seq_file_single_net(
struct seq_file *seq)
117 #ifdef CONFIG_IP_VS_IPV6
119 const struct ipv6hdr *iph = nh;
127 const struct iphdr *iph = nh;
128 iphdr->
len = iph->ihl * 4;
138 #ifdef CONFIG_IP_VS_IPV6
146 static inline int ip_vs_addr_equal(
int af,
const union nf_inet_addr *
a,
149 #ifdef CONFIG_IP_VS_IPV6
151 return ipv6_addr_equal(&a->
in6, &b->
in6);
153 return a->
ip == b->
ip;
156 #ifdef CONFIG_IP_VS_DEBUG
157 #include <linux/net.h>
159 extern int ip_vs_get_debug_level(
void);
161 static inline const char *ip_vs_dbg_addr(
int af,
char *
buf,
size_t buf_len,
166 #ifdef CONFIG_IP_VS_IPV6
168 len =
snprintf(&buf[*idx], buf_len - *idx,
"[%pI6]",
172 len =
snprintf(&buf[*idx], buf_len - *idx,
"%pI4",
176 BUG_ON(*idx > buf_len + 1);
177 return &buf[*idx - len];
180 #define IP_VS_DBG_BUF(level, msg, ...) \
182 char ip_vs_dbg_buf[160]; \
183 int ip_vs_dbg_idx = 0; \
184 if (level <= ip_vs_get_debug_level()) \
185 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
187 #define IP_VS_ERR_BUF(msg...) \
189 char ip_vs_dbg_buf[160]; \
190 int ip_vs_dbg_idx = 0; \
195 #define IP_VS_DBG_ADDR(af, addr) \
196 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
197 sizeof(ip_vs_dbg_buf), addr, \
200 #define IP_VS_DBG(level, msg, ...) \
202 if (level <= ip_vs_get_debug_level()) \
203 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
205 #define IP_VS_DBG_RL(msg, ...) \
207 if (net_ratelimit()) \
208 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
210 #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
212 if (level <= ip_vs_get_debug_level()) \
213 pp->debug_packet(af, pp, skb, ofs, msg); \
215 #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
217 if (level <= ip_vs_get_debug_level() && \
219 pp->debug_packet(af, pp, skb, ofs, msg); \
222 #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
223 #define IP_VS_ERR_BUF(msg...) do {} while (0)
224 #define IP_VS_DBG(level, msg...) do {} while (0)
225 #define IP_VS_DBG_RL(msg...) do {} while (0)
226 #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
227 #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
230 #define IP_VS_BUG() BUG()
231 #define IP_VS_ERR_RL(msg, ...) \
233 if (net_ratelimit()) \
234 pr_err(msg, ##__VA_ARGS__); \
237 #ifdef CONFIG_IP_VS_DEBUG
238 #define EnterFunction(level) \
240 if (level <= ip_vs_get_debug_level()) \
242 pr_fmt("Enter: %s, %s line %i\n"), \
243 __func__, __FILE__, __LINE__); \
245 #define LeaveFunction(level) \
247 if (level <= ip_vs_get_debug_level()) \
249 pr_fmt("Leave: %s, %s line %i\n"), \
250 __func__, __FILE__, __LINE__); \
253 #define EnterFunction(level) do {} while (0)
254 #define LeaveFunction(level) do {} while (0)
257 #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
263 #define FTPPORT cpu_to_be16(21)
264 #define FTPDATA cpu_to_be16(20)
404 (*conn_in_get)(
int af,
407 unsigned int proto_off,
411 (*conn_out_get)(
int af,
414 unsigned int proto_off,
426 const char *(*state_name)(
int state);
459 unsigned short proto);
554 static inline int ip_vs_conn_net_eq(
const struct ip_vs_conn *
cp,
558 return cp->net == net;
772 const struct iphdr *iph,
unsigned int proto_off,
777 const struct iphdr *iph,
unsigned int proto_off,
804 #define IP_VS_RTAB_BITS 4
805 #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
806 #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
812 #define IP_VS_PROTO_TAB_SIZE 32
815 #ifdef CONFIG_IP_VS_PROTO_TCP
816 #define TCP_APP_TAB_BITS 4
817 #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
818 #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
819 struct list_head tcp_apps[TCP_APP_TAB_SIZE];
823 #ifdef CONFIG_IP_VS_PROTO_UDP
824 #define UDP_APP_TAB_BITS 4
825 #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
826 #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
827 struct list_head udp_apps[UDP_APP_TAB_SIZE];
831 #ifdef CONFIG_IP_VS_PROTO_SCTP
832 #define SCTP_APP_TAB_BITS 4
833 #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
834 #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
836 struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
876 #ifdef CONFIG_IP_VS_NFCT
877 int sysctl_conntrack;
924 #define DEFAULT_SYNC_THRESHOLD 3
925 #define DEFAULT_SYNC_PERIOD 50
926 #define DEFAULT_SYNC_VER 1
927 #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ)
928 #define DEFAULT_SYNC_RETRIES 0
929 #define IPVS_SYNC_WAKEUP_RATE 8
930 #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)
931 #define IPVS_SYNC_SEND_DELAY (HZ / 50)
932 #define IPVS_SYNC_CHECK_PERIOD HZ
933 #define IPVS_SYNC_FLUSH_TIME (HZ * 2)
934 #define IPVS_SYNC_PORTS_MAX (1 << 6)
948 static inline unsigned int sysctl_sync_refresh_period(
struct netns_ipvs *
ipvs)
995 static inline unsigned int sysctl_sync_refresh_period(
struct netns_ipvs *
ipvs)
1038 #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
1040 #define IP_VS_APP_TYPE_FTP 1
1054 static inline void ip_vs_conn_fill_param(
struct net *
net,
int af,
int protocol,
1077 unsigned int proto_off,
1084 unsigned int proto_off,
1088 static inline void __ip_vs_conn_put(
struct ip_vs_conn *
cp)
1109 static inline void ip_vs_control_del(
struct ip_vs_conn *
cp)
1115 IP_VS_DBG_ADDR(cp->
af, &cp->
caddr),
1117 IP_VS_DBG_ADDR(cp->
af, &cp->
vaddr),
1124 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1125 IP_VS_DBG_ADDR(cp->
af, &cp->
caddr),
1127 IP_VS_DBG_ADDR(cp->
af, &ctl_cp->
caddr),
1134 IP_VS_DBG_ADDR(cp->
af, &cp->
caddr),
1136 IP_VS_DBG_ADDR(cp->
af, &cp->
vaddr),
1148 IP_VS_ERR_BUF(
"request control ADD for already controlled: "
1150 IP_VS_DBG_ADDR(cp->
af, &cp->
caddr),
1152 IP_VS_DBG_ADDR(cp->
af, &cp->
vaddr),
1155 ip_vs_control_del(cp);
1159 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1160 IP_VS_DBG_ADDR(cp->
af, &cp->
caddr),
1162 IP_VS_DBG_ADDR(cp->
af, &ctl_cp->
caddr),
1190 #define IP_VS_APP_MAX_PORTS 8
1214 #define ip_vs_pe_get(pe) \
1215 if (pe && pe->module) \
1216 __module_get(pe->module);
1218 #define ip_vs_pe_put(pe) \
1219 if (pe && pe->module) \
1220 module_put(pe->module);
1231 const char *
name,
int to);
1274 static inline void ip_vs_service_put(
struct ip_vs_service *svc)
1333 #ifdef CONFIG_IP_VS_IPV6
1334 extern int ip_vs_bypass_xmit_v6
1336 extern int ip_vs_nat_xmit_v6
1338 extern int ip_vs_tunnel_xmit_v6
1340 extern int ip_vs_dr_xmit_v6
1342 extern int ip_vs_icmp_xmit_v6
1347 #ifdef CONFIG_SYSCTL
1354 static inline int ip_vs_todrop(
struct netns_ipvs *ipvs)
1356 if (!ipvs->drop_rate)
1358 if (--ipvs->drop_counter > 0)
1360 ipvs->drop_counter = ipvs->drop_rate;
1364 static inline int ip_vs_todrop(
struct netns_ipvs *ipvs) {
return 0; }
1370 #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
1372 static inline char ip_vs_fwd_tag(
struct ip_vs_conn *cp)
1396 #ifdef CONFIG_IP_VS_IPV6
1405 __be32 diff[2] = { ~old,
new };
1410 #ifdef CONFIG_IP_VS_IPV6
1414 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
1415 new[3],
new[2],
new[1],
new[0] };
1423 __be16 diff[2] = { ~old,
new };
1431 static inline void ip_vs_notrack(
struct sk_buff *skb)
1433 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1435 struct nf_conn *
ct = nf_ct_get(skb, &ctinfo);
1437 if (!ct || !nf_ct_is_untracked(ct)) {
1438 nf_conntrack_put(skb->nfct);
1439 skb->nfct = &nf_ct_untracked_get()->ct_general;
1441 nf_conntrack_get(skb->nfct);
1446 #ifdef CONFIG_IP_VS_NFCT
1451 static inline int ip_vs_conntrack_enabled(
struct netns_ipvs *ipvs)
1453 #ifdef CONFIG_SYSCTL
1454 return ipvs->sysctl_conntrack;
1470 static inline int ip_vs_conntrack_enabled(
struct netns_ipvs *ipvs)
1491 static inline unsigned int