21 #define KMSG_COMPONENT "IPVS"
22 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
24 #include <linux/module.h>
26 #include <linux/types.h>
27 #include <linux/capability.h>
29 #include <linux/sysctl.h>
34 #include <linux/slab.h>
36 #include <linux/netfilter.h>
37 #include <linux/netfilter_ipv4.h>
43 #ifdef CONFIG_IP_VS_IPV6
51 #include <asm/uaccess.h>
63 #ifdef CONFIG_IP_VS_DEBUG
64 static int sysctl_ip_vs_debug_level = 0;
66 int ip_vs_get_debug_level(
void)
68 return sysctl_ip_vs_debug_level;
77 #ifdef CONFIG_IP_VS_IPV6
79 static bool __ip_vs_addr_is_local_v6(
struct net *
net,
100 static void update_defense_level(
struct netns_ipvs *ipvs)
103 static int old_secure_tcp = 0;
110 availmem =
i.freeram +
i.bufferram;
121 spin_lock(&ipvs->dropentry_lock);
146 spin_unlock(&ipvs->dropentry_lock);
149 spin_lock(&ipvs->droppacket_lock);
156 ipvs->drop_rate = ipvs->drop_counter
166 ipvs->drop_rate = ipvs->drop_counter
178 spin_unlock(&ipvs->droppacket_lock);
181 spin_lock(&ipvs->securetcp_lock);
184 if (old_secure_tcp >= 2)
189 if (old_secure_tcp < 2)
193 if (old_secure_tcp >= 2)
199 if (old_secure_tcp < 2)
202 if (old_secure_tcp >= 2)
208 if (old_secure_tcp < 2)
216 spin_unlock(&ipvs->securetcp_lock);
225 #define DEFENSE_TIMER_PERIOD 1*HZ
232 update_defense_level(ipvs);
255 #define IP_VS_SVC_TAB_BITS 8
256 #define IP_VS_SVC_TAB_SIZE (1 << IP_VS_SVC_TAB_BITS)
257 #define IP_VS_SVC_TAB_MASK (IP_VS_SVC_TAB_SIZE - 1)
268 static inline unsigned int
269 ip_vs_svc_hashkey(
struct net *
net,
int af,
unsigned int proto,
272 register unsigned int porth =
ntohs(port);
275 #ifdef CONFIG_IP_VS_IPV6
277 addr_fold = addr->
ip6[0]^addr->
ip6[1]^
278 addr->
ip6[2]^addr->
ip6[3];
280 addr_fold ^= ((
size_t)net>>8);
289 static inline unsigned int ip_vs_svc_fwm_hashkey(
struct net *net,
__u32 fwmark)
304 pr_err(
"%s(): request for already hashed, called from %pF\n",
305 __func__, __builtin_return_address(0));
315 list_add(&svc->
s_list, &ip_vs_svc_table[hash]);
320 hash = ip_vs_svc_fwm_hashkey(svc->
net, svc->
fwmark);
321 list_add(&svc->
f_list, &ip_vs_svc_fwm_table[hash]);
338 pr_err(
"%s(): request for unhash flagged, called from %pF\n",
339 __func__, __builtin_return_address(0));
361 __ip_vs_service_find(
struct net *net,
int af,
__u16 protocol,
368 hash = ip_vs_svc_hashkey(net, af, protocol, vaddr, vport);
372 && ip_vs_addr_equal(af, &svc->
addr, vaddr)
373 && (svc->
port == vport)
375 && net_eq(svc->
net, net)) {
389 __ip_vs_svc_fwm_find(
struct net *net,
int af,
__u32 fwmark)
395 hash = ip_vs_svc_fwm_hashkey(net, fwmark);
398 if (svc->
fwmark == fwmark && svc->
af == af
399 && net_eq(svc->
net, net)) {
421 svc = __ip_vs_svc_fwm_find(net, af, fwmark);
430 svc = __ip_vs_service_find(net, af, protocol, vaddr, vport);
440 svc = __ip_vs_service_find(net, af, protocol, vaddr,
FTPPORT);
448 svc = __ip_vs_service_find(net, af, protocol, vaddr, 0);
458 IP_VS_DBG_ADDR(af, vaddr),
ntohs(vport),
459 svc ?
"hit" :
"not hit");
481 IP_VS_DBG_ADDR(svc->
af, &svc->
addr),
492 static inline unsigned int ip_vs_rs_hashkey(
int af,
496 register unsigned int porth =
ntohs(port);
499 #ifdef CONFIG_IP_VS_IPV6
501 addr_fold = addr->
ip6[0]^addr->
ip6[1]^
502 addr->
ip6[2]^addr->
ip6[3];
517 if (!list_empty(&dest->
d_list)) {
525 hash = ip_vs_rs_hashkey(dest->
af, &dest->
addr, dest->
port);
536 static int ip_vs_rs_unhash(
struct ip_vs_dest *dest)
541 if (!list_empty(&dest->
d_list)) {
542 list_del_init(&dest->
d_list);
564 hash = ip_vs_rs_hashkey(af, daddr, dport);
569 && ip_vs_addr_equal(af, &dest->
addr, daddr)
570 && (dest->
port == dport)
596 if ((dest->
af == svc->
af)
597 && ip_vs_addr_equal(svc->
af, &dest->
addr, daddr)
598 && (dest->
port == dport)) {
633 dest = ip_vs_lookup_dest(svc, daddr, port);
635 dest = ip_vs_lookup_dest(svc, daddr, port ^ dport);
638 ip_vs_service_put(svc);
666 IP_VS_DBG_ADDR(svc->
af, &dest->
addr),
669 if (dest->
af == svc->
af &&
670 ip_vs_addr_equal(svc->
af, &dest->
addr, daddr) &&
671 dest->
port == dport &&
675 (ip_vs_addr_equal(svc->
af, &dest->
vaddr, &svc->
addr) &&
688 IP_VS_DBG_ADDR(svc->
af, &dest->
addr),
692 __ip_vs_unbind_svc(dest);
711 static void ip_vs_trash_cleanup(
struct net *net)
719 __ip_vs_unbind_svc(dest);
728 #define IP_VS_SHOW_STATS_COUNTER(c) dst->c = src->ustats.c - src->ustats0.c
730 spin_lock_bh(&src->
lock);
740 spin_unlock_bh(&src->
lock);
746 spin_lock_bh(&stats->
lock);
750 #define IP_VS_ZERO_STATS_COUNTER(c) stats->ustats0.c = stats->ustats.c
760 spin_unlock_bh(&stats->
lock);
787 ip_vs_rs_hash(ipvs, dest);
794 __ip_vs_bind_svc(dest, svc);
796 if (dest->
svc != svc) {
797 __ip_vs_unbind_svc(dest);
798 ip_vs_zero_stats(&dest->
stats);
799 __ip_vs_bind_svc(dest, svc);
848 #ifdef CONFIG_IP_VS_IPV6
850 atype = ipv6_addr_type(&udest->
addr.
in6);
853 !__ip_vs_addr_is_local_v6(svc->
net, &udest->
addr.
in6))
868 if (!dest->
stats.cpustats)
876 ip_vs_addr_copy(svc->
af, &dest->
addr, &udest->
addr);
884 INIT_LIST_HEAD(&dest->
d_list);
887 __ip_vs_update_dest(svc, dest, udest, 1);
914 pr_err(
"%s(): server weight less than zero\n", __func__);
919 pr_err(
"%s(): lower threshold is higher than upper threshold\n",
924 ip_vs_addr_copy(svc->
af, &daddr, &udest->
addr);
929 dest = ip_vs_lookup_dest(svc, &daddr, dport);
932 IP_VS_DBG(1,
"%s(): dest already exists\n", __func__);
940 dest = ip_vs_trash_get_dest(svc, &daddr, dport);
944 "dest->refcnt=%d, service %u/%s:%u\n",
945 IP_VS_DBG_ADDR(svc->
af, &daddr),
ntohs(dport),
948 IP_VS_DBG_ADDR(svc->
af, &dest->
vaddr),
956 __ip_vs_update_dest(svc, dest, udest, 1);
962 ret = ip_vs_new_dest(svc, udest, &dest);
983 pr_err(
"%s(): server weight less than zero\n", __func__);
988 pr_err(
"%s(): lower threshold is higher than upper threshold\n",
993 ip_vs_addr_copy(svc->
af, &daddr, &udest->
addr);
998 dest = ip_vs_lookup_dest(svc, &daddr, dport);
1001 IP_VS_DBG(1,
"%s(): dest doesn't exist\n", __func__);
1005 __ip_vs_update_dest(svc, dest, udest, 0);
1015 static void __ip_vs_del_dest(
struct net *net,
struct ip_vs_dest *dest)
1025 ip_vs_rs_unhash(dest);
1036 IP_VS_DBG_ADDR(dest->
af, &dest->
addr),
1049 "dest->refcnt=%d\n",
1050 IP_VS_DBG_ADDR(dest->
af, &dest->
addr),
1077 if (svcupd && svc->
scheduler->update_service)
1093 dest = ip_vs_lookup_dest(svc, &udest->
addr, dport);
1096 IP_VS_DBG(1,
"%s(): destination not found!\n", __func__);
1110 __ip_vs_unlink_dest(svc, dest, 1);
1117 __ip_vs_del_dest(svc->
net, dest);
1143 if (sched ==
NULL) {
1152 pr_info(
"persistence engine module ip_vs_pe_%s "
1159 #ifdef CONFIG_IP_VS_IPV6
1168 IP_VS_DBG(1,
"%s(): no memory\n", __func__);
1173 if (!svc->
stats.cpustats) {
1184 ip_vs_addr_copy(svc->
af, &svc->
addr, &u->
addr);
1209 else if (svc->
port == 0)
1220 ip_vs_svc_hash(svc);
1237 if (svc->
stats.cpustats)
1265 if (sched ==
NULL) {
1274 pr_info(
"persistence engine module ip_vs_pe_%s "
1282 #ifdef CONFIG_IP_VS_IPV6
1304 if (sched != old_sched) {
1360 pr_info(
"%s: enter\n", __func__);
1388 __ip_vs_unlink_dest(svc, dest, 0);
1389 __ip_vs_del_dest(svc->
net, dest);
1397 else if (svc->
port == 0)
1406 IP_VS_DBG_ADDR(svc->
af, &svc->
addr),
1426 ip_vs_svc_unhash(svc);
1433 __ip_vs_del_service(svc);
1445 ip_vs_unlink_service(svc);
1454 static int ip_vs_flush(
struct net *net)
1465 if (net_eq(svc->
net, net))
1466 ip_vs_unlink_service(svc);
1475 &ip_vs_svc_fwm_table[idx],
f_list) {
1476 if (net_eq(svc->
net, net))
1477 ip_vs_unlink_service(svc);
1505 IP_VS_DBG_BUF(3,
"Reset dev:%s dest %s:%u ,dest->refcnt=%d\n",
1507 IP_VS_DBG_ADDR(dest->
af, &dest->
addr),
1524 struct net *net = dev_net(dev);
1537 if (net_eq(svc->
net, net)) {
1540 __ip_vs_dev_reset(dest, dev);
1546 if (net_eq(svc->
net, net)) {
1549 __ip_vs_dev_reset(dest, dev);
1557 __ip_vs_dev_reset(dest, dev);
1573 ip_vs_zero_stats(&dest->
stats);
1575 ip_vs_zero_stats(&svc->
stats);
1580 static int ip_vs_zero_all(
struct net *net)
1587 if (net_eq(svc->
net, net))
1588 ip_vs_zero_service(svc);
1594 if (net_eq(svc->
net, net))
1595 ip_vs_zero_service(svc);
1599 ip_vs_zero_stats(&net_ipvs(net)->tot_stats);
1603 #ifdef CONFIG_SYSCTL
1606 static int three = 3;
1610 void __user *
buffer,
size_t *lenp, loff_t *ppos)
1612 struct net *net =
current->nsproxy->net_ns;
1613 int *valp = table->
data;
1618 if (write && (*valp != val)) {
1619 if ((*valp < 0) || (*valp > 3)) {
1623 update_defense_level(net_ipvs(net));
1630 proc_do_sync_threshold(
ctl_table *table,
int write,
1631 void __user *buffer,
size_t *lenp, loff_t *ppos)
1633 int *valp = table->
data;
1638 memcpy(val, valp,
sizeof(val));
1641 if (write && (valp[0] < 0 || valp[1] < 0 ||
1642 (valp[0] >= valp[1] && valp[1]))) {
1644 memcpy(valp, val,
sizeof(val));
1650 proc_do_sync_mode(
ctl_table *table,
int write,
1651 void __user *buffer,
size_t *lenp, loff_t *ppos)
1653 int *valp = table->
data;
1658 if (write && (*valp != val)) {
1659 if ((*valp < 0) || (*valp > 1)) {
1668 proc_do_sync_ports(
ctl_table *table,
int write,
1669 void __user *buffer,
size_t *lenp, loff_t *ppos)
1671 int *valp = table->
data;
1676 if (write && (*valp != val)) {
1694 .maxlen =
sizeof(
int),
1699 .procname =
"am_droprate",
1700 .maxlen =
sizeof(
int),
1705 .procname =
"drop_entry",
1706 .maxlen =
sizeof(
int),
1711 .procname =
"drop_packet",
1712 .maxlen =
sizeof(
int),
1716 #ifdef CONFIG_IP_VS_NFCT
1718 .procname =
"conntrack",
1719 .maxlen =
sizeof(
int),
1725 .procname =
"secure_tcp",
1726 .maxlen =
sizeof(
int),
1731 .procname =
"snat_reroute",
1732 .maxlen =
sizeof(
int),
1737 .procname =
"sync_version",
1738 .maxlen =
sizeof(
int),
1743 .procname =
"sync_ports",
1744 .maxlen =
sizeof(
int),
1749 .procname =
"sync_qlen_max",
1750 .maxlen =
sizeof(
int),
1755 .procname =
"sync_sock_size",
1756 .maxlen =
sizeof(
int),
1761 .procname =
"cache_bypass",
1762 .maxlen =
sizeof(
int),
1767 .procname =
"expire_nodest_conn",
1768 .maxlen =
sizeof(
int),
1773 .procname =
"expire_quiescent_template",
1774 .maxlen =
sizeof(
int),
1779 .procname =
"sync_threshold",
1781 sizeof(((
struct netns_ipvs *)0)->sysctl_sync_threshold),
1786 .procname =
"sync_refresh_period",
1787 .maxlen =
sizeof(
int),
1792 .procname =
"sync_retries",
1793 .maxlen =
sizeof(
int),
1800 .procname =
"nat_icmp_send",
1801 .maxlen =
sizeof(
int),
1806 .procname =
"pmtu_disc",
1807 .maxlen =
sizeof(
int),
1811 #ifdef CONFIG_IP_VS_DEBUG
1813 .procname =
"debug_level",
1814 .data = &sysctl_ip_vs_debug_level,
1815 .maxlen =
sizeof(
int),
1822 .procname =
"timeout_established",
1823 .data = &vs_timeout_table_dos.timeout[IP_VS_S_ESTABLISHED],
1824 .maxlen =
sizeof(
int),
1829 .procname =
"timeout_synsent",
1830 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYN_SENT],
1831 .maxlen =
sizeof(
int),
1836 .procname =
"timeout_synrecv",
1837 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYN_RECV],
1838 .maxlen =
sizeof(
int),
1843 .procname =
"timeout_finwait",
1844 .data = &vs_timeout_table_dos.timeout[IP_VS_S_FIN_WAIT],
1845 .maxlen =
sizeof(
int),
1850 .procname =
"timeout_timewait",
1851 .data = &vs_timeout_table_dos.timeout[IP_VS_S_TIME_WAIT],
1852 .maxlen =
sizeof(
int),
1857 .procname =
"timeout_close",
1858 .data = &vs_timeout_table_dos.timeout[IP_VS_S_CLOSE],
1859 .maxlen =
sizeof(
int),
1864 .procname =
"timeout_closewait",
1865 .data = &vs_timeout_table_dos.timeout[IP_VS_S_CLOSE_WAIT],
1866 .maxlen =
sizeof(
int),
1871 .procname =
"timeout_lastack",
1872 .data = &vs_timeout_table_dos.timeout[IP_VS_S_LAST_ACK],
1873 .maxlen =
sizeof(
int),
1878 .procname =
"timeout_listen",
1879 .data = &vs_timeout_table_dos.timeout[IP_VS_S_LISTEN],
1880 .maxlen =
sizeof(
int),
1885 .procname =
"timeout_synack",
1886 .data = &vs_timeout_table_dos.timeout[IP_VS_S_SYNACK],
1887 .maxlen =
sizeof(
int),
1892 .procname =
"timeout_udp",
1893 .data = &vs_timeout_table_dos.timeout[IP_VS_S_UDP],
1894 .maxlen =
sizeof(
int),
1899 .procname =
"timeout_icmp",
1900 .data = &vs_timeout_table_dos.timeout[IP_VS_S_ICMP],
1901 .maxlen =
sizeof(
int),
1911 #ifdef CONFIG_PROC_FS
1923 static inline const char *ip_vs_fwd_name(
unsigned int flags)
1925 switch (flags & IP_VS_CONN_F_FWD_MASK) {
1941 struct net *net = seq_file_net(seq);
1942 struct ip_vs_iter *iter = seq->
private;
1949 if (net_eq(svc->
net, net) && pos-- == 0) {
1950 iter->table = ip_vs_svc_table;
1960 if (net_eq(svc->
net, net) && pos-- == 0) {
1961 iter->table = ip_vs_svc_fwm_table;
1971 static void *ip_vs_info_seq_start(
struct seq_file *seq, loff_t *pos)
1980 static void *ip_vs_info_seq_next(
struct seq_file *seq,
void *
v, loff_t *pos)
1983 struct ip_vs_iter *iter;
1988 return ip_vs_info_array(seq,0);
1993 if (iter->table == ip_vs_svc_table) {
1995 if ((e = svc->
s_list.next) != &ip_vs_svc_table[iter->bucket])
1999 while (++iter->bucket < IP_VS_SVC_TAB_SIZE) {
2006 iter->table = ip_vs_svc_fwm_table;
2012 if ((e = svc->
f_list.next) != &ip_vs_svc_fwm_table[iter->bucket])
2016 while (++iter->bucket < IP_VS_SVC_TAB_SIZE) {
2032 static int ip_vs_info_seq_show(
struct seq_file *seq,
void *v)
2036 "IP Virtual Server version %d.%d.%d (size=%d)\n",
2039 "Prot LocalAddress:Port Scheduler Flags\n");
2041 " -> RemoteAddress:Port Forward Weight ActiveConn InActConn\n");
2044 const struct ip_vs_iter *iter = seq->
private;
2047 if (iter->table == ip_vs_svc_table) {
2048 #ifdef CONFIG_IP_VS_IPV6
2077 #ifdef CONFIG_IP_VS_IPV6
2081 " %-7s %-6d %-10d %-10d\n",
2092 "%-7s %-6d %-10d %-10d\n",
2106 .
start = ip_vs_info_seq_start,
2107 .next = ip_vs_info_seq_next,
2108 .stop = ip_vs_info_seq_stop,
2109 .show = ip_vs_info_seq_show,
2115 sizeof(
struct ip_vs_iter));
2120 .open = ip_vs_info_open,
2126 static int ip_vs_stats_show(
struct seq_file *seq,
void *v)
2128 struct net *net = seq_file_single_net(seq);
2133 " Total Incoming Outgoing Incoming Outgoing\n");
2135 " Conns Packets Packets Bytes Bytes\n");
2137 ip_vs_copy_stats(&show, &net_ipvs(net)->tot_stats);
2140 (
unsigned long long)
show.inbytes,
2141 (
unsigned long long)
show.outbytes);
2145 " Conns/s Pkts/s Pkts/s Bytes/s Bytes/s\n");
2153 static int ip_vs_stats_seq_open(
struct inode *inode,
struct file *file)
2160 .open = ip_vs_stats_seq_open,
2166 static int ip_vs_stats_percpu_show(
struct seq_file *seq,
void *v)
2168 struct net *net = seq_file_single_net(seq);
2169 struct ip_vs_stats *tot_stats = &net_ipvs(net)->tot_stats;
2176 " Total Incoming Outgoing Incoming Outgoing\n");
2178 "CPU Conns Packets Packets Bytes Bytes\n");
2183 __u64 inbytes, outbytes;
2186 start = u64_stats_fetch_begin_bh(&u->
syncp);
2187 inbytes = u->
ustats.inbytes;
2188 outbytes = u->
ustats.outbytes;
2189 }
while (u64_stats_fetch_retry_bh(&u->
syncp, start));
2191 seq_printf(seq,
"%3X %8X %8X %8X %16LX %16LX\n",
2197 spin_lock_bh(&tot_stats->
lock);
2199 seq_printf(seq,
" ~ %8X %8X %8X %16LX %16LX\n\n",
2201 tot_stats->
ustats.outpkts,
2202 (
unsigned long long) tot_stats->
ustats.inbytes,
2203 (
unsigned long long) tot_stats->
ustats.outbytes);
2207 spin_unlock_bh(&tot_stats->
lock);
2211 " Conns/s Pkts/s Pkts/s Bytes/s Bytes/s\n");
2222 static int ip_vs_stats_percpu_seq_open(
struct inode *inode,
struct file *file)
2229 .open = ip_vs_stats_percpu_seq_open,
2241 #if defined(CONFIG_IP_VS_PROTO_TCP) || defined(CONFIG_IP_VS_PROTO_UDP)
2245 IP_VS_DBG(2,
"Setting timeout tcp:%d tcpfin:%d udp:%d\n",
2250 #ifdef CONFIG_IP_VS_PROTO_TCP
2264 #ifdef CONFIG_IP_VS_PROTO_UDP
2275 #define SET_CMDID(cmd) (cmd - IP_VS_BASE_CTL)
2276 #define SERVICE_ARG_LEN (sizeof(struct ip_vs_service_user))
2277 #define SVCDEST_ARG_LEN (sizeof(struct ip_vs_service_user) + \
2278 sizeof(struct ip_vs_dest_user))
2279 #define TIMEOUT_ARG_LEN (sizeof(struct ip_vs_timeout_user))
2280 #define DAEMON_ARG_LEN (sizeof(struct ip_vs_daemon_user))
2281 #define MAX_ARG_LEN SVCDEST_ARG_LEN
2300 memset(usvc, 0,
sizeof(*usvc));
2319 memset(udest, 0,
sizeof(*udest));
2330 do_ip_vs_set_ctl(
struct sock *
sk,
int cmd,
void __user *
user,
unsigned int len)
2332 struct net *net = sock_net(sk);
2349 if (len != set_arglen[
SET_CMDID(cmd)]) {
2350 pr_err(
"set_ctl: len %u != %u\n",
2386 ret = ip_vs_flush(net);
2399 ip_vs_copy_usvc_compat(&usvc, usvc_compat);
2400 ip_vs_copy_udest_compat(&udest, udest_compat);
2405 ret = ip_vs_zero_all(net);
2413 pr_err(
"set_ctl: invalid protocol: %d %pI4:%d %s\n",
2422 svc = __ip_vs_service_find(net, usvc.
af, usvc.
protocol,
2425 svc = __ip_vs_svc_fwm_find(net, usvc.
af, usvc.
fwmark);
2438 ret = ip_vs_add_service(net, &usvc, &svc);
2441 ret = ip_vs_edit_service(svc, &usvc);
2444 ret = ip_vs_del_service(svc);
2449 ret = ip_vs_zero_service(svc);
2452 ret = ip_vs_add_dest(svc, &udest);
2455 ret = ip_vs_edit_dest(svc, &udest);
2458 ret = ip_vs_del_dest(svc, &udest);
2490 __ip_vs_get_service_entries(
struct net *net,
2505 if (count >=
get->num_services)
2508 ip_vs_copy_service(&
entry, svc);
2524 if (count >=
get->num_services)
2527 ip_vs_copy_service(&
entry, svc);
2541 __ip_vs_get_dest_entries(
struct net *net,
const struct ip_vs_get_dests *
get,
2549 svc = __ip_vs_svc_fwm_find(net,
AF_INET,
get->fwmark);
2551 svc = __ip_vs_service_find(net,
AF_INET,
get->protocol, &addr,
2560 if (count >=
get->num_dests)
2572 ip_vs_copy_stats(&
entry.stats, &dest->
stats);
2588 #if defined(CONFIG_IP_VS_PROTO_TCP) || defined(CONFIG_IP_VS_PROTO_UDP)
2592 memset(u, 0,
sizeof (*u));
2594 #ifdef CONFIG_IP_VS_PROTO_TCP
2599 #ifdef CONFIG_IP_VS_PROTO_UDP
2607 #define GET_CMDID(cmd) (cmd - IP_VS_BASE_CTL)
2608 #define GET_INFO_ARG_LEN (sizeof(struct ip_vs_getinfo))
2609 #define GET_SERVICES_ARG_LEN (sizeof(struct ip_vs_get_services))
2610 #define GET_SERVICE_ARG_LEN (sizeof(struct ip_vs_service_entry))
2611 #define GET_DESTS_ARG_LEN (sizeof(struct ip_vs_get_dests))
2612 #define GET_TIMEOUT_ARG_LEN (sizeof(struct ip_vs_timeout_user))
2613 #define GET_DAEMON_ARG_LEN (sizeof(struct ip_vs_daemon_user) * 2)
2626 do_ip_vs_get_ctl(
struct sock *sk,
int cmd,
void __user *user,
int *len)
2628 unsigned char arg[128];
2630 unsigned int copylen;
2631 struct net *net = sock_net(sk);
2641 if (*len < get_arglen[
GET_CMDID(cmd)]) {
2642 pr_err(
"get_ctl: len %u < %u\n",
2666 sizeof(
d[0].mcast_ifn));
2672 sizeof(
d[1].mcast_ifn));
2689 sprintf(buf,
"IP Virtual Server version %d.%d.%d (size=%d)",
2716 size =
sizeof(*get) +
2719 pr_err(
"length: %u != %u\n", *len, size);
2723 ret = __ip_vs_get_service_entries(net,
get, user);
2734 addr.
ip = entry->addr;
2736 svc = __ip_vs_svc_fwm_find(net,
AF_INET, entry->fwmark);
2738 svc = __ip_vs_service_find(net,
AF_INET,
2739 entry->protocol, &addr,
2742 ip_vs_copy_service(entry, svc);
2756 size =
sizeof(*get) +
2759 pr_err(
"length: %u != %u\n", *len, size);
2763 ret = __ip_vs_get_dest_entries(net,
get, user);
2771 __ip_vs_get_timeouts(net, &
t);
2787 static struct nf_sockopt_ops ip_vs_sockopts = {
2790 .set_optmax = IP_VS_SO_SET_MAX+1,
2791 .set = do_ip_vs_set_ctl,
2793 .get_optmax = IP_VS_SO_GET_MAX+1,
2794 .get = do_ip_vs_get_ctl,
2864 static int ip_vs_genl_fill_stats(
struct sk_buff *
skb,
int container_type,
2868 struct nlattr *nl_stats = nla_nest_start(skb, container_type);
2872 ip_vs_copy_stats(&ustats, stats);
2884 goto nla_put_failure;
2885 nla_nest_end(skb, nl_stats);
2890 nla_nest_cancel(skb, nl_stats);
2894 static int ip_vs_genl_fill_service(
struct sk_buff *skb,
2897 struct nlattr *nl_service;
2906 goto nla_put_failure;
2909 goto nla_put_failure;
2914 goto nla_put_failure;
2923 goto nla_put_failure;
2925 goto nla_put_failure;
2927 nla_nest_end(skb, nl_service);
2932 nla_nest_cancel(skb, nl_service);
2936 static int ip_vs_genl_dump_service(
struct sk_buff *skb,
2948 if (ip_vs_genl_fill_service(skb, svc) < 0)
2949 goto nla_put_failure;
2951 return genlmsg_end(skb, hdr);
2954 genlmsg_cancel(skb, hdr);
2958 static int ip_vs_genl_dump_services(
struct sk_buff *skb,
2962 int start = cb->
args[0];
2964 struct net *net = skb_sknet(skb);
2969 if (++idx <= start || !net_eq(svc->
net, net))
2971 if (ip_vs_genl_dump_service(skb, svc, cb) < 0) {
2973 goto nla_put_failure;
2980 if (++idx <= start || !net_eq(svc->
net, net))
2982 if (ip_vs_genl_dump_service(skb, svc, cb) < 0) {
2984 goto nla_put_failure;
2996 static int ip_vs_genl_parse_service(
struct net *net,
3002 struct nlattr *nla_af, *nla_port, *nla_fwmark, *nla_protocol, *nla_addr;
3016 if (!(nla_af && (nla_fwmark || (nla_port && nla_protocol && nla_addr))))
3019 memset(usvc, 0,
sizeof(*usvc));
3021 usvc->
af = nla_get_u16(nla_af);
3022 #ifdef CONFIG_IP_VS_IPV6
3031 usvc->
fwmark = nla_get_u32(nla_fwmark);
3033 usvc->
protocol = nla_get_u16(nla_protocol);
3035 usvc->
port = nla_get_u16(nla_port);
3040 svc = __ip_vs_svc_fwm_find(net, usvc->
af, usvc->
fwmark);
3042 svc = __ip_vs_service_find(net, usvc->
af, usvc->
protocol,
3048 struct nlattr *nla_sched, *nla_flags, *nla_pe, *nla_timeout,
3058 if (!(nla_sched && nla_flags && nla_timeout && nla_netmask))
3061 nla_memcpy(&flags, nla_flags,
sizeof(flags));
3072 usvc->
timeout = nla_get_u32(nla_timeout);
3073 usvc->
netmask = nla_get_u32(nla_netmask);
3079 static struct ip_vs_service *ip_vs_genl_find_service(
struct net *net,
3086 ret = ip_vs_genl_parse_service(net, &usvc, nla, 0, &svc);
3087 return ret ? ERR_PTR(ret) : svc;
3102 IP_VS_CONN_F_FWD_MASK)) ||
3113 goto nla_put_failure;
3115 goto nla_put_failure;
3117 nla_nest_end(skb, nl_dest);
3122 nla_nest_cancel(skb, nl_dest);
3137 if (ip_vs_genl_fill_dest(skb, dest) < 0)
3138 goto nla_put_failure;
3140 return genlmsg_end(skb, hdr);
3143 genlmsg_cancel(skb, hdr);
3147 static int ip_vs_genl_dump_dests(
struct sk_buff *skb,
3151 int start = cb->
args[0];
3155 struct net *net = skb_sknet(skb);
3166 if (IS_ERR(svc) || svc ==
NULL)
3173 if (ip_vs_genl_dump_dest(skb, dest, cb) < 0) {
3175 goto nla_put_failure;
3189 struct nlattr *nla,
int full_entry)
3192 struct nlattr *nla_addr, *nla_port;
3202 if (!(nla_addr && nla_port))
3205 memset(udest, 0,
sizeof(*udest));
3208 udest->
port = nla_get_u16(nla_port);
3212 struct nlattr *nla_fwd, *nla_weight, *nla_u_thresh,
3220 if (!(nla_fwd && nla_weight && nla_u_thresh && nla_l_thresh))
3225 udest->
weight = nla_get_u32(nla_weight);
3234 const char *mcast_ifn,
__be32 syncid)
3236 struct nlattr *nl_daemon;
3245 goto nla_put_failure;
3246 nla_nest_end(skb, nl_daemon);
3251 nla_nest_cancel(skb, nl_daemon);
3255 static int ip_vs_genl_dump_daemon(
struct sk_buff *skb,
__be32 state,
3256 const char *mcast_ifn,
__be32 syncid,
3266 if (ip_vs_genl_fill_daemon(skb, state, mcast_ifn, syncid))
3267 goto nla_put_failure;
3269 return genlmsg_end(skb, hdr);
3272 genlmsg_cancel(skb, hdr);
3276 static int ip_vs_genl_dump_daemons(
struct sk_buff *skb,
3279 struct net *net = skb_sknet(skb);
3287 goto nla_put_failure;
3296 goto nla_put_failure;
3307 static int ip_vs_genl_new_daemon(
struct net *net,
struct nlattr **attrs)
3317 nla_get_u32(attrs[IPVS_DAEMON_ATTR_SYNC_ID]));
3320 static int ip_vs_genl_del_daemon(
struct net *net,
struct nlattr **attrs)
3322 if (!attrs[IPVS_DAEMON_ATTR_STATE])
3326 nla_get_u32(attrs[IPVS_DAEMON_ATTR_STATE]));
3329 static int ip_vs_genl_set_config(
struct net *net,
struct nlattr **attrs)
3333 __ip_vs_get_timeouts(net, &
t);
3336 t.tcp_timeout = nla_get_u32(attrs[IPVS_CMD_ATTR_TIMEOUT_TCP]);
3340 nla_get_u32(attrs[IPVS_CMD_ATTR_TIMEOUT_TCP_FIN]);
3343 t.udp_timeout = nla_get_u32(attrs[IPVS_CMD_ATTR_TIMEOUT_UDP]);
3345 return ip_vs_set_timeout(net, &
t);
3354 net = skb_sknet(skb);
3355 ipvs = net_ipvs(net);
3365 ip_vs_daemon_policy)) {
3371 ret = ip_vs_genl_new_daemon(net, daemon_attrs);
3373 ret = ip_vs_genl_del_daemon(net, daemon_attrs);
3386 int need_full_svc = 0, need_full_dest = 0;
3389 net = skb_sknet(skb);
3395 ret = ip_vs_flush(net);
3398 ret = ip_vs_genl_set_config(net, info->
attrs);
3402 ret = ip_vs_zero_all(net);
3412 ret = ip_vs_genl_parse_service(net, &usvc,
3414 need_full_svc, &svc);
3432 ret = ip_vs_genl_parse_dest(&udest,
3442 ret = ip_vs_add_service(net, &usvc, &svc);
3447 ret = ip_vs_edit_service(svc, &usvc);
3450 ret = ip_vs_del_service(svc);
3454 ret = ip_vs_add_dest(svc, &udest);
3457 ret = ip_vs_edit_dest(svc, &udest);
3460 ret = ip_vs_del_dest(svc, &udest);
3463 ret = ip_vs_zero_service(svc);
3482 net = skb_sknet(skb);
3492 pr_err(
"unknown Generic Netlink command\n");
3502 reply = genlmsg_put_reply(msg, info, &ip_vs_genl_family, 0, reply_cmd);
3504 goto nla_put_failure;
3511 svc = ip_vs_genl_find_service(net,
3517 ret = ip_vs_genl_fill_service(msg, svc);
3519 goto nla_put_failure;
3532 __ip_vs_get_timeouts(net, &
t);
3533 #ifdef CONFIG_IP_VS_PROTO_TCP
3534 if (nla_put_u32(msg, IPVS_CMD_ATTR_TIMEOUT_TCP,
3536 nla_put_u32(msg, IPVS_CMD_ATTR_TIMEOUT_TCP_FIN,
3538 goto nla_put_failure;
3540 #ifdef CONFIG_IP_VS_PROTO_UDP
3542 goto nla_put_failure;
3552 ip_vs_conn_tab_size))
3553 goto nla_put_failure;
3557 genlmsg_end(msg, reply);
3558 ret = genlmsg_reply(msg, info);
3562 pr_err(
"not enough space in Netlink message\n");
3578 .policy = ip_vs_cmd_policy,
3579 .doit = ip_vs_genl_set_cmd,
3584 .policy = ip_vs_cmd_policy,
3585 .doit = ip_vs_genl_set_cmd,
3590 .policy = ip_vs_cmd_policy,
3591 .doit = ip_vs_genl_set_cmd,
3596 .doit = ip_vs_genl_get_cmd,
3597 .dumpit = ip_vs_genl_dump_services,
3598 .policy = ip_vs_cmd_policy,
3603 .policy = ip_vs_cmd_policy,
3604 .doit = ip_vs_genl_set_cmd,
3609 .policy = ip_vs_cmd_policy,
3610 .doit = ip_vs_genl_set_cmd,
3615 .policy = ip_vs_cmd_policy,
3616 .doit = ip_vs_genl_set_cmd,
3621 .policy = ip_vs_cmd_policy,
3622 .dumpit = ip_vs_genl_dump_dests,
3627 .policy = ip_vs_cmd_policy,
3628 .doit = ip_vs_genl_set_daemon,
3633 .policy = ip_vs_cmd_policy,
3634 .doit = ip_vs_genl_set_daemon,
3639 .dumpit = ip_vs_genl_dump_daemons,
3644 .policy = ip_vs_cmd_policy,
3645 .doit = ip_vs_genl_set_cmd,
3650 .doit = ip_vs_genl_get_cmd,
3655 .doit = ip_vs_genl_get_cmd,
3660 .policy = ip_vs_cmd_policy,
3661 .doit = ip_vs_genl_set_cmd,
3666 .doit = ip_vs_genl_set_cmd,
3670 static int __init ip_vs_genl_register(
void)
3676 static void ip_vs_genl_unregister(
void)
3686 #ifdef CONFIG_SYSCTL
3687 static int __net_init ip_vs_control_net_init_sysctl(
struct net *net)
3712 #ifdef CONFIG_IP_VS_NFCT
3713 tbl[idx++].
data = &ipvs->sysctl_conntrack;
3743 if (ipvs->sysctl_hdr ==
NULL) {
3749 ipvs->sysctl_tbl = tbl;
3757 static void __net_exit ip_vs_control_net_cleanup_sysctl(
struct net *net)
3768 static int __net_init ip_vs_control_net_init_sysctl(
struct net *net) {
return 0; }
3769 static void __net_exit ip_vs_control_net_cleanup_sysctl(
struct net *net) { }
3774 .notifier_call = ip_vs_dst_event,
3786 INIT_LIST_HEAD(&ipvs->
rs_table[idx]);
3802 &ip_vs_stats_percpu_fops);
3804 if (ip_vs_control_net_init_sysctl(net))
3818 ip_vs_trash_cleanup(net);
3820 ip_vs_control_net_cleanup_sysctl(net);
3833 pr_err(
"cannot register sockopt.\n");
3837 ret = ip_vs_genl_register();
3839 pr_err(
"cannot register Generic Netlink interface.\n");
3852 ip_vs_genl_unregister();
3865 INIT_LIST_HEAD(&ip_vs_svc_table[idx]);
3866 INIT_LIST_HEAD(&ip_vs_svc_fwm_table[idx]);