YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1 | /* Cluster IP hashmark target |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * (C) 2003-2004 by Harald Welte <laforge@netfilter.org> |
| 3 | * based on ideas of Fabio Olive Leite <olive@unixforge.org> |
| 4 | * |
| 5 | * Development of this code funded by SuSE Linux AG, http://www.suse.com/ |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | */ |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/proc_fs.h> |
| 15 | #include <linux/jhash.h> |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 16 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/skbuff.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/ip.h> |
| 20 | #include <linux/tcp.h> |
| 21 | #include <linux/udp.h> |
| 22 | #include <linux/icmp.h> |
| 23 | #include <linux/if_arp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/netfilter_arp.h> |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 26 | #include <linux/netfilter/x_tables.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/netfilter_ipv4/ip_tables.h> |
| 28 | #include <linux/netfilter_ipv4/ipt_CLUSTERIP.h> |
Patrick McHardy | 587aa64 | 2007-03-14 16:37:25 -0700 | [diff] [blame] | 29 | #include <net/netfilter/nf_conntrack.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 30 | #include <net/net_namespace.h> |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 31 | #include <net/netns/generic.h> |
Patrick McHardy | 587aa64 | 2007-03-14 16:37:25 -0700 | [diff] [blame] | 32 | #include <net/checksum.h> |
Changli Gao | 3d04ebb | 2010-08-17 20:34:40 +0000 | [diff] [blame] | 33 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 35 | #define CLUSTERIP_VERSION "0.8" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | MODULE_LICENSE("GPL"); |
| 38 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); |
Jan Engelhardt | 2ae15b6 | 2008-01-14 23:42:28 -0800 | [diff] [blame] | 39 | MODULE_DESCRIPTION("Xtables: CLUSTERIP target"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | struct clusterip_config { |
| 42 | struct list_head list; /* list of all configs */ |
| 43 | atomic_t refcount; /* reference count */ |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 44 | atomic_t entries; /* number of entries/rules |
| 45 | * referencing us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Al Viro | 6a19d61 | 2006-09-28 14:22:24 -0700 | [diff] [blame] | 47 | __be32 clusterip; /* the IP address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | u_int8_t clustermac[ETH_ALEN]; /* the MAC address */ |
| 49 | struct net_device *dev; /* device */ |
| 50 | u_int16_t num_total_nodes; /* total number of nodes */ |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 51 | unsigned long local_nodes; /* node number array */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #ifdef CONFIG_PROC_FS |
| 54 | struct proc_dir_entry *pde; /* proc dir entry */ |
| 55 | #endif |
| 56 | enum clusterip_hashmode hash_mode; /* which hashing mode */ |
| 57 | u_int32_t hash_initval; /* hash initialization */ |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 58 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #ifdef CONFIG_PROC_FS |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 62 | static const struct file_operations clusterip_proc_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #endif |
| 64 | |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 65 | static int clusterip_net_id __read_mostly; |
| 66 | |
| 67 | struct clusterip_net { |
Gao feng | 26a89e4 | 2013-09-25 15:38:45 +0800 | [diff] [blame] | 68 | struct list_head configs; |
Gao feng | f1e8077 | 2013-09-25 15:38:46 +0800 | [diff] [blame] | 69 | /* lock protects the configs list */ |
| 70 | spinlock_t lock; |
| 71 | |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 72 | #ifdef CONFIG_PROC_FS |
| 73 | struct proc_dir_entry *procdir; |
| 74 | #endif |
| 75 | }; |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static inline void |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 78 | clusterip_config_get(struct clusterip_config *c) |
| 79 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | atomic_inc(&c->refcount); |
| 81 | } |
| 82 | |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 83 | |
| 84 | static void clusterip_config_rcu_free(struct rcu_head *head) |
| 85 | { |
| 86 | kfree(container_of(head, struct clusterip_config, rcu)); |
| 87 | } |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | static inline void |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 90 | clusterip_config_put(struct clusterip_config *c) |
| 91 | { |
| 92 | if (atomic_dec_and_test(&c->refcount)) |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 93 | call_rcu_bh(&c->rcu, clusterip_config_rcu_free); |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 94 | } |
| 95 | |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 96 | /* decrease the count of entries using/referencing this config. If last |
| 97 | * entry(rule) is removed, remove the config from lists, but don't free it |
| 98 | * yet, since proc-files could still be holding references */ |
| 99 | static inline void |
| 100 | clusterip_config_entry_put(struct clusterip_config *c) |
| 101 | { |
Gao feng | d86946d | 2013-09-25 15:38:49 +0800 | [diff] [blame] | 102 | struct net *net = dev_net(c->dev); |
| 103 | struct clusterip_net *cn = net_generic(net, clusterip_net_id); |
Gao feng | f1e8077 | 2013-09-25 15:38:46 +0800 | [diff] [blame] | 104 | |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 105 | local_bh_disable(); |
Gao feng | f1e8077 | 2013-09-25 15:38:46 +0800 | [diff] [blame] | 106 | if (atomic_dec_and_lock(&c->entries, &cn->lock)) { |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 107 | list_del_rcu(&c->list); |
Gao feng | f1e8077 | 2013-09-25 15:38:46 +0800 | [diff] [blame] | 108 | spin_unlock(&cn->lock); |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 109 | local_bh_enable(); |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 110 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 111 | dev_mc_del(c->dev, c->clustermac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | dev_put(c->dev); |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 113 | |
| 114 | /* In case anyone still accesses the file, the open/close |
| 115 | * functions are also incrementing the refcount on their own, |
| 116 | * so it's safe to remove the entry even if it's in use. */ |
| 117 | #ifdef CONFIG_PROC_FS |
David Howells | a8ca16e | 2013-04-12 17:27:28 +0100 | [diff] [blame] | 118 | proc_remove(c->pde); |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 119 | #endif |
Pavel Emelyanov | 4dee959 | 2008-04-14 00:44:52 -0700 | [diff] [blame] | 120 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 122 | local_bh_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | static struct clusterip_config * |
Gao feng | b5ef0f8 | 2013-09-25 15:38:47 +0800 | [diff] [blame] | 126 | __clusterip_config_find(struct net *net, __be32 clusterip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
Li Zefan | 4c61097 | 2007-12-04 23:22:26 -0800 | [diff] [blame] | 128 | struct clusterip_config *c; |
Gao feng | b5ef0f8 | 2013-09-25 15:38:47 +0800 | [diff] [blame] | 129 | struct clusterip_net *cn = net_generic(net, clusterip_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Gao feng | 26a89e4 | 2013-09-25 15:38:45 +0800 | [diff] [blame] | 131 | list_for_each_entry_rcu(c, &cn->configs, list) { |
Jan Engelhardt | 7c4e36b | 2007-07-07 22:19:08 -0700 | [diff] [blame] | 132 | if (c->clusterip == clusterip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | return NULL; |
| 137 | } |
| 138 | |
| 139 | static inline struct clusterip_config * |
Gao feng | b5ef0f8 | 2013-09-25 15:38:47 +0800 | [diff] [blame] | 140 | clusterip_config_find_get(struct net *net, __be32 clusterip, int entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
| 142 | struct clusterip_config *c; |
| 143 | |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 144 | rcu_read_lock_bh(); |
Gao feng | b5ef0f8 | 2013-09-25 15:38:47 +0800 | [diff] [blame] | 145 | c = __clusterip_config_find(net, clusterip); |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 146 | if (c) { |
| 147 | if (unlikely(!atomic_inc_not_zero(&c->refcount))) |
| 148 | c = NULL; |
| 149 | else if (entry) |
| 150 | atomic_inc(&c->entries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 152 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | return c; |
| 155 | } |
| 156 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 157 | static void |
| 158 | clusterip_config_init_nodelist(struct clusterip_config *c, |
| 159 | const struct ipt_clusterip_tgt_info *i) |
| 160 | { |
| 161 | int n; |
| 162 | |
Jan Engelhardt | 7c4e36b | 2007-07-07 22:19:08 -0700 | [diff] [blame] | 163 | for (n = 0; n < i->num_local_nodes; n++) |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 164 | set_bit(i->local_nodes[n] - 1, &c->local_nodes); |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | static struct clusterip_config * |
Jan Engelhardt | 3cf93c9 | 2008-04-14 09:56:05 +0200 | [diff] [blame] | 168 | clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | struct net_device *dev) |
| 170 | { |
| 171 | struct clusterip_config *c; |
Gao feng | f58d786 | 2013-09-25 15:38:48 +0800 | [diff] [blame] | 172 | struct clusterip_net *cn = net_generic(dev_net(dev), clusterip_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 174 | c = kzalloc(sizeof(*c), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | if (!c) |
| 176 | return NULL; |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | c->dev = dev; |
| 179 | c->clusterip = ip; |
| 180 | memcpy(&c->clustermac, &i->clustermac, ETH_ALEN); |
| 181 | c->num_total_nodes = i->num_total_nodes; |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 182 | clusterip_config_init_nodelist(c, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | c->hash_mode = i->hash_mode; |
| 184 | c->hash_initval = i->hash_initval; |
| 185 | atomic_set(&c->refcount, 1); |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 186 | atomic_set(&c->entries, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | #ifdef CONFIG_PROC_FS |
Patrick McHardy | 7659258 | 2006-11-29 02:35:42 +0100 | [diff] [blame] | 189 | { |
| 190 | char buffer[16]; |
| 191 | |
| 192 | /* create proc dir entry */ |
Harvey Harrison | cffee38 | 2008-10-31 00:53:08 -0700 | [diff] [blame] | 193 | sprintf(buffer, "%pI4", &ip); |
Denis V. Lunev | 6e79d85 | 2008-05-02 02:45:42 -0700 | [diff] [blame] | 194 | c->pde = proc_create_data(buffer, S_IWUSR|S_IRUSR, |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 195 | cn->procdir, |
Denis V. Lunev | 6e79d85 | 2008-05-02 02:45:42 -0700 | [diff] [blame] | 196 | &clusterip_proc_fops, c); |
Patrick McHardy | 7659258 | 2006-11-29 02:35:42 +0100 | [diff] [blame] | 197 | if (!c->pde) { |
| 198 | kfree(c); |
| 199 | return NULL; |
| 200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | #endif |
| 203 | |
Gao feng | f1e8077 | 2013-09-25 15:38:46 +0800 | [diff] [blame] | 204 | spin_lock_bh(&cn->lock); |
Gao feng | 26a89e4 | 2013-09-25 15:38:45 +0800 | [diff] [blame] | 205 | list_add_rcu(&c->list, &cn->configs); |
Gao feng | f1e8077 | 2013-09-25 15:38:46 +0800 | [diff] [blame] | 206 | spin_unlock_bh(&cn->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | return c; |
| 209 | } |
| 210 | |
Patrick McHardy | 7659258 | 2006-11-29 02:35:42 +0100 | [diff] [blame] | 211 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | static int |
| 213 | clusterip_add_node(struct clusterip_config *c, u_int16_t nodenum) |
| 214 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 216 | if (nodenum == 0 || |
| 217 | nodenum > c->num_total_nodes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 220 | /* check if we already have this number in our bitfield */ |
| 221 | if (test_and_set_bit(nodenum - 1, &c->local_nodes)) |
| 222 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
Jan Engelhardt | e1931b7 | 2007-07-07 22:16:26 -0700 | [diff] [blame] | 227 | static bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | clusterip_del_node(struct clusterip_config *c, u_int16_t nodenum) |
| 229 | { |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 230 | if (nodenum == 0 || |
| 231 | nodenum > c->num_total_nodes) |
Jan Engelhardt | e1931b7 | 2007-07-07 22:16:26 -0700 | [diff] [blame] | 232 | return true; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 233 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 234 | if (test_and_clear_bit(nodenum - 1, &c->local_nodes)) |
Jan Engelhardt | e1931b7 | 2007-07-07 22:16:26 -0700 | [diff] [blame] | 235 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Jan Engelhardt | e1931b7 | 2007-07-07 22:16:26 -0700 | [diff] [blame] | 237 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
Patrick McHardy | 7659258 | 2006-11-29 02:35:42 +0100 | [diff] [blame] | 239 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | static inline u_int32_t |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 242 | clusterip_hashfn(const struct sk_buff *skb, |
| 243 | const struct clusterip_config *config) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 245 | const struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | unsigned long hashval; |
Changli Gao | 3d04ebb | 2010-08-17 20:34:40 +0000 | [diff] [blame] | 247 | u_int16_t sport = 0, dport = 0; |
| 248 | int poff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Changli Gao | 3d04ebb | 2010-08-17 20:34:40 +0000 | [diff] [blame] | 250 | poff = proto_ports_offset(iph->protocol); |
| 251 | if (poff >= 0) { |
| 252 | const u_int16_t *ports; |
| 253 | u16 _ports[2]; |
| 254 | |
| 255 | ports = skb_header_pointer(skb, iph->ihl * 4 + poff, 4, _ports); |
| 256 | if (ports) { |
| 257 | sport = ports[0]; |
| 258 | dport = ports[1]; |
| 259 | } |
| 260 | } else { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 261 | net_info_ratelimited("unknown protocol %u\n", iph->protocol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | switch (config->hash_mode) { |
| 265 | case CLUSTERIP_HASHMODE_SIP: |
| 266 | hashval = jhash_1word(ntohl(iph->saddr), |
| 267 | config->hash_initval); |
| 268 | break; |
| 269 | case CLUSTERIP_HASHMODE_SIP_SPT: |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 270 | hashval = jhash_2words(ntohl(iph->saddr), sport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | config->hash_initval); |
| 272 | break; |
| 273 | case CLUSTERIP_HASHMODE_SIP_SPT_DPT: |
| 274 | hashval = jhash_3words(ntohl(iph->saddr), sport, dport, |
| 275 | config->hash_initval); |
| 276 | break; |
| 277 | default: |
| 278 | /* to make gcc happy */ |
| 279 | hashval = 0; |
| 280 | /* This cannot happen, unless the check function wasn't called |
| 281 | * at rule load time */ |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 282 | pr_info("unknown mode %u\n", config->hash_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | BUG(); |
| 284 | break; |
| 285 | } |
| 286 | |
| 287 | /* node numbers are 1..n, not 0..n */ |
Daniel Borkmann | 8fc54f6 | 2014-08-23 20:58:54 +0200 | [diff] [blame] | 288 | return reciprocal_scale(hashval, config->num_total_nodes) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | static inline int |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 292 | clusterip_responsible(const struct clusterip_config *config, u_int32_t hash) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 294 | return test_bit(hash - 1, &config->local_nodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 297 | /*********************************************************************** |
| 298 | * IPTABLES TARGET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | ***********************************************************************/ |
| 300 | |
| 301 | static unsigned int |
Jan Engelhardt | 4b560b4 | 2009-07-05 19:43:26 +0200 | [diff] [blame] | 302 | clusterip_tg(struct sk_buff *skb, const struct xt_action_param *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 304 | const struct ipt_clusterip_tgt_info *cipinfo = par->targinfo; |
Patrick McHardy | 587aa64 | 2007-03-14 16:37:25 -0700 | [diff] [blame] | 305 | struct nf_conn *ct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | enum ip_conntrack_info ctinfo; |
Patrick McHardy | 587aa64 | 2007-03-14 16:37:25 -0700 | [diff] [blame] | 307 | u_int32_t hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* don't need to clusterip_config_get() here, since refcount |
| 310 | * is only decremented by destroy() - and ip_tables guarantees |
| 311 | * that the ->target() function isn't called after ->destroy() */ |
| 312 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 313 | ct = nf_ct_get(skb, &ctinfo); |
Eric Dumazet | 94d117a | 2011-01-18 16:27:56 +0100 | [diff] [blame] | 314 | if (ct == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | return NF_DROP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | /* special case: ICMP error handling. conntrack distinguishes between |
| 318 | * error messages (RELATED) and information requests (see below) */ |
Joe Perches | 3666ed1 | 2009-11-23 23:17:06 +0100 | [diff] [blame] | 319 | if (ip_hdr(skb)->protocol == IPPROTO_ICMP && |
| 320 | (ctinfo == IP_CT_RELATED || |
Eric Dumazet | fb04883 | 2011-05-19 15:44:27 +0200 | [diff] [blame] | 321 | ctinfo == IP_CT_RELATED_REPLY)) |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 322 | return XT_CONTINUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 324 | /* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | * TIMESTAMP, INFO_REQUEST or ADDRESS type icmp packets from here |
| 326 | * on, which all have an ID field [relevant for hashing]. */ |
| 327 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 328 | hash = clusterip_hashfn(skb, cipinfo->config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | switch (ctinfo) { |
Joe Perches | 181b1e9 | 2011-07-01 09:43:06 +0000 | [diff] [blame] | 331 | case IP_CT_NEW: |
| 332 | ct->mark = hash; |
| 333 | break; |
| 334 | case IP_CT_RELATED: |
| 335 | case IP_CT_RELATED_REPLY: |
| 336 | /* FIXME: we don't handle expectations at the moment. |
| 337 | * They can arrive on a different node than |
| 338 | * the master connection (e.g. FTP passive mode) */ |
| 339 | case IP_CT_ESTABLISHED: |
| 340 | case IP_CT_ESTABLISHED_REPLY: |
| 341 | break; |
| 342 | default: /* Prevent gcc warnings */ |
| 343 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 346 | #ifdef DEBUG |
Jan Engelhardt | 3c9fba6 | 2008-04-14 11:15:54 +0200 | [diff] [blame] | 347 | nf_ct_dump_tuple_ip(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | #endif |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 349 | pr_debug("hash=%u ct_hash=%u ", hash, ct->mark); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (!clusterip_responsible(cipinfo->config, hash)) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 351 | pr_debug("not responsible\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return NF_DROP; |
| 353 | } |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 354 | pr_debug("responsible\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | /* despite being received via linklayer multicast, this is |
| 357 | * actually a unicast IP packet. TCP doesn't like PACKET_MULTICAST */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 358 | skb->pkt_type = PACKET_HOST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 360 | return XT_CONTINUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Jan Engelhardt | 135367b | 2010-03-19 17:16:42 +0100 | [diff] [blame] | 363 | static int clusterip_tg_check(const struct xt_tgchk_param *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 365 | struct ipt_clusterip_tgt_info *cipinfo = par->targinfo; |
| 366 | const struct ipt_entry *e = par->entryinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | struct clusterip_config *config; |
Dmitry Vyukov | ab2b0f7 | 2018-01-30 15:21:34 +0100 | [diff] [blame] | 368 | int ret, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Pablo Neira Ayuso | 55917a2 | 2015-05-14 14:57:23 +0200 | [diff] [blame] | 370 | if (par->nft_compat) { |
| 371 | pr_err("cannot use CLUSTERIP target from nftables compat\n"); |
| 372 | return -EOPNOTSUPP; |
| 373 | } |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | if (cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP && |
| 376 | cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT && |
| 377 | cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT_DPT) { |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 378 | pr_info("unknown mode %u\n", cipinfo->hash_mode); |
Jan Engelhardt | d6b00a5 | 2010-03-25 16:34:45 +0100 | [diff] [blame] | 379 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
| 381 | } |
Joe Perches | 3666ed1 | 2009-11-23 23:17:06 +0100 | [diff] [blame] | 382 | if (e->ip.dmsk.s_addr != htonl(0xffffffff) || |
| 383 | e->ip.dst.s_addr == 0) { |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 384 | pr_info("Please specify destination IP\n"); |
Jan Engelhardt | d6b00a5 | 2010-03-25 16:34:45 +0100 | [diff] [blame] | 385 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
Dmitry Vyukov | ab2b0f7 | 2018-01-30 15:21:34 +0100 | [diff] [blame] | 387 | if (cipinfo->num_local_nodes > ARRAY_SIZE(cipinfo->local_nodes)) { |
| 388 | pr_info("bad num_local_nodes %u\n", cipinfo->num_local_nodes); |
| 389 | return -EINVAL; |
| 390 | } |
| 391 | for (i = 0; i < cipinfo->num_local_nodes; i++) { |
| 392 | if (cipinfo->local_nodes[i] - 1 >= |
| 393 | sizeof(config->local_nodes) * 8) { |
| 394 | pr_info("bad local_nodes[%d] %u\n", |
| 395 | i, cipinfo->local_nodes[i]); |
| 396 | return -EINVAL; |
| 397 | } |
| 398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Gao feng | d86946d | 2013-09-25 15:38:49 +0800 | [diff] [blame] | 400 | config = clusterip_config_find_get(par->net, e->ip.dst.s_addr, 1); |
Patrick McHardy | d3c3f42 | 2007-07-07 22:38:30 -0700 | [diff] [blame] | 401 | if (!config) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) { |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 403 | pr_info("no config found for %pI4, need 'new'\n", |
| 404 | &e->ip.dst.s_addr); |
Jan Engelhardt | d6b00a5 | 2010-03-25 16:34:45 +0100 | [diff] [blame] | 405 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } else { |
| 407 | struct net_device *dev; |
| 408 | |
| 409 | if (e->ip.iniface[0] == '\0') { |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 410 | pr_info("Please specify an interface name\n"); |
Jan Engelhardt | d6b00a5 | 2010-03-25 16:34:45 +0100 | [diff] [blame] | 411 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Gao feng | d86946d | 2013-09-25 15:38:49 +0800 | [diff] [blame] | 414 | dev = dev_get_by_name(par->net, e->ip.iniface); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (!dev) { |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 416 | pr_info("no such interface %s\n", |
| 417 | e->ip.iniface); |
Jan Engelhardt | 4a5a5c7 | 2010-03-19 17:32:59 +0100 | [diff] [blame] | 418 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 421 | config = clusterip_config_init(cipinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | e->ip.dst.s_addr, dev); |
| 423 | if (!config) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | dev_put(dev); |
Jan Engelhardt | 4a5a5c7 | 2010-03-19 17:32:59 +0100 | [diff] [blame] | 425 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 427 | dev_mc_add(config->dev, config->clustermac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
Patrick McHardy | d3c3f42 | 2007-07-07 22:38:30 -0700 | [diff] [blame] | 430 | cipinfo->config = config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Jan Engelhardt | 4a5a5c7 | 2010-03-19 17:32:59 +0100 | [diff] [blame] | 432 | ret = nf_ct_l3proto_try_module_get(par->family); |
Jan Engelhardt | f95c74e | 2010-03-21 04:05:56 +0100 | [diff] [blame] | 433 | if (ret < 0) |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 434 | pr_info("cannot load conntrack support for proto=%u\n", |
| 435 | par->family); |
Pablo Neira Ayuso | 43270b1 | 2015-03-02 14:40:39 +0100 | [diff] [blame] | 436 | |
| 437 | if (!par->net->xt.clusterip_deprecated_warning) { |
| 438 | pr_info("ipt_CLUSTERIP is deprecated and it will removed soon, " |
| 439 | "use xt_cluster instead\n"); |
| 440 | par->net->xt.clusterip_deprecated_warning = true; |
| 441 | } |
| 442 | |
Jan Engelhardt | f95c74e | 2010-03-21 04:05:56 +0100 | [diff] [blame] | 443 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /* drop reference count of cluster config when rule is deleted */ |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 447 | static void clusterip_tg_destroy(const struct xt_tgdtor_param *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 449 | const struct ipt_clusterip_tgt_info *cipinfo = par->targinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
KOVACS Krisztian | 4451362 | 2005-09-16 16:59:46 -0700 | [diff] [blame] | 451 | /* if no more entries are referencing the config, remove it |
| 452 | * from the list and destroy the proc entry */ |
| 453 | clusterip_config_entry_put(cipinfo->config); |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | clusterip_config_put(cipinfo->config); |
Yasuyuki Kozakai | 11078c3 | 2006-12-12 00:29:02 -0800 | [diff] [blame] | 456 | |
Jan Engelhardt | 0d34545 | 2010-03-19 18:47:51 +0100 | [diff] [blame] | 457 | nf_ct_l3proto_module_put(par->family); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Patrick McHardy | d3c3f42 | 2007-07-07 22:38:30 -0700 | [diff] [blame] | 460 | #ifdef CONFIG_COMPAT |
| 461 | struct compat_ipt_clusterip_tgt_info |
| 462 | { |
| 463 | u_int32_t flags; |
| 464 | u_int8_t clustermac[6]; |
| 465 | u_int16_t num_total_nodes; |
| 466 | u_int16_t num_local_nodes; |
| 467 | u_int16_t local_nodes[CLUSTERIP_MAX_NODES]; |
| 468 | u_int32_t hash_mode; |
| 469 | u_int32_t hash_initval; |
| 470 | compat_uptr_t config; |
| 471 | }; |
| 472 | #endif /* CONFIG_COMPAT */ |
| 473 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 474 | static struct xt_target clusterip_tg_reg __read_mostly = { |
Patrick McHardy | 1d5cd90 | 2006-03-20 18:01:14 -0800 | [diff] [blame] | 475 | .name = "CLUSTERIP", |
Jan Engelhardt | ee999d8 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 476 | .family = NFPROTO_IPV4, |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 477 | .target = clusterip_tg, |
| 478 | .checkentry = clusterip_tg_check, |
| 479 | .destroy = clusterip_tg_destroy, |
Patrick McHardy | d3c3f42 | 2007-07-07 22:38:30 -0700 | [diff] [blame] | 480 | .targetsize = sizeof(struct ipt_clusterip_tgt_info), |
| 481 | #ifdef CONFIG_COMPAT |
| 482 | .compatsize = sizeof(struct compat_ipt_clusterip_tgt_info), |
| 483 | #endif /* CONFIG_COMPAT */ |
Patrick McHardy | 1d5cd90 | 2006-03-20 18:01:14 -0800 | [diff] [blame] | 484 | .me = THIS_MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | }; |
| 486 | |
| 487 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 488 | /*********************************************************************** |
| 489 | * ARP MANGLING CODE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | ***********************************************************************/ |
| 491 | |
| 492 | /* hardcoded for 48bit ethernet and 32bit ipv4 addresses */ |
| 493 | struct arp_payload { |
| 494 | u_int8_t src_hw[ETH_ALEN]; |
Al Viro | 6a19d61 | 2006-09-28 14:22:24 -0700 | [diff] [blame] | 495 | __be32 src_ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | u_int8_t dst_hw[ETH_ALEN]; |
Al Viro | 6a19d61 | 2006-09-28 14:22:24 -0700 | [diff] [blame] | 497 | __be32 dst_ip; |
Gustavo F. Padovan | 3f30fc1 | 2010-07-21 10:59:58 +0000 | [diff] [blame] | 498 | } __packed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 500 | #ifdef DEBUG |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 501 | static void arp_print(struct arp_payload *payload) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
| 503 | #define HBUFFERLEN 30 |
| 504 | char hbuffer[HBUFFERLEN]; |
Ian Morris | c8d71d0 | 2015-10-14 23:17:08 +0100 | [diff] [blame] | 505 | int j, k; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Ian Morris | c8d71d0 | 2015-10-14 23:17:08 +0100 | [diff] [blame] | 507 | for (k = 0, j = 0; k < HBUFFERLEN - 3 && j < ETH_ALEN; j++) { |
Harvey Harrison | 6a8341b | 2008-07-30 16:30:15 -0700 | [diff] [blame] | 508 | hbuffer[k++] = hex_asc_hi(payload->src_hw[j]); |
| 509 | hbuffer[k++] = hex_asc_lo(payload->src_hw[j]); |
Ian Morris | c8d71d0 | 2015-10-14 23:17:08 +0100 | [diff] [blame] | 510 | hbuffer[k++] = ':'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
Ian Morris | c8d71d0 | 2015-10-14 23:17:08 +0100 | [diff] [blame] | 512 | hbuffer[--k] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 514 | pr_debug("src %pI4@%s, dst %pI4\n", |
| 515 | &payload->src_ip, hbuffer, &payload->dst_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | } |
| 517 | #endif |
| 518 | |
| 519 | static unsigned int |
Eric W. Biederman | 06198b3 | 2015-09-18 14:33:06 -0500 | [diff] [blame] | 520 | arp_mangle(void *priv, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 521 | struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 522 | const struct nf_hook_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 524 | struct arphdr *arp = arp_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | struct arp_payload *payload; |
| 526 | struct clusterip_config *c; |
Eric W. Biederman | 9dff2c9 | 2015-09-15 20:04:17 -0500 | [diff] [blame] | 527 | struct net *net = state->net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | /* we don't care about non-ethernet and non-ipv4 ARP */ |
Joe Perches | 3666ed1 | 2009-11-23 23:17:06 +0100 | [diff] [blame] | 530 | if (arp->ar_hrd != htons(ARPHRD_ETHER) || |
| 531 | arp->ar_pro != htons(ETH_P_IP) || |
| 532 | arp->ar_pln != 4 || arp->ar_hln != ETH_ALEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | return NF_ACCEPT; |
| 534 | |
Harald Welte | 4095ebf | 2005-06-28 12:49:30 -0700 | [diff] [blame] | 535 | /* we only want to mangle arp requests and replies */ |
Joe Perches | 3666ed1 | 2009-11-23 23:17:06 +0100 | [diff] [blame] | 536 | if (arp->ar_op != htons(ARPOP_REPLY) && |
| 537 | arp->ar_op != htons(ARPOP_REQUEST)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | return NF_ACCEPT; |
| 539 | |
| 540 | payload = (void *)(arp+1); |
| 541 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 542 | /* if there is no clusterip configuration for the arp reply's |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | * source ip, we don't want to mangle it */ |
Gao feng | d86946d | 2013-09-25 15:38:49 +0800 | [diff] [blame] | 544 | c = clusterip_config_find_get(net, payload->src_ip, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (!c) |
| 546 | return NF_ACCEPT; |
| 547 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 548 | /* normally the linux kernel always replies to arp queries of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | * addresses on different interfacs. However, in the CLUSTERIP case |
| 550 | * this wouldn't work, since we didn't subscribe the mcast group on |
| 551 | * other interfaces */ |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 552 | if (c->dev != state->out) { |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 553 | pr_debug("not mangling arp reply on different " |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 554 | "interface: cip'%s'-skb'%s'\n", |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 555 | c->dev->name, state->out->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | clusterip_config_put(c); |
| 557 | return NF_ACCEPT; |
| 558 | } |
| 559 | |
| 560 | /* mangle reply hardware address */ |
| 561 | memcpy(payload->src_hw, c->clustermac, arp->ar_hln); |
| 562 | |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 563 | #ifdef DEBUG |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 564 | pr_debug("mangled arp reply: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | arp_print(payload); |
| 566 | #endif |
| 567 | |
| 568 | clusterip_config_put(c); |
| 569 | |
| 570 | return NF_ACCEPT; |
| 571 | } |
| 572 | |
Patrick McHardy | 1999414 | 2007-12-05 01:23:00 -0800 | [diff] [blame] | 573 | static struct nf_hook_ops cip_arp_ops __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | .hook = arp_mangle, |
Jan Engelhardt | ee999d8 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 575 | .pf = NFPROTO_ARP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | .hooknum = NF_ARP_OUT, |
| 577 | .priority = -1 |
| 578 | }; |
| 579 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 580 | /*********************************************************************** |
| 581 | * PROC DIR HANDLING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | ***********************************************************************/ |
| 583 | |
| 584 | #ifdef CONFIG_PROC_FS |
| 585 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 586 | struct clusterip_seq_position { |
| 587 | unsigned int pos; /* position */ |
| 588 | unsigned int weight; /* number of bits set == size */ |
| 589 | unsigned int bit; /* current bit */ |
| 590 | unsigned long val; /* current value */ |
| 591 | }; |
| 592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | static void *clusterip_seq_start(struct seq_file *s, loff_t *pos) |
| 594 | { |
Alexey Dobriyan | 4777814 | 2010-01-22 22:21:18 +0100 | [diff] [blame] | 595 | struct clusterip_config *c = s->private; |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 596 | unsigned int weight; |
| 597 | u_int32_t local_nodes; |
| 598 | struct clusterip_seq_position *idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 600 | /* FIXME: possible race */ |
| 601 | local_nodes = c->local_nodes; |
| 602 | weight = hweight32(local_nodes); |
| 603 | if (*pos >= weight) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | return NULL; |
| 605 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 606 | idx = kmalloc(sizeof(struct clusterip_seq_position), GFP_KERNEL); |
| 607 | if (!idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | return ERR_PTR(-ENOMEM); |
| 609 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 610 | idx->pos = *pos; |
| 611 | idx->weight = weight; |
| 612 | idx->bit = ffs(local_nodes); |
| 613 | idx->val = local_nodes; |
| 614 | clear_bit(idx->bit - 1, &idx->val); |
| 615 | |
| 616 | return idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | static void *clusterip_seq_next(struct seq_file *s, void *v, loff_t *pos) |
| 620 | { |
Jan Engelhardt | 3cf93c9 | 2008-04-14 09:56:05 +0200 | [diff] [blame] | 621 | struct clusterip_seq_position *idx = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 623 | *pos = ++idx->pos; |
| 624 | if (*pos >= idx->weight) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | kfree(v); |
| 626 | return NULL; |
| 627 | } |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 628 | idx->bit = ffs(idx->val); |
| 629 | clear_bit(idx->bit - 1, &idx->val); |
| 630 | return idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | static void clusterip_seq_stop(struct seq_file *s, void *v) |
| 634 | { |
Eric Dumazet | 902a3dd | 2010-04-01 12:54:09 +0200 | [diff] [blame] | 635 | if (!IS_ERR(v)) |
| 636 | kfree(v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | static int clusterip_seq_show(struct seq_file *s, void *v) |
| 640 | { |
Jan Engelhardt | 3cf93c9 | 2008-04-14 09:56:05 +0200 | [diff] [blame] | 641 | struct clusterip_seq_position *idx = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 643 | if (idx->pos != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | seq_putc(s, ','); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
KOVACS Krisztian | 136e92b | 2005-09-16 17:00:04 -0700 | [diff] [blame] | 646 | seq_printf(s, "%u", idx->bit); |
| 647 | |
| 648 | if (idx->pos == idx->weight - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | seq_putc(s, '\n'); |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 654 | static const struct seq_operations clusterip_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | .start = clusterip_seq_start, |
| 656 | .next = clusterip_seq_next, |
| 657 | .stop = clusterip_seq_stop, |
| 658 | .show = clusterip_seq_show, |
| 659 | }; |
| 660 | |
| 661 | static int clusterip_proc_open(struct inode *inode, struct file *file) |
| 662 | { |
| 663 | int ret = seq_open(file, &clusterip_seq_ops); |
| 664 | |
| 665 | if (!ret) { |
| 666 | struct seq_file *sf = file->private_data; |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 667 | struct clusterip_config *c = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Alexey Dobriyan | 4777814 | 2010-01-22 22:21:18 +0100 | [diff] [blame] | 669 | sf->private = c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
| 671 | clusterip_config_get(c); |
| 672 | } |
| 673 | |
| 674 | return ret; |
| 675 | } |
| 676 | |
| 677 | static int clusterip_proc_release(struct inode *inode, struct file *file) |
| 678 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 679 | struct clusterip_config *c = PDE_DATA(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | int ret; |
| 681 | |
| 682 | ret = seq_release(inode, file); |
| 683 | |
| 684 | if (!ret) |
| 685 | clusterip_config_put(c); |
| 686 | |
| 687 | return ret; |
| 688 | } |
| 689 | |
| 690 | static ssize_t clusterip_proc_write(struct file *file, const char __user *input, |
| 691 | size_t size, loff_t *ofs) |
| 692 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 693 | struct clusterip_config *c = PDE_DATA(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | #define PROC_WRITELEN 10 |
| 695 | char buffer[PROC_WRITELEN+1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | unsigned long nodenum; |
Abhijit Pawar | 4b5511e | 2012-12-09 23:12:28 +0000 | [diff] [blame] | 697 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Vasiliy Kulikov | 961ed18 | 2011-03-20 15:42:52 +0100 | [diff] [blame] | 699 | if (size > PROC_WRITELEN) |
| 700 | return -EIO; |
| 701 | if (copy_from_user(buffer, input, size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | return -EFAULT; |
Vasiliy Kulikov | 961ed18 | 2011-03-20 15:42:52 +0100 | [diff] [blame] | 703 | buffer[size] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
| 705 | if (*buffer == '+') { |
Abhijit Pawar | 4b5511e | 2012-12-09 23:12:28 +0000 | [diff] [blame] | 706 | rc = kstrtoul(buffer+1, 10, &nodenum); |
| 707 | if (rc) |
| 708 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | if (clusterip_add_node(c, nodenum)) |
| 710 | return -ENOMEM; |
| 711 | } else if (*buffer == '-') { |
Abhijit Pawar | 4b5511e | 2012-12-09 23:12:28 +0000 | [diff] [blame] | 712 | rc = kstrtoul(buffer+1, 10, &nodenum); |
| 713 | if (rc) |
| 714 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | if (clusterip_del_node(c, nodenum)) |
| 716 | return -ENOENT; |
| 717 | } else |
| 718 | return -EIO; |
| 719 | |
| 720 | return size; |
| 721 | } |
| 722 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 723 | static const struct file_operations clusterip_proc_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | .owner = THIS_MODULE, |
| 725 | .open = clusterip_proc_open, |
| 726 | .read = seq_read, |
| 727 | .write = clusterip_proc_write, |
| 728 | .llseek = seq_lseek, |
| 729 | .release = clusterip_proc_release, |
| 730 | }; |
| 731 | |
| 732 | #endif /* CONFIG_PROC_FS */ |
| 733 | |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 734 | static int clusterip_net_init(struct net *net) |
| 735 | { |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 736 | struct clusterip_net *cn = net_generic(net, clusterip_net_id); |
| 737 | |
Gao feng | 26a89e4 | 2013-09-25 15:38:45 +0800 | [diff] [blame] | 738 | INIT_LIST_HEAD(&cn->configs); |
| 739 | |
Gao feng | f1e8077 | 2013-09-25 15:38:46 +0800 | [diff] [blame] | 740 | spin_lock_init(&cn->lock); |
| 741 | |
Gao feng | 26a89e4 | 2013-09-25 15:38:45 +0800 | [diff] [blame] | 742 | #ifdef CONFIG_PROC_FS |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 743 | cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net); |
| 744 | if (!cn->procdir) { |
| 745 | pr_err("Unable to proc dir entry\n"); |
| 746 | return -ENOMEM; |
| 747 | } |
| 748 | #endif /* CONFIG_PROC_FS */ |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static void clusterip_net_exit(struct net *net) |
| 754 | { |
| 755 | #ifdef CONFIG_PROC_FS |
| 756 | struct clusterip_net *cn = net_generic(net, clusterip_net_id); |
| 757 | proc_remove(cn->procdir); |
| 758 | #endif |
| 759 | } |
| 760 | |
| 761 | static struct pernet_operations clusterip_net_ops = { |
| 762 | .init = clusterip_net_init, |
| 763 | .exit = clusterip_net_exit, |
| 764 | .id = &clusterip_net_id, |
| 765 | .size = sizeof(struct clusterip_net), |
| 766 | }; |
| 767 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 768 | static int __init clusterip_tg_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { |
| 770 | int ret; |
| 771 | |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 772 | ret = register_pernet_subsys(&clusterip_net_ops); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 773 | if (ret < 0) |
| 774 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 776 | ret = xt_register_target(&clusterip_tg_reg); |
| 777 | if (ret < 0) |
| 778 | goto cleanup_subsys; |
| 779 | |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 780 | ret = nf_register_hook(&cip_arp_ops); |
| 781 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | goto cleanup_target; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 784 | pr_info("ClusterIP Version %s loaded successfully\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | CLUSTERIP_VERSION); |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | return 0; |
| 788 | |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 789 | cleanup_target: |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 790 | xt_unregister_target(&clusterip_tg_reg); |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 791 | cleanup_subsys: |
| 792 | unregister_pernet_subsys(&clusterip_net_ops); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 793 | return ret; |
| 794 | } |
| 795 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 796 | static void __exit clusterip_tg_exit(void) |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 797 | { |
Jan Engelhardt | ff67e4e | 2010-03-19 21:08:16 +0100 | [diff] [blame] | 798 | pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION); |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | nf_unregister_hook(&cip_arp_ops); |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 801 | xt_unregister_target(&clusterip_tg_reg); |
Gao feng | ce4ff76 | 2013-09-25 15:38:44 +0800 | [diff] [blame] | 802 | unregister_pernet_subsys(&clusterip_net_ops); |
Eric Dumazet | d73f33b | 2010-06-15 13:08:51 +0200 | [diff] [blame] | 803 | |
| 804 | /* Wait for completion of call_rcu_bh()'s (clusterip_config_rcu_free) */ |
| 805 | rcu_barrier_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 808 | module_init(clusterip_tg_init); |
| 809 | module_exit(clusterip_tg_exit); |