Release 4.11 net/ipv4/netfilter/ipt_CLUSTERIP.c
/* Cluster IP hashmark target
* (C) 2003-2004 by Harald Welte <laforge@netfilter.org>
* based on ideas of Fabio Olive Leite <olive@unixforge.org>
*
* Development of this code funded by SuSE Linux AG, http://www.suse.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/jhash.h>
#include <linux/bitops.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/icmp.h>
#include <linux/if_arp.h>
#include <linux/seq_file.h>
#include <linux/netfilter_arp.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter_ipv4/ip_tables.h>
#include <linux/netfilter_ipv4/ipt_CLUSTERIP.h>
#include <net/netfilter/nf_conntrack.h>
#include <net/net_namespace.h>
#include <net/netns/generic.h>
#include <net/checksum.h>
#include <net/ip.h>
#define CLUSTERIP_VERSION "0.8"
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
MODULE_DESCRIPTION("Xtables: CLUSTERIP target");
struct clusterip_config {
struct list_head list; /* list of all configs */
atomic_t refcount; /* reference count */
atomic_t entries; /* number of entries/rules
* referencing us */
__be32 clusterip; /* the IP address */
u_int8_t clustermac[ETH_ALEN]; /* the MAC address */
struct net_device *dev; /* device */
u_int16_t num_total_nodes; /* total number of nodes */
unsigned long local_nodes; /* node number array */
#ifdef CONFIG_PROC_FS
struct proc_dir_entry *pde; /* proc dir entry */
#endif
enum clusterip_hashmode hash_mode; /* which hashing mode */
u_int32_t hash_initval; /* hash initialization */
struct rcu_head rcu;
};
#ifdef CONFIG_PROC_FS
static const struct file_operations clusterip_proc_fops;
#endif
static unsigned int clusterip_net_id __read_mostly;
struct clusterip_net {
struct list_head configs;
/* lock protects the configs list */
spinlock_t lock;
#ifdef CONFIG_PROC_FS
struct proc_dir_entry *procdir;
#endif
};
static inline void
clusterip_config_get(struct clusterip_config *c)
{
atomic_inc(&c->refcount);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 20 | 100.00% | 1 | 100.00% |
Total | 20 | 100.00% | 1 | 100.00% |
static void clusterip_config_rcu_free(struct rcu_head *head)
{
kfree(container_of(head, struct clusterip_config, rcu));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Dumazet | 24 | 100.00% | 1 | 100.00% |
Total | 24 | 100.00% | 1 | 100.00% |
static inline void
clusterip_config_put(struct clusterip_config *c)
{
if (atomic_dec_and_test(&c->refcount))
call_rcu_bh(&c->rcu, clusterip_config_rcu_free);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 21 | 65.62% | 1 | 33.33% |
Eric Dumazet | 6 | 18.75% | 1 | 33.33% |
KOVACS Krisztian | 5 | 15.62% | 1 | 33.33% |
Total | 32 | 100.00% | 3 | 100.00% |
/* decrease the count of entries using/referencing this config. If last
* entry(rule) is removed, remove the config from lists, but don't free it
* yet, since proc-files could still be holding references */
static inline void
clusterip_config_entry_put(struct clusterip_config *c)
{
struct net *net = dev_net(c->dev);
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
local_bh_disable();
if (atomic_dec_and_lock(&c->entries, &cn->lock)) {
list_del_rcu(&c->list);
spin_unlock(&cn->lock);
local_bh_enable();
dev_mc_del(c->dev, c->clustermac);
dev_put(c->dev);
/* In case anyone still accesses the file, the open/close
* functions are also incrementing the refcount on their own,
* so it's safe to remove the entry even if it's in use. */
#ifdef CONFIG_PROC_FS
proc_remove(c->pde);
#endif
return;
}
local_bh_enable();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 35 | 31.82% | 1 | 12.50% |
Gao Feng | 30 | 27.27% | 2 | 25.00% |
KOVACS Krisztian | 28 | 25.45% | 1 | 12.50% |
Eric Dumazet | 12 | 10.91% | 1 | 12.50% |
Pavel Emelyanov | 3 | 2.73% | 1 | 12.50% |
Jiri Pirko | 1 | 0.91% | 1 | 12.50% |
David Howells | 1 | 0.91% | 1 | 12.50% |
Total | 110 | 100.00% | 8 | 100.00% |
static struct clusterip_config *
__clusterip_config_find(struct net *net, __be32 clusterip)
{
struct clusterip_config *c;
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
list_for_each_entry_rcu(c, &cn->configs, list) {
if (c->clusterip == clusterip)
return c;
}
return NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 33 | 57.89% | 1 | 16.67% |
Gao Feng | 18 | 31.58% | 2 | 33.33% |
Li Zefan | 4 | 7.02% | 1 | 16.67% |
Al Viro | 1 | 1.75% | 1 | 16.67% |
Eric Dumazet | 1 | 1.75% | 1 | 16.67% |
Total | 57 | 100.00% | 6 | 100.00% |
static inline struct clusterip_config *
clusterip_config_find_get(struct net *net, __be32 clusterip, int entry)
{
struct clusterip_config *c;
rcu_read_lock_bh();
c = __clusterip_config_find(net, clusterip);
if (c) {
#ifdef CONFIG_PROC_FS
if (!c->pde)
c = NULL;
else
#endif
if (unlikely(!atomic_inc_not_zero(&c->refcount)))
c = NULL;
else if (entry)
atomic_inc(&c->entries);
}
rcu_read_unlock_bh();
return c;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 41 | 42.27% | 1 | 14.29% |
Eric Dumazet | 16 | 16.49% | 1 | 14.29% |
KOVACS Krisztian | 15 | 15.46% | 1 | 14.29% |
Arnd Bergmann | 13 | 13.40% | 1 | 14.29% |
Gao Feng | 7 | 7.22% | 1 | 14.29% |
Xin Long | 4 | 4.12% | 1 | 14.29% |
Al Viro | 1 | 1.03% | 1 | 14.29% |
Total | 97 | 100.00% | 7 | 100.00% |
static void
clusterip_config_init_nodelist(struct clusterip_config *c,
const struct ipt_clusterip_tgt_info *i)
{
int n;
for (n = 0; n < i->num_local_nodes; n++)
set_bit(i->local_nodes[n] - 1, &c->local_nodes);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
KOVACS Krisztian | 51 | 98.08% | 1 | 50.00% |
Harald Welte | 1 | 1.92% | 1 | 50.00% |
Total | 52 | 100.00% | 2 | 100.00% |
static struct clusterip_config *
clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,
struct net_device *dev)
{
struct net *net = dev_net(dev);
struct clusterip_config *c;
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
c = kzalloc(sizeof(*c), GFP_ATOMIC);
if (!c)
return ERR_PTR(-ENOMEM);
c->dev = dev;
c->clusterip = ip;
memcpy(&c->clustermac, &i->clustermac, ETH_ALEN);
c->num_total_nodes = i->num_total_nodes;
clusterip_config_init_nodelist(c, i);
c->hash_mode = i->hash_mode;
c->hash_initval = i->hash_initval;
atomic_set(&c->refcount, 1);
atomic_set(&c->entries, 1);
spin_lock_bh(&cn->lock);
if (__clusterip_config_find(net, ip)) {
spin_unlock_bh(&cn->lock);
kfree(c);
return ERR_PTR(-EBUSY);
}
list_add_rcu(&c->list, &cn->configs);
spin_unlock_bh(&cn->lock);
#ifdef CONFIG_PROC_FS
{
char buffer[16];
/* create proc dir entry */
sprintf(buffer, "%pI4", &ip);
c->pde = proc_create_data(buffer, S_IWUSR|S_IRUSR,
cn->procdir,
&clusterip_proc_fops, c);
if (!c->pde) {
spin_lock_bh(&cn->lock);
list_del_rcu(&c->list);
spin_unlock_bh(&cn->lock);
kfree(c);
return ERR_PTR(-ENOMEM);
}
}
#endif
return c;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 161 | 52.61% | 1 | 7.14% |
Xin Long | 93 | 30.39% | 1 | 7.14% |
Gao Feng | 20 | 6.54% | 2 | 14.29% |
KOVACS Krisztian | 12 | 3.92% | 2 | 14.29% |
Patrick McHardy | 7 | 2.29% | 1 | 7.14% |
Denis V. Lunev | 6 | 1.96% | 2 | 14.29% |
Harvey Harrison | 2 | 0.65% | 1 | 7.14% |
Eric Dumazet | 2 | 0.65% | 1 | 7.14% |
Jan Engelhardt | 1 | 0.33% | 1 | 7.14% |
Panagiotis Issaris | 1 | 0.33% | 1 | 7.14% |
Al Viro | 1 | 0.33% | 1 | 7.14% |
Total | 306 | 100.00% | 14 | 100.00% |
#ifdef CONFIG_PROC_FS
static int
clusterip_add_node(struct clusterip_config *c, u_int16_t nodenum)
{
if (nodenum == 0 ||
nodenum > c->num_total_nodes)
return 1;
/* check if we already have this number in our bitfield */
if (test_and_set_bit(nodenum - 1, &c->local_nodes))
return 1;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 35 | 70.00% | 1 | 50.00% |
KOVACS Krisztian | 15 | 30.00% | 1 | 50.00% |
Total | 50 | 100.00% | 2 | 100.00% |
static bool
clusterip_del_node(struct clusterip_config *c, u_int16_t nodenum)
{
if (nodenum == 0 ||
nodenum > c->num_total_nodes)
return true;
if (test_and_clear_bit(nodenum - 1, &c->local_nodes))
return false;
return true;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 36 | 73.47% | 1 | 33.33% |
KOVACS Krisztian | 9 | 18.37% | 1 | 33.33% |
Jan Engelhardt | 4 | 8.16% | 1 | 33.33% |
Total | 49 | 100.00% | 3 | 100.00% |
#endif
static inline u_int32_t
clusterip_hashfn(const struct sk_buff *skb,
const struct clusterip_config *config)
{
const struct iphdr *iph = ip_hdr(skb);
unsigned long hashval;
u_int16_t sport = 0, dport = 0;
int poff;
poff = proto_ports_offset(iph->protocol);
if (poff >= 0) {
const u_int16_t *ports;
u16 _ports[2];
ports = skb_header_pointer(skb, iph->ihl * 4 + poff, 4, _ports);
if (ports) {
sport = ports[0];
dport = ports[1];
}
} else {
net_info_ratelimited("unknown protocol %u\n", iph->protocol);
}
switch (config->hash_mode) {
case CLUSTERIP_HASHMODE_SIP:
hashval = jhash_1word(ntohl(iph->saddr),
config->hash_initval);
break;
case CLUSTERIP_HASHMODE_SIP_SPT:
hashval = jhash_2words(ntohl(iph->saddr), sport,
config->hash_initval);
break;
case CLUSTERIP_HASHMODE_SIP_SPT_DPT:
hashval = jhash_3words(ntohl(iph->saddr), sport, dport,
config->hash_initval);
break;
default:
/* to make gcc happy */
hashval = 0;
/* This cannot happen, unless the check function wasn't called
* at rule load time */
pr_info("unknown mode %u\n", config->hash_mode);
BUG();
break;
}
/* node numbers are 1..n, not 0..n */
return reciprocal_scale(hashval, config->num_total_nodes) + 1;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 161 | 69.40% | 1 | 12.50% |
Changli Gao | 48 | 20.69% | 1 | 12.50% |
Patrick McHardy | 9 | 3.88% | 1 | 12.50% |
Jan Engelhardt | 6 | 2.59% | 2 | 25.00% |
Daniel Borkmann | 4 | 1.72% | 1 | 12.50% |
Arnaldo Carvalho de Melo | 3 | 1.29% | 1 | 12.50% |
Joe Perches | 1 | 0.43% | 1 | 12.50% |
Total | 232 | 100.00% | 8 | 100.00% |
static inline int
clusterip_responsible(const struct clusterip_config *config, u_int32_t hash)
{
return test_bit(hash - 1, &config->local_nodes);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 22 | 75.86% | 1 | 33.33% |
KOVACS Krisztian | 6 | 20.69% | 1 | 33.33% |
Jan Engelhardt | 1 | 3.45% | 1 | 33.33% |
Total | 29 | 100.00% | 3 | 100.00% |
/***********************************************************************
* IPTABLES TARGET
***********************************************************************/
static unsigned int
clusterip_tg(struct sk_buff *skb, const struct xt_action_param *par)
{
const struct ipt_clusterip_tgt_info *cipinfo = par->targinfo;
struct nf_conn *ct;
enum ip_conntrack_info ctinfo;
u_int32_t hash;
/* don't need to clusterip_config_get() here, since refcount
* is only decremented by destroy() - and ip_tables guarantees
* that the ->target() function isn't called after ->destroy() */
ct = nf_ct_get(skb, &ctinfo);
if (ct == NULL)
return NF_DROP;
/* special case: ICMP error handling. conntrack distinguishes between
* error messages (RELATED) and information requests (see below) */
if (ip_hdr(skb)->protocol == IPPROTO_ICMP &&
(ctinfo == IP_CT_RELATED ||
ctinfo == IP_CT_RELATED_REPLY))
return XT_CONTINUE;
/* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO,
* TIMESTAMP, INFO_REQUEST or ADDRESS type icmp packets from here
* on, which all have an ID field [relevant for hashing]. */
hash = clusterip_hashfn(skb, cipinfo->config);
switch (ctinfo) {
case IP_CT_NEW:
ct->mark = hash;
break;
case IP_CT_RELATED:
case IP_CT_RELATED_REPLY:
/* FIXME: we don't handle expectations at the moment.
* They can arrive on a different node than
* the master connection (e.g. FTP passive mode) */
case IP_CT_ESTABLISHED:
case IP_CT_ESTABLISHED_REPLY:
break;
default: /* Prevent gcc warnings */
break;
}
#ifdef DEBUG
nf_ct_dump_tuple_ip(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
#endif
pr_debug("hash=%u ct_hash=%u ", hash, ct->mark);
if (!clusterip_responsible(cipinfo->config, hash)) {
pr_debug("not responsible\n");
return NF_DROP;
}
pr_debug("responsible\n");
/* despite being received via linklayer multicast, this is
* actually a unicast IP packet. TCP doesn't like PACKET_MULTICAST */
skb->pkt_type = PACKET_HOST;
return XT_CONTINUE;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 150 | 76.53% | 2 | 13.33% |
Patrick McHardy | 16 | 8.16% | 2 | 13.33% |
Yasuyuki Kozakai | 8 | 4.08% | 1 | 6.67% |
Jan Engelhardt | 8 | 4.08% | 5 | 33.33% |
Herbert Xu | 5 | 2.55% | 1 | 6.67% |
Eric Dumazet | 3 | 1.53% | 1 | 6.67% |
Arnaldo Carvalho de Melo | 3 | 1.53% | 1 | 6.67% |
Joe Perches | 2 | 1.02% | 1 | 6.67% |
Hideaki Yoshifuji / 吉藤英明 | 1 | 0.51% | 1 | 6.67% |
Total | 196 | 100.00% | 15 | 100.00% |
static int clusterip_tg_check(const struct xt_tgchk_param *par)
{
struct ipt_clusterip_tgt_info *cipinfo = par->targinfo;
const struct ipt_entry *e = par->entryinfo;
struct clusterip_config *config;
int ret;
if (par->nft_compat) {
pr_err("cannot use CLUSTERIP target from nftables compat\n");
return -EOPNOTSUPP;
}
if (cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP &&
cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT &&
cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT_DPT) {
pr_info("unknown mode %u\n", cipinfo->hash_mode);
return -EINVAL;
}
if (e->ip.dmsk.s_addr != htonl(0xffffffff) ||
e->ip.dst.s_addr == 0) {
pr_info("Please specify destination IP\n");
return -EINVAL;
}
/* FIXME: further sanity checks */
config = clusterip_config_find_get(par->net, e->ip.dst.s_addr, 1);
if (!config) {
if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) {
pr_info("no config found for %pI4, need 'new'\n",
&e->ip.dst.s_addr);
return -EINVAL;
} else {
struct net_device *dev;
if (e->ip.iniface[0] == '\0') {
pr_info("Please specify an interface name\n");
return -EINVAL;
}
dev = dev_get_by_name(par->net, e->ip.iniface);
if (!dev) {
pr_info("no such interface %s\n",
e->ip.iniface);
return -ENOENT;
}
config = clusterip_config_init(cipinfo,
e->ip.dst.s_addr, dev);
if (IS_ERR(config)) {
dev_put(dev);
return PTR_ERR(config);
}
dev_mc_add(config->dev, config->clustermac);
}
}
cipinfo->config = config;
ret = nf_ct_netns_get(par->net, par->family);
if (ret < 0)
pr_info("cannot load conntrack support for proto=%u\n",
par->family);
if (!par->net->xt.clusterip_deprecated_warning) {
pr_info("ipt_CLUSTERIP is deprecated and it will removed soon, "
"use xt_cluster instead\n");
par->net->xt.clusterip_deprecated_warning = true;
}
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 234 | 63.59% | 2 | 9.52% |
Pablo Neira Ayuso | 46 | 12.50% | 2 | 9.52% |
Jan Engelhardt | 45 | 12.23% | 6 | 28.57% |
Yasuyuki Kozakai | 14 | 3.80% | 1 | 4.76% |
Xin Long | 7 | 1.90% | 1 | 4.76% |
Gao Feng | 7 | 1.90% | 2 | 9.52% |
Florian Westphal | 5 | 1.36% | 1 | 4.76% |
Al Viro | 3 | 0.82% | 1 | 4.76% |
Patrick McHardy | 3 | 0.82% | 2 | 9.52% |
KOVACS Krisztian | 2 | 0.54% | 1 | 4.76% |
Eric W. Biedermann | 1 | 0.27% | 1 | 4.76% |
Harvey Harrison | 1 | 0.27% | 1 | 4.76% |
Total | 368 | 100.00% | 21 | 100.00% |
/* drop reference count of cluster config when rule is deleted */
static void clusterip_tg_destroy(const struct xt_tgdtor_param *par)
{
const struct ipt_clusterip_tgt_info *cipinfo = par->targinfo;
/* if no more entries are referencing the config, remove it
* from the list and destroy the proc entry */
clusterip_config_entry_put(cipinfo->config);
clusterip_config_put(cipinfo->config);
nf_ct_netns_put(par->net, par->family);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 25 | 52.08% | 1 | 11.11% |
Jan Engelhardt | 8 | 16.67% | 3 | 33.33% |
Florian Westphal | 4 | 8.33% | 1 | 11.11% |
Patrick McHardy | 4 | 8.33% | 1 | 11.11% |
Yasuyuki Kozakai | 4 | 8.33% | 1 | 11.11% |
KOVACS Krisztian | 2 | 4.17% | 1 | 11.11% |
Gao Feng | 1 | 2.08% | 1 | 11.11% |
Total | 48 | 100.00% | 9 | 100.00% |
#ifdef CONFIG_COMPAT
struct compat_ipt_clusterip_tgt_info
{
u_int32_t flags;
u_int8_t clustermac[6];
u_int16_t num_total_nodes;
u_int16_t num_local_nodes;
u_int16_t local_nodes[CLUSTERIP_MAX_NODES];
u_int32_t hash_mode;
u_int32_t hash_initval;
compat_uptr_t config;
};
#endif /* CONFIG_COMPAT */
static struct xt_target clusterip_tg_reg __read_mostly = {
.name = "CLUSTERIP",
.family = NFPROTO_IPV4,
.target = clusterip_tg,
.checkentry = clusterip_tg_check,
.destroy = clusterip_tg_destroy,
.targetsize = sizeof(struct ipt_clusterip_tgt_info),
.usersize = offsetof(struct ipt_clusterip_tgt_info, config),
#ifdef CONFIG_COMPAT
.compatsize = sizeof(struct compat_ipt_clusterip_tgt_info),
#endif /* CONFIG_COMPAT */
.me = THIS_MODULE
};
/***********************************************************************
* ARP MANGLING CODE
***********************************************************************/
/* hardcoded for 48bit ethernet and 32bit ipv4 addresses */
struct arp_payload {
u_int8_t src_hw[ETH_ALEN];
__be32 src_ip;
u_int8_t dst_hw[ETH_ALEN];
__be32 dst_ip;
}
__packed;
#ifdef DEBUG
static void arp_print(struct arp_payload *payload)
{
#define HBUFFERLEN 30
char hbuffer[HBUFFERLEN];
int j, k;
for (k = 0, j = 0; k < HBUFFERLEN - 3 && j < ETH_ALEN; j++) {
hbuffer[k++] = hex_asc_hi(payload->src_hw[j]);
hbuffer[k++] = hex_asc_lo(payload->src_hw[j]);
hbuffer[k++] = ':';
}
hbuffer[--k] = '\0';
pr_debug("src %pI4@%s, dst %pI4\n",
&payload->src_ip, hbuffer, &payload->dst_ip);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 106 | 91.38% | 1 | 25.00% |
Harvey Harrison | 9 | 7.76% | 2 | 50.00% |
Jan Engelhardt | 1 | 0.86% | 1 | 25.00% |
Total | 116 | 100.00% | 4 | 100.00% |
#endif
static unsigned int
arp_mangle(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
{
struct arphdr *arp = arp_hdr(skb);
struct arp_payload *payload;
struct clusterip_config *c;
struct net *net = state->net;
/* we don't care about non-ethernet and non-ipv4 ARP */
if (arp->ar_hrd != htons(ARPHRD_ETHER) ||
arp->ar_pro != htons(ETH_P_IP) ||
arp->ar_pln != 4 || arp->ar_hln != ETH_ALEN)
return NF_ACCEPT;
/* we only want to mangle arp requests and replies */
if (arp->ar_op != htons(ARPOP_REPLY) &&
arp->ar_op != htons(ARPOP_REQUEST))
return NF_ACCEPT;
payload = (void *)(arp+1);
/* if there is no clusterip configuration for the arp reply's
* source ip, we don't want to mangle it */
c = clusterip_config_find_get(net, payload->src_ip, 0);
if (!c)
return NF_ACCEPT;
/* normally the linux kernel always replies to arp queries of
* addresses on different interfacs. However, in the CLUSTERIP case
* this wouldn't work, since we didn't subscribe the mcast group on
* other interfaces */
if (c->dev != state->out) {
pr_debug("not mangling arp reply on different "
"interface: cip'%s'-skb'%s'\n",
c->dev->name, state->out->name);
clusterip_config_put(c);
return NF_ACCEPT;
}
/* mangle reply hardware address */
memcpy(payload->src_hw, c->clustermac, arp->ar_hln);
#ifdef DEBUG
pr_debug("mangled arp reply: ");
arp_print(payload);
#endif
clusterip_config_put(c);
return NF_ACCEPT;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 189 | 84.75% | 2 | 14.29% |
David S. Miller | 8 | 3.59% | 1 | 7.14% |
Gao Feng | 8 | 3.59% | 2 | 14.29% |
Patrick McHardy | 4 | 1.79% | 2 | 14.29% |
Eric W. Biedermann | 3 | 1.35% | 2 | 14.29% |
Arnaldo Carvalho de Melo | 3 | 1.35% | 1 | 7.14% |
Herbert Xu | 2 | 0.90% | 1 | 7.14% |
Hideaki Yoshifuji / 吉藤英明 | 2 | 0.90% | 1 | 7.14% |
Jan Engelhardt | 2 | 0.90% | 1 | 7.14% |
KOVACS Krisztian | 2 | 0.90% | 1 | 7.14% |
Total | 223 | 100.00% | 14 | 100.00% |
static struct nf_hook_ops cip_arp_ops __read_mostly = {
.hook = arp_mangle,
.pf = NFPROTO_ARP,
.hooknum = NF_ARP_OUT,
.priority = -1
};
/***********************************************************************
* PROC DIR HANDLING
***********************************************************************/
#ifdef CONFIG_PROC_FS
struct clusterip_seq_position {
unsigned int pos; /* position */
unsigned int weight; /* number of bits set == size */
unsigned int bit; /* current bit */
unsigned long val; /* current value */
};
static void *clusterip_seq_start(struct seq_file *s, loff_t *pos)
{
struct clusterip_config *c = s->private;
unsigned int weight;
u_int32_t local_nodes;
struct clusterip_seq_position *idx;
/* FIXME: possible race */
local_nodes = c->local_nodes;
weight = hweight32(local_nodes);
if (*pos >= weight)
return NULL;
idx = kmalloc(sizeof(struct clusterip_seq_position), GFP_KERNEL);
if (!idx)
return ERR_PTR(-ENOMEM);
idx->pos = *pos;
idx->weight = weight;
idx->bit = ffs(local_nodes);
idx->val = local_nodes;
clear_bit(idx->bit - 1, &idx->val);
return idx;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
KOVACS Krisztian | 66 | 50.38% | 1 | 33.33% |
Harald Welte | 63 | 48.09% | 1 | 33.33% |
Alexey Dobriyan | 2 | 1.53% | 1 | 33.33% |
Total | 131 | 100.00% | 3 | 100.00% |
static void *clusterip_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
struct clusterip_seq_position *idx = v;
*pos = ++idx->pos;
if (*pos >= idx->weight) {
kfree(v);
return NULL;
}
idx->bit = ffs(idx->val);
clear_bit(idx->bit - 1, &idx->val);
return idx;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 49 | 59.76% | 1 | 50.00% |
KOVACS Krisztian | 33 | 40.24% | 1 | 50.00% |
Total | 82 | 100.00% | 2 | 100.00% |
static void clusterip_seq_stop(struct seq_file *s, void *v)
{
if (!IS_ERR(v))
kfree(v);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 20 | 71.43% | 1 | 50.00% |
Eric Dumazet | 8 | 28.57% | 1 | 50.00% |
Total | 28 | 100.00% | 2 | 100.00% |
static int clusterip_seq_show(struct seq_file *s, void *v)
{
struct clusterip_seq_position *idx = v;
if (idx->pos != 0)
seq_putc(s, ',');
seq_printf(s, "%u", idx->bit);
if (idx->pos == idx->weight - 1)
seq_putc(s, '\n');
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 58 | 82.86% | 1 | 50.00% |
KOVACS Krisztian | 12 | 17.14% | 1 | 50.00% |
Total | 70 | 100.00% | 2 | 100.00% |
static const struct seq_operations clusterip_seq_ops = {
.start = clusterip_seq_start,
.next = clusterip_seq_next,
.stop = clusterip_seq_stop,
.show = clusterip_seq_show,
};
static int clusterip_proc_open(struct inode *inode, struct file *file)
{
int ret = seq_open(file, &clusterip_seq_ops);
if (!ret) {
struct seq_file *sf = file->private_data;
struct clusterip_config *c = PDE_DATA(inode);
sf->private = c;
clusterip_config_get(c);
}
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 63 | 94.03% | 1 | 33.33% |
Alexey Dobriyan | 3 | 4.48% | 1 | 33.33% |
Al Viro | 1 | 1.49% | 1 | 33.33% |
Total | 67 | 100.00% | 3 | 100.00% |
static int clusterip_proc_release(struct inode *inode, struct file *file)
{
struct clusterip_config *c = PDE_DATA(inode);
int ret;
ret = seq_release(inode, file);
if (!ret)
clusterip_config_put(c);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 48 | 94.12% | 1 | 33.33% |
Alexey Dobriyan | 2 | 3.92% | 1 | 33.33% |
Al Viro | 1 | 1.96% | 1 | 33.33% |
Total | 51 | 100.00% | 3 | 100.00% |
static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
size_t size, loff_t *ofs)
{
struct clusterip_config *c = PDE_DATA(file_inode(file));
#define PROC_WRITELEN 10
char buffer[PROC_WRITELEN+1];
unsigned long nodenum;
int rc;
if (size > PROC_WRITELEN)
return -EIO;
if (copy_from_user(buffer, input, size))
return -EFAULT;
buffer[size] = 0;
if (*buffer == '+') {
rc = kstrtoul(buffer+1, 10, &nodenum);
if (rc)
return rc;
if (clusterip_add_node(c, nodenum))
return -ENOMEM;
} else if (*buffer == '-') {
rc = kstrtoul(buffer+1, 10, &nodenum);
if (rc)
return rc;
if (clusterip_del_node(c, nodenum))
return -ENOENT;
} else
return -EIO;
return size;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 119 | 65.03% | 1 | 14.29% |
Abhijit Pawar | 27 | 14.75% | 1 | 14.29% |
Vasiliy Kulikov | 18 | 9.84% | 1 | 14.29% |
Alexey Dobriyan | 14 | 7.65% | 1 | 14.29% |
Al Viro | 5 | 2.73% | 3 | 42.86% |
Total | 183 | 100.00% | 7 | 100.00% |
static const struct file_operations clusterip_proc_fops = {
.owner = THIS_MODULE,
.open = clusterip_proc_open,
.read = seq_read,
.write = clusterip_proc_write,
.llseek = seq_lseek,
.release = clusterip_proc_release,
};
#endif /* CONFIG_PROC_FS */
static int clusterip_net_init(struct net *net)
{
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
INIT_LIST_HEAD(&cn->configs);
spin_lock_init(&cn->lock);
#ifdef CONFIG_PROC_FS
cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
if (!cn->procdir) {
pr_err("Unable to proc dir entry\n");
return -ENOMEM;
}
#endif /* CONFIG_PROC_FS */
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Gao Feng | 79 | 100.00% | 3 | 100.00% |
Total | 79 | 100.00% | 3 | 100.00% |
static void clusterip_net_exit(struct net *net)
{
#ifdef CONFIG_PROC_FS
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
proc_remove(cn->procdir);
#endif
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Gao Feng | 35 | 100.00% | 1 | 100.00% |
Total | 35 | 100.00% | 1 | 100.00% |
static struct pernet_operations clusterip_net_ops = {
.init = clusterip_net_init,
.exit = clusterip_net_exit,
.id = &clusterip_net_id,
.size = sizeof(struct clusterip_net),
};
static int __init clusterip_tg_init(void)
{
int ret;
ret = register_pernet_subsys(&clusterip_net_ops);
if (ret < 0)
return ret;
ret = xt_register_target(&clusterip_tg_reg);
if (ret < 0)
goto cleanup_subsys;
ret = nf_register_hook(&cip_arp_ops);
if (ret < 0)
goto cleanup_target;
pr_info("ClusterIP Version %s loaded successfully\n",
CLUSTERIP_VERSION);
return 0;
cleanup_target:
xt_unregister_target(&clusterip_tg_reg);
cleanup_subsys:
unregister_pernet_subsys(&clusterip_net_ops);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 41 | 44.57% | 1 | 20.00% |
Patrick McHardy | 30 | 32.61% | 1 | 20.00% |
Gao Feng | 19 | 20.65% | 1 | 20.00% |
Jan Engelhardt | 2 | 2.17% | 2 | 40.00% |
Total | 92 | 100.00% | 5 | 100.00% |
static void __exit clusterip_tg_exit(void)
{
pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION);
nf_unregister_hook(&cip_arp_ops);
xt_unregister_target(&clusterip_tg_reg);
unregister_pernet_subsys(&clusterip_net_ops);
/* Wait for completion of call_rcu_bh()'s (clusterip_config_rcu_free) */
rcu_barrier_bh();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 17 | 44.74% | 1 | 14.29% |
Patrick McHardy | 7 | 18.42% | 1 | 14.29% |
Gao Feng | 6 | 15.79% | 1 | 14.29% |
Jan Engelhardt | 4 | 10.53% | 3 | 42.86% |
Eric Dumazet | 4 | 10.53% | 1 | 14.29% |
Total | 38 | 100.00% | 7 | 100.00% |
module_init(clusterip_tg_init);
module_exit(clusterip_tg_exit);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harald Welte | 2032 | 60.03% | 4 | 4.76% |
KOVACS Krisztian | 294 | 8.69% | 2 | 2.38% |
Gao Feng | 288 | 8.51% | 6 | 7.14% |
Patrick McHardy | 162 | 4.79% | 11 | 13.10% |
Jan Engelhardt | 106 | 3.13% | 16 | 19.05% |
Xin Long | 104 | 3.07% | 1 | 1.19% |
Eric Dumazet | 80 | 2.36% | 3 | 3.57% |
Changli Gao | 51 | 1.51% | 1 | 1.19% |
Pablo Neira Ayuso | 46 | 1.36% | 2 | 2.38% |
Abhijit Pawar | 27 | 0.80% | 1 | 1.19% |
Yasuyuki Kozakai | 26 | 0.77% | 2 | 2.38% |
Alexey Dobriyan | 22 | 0.65% | 2 | 2.38% |
Vasiliy Kulikov | 18 | 0.53% | 1 | 1.19% |
Al Viro | 16 | 0.47% | 4 | 4.76% |
Arnd Bergmann | 13 | 0.38% | 1 | 1.19% |
Harvey Harrison | 12 | 0.35% | 2 | 2.38% |
Willem de Bruijn | 11 | 0.32% | 1 | 1.19% |
Florian Westphal | 9 | 0.27% | 1 | 1.19% |
Arnaldo Carvalho de Melo | 9 | 0.27% | 2 | 2.38% |
David S. Miller | 8 | 0.24% | 1 | 1.19% |
Eric W. Biedermann | 7 | 0.21% | 4 | 4.76% |
Herbert Xu | 7 | 0.21% | 1 | 1.19% |
Hideaki Yoshifuji / 吉藤英明 | 7 | 0.21% | 1 | 1.19% |
Denis V. Lunev | 6 | 0.18% | 2 | 2.38% |
Li Zefan | 4 | 0.12% | 1 | 1.19% |
Daniel Borkmann | 4 | 0.12% | 1 | 1.19% |
Tejun Heo | 3 | 0.09% | 1 | 1.19% |
Pavel Emelyanov | 3 | 0.09% | 1 | 1.19% |
Joe Perches | 3 | 0.09% | 2 | 2.38% |
Arjan van de Ven | 2 | 0.06% | 1 | 1.19% |
Jiri Pirko | 1 | 0.03% | 1 | 1.19% |
David Howells | 1 | 0.03% | 1 | 1.19% |
Gustavo Fernando Padovan | 1 | 0.03% | 1 | 1.19% |
Philippe De Muyter | 1 | 0.03% | 1 | 1.19% |
Panagiotis Issaris | 1 | 0.03% | 1 | 1.19% |
Total | 3385 | 100.00% | 84 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.