Skip to content

Commit

Permalink
IPVS: Change IPVS data structures to support IPv6 addresses
Browse files Browse the repository at this point in the history
Introduce new 'af' fields into IPVS data structures for specifying an
entry's address family. Convert IP addresses to be of type union
nf_inet_addr.

Signed-off-by: Julius Volz <juliusv@google.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
  • Loading branch information
Julius Volz authored and Simon Horman committed Sep 5, 2008
1 parent fab0de0 commit e7ade46
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 114 deletions.
18 changes: 12 additions & 6 deletions include/net/ip_vs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <linux/timer.h>

#include <net/checksum.h>
#include <linux/netfilter.h> /* for union nf_inet_addr */
#include <linux/ipv6.h> /* for struct ipv6hdr */
#include <net/ipv6.h> /* for ipv6_addr_copy */

#ifdef CONFIG_IP_VS_DEBUG
#include <linux/net.h>
Expand Down Expand Up @@ -259,9 +262,10 @@ struct ip_vs_conn {
struct list_head c_list; /* hashed list heads */

/* Protocol, addresses and port numbers */
__be32 caddr; /* client address */
__be32 vaddr; /* virtual address */
__be32 daddr; /* destination address */
u16 af; /* address family */
union nf_inet_addr caddr; /* client address */
union nf_inet_addr vaddr; /* virtual address */
union nf_inet_addr daddr; /* destination address */
__be16 cport;
__be16 vport;
__be16 dport;
Expand Down Expand Up @@ -314,8 +318,9 @@ struct ip_vs_service {
atomic_t refcnt; /* reference counter */
atomic_t usecnt; /* use counter */

u16 af; /* address family */
__u16 protocol; /* which protocol (TCP/UDP) */
__be32 addr; /* IP address for virtual service */
union nf_inet_addr addr; /* IP address for virtual service */
__be16 port; /* port number for the service */
__u32 fwmark; /* firewall mark of the service */
unsigned flags; /* service status flags */
Expand All @@ -342,7 +347,8 @@ struct ip_vs_dest {
struct list_head n_list; /* for the dests in the service */
struct list_head d_list; /* for table with all the dests */

__be32 addr; /* IP address of the server */
u16 af; /* address family */
union nf_inet_addr addr; /* IP address of the server */
__be16 port; /* port number of the server */
volatile unsigned flags; /* dest status flags */
atomic_t conn_flags; /* flags to copy to conn */
Expand All @@ -366,7 +372,7 @@ struct ip_vs_dest {
/* for virtual service */
struct ip_vs_service *svc; /* service it belongs to */
__u16 protocol; /* which protocol (TCP/UDP) */
__be32 vaddr; /* virtual IP address */
union nf_inet_addr vaddr; /* virtual IP address */
__be16 vport; /* virtual port number */
__u32 vfwmark; /* firewall mark of service */
};
Expand Down
60 changes: 30 additions & 30 deletions net/ipv4/ipvs/ip_vs_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static inline int ip_vs_conn_hash(struct ip_vs_conn *cp)
int ret;

/* Hash by protocol, client address and port */
hash = ip_vs_conn_hashkey(cp->protocol, cp->caddr, cp->cport);
hash = ip_vs_conn_hashkey(cp->protocol, cp->caddr.ip, cp->cport);

ct_write_lock(hash);

Expand Down Expand Up @@ -162,7 +162,7 @@ static inline int ip_vs_conn_unhash(struct ip_vs_conn *cp)
int ret;

/* unhash it and decrease its reference counter */
hash = ip_vs_conn_hashkey(cp->protocol, cp->caddr, cp->cport);
hash = ip_vs_conn_hashkey(cp->protocol, cp->caddr.ip, cp->cport);

ct_write_lock(hash);

Expand Down Expand Up @@ -197,10 +197,10 @@ static inline struct ip_vs_conn *__ip_vs_conn_in_get
ct_read_lock(hash);

list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
if (s_addr==cp->caddr && s_port==cp->cport &&
d_port==cp->vport && d_addr==cp->vaddr &&
if (s_addr == cp->caddr.ip && s_port == cp->cport &&
d_port == cp->vport && d_addr == cp->vaddr.ip &&
((!s_port) ^ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
protocol==cp->protocol) {
protocol == cp->protocol) {
/* HIT */
atomic_inc(&cp->refcnt);
ct_read_unlock(hash);
Expand Down Expand Up @@ -243,10 +243,10 @@ struct ip_vs_conn *ip_vs_ct_in_get
ct_read_lock(hash);

list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
if (s_addr==cp->caddr && s_port==cp->cport &&
d_port==cp->vport && d_addr==cp->vaddr &&
if (s_addr == cp->caddr.ip && s_port == cp->cport &&
d_port == cp->vport && d_addr == cp->vaddr.ip &&
cp->flags & IP_VS_CONN_F_TEMPLATE &&
protocol==cp->protocol) {
protocol == cp->protocol) {
/* HIT */
atomic_inc(&cp->refcnt);
goto out;
Expand Down Expand Up @@ -286,8 +286,8 @@ struct ip_vs_conn *ip_vs_conn_out_get
ct_read_lock(hash);

list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
if (d_addr == cp->caddr && d_port == cp->cport &&
s_port == cp->dport && s_addr == cp->daddr &&
if (d_addr == cp->caddr.ip && d_port == cp->cport &&
s_port == cp->dport && s_addr == cp->daddr.ip &&
protocol == cp->protocol) {
/* HIT */
atomic_inc(&cp->refcnt);
Expand Down Expand Up @@ -406,9 +406,9 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
"d:%u.%u.%u.%u:%d fwd:%c s:%u conn->flags:%X conn->refcnt:%d "
"dest->refcnt:%d\n",
ip_vs_proto_name(cp->protocol),
NIPQUAD(cp->caddr), ntohs(cp->cport),
NIPQUAD(cp->vaddr), ntohs(cp->vport),
NIPQUAD(cp->daddr), ntohs(cp->dport),
NIPQUAD(cp->caddr.ip), ntohs(cp->cport),
NIPQUAD(cp->vaddr.ip), ntohs(cp->vport),
NIPQUAD(cp->daddr.ip), ntohs(cp->dport),
ip_vs_fwd_tag(cp), cp->state,
cp->flags, atomic_read(&cp->refcnt),
atomic_read(&dest->refcnt));
Expand Down Expand Up @@ -444,8 +444,8 @@ struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp)
struct ip_vs_dest *dest;

if ((cp) && (!cp->dest)) {
dest = ip_vs_find_dest(cp->daddr, cp->dport,
cp->vaddr, cp->vport, cp->protocol);
dest = ip_vs_find_dest(cp->daddr.ip, cp->dport,
cp->vaddr.ip, cp->vport, cp->protocol);
ip_vs_bind_dest(cp, dest);
return dest;
} else
Expand All @@ -468,9 +468,9 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)
"d:%u.%u.%u.%u:%d fwd:%c s:%u conn->flags:%X conn->refcnt:%d "
"dest->refcnt:%d\n",
ip_vs_proto_name(cp->protocol),
NIPQUAD(cp->caddr), ntohs(cp->cport),
NIPQUAD(cp->vaddr), ntohs(cp->vport),
NIPQUAD(cp->daddr), ntohs(cp->dport),
NIPQUAD(cp->caddr.ip), ntohs(cp->cport),
NIPQUAD(cp->vaddr.ip), ntohs(cp->vport),
NIPQUAD(cp->daddr.ip), ntohs(cp->dport),
ip_vs_fwd_tag(cp), cp->state,
cp->flags, atomic_read(&cp->refcnt),
atomic_read(&dest->refcnt));
Expand Down Expand Up @@ -530,9 +530,9 @@ int ip_vs_check_template(struct ip_vs_conn *ct)
"protocol %s s:%u.%u.%u.%u:%d v:%u.%u.%u.%u:%d "
"-> d:%u.%u.%u.%u:%d\n",
ip_vs_proto_name(ct->protocol),
NIPQUAD(ct->caddr), ntohs(ct->cport),
NIPQUAD(ct->vaddr), ntohs(ct->vport),
NIPQUAD(ct->daddr), ntohs(ct->dport));
NIPQUAD(ct->caddr.ip), ntohs(ct->cport),
NIPQUAD(ct->vaddr.ip), ntohs(ct->vport),
NIPQUAD(ct->daddr.ip), ntohs(ct->dport));

/*
* Invalidate the connection template
Expand Down Expand Up @@ -641,11 +641,11 @@ ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport
INIT_LIST_HEAD(&cp->c_list);
setup_timer(&cp->timer, ip_vs_conn_expire, (unsigned long)cp);
cp->protocol = proto;
cp->caddr = caddr;
cp->caddr.ip = caddr;
cp->cport = cport;
cp->vaddr = vaddr;
cp->vaddr.ip = vaddr;
cp->vport = vport;
cp->daddr = daddr;
cp->daddr.ip = daddr;
cp->dport = dport;
cp->flags = flags;
spin_lock_init(&cp->lock);
Expand Down Expand Up @@ -763,9 +763,9 @@ static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)
seq_printf(seq,
"%-3s %08X %04X %08X %04X %08X %04X %-11s %7lu\n",
ip_vs_proto_name(cp->protocol),
ntohl(cp->caddr), ntohs(cp->cport),
ntohl(cp->vaddr), ntohs(cp->vport),
ntohl(cp->daddr), ntohs(cp->dport),
ntohl(cp->caddr.ip), ntohs(cp->cport),
ntohl(cp->vaddr.ip), ntohs(cp->vport),
ntohl(cp->daddr.ip), ntohs(cp->dport),
ip_vs_state_name(cp->protocol, cp->state),
(cp->timer.expires-jiffies)/HZ);
}
Expand Down Expand Up @@ -812,9 +812,9 @@ static int ip_vs_conn_sync_seq_show(struct seq_file *seq, void *v)
seq_printf(seq,
"%-3s %08X %04X %08X %04X %08X %04X %-11s %-6s %7lu\n",
ip_vs_proto_name(cp->protocol),
ntohl(cp->caddr), ntohs(cp->cport),
ntohl(cp->vaddr), ntohs(cp->vport),
ntohl(cp->daddr), ntohs(cp->dport),
ntohl(cp->caddr.ip), ntohs(cp->cport),
ntohl(cp->vaddr.ip), ntohs(cp->vport),
ntohl(cp->daddr.ip), ntohs(cp->dport),
ip_vs_state_name(cp->protocol, cp->state),
ip_vs_origin_name(cp->flags),
(cp->timer.expires-jiffies)/HZ);
Expand Down
28 changes: 14 additions & 14 deletions net/ipv4/ipvs/ip_vs_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
snet, 0,
iph->daddr,
ports[1],
dest->addr, dest->port,
dest->addr.ip, dest->port,
IP_VS_CONN_F_TEMPLATE,
dest);
else
ct = ip_vs_conn_new(iph->protocol,
snet, 0,
iph->daddr, 0,
dest->addr, 0,
dest->addr.ip, 0,
IP_VS_CONN_F_TEMPLATE,
dest);
if (ct == NULL)
Expand Down Expand Up @@ -286,14 +286,14 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
ct = ip_vs_conn_new(IPPROTO_IP,
snet, 0,
htonl(svc->fwmark), 0,
dest->addr, 0,
dest->addr.ip, 0,
IP_VS_CONN_F_TEMPLATE,
dest);
else
ct = ip_vs_conn_new(iph->protocol,
snet, 0,
iph->daddr, 0,
dest->addr, 0,
dest->addr.ip, 0,
IP_VS_CONN_F_TEMPLATE,
dest);
if (ct == NULL)
Expand All @@ -313,7 +313,7 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
cp = ip_vs_conn_new(iph->protocol,
iph->saddr, ports[0],
iph->daddr, ports[1],
dest->addr, dport,
dest->addr.ip, dport,
0,
dest);
if (cp == NULL) {
Expand Down Expand Up @@ -380,7 +380,7 @@ ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
cp = ip_vs_conn_new(iph->protocol,
iph->saddr, pptr[0],
iph->daddr, pptr[1],
dest->addr, dest->port?dest->port:pptr[1],
dest->addr.ip, dest->port ? dest->port : pptr[1],
0,
dest);
if (cp == NULL)
Expand All @@ -389,9 +389,9 @@ ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
IP_VS_DBG(6, "Schedule fwd:%c c:%u.%u.%u.%u:%u v:%u.%u.%u.%u:%u "
"d:%u.%u.%u.%u:%u conn->flags:%X conn->refcnt:%d\n",
ip_vs_fwd_tag(cp),
NIPQUAD(cp->caddr), ntohs(cp->cport),
NIPQUAD(cp->vaddr), ntohs(cp->vport),
NIPQUAD(cp->daddr), ntohs(cp->dport),
NIPQUAD(cp->caddr.ip), ntohs(cp->cport),
NIPQUAD(cp->vaddr.ip), ntohs(cp->vport),
NIPQUAD(cp->daddr.ip), ntohs(cp->dport),
cp->flags, atomic_read(&cp->refcnt));

ip_vs_conn_stats(cp, svc);
Expand Down Expand Up @@ -526,14 +526,14 @@ void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
struct iphdr *ciph = (struct iphdr *)(icmph + 1);

if (inout) {
iph->saddr = cp->vaddr;
iph->saddr = cp->vaddr.ip;
ip_send_check(iph);
ciph->daddr = cp->vaddr;
ciph->daddr = cp->vaddr.ip;
ip_send_check(ciph);
} else {
iph->daddr = cp->daddr;
iph->daddr = cp->daddr.ip;
ip_send_check(iph);
ciph->saddr = cp->daddr;
ciph->saddr = cp->daddr.ip;
ip_send_check(ciph);
}

Expand Down Expand Up @@ -762,7 +762,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,
/* mangle the packet */
if (pp->snat_handler && !pp->snat_handler(skb, pp, cp))
goto drop;
ip_hdr(skb)->saddr = cp->vaddr;
ip_hdr(skb)->saddr = cp->vaddr.ip;
ip_send_check(ip_hdr(skb));

/* For policy routing, packets originating from this
Expand Down
Loading

0 comments on commit e7ade46

Please sign in to comment.