aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/ip_vs.h
diff options
context:
space:
mode:
authorJulius Volz <juliusv@google.com>2008-09-02 09:55:34 -0400
committerSimon Horman <horms@verge.net.au>2008-09-04 21:17:03 -0400
commit64aae3cb9fd22f33e491c4730d363eb2229ef910 (patch)
tree71a9ac96d585d4998e4df7c33aa515764d5ad5e1 /include/net/ip_vs.h
parente7ade46a53055c19a01c8becbe7807f9075d6fee (diff)
IPVS: Add general v4/v6 helper functions / data structures
Add a struct ip_vs_iphdr for easier handling of common v4 and v6 header fields in the same code path. ip_vs_fill_iphdr() helps to fill this struct from an IPv4 or IPv6 header. Add further helper functions for copying and comparing addresses. Signed-off-by: Julius Volz <juliusv@google.com> Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'include/net/ip_vs.h')
-rw-r--r--include/net/ip_vs.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index d32825585500..5d6313d972fc 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -25,6 +25,55 @@
25#include <linux/ipv6.h> /* for struct ipv6hdr */ 25#include <linux/ipv6.h> /* for struct ipv6hdr */
26#include <net/ipv6.h> /* for ipv6_addr_copy */ 26#include <net/ipv6.h> /* for ipv6_addr_copy */
27 27
28struct ip_vs_iphdr {
29 int len;
30 __u8 protocol;
31 union nf_inet_addr saddr;
32 union nf_inet_addr daddr;
33};
34
35static inline void
36ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr)
37{
38#ifdef CONFIG_IP_VS_IPV6
39 if (af == AF_INET6) {
40 const struct ipv6hdr *iph = nh;
41 iphdr->len = sizeof(struct ipv6hdr);
42 iphdr->protocol = iph->nexthdr;
43 ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr);
44 ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr);
45 } else
46#endif
47 {
48 const struct iphdr *iph = nh;
49 iphdr->len = iph->ihl * 4;
50 iphdr->protocol = iph->protocol;
51 iphdr->saddr.ip = iph->saddr;
52 iphdr->daddr.ip = iph->daddr;
53 }
54}
55
56static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
57 const union nf_inet_addr *src)
58{
59#ifdef CONFIG_IP_VS_IPV6
60 if (af == AF_INET6)
61 ipv6_addr_copy(&dst->in6, &src->in6);
62 else
63#endif
64 dst->ip = src->ip;
65}
66
67static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
68 const union nf_inet_addr *b)
69{
70#ifdef CONFIG_IP_VS_IPV6
71 if (af == AF_INET6)
72 return ipv6_addr_equal(&a->in6, &b->in6);
73#endif
74 return a->ip == b->ip;
75}
76
28#ifdef CONFIG_IP_VS_DEBUG 77#ifdef CONFIG_IP_VS_DEBUG
29#include <linux/net.h> 78#include <linux/net.h>
30 79