aboutsummaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorHans Schillstrom <hans.schillstrom@ericsson.com>2011-01-03 08:44:43 -0500
committerSimon Horman <horms@verge.net.au>2011-01-12 20:30:26 -0500
commitfc723250c9cb046cc19833a2b1c4309bbf59ac36 (patch)
treefa8cd33ad9e020549dd8c6389f311d25e495ca7d /include/net
parent61b1ab4583e275af216c8454b9256de680499b19 (diff)
IPVS: netns to services part 1
Services hash tables got netns ptr a hash arg, While Real Servers (rs) has been moved to ipvs struct. Two new inline functions added to get net ptr from skb. Since ip_vs is called from different contexts there is two places to dig for the net ptr skb->dev or skb->sk this is handled in skb_net() and skb_sknet() Global functions, ip_vs_service_get() ip_vs_lookup_real_service() etc have got struct net *net as first param. If possible get net ptr skb etc, - if not &init_net is used at this early stage of patching. ip_vs_ctl.c procfs not ready for netns yet. *v3 Comments by Julian - __ip_vs_service_find and __ip_vs_svc_fwm_find are fast path, net_eq(svc->net, net) so the check is at the end now. - net = skb_net(skb) in ip_vs_out moved after check for skb_dst. Signed-off-by: Hans Schillstrom <hans.schillstrom@ericsson.com> Acked-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/ip_vs.h64
-rw-r--r--include/net/netns/ip_vs.h8
2 files changed, 67 insertions, 5 deletions
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index c1c2ece3ed9..d551e0d8fd9 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -37,6 +37,59 @@ static inline struct netns_ipvs *net_ipvs(struct net* net)
37{ 37{
38 return net->ipvs; 38 return net->ipvs;
39} 39}
40/*
41 * Get net ptr from skb in traffic cases
42 * use skb_sknet when call is from userland (ioctl or netlink)
43 */
44static inline struct net *skb_net(struct sk_buff *skb)
45{
46#ifdef CONFIG_NET_NS
47#ifdef CONFIG_IP_VS_DEBUG
48 /*
49 * This is used for debug only.
50 * Start with the most likely hit
51 * End with BUG
52 */
53 if (likely(skb->dev && skb->dev->nd_net))
54 return dev_net(skb->dev);
55 if (skb_dst(skb)->dev)
56 return dev_net(skb_dst(skb)->dev);
57 WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
58 __func__, __LINE__);
59 if (likely(skb->sk && skb->sk->sk_net))
60 return sock_net(skb->sk);
61 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
62 __func__, __LINE__);
63 BUG();
64#else
65 return dev_net(skb->dev ? : skb_dst(skb)->dev);
66#endif
67#else
68 return &init_net;
69#endif
70}
71
72static inline struct net *skb_sknet(struct sk_buff *skb)
73{
74#ifdef CONFIG_NET_NS
75#ifdef CONFIG_IP_VS_DEBUG
76 /* Start with the most likely hit */
77 if (likely(skb->sk && skb->sk->sk_net))
78 return sock_net(skb->sk);
79 WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
80 __func__, __LINE__);
81 if (likely(skb->dev && skb->dev->nd_net))
82 return dev_net(skb->dev);
83 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
84 __func__, __LINE__);
85 BUG();
86#else
87 return sock_net(skb->sk);
88#endif
89#else
90 return &init_net;
91#endif
92}
40 93
41/* Connections' size value needed by ip_vs_ctl.c */ 94/* Connections' size value needed by ip_vs_ctl.c */
42extern int ip_vs_conn_tab_size; 95extern int ip_vs_conn_tab_size;
@@ -496,6 +549,7 @@ struct ip_vs_service {
496 unsigned flags; /* service status flags */ 549 unsigned flags; /* service status flags */
497 unsigned timeout; /* persistent timeout in ticks */ 550 unsigned timeout; /* persistent timeout in ticks */
498 __be32 netmask; /* grouping granularity */ 551 __be32 netmask; /* grouping granularity */
552 struct net *net;
499 553
500 struct list_head destinations; /* real server d-linked list */ 554 struct list_head destinations; /* real server d-linked list */
501 __u32 num_dests; /* number of servers */ 555 __u32 num_dests; /* number of servers */
@@ -896,7 +950,7 @@ extern int sysctl_ip_vs_sync_ver;
896 950
897extern void ip_vs_sync_switch_mode(int mode); 951extern void ip_vs_sync_switch_mode(int mode);
898extern struct ip_vs_service * 952extern struct ip_vs_service *
899ip_vs_service_get(int af, __u32 fwmark, __u16 protocol, 953ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol,
900 const union nf_inet_addr *vaddr, __be16 vport); 954 const union nf_inet_addr *vaddr, __be16 vport);
901 955
902static inline void ip_vs_service_put(struct ip_vs_service *svc) 956static inline void ip_vs_service_put(struct ip_vs_service *svc)
@@ -905,7 +959,7 @@ static inline void ip_vs_service_put(struct ip_vs_service *svc)
905} 959}
906 960
907extern struct ip_vs_dest * 961extern struct ip_vs_dest *
908ip_vs_lookup_real_service(int af, __u16 protocol, 962ip_vs_lookup_real_service(struct net *net, int af, __u16 protocol,
909 const union nf_inet_addr *daddr, __be16 dport); 963 const union nf_inet_addr *daddr, __be16 dport);
910 964
911extern int ip_vs_use_count_inc(void); 965extern int ip_vs_use_count_inc(void);
@@ -913,9 +967,9 @@ extern void ip_vs_use_count_dec(void);
913extern int ip_vs_control_init(void); 967extern int ip_vs_control_init(void);
914extern void ip_vs_control_cleanup(void); 968extern void ip_vs_control_cleanup(void);
915extern struct ip_vs_dest * 969extern struct ip_vs_dest *
916ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport, 970ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr,
917 const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol, 971 __be16 dport, const union nf_inet_addr *vaddr, __be16 vport,
918 __u32 fwmark); 972 __u16 protocol, __u32 fwmark);
919extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp); 973extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
920 974
921 975
diff --git a/include/net/netns/ip_vs.h b/include/net/netns/ip_vs.h
index 12fe84087ce..5b87d22a39f 100644
--- a/include/net/netns/ip_vs.h
+++ b/include/net/netns/ip_vs.h
@@ -20,6 +20,14 @@ struct ctl_table_header;
20 20
21struct netns_ipvs { 21struct netns_ipvs {
22 int gen; /* Generation */ 22 int gen; /* Generation */
23 /*
24 * Hash table: for real service lookups
25 */
26 #define IP_VS_RTAB_BITS 4
27 #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
28 #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
29
30 struct list_head rs_table[IP_VS_RTAB_SIZE];
23}; 31};
24 32
25#endif /* IP_VS_H_ */ 33#endif /* IP_VS_H_ */