aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Schillstrom <hans.schillstrom@ericsson.com>2011-01-03 08:44:49 -0500
committerSimon Horman <horms@verge.net.au>2011-01-12 20:30:27 -0500
commit9d934878e7870fbbbd8eaed2e467552536877def (patch)
tree82be8a59a2a68a7f8511c9d2b5a1a457b21fce58
parent78b16bde104cc74bedbf462b0ebed2990f35ff6b (diff)
IPVS: netns preparation for proto_sctp
In this phase (one), all local vars will be moved to ipvs struct. Remaining work, add param struct net *net to a couple of functions that is common for all protos and use ip_vs_proto_data *v3 Removed unuset function set_state_timeout() 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>
-rw-r--r--include/net/netns/ip_vs.h9
-rw-r--r--net/netfilter/ipvs/ip_vs_proto.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_proto_sctp.c121
3 files changed, 70 insertions, 63 deletions
diff --git a/include/net/netns/ip_vs.h b/include/net/netns/ip_vs.h
index 62b1448d3795..58bd3fd85a97 100644
--- a/include/net/netns/ip_vs.h
+++ b/include/net/netns/ip_vs.h
@@ -47,6 +47,15 @@ struct netns_ipvs {
47 struct list_head udp_apps[UDP_APP_TAB_SIZE]; 47 struct list_head udp_apps[UDP_APP_TAB_SIZE];
48 spinlock_t udp_app_lock; 48 spinlock_t udp_app_lock;
49#endif 49#endif
50 /* ip_vs_proto_sctp */
51#ifdef CONFIG_IP_VS_PROTO_SCTP
52 #define SCTP_APP_TAB_BITS 4
53 #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
54 #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
55 /* Hash table for SCTP application incarnations */
56 struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
57 spinlock_t sctp_app_lock;
58#endif
50 59
51 /* ip_vs_lblc */ 60 /* ip_vs_lblc */
52 int sysctl_lblc_expiration; 61 int sysctl_lblc_expiration;
diff --git a/net/netfilter/ipvs/ip_vs_proto.c b/net/netfilter/ipvs/ip_vs_proto.c
index cdc414238fcb..001b2f825043 100644
--- a/net/netfilter/ipvs/ip_vs_proto.c
+++ b/net/netfilter/ipvs/ip_vs_proto.c
@@ -313,6 +313,9 @@ static int __net_init __ip_vs_protocol_init(struct net *net)
313#ifdef CONFIG_IP_VS_PROTO_UDP 313#ifdef CONFIG_IP_VS_PROTO_UDP
314 register_ip_vs_proto_netns(net, &ip_vs_protocol_udp); 314 register_ip_vs_proto_netns(net, &ip_vs_protocol_udp);
315#endif 315#endif
316#ifdef CONFIG_IP_VS_PROTO_SCTP
317 register_ip_vs_proto_netns(net, &ip_vs_protocol_sctp);
318#endif
316 return 0; 319 return 0;
317} 320}
318 321
diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
index 521b827083fe..f826dd1e4630 100644
--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -862,7 +862,7 @@ static struct ipvs_sctp_nextstate
862/* 862/*
863 * Timeout table[state] 863 * Timeout table[state]
864 */ 864 */
865static int sctp_timeouts[IP_VS_SCTP_S_LAST + 1] = { 865static const int sctp_timeouts[IP_VS_SCTP_S_LAST + 1] = {
866 [IP_VS_SCTP_S_NONE] = 2 * HZ, 866 [IP_VS_SCTP_S_NONE] = 2 * HZ,
867 [IP_VS_SCTP_S_INIT_CLI] = 1 * 60 * HZ, 867 [IP_VS_SCTP_S_INIT_CLI] = 1 * 60 * HZ,
868 [IP_VS_SCTP_S_INIT_SER] = 1 * 60 * HZ, 868 [IP_VS_SCTP_S_INIT_SER] = 1 * 60 * HZ,
@@ -906,18 +906,6 @@ static const char *sctp_state_name(int state)
906 return "?"; 906 return "?";
907} 907}
908 908
909static void sctp_timeout_change(struct ip_vs_protocol *pp, int flags)
910{
911}
912
913static int
914sctp_set_state_timeout(struct ip_vs_protocol *pp, char *sname, int to)
915{
916
917return ip_vs_set_state_timeout(pp->timeout_table, IP_VS_SCTP_S_LAST,
918 sctp_state_name_table, sname, to);
919}
920
921static inline int 909static inline int
922set_sctp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp, 910set_sctp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp,
923 int direction, const struct sk_buff *skb) 911 int direction, const struct sk_buff *skb)
@@ -926,6 +914,7 @@ set_sctp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp,
926 unsigned char chunk_type; 914 unsigned char chunk_type;
927 int event, next_state; 915 int event, next_state;
928 int ihl; 916 int ihl;
917 struct ip_vs_proto_data *pd;
929 918
930#ifdef CONFIG_IP_VS_IPV6 919#ifdef CONFIG_IP_VS_IPV6
931 ihl = cp->af == AF_INET ? ip_hdrlen(skb) : sizeof(struct ipv6hdr); 920 ihl = cp->af == AF_INET ? ip_hdrlen(skb) : sizeof(struct ipv6hdr);
@@ -1001,10 +990,13 @@ set_sctp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp,
1001 } 990 }
1002 } 991 }
1003 } 992 }
993 pd = ip_vs_proto_data_get(&init_net, pp->protocol); /* tmp fix */
994 if (likely(pd))
995 cp->timeout = pd->timeout_table[cp->state = next_state];
996 else /* What to do ? */
997 cp->timeout = sctp_timeouts[cp->state = next_state];
1004 998
1005 cp->timeout = pp->timeout_table[cp->state = next_state]; 999 return 1;
1006
1007 return 1;
1008} 1000}
1009 1001
1010static int 1002static int
@@ -1020,16 +1012,6 @@ sctp_state_transition(struct ip_vs_conn *cp, int direction,
1020 return ret; 1012 return ret;
1021} 1013}
1022 1014
1023/*
1024 * Hash table for SCTP application incarnations
1025 */
1026#define SCTP_APP_TAB_BITS 4
1027#define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
1028#define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
1029
1030static struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
1031static DEFINE_SPINLOCK(sctp_app_lock);
1032
1033static inline __u16 sctp_app_hashkey(__be16 port) 1015static inline __u16 sctp_app_hashkey(__be16 port)
1034{ 1016{
1035 return (((__force u16)port >> SCTP_APP_TAB_BITS) ^ (__force u16)port) 1017 return (((__force u16)port >> SCTP_APP_TAB_BITS) ^ (__force u16)port)
@@ -1042,34 +1024,40 @@ static int sctp_register_app(struct ip_vs_app *inc)
1042 __u16 hash; 1024 __u16 hash;
1043 __be16 port = inc->port; 1025 __be16 port = inc->port;
1044 int ret = 0; 1026 int ret = 0;
1027 struct netns_ipvs *ipvs = net_ipvs(&init_net);
1028 struct ip_vs_proto_data *pd = ip_vs_proto_data_get(&init_net, IPPROTO_SCTP);
1045 1029
1046 hash = sctp_app_hashkey(port); 1030 hash = sctp_app_hashkey(port);
1047 1031
1048 spin_lock_bh(&sctp_app_lock); 1032 spin_lock_bh(&ipvs->sctp_app_lock);
1049 list_for_each_entry(i, &sctp_apps[hash], p_list) { 1033 list_for_each_entry(i, &ipvs->sctp_apps[hash], p_list) {
1050 if (i->port == port) { 1034 if (i->port == port) {
1051 ret = -EEXIST; 1035 ret = -EEXIST;
1052 goto out; 1036 goto out;
1053 } 1037 }
1054 } 1038 }
1055 list_add(&inc->p_list, &sctp_apps[hash]); 1039 list_add(&inc->p_list, &ipvs->sctp_apps[hash]);
1056 atomic_inc(&ip_vs_protocol_sctp.appcnt); 1040 atomic_inc(&pd->pp->appcnt);
1057out: 1041out:
1058 spin_unlock_bh(&sctp_app_lock); 1042 spin_unlock_bh(&ipvs->sctp_app_lock);
1059 1043
1060 return ret; 1044 return ret;
1061} 1045}
1062 1046
1063static void sctp_unregister_app(struct ip_vs_app *inc) 1047static void sctp_unregister_app(struct ip_vs_app *inc)
1064{ 1048{
1065 spin_lock_bh(&sctp_app_lock); 1049 struct netns_ipvs *ipvs = net_ipvs(&init_net);
1066 atomic_dec(&ip_vs_protocol_sctp.appcnt); 1050 struct ip_vs_proto_data *pd = ip_vs_proto_data_get(&init_net, IPPROTO_SCTP);
1051
1052 spin_lock_bh(&ipvs->sctp_app_lock);
1053 atomic_dec(&pd->pp->appcnt);
1067 list_del(&inc->p_list); 1054 list_del(&inc->p_list);
1068 spin_unlock_bh(&sctp_app_lock); 1055 spin_unlock_bh(&ipvs->sctp_app_lock);
1069} 1056}
1070 1057
1071static int sctp_app_conn_bind(struct ip_vs_conn *cp) 1058static int sctp_app_conn_bind(struct ip_vs_conn *cp)
1072{ 1059{
1060 struct netns_ipvs *ipvs = net_ipvs(&init_net);
1073 int hash; 1061 int hash;
1074 struct ip_vs_app *inc; 1062 struct ip_vs_app *inc;
1075 int result = 0; 1063 int result = 0;
@@ -1080,12 +1068,12 @@ static int sctp_app_conn_bind(struct ip_vs_conn *cp)
1080 /* Lookup application incarnations and bind the right one */ 1068 /* Lookup application incarnations and bind the right one */
1081 hash = sctp_app_hashkey(cp->vport); 1069 hash = sctp_app_hashkey(cp->vport);
1082 1070
1083 spin_lock(&sctp_app_lock); 1071 spin_lock(&ipvs->sctp_app_lock);
1084 list_for_each_entry(inc, &sctp_apps[hash], p_list) { 1072 list_for_each_entry(inc, &ipvs->sctp_apps[hash], p_list) {
1085 if (inc->port == cp->vport) { 1073 if (inc->port == cp->vport) {
1086 if (unlikely(!ip_vs_app_inc_get(inc))) 1074 if (unlikely(!ip_vs_app_inc_get(inc)))
1087 break; 1075 break;
1088 spin_unlock(&sctp_app_lock); 1076 spin_unlock(&ipvs->sctp_app_lock);
1089 1077
1090 IP_VS_DBG_BUF(9, "%s: Binding conn %s:%u->" 1078 IP_VS_DBG_BUF(9, "%s: Binding conn %s:%u->"
1091 "%s:%u to app %s on port %u\n", 1079 "%s:%u to app %s on port %u\n",
@@ -1101,43 +1089,50 @@ static int sctp_app_conn_bind(struct ip_vs_conn *cp)
1101 goto out; 1089 goto out;
1102 } 1090 }
1103 } 1091 }
1104 spin_unlock(&sctp_app_lock); 1092 spin_unlock(&ipvs->sctp_app_lock);
1105out: 1093out:
1106 return result; 1094 return result;
1107} 1095}
1108 1096
1109static void ip_vs_sctp_init(struct ip_vs_protocol *pp) 1097/* ---------------------------------------------
1098 * timeouts is netns related now.
1099 * ---------------------------------------------
1100 */
1101static void __ip_vs_sctp_init(struct net *net, struct ip_vs_proto_data *pd)
1110{ 1102{
1111 IP_VS_INIT_HASH_TABLE(sctp_apps); 1103 struct netns_ipvs *ipvs = net_ipvs(net);
1112 pp->timeout_table = sctp_timeouts;
1113}
1114 1104
1105 ip_vs_init_hash_table(ipvs->sctp_apps, SCTP_APP_TAB_SIZE);
1106 spin_lock_init(&ipvs->tcp_app_lock);
1107 pd->timeout_table = ip_vs_create_timeout_table((int *)sctp_timeouts,
1108 sizeof(sctp_timeouts));
1109}
1115 1110
1116static void ip_vs_sctp_exit(struct ip_vs_protocol *pp) 1111static void __ip_vs_sctp_exit(struct net *net, struct ip_vs_proto_data *pd)
1117{ 1112{
1118 1113 kfree(pd->timeout_table);
1119} 1114}
1120 1115
1121struct ip_vs_protocol ip_vs_protocol_sctp = { 1116struct ip_vs_protocol ip_vs_protocol_sctp = {
1122 .name = "SCTP", 1117 .name = "SCTP",
1123 .protocol = IPPROTO_SCTP, 1118 .protocol = IPPROTO_SCTP,
1124 .num_states = IP_VS_SCTP_S_LAST, 1119 .num_states = IP_VS_SCTP_S_LAST,
1125 .dont_defrag = 0, 1120 .dont_defrag = 0,
1126 .appcnt = ATOMIC_INIT(0), 1121 .init = NULL,
1127 .init = ip_vs_sctp_init, 1122 .exit = NULL,
1128 .exit = ip_vs_sctp_exit, 1123 .init_netns = __ip_vs_sctp_init,
1129 .register_app = sctp_register_app, 1124 .exit_netns = __ip_vs_sctp_exit,
1125 .register_app = sctp_register_app,
1130 .unregister_app = sctp_unregister_app, 1126 .unregister_app = sctp_unregister_app,
1131 .conn_schedule = sctp_conn_schedule, 1127 .conn_schedule = sctp_conn_schedule,
1132 .conn_in_get = ip_vs_conn_in_get_proto, 1128 .conn_in_get = ip_vs_conn_in_get_proto,
1133 .conn_out_get = ip_vs_conn_out_get_proto, 1129 .conn_out_get = ip_vs_conn_out_get_proto,
1134 .snat_handler = sctp_snat_handler, 1130 .snat_handler = sctp_snat_handler,
1135 .dnat_handler = sctp_dnat_handler, 1131 .dnat_handler = sctp_dnat_handler,
1136 .csum_check = sctp_csum_check, 1132 .csum_check = sctp_csum_check,
1137 .state_name = sctp_state_name, 1133 .state_name = sctp_state_name,
1138 .state_transition = sctp_state_transition, 1134 .state_transition = sctp_state_transition,
1139 .app_conn_bind = sctp_app_conn_bind, 1135 .app_conn_bind = sctp_app_conn_bind,
1140 .debug_packet = ip_vs_tcpudp_debug_packet, 1136 .debug_packet = ip_vs_tcpudp_debug_packet,
1141 .timeout_change = sctp_timeout_change, 1137 .timeout_change = NULL,
1142 .set_state_timeout = sctp_set_state_timeout,
1143}; 1138};