aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Anastasov <ja@ssi.bg>2013-04-17 16:50:49 -0400
committerSimon Horman <horms@verge.net.au>2013-04-22 22:43:05 -0400
commit0a925864c1038a78fd1cc9b048d9a2b1ae04b63e (patch)
tree1e7816ea1ad26b9945b91d001450646ac489958a
parentf33c8b94fd51aeb0bc02f87ee172691ddf7936b6 (diff)
ipvs: fix sparse warnings for some parameters
Some service fields are in network order: - netmask: used once in network order and also as prefix len for IPv6 - port Other parameters are in host order: - struct ip_vs_flags: flags and mask moved between user and kernel only - sync state: moved between user and kernel only - syncid: sent over network as single octet Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r--include/net/ip_vs.h8
-rw-r--r--include/uapi/linux/ip_vs.h4
-rw-r--r--net/netfilter/ipvs/ip_vs_core.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c40
4 files changed, 32 insertions, 23 deletions
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index f9f5b057b480..4c062ccff9aa 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -678,7 +678,7 @@ struct ip_vs_service_user_kern {
678 u16 af; 678 u16 af;
679 u16 protocol; 679 u16 protocol;
680 union nf_inet_addr addr; /* virtual ip address */ 680 union nf_inet_addr addr; /* virtual ip address */
681 u16 port; 681 __be16 port;
682 u32 fwmark; /* firwall mark of service */ 682 u32 fwmark; /* firwall mark of service */
683 683
684 /* virtual service options */ 684 /* virtual service options */
@@ -686,14 +686,14 @@ struct ip_vs_service_user_kern {
686 char *pe_name; 686 char *pe_name;
687 unsigned int flags; /* virtual service flags */ 687 unsigned int flags; /* virtual service flags */
688 unsigned int timeout; /* persistent timeout in sec */ 688 unsigned int timeout; /* persistent timeout in sec */
689 u32 netmask; /* persistent netmask */ 689 __be32 netmask; /* persistent netmask or plen */
690}; 690};
691 691
692 692
693struct ip_vs_dest_user_kern { 693struct ip_vs_dest_user_kern {
694 /* destination server address */ 694 /* destination server address */
695 union nf_inet_addr addr; 695 union nf_inet_addr addr;
696 u16 port; 696 __be16 port;
697 697
698 /* real server options */ 698 /* real server options */
699 unsigned int conn_flags; /* connection flags */ 699 unsigned int conn_flags; /* connection flags */
@@ -721,7 +721,7 @@ struct ip_vs_service {
721 __u32 fwmark; /* firewall mark of the service */ 721 __u32 fwmark; /* firewall mark of the service */
722 unsigned int flags; /* service status flags */ 722 unsigned int flags; /* service status flags */
723 unsigned int timeout; /* persistent timeout in ticks */ 723 unsigned int timeout; /* persistent timeout in ticks */
724 __be32 netmask; /* grouping granularity */ 724 __be32 netmask; /* grouping granularity, mask/plen */
725 struct net *net; 725 struct net *net;
726 726
727 struct list_head destinations; /* real server d-linked list */ 727 struct list_head destinations; /* real server d-linked list */
diff --git a/include/uapi/linux/ip_vs.h b/include/uapi/linux/ip_vs.h
index 8a2d438dc499..a24537725e80 100644
--- a/include/uapi/linux/ip_vs.h
+++ b/include/uapi/linux/ip_vs.h
@@ -280,8 +280,8 @@ struct ip_vs_daemon_user {
280#define IPVS_GENL_VERSION 0x1 280#define IPVS_GENL_VERSION 0x1
281 281
282struct ip_vs_flags { 282struct ip_vs_flags {
283 __be32 flags; 283 __u32 flags;
284 __be32 mask; 284 __u32 mask;
285}; 285};
286 286
287/* Generic Netlink command attributes */ 287/* Generic Netlink command attributes */
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index f26fe3353a30..a0d7bd342775 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -235,7 +235,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
235 /* Mask saddr with the netmask to adjust template granularity */ 235 /* Mask saddr with the netmask to adjust template granularity */
236#ifdef CONFIG_IP_VS_IPV6 236#ifdef CONFIG_IP_VS_IPV6
237 if (svc->af == AF_INET6) 237 if (svc->af == AF_INET6)
238 ipv6_addr_prefix(&snet.in6, &iph->saddr.in6, svc->netmask); 238 ipv6_addr_prefix(&snet.in6, &iph->saddr.in6,
239 (__force __u32) svc->netmask);
239 else 240 else
240#endif 241#endif
241 snet.ip = iph->saddr.ip & svc->netmask; 242 snet.ip = iph->saddr.ip & svc->netmask;
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 64075a775e35..5b142fb16480 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -1164,9 +1164,13 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,
1164 } 1164 }
1165 1165
1166#ifdef CONFIG_IP_VS_IPV6 1166#ifdef CONFIG_IP_VS_IPV6
1167 if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) { 1167 if (u->af == AF_INET6) {
1168 ret = -EINVAL; 1168 __u32 plen = (__force __u32) u->netmask;
1169 goto out_err; 1169
1170 if (plen < 1 || plen > 128) {
1171 ret = -EINVAL;
1172 goto out_err;
1173 }
1170 } 1174 }
1171#endif 1175#endif
1172 1176
@@ -1277,9 +1281,13 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
1277 } 1281 }
1278 1282
1279#ifdef CONFIG_IP_VS_IPV6 1283#ifdef CONFIG_IP_VS_IPV6
1280 if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) { 1284 if (u->af == AF_INET6) {
1281 ret = -EINVAL; 1285 __u32 plen = (__force __u32) u->netmask;
1282 goto out; 1286
1287 if (plen < 1 || plen > 128) {
1288 ret = -EINVAL;
1289 goto out;
1290 }
1283 } 1291 }
1284#endif 1292#endif
1285 1293
@@ -2892,7 +2900,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
2892 } else { 2900 } else {
2893 if (nla_put_u16(skb, IPVS_SVC_ATTR_PROTOCOL, svc->protocol) || 2901 if (nla_put_u16(skb, IPVS_SVC_ATTR_PROTOCOL, svc->protocol) ||
2894 nla_put(skb, IPVS_SVC_ATTR_ADDR, sizeof(svc->addr), &svc->addr) || 2902 nla_put(skb, IPVS_SVC_ATTR_ADDR, sizeof(svc->addr), &svc->addr) ||
2895 nla_put_u16(skb, IPVS_SVC_ATTR_PORT, svc->port)) 2903 nla_put_be16(skb, IPVS_SVC_ATTR_PORT, svc->port))
2896 goto nla_put_failure; 2904 goto nla_put_failure;
2897 } 2905 }
2898 2906
@@ -2902,7 +2910,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
2902 (pe && nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, pe->name)) || 2910 (pe && nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, pe->name)) ||
2903 nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) || 2911 nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
2904 nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) || 2912 nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
2905 nla_put_u32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask)) 2913 nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
2906 goto nla_put_failure; 2914 goto nla_put_failure;
2907 if (ip_vs_genl_fill_stats(skb, IPVS_SVC_ATTR_STATS, &svc->stats)) 2915 if (ip_vs_genl_fill_stats(skb, IPVS_SVC_ATTR_STATS, &svc->stats))
2908 goto nla_put_failure; 2916 goto nla_put_failure;
@@ -3015,7 +3023,7 @@ static int ip_vs_genl_parse_service(struct net *net,
3015 } else { 3023 } else {
3016 usvc->protocol = nla_get_u16(nla_protocol); 3024 usvc->protocol = nla_get_u16(nla_protocol);
3017 nla_memcpy(&usvc->addr, nla_addr, sizeof(usvc->addr)); 3025 nla_memcpy(&usvc->addr, nla_addr, sizeof(usvc->addr));
3018 usvc->port = nla_get_u16(nla_port); 3026 usvc->port = nla_get_be16(nla_port);
3019 usvc->fwmark = 0; 3027 usvc->fwmark = 0;
3020 } 3028 }
3021 3029
@@ -3055,7 +3063,7 @@ static int ip_vs_genl_parse_service(struct net *net,
3055 usvc->sched_name = nla_data(nla_sched); 3063 usvc->sched_name = nla_data(nla_sched);
3056 usvc->pe_name = nla_pe ? nla_data(nla_pe) : NULL; 3064 usvc->pe_name = nla_pe ? nla_data(nla_pe) : NULL;
3057 usvc->timeout = nla_get_u32(nla_timeout); 3065 usvc->timeout = nla_get_u32(nla_timeout);
3058 usvc->netmask = nla_get_u32(nla_netmask); 3066 usvc->netmask = nla_get_be32(nla_netmask);
3059 } 3067 }
3060 3068
3061 return 0; 3069 return 0;
@@ -3081,7 +3089,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
3081 return -EMSGSIZE; 3089 return -EMSGSIZE;
3082 3090
3083 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) || 3091 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
3084 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) || 3092 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
3085 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD, 3093 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
3086 (atomic_read(&dest->conn_flags) & 3094 (atomic_read(&dest->conn_flags) &
3087 IP_VS_CONN_F_FWD_MASK)) || 3095 IP_VS_CONN_F_FWD_MASK)) ||
@@ -3190,7 +3198,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
3190 memset(udest, 0, sizeof(*udest)); 3198 memset(udest, 0, sizeof(*udest));
3191 3199
3192 nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr)); 3200 nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
3193 udest->port = nla_get_u16(nla_port); 3201 udest->port = nla_get_be16(nla_port);
3194 3202
3195 /* If a full entry was requested, check for the additional fields */ 3203 /* If a full entry was requested, check for the additional fields */
3196 if (full_entry) { 3204 if (full_entry) {
@@ -3215,8 +3223,8 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
3215 return 0; 3223 return 0;
3216} 3224}
3217 3225
3218static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __be32 state, 3226static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __u32 state,
3219 const char *mcast_ifn, __be32 syncid) 3227 const char *mcast_ifn, __u32 syncid)
3220{ 3228{
3221 struct nlattr *nl_daemon; 3229 struct nlattr *nl_daemon;
3222 3230
@@ -3237,8 +3245,8 @@ nla_put_failure:
3237 return -EMSGSIZE; 3245 return -EMSGSIZE;
3238} 3246}
3239 3247
3240static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __be32 state, 3248static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __u32 state,
3241 const char *mcast_ifn, __be32 syncid, 3249 const char *mcast_ifn, __u32 syncid,
3242 struct netlink_callback *cb) 3250 struct netlink_callback *cb)
3243{ 3251{
3244 void *hdr; 3252 void *hdr;