From b8d58bd1f1fe3b329c5a97152ae05a1779a1fb27 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 12 Oct 2007 14:31:29 +0200 Subject: [PATCH] ipvs plugin: Get IP_VS_SO_GET_INFO in ip_vs_get_services(). IP_VS_SO_GET_INFO also provides the number of services which might change after initializing the plugin. Also, the globale variable ipvs_info could be removed as ip_vs_get_services() is the only function using these information. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- src/ipvs.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/ipvs.c b/src/ipvs.c index c670b09d..f9acab5c 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -61,8 +61,6 @@ static int sockfd = -1; static void *ipvs_func = NULL; -static struct ip_vs_getinfo ipvs_info; - /* * libipvs API @@ -99,9 +97,20 @@ static const char *ipvs_strerror (int err) static struct ip_vs_get_services *ipvs_get_services (void) { + struct ip_vs_getinfo ipvs_info; struct ip_vs_get_services *ret; + socklen_t len; + len = sizeof (ipvs_info); + + if (0 != getsockopt (sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO, + (void *)&ipvs_info, &len)) { + log_err ("ip_vs_get_services: getsockopt() failed: %s", + ipvs_strerror (errno)); + return NULL; + } + len = sizeof (*ret) + sizeof (struct ip_vs_service_entry) * ipvs_info.num_services; @@ -162,20 +171,10 @@ static struct ip_vs_get_dests *ipvs_get_dests (struct ip_vs_service_entry *se) static int cipvs_init (void) { - socklen_t len; - - len = sizeof (ipvs_info); - if (-1 == (sockfd = socket (AF_INET, SOCK_RAW, IPPROTO_RAW))) { log_err ("cipvs_init: socket() failed: %s", ipvs_strerror (errno)); return -1; } - - if (0 != getsockopt (sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO, - (void *)&ipvs_info, &len)) { - log_err ("cipvs_init: getsockopt() failed: %s", ipvs_strerror (errno)); - return -1; - } return 0; } /* cipvs_init */ -- 2.30.2