[collectd] [PATCH] ipvs plugin: Check for correct IPVS version in cipvs_init().

Sebastian Harl sh at tokkee.org
Fri Oct 12 16:14:25 CEST 2007


I took over the required minimum version (1.1.4) as used in ipvsadm 1.24
for Linux kernels >= 2.6.

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/ipvs.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/ipvs.c b/src/ipvs.c
index 9bf2224..4c63058 100644
--- a/src/ipvs.c
+++ b/src/ipvs.c
@@ -52,6 +52,7 @@
 #endif /* HAVE_IP_VS_H */
 
 #define log_err(...) ERROR ("ipvs: " __VA_ARGS__)
+#define log_info(...) INFO ("ipvs: " __VA_ARGS__)
 
 
 /*
@@ -140,12 +141,39 @@ static struct ip_vs_get_dests *ipvs_get_dests (struct ip_vs_service_entry *se)
 
 static int cipvs_init (void)
 {
+	struct ip_vs_getinfo ipvs_info;
+
+	socklen_t len;
+
 	if (-1 == (sockfd = socket (AF_INET, SOCK_RAW, IPPROTO_RAW))) {
 		char errbuf[1024];
 		log_err ("cipvs_init: socket() failed: %s",
 				sstrerror (errno, errbuf, sizeof (errbuf)));
 		return -1;
 	}
+
+	len = sizeof (ipvs_info);
+
+	if (0 != getsockopt (sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO,
+				(void *)&ipvs_info, &len)) {
+		char errbuf[1024];
+		log_err ("cipvs_init: getsockopt() failed: %s",
+				sstrerror (errno, errbuf, sizeof (errbuf)));
+		close (sockfd);
+		return -1;
+	}
+
+	/* we need IPVS >= 1.1.4 */
+	if (ipvs_info.version < ((1 << 16) + (1 << 8) + 4)) {
+		log_err ("cipvs_init: IPVS version too old (%d.%d.%d < %d.%d.%d)",
+				NVERSION (ipvs_info.version), 1, 1, 4);
+		close (sockfd);
+		return -1;
+	}
+	else {
+		log_info ("Successfully connected to IPVS %d.%d.%d",
+				NVERSION (ipvs_info.version));
+	}
 	return 0;
 } /* cipvs_init */
 
-- 
1.5.3.4.206.g58ba4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20071012/78a897a7/attachment.pgp 


More information about the collectd mailing list