summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Wegener <sven.wegener@stealer.net>2010-08-17 23:16:02 +0200
committerSven Wegener <sven.wegener@stealer.net>2010-08-17 23:16:02 +0200
commitbc9e861dd10f54545fa928a2fc33caf9d0e9956f (patch)
treefcadb6e911d0ab2f50875f26c9269c5e0d3b22a7
parent063baf510e72f0748f047f14c110596da6f5e8d3 (diff)
Touchup ip_vs.hip_vs.h-cleanup
Signed-off-by: Sven Wegener <sven.wegener@stealer.net> Conflicts: libipvs/ip_vs.h
-rw-r--r--libipvs/ip_vs.h181
-rw-r--r--libipvs/libipvs.c35
-rw-r--r--libipvs/libipvs.h98
3 files changed, 149 insertions, 165 deletions
diff --git a/libipvs/ip_vs.h b/libipvs/ip_vs.h
index 843c51a..15fb045 100644
--- a/libipvs/ip_vs.h
+++ b/libipvs/ip_vs.h
@@ -6,17 +6,8 @@
#ifndef _IP_VS_H
#define _IP_VS_H
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
#include <linux/types.h> /* For __beXX types in userland */
-#ifdef LIBIPVS_USE_NL
-#include <netlink/netlink.h>
-#include <netlink/genl/genl.h>
-#include <netlink/genl/ctrl.h>
-#endif
-
#define IP_VS_VERSION_CODE 0x010201
#define NVERSION(version) \
(version >> 16) & 0xFF, \
@@ -31,6 +22,12 @@
#define IP_VS_SVC_F_ONEPACKET 0x0004 /* one-packet scheduling */
/*
+ * Destination Server Flags
+ */
+#define IP_VS_DEST_F_AVAILABLE 0x0001 /* server is available */
+#define IP_VS_DEST_F_OVERLOAD 0x0002 /* server is overloaded */
+
+/*
* IPVS sync daemon states
*/
#define IP_VS_STATE_NONE 0x0000 /* daemon is stopped */
@@ -90,69 +87,34 @@
#define IP_VS_CONN_F_NO_CPORT 0x0800 /* no client port set yet */
#define IP_VS_CONN_F_TEMPLATE 0x1000 /* template, not connection */
#define IP_VS_CONN_F_ONE_PACKET 0x2000 /* forward only one packet */
+#define IP_VS_CONN_F_BACKLOG 0x4000 /* backlog connection */
#define IP_VS_SCHEDNAME_MAXLEN 16
#define IP_VS_IFNAME_MAXLEN 16
-union nf_inet_addr {
- __u32 all[4];
- __be32 ip;
- __be32 ip6[4];
- struct in_addr in;
- struct in6_addr in6;
-};
/*
* The struct ip_vs_service_user and struct ip_vs_dest_user are
* used to set IPVS rules through setsockopt.
*/
-struct ip_vs_service_kern {
- /* virtual service addresses */
- u_int16_t protocol;
- __be32 addr; /* virtual ip address */
- __be16 port;
- u_int32_t fwmark; /* firwall mark of service */
-
- /* virtual service options */
- char sched_name[IP_VS_SCHEDNAME_MAXLEN];
- unsigned flags; /* virtual service flags */
- unsigned timeout; /* persistent timeout in sec */
- __be32 netmask; /* persistent netmask */
-};
-
struct ip_vs_service_user {
/* virtual service addresses */
- u_int16_t protocol;
- __be32 __addr_v4; /* virtual ip address - internal use only */
+ __u16 protocol;
+ __be32 addr; /* virtual ip address */
__be16 port;
- u_int32_t fwmark; /* firwall mark of service */
+ __u32 fwmark; /* firwall mark of service */
/* virtual service options */
char sched_name[IP_VS_SCHEDNAME_MAXLEN];
unsigned flags; /* virtual service flags */
unsigned timeout; /* persistent timeout in sec */
__be32 netmask; /* persistent netmask */
- u_int16_t af;
- union nf_inet_addr addr;
};
-struct ip_vs_dest_kern {
- /* destination server address */
- __be32 addr;
- __be16 port;
-
- /* real server options */
- unsigned conn_flags; /* connection flags */
- int weight; /* destination weight */
-
- /* thresholds for active connections */
- u_int32_t u_threshold; /* upper threshold */
- u_int32_t l_threshold; /* lower threshold */
-};
struct ip_vs_dest_user {
/* destination server address */
- __be32 __addr_v4; /* internal use only */
+ __be32 addr;
__be16 port;
/* real server options */
@@ -160,17 +122,15 @@ struct ip_vs_dest_user {
int weight; /* destination weight */
/* thresholds for active connections */
- u_int32_t u_threshold; /* upper threshold */
- u_int32_t l_threshold; /* lower threshold */
- u_int16_t af;
- union nf_inet_addr addr;
+ __u32 u_threshold; /* upper threshold */
+ __u32 l_threshold; /* lower threshold */
};
+
/*
* IPVS statistics object (for user space)
*/
-struct ip_vs_stats_user
-{
+struct ip_vs_stats_user {
__u32 conns; /* connections scheduled */
__u32 inpkts; /* incoming packets */
__u32 outpkts; /* outgoing packets */
@@ -199,32 +159,12 @@ struct ip_vs_getinfo {
/* The argument to IP_VS_SO_GET_SERVICE */
-struct ip_vs_service_entry_kern {
- /* which service: user fills in these */
- u_int16_t protocol;
- __be32 addr; /* virtual address */
- __be16 port;
- u_int32_t fwmark; /* firwall mark of service */
-
- /* service options */
- char sched_name[IP_VS_SCHEDNAME_MAXLEN];
- unsigned flags; /* virtual service flags */
- unsigned timeout; /* persistent timeout */
- __be32 netmask; /* persistent netmask */
-
- /* number of real servers */
- unsigned int num_dests;
-
- /* statistics */
- struct ip_vs_stats_user stats;
-};
-
struct ip_vs_service_entry {
/* which service: user fills in these */
- u_int16_t protocol;
- __be32 __addr_v4; /* virtual address - internal use only*/
+ __u16 protocol;
+ __be32 addr; /* virtual address */
__be16 port;
- u_int32_t fwmark; /* firwall mark of service */
+ __u32 fwmark; /* firwall mark of service */
/* service options */
char sched_name[IP_VS_SCHEDNAME_MAXLEN];
@@ -237,79 +177,43 @@ struct ip_vs_service_entry {
/* statistics */
struct ip_vs_stats_user stats;
-
- u_int16_t af;
- union nf_inet_addr addr;
-
};
-struct ip_vs_dest_entry_kern {
- __be32 addr; /* destination address */
- __be16 port;
- unsigned conn_flags; /* connection flags */
- int weight; /* destination weight */
-
- u_int32_t u_threshold; /* upper threshold */
- u_int32_t l_threshold; /* lower threshold */
-
- u_int32_t activeconns; /* active connections */
- u_int32_t inactconns; /* inactive connections */
- u_int32_t persistconns; /* persistent connections */
-
- /* statistics */
- struct ip_vs_stats_user stats;
-};
struct ip_vs_dest_entry {
- __be32 __addr_v4; /* destination address - internal use only */
+ __be32 addr; /* destination address */
__be16 port;
unsigned conn_flags; /* connection flags */
int weight; /* destination weight */
- u_int32_t u_threshold; /* upper threshold */
- u_int32_t l_threshold; /* lower threshold */
+ __u32 u_threshold; /* upper threshold */
+ __u32 l_threshold; /* lower threshold */
- u_int32_t activeconns; /* active connections */
- u_int32_t inactconns; /* inactive connections */
- u_int32_t persistconns; /* persistent connections */
+ __u32 activeconns; /* active connections */
+ __u32 inactconns; /* inactive connections */
+ __u32 persistconns; /* persistent connections */
/* statistics */
struct ip_vs_stats_user stats;
- u_int16_t af;
- union nf_inet_addr addr;
};
-/* The argument to IP_VS_SO_GET_DESTS */
-struct ip_vs_get_dests_kern {
- /* which service: user fills in these */
- u_int16_t protocol;
- __be32 addr; /* virtual address - internal use only */
- __be16 port;
- u_int32_t fwmark; /* firwall mark of service */
-
- /* number of real servers */
- unsigned int num_dests;
-
- /* the real servers */
- struct ip_vs_dest_entry_kern entrytable[0];
-};
+/* The argument to IP_VS_SO_GET_DESTS */
struct ip_vs_get_dests {
/* which service: user fills in these */
- u_int16_t protocol;
- __be32 __addr_v4; /* virtual address - internal use only */
+ __u16 protocol;
+ __be32 addr; /* virtual address */
__be16 port;
- u_int32_t fwmark; /* firwall mark of service */
+ __u32 fwmark; /* firwall mark of service */
/* number of real servers */
unsigned int num_dests;
- u_int16_t af;
- union nf_inet_addr addr;
/* the real servers */
struct ip_vs_dest_entry entrytable[0];
};
+
/* The argument to IP_VS_SO_GET_SERVICES */
struct ip_vs_get_services {
/* number of virtual services */
@@ -319,13 +223,6 @@ struct ip_vs_get_services {
struct ip_vs_service_entry entrytable[0];
};
-struct ip_vs_get_services_kern {
- /* number of virtual services */
- unsigned int num_services;
-
- /* service table */
- struct ip_vs_service_entry_kern entrytable[0];
-};
/* The argument to IP_VS_SO_GET_TIMEOUT */
struct ip_vs_timeout_user {
@@ -347,7 +244,6 @@ struct ip_vs_daemon_user {
int syncid;
};
-
/*
*
* IPVS Generic Netlink interface definitions
@@ -371,19 +267,19 @@ enum {
IPVS_CMD_NEW_SERVICE, /* add service */
IPVS_CMD_SET_SERVICE, /* modify service */
IPVS_CMD_DEL_SERVICE, /* delete service */
- IPVS_CMD_GET_SERVICE, /* get info about specific service */
+ IPVS_CMD_GET_SERVICE, /* get service info */
IPVS_CMD_NEW_DEST, /* add destination */
IPVS_CMD_SET_DEST, /* modify destination */
IPVS_CMD_DEL_DEST, /* delete destination */
- IPVS_CMD_GET_DEST, /* get list of all service dests */
+ IPVS_CMD_GET_DEST, /* get destination info */
IPVS_CMD_NEW_DAEMON, /* start sync daemon */
IPVS_CMD_DEL_DAEMON, /* stop sync daemon */
IPVS_CMD_GET_DAEMON, /* get sync daemon status */
- IPVS_CMD_SET_TIMEOUT, /* set TCP and UDP timeouts */
- IPVS_CMD_GET_TIMEOUT, /* get TCP and UDP timeouts */
+ IPVS_CMD_SET_CONFIG, /* set config settings */
+ IPVS_CMD_GET_CONFIG, /* get config settings */
IPVS_CMD_SET_INFO, /* only used in GET_INFO reply */
IPVS_CMD_GET_INFO, /* get general IPVS info */
@@ -508,15 +404,4 @@ enum {
#define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1)
-#ifdef LIBIPVS_USE_NL
-extern struct nla_policy ipvs_cmd_policy[IPVS_CMD_ATTR_MAX + 1];
-extern struct nla_policy ipvs_service_policy[IPVS_SVC_ATTR_MAX + 1];
-extern struct nla_policy ipvs_dest_policy[IPVS_DEST_ATTR_MAX + 1];
-extern struct nla_policy ipvs_stats_policy[IPVS_STATS_ATTR_MAX + 1];
-extern struct nla_policy ipvs_info_policy[IPVS_INFO_ATTR_MAX + 1];
-extern struct nla_policy ipvs_daemon_policy[IPVS_DAEMON_ATTR_MAX + 1];
-#endif
-
-/* End of Generic Netlink interface definitions */
-
#endif /* _IP_VS_H */
diff --git a/libipvs/libipvs.c b/libipvs/libipvs.c
index 979d5bd..f8919c2 100644
--- a/libipvs/libipvs.c
+++ b/libipvs/libipvs.c
@@ -20,11 +20,17 @@
#include <sys/socket.h>
#include <arpa/inet.h>
+#ifdef LIBIPVS_USE_NL
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+#endif
+
#include "libipvs.h"
-typedef struct ipvs_servicedest_s {
- struct ip_vs_service_kern svc;
- struct ip_vs_dest_kern dest;
+typedef struct {
+ ipvs_service_t svc;
+ ipvs_dest_t dest;
} ipvs_servicedest_t;
static int sockfd = -1;
@@ -34,6 +40,13 @@ struct ip_vs_getinfo ipvs_info;
#ifdef LIBIPVS_USE_NL
static struct nl_handle *sock = NULL;
static int family, try_nl = 1;
+
+extern struct nla_policy ipvs_cmd_policy[IPVS_CMD_ATTR_MAX + 1];
+extern struct nla_policy ipvs_service_policy[IPVS_SVC_ATTR_MAX + 1];
+extern struct nla_policy ipvs_dest_policy[IPVS_DEST_ATTR_MAX + 1];
+extern struct nla_policy ipvs_stats_policy[IPVS_STATS_ATTR_MAX + 1];
+extern struct nla_policy ipvs_info_policy[IPVS_INFO_ATTR_MAX + 1];
+extern struct nla_policy ipvs_daemon_policy[IPVS_DAEMON_ATTR_MAX + 1];
#endif
#define CHECK_IPV4(s, ret) if (s->af && s->af != AF_INET) \
@@ -247,7 +260,7 @@ int ipvs_add_service(ipvs_service_t *svc)
CHECK_IPV4(svc, -1);
return setsockopt(sockfd, IPPROTO_IP, IP_VS_SO_SET_ADD, (char *)svc,
- sizeof(struct ip_vs_service_kern));
+ sizeof(struct ip_vs_service_user));
}
@@ -267,7 +280,7 @@ int ipvs_update_service(ipvs_service_t *svc)
#endif
CHECK_IPV4(svc, -1);
return setsockopt(sockfd, IPPROTO_IP, IP_VS_SO_SET_EDIT, (char *)svc,
- sizeof(struct ip_vs_service_kern));
+ sizeof(struct ip_vs_service_user));
}
@@ -287,7 +300,7 @@ int ipvs_del_service(ipvs_service_t *svc)
#endif
CHECK_IPV4(svc, -1);
return setsockopt(sockfd, IPPROTO_IP, IP_VS_SO_SET_DEL, (char *)svc,
- sizeof(struct ip_vs_service_kern));
+ sizeof(struct ip_vs_service_user));
}
@@ -312,7 +325,7 @@ int ipvs_zero_service(ipvs_service_t *svc)
#endif
CHECK_IPV4(svc, -1);
return setsockopt(sockfd, IPPROTO_IP, IP_VS_SO_SET_ZERO, (char *)svc,
- sizeof(struct ip_vs_service_kern));
+ sizeof(struct ip_vs_service_user));
}
#ifdef LIBIPVS_USE_NL
@@ -433,7 +446,7 @@ int ipvs_set_timeout(ipvs_timeout_t *to)
ipvs_func = ipvs_set_timeout;
#ifdef LIBIPVS_USE_NL
if (try_nl) {
- struct nl_msg *msg = ipvs_nl_message(IPVS_CMD_SET_TIMEOUT, 0);
+ struct nl_msg *msg = ipvs_nl_message(IPVS_CMD_SET_CONFIG, 0);
if (!msg) return -1;
NLA_PUT_U32(msg, IPVS_CMD_ATTR_TIMEOUT_TCP, to->tcp_timeout);
NLA_PUT_U32(msg, IPVS_CMD_ATTR_TIMEOUT_TCP_FIN, to->tcp_fin_timeout);
@@ -644,7 +657,7 @@ struct ip_vs_get_services *ipvs_get_services(void)
if (!(get = malloc(len)))
return NULL;
len = sizeof(*getk) +
- sizeof(struct ip_vs_service_entry_kern) * ipvs_info.num_services;
+ sizeof(struct ip_vs_service_entry) * ipvs_info.num_services;
if (!(getk = malloc(len)))
return NULL;
@@ -659,7 +672,7 @@ struct ip_vs_get_services *ipvs_get_services(void)
memcpy(get, getk, sizeof(struct ip_vs_get_services));
for (i = 0; i < getk->num_services; i++) {
memcpy(&get->entrytable[i], &getk->entrytable[i],
- sizeof(struct ip_vs_service_entry_kern));
+ sizeof(struct ip_vs_service_entry));
get->entrytable[i].af = AF_INET;
get->entrytable[i].addr.ip = get->entrytable[i].__addr_v4;
}
@@ -983,7 +996,7 @@ ipvs_timeout_t *ipvs_get_timeout(void)
if (try_nl) {
struct nl_msg *msg;
memset(u, 0, sizeof(*u));
- msg = ipvs_nl_message(IPVS_CMD_GET_TIMEOUT, 0);
+ msg = ipvs_nl_message(IPVS_CMD_GET_CONFIG, 0);
if (msg && (ipvs_nl_send_message(msg, ipvs_timeout_parse_cb, u) == 0))
return u;
diff --git a/libipvs/libipvs.h b/libipvs/libipvs.h
index 15b7d5d..265f681 100644
--- a/libipvs/libipvs.h
+++ b/libipvs/libipvs.h
@@ -33,14 +33,100 @@
*/
#define IPVS_SVC_PERSISTENT_TIMEOUT (6*60)
-
-typedef struct ip_vs_service_user ipvs_service_t;
-typedef struct ip_vs_dest_user ipvs_dest_t;
+union nf_inet_addr {
+ __u32 all[4];
+ __be32 ip;
+ __be32 ip6[4];
+ struct in_addr in;
+ struct in6_addr in6;
+};
+
+typedef struct {
+ /* which service: user fills in these */
+ u_int16_t protocol;
+ __be32 __addr_v4; /* virtual ip address - internal use only */
+ __be16 port;
+ u_int32_t fwmark; /* firwall mark of service */
+
+ /* service options */
+ char sched_name[IP_VS_SCHEDNAME_MAXLEN];
+ unsigned flags; /* virtual service flags */
+ unsigned timeout; /* persistent timeout */
+ __be32 netmask; /* persistent netmask */
+
+ /* number of real servers */
+ unsigned int num_dests;
+
+ /* statistics */
+ struct ip_vs_stats_user stats;
+
+ u_int16_t af;
+ union nf_inet_addr addr;
+} ipvs_service_entry_t;
+
+typedef struct {
+ /* virtual service addresses */
+ u_int16_t protocol;
+ __be32 __addr_v4; /* virtual ip address - internal use only */
+ __be16 port;
+ u_int32_t fwmark; /* firwall mark of service */
+
+ /* virtual service options */
+ char sched_name[IP_VS_SCHEDNAME_MAXLEN];
+ unsigned flags; /* virtual service flags */
+ unsigned timeout; /* persistent timeout in sec */
+ __be32 netmask; /* persistent netmask */
+
+ u_int16_t af;
+ union nf_inet_addr addr;
+} ipvs_service_t;
+
+typedef struct {
+ /* destination server address */
+ __be32 __addr_v4; /* internal use only */
+ __be16 port;
+
+ /* real server options */
+ unsigned conn_flags; /* connection flags */
+ int weight; /* destination weight */
+
+ /* thresholds for active connections */
+ u_int32_t u_threshold; /* upper threshold */
+ u_int32_t l_threshold; /* lower threshold */
+
+ u_int16_t af;
+ union nf_inet_addr addr;
+} ipvs_dest_t;
+
+typedef struct {
+ __be32 __addr_v4; /* destination address - internal use only */
+ __be16 port;
+ unsigned conn_flags; /* connection flags */
+ int weight; /* destination weight */
+
+ u_int32_t u_threshold; /* upper threshold */
+ u_int32_t l_threshold; /* lower threshold */
+
+ u_int32_t activeconns; /* active connections */
+ u_int32_t inactconns; /* inactive connections */
+ u_int32_t persistconns; /* persistent connections */
+
+ /* statistics */
+ struct ip_vs_stats_user stats;
+
+ u_int16_t af;
+ union nf_inet_addr addr;
+} ipvs_dest_entry_t;
+
+
+
+
+//typedef struct ip_vs_service_user ipvs_service_t;
+//typedef struct ip_vs_dest_user ipvs_dest_t;
typedef struct ip_vs_timeout_user ipvs_timeout_t;
typedef struct ip_vs_daemon_user ipvs_daemon_t;
-typedef struct ip_vs_service_entry ipvs_service_entry_t;
-typedef struct ip_vs_dest_entry ipvs_dest_entry_t;
-
+//typedef struct ip_vs_service_entry ipvs_service_entry_t;
+//typedef struct ip_vs_dest_entry ipvs_dest_entry_t;
/* ipvs info variable */
extern struct ip_vs_getinfo ipvs_info;