3 * @brief the realserver information management component
4 * @brief it operates realserver infomation struct
6 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
7 * Copyright (C) 2005 NTT COMWARE Corporation.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 **********************************************************************/
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <netinet/tcp.h>
30 #include <arpa/inet.h>
33 #include "logger_wrapper.h"
34 #include "l7vs_dest.h"
38 * @param[in] *addr sockaddr_in
39 * @param[in] weight source int
40 * @return struct l7vs_dest *
43 l7vs_dest_create(struct sockaddr_in *addr, int weight)
45 char dest_str[DEBUG_STR_LEN] = {0};
46 struct l7vs_dest *dest;
47 char addr_str[DEBUG_STR_LEN] = {0};
50 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_L7VSD_REAL_SERVER)) {
51 l7vs_dest_sockaddr_in_c_str(addr_str,addr);
52 LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_REAL_SERVER,9,
53 "in_function: struct l7vs_dest * l7vs_dest_create(struct sockaddr_in *addr, int weight)"
59 dest = (struct l7vs_dest *)malloc(sizeof(*dest));
61 LOGGER_PUT_LOG_ERROR(LOG_CAT_L7VSD_SYSTEM_MEMORY,7,"dest create : Could not allocate memory");
65 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_L7VSD_SYSTEM_MEMORY)) {
66 LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_SYSTEM_MEMORY,1,
67 "in_function l7vs_dest_create:allocate memory"
68 " : size=%ld , pointer=%p",
73 dest->weight = weight;
74 dest->nactive = dest->ninact = 0;
76 l7vs_dest_c_str(dest_str, dest);
77 LOGGER_PUT_LOG_INFO(LOG_CAT_L7VSD_REAL_SERVER,3,"RealServer Information: %s",dest_str);
79 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_L7VSD_REAL_SERVER)) {
80 l7vs_dest_c_str(dest_str, dest);
81 LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_REAL_SERVER,10,
82 "pointer_assign: dest=%s",
88 mss = l7vs_dest_get_mss(addr);
101 * destroy struct dest
102 * @param[in] *dest l7vs_dest
106 l7vs_dest_destroy(struct l7vs_dest *dest)
108 char dest_str[DEBUG_STR_LEN] = {0};
110 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_L7VSD_REAL_SERVER)) {
111 l7vs_dest_c_str(dest_str, dest);
112 LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_REAL_SERVER,11,
113 "in_function: void l7vs_dest_create(struct l7vs_dest *dest)"
118 l7vs_dest_c_str(dest_str, dest);
119 LOGGER_PUT_LOG_INFO(LOG_CAT_L7VSD_REAL_SERVER,4,"RealServer Information: %s",dest_str);
126 * create struct l7vs_dest_arg
127 * @param[in] *dest l7vs_dest
128 * @param[in] *darg l7vs_dest_arg
132 l7vs_dest_to_arg(struct l7vs_dest *dest, struct l7vs_dest_arg *darg)
134 if(darg != NULL && dest != NULL)
136 darg->addr = dest->addr;
137 darg->weight = dest->weight;
138 darg->nactive = dest->nactive;
139 darg->ninact = dest->ninact;
141 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_L7VSD_REAL_SERVER)) {
142 char dest_str[DEBUG_STR_LEN] = {0};
143 char darg_str[DEBUG_STR_LEN] = {0};
144 l7vs_dest_c_str(dest_str, dest);
145 l7vs_darg_c_str(darg_str, darg);
146 LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_REAL_SERVER,12,
147 "in_function: void l7vs_dest_to_arg(struct l7vs_dest *dest, struct l7vs_dest_arg *darg)"