OSDN Git Service

Update INSTALL.ja.utf-8 for new release.
[ultramonkey-l7/ultramonkey-l7-v2.git] / src / dest.c
1 /*
2  * @file  dest.c
3  * @brief the realserver information management component 
4  * @brief it operates realserver infomation struct
5  *
6  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
7  * Copyright (C) 2005  NTT COMWARE Corporation.
8  *
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.
13  *
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.
18  *
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
22  * 02110-1301 USA
23  *
24  **********************************************************************/
25
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>
31 #include <unistd.h>
32 #include <stdlib.h>
33 #include "logger_wrapper.h"
34 #include "l7vs_dest.h"
35
36 /*!
37  * create struct dest
38  * @param[in]   *addr     sockaddr_in
39  * @param[in]   weight    source int
40  * @return      struct l7vs_dest *
41  */
42 struct l7vs_dest *
43 l7vs_dest_create(struct sockaddr_in *addr, int weight)
44 {
45         char dest_str[DEBUG_STR_LEN] = {0};
46         struct l7vs_dest *dest;
47         char addr_str[DEBUG_STR_LEN] = {0};
48
49
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)"
54                         "addr = %s"
55                         "weight = %d",
56                         addr_str,weight);
57         }
58
59         dest = (struct l7vs_dest *)malloc(sizeof(*dest));
60         if (dest == NULL) {
61                 LOGGER_PUT_LOG_ERROR(LOG_CAT_L7VSD_SYSTEM_MEMORY,7,"dest create : Could not allocate memory");
62                 return dest;
63         }
64
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",
69                         sizeof(*dest),dest);
70         }
71
72         dest->addr = *addr;
73         dest->weight = weight;
74         dest->nactive = dest->ninact = 0;
75
76         l7vs_dest_c_str(dest_str, dest);
77         LOGGER_PUT_LOG_INFO(LOG_CAT_L7VSD_REAL_SERVER,3,"RealServer Information: %s",dest_str);
78
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",
83                         dest_str);
84         }
85
86
87 #if 0
88         mss = l7vs_dest_get_mss(addr);
89         if (mss < 0) {
90                 free(dest);
91                 return NULL;
92         }
93         dest->mss = mss;
94 #endif
95         
96
97         return dest;
98 }
99
100 /*!
101  * destroy struct dest
102  * @param[in]   *dest   l7vs_dest
103  * @return      void
104  */
105 void
106 l7vs_dest_destroy(struct l7vs_dest *dest)
107 {
108         char dest_str[DEBUG_STR_LEN] = {0};
109
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)"
114                         "dest = %s",
115                         dest_str);
116         }
117
118         l7vs_dest_c_str(dest_str, dest);
119         LOGGER_PUT_LOG_INFO(LOG_CAT_L7VSD_REAL_SERVER,4,"RealServer Information: %s",dest_str);
120
121         free(dest);
122         dest = NULL;
123 }
124
125 /*!
126  * create struct l7vs_dest_arg
127  * @param[in]   *dest  l7vs_dest
128  * @param[in]   *darg  l7vs_dest_arg
129  * @return      void
130  */
131 void
132 l7vs_dest_to_arg(struct l7vs_dest *dest, struct l7vs_dest_arg *darg)
133 {
134         if(darg != NULL && dest != NULL)
135         {
136                 darg->addr = dest->addr;
137                 darg->weight = dest->weight;
138                 darg->nactive = dest->nactive;
139                 darg->ninact = dest->ninact;
140         }
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)"
148                         "dest=%s: "
149                         "darg=%s",
150                         dest_str,darg_str);
151         }
152 }
153