2006-06-26 00:48:02 +00:00
|
|
|
/*
|
|
|
|
* AppSession functions.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2006 Alexander Lazic, Klaus Wagner
|
2007-05-13 19:29:55 +00:00
|
|
|
* Copyright 2006-2007 Willy Tarreau
|
2006-06-26 00:48:02 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2006-06-29 15:53:05 +00:00
|
|
|
#include <string.h>
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2006-06-29 15:53:05 +00:00
|
|
|
#include <common/appsession.h>
|
2006-06-29 16:54:54 +00:00
|
|
|
#include <common/config.h>
|
2007-05-13 19:29:55 +00:00
|
|
|
#include <common/memory.h>
|
2007-09-09 19:56:53 +00:00
|
|
|
#include <common/sessionhash.h>
|
2008-07-06 22:09:58 +00:00
|
|
|
#include <common/ticks.h>
|
2006-06-29 15:53:05 +00:00
|
|
|
#include <common/time.h>
|
2006-06-26 00:48:02 +00:00
|
|
|
|
|
|
|
#include <types/buffers.h>
|
|
|
|
#include <types/global.h>
|
|
|
|
#include <types/proxy.h>
|
|
|
|
#include <types/server.h>
|
|
|
|
|
|
|
|
#include <proto/task.h>
|
|
|
|
|
[MEDIUM] Fix memory freeing at exit
New functions implemented:
- deinit_pollers: called at the end of deinit())
- prune_acl: called via list_for_each_entry_safe
Add missing pool_destroy2 calls:
- p->hdr_idx_pool
- pool2_tree64
Implement all task stopping:
- health-check: needs new "struct task" in the struct server
- queue processing: queue_mgt
- appsess_refresh: appsession_refresh
before (idle system):
==6079== LEAK SUMMARY:
==6079== definitely lost: 1,112 bytes in 75 blocks.
==6079== indirectly lost: 53,356 bytes in 2,090 blocks.
==6079== possibly lost: 52 bytes in 1 blocks.
==6079== still reachable: 150,996 bytes in 504 blocks.
==6079== suppressed: 0 bytes in 0 blocks.
after (idle system):
==6945== LEAK SUMMARY:
==6945== definitely lost: 7,644 bytes in 137 blocks.
==6945== indirectly lost: 9,913 bytes in 587 blocks.
==6945== possibly lost: 0 bytes in 0 blocks.
==6945== still reachable: 0 bytes in 0 blocks.
==6945== suppressed: 0 bytes in 0 blocks.
before (running system for ~2m):
==9343== LEAK SUMMARY:
==9343== definitely lost: 1,112 bytes in 75 blocks.
==9343== indirectly lost: 54,199 bytes in 2,122 blocks.
==9343== possibly lost: 52 bytes in 1 blocks.
==9343== still reachable: 151,128 bytes in 509 blocks.
==9343== suppressed: 0 bytes in 0 blocks.
after (running system for ~2m):
==11616== LEAK SUMMARY:
==11616== definitely lost: 7,644 bytes in 137 blocks.
==11616== indirectly lost: 9,981 bytes in 591 blocks.
==11616== possibly lost: 0 bytes in 0 blocks.
==11616== still reachable: 4 bytes in 1 blocks.
==11616== suppressed: 0 bytes in 0 blocks.
Still not perfect but significant improvement.
2008-05-29 21:53:44 +00:00
|
|
|
static struct task *appsess_refresh = NULL;
|
2007-05-13 19:29:55 +00:00
|
|
|
struct pool_head *pool2_appsess;
|
2006-06-26 00:48:02 +00:00
|
|
|
struct app_pool apools;
|
|
|
|
int have_appsession;
|
|
|
|
|
|
|
|
int appsession_init(void)
|
|
|
|
{
|
|
|
|
static int initialized = 0;
|
|
|
|
int idlen;
|
|
|
|
struct server *s;
|
|
|
|
struct proxy *p = proxy;
|
|
|
|
|
|
|
|
if (!initialized) {
|
2007-05-13 19:29:55 +00:00
|
|
|
pool2_appsess = create_pool("appsess", sizeof(appsess), MEM_F_SHARED);
|
|
|
|
if (pool2_appsess == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
if (!appsession_task_init()) {
|
2007-05-13 19:29:55 +00:00
|
|
|
int ser_msize, ses_msize;
|
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
apools.sessid = NULL;
|
|
|
|
apools.serverid = NULL;
|
2007-05-13 19:29:55 +00:00
|
|
|
|
|
|
|
ser_msize = sizeof(void *);
|
|
|
|
ses_msize = sizeof(void *);
|
2006-06-26 00:48:02 +00:00
|
|
|
while (p) {
|
|
|
|
s = p->srv;
|
2007-05-13 19:29:55 +00:00
|
|
|
if (ses_msize < p->appsession_len)
|
|
|
|
ses_msize = p->appsession_len;
|
2006-06-26 00:48:02 +00:00
|
|
|
while (s) {
|
|
|
|
idlen = strlen(s->id);
|
2007-05-13 19:29:55 +00:00
|
|
|
if (ser_msize < idlen)
|
|
|
|
ser_msize = idlen;
|
2006-06-26 00:48:02 +00:00
|
|
|
s = s->next;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
/* we use strings, so reserve space for '\0' */
|
2007-05-13 19:29:55 +00:00
|
|
|
ser_msize ++;
|
|
|
|
ses_msize ++;
|
|
|
|
|
|
|
|
apools.sessid = create_pool("sessid", ses_msize, MEM_F_SHARED);
|
|
|
|
if (!apools.sessid)
|
|
|
|
return -1;
|
|
|
|
apools.serverid = create_pool("serverid", ser_msize, MEM_F_SHARED);
|
|
|
|
if (!apools.serverid)
|
|
|
|
return -1;
|
2006-06-26 00:48:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "appsession_task_init failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
initialized ++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int appsession_task_init(void)
|
|
|
|
{
|
|
|
|
static int initialized = 0;
|
|
|
|
if (!initialized) {
|
[MEDIUM] Fix memory freeing at exit
New functions implemented:
- deinit_pollers: called at the end of deinit())
- prune_acl: called via list_for_each_entry_safe
Add missing pool_destroy2 calls:
- p->hdr_idx_pool
- pool2_tree64
Implement all task stopping:
- health-check: needs new "struct task" in the struct server
- queue processing: queue_mgt
- appsess_refresh: appsession_refresh
before (idle system):
==6079== LEAK SUMMARY:
==6079== definitely lost: 1,112 bytes in 75 blocks.
==6079== indirectly lost: 53,356 bytes in 2,090 blocks.
==6079== possibly lost: 52 bytes in 1 blocks.
==6079== still reachable: 150,996 bytes in 504 blocks.
==6079== suppressed: 0 bytes in 0 blocks.
after (idle system):
==6945== LEAK SUMMARY:
==6945== definitely lost: 7,644 bytes in 137 blocks.
==6945== indirectly lost: 9,913 bytes in 587 blocks.
==6945== possibly lost: 0 bytes in 0 blocks.
==6945== still reachable: 0 bytes in 0 blocks.
==6945== suppressed: 0 bytes in 0 blocks.
before (running system for ~2m):
==9343== LEAK SUMMARY:
==9343== definitely lost: 1,112 bytes in 75 blocks.
==9343== indirectly lost: 54,199 bytes in 2,122 blocks.
==9343== possibly lost: 52 bytes in 1 blocks.
==9343== still reachable: 151,128 bytes in 509 blocks.
==9343== suppressed: 0 bytes in 0 blocks.
after (running system for ~2m):
==11616== LEAK SUMMARY:
==11616== definitely lost: 7,644 bytes in 137 blocks.
==11616== indirectly lost: 9,981 bytes in 591 blocks.
==11616== possibly lost: 0 bytes in 0 blocks.
==11616== still reachable: 4 bytes in 1 blocks.
==11616== suppressed: 0 bytes in 0 blocks.
Still not perfect but significant improvement.
2008-05-29 21:53:44 +00:00
|
|
|
if ((appsess_refresh = pool_alloc2(pool2_task)) == NULL)
|
2006-06-26 00:48:02 +00:00
|
|
|
return -1;
|
[MEDIUM] Fix memory freeing at exit
New functions implemented:
- deinit_pollers: called at the end of deinit())
- prune_acl: called via list_for_each_entry_safe
Add missing pool_destroy2 calls:
- p->hdr_idx_pool
- pool2_tree64
Implement all task stopping:
- health-check: needs new "struct task" in the struct server
- queue processing: queue_mgt
- appsess_refresh: appsession_refresh
before (idle system):
==6079== LEAK SUMMARY:
==6079== definitely lost: 1,112 bytes in 75 blocks.
==6079== indirectly lost: 53,356 bytes in 2,090 blocks.
==6079== possibly lost: 52 bytes in 1 blocks.
==6079== still reachable: 150,996 bytes in 504 blocks.
==6079== suppressed: 0 bytes in 0 blocks.
after (idle system):
==6945== LEAK SUMMARY:
==6945== definitely lost: 7,644 bytes in 137 blocks.
==6945== indirectly lost: 9,913 bytes in 587 blocks.
==6945== possibly lost: 0 bytes in 0 blocks.
==6945== still reachable: 0 bytes in 0 blocks.
==6945== suppressed: 0 bytes in 0 blocks.
before (running system for ~2m):
==9343== LEAK SUMMARY:
==9343== definitely lost: 1,112 bytes in 75 blocks.
==9343== indirectly lost: 54,199 bytes in 2,122 blocks.
==9343== possibly lost: 52 bytes in 1 blocks.
==9343== still reachable: 151,128 bytes in 509 blocks.
==9343== suppressed: 0 bytes in 0 blocks.
after (running system for ~2m):
==11616== LEAK SUMMARY:
==11616== definitely lost: 7,644 bytes in 137 blocks.
==11616== indirectly lost: 9,981 bytes in 591 blocks.
==11616== possibly lost: 0 bytes in 0 blocks.
==11616== still reachable: 4 bytes in 1 blocks.
==11616== suppressed: 0 bytes in 0 blocks.
Still not perfect but significant improvement.
2008-05-29 21:53:44 +00:00
|
|
|
|
2008-06-24 06:17:16 +00:00
|
|
|
task_init(appsess_refresh);
|
[MEDIUM] Fix memory freeing at exit
New functions implemented:
- deinit_pollers: called at the end of deinit())
- prune_acl: called via list_for_each_entry_safe
Add missing pool_destroy2 calls:
- p->hdr_idx_pool
- pool2_tree64
Implement all task stopping:
- health-check: needs new "struct task" in the struct server
- queue processing: queue_mgt
- appsess_refresh: appsession_refresh
before (idle system):
==6079== LEAK SUMMARY:
==6079== definitely lost: 1,112 bytes in 75 blocks.
==6079== indirectly lost: 53,356 bytes in 2,090 blocks.
==6079== possibly lost: 52 bytes in 1 blocks.
==6079== still reachable: 150,996 bytes in 504 blocks.
==6079== suppressed: 0 bytes in 0 blocks.
after (idle system):
==6945== LEAK SUMMARY:
==6945== definitely lost: 7,644 bytes in 137 blocks.
==6945== indirectly lost: 9,913 bytes in 587 blocks.
==6945== possibly lost: 0 bytes in 0 blocks.
==6945== still reachable: 0 bytes in 0 blocks.
==6945== suppressed: 0 bytes in 0 blocks.
before (running system for ~2m):
==9343== LEAK SUMMARY:
==9343== definitely lost: 1,112 bytes in 75 blocks.
==9343== indirectly lost: 54,199 bytes in 2,122 blocks.
==9343== possibly lost: 52 bytes in 1 blocks.
==9343== still reachable: 151,128 bytes in 509 blocks.
==9343== suppressed: 0 bytes in 0 blocks.
after (running system for ~2m):
==11616== LEAK SUMMARY:
==11616== definitely lost: 7,644 bytes in 137 blocks.
==11616== indirectly lost: 9,981 bytes in 591 blocks.
==11616== possibly lost: 0 bytes in 0 blocks.
==11616== still reachable: 4 bytes in 1 blocks.
==11616== suppressed: 0 bytes in 0 blocks.
Still not perfect but significant improvement.
2008-05-29 21:53:44 +00:00
|
|
|
appsess_refresh->context = NULL;
|
2008-07-06 22:09:58 +00:00
|
|
|
appsess_refresh->expire = tick_add(now_ms, MS_TO_TICKS(TBLCHKINT));
|
[MEDIUM] Fix memory freeing at exit
New functions implemented:
- deinit_pollers: called at the end of deinit())
- prune_acl: called via list_for_each_entry_safe
Add missing pool_destroy2 calls:
- p->hdr_idx_pool
- pool2_tree64
Implement all task stopping:
- health-check: needs new "struct task" in the struct server
- queue processing: queue_mgt
- appsess_refresh: appsession_refresh
before (idle system):
==6079== LEAK SUMMARY:
==6079== definitely lost: 1,112 bytes in 75 blocks.
==6079== indirectly lost: 53,356 bytes in 2,090 blocks.
==6079== possibly lost: 52 bytes in 1 blocks.
==6079== still reachable: 150,996 bytes in 504 blocks.
==6079== suppressed: 0 bytes in 0 blocks.
after (idle system):
==6945== LEAK SUMMARY:
==6945== definitely lost: 7,644 bytes in 137 blocks.
==6945== indirectly lost: 9,913 bytes in 587 blocks.
==6945== possibly lost: 0 bytes in 0 blocks.
==6945== still reachable: 0 bytes in 0 blocks.
==6945== suppressed: 0 bytes in 0 blocks.
before (running system for ~2m):
==9343== LEAK SUMMARY:
==9343== definitely lost: 1,112 bytes in 75 blocks.
==9343== indirectly lost: 54,199 bytes in 2,122 blocks.
==9343== possibly lost: 52 bytes in 1 blocks.
==9343== still reachable: 151,128 bytes in 509 blocks.
==9343== suppressed: 0 bytes in 0 blocks.
after (running system for ~2m):
==11616== LEAK SUMMARY:
==11616== definitely lost: 7,644 bytes in 137 blocks.
==11616== indirectly lost: 9,981 bytes in 591 blocks.
==11616== possibly lost: 0 bytes in 0 blocks.
==11616== still reachable: 4 bytes in 1 blocks.
==11616== suppressed: 0 bytes in 0 blocks.
Still not perfect but significant improvement.
2008-05-29 21:53:44 +00:00
|
|
|
appsess_refresh->process = appsession_refresh;
|
|
|
|
task_queue(appsess_refresh);
|
2006-06-26 00:48:02 +00:00
|
|
|
initialized ++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-06 22:09:58 +00:00
|
|
|
void appsession_refresh(struct task *t, int *next)
|
2006-06-26 00:48:02 +00:00
|
|
|
{
|
2007-09-09 19:56:53 +00:00
|
|
|
struct proxy *p = proxy;
|
|
|
|
struct appsession_hash *htbl;
|
|
|
|
appsess *element, *back;
|
|
|
|
int i;
|
2006-06-26 00:48:02 +00:00
|
|
|
|
|
|
|
while (p) {
|
|
|
|
if (p->appsession_name != NULL) {
|
|
|
|
htbl = &p->htbl_proxy;
|
2007-09-09 19:56:53 +00:00
|
|
|
as_hash_for_each_entry_safe(i, element, back, &p->htbl_proxy, hash_list) {
|
2008-07-06 22:09:58 +00:00
|
|
|
if (tick_is_expired(element->expire, now_ms)) {
|
2007-09-09 19:56:53 +00:00
|
|
|
if ((global.mode & MODE_DEBUG) &&
|
|
|
|
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
|
|
|
|
int len;
|
|
|
|
/*
|
|
|
|
on Linux NULL pointers are caught by sprintf, on solaris -> segfault
|
|
|
|
*/
|
|
|
|
len = sprintf(trash, "appsession_refresh: cleaning up expired Session '%s' on Server %s\n",
|
|
|
|
element->sessid, element->serverid?element->serverid:"(null)");
|
|
|
|
write(1, trash, len);
|
|
|
|
}
|
|
|
|
/* delete the expired element from within the hash table */
|
|
|
|
LIST_DEL(&element->hash_list);
|
|
|
|
htbl->destroy(element);
|
|
|
|
}/* end if (tv_isle(&asession->expire, &now)) */
|
2006-06-26 00:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
2008-07-06 22:09:58 +00:00
|
|
|
t->expire = tick_add(now_ms, MS_TO_TICKS(TBLCHKINT)); /* check expiration every 5 seconds */
|
2007-05-13 19:29:55 +00:00
|
|
|
task_queue(t);
|
2007-05-12 20:35:00 +00:00
|
|
|
*next = t->expire;
|
2006-06-26 00:48:02 +00:00
|
|
|
} /* end appsession_refresh */
|
|
|
|
|
|
|
|
int match_str(const void *key1, const void *key2)
|
|
|
|
{
|
|
|
|
appsess *temp1,*temp2;
|
|
|
|
temp1 = (appsess *)key1;
|
|
|
|
temp2 = (appsess *)key2;
|
|
|
|
|
|
|
|
//fprintf(stdout,">>>>>>>>>>>>>>temp1->sessid :%s:\n",temp1->sessid);
|
|
|
|
//fprintf(stdout,">>>>>>>>>>>>>>temp2->sessid :%s:\n",temp2->sessid);
|
|
|
|
|
|
|
|
return (strcmp(temp1->sessid,temp2->sessid) == 0);
|
|
|
|
}/* end match_str */
|
|
|
|
|
2007-09-09 19:56:53 +00:00
|
|
|
void destroy(appsess *temp1) {
|
2006-06-26 00:48:02 +00:00
|
|
|
if (temp1->sessid)
|
2007-05-13 19:29:55 +00:00
|
|
|
pool_free2(apools.sessid, temp1->sessid);
|
2006-06-26 00:48:02 +00:00
|
|
|
|
|
|
|
if (temp1->serverid)
|
2007-05-13 19:29:55 +00:00
|
|
|
pool_free2(apools.serverid, temp1->serverid);
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2007-05-13 19:29:55 +00:00
|
|
|
pool_free2(pool2_appsess, temp1);
|
2006-06-26 00:48:02 +00:00
|
|
|
} /* end destroy */
|
|
|
|
|
|
|
|
void appsession_cleanup( void )
|
|
|
|
{
|
|
|
|
struct proxy *p = proxy;
|
|
|
|
|
|
|
|
while(p) {
|
2007-09-09 19:56:53 +00:00
|
|
|
appsession_hash_destroy(&(p->htbl_proxy));
|
2006-06-26 00:48:02 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
[MEDIUM] Fix memory freeing at exit
New functions implemented:
- deinit_pollers: called at the end of deinit())
- prune_acl: called via list_for_each_entry_safe
Add missing pool_destroy2 calls:
- p->hdr_idx_pool
- pool2_tree64
Implement all task stopping:
- health-check: needs new "struct task" in the struct server
- queue processing: queue_mgt
- appsess_refresh: appsession_refresh
before (idle system):
==6079== LEAK SUMMARY:
==6079== definitely lost: 1,112 bytes in 75 blocks.
==6079== indirectly lost: 53,356 bytes in 2,090 blocks.
==6079== possibly lost: 52 bytes in 1 blocks.
==6079== still reachable: 150,996 bytes in 504 blocks.
==6079== suppressed: 0 bytes in 0 blocks.
after (idle system):
==6945== LEAK SUMMARY:
==6945== definitely lost: 7,644 bytes in 137 blocks.
==6945== indirectly lost: 9,913 bytes in 587 blocks.
==6945== possibly lost: 0 bytes in 0 blocks.
==6945== still reachable: 0 bytes in 0 blocks.
==6945== suppressed: 0 bytes in 0 blocks.
before (running system for ~2m):
==9343== LEAK SUMMARY:
==9343== definitely lost: 1,112 bytes in 75 blocks.
==9343== indirectly lost: 54,199 bytes in 2,122 blocks.
==9343== possibly lost: 52 bytes in 1 blocks.
==9343== still reachable: 151,128 bytes in 509 blocks.
==9343== suppressed: 0 bytes in 0 blocks.
after (running system for ~2m):
==11616== LEAK SUMMARY:
==11616== definitely lost: 7,644 bytes in 137 blocks.
==11616== indirectly lost: 9,981 bytes in 591 blocks.
==11616== possibly lost: 0 bytes in 0 blocks.
==11616== still reachable: 4 bytes in 1 blocks.
==11616== suppressed: 0 bytes in 0 blocks.
Still not perfect but significant improvement.
2008-05-29 21:53:44 +00:00
|
|
|
|
|
|
|
if (appsess_refresh) {
|
|
|
|
task_delete(appsess_refresh);
|
|
|
|
task_free(appsess_refresh);
|
|
|
|
appsess_refresh = NULL;
|
|
|
|
}
|
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
}/* end appsession_cleanup() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-indent-level: 8
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|