src/backend.c
int tcp_persist_rdp_cookie(struct session *s, struct channel *req, int an_bit)
{
	struct proxy    *px   = s->be;
	int              ret;
	struct sample    smp;
	struct server *srv = px->srv;
	struct sockaddr_in addr;
	char *p;
	struct arg       args[2];

	DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
		now_ms, __FUNCTION__,
		s,
		req,
		req->rex, req->wex,
		req->flags,
		req->buf->i,
		req->analysers);

	if (s->flags & SN_ASSIGNED)
		goto no_cookie;

	memset(&smp, 0, sizeof(smp));

	args[0].type = ARGT_STR;
	args[0].data.str.str = s->be->rdp_cookie_name;
	args[0].data.str.len = s->be->rdp_cookie_len;
	args[1].type = ARGT_STOP;

	ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp);
	if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || smp.data.str.len == 0)
		goto no_cookie;

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;

	/* Considering an rdp cookie detected using acl, str ended with <cr><lf> and should return */
	addr.sin_addr.s_addr = strtoul(smp.data.str.str, &p, 10);
	if (*p != '.')
		goto no_cookie;
	p++;
	addr.sin_port = (unsigned short)strtoul(p, &p, 10);
	if (*p != '.')
		goto no_cookie;

	s->target = NULL;
	while (srv) {
		if (memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) {
			if ((srv->state & SRV_RUNNING) || (px->options & PR_O_PERSIST)) {
				/* we found the server and it is usable */
				s->flags |= SN_DIRECT | SN_ASSIGNED;
				s->target = &srv->obj_type;
				break;
			}
		}
		srv = srv->next;
	}

no_cookie:
	req->analysers &= ~an_bit;
	req->analyse_exp = TICK_ETERNITY;
	return 1;
}
/* Apply RDP cookie persistence to the current session. For this, the function
 * tries to extract an RDP cookie from the request buffer, and look for the
 * matching server in the list. If the server is found, it is assigned to the
 * session. This always returns 1, and the analyser removes itself from the
 * list. Nothing is performed if a server was already assigned.
 */
Apply RDP cookie persistence to the current session. For this, the function
tries to extract an RDP cookie from the request buffer, and look for the
matching server in the list. If the server is found, it is assigned to the
session. This always returns 1, and the analyser removes itself from the
list. Nothing is performed if a server was already assigned.
Apply RDP cookie persistence to the current session . For this the function tries to extract an RDP cookie from the request buffer and look for the matching server in the list . If the server is found it is assigned to the session . This always returns 1 and the analyser removes itself from the list . Nothing is performed if a server was already assigned .
int tcp_persist_rdp_cookie(struct session *s, struct channel *req, int an_bit)
{
	struct proxy    *px   = s->be;
	int              ret;
	struct sample    smp;
	struct server *srv = px->srv;
	struct sockaddr_in addr;
	char *p;
	struct arg       args[2];
	DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
		now_ms, __FUNCTION__,
		s,
		req,
		req->rex, req->wex,
		req->flags,
		req->buf->i,
		req->analysers);
	if (s->flags & SN_ASSIGNED)
		goto no_cookie;
	memset(&smp, 0, sizeof(smp));
	args[0].type = ARGT_STR;
	args[0].data.str.str = s->be->rdp_cookie_name;
	args[0].data.str.len = s->be->rdp_cookie_len;
	args[1].type = ARGT_STOP;
	ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp);
	if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || smp.data.str.len == 0)
		goto no_cookie;
	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = strtoul(smp.data.str.str, &p, 10);
	if (*p != '.')
		goto no_cookie;
	p++;
	addr.sin_port = (unsigned short)strtoul(p, &p, 10);
	if (*p != '.')
		goto no_cookie;
	s->target = NULL;
	while (srv) {
		if (memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) {
			if ((srv->state & SRV_RUNNING) || (px->options & PR_O_PERSIST)) {
				s->flags |= SN_DIRECT | SN_ASSIGNED;
				s->target = &srv->obj_type;
				break;
			}
		}
		srv = srv->next;
	}
no_cookie:
	req->analysers &= ~an_bit;
	req->analyse_exp = TICK_ETERNITY;
	return 1;
}
int tcp_persist_rdp_cookie ( struct session * s , struct channel * req , int an_bit ) { struct proxy * px = s -> be ; int ret ; struct sample smp ; struct server * srv = px -> srv ; struct sockaddr_in addr ; char * p ; struct arg args [ 2 ] ; DPRINTF ( stderr , " \n " , now_ms , __FUNCTION__ , s , req , req -> rex , req -> wex , req -> flags , req -> buf -> i , req -> analysers ) ; if ( s -> flags & SN_ASSIGNED ) goto no_cookie ; memset ( & smp , 0 , sizeof ( smp ) ) ; args [ 0 ] . type = ARGT_STR ; args [ 0 ] . data . str . str = s -> be -> rdp_cookie_name ; args [ 0 ] . data . str . len = s -> be -> rdp_cookie_len ; args [ 1 ] . type = ARGT_STOP ; ret = smp_fetch_rdp_cookie ( px , s , NULL , SMP_OPT_DIR_REQ | SMP_OPT_FINAL , args , & smp ) ; if ( ret == 0 || ( smp . flags & SMP_F_MAY_CHANGE ) || smp . data . str . len == 0 ) goto no_cookie ; memset ( & addr , 0 , sizeof ( addr ) ) ; addr . sin_family = AF_INET ; addr . sin_addr . s_addr = strtoul ( smp . data . str . str , & p , 10 ) ; if ( * p != ' ' ) goto no_cookie ; p ++ ; addr . sin_port = ( unsigned short ) strtoul ( p , & p , 10 ) ; if ( * p != ' ' ) goto no_cookie ; s -> target = NULL ; while ( srv ) { if ( memcmp ( & addr , & ( srv -> addr ) , sizeof ( addr ) ) == 0 ) { if ( ( srv -> state & SRV_RUNNING ) || ( px -> options & PR_O_PERSIST ) ) { s -> flags |= SN_DIRECT | SN_ASSIGNED ; s -> target = & srv -> obj_type ; break ; } } srv = srv -> next ; } no_cookie : req -> analysers &= ~ an_bit ; req -> analyse_exp = TICK_ETERNITY ; return 1 ; }
Apply RDP cookie persistence to the current session.
Apply RDP cookie persistence to the current session .
/* Considering an rdp cookie detected using acl, str ended with <cr><lf> and should return */ /* we found the server and it is usable */