Skip to content

Commit

Permalink
add tfw_server_snprint() required by tfw_sched_rr
Browse files Browse the repository at this point in the history
  • Loading branch information
vdmit11 committed Sep 22, 2014
1 parent 809ae2a commit 0deb5db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
26 changes: 19 additions & 7 deletions tempesta_fw/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#include <linux/slab.h>

#include "connection.h"
#include "lib.h"
#include "log.h"
#include "sched.h"
#include "server.h"

static TfwServer *be_srv;
static struct kmem_cache *srv_cache;

void
Expand All @@ -50,8 +50,6 @@ tfw_destroy_server(struct sock *s)

srv->sock = NULL;
conn->hndl = NULL;

be_srv = NULL;

/* FIXME clear the server references from all current sessions. */
#if 0
Expand All @@ -74,13 +72,27 @@ tfw_create_server(struct sock *s)
return NULL;
}

/* TODO Only one back-end server is supported yet. */
BUG_ON(be_srv);
be_srv = srv;

return srv;
}

int tfw_server_snprint(const TfwServer *srv, char *buf, size_t buf_size)
{
TfwAddr addr;
int len = sizeof(addr);
char addr_str_buf[MAX_ADDR_LEN];

BUG_ON(!srv || !buf || !buf_size);

memset(&addr, 0, sizeof(addr));
kernel_getpeername(srv->sock->sk_socket, &addr.addr, &len);
tfw_inet_ntop(&addr, addr_str_buf);

len = snprintf(buf, buf_size, "srv %p: %s", srv, addr_str_buf);

return len;
}
EXPORT_SYMBOL(tfw_server_snprint);

int __init
tfw_server_init(void)
{
Expand Down
4 changes: 4 additions & 0 deletions tempesta_fw/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <net/sock.h>

#define TFW_MAX_SERVER_STR_SIZE 100

typedef struct {
/* The server current stress (overloading) value. */
int stress;
Expand All @@ -32,6 +34,8 @@ typedef struct {
TfwServer *tfw_create_server(struct sock *s);
void tfw_destroy_server(struct sock *s);

int tfw_server_snprint(const TfwServer *srv, char *buf, size_t buf_size);

int tfw_server_init(void);
void tfw_server_exit(void);

Expand Down

0 comments on commit 0deb5db

Please sign in to comment.