2011-07-22 10:43:40 +00:00
|
|
|
// (c) 2011 Thomas Schoebel-Theuer / 1&1 Internet AG
|
|
|
|
|
|
|
|
//#define BRICK_DEBUGGING
|
|
|
|
//#define MARS_DEBUGGING
|
|
|
|
//#define IO_DEBUGGING
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
|
|
|
#include "strategy.h"
|
|
|
|
#include "../mars_net.h"
|
|
|
|
|
|
|
|
static
|
|
|
|
char *_mars_translate_hostname(const char *name)
|
|
|
|
{
|
|
|
|
struct mars_global *global = mars_global;
|
|
|
|
const char *res = name;
|
|
|
|
struct mars_dent *test;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (unlikely(!global)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
tmp = path_make("/mars/ips/ip-%s", name);
|
|
|
|
if (unlikely(!tmp)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
test = mars_find_dent(global, tmp);
|
|
|
|
if (test && test->new_link) {
|
|
|
|
MARS_DBG("'%s' => '%s'\n", tmp, test->new_link);
|
|
|
|
res = test->new_link;
|
|
|
|
}
|
2011-08-12 11:09:48 +00:00
|
|
|
brick_string_free(tmp);
|
2011-07-22 10:43:40 +00:00
|
|
|
|
|
|
|
done:
|
2011-08-12 11:09:48 +00:00
|
|
|
return brick_strdup(res);
|
2011-07-22 10:43:40 +00:00
|
|
|
}
|
|
|
|
|
2011-08-31 11:42:04 +00:00
|
|
|
int mars_send_dent_list(struct mars_socket *sock, struct list_head *anchor)
|
2011-07-22 10:43:40 +00:00
|
|
|
{
|
|
|
|
struct list_head *tmp;
|
|
|
|
struct mars_dent *dent;
|
|
|
|
int status = 0;
|
|
|
|
for (tmp = anchor->next; tmp != anchor; tmp = tmp->next) {
|
|
|
|
dent = container_of(tmp, struct mars_dent, dent_link);
|
|
|
|
status = mars_send_struct(sock, dent, mars_dent_meta);
|
|
|
|
if (status < 0)
|
|
|
|
break;
|
|
|
|
}
|
2011-08-31 11:42:04 +00:00
|
|
|
if (status >= 0) { // send EOR
|
2011-07-22 10:43:40 +00:00
|
|
|
status = mars_send_struct(sock, NULL, mars_dent_meta);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mars_send_dent_list);
|
|
|
|
|
2011-08-31 11:42:04 +00:00
|
|
|
int mars_recv_dent_list(struct mars_socket *sock, struct list_head *anchor)
|
2011-07-22 10:43:40 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
for (;;) {
|
2011-08-12 11:09:48 +00:00
|
|
|
struct mars_dent *dent = brick_zmem_alloc(sizeof(struct mars_dent));
|
2011-07-22 10:43:40 +00:00
|
|
|
if (!dent)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
//MARS_IO("\n");
|
|
|
|
|
|
|
|
status = mars_recv_struct(sock, dent, mars_dent_meta);
|
|
|
|
if (status <= 0) {
|
2011-08-12 11:09:48 +00:00
|
|
|
brick_mem_free(dent);
|
2011-07-22 10:43:40 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
list_add_tail(&dent->dent_link, anchor);
|
|
|
|
INIT_LIST_HEAD(&dent->brick_list);
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mars_recv_dent_list);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////// module init stuff /////////////////////////
|
|
|
|
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
int __init init_sy_net(void)
|
2011-07-22 10:43:40 +00:00
|
|
|
{
|
|
|
|
MARS_INF("init_sy_net()\n");
|
|
|
|
mars_translate_hostname = _mars_translate_hostname;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
void __exit exit_sy_net(void)
|
2011-07-22 10:43:40 +00:00
|
|
|
{
|
|
|
|
MARS_INF("exit_sy_net()\n");
|
|
|
|
}
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
#ifndef CONFIG_MARS_HAVE_BIGMODULE
|
2011-07-22 10:43:40 +00:00
|
|
|
MODULE_DESCRIPTION("MARS network infrastructure");
|
|
|
|
MODULE_AUTHOR("Thomas Schoebel-Theuer <tst@1und1.de>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
module_init(init_sy_net);
|
|
|
|
module_exit(exit_sy_net);
|
|
|
|
#endif
|