资源简介
Linux ebtables for networks
代码片段和文件信息
/*
* communication.c v2.0 July 2002
*
* Author: Bart De Schuymer
*
*/
/*
* All the userspace/kernel communication is in this file.
* The other code should not have to know anything about the way the
* kernel likes the structure of the table data.
* The other code works with linked lists. So the translation is done here.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include “include/ebtables_u.h“
extern char* hooknames[NF_BR_NUMHOOKS];
#ifdef KERNEL_64_USERSPACE_32
#define sparc_cast (uint64_t)
#else
#define sparc_cast
#endif
int sockfd = -1;
static int get_sockfd()
{
int ret = 0;
if (sockfd == -1) {
sockfd = socket(AF_INET SOCK_RAW PF_INET);
if (sockfd < 0) {
ebt_print_error(“Problem getting a socket “
“you probably don‘t have the right “
“permissions“);
ret = -1;
}
}
return ret;
}
static struct ebt_replace *translate_user2kernel(struct ebt_u_replace *u_repl)
{
struct ebt_replace *new;
struct ebt_u_entry *e;
struct ebt_u_match_list *m_l;
struct ebt_u_watcher_list *w_l;
struct ebt_u_entries *entries;
char *p *base;
int i j;
unsigned int entries_size = 0 *chain_offsets;
new = (struct ebt_replace *)malloc(sizeof(struct ebt_replace));
if (!new)
ebt_print_memory();
new->valid_hooks = u_repl->valid_hooks;
strcpy(new->name u_repl->name);
new->nentries = u_repl->nentries;
new->num_counters = u_repl->num_counters;
new->counters = sparc_cast u_repl->counters;
chain_offsets = (unsigned int *)calloc(u_repl->num_chains sizeof(unsigned int));
if (!chain_offsets)
ebt_print_memory();
/* Determine size */
for (i = 0; i < u_repl->num_chains; i++) {
if (!(entries = u_repl->chains[i]))
continue;
chain_offsets[i] = entries_size;
entries_size += sizeof(struct ebt_entries);
j = 0;
e = entries->entries->next;
while (e != entries->entries) {
j++;
entries_size += sizeof(struct ebt_entry);
m_l = e->m_list;
while (m_l) {
entries_size += m_l->m->match_size +
sizeof(struct ebt_entry_match);
m_l = m_l->next;
}
w_l = e->w_list;
while (w_l) {
entries_size += w_l->w->watcher_size +
sizeof(struct ebt_entry_watcher);
w_l = w_l->next;
}
entries_size += e->t->target_size +
sizeof(struct ebt_entry_target);
e = e->next;
}
/* A little sanity check */
if (j != entries->nentries)
ebt_print_bug(“Wrong nentries: %d != %d hook = %s“ j
entries->nentries entries->name);
}
new->entries_size = entries_size;
p = (char *)malloc(entries_size);
if (!p)
ebt_print_memory();
/* Put everything in one block */
new->entries = sparc_cast p;
for (i = 0; i < u_repl->num_chains; i++) {
struct ebt_entries *hlp;
hlp = (struct ebt_entries *)p;
if (!(entries = u_repl->chains[i]))
continue;
if (i < NF_BR_NUMHOOKS)
new->hook_entry[i] = sparc_cast hlp;
hlp->nentries = entries->nentries;
hlp->poli
评论
共有 条评论