[완료]커널 단에서의 netfilter 질문!!!!!

rodio21의 이미지

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include

#define NF_IP_LOCAL_IN 1

static struct proc_dir_entry *packet_dir=NULL;
static struct proc_dir_entry *packets=NULL;

static char proc_buf[100];
static int proc_buf_size=0;

/*static void print_str(char *str) {
struct tty_struct *my_tty;
my_tty = current->signal->tty;
if(my_tty != NULL)
((my_tty->driver)->write(my_tty,str,strlen(str)));
}*/
/*
static int readproc(char * page, char **start, off_t off, int count, int *eof, void *data){
memcpy(page, proc_buf, proc_buf_size);
return proc_buf_size;
}*/
/*
static int writeproc(struct file *file, const char *buffer, unsigned long count, void *data) {
copy_from_user(proc_buf, buffer, count);
return count;
}*/
unsigned int hook_simple(unsigned int hook_no, struct sk_buff *skb, const struct net_device *dev_in, const struct net_device *dev_out, int (*handler)(struct sk_buff *)) {
struct iphdr *iph = ip_hdr(skb);
struct tcphdr *th = tcp_hdr(skb);
/*
if(iph->protocol == 6) printk(KERN_ERR "TCP\n");
if(iph->protocol == 17) return NF_DROP;
//printk(KERN_ERR "UDP\n");*/
char *data = NULL;
int ctr=0;
unsigned int length=0;
unsigned long saddr=0, daddr=0;
unsigned short sport=0, dport=0;

length = ((skb)->len) - (iph->ihl*4) - (th->doff*4); // data size
length = ((skb)->data_len);
data = kmalloc(length, GFP_KERNEL);
saddr = iph->saddr;
proc_buf_size += sprintf(proc_buf, "%lu.%lu.%lu.%lu\n",
(saddr&0xFF000000)>>24, (saddr&0x00FF0000)>>16,
(saddr&0x0000FF00)>>8 , (saddr&0x000000FF));
daddr = iph->daddr;
sport = th->source;
dport = th->dest;
memset(data, 0, length);
memcpy(data, (unsigned char *)th + th->doff*4, length);
saddr = ntohl(iph->saddr);
daddr = ntohl(iph->daddr);
sport = th->source;
dport = th->dest;
/*
printk(KERN_ALERT "%lu.%lu.%lu.%lu:%5u --> %lu.%lu.%lu.%lu:%5u \n",
(saddr&0xFF000000)>>24, (saddr&0x00FF0000)>>16,
(saddr&0x0000FF00)>>8 , (saddr&0x000000FF), sport,
(daddr&0xFF000000)>>24, (daddr&0x00FF0000)>>16,
(daddr&0x0000FF00)>>8 , (daddr&0x000000FF), dport);
*/
for(ctr=0; ctr printk("%02x\n", *(data+ctr));
printk(KERN_ALERT "packet Received with length : %u\n",skb->len);
kfree(data);
return NF_ACCEPT;
}

static struct nf_hook_ops nfilter = {
.hook = hook_simple,
.pf = PF_INET,
.hooknum = NF_IP_LOCAL_IN,
.priority = NF_IP_PRI_FIRST
};

int nfilter_init(void) {
int ret;
packet_dir = proc_mkdir("packets", NULL);
packets = create_proc_entry("packet", 0, packet_dir);
//packets->read_proc = readproc;
//packets->write_proc = writeproc;
ret = nf_register_hook(&nfilter);
if (ret < 0){
printk(KERN_ALERT "netfilter init error!. \n");
return ret;
}else {
printk(KERN_ALERT "netfilter start. \n");
return 0;
}
}

void nfilter_exit(void) {
nf_unregister_hook(&nfilter);
remove_proc_entry("packet", packet_dir);
remove_proc_entry("packets", 0);
printk(KERN_ALERT "netfilter finish. \n");
}

module_init(nfilter_init);
module_exit(nfilter_exit);

이게 소스인데요 이렇게 해서 패킷은 보이는데 저는 브릿지 유틸을 이용해서 브릿지 역할을 하는 컴퓨터로 패킷을 잡으려고 하거든요 근데 자기에게 오는 브로드캐스트나 유니캐스트는 다 신호가 잡히는네 이 컴퓨터에 연결한 내부 내트워크고 들어가는 다른 지나가는 패킷은 잡히지가 않습니다 문제가 무엇일까요?

mithrandir의 이미지

hook이 local_in 라서 그렇습니다.
bridge 같은경우는 forward에도 해당이 안 될 것 같고, bridge에서 사용가능한 netfilter(arptables?) 를 어떻게 쓰나 찾아보세요.
버전따라 다를 수 있습니다.

언제나 삽질 - http://tisphie.net/typo/
프로그래밍 언어 개발 - http://langdev.net

언제나 삽질 - http://tisphie.net/typo/
프로그래밍 언어 개발 - http://langdev.net

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.