기본 콘텐츠로 건너뛰기

netfilter

http://www.netfilter.org/

: 네트웍 정보를 확인할 수 있다
netlink: memory mapped I/O https://lwn.net/Articles/512442/
참조:https://hydra.geht.net/tino/howto/linux/net/netfilter/



http://netfilter.org/projects/libnetfilter_queue/doxygen/nfqnl__test_8c_source.html

nfqnl_test.c 00001 00002 #include <stdio .h=""> 00003 #include <stdlib .h=""> 00004 #include <unistd .h=""> 00005 #include <netinet in.h=""> 00006 #include <linux types.h=""> 00007 #include <linux netfilter.h=""> /* for NF_ACCEPT */ 00008 00009 #include <libnetfilter_queue libnetfilter_queue.h=""> 00010 00011 /* returns packet id */ 00012 static u_int32_t print_pkt (struct nfq_data *tb) 00013 { 00014 int id = 0; 00015 struct nfqnl_msg_packet_hdr *ph; 00016 struct nfqnl_msg_packet_hw *hwph; 00017 u_int32_t mark,ifi; 00018 int ret; 00019 unsigned char *data; 00020 00021 ph = nfq_get_msg_packet_hdr(tb); 00022 if (ph) { 00023 id = ntohl(ph-&gt;packet_id); 00024 printf("hw_protocol=0x%04x hook=%u id=%u ", 00025 ntohs(ph-&gt;hw_protocol), ph-&gt;hook, id); 00026 } 00027 00028 hwph = nfq_get_packet_hw(tb); 00029 if (hwph) { 00030 int i, hlen = ntohs(hwph-&gt;hw_addrlen); 00031 00032 printf("hw_src_addr="); 00033 for (i = 0; i &lt; hlen-1; i++) 00034 printf("%02x:", hwph-&gt;hw_addr[i]); 00035 printf("%02x ", hwph-&gt;hw_addr[hlen-1]); 00036 } 00037 00038 mark = nfq_get_nfmark(tb); 00039 if (mark) 00040 printf("mark=%u ", mark); 00041 00042 ifi = nfq_get_indev(tb); 00043 if (ifi) 00044 printf("indev=%u ", ifi); 00045 00046 ifi = nfq_get_outdev(tb); 00047 if (ifi) 00048 printf("outdev=%u ", ifi); 00049 ifi = nfq_get_physindev(tb); 00050 if (ifi) 00051 printf("physindev=%u ", ifi); 00052 00053 ifi = nfq_get_physoutdev(tb); 00054 if (ifi) 00055 printf("physoutdev=%u ", ifi); 00056 00057 ret = nfq_get_payload(tb, &amp;data); 00058 if (ret &gt;= 0) 00059 printf("payload_len=%d ", ret); 00060 00061 fputc('\n', stdout); 00062 00063 return id; 00064 } 00065 00066 00067 static int cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, 00068 struct nfq_data *nfa, void *data) 00069 { 00070 u_int32_t id = print_pkt(nfa); 00071 printf("entering callback\n"); 00072 return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL); 00073 } 00074 00075 int main(int argc, char **argv) 00076 { 00077 struct nfq_handle *h; 00078 struct nfq_q_handle *qh; 00079 struct nfnl_handle *nh; 00080 int fd; 00081 int rv; 00082 char buf[4096] __attribute__ ((aligned)); 00083 00084 printf("opening library handle\n"); 00085 h = nfq_open(); 00086 if (!h) { 00087 fprintf(stderr, "error during nfq_open()\n"); 00088 exit(1); 00089 } 00090 00091 printf("unbinding existing nf_queue handler for AF_INET (if any)\n"); 00092 if (nfq_unbind_pf(h, AF_INET) &lt; 0) { 00093 fprintf(stderr, "error during nfq_unbind_pf()\n"); 00094 exit(1); 00095 } 00096 00097 printf("binding nfnetlink_queue as nf_queue handler for AF_INET\n"); 00098 if (nfq_bind_pf(h, AF_INET) &lt; 0) { 00099 fprintf(stderr, "error during nfq_bind_pf()\n"); 00100 exit(1); 00101 } 00102 00103 printf("binding this socket to queue '0'\n"); 00104 qh = nfq_create_queue(h, 0, &amp;cb, NULL); 00105 if (!qh) { 00106 fprintf(stderr, "error during nfq_create_queue()\n"); 00107 exit(1); 00108 } 00109 00110 printf("setting copy_packet mode\n"); 00111 if (nfq_set_mode(qh, NFQNL_COPY_PACKET, 0xffff) &lt; 0) { 00112 fprintf(stderr, "can't set packet_copy mode\n"); 00113 exit(1); 00114 } 00115 00116 fd = nfq_fd(h); 00117 00118 while ((rv = recv(fd, buf, sizeof(buf), 0)) &amp;&amp; rv &gt;= 0) { 00119 printf("pkt received\n"); 00120 nfq_handle_packet(h, buf, rv); 00121 } 00122 00123 printf("unbinding from queue 0\n"); 00124 nfq_destroy_queue(qh); 00125 00126 #ifdef INSANE 00127 /* normally, applications SHOULD NOT issue this command, since 00128 * it detaches other programs/sockets from AF_INET, too ! */ 00129 printf("unbinding from AF_INET\n"); 00130 nfq_unbind_pf(h, AF_INET); 00131 #endif 00132 00133 printf("closing library handle\n"); 00134 nfq_close(h); 00135 00136 exit(0); 00137 } </libnetfilter_queue></linux></linux></netinet></unistd></stdlib></stdio>

댓글

댓글 쓰기

이 블로그의 인기 게시물

톰캣 세션 타임 아웃 설정

web.xml 파일이 있습니다. 이 파일을 열어서 session이라고 검색해 보십시오. <session-config>   <session-timeout>360</session-timeout> </session-config> 위 단락을 찾을 수 있습니다. session-timeout 시간 360이 바로 자동로그아웃 세션 시간입니다.  단위는 분이고요. 30분으로 하고 싶으시면 30으로 바꿔서 저장해주시면 되는 것이죠~ Tomcat 내에서 Session Timeout 를 설정하는 우선 순위가 존재 한다. session.setMaxInactiveInterval() 프로그램내에서 time out 를 설정했을 경우 Web application 내의 WEB-INF/web.xml Tomcat 내의 conf/web.xml 실제로 Tomcat(conf/web.xml)내에 Default 로 설정되어 있는 것은 다음과 같다. < HttpSession 메서드 > getCreationTime() - 세션 생성 시간 getLastAccessedTime() - 마지막 요청 시간 setMaxInactiveInterval() - 최대허용시간 설정 (초) getMaxInactiveInterval() - 최대허용시간 invalidate() - 세션 제거 < 타임아웃 설정하기 > - 일정 시간 동안 요청이 없으면 세션을 제거한다  1. DD에서 전체 세션 타임아웃 설정       web.xml 1. DD에서 전체 세션 타임아웃 설정       web.xml <web-app ... >     <servlet>          ...     </servlet>     <session-config>         <session-timeout>30</session-timeout>

dmesg 메시지 실시간으로 보기

참조사이트 http://imitator.kr/Linux/556 # tail -f /var/log/messages # tail -f |dmesg //기본 2초 단위로 갱신 된다. # watch "dmesg | tail -f" //1초 단위로 갱신하면서 보여준다. # watch -n 1 "dmesg | tail -f" // 보여주는 줄을 20으로 늘린다. (기본 10줄) # watch -n 1 "dmesg | tail -f -n 20"

kernel Hello World

리눅스 커널 모듈 프로그래밍 가이드 참조:http://www.tldp.org/LDP/lkmpg/2.6/html/lkmpg.html 커널 모듈 가이드 아래 테스트는 우분투 14.04에서 테스트 되었습니다. 모듈 유틸리티 insmod:모듈을 커널에 적재한다. rmmod:커널에서 모듈을 제거한다. lsmod:커널에서 적재된 모듈 목록을 보여준다. depmod: 모듈간 의존성 정보를 생성한다. modprobe:모듈을 커널에 적재하거나 제거한다. modinfo rdma_ucm 모듈 정보 보기: #lsmod #cat /etc/modprobe.conf #modinfo ib_core 커널에서 제공하는 심볼 테이블 :커널 내부의 함수나 변수 중 외부에서 참조할 수 있는 함수의 심볼과 주소를 담은 테이블 #cat /proc/kallsyms 커널 모듈 제작해 보기 kernel ver 3.16 hello.c /*  *  hello.c - The simplest kernel module.  */ # #include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk("<1>Hello World 1.\n"); return 0; } void cleanup_module(void) { printk(KERN_ALERT "Goodbye world 1.\n"); } Makefile obj-m += hello.o all:         make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean:         make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean #make make -C /lib/modules/3