⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux防火墙程序设计.htm

📁 这是我对防火墙技术的一些见解
💻 HTM
📖 第 1 页 / 共 2 页
字号:
        <BR>利用这个参数可以向内核传递信息,如重定向时的端口号。 <BR>* 参数pskb 
        <BR>此参数是指向sk_buff结构指针的指针。在Linux中,所有网络数据的发送和接收都用sk_buff数据结构表示。在sk_buff数据结构中包含有对应设备结构的device地址、传输层、网络层、链路层协议头地址等。关于sk_buff的定义可参见skbuff.h头文件。 
        <BR>3、防火墙程序示例 
        <BR>下面给出一个简单防火墙程序。在这里假设读者对以太协议、IP协议、TCP协议等常用协议有一定的了解。用命令行\"gcc -Wall -O2 
        -c 
        MyFirewall.c\"进行编译,再用insmod命令加载程序后,系统将只响应外部网络用TCP协议的80端口所进行的访问。要让系统恢复原有功能,则可用rmmod命令卸载该程序,源代码见网站www.pccomputing.com.cn上的同名文章。 
        <BR><BR><BR>// MyFirewall.c 2000年3月7日编写 <BR>#ifndef __KERNEL__ <BR># 
        define __KERNEL__ //按内核模块编译 <BR>#endif <BR>#ifndef MODULE <BR># define 
        MODULE //按设备驱动程序模块编译 <BR>#endif <BR>#include <LINUX 
        module.h>//最基本的内核模块头文件 <BR>#include <LINUX sched.h><BR>#include <LINUX 
        kernel.h>//最基本的内核模块头文件 <BR>#include <LINUX netdevice.h><BR>#include 
        <LINUX ip.h><BR>#include <LINUX tcp.h><BR>#include <LINUX 
        skbuff.h><BR>#include <LINUX proc_fs.h><BR>#include <LINUX 
        if.h><BR>#include <LINUX in.h><BR>#include <LINUX firewall.h><BR>#define 
        SOL_ICMP 1 <BR>#define PERMIT_PORT 80 //只允许访问TCP的80端口 <BR><BR>int 
        zzl_input(struct firewall_ops *this,int pf,struct device *dev, <BR>void 
        *phdr,void *arg,struct sk_buff **pskb) <BR>{//每当收到一个网络报时,此函数将被内核调用 
        <BR>struct tcphdr *tcph; //TCP的头指针 <BR>struct iphdr *iph; //IP头指针 
        <BR>struct sk_buff *skb=*pskb; <BR>if 
        (skb-&gt;protocol==htons(ETH_P_ARP)){ <BR>printk(\"\\nPermit a ARP 
        Packet\"); <BR>return FW_ACCEPT;//允许地址解析协议报 <BR>} 
        <BR>if(skb-&gt;protocol==htons(ETH_P_RARP)){ <BR>printk(\"\\nPermit a 
        RARP Packet\"); <BR>return FW_ACCEPT;//允许反向地址解析协议报 <BR>} 
        <BR>if(skb-&gt;protocol==htons(ETH_P_IP)) <BR>{ <BR>iph=skb-&gt;nh.iph; 
        <BR>if (iph-&gt;protocol==SOL_ICMP) <BR>{ <BR>printk(\"\\nPermit a ICMP 
        Packet\"); <BR>return FW_ACCEPT;//允许网络控制报 <BR>} 
        <BR>if(iph-&gt;protocol==SOL_TCP){ <BR>tcph=skb-&gt;h.th; 
        <BR>if(tcph-&gt;dest==PERMIT_PORT){ <BR>printk(\"\\nPermit a valid 
        access\"); <BR>return FW_ACCEPT;//允许对TCP端口80的访问 <BR>} <BR>} <BR>} 
        <BR>return FW_REJECT;//禁止对本计算机的所有其它访问 <BR>} <BR>int zzl_output(struct 
        firewall_ops *this,int pf,struct device *dev, <BR>void *phdr,void 
        *arg,struct sk_buff **pskb) <BR>{//程序编写方法同zzl_input函数模块 
        <BR>printk(\"\\nzzl_output is called \"); <BR>return FW_SKIP; <BR>} 
        <BR>int zzl_foreward(struct firewall_ops *this,int pf,struct device 
        *dev, <BR>void *phdr,void *arg,struct sk_buff **pskb) 
        <BR>{//程序编写方法同zzl_input函数模块 <BR>printk(\"\\nzzl_foreward is called \"); 
        <BR>return FW_SKIP; <BR>} <BR>struct firewall_ops zzl_ops= <BR>{ 
        <BR>NULL, <BR>zzl_foreward, <BR>zzl_input, <BR>zzl_output, <BR>PF_INET, 
        <BR>01 <BR>}; <BR>int init_module(void) <BR>{ 
        <BR>if(register_firewall(PF_INET,&amp;zzl_ops)!=0) <BR>{ 
        <BR>printk(\"\\nunable register firewall\"); <BR>return -1; <BR>} 
        <BR>printk(\"\\nzzl_ops=%p\",&amp;zzl_ops); <BR>return 0; <BR>} <BR>void 
        cleanup_module(void) <BR>{ <BR>printk(\"unload\\n\"); 
        <BR>unregister_firewall(PF_INET,&amp;zzl_ops); <BR>} 
        <BR><BR>(作者地址:北京市北三环中路四号750房 100720 收稿日期:2000.3.13) 
        <BR><BR><BR><BR>——摘自:游侠部落
        <DIV align=right>发布人:netbull&nbsp;来自:蓝森林&nbsp;</DIV><BR></UL><IMG 
      src="Linux防火墙程序设计.files/line.jpg"><BR>
      <FORM action=post.php?skin=reart&amp;ID=58 method=post>
      <UL>-- 发表评论 --<BR>&nbsp;昵称:<INPUT name=name>&nbsp;Email:<INPUT 
        name=email><BR>&nbsp;内容:<BR><TEXTAREA name=content rows=5 cols=56></TEXTAREA><BR>&nbsp;&nbsp;<INPUT type=submit value=确定回复>&nbsp;<INPUT type=reset value=清除></UL></FORM><IMG 
      src="Linux防火墙程序设计.files/line.jpg"><BR>
      <UL>
        <LI>以下是对此文的评论:<BR><BR></LI></UL></TD><!--第三列-->
    <TD vAlign=top align=left width="25%">&nbsp;<IMG 
      src="Linux防火墙程序设计.files/online.jpg" border=0> 
      <UL>
        <LI><A href="http://www.linuxbyte.net/addnews.php" 
        target=_blank>新闻发布</A><BR><BR>
        <LI><A href="http://www.linuxbyte.net/addart.php" 
        target=_blank>文献发布</A><BR><BR>
        <LI><A href="http://www.linuxbyte.net/addsoft.php" 
        target=_blank>软件发布</A><BR><BR>
        <LI><A href="http://www.linuxbyte.net/manger.php" 
        target=_blank>软件管理</A><BR></LI></UL><IMG height=5 
      src="Linux防火墙程序设计.files/tabledi2.jpg" width="100%"><!--下载排行--> &nbsp;<IMG 
      src="Linux防火墙程序设计.files/download.jpg" border=0> <BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=676">Red Hat 
      Linux</A>&nbsp;(81310)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=219">Oracle9i 
      Enterprise</A>&nbsp;(40541)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=93">星际译王1.31版</A>&nbsp;(37768)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=785">kylix</A>&nbsp;(36519)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=1642">Lindows OS 
      4.5</A>&nbsp;(29616)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=287">AOL 
      server</A>&nbsp;(27385)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=969">RedHat 
      中文环境</A>&nbsp;(26129)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=647">Chinput</A>&nbsp;(24366)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=1041">中软Linux</A>&nbsp;(21925)<BR>&nbsp;<A 
      href="http://www.linuxbyte.net/view.php?skin=soft&amp;id=946">RedHat Linux 
      7.1正式</A>&nbsp;(21608)<BR><IMG height=5 
      src="Linux防火墙程序设计.files/tabledi2.jpg" width="100%"> <!--文摘分类-->&nbsp;<IMG 
      src="Linux防火墙程序设计.files/artstyle.jpg" border=0> <BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=1">内核分析</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=2">网络技术及应用</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=3">应用编程</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=4">硬件应用</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=5">软件应用</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=6">系统管理</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=7">数据库应用</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=8">系统安全</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=9">Linux中文化</A><BR>&nbsp;&nbsp;<A 
      href="http://www.linuxbyte.net/arttype.php?dno=10">市场与观点</A><BR><IMG 
      height=5 src="Linux防火墙程序设计.files/tabledi2.jpg" width="100%"> <BR><!--合作伙伴-->&nbsp;<IMG src="Linux防火墙程序设计.files/friends.jpg" border=0> 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A href="http://www.5ilinux.com/" 
      target=_blank>我爱linux</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.heblinux.org/" 
      target=_blank>河北LINUX协会</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.xteamlinux.com.cn/" 
      target=_blank>冲浪软件下载中心</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://cosoft.org.cn/html/" 
      target=_blank>共创联盟</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.coventive.com.cn/" 
      target=_blank>XLinux</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.it365.net/" 
      target=_blank>诺金软件电脑网络</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.ch2000.com.cn/" 
      target=_blank>中文2000软件</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.csuu.com/" 
      target=_blank>中国Unix联盟</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://freewares.cn/" 
      target=_blank>自由软件在中国</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.pconline.com.cn/pcedu" 
      target=_blank>太平洋电脑信息网</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.linuxaid.com.cn/" 
      target=_blank>LinuxAid</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://www.cosoft.org.cn/" 
      target=_blank>共创软件联盟</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://wsdn.org/" 
      target=_blank>WEB程序开发网络</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://linux.softhouse.com.cn/" 
      target=_blank>软件屋Linux之家</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://ljb.vpnet.cn/" 
      target=_blank>随意网络</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A 
      href="http://linux.ccidnet.com/" 
  target=_blank>赛迪网Linux专区</A><BR></TD></TR></TBODY></TABLE>
<CENTER>Completed in 0.0548579692841&nbsp;seconds</CENTER>
<CENTER>COPYRIGHT 2002-2003 <FONT color=#9b2626>LinuxByte.net</FONT> <A 
href="mailto:oneteam@mail.linuxbyte.net">联系本站</A></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -