linux防火墙实现技术比较(1)

http://tech.ddvip.com   2006年04月03日    社区交流 收藏本文

本文详细介绍linux防火墙实现技术比较(1)

  5.1 ipchains

  由于ipchains是已经是内核的正式一部分,它采用了修改系统调用的办法来添加修改命令,采用的办法就是扩展setsockopt系统调用:

  int setsockopt (int socket, IPPROTO_IP, int command, void *data, int length)

  man ipfw可以获得这方面的细节。

  ipchains应用程序首先要需要建立一个raw socket(libipfwc.c),然后在之上调用setsockopt。

  sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)

  调用顺序:

  ipchains在应用层调用setsockopt,进入内核:

  --->sys_socketcall(net/socket.c)

  --->sys_setsockopt(net/socket.c)

  --->inet_setsockopt(net/ipv4/af_inet.c)

  --->sock_setsockopt(net/core/sock.c)

  --->raw_setsockopt(net/ipv4/raw.c)

  --->ip_setsockopt(net/ipv4/ip_sockglue.c)

  --->ip_fw_ctl(net/ipv4/ip_fw.c)

  5.2 iptables

  原理同ipchains, 但内部命令格式作了大幅简化。详见nf_setsockopt()。

  5.3 FW1

  FW1 登记了一个字符设备,通过它来进行用户空间与内核空间的交互。相关代码(从汇编代码翻译成的C程序)如下:

  static unsigned int fw_major=0;

  static struct file_operations fw_fops=

  {

  NULL, /* lseek */

  fw_read, /* read */

  fw_write, /* write */

  NULL, /* readdir */

  fw_poll, /* poll */

  fw_ioctl, /* ioctl */

  NULL, /* mmap */

  fw_open, /* open */

  NULL, /* flush */

  fw_release /* release */

  NULL, /* fsync */

  };

  int init_module()

责编:豆豆技术应用

正在加载评论...