ebtables.ppt
《ebtables.ppt》由会员分享,可在线阅读,更多相关《ebtables.ppt(64页珍藏版)》请在三一办公上搜索。
1、EBTABLS 培训,欧阳棣,培训内容,Ebtables 概述Ebtables 框架扩展 ebtablesEbtables 应用问题思考,Ebtables 概述,Ebtables 是什么,说到ebtables 大家可能最首先会想到iptables,iptables、ebtables它们是linux防火墙的两个组成部份。iptables主要提供了基于ip头部信息的过滤,如IP五元组等ebtables提供了基于桥的以太帧过滤,日志,MAC DNAT和brouting,同时它也有一些简单的IP过滤功能。,Ebtables 功能,Ethernet protocol filtering.MAC addr
2、ess filtering.Simple IP header filtering.ARP header filtering.802.1Q VLAN filtering.In/Out interface filtering(logical and physical device).MAC address nat.,Ebtables 功能,Logging.Frame counters.Ability to add,delete and insert rules;flush chains;zero counters.Brouter facility.Ability to atomically loa
3、d a complete table,containing the rules you made,into the kernel.See the man page and the examples section.Support for user defined chains.Support for marking frames and matching marked frames.,Ebtables 框架,用户交互,应用程序 communication.c内核层 static struct nf_sockopt_ops ebt_sockopts,Hook 点,nf_hooksNPROTONF
4、_MAX_HOOKS,NPROTO=32,支持协议族的数量 NF_MAX_HOOKS=8,支持检查点的数量 检查点上的nf_hook_ops结构,按priority的值,从小到大排列,nf_hook_ops,Hook 点上的数据结构,struct nf_hook_opsstruct list_head list;nf_hookfn*hook;int pf;int hooknum;int priority;,unsigned int nf_hookfn(unsigned int hooknum,struct sk_buff*skb,const struct net_device*in,const
5、 struct net_device*out,int(*okfn)(struct sk_buff*);,list:链表结构;hook:检查点上调用的函数;pf:协议族;hooknum:检查点的编号;priority:此结构的优先级 nf_register_hook:注册nf_hook_ops结构 nf_unregister_hook:卸载nf_hoop_ops结构,Hook 宏定义,#define NF_HOOK(pf,hook,skb,indev,outdev,okfn)NF_HOOK_THRESH(pf,hook,skb,indev,outdev,okfn,INT_MIN)#define
6、NF_HOOK_THRESH(pf,hook,skb,indev,outdev,okfn,thresh(int _ret;if(_ret=nf_hook_thresh(pf,hook,),NF_HOOK:定义检查点(okfn)(skb):如果检查点上没有钩子函数,直接调用这个函数;如果有钩子函数,则先遍历检查点上的钩子函数,并根据钩子函数的返回值来确定下一步的动作;如果钩子函数完全遍历,同样需要调用这个函数 nf_hook_thresh:调用hook,返回表示包通过,返回其他表示包被消耗,Hook 点的调用流程,NF_DROP:禁止包通过NF_ACCEPT:允许包通过NF_STOLEN:包被本
7、机缓存NF_QUEUE:把包发送到用户空间NF_REPEAT:重复上一次遍历过程,NF_HOOK,nf_hook_slow,nf_iterate,nf_hookfn,返回值,nf_hook_thresh,ebt_do_table,Ebtables hook 点位置,Bridge Hooks,#define NF_BR_PRE_ROUTING0#define NF_BR_LOCAL_IN1#define NF_BR_FORWARD2#define NF_BR_LOCAL_OUT3#define NF_BR_POST_ROUTING4/*Not really a hook,but used for
8、 the ebtables broute table*/#define NF_BR_BROUTING5注:NF_BR_BROUTING不是真正hook,不会通过hook点调用流程调用,NF_BR_PRE_ROUTING,NF_BR_LOCAL_IN,NF_BR_FORWARD,NF_BR_LOCAL_OUT,NF_BR_POST_ROUTING,NF_BR_BROUTING,static int ebt_broute(struct sk_buff*pskb)int ret;ret=ebt_do_table(NF_BR_BROUTING,pskb,(*pskb)-dev,NULL,/外部函数指针
9、,nf_hook_ops 结构体,struct nf_hook_opsstruct list_head list;/*User fills in from here down.*/nf_hookfn*hook;struct module*owner;int pf;int hooknum;/*Hooks are ordered in ascending priority.*/int priority;,在每一个table中都会有一个nf_hook_ops结构体数组,它通过去nf_register_hook注册到全局变量nf_hook中,ebt_table 结构体,struct ebt_table
10、struct list_head list;char nameEBT_TABLE_MAXNAMELEN;struct ebt_replace*table;unsigned int valid_hooks;rwlock_t lock;/*e.g.could be the table explicitly only allows certain*matches,targets,.0=let it in*/int(*check)(const struct ebt_table_info*info,unsigned int valid_hooks);/*the data used by the kern
11、el*/struct ebt_table_info*private;struct module*me;,ebt_tables 链表,Ebtables有三个表broutefilterNat表注册函数:ebt_register_tableebt_unregister_table,ebt_entries 结构体,struct ebt_entries/*this field is always set to zero*See EBT_ENTRY_OR_ENTRIES.*Must be same size as ebt_entry.bitmask*/unsigned int distinguisher;
12、/*the chain name*/char nameEBT_CHAIN_MAXNAMELEN;/*counter offset for this chain*/unsigned int counter_offset;/*one standard(accept,drop,return)per hook*/int policy;/*nr.of entries*/unsigned int nentries;/*entry list*/char data0 _attribute_(aligned(_alignof_(struct ebt_replace);,ebt_entries 处理流程,targ
13、et,hook_entry,eb_table_info,ebt_match 结构体,struct ebt_matchstruct list_head list;const char nameEBT_FUNCTION_MAXNAMELEN;/*0=it matches*/int(*match)(const struct sk_buff*skb,const struct net_device*in,const struct net_device*out,const void*matchdata,unsigned int datalen);/*0=let it in*/int(*check)(con
14、st char*tablename,unsigned int hookmask,const struct ebt_entry*e,void*matchdata,unsigned int datalen);void(*destroy)(void*matchdata,unsigned int datalen);struct module*me;,ebt_matches 链表,Match注册函数ebt_register_matchebt_unregister_match,ebt_watcher 结构体,struct ebt_watcherstruct list_head list;const cha
15、r nameEBT_FUNCTION_MAXNAMELEN;void(*watcher)(const struct sk_buff*skb,unsigned int hooknr,const struct net_device*in,const struct net_device*out,const void*watcherdata,unsigned int datalen);/*0=let it in*/int(*check)(const char*tablename,unsigned int hookmask,const struct ebt_entry*e,void*watcherdat
16、a,unsigned int datalen);void(*destroy)(void*watcherdata,unsigned int datalen);struct module*me;,ebt_watchers 链表,Watcher注册函数ebt_register_watcherebt_unregister_watcher,ebt_target 结构体,struct list_head list;const char nameEBT_FUNCTION_MAXNAMELEN;/*returns one of the standard verdicts*/int(*target)(struc
17、t sk_buff*pskb,unsigned int hooknr,const struct net_device*in,const struct net_device*out,const void*targetdata,unsigned int datalen);/*0=let it in*/int(*check)(const char*tablename,unsigned int hookmask,const struct ebt_entry*e,void*targetdata,unsigned int datalen);void(*destroy)(void*targetdata,un
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ebtables
![提示](https://www.31ppt.com/images/bang_tan.gif)
链接地址:https://www.31ppt.com/p-2912579.html