ebtables中有三张表filter,nat,broute,六条链INPUT,FORWARD,OUTPUT,PREROUTING,POSTROUTING和BROUTING
ebtables -A INPUT --log-level info --log-ip --log-ip6 --log-arp --log-prefix 'ebtable/input'
#!/bin/bash
insert() {
ebtables -t broute -I BROUTING -p ipv4 --ip-proto 17 --log --log-prefix 'ebtable/broute-BROUTING' --log-level debug --log-ip
ebtables -t nat -I PREROUTING -p ipv4 --ip-proto 17 --log --log-prefix 'ebtable/nat-PREROUTE' --log-level debug --log-ip
ebtables -t nat -I POSTROUTING -p ipv4 --ip-proto 17 --log --log-prefix 'ebtable/nat-POSTROUTE' --log-level debug --log-ip
ebtables -t nat -I OUTPUT -p ipv4 --ip-proto 17 --log --log-prefix 'ebtable/nat-OUTPUT' --log-level debug --log-ip
ebtables -t filter -I INPUT -p ipv4 --ip-proto 17 --log --log-prefix 'ebtable/filter-INPUT' --log-level debug --log-ip
ebtables -t filter -I OUTPUT -p ipv4 --ip-proto 17 --log --log-prefix 'ebtable/filter-OUTPUT' --log-level debug --log-ip
ebtables -t filter -I FORWARD -p ipv4 --ip-proto 17 --log --log-prefix 'ebtable/filter-FORWARD' --log-level debug --log-ip
}
delete() {
ebtables -t broute -D BROUTING --log --log-prefix 'ebtable/broute-BROUTING' --log-level debug -p ipv4 --ip-proto 17 --log-ip
ebtables -t nat -D PREROUTING --log --log-prefix 'ebtable/nat-PREROUTE' --log-level debug -p ipv4 --ip-proto 17 --log-ip
ebtables -t nat -D POSTROUTING --log --log-prefix 'ebtable/nat-POSTROUTE' --log-level debug -p ipv4 --ip-proto 17 --log-ip
ebtables -t nat -D OUTPUT --log --log-prefix 'ebtable/nat-OUTPUT' --log-level debug -p ipv4 --ip-proto 17 --log-ip
ebtables -t filter -D INPUT --log --log-prefix 'ebtable/filter-INPUT' --log-level debug -p ipv4 --ip-proto 17 --log-ip
ebtables -t filter -D OUTPUT --log --log-prefix 'ebtable/filter-OUTPUT' --log-level debug -p ipv4 --ip-proto 17 --log-ip
ebtables -t filter -D FORWARD --log --log-prefix 'ebtable/filter-FORWARD' --log-level debug -p ipv4 --ip-proto 17 --log-ip
}
static struct xt_target ebt_log_tg_reg __read_mostly = {
.name = "log",
.revision = 0,
.family = NFPROTO_BRIDGE,
.target = ebt_log_tg,
.checkentry = ebt_log_tg_check,
.targetsize = sizeof(struct ebt_log_info),
.me = THIS_MODULE,
};
ebt_log_tg(struct sk_buff *skb, const struct xt_action_param *par)
{
const struct ebt_log_info *info = par->targinfo;
struct nf_loginfo li;
struct net *net = xt_net(par);
li.type = NF_LOG_TYPE_LOG;
li.u.log.level = info->loglevel;
li.u.log.logflags = info->bitmask;
/* Remember that we have to use ebt_log_packet() not to break backward
* compatibility. We cannot use the default bridge packet logger via
* nf_log_packet() with NFT_LOG_TYPE_LOG here. --Pablo
*/
if (info->bitmask & EBT_LOG_NFLOG)
nf_log_packet(net, NFPROTO_BRIDGE, xt_hooknum(par), skb,
xt_in(par), xt_out(par), &li, "%s",
info->prefix);
else
ebt_log_packet(net, NFPROTO_BRIDGE, xt_hooknum(par), skb,
xt_in(par), xt_out(par), &li, info->prefix);
return EBT_CONTINUE;
}
static void
ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
const struct sk_buff *skb, const struct net_device *in,
const struct net_device *out, const struct nf_loginfo *loginfo,
const char *prefix)
{
unsigned int bitmask;
/* FIXME: Disabled from containers until syslog ns is supported */
if (!net_eq(net, &init_net) && !sysctl_nf_log_all_netns)
return;
spin_lock_bh(&ebt_log_lock);
printk(KERN_SOH "%c%s IN=%s OUT=%s MAC source = %pM MAC dest = %pM proto = 0x%04x",
'0' + loginfo->u.log.level, prefix,
in ? in->name : "", out ? out->name : "",
eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest,
ntohs(eth_hdr(skb)->h_proto));
if (loginfo->type == NF_LOG_TYPE_LOG)
bitmask = loginfo->u.log.logflags;
else
bitmask = NF_LOG_DEFAULT_MASK;
//如果设置了控制选项(–log-ip),并且报文为IP报文,显示IP头部信息,以及尝试显示四层报文信息(print_ports)。
if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto ==
htons(ETH_P_IP)) {
const struct iphdr *ih;
struct iphdr _iph;
ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
if (ih == NULL) {
pr_cont(" INCOMPLETE IP header");
goto out;
}
pr_cont(" IP SRC=%pI4 IP DST=%pI4, IP tos=0x%02X, IP proto=%d",
&ih->saddr, &ih->daddr, ih->tos, ih->protocol);
print_ports(skb, ih->protocol, ih->ihl*4);
goto out;
}
//对于ARP协议报文,如果设置了选项(–log-arp),显示ARP头部信息。对于Ethernet,另外显示报文信息,
//包括发送者(Sender)的MAC和IP地址,目标(Target)的MAC和IP地址。
if ((bitmask & EBT_LOG_ARP) &&
((eth_hdr(skb)->h_proto == htons(ETH_P_ARP)) ||
(eth_hdr(skb)->h_proto == htons(ETH_P_RARP)))) {
const struct arphdr *ah;
struct arphdr _arph;
ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
if (ah == NULL) {
pr_cont(" INCOMPLETE ARP header");
goto out;
}
pr_cont(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
ntohs(ah->ar_hrd), ntohs(ah->ar_pro),
ntohs(ah->ar_op));
/* If it's for Ethernet and the lengths are OK,
* then log the ARP payload
*/
if (ah->ar_hrd == htons(1) &&
ah->ar_hln == ETH_ALEN &&
ah->ar_pln == sizeof(__be32)) {
const struct arppayload *ap;
struct arppayload _arpp;
ap = skb_header_pointer(skb, sizeof(_arph),
sizeof(_arpp), &_arpp);
if (ap == NULL) {
pr_cont(" INCOMPLETE ARP payload");
goto out;
}
pr_cont(" ARP MAC SRC=%pM ARP IP SRC=%pI4 ARP MAC DST=%pM ARP IP DST=%pI4",
ap->mac_src, ap->ip_src,
ap->mac_dst, ap->ip_dst);
}
}
out:
pr_cont("\n");
spin_unlock_bh(&ebt_log_lock);
}
http代理服务器(3-4-7层代理)-网络事件库公共组件、内核kernel驱动 摄像头驱动 tcpip网络协议栈、netfilter、bridge 好像看过!!!! 但行好事 莫问前程 --身高体重180的胖子