Iptables rules are bound to the port instead of blocking on the protocol stack.

Source: Internet
Author: User

Is it necessary to redesign the HOOK Point Location of Netfilter? Undoubtedly, this is meaningless because you cannot prove that the new solution is better. You may just look at the solution of another platform, which is different from the Netfilter solution. In fact, I am such a person.
The Cisco ACL can be compiled on the port. In fact, the network port role of the Cisco device can be defined. The concept of Linux is completely different from this, linux Kernel considers role-defining as the responsibility of the user State. To implement a complete data packet interception mechanism that does not depend on the user State configuration, it must be intercepted on the protocol stack path. In other words, Netfilter completely blocks and processes data packets based on skb itself. This can be seen from the NF_HOOK macro parameter, but you can see that Netfilter has two net_device parameters, based on this, we can follow the Cisco device method to bind the rule to the device. This is advantageous and can greatly improve the efficiency. For example, if you have configured 10000 rules, if there are packets from unrelated network port Devices, these packets do not need to be filtered by iptables rules.
Few items need to be modified. Here, only ipt_hook modifications are provided:

Static unsigned intipt_hook (unsigned int hook, struct sk_buff * skb, const struct net_device * in, const struct net_device * out, int (* okfn) (struct sk_buff *)) {struct netns_table_per_dev {struct list_head list; struct net_device * dev; struct xt_table * table;}; // dev_net (in)-> ipv4.iptable _ filter is no longer an xt_table, instead, it is a list struct wrap_table {struct list_head * tb_list;}; struct xt_table * table; struct * table_dev; struct list_head * pos; struct wrap_table * tb_list = (struct wrap_table *) dev_net (in)-> ipv4.iptable _ filter; list_for_each (pos, tb_list-> tb_list) {table_dev = list_entry (pos, struct netns_table_per_dev, dev ); if (table_dev-> dev = in) {table = table_dev-> table;} if (table = NULL) {return NF_ACCEPT;} return ipt_do_table (skb, hook, in, out, table );}
One is intercept on the protocol stack, and the other is intercept on the device. The operation is a little too big, subverting the existing concept and wondering if there will be any sequelae.
In any case, you cannot get lost.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.