Linux Netfilter Code Trace Part1: Iptable 周世中嚴長青.

Slides:



Advertisements
Similar presentations
COMS W6998 Spring 2010 Erich Nahum
Advertisements

1 Network Address Translation (NAT) Relates to Lab 7. Module about private networks and NAT.
CSC458 Programming Assignment II: NAT Nov 7, 2014.
Ryu Book Chapter 1 Speaker: Chang, Cheng-Yu Date: 25/Nov./
Ipchains and Iptables Linux operating system natively supports packet-filtering rules: Kernel versions 2.2 and earlier support the ipchains command. Kernel.
ITINERANT: TCP Socket Migration Titus Winters Dan Berger CS 202: Spring ‘03.
1 Network Address Translation (NAT) Relates to Lab 7. Module about private networks and NAT.
Packet Filtering CS-480b Dick Steflik. Stateless Packet Filters A border router configured to pass or reject packets based on information in the header.
1 Netfilter in Linux Bing Qi Department of Computer Science and Engineering Auburn university.
LİNUX-ROUTER-1 Gw1: GW2: ISP1 eth eth /30 LİNUX-ROUTER-2 Gw1: Gw2: eth1.
Module 10. Internet Protocol (IP) is the routed protocol of the Internet. IP addressing enables packets to be routed from source to destination using.
Small Form Computing A bump in the wire. The questions ● What can we do with an inexpensive small computer? ● Can we make it a part of a seamless wireless.
Lab 5: NAT CS144 Review Session 7 November 13 th, 2009 Roger Liao.
1 Introduction to Raw Sockets 2 IP address Port address MAC address TCP/IP Stack 67 Bootp DHCP OSPF protocol frame type UDP Port # TCP Port.
COMS W COMS W Lecture 8. NAT, DHCP & Firewalls.
NetFilter – IPtables Firewall –Series of rules to govern what Kind of access to allow on your system –Packet filtering –Drop or Accept packets NAT –Network.
07/11/ L10/1/63 COM342 Networks and Data Communications Ian McCrumRoom 5B18 Tel: voice.
Packet Filtering and Firewall
By Deepthi Reddy Ramya Balakumar Vandana Bhardwaj Simple Packet Filtering Firewall.
Iptables and apache 魏凡琮 (Jerry Wei). Agenda iptables apache.
LWIP TCP/IP Stack 김백규.
Firewalls A device that screens incoming and outgoing network traffic and allows or disallows traffic based on a set of rules The “device” –Needs at least.
Packet Filtering Chapter 4. Learning Objectives Understand packets and packet filtering Understand approaches to packet filtering Set specific filtering.
TCOM 515 IP Routing. Syllabus Objectives IP header IP addresses, classes and subnetting Routing tables Routing decisions Directly connected routes Static.
1 實驗九:建置網路安全閘道器 教師: 助教:. 2 Outline  Background  Proxy – Squid  Firewall – IPTables  VPN – OpenVPN  Experiment  Internet gateway  Firewall  VPN.
Firewalling With Netfilter/Iptables. What Is Netfilter/Iptables? Improved successor to ipchains available in linux kernel 2.4/2.6. Netfilter is a set.
IPtables Objectives Contents Practicals Summary
CS4550 Computer Networks II IP : internet protocol, part 2 : packet formats, routing, routing tables, ICMP read feit chapter 6.
Firewall Tutorial Hyukjae Jang Nc lab, CS dept, Kaist.
Private Network Addresses IP addresses in a private network can be assigned arbitrarily. – Not registered and not guaranteed to be globally unique Generally,
Network Programming Chapter 5: Raw Socket Programming.
An initial study on Multi Path Routing Over Multiple Devices in Linux 2.4.x kernel Towards CS522 term project By Syama Sundar Kosuri.
1 Firewalls Types of Firewalls Inspection Methods  Static Packet Inspection  Stateful Packet Inspection  NAT  Application Firewalls Firewall Architecture.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Netfilter.
Network Configuration in Linux
Linux Kernel Backdoors And Their Detection Joanna Rutkowska ITUnderground Conference, October 12 th -13 th 2004, Warsaw.
1 Network Address Translation (NAT) and Dynamic Host Configuration Protocol (DHCP) Relates to Lab 7. Module about private networks and NAT.
Linux Networking Stack 指導老師 李正帆
Introduction to Linux Firewall
Firewalls A brief introduction to firewalls. What does a Firewall do? Firewalls are essential tools in managing and controlling network traffic Firewalls.
1 Network Address Translation. 2 Network Address Translation (NAT) Extension of original addressing scheme Motivated by exhaustion of IP address space.
Computer Networking Project II question/answer session October 18, 2001.
First generation firewalls packets filtering ريماز ابراهيم محمد علي دعاء عادل محمد عسجد سامي عبدالكريم.
LINUX® Netfilter The Linux Firewall Engine. Overview LINUX® Netfilter is a firewall engine built into the Linux kernel Sometimes called “iptables” for.
H.323 NAT Traversal Problem particular to H.323(RAS->Q.931->H.245):  RAS from private network to public network can pass NAT  Q931 、 H.245 adopts the.
Session 25: Netlink Sockets 문준혁. Index What are netlink sockets? Opening a netlink socket –Family Netlink messages –nlmsg_type –nlmsg_flags Lab.
Lecture 3: Stateless Packet Filtering. 2 Agenda 1 1 Linux file system - networking sk_buff 2 2 Stateless packet filtering 3 3 About next assignment 4.
Netfilter Framework Jimit Mahadevia Nishit Shah This work is licensed under a Creative Commons Attribution-Share.
Conntrack + NAT Helpers Jimit Mahadevia Nishit Shah This work is licensed under a Creative Commons Attribution-Share.
Firewalls. A Firewall is: a) Device that interconnects two networks b) Network device that regulates the access to an internal network c) Program that.
Firewalls and DMZ Dr. X. Firewalls Filtering traffic based on policy Policy determines what is acceptable traffic Access control over traffic Accept or.
Network Address Translation (NAT)

CSC458 Programming Assignment II: NAT
FIREWALL configuration in linux
Network Address Translation (NAT)
Mateti/PacketFilters
Jimit Mahadevia Nishit Shah This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Network Address Translation (NAT)
Packet Filtering Dick Steflik.
Network and System Security Risk Assessment
Chapter 4: Access Control Lists (ACLs)
FSU CIS 5930 Internet Protocols
Setting Up Firewall using Netfilter and Iptables
Firewalls By conventional definition, a firewall is a partition made
From ACCEPT to MASQUERADE Tim(othy) Clark (eclipse)
46 to 1500 bytes TYPE CODE CHECKSUM IDENTIFIER SEQUENCE NUMBER OPTIONAL DATA ICMP Echo message.
Firewalls.
Chapter 4: outline 4.1 Overview of Network layer data plane
Presentation transcript:

Linux Netfilter Code Trace Part1: Iptable 周世中嚴長青

Outline Hook IP Table Ipt_match Ipt_target

Outline Hook IP Table Ipt_match Ipt_target

Hooks Default hooks: –PRE_ROUTING –POST_ROUTING –FORWARD –LOCAL_IN –LOCAL_OUT

Hooks PREROUTE LOCAL_INLOCAL_OUT FORWARDPOSTROUTE

Hooks NF_HOOK(pf, hook, skb, indev, outdev, okfn) –pf: protocol family (PF_INET) –hook:the location of the hooks –skb: sk_buff(packet information) –indev: which device the packet come from –outdev: which device the packet go to –okfn: call the function if the packet is accepted

Hook – PRE_ROUTING NF_IP_PRE_ROUTING ip_input.c:441(ip_rcv) –NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL, ip_rcv_finish)

Hook – POST_ROUTING NF_IP_POST_ROUTING ip_output.c:190(ip_finish_output) –NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev, ip_finish_output2) Ip_output.c:232(ip_mc_output) –NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL, newskb->dev, ip_dev_loopback_xmit)

Hook – POST_ROUTING ip_output.c:248(ip_mc_output) –NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL, newskb->dev, ip_dev_loopback_xmit);

Hook – FORWARD NF_IP_FORWARD ip_forward.c:145(ip_forward) –NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, dev2, ip_forward_finish)

Hook – LOCAL_IN NF_IP_LOCAL_IN ip_input.c:305(ip_local_deliver) –NF_HOOK(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL, ip_local_deliver_finish)

Hook – LOCAL_OUT NF_IP_LOCAL_OUT igmp.c:252 (igmp_send_report) –NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, output_maybe_reroute) ip_output.c:155 (ip_build_and_send_pkt) –NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, output_maybe_reroute)

Hook – Write a new hook Default a new hook value and modify NF_IP_NUMHOOKS in /include/linux/netfilter_ipv4.h Insert NF_HOOK into the appropriate place to call the hook

Outline Hook IP Table Ipt_match Ipt_target

IP table Hitches on hooks Separates into data and operations Contains all rules for each hooks Removing or adding a rule will rebuild the rule base Process the tables in priority on hooks

IP table IP Table ipt_entry …… IP Table Hook op packet ……

IP table(ipt_table) struct ipt_table –char name[] –struct ipt_replace *table; Seed table, used to product ipt_table_info –unsigned int valid_hooks; –rwlock_t lock; –struct ipt_table_info *private; The place to record rules

IP table(ipt_table) struct ipt_replace –char name[]; –unsigned int valid_hooks; –unsigned int num_entries; –unsigned int size; –unsigned int hook_entry[NF_IP_NUMHOOKS]; –unsigned int underflow[NF_IP_NUMHOOKS]; –unsigned int num_counters; –struct ipt_counters *counters; –struct ipt_entry entries[0]; Rules entrance for each HOOK Default rules for each HOOK

IP table(ipt_table_info) struct ipt_table_info –unsigned int size –unsigned int number Number of entries –unsigned int initial_entries Initial number of entries –unsigned int hook_entry[NF_IP_NUMHOOKS] –unsigned int underflow[NF_IP_NUMHOOKS] –char entries[0]

IP table(nf_hook_ops) struct nf_hook_ops –nf_hookfn *hook How to process the table on the hook –int pf Protocol family(e.g. PF_INET) –int hooknum; Hitches on which hook –int priority; Priority to process the table in the hook

IP table Default IP Tables: –Filter –Mangle –NAT

Write a new table Define a table –iptable_filter.c: 84 static struct ipt_table packet_filter = { { NULL, NULL }, "filter", &initial_table.repl, FILTER_VALID_HOOKS, RW_LOCK_UNLOCKED, NULL, THIS_MODULE }; Define default ipt_replace –iptable_filter.c: 30

Write a new table Initialize –iptable_filter.c: 128 –Register table, its operations to the hook Finish –iptable_filter.c: 170 –Unregister table, operations, and clean datas

Outline Hook IP Table Ipt_match Ipt_target

Match A part of a rule Process a packet and determine whether it fulfill the condition of the rule Return 1 for true and 0 for false Match information: specification of the match in a IPT Entry

ipt_entryipt_entry_target ipt_entry_match ipt_match ipt_match *match The match function return unsigned int

Ipt_match struct ipt_match –const char name[]; –int (*match) (); Match function to match a packet –int (*checkentry)(); Check whether the parameter to the match is vaild –void (*destroy)(); Destroy the match information if necessary

Build-in match TCP match –source port, destination port, TCP flag UDP match –source port, destination port ICMP match –ICMP code

Match extensions ipt_ah.c: match for AH parameters ipt_esp.c: match for ESP parameters ipt_length.c: match for packet length ipt_limit.c: control the rate ipt_mac.c: match MAC address ipt_mark.c: match NFMASK ipt_multiport.c: match list of ports in TCP/UDP

Match extensions ipt_owner.c: match the owner of the socket ipt_state.c: match connection tracking information ipt_tcpmss.c: match TCP MSS(Maximum Segment Size) values ipt_tos.c: match TOS field ipt_ttl.c: match TTL field ipt_unclean.c: check a packet is valid strictly

Match example ipt_tos.c Define the ipt_match structure –struct ipt_match tos_match = { { NULL, NULL }, "tos", &match, &checkentry, NULL, THIS_MODULE }; Initialize: register match into iptable Finish: unregister the match

Match example Match –return (iph->tos == info->tos) ^ info->invert Checkentry –return matchsize == IPT_ALIGN(sizeof(struct ipt_tos_info))

Write a new match Define ipt_match Initialize: register match into iptable Finish: unregister the match Write match and checkentry function Write destroy function if necessary

Outline Hook IP Table Ipt_match Ipt_target

Target A part of a rule Process a packet and determine the packet verdict Return verdict or IPT_CONTINUE to continue the iptable Target information: specification of the match in a IPT Entry

ipt_entryipt_entry_target ipt_entry_match ipt_target ipt_taeget ipt_target *target The target function return 0 or a packet verdict

Ipt_target struct ipt_target –const char name[]; –int (*target) (); Target function to determine the verdict of a packet “Target=NULL” means the ipt_target is a standard target –int (*checkentry)(); Check whether the parameter to the target is vaild –void (*destroy)(); Destroy the target information if necessary

Standard target Target in structure ipt_target is NULL Following a verdict, e.g. NF_ACCEPT, NF_DROP

Target extensions ipt_LOG.c: logging packets ipt_MARK.c: set NFMARK in sk_buff ipt_MASQUERADE.c: masquerade ipt_MIRROR.c: invert the src and dst IP ipt_REDIRECT.c: alert dst IP to a local IP ipt_REJECT.c: reject packets(sending ICMP unreachable or TCP reset)

Target extensions ipt_MSS.c: set the TCP MSS field ipt_TOS.c: set the IP TOS field ipt_ULOG.c: send to user space daemon to log packets

Target example ipt_TOS.c Define the ipt_target structure –static struct ipt_target ipt_tos_reg = { { NULL, NULL }, "TOS", target, checkentry, NULL, THIS_MODULE }; Initialize: register target into iptable Finish: unregister the target

Target example Target –Change TOS to predefined value in target info –Recompute the IP checksum –Continue filtering Checkentry –Check size, table, and predefined value to TOS

Write a new target Define ipt_target Initialize: register target into iptable Finish: unregister the target Write target and checkentry function Write destroy function if necessary

Reference –IPTables-tutorial