⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 klips2-design.txt

📁 网上下到的一个很详细介绍VPN基础知识的资料
💻 TXT
📖 第 1 页 / 共 2 页
字号:
* NetFilter overview:The basic architecture of NetFilter is:       --->[1]--->(ROUTE)--->[3]--->[4]--->     where:                     |            ^             [1] NF_IP_PRE_ROUTING                     |            |             [2] NF_IP_LOCAL_IN                     |         (ROUTE)          [3] NF_IP_FORWARD                     v            |             [4] NF_IP_POST_ROUTING                    [2]          [5]            [5] NF_IP_LOCAL_OUT                     |            ^                                  |            |                                  v            |             Destination NAT (port forwarding) gets applied in NF_IP_PRE_ROUTING andNF_IP_LOCAL_OUT at priority NF_IP_PRIORITY_DNAT = -100, and Source NAT(masquerading) gets applied in NF_IP_POST_ROUTING at priorityNF_IP_PRIORITY_SNAT = 100, .  Filtering is applied in NF_IP_LOCAL_IN,NF_IP_FORWARD and NF_IP_LOCAL_OUT at priority NF_IP_PRIORITY_FILTER = 0.Hook processing order would generally be:<PRE>PRE	IN	FWD	OUT	POST	PRIORITY MACRO         PRI=======.=======.=======.=======.=======.=================== = ====-500?  .       .       .       .       .NF_IP_PRI_IPSEC_IN  = -500 (?)-200   .       .       .-200   .       .NF_IP_PRI_CONNTRACK = -200-175? . . . . . . . . . . . . . . . . .	NF_IP_PRI_IPSEC_IN  = -175 (?)-150   .       .       .-150   .       .NF_IP_PRI_MANGLE    = -150-100   .       .       .-100   .       .NF_IP_PRI_NAT_DST   = -100. . . . . .0. . . .0. .	. .0. . . . . . NF_IP_PRI_FILTER    =    0       .       .       .       . 100   .NF_IP_PRI_NAT_SRC   =  100       .       .       .       . 500   .NF_IP_PRI_IPSEC_OUT =  500=======.=======.=======.=======.=======.=================== = ====</PRE>Not all modules are present at each hook.  I am uncertain still if IPSEC_INshould be before or after CONNTRACK.  Any comments?* IPSec path description:Treat incoming IPSec encapsulation as a transport layer protocol anddecapsulate it at the transport layer demultiplexer since it appears as atransport layer protocol from the bottom of the Internet Protocol networkstack.  For outgoing, we treat IPSec as a network layer protocol since that iswhat IPSec appears to be from the top of the IP stack.An incoming packet starts off with a sanity check.  It then goes through allthe NF_IP_PRE_ROUTING hooks starting with the SPDB checking.  It would haveseveral possible targets: DROP; REJECT; ACCEPT; PEEK.  DROP, REJECT, ACCEPTare standard NetFilter targets.  It would DROP if it should have beenencrypted.  REJECT is a special case of DROP where an ICMP is returned.  Itwould ACCEPT if it was an encrypted IPSec packet bound for this machine and noother policy was expected first, it had already been decrypted from expectedSAs indicated by nfmarks or virtual IPSec device or there was policy to allowit through.  PEEK would let the KMd have a look at the packet to see if itneeded to start thinking about opportunistic and then pass it on.  Since it isa fresh ESP or AH packet, it will not have any nfmarks or virtual IPSec deviceassociation and unless that outer IP header should have been processed byanother SG in between, no policy will have been required, letting it through.The rest of the NF_IP_PRE_ROUTING hooks may cause it to be DNATed anddefragmented.  It then goes through routing which thinks it is a local packet,deals with any outer header IP options, then defragmentation andNF_IP_LOCAL_IN filter (allow ESP,AH) before getting to ipsec_rcv() where theouter bundle is authenticated and decrypted and nfmarked or associated with avirtual IPSec device to indicate what decapsulation happenned before beingpassed back to netif_rx().  The next IP header is now visible.  The packet nowgets re-injected at the beginning.  It goes through the incoming sanity checkagain, getting checked at NF_IP_PRE_ROUTING for policy using previously setnfmark or virtual IPSec device from decryption.  It may again be DNATed anddefragmented.  Routing looks at the now-visible next IP header and routes itlocally or via the forward hook.If it is a local packet, IP options and defragmentation are processed.NF_IP_LOCAL_IN then gets to check filtering policy for other transport layerprotocols.  If it is the endpoint for nested bundles, it is sent back tonetif_rx(), having exposed the next IP header.If it is not a local packet, routing has selected a route, potentially throughan existing virtual IPSec device, one per connection, not per physical I/F.IP options and TTL are processed before being filtered at NF_IP_FORWARD,fragmented, then sent to NF_IP_POST_ROUTING.If it is a locally generated packet, it would go through normal filtering atNF_IP_LOCAL_OUT, then go through routing, then be sent to NF_IP_POST_ROUTING.At NF_IP_POST_ROUTING, the ipsec table would make a decision about the fate ofthe packet.  It would have several possible targets: ACCEPT; IPSEC SAList;DROP; REJECT; TRAP; HOLD.  ACCEPT would allow the packet through with noprocessing.  IPSEC would return NF_STOLEN, stealing the packet and applyingthe policy specified by its parameter of an SA list.  If the SA(s) do(es)n'texist(s) or if the TRAP target was specified, it would send up an ACQUIRE toall listening key management daemons via PF_KEYv2 and put in a HOLD that wouldkeep only the last packet that matched for that HOLD, waiting for theappropriate SA(s).  If or once the SA(s) is/are available, it then IPSecprocesses the packet, then re-injects the packet at NF_IP_LOCAL_OUT (since thepacket now appears to originate from this host) and sets nfmark or associatesit with a virtual IPSec device to indicate what processing happenned.  Thepacket would then be routed and sent back to NF_IP_POST_ROUTING.  If the IPSecremote security gateway is not different upon policy lookup, the ipsec tablewould ACCEPT it.  DROP would drop the packet if previous attempts to doopportunistic encryption failed and the default policy was to block non-IPSecpackets.  REJECT would be almost the same as DROP, except that it returnsICMPs.  ACCEPT, DROP, REJECT are standard NetFilter targets.A packet routed through an optional IPSec virtual I/F simply gets assigned aspecific source address, and has the nfmark/SA list preloaded.* Other issues:The way that nfmark is used is rather vague.  It is presently only 32 bits.Ideally, I would like to be able to indicate exactly which SAs were processedon the way in, which would most easily be represented by as many as 4 SAs (AH,ESP, IPCOMP, IPIP), each having an 8 bit protocol field (absolute minimum of2-bits), 32-bit destination address field (for IPv4, IPv6 would be 128) and a32-bit SPI.  This is a potential maximum of 672 bits.  A way of mapping 672bits on to the 32 bits available would be required to use this.  A lookuptable could be used to map nfmarks to SAIDs, not the SAs themselves, since theSAs could disappear at any time the SADB is not locked.  It should beable to represent a bundle of SAs where one SA could be used in more than onebundle.  There could also be more than one right answer for the incoming SPDB.I have an idea how to accomplish this by changing/extending nfmark byconverting it to a list of nfmark structures that contain a pointer to thenext item on the list, a cookie for the specific netfilter function that ownsthe data and a pointer to a data structure.nfmark may not be the right tool for this.  Another possible solution is toadd a member to the struct sk_buff to point to this information.  This has thebenefit of not depending on anyone else, but the drawback of needing to patcha header file *and recompiling the entire kernel*.  There is also thepossibility of using the NetFilter Connection Tracking facility.The SADB would be managed via the PF_KEYv2 socket I/F.The SPDB would be managed via a combination of PF_KEYv2 socket I/F extensionsand iptables.  A separate NetFilter table called 'ipsec' (as opposed to'filter', 'nat' or 'mangle') would have the first hook at NF_IP_PRE_ROUTINGand the last hook at NF_IP_POST_ROUTING.  iptables(8) currently usesget/set_sockopt(2) system calles, but there is discussion of having itconverted to use the AF_NETLINK socket family.  Having it use a PF_POLICYinterface that was interoperable with multiple platforms would be a big win.For matches, we have source/destination address/mask/port, userid (owner) andsecurity label.  source/destination address/mask/port and userid are alreadysupplied by iptables.  We only need to supply security label, if we even thinkwe need it.For targets, how do we do this?  SPDB with policies, or name specific SAs, SAchains or SA lists or even virtual IPSec devices.  Currently, we name specificSAs which are chained exclusively together. We could have a target iptables library and kernel module that has a target ofIPSEC which:	1. names a specific SA/chain which are unsharable	2. lists SAs to apply which are sharable	3. names a specific virtual IPSec device which implies a list of SAs	4. spec's req'd policy, ie.: cipher, hash, shared?, remote gw		(pfs should not be and option) I am favouring option number 2.  Option number 3 would map to number 2 in theSPDB. SAs would still be stored in a SADB hash table.  The prev and next fields ofstruct ipsec_sa would be removed if SAs were no longer chained, but werelisted in lists, either from a direct list, virtual IPSec device or from anSPDB.We could use one table for ipsec matching or maybe use one table for each ofipsec_in and ipsec_out.  It would have to use a table separate from filter,nat or mangle since we need an input NF_IP_PREROUTE priority of less than -200(CONNTRACK) and an output NF_IP_POST_ROUTING priority of more than 200(CONNTRACK?).  I suggest NF_IP_PRIORITY_IPSEC_IN = -500 andNF_IP_PRIORITY_IPSEC_OUT = 500.There might be a security level iptables library and netfilter kernelmodule, if needed.There would be "IPSEC", "TRAP" and "HOLD" iptables target librariesand netfilter target kernel modules.Equivalent ipsec_rcv() functionality would be installed as an IPtransport layer protocol handler and be included with the netfilteripsec table module.Equivalent ipsec_tunnel_start_xmit() functionality would be in theIPSEC netfilter target kernel module.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -