1 / 68

Linux Networking

Linux Networking. High Speed Network Lab canaan@totoro.cs.nthu.edu.tw 939609 高迦南 946321 賴昇鴻 944361 陳世興. Outline. Introduction BSD Socket Interface Packet Sending Packet Receiving Packet Forwarding NAT Implementation References. Outline. Introduction BSD Socket Interface

gamba
Télécharger la présentation

Linux Networking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linux Networking High Speed Network Lab canaan@totoro.cs.nthu.edu.tw 939609 高迦南 946321 賴昇鴻 944361 陳世興

  2. Outline • Introduction • BSD Socket Interface • Packet Sending • Packet Receiving • Packet Forwarding • NAT Implementation • References Linux Networking

  3. Outline • Introduction • BSD Socket Interface • Packet Sending • Packet Receiving • Packet Forwarding • NAT Implementation • References Linux Networking

  4. Introduction 1Source Lines of Linux 2.6.5 Linux Networking

  5. Introduction 2 Source Lines of Linux 2.6.5 Drivers Top 7 Linux Networking

  6. Introduction 3 • 6% (244,421 lines) of all kernel code is devoted to networking(L3L4,Tcp/Ip Stack). • 10.1% (409,618 lines) of all kernel code is devoted to networking driver (L2). • The data are generated using David A. Wheeler's 'SLOCCount'. Linux Networking

  7. Process 2: Data Link Interface Layer (Ethernet, etc.) NIC driver (MAC Layer) Introduction 4Linux Networking Layers TCP / IP vs. OSI model 7: Application 6: Presentation 5: Session User Space BSD socket API 4: Transport 3: Network TCP/IP Stack Kernel Space 1: Physical Layer Linux Networking

  8. Outline • Introduction • BSD Socket Interface • Packet Sending • Packet Receiving • Packet Forwarding • NAT Implementation • References Linux Networking

  9. BSD Socket Interfacecygwin 1.5.9 /usr/include/sys/socket.h Linux Networking

  10. BSD Socket InterfaceLinux System Call Linux Networking

  11. BSD Socket Interface syscall_handler_t *sys_call_table[] Linux Networking

  12. BSD Socket Interface syscall_handler_t *sys_call_table[] Linux Networking

  13. BSD Socket Interface Linux Socket System Calllinux-2.6.2\net\socket.c Linux Networking

  14. BSD Socket Interface Socket Layer Detail Relation Linux Networking

  15. linux-2.6.2\net\socket.c Linux Networking

  16. BSD Socket Interface Sockfd_lookup() Linux Networking

  17. BSD Socket Interface linux-2.6.2\include\linux\net.h Linux Networking

  18. BSD Socket Interface BSD socket,proto_opslinux-2.6.2\include\linux\net.h Linux Networking

  19. BSD Socket Interface Linux Networking

  20. What is the sk->sk_prot->connect()? Linux Networking

  21. Process 2: Data Link Interface Layer (Ethernet, etc.) NIC driver (MAC Layer) Linux Networking LayersCurrent Tracing Pointer TCP / IP vs. OSI model 7: Application 6: Presentation 5: Session User Space BSD socket API 4: Transport 3: Network TCP/IP Stack Kernel Space 1: Physical Layer Linux Networking

  22. Outline • Introduction • BSD Socket Interface • Packet Sending (TCP) • Packet Receiving • Packet Forwarding • NAT Implementation • References Linux Networking

  23. Linux Networking

  24. Packet Sending (TCP)Tcp Ops Linux Networking

  25. Packet Sending (TCP)L4 Tcp Header Linux Networking

  26. linux-2.6.2\net\ipv4\tcp_ipv4.c Linux Networking

  27. linux-2.6.2\net\ipv4\tcp_ipv4.ctcp_v4_connect() • checks for errors • calls ip_route_connect() to find route to destination • creates connection packet • calls tcp_connect() to send packet Linux Networking

  28. linux-2.6.2\net\ipv4\tcp_output.c Linux Networking

  29. linux-2.6.2\net\ipv4\tcp_output.c tcp_connect() • completes connection packet with appropriate bits and window sizes set • puts packet on socket output queue • calls tcp_transmit_skb() to send packet, initiating TCP connection Linux Networking

  30. // include/linux/skbuff.h struct sk_buff { struct sk_buff *next; struct sk_buff *prev; unsigned char *head; unsigned char *data; unsigned char *tail; unsigned char *end; struct sk_buff_head *list; struct sock *sk; struct timeval stamp; struct net_device *dev; /* Transport layer header */ union { struct tcphdr *th; struct udphdr *uh; struct icmphdr *icmph; struct igmphdr *igmph; struct iphdr *ipiph; struct spxhdr *spxh; unsigned char *raw; } h; sk_buff Sock buffer? Packet buffer? Linux Networking

  31. /* Network layer header */ union { struct iphdr *iph; struct ipv6hdr *ipv6h; struct arphdr *arph; struct ipxhdr *ipxh; unsigned char *raw; } nh; /* Link layer header */ union { struct ethhdr *ethernet; unsigned char *raw; } mac; struct dst_entry *dst; unsigned int len; unsigned int data_len; unsigned int csum; }; sk_buff Sock buffer? Packet buffer? Linux Networking

  32. linux-2.6.2\net\ipv4\tcp_output.c Linux Networking

  33. linux-2.6.2\net\ipv4\tcp_output.ctcp_transmit_skb() • builds TCP header and adds checksum • calls tcp_build_and_update_options() • checks ACKs,SYN • calls tp->af_specific->queue_xmit() Linux Networking

  34. Packet Sending (IP)L3 IP Header Linux Networking

  35. Linux Networking

  36. linux-2.6.2/net/ipv4/ip_output.cip_queue_xmit() • looks up route • builds IP header • fragments if required • adds IP checksum • Enter NetFilter LocalOut Hook • calls dst_output() “calls skb->dst->output() ” Linux Networking

  37. Process 2: Data Link Interface Layer (Ethernet, etc.) NIC driver (MAC Layer) Linux Networking LayersCurrent Tracing Pointer TCP / IP vs. OSI model 7: Application 6: Presentation 5: Session User Space BSD socket API 4: Transport 3: Network TCP/IP Stack Kernel Space 1: Physical Layer Linux Networking

  38. After ip_queue_xmit() Linux Networking

  39. Outline • Introduction • BSD Socket Interface • Packet Sending (TCP) • Packet Receiving • Packet Forwarding • NAT Implementation • References Linux Networking

  40. Linux Networking

  41. L3 NetFilter Architecture Linux Networking

  42. L3 NetFilter Function View Linux Networking

  43. Process 2: Data Link Interface Layer (Ethernet, etc.) NIC driver (MAC Layer) Linux Networking LayersCurrent Tracing Pointer TCP / IP vs. OSI model 7: Application 6: Presentation 5: Session User Space BSD socket API 4: Transport 3: Network TCP/IP Stack Kernel Space 1: Physical Layer Linux Networking

  44. eth_type_trans() … Linux Networking

  45. After eth_type_trans() IP_Header Linux Networking

  46. netif_rx() (1) enqueue (2) Send NET_RX_SOFTIRQ to interrupt handler (排隊) NET_RX_SOFTIRQ netif_rx() Kernel Interrupt handler sk_buff driver packet net_rx_action() … Cpu queue Linux Networking

  47. net_rx_action • Extracts the first packet from the queueuntil the queue is empty • Detemines the network layer protocol number • Invokes a suitable function of the network layer protocol (ip_rcv) Linux Networking

  48. ip_rcv() 1. check length and checksum of the packet and disgards it if it is corrupted 2. Invoke ip_route_input => determines whether the packet (1) must be forwarded to another host (2) pass to a protocal of transport layer Linux Networking

  49. ip_rcv_finish() ip_route_input() ip_route_input_slow() IN_DEV_FORWARD Ip_forward() Ip_local_deliver Linux Networking

  50. Outline • Introduction • BSD Socket Interface • Packet Sending (TCP) • Packet Receiving • Packet Forwarding • NAT Implementation • References Linux Networking

More Related