1 / 19

Network Implementation

Network Implementation. 숭실대학교 네트워크 연구실 황진호. Outline. Network Overview Important structures BSD socket INET socket sk_buff. Overview. Network layer model. BSD socket layer provides a set of network related funtion

gari
Download Presentation

Network Implementation

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. Network Implementation 숭실대학교 네트워크 연구실 황진호

  2. Outline • Network Overview • Important structures • BSD socket • INET socket • sk_buff

  3. Overview

  4. Network layer model • BSD socket layer provides a set of network related funtion • INET layer manages the communcation end points for the IP based protocol TCP and UDP • TCP is Transmission Control protocol • UDP is User Datagram Protocol • Device is physical transmission

  5. Application, BSD and INET • Process • Using C command [ socket() ] • BSD socket • sock_create()는 AF에 따라 다음 호출될 함수를 결정한다. • INET socket • 만약 AF_INET이면 inet_create()를 호출한다.

  6. Socket systemcall structure socket() bind() connect() listen() accept() setsockopt() getsockopt() send() sendto() recv() recvfrom() shutdown() socketpair() …… sys_socket() sys_bind() sys_connect() sys_listen() sys_accept() sys_setsockopt() sys_getsockopt() sys_send() sys_sendto() sys_recv() sys_recvfrom() sys_shutdown() sys_socketpair() …… system call socketcall() sys_socketcall( call , *args) [ linux/net/socket.c ] kernel

  7. Network code TCP server TCP client start start socket() socket() bind() listen() connect() accept() read() write() end end

  8. socket() socket() [ net/socket.c ] sys_socket() check protocol, type, family sock_alloc() sock_create() create socket structure net_families[family]->create(sock, protocol) inet_create() [ net/ipv4/af_inet.c ] tcp_v4_ init_sock() get_fd() return

  9. socket() • socket( int domain, int type, int protocol ) • Domain : communication domain • PF_INET, PF_IPX ….. • Type : communication semantics • SOCK_STREAM, SOCK_DGRAM, SOCK_RAW • sys_socket( family, type , protocol ) • sock_create( family, type, protocol, struct socket * sock) • Sock_alloc : socket 구조체, inode 초기화 • net_families->create • inet_create( struct socket, protocol )

  10. socket() • inet_create( struct socket *sock, int protocol ) • sock->state = SS_UNCONNECTED; • sk = sk_alloc(PF_INET, GFP_KERNEL, 1); • switch (sock->type) { • case SOCK_STREAM: • protocol = IPPROTO_TCP; • prot = &tcp_prot; • sock->ops = &inet_stream_ops; • break;

  11. socket() inet_create() BSD socket INET socket struct socket{ } struct sock{ } *sk socket type protocol IPPROTO_{UDP, TCP, RAW} state family PF_INET . . . struct proto{ } *prot tcp_prot init() tcp_v4_init_sock() … more initialization . . [ include/linux/net.h ] tcp_prot (next) tcp_prot (prev) {udp, tcp, raw}_prot [ net/ipv4/tcp_ipv4.c ] [ include/net/sock.h ]

  12. socket() inet_create() [ include/linux/fs.h ] files_struct{ } struct file{ } struct file_operations{ } count read, write, lseek, … close_on_exec f_op open_fs **fd struct inode{ } struct sock{ } struct socket{ } [ include/linux/sched.h ]

  13. bind() [ net/socket.c ] bind() sys_bind() sock->ops->bind() inet_bind() Binding name to socket Name = port & address return

  14. listen() [ net/socket.c ] listen() sys_listen() sock->ops->listen() inet_listen() sk->state  TCP_LISTEN return

  15. connect() connect() sys_connect() sys_connect() [ net/socket.c ] sock->ops->connect() inet_stream_connect() for TCP SS_CONNECTING SS_UNCONNECTED inet_autobind() TCP state is TCP_ESTABLISHED, then socket state set to SS_CONNECTED tcp_v4_connect() tcp_connect() SS_CONNECTING If blockig mode, inet_wait_for_connect() return

  16. accept() accept() sys_connect() sys_accept() [ net/socket.c ] New socket duplication sock->ops->accept() inet_accept() tcp_accept() to new sk struct no Blocking mode? yes wait_for_connect() TCP state is TCP_ESTABLISHED, then socket state set to SS_CONNECTED return

  17. sk_buff() application socket recv buffer send buffer TCP/UDP User data 전달 Header 추가/삭제 Fragmentation Queueing/drop … IP Device driver ports [ net/core/skbuff.c ] [ include/linux/skbuff.h ]

  18. sk_buff() sk_buff_head { } struct sk_buff{ } *next *prev *list *sk data *dev union h Th, uh, icmph, igmph, spxh, raw union nh iph, ip6h, arph, ipxh, raw union mac ethernet, raw head data tail end (continued)

  19. Socket buffering Socket buffer  TCP/UDP IP  device struct sock{ } struct device{ } write_queue struct sk_buff_head{ } buffs[ ] *prev *next *next, *prev *next, *prev *next, *prev *linux kernel internals *sk *sk *sk *dev *dev *dev struct sk_buff { } struct sk_buff { } struct sk_buff { }

More Related