200 likes | 382 Views
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
E N D
Network Implementation 숭실대학교 네트워크 연구실 황진호
Outline • Network Overview • Important structures • BSD socket • INET socket • sk_buff
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
Application, BSD and INET • Process • Using C command [ socket() ] • BSD socket • sock_create()는 AF에 따라 다음 호출될 함수를 결정한다. • INET socket • 만약 AF_INET이면 inet_create()를 호출한다.
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
Network code TCP server TCP client start start socket() socket() bind() listen() connect() accept() read() write() end end
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
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 )
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;
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 ]
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 ]
bind() [ net/socket.c ] bind() sys_bind() sock->ops->bind() inet_bind() Binding name to socket Name = port & address return
listen() [ net/socket.c ] listen() sys_listen() sock->ops->listen() inet_listen() sk->state TCP_LISTEN return
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
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
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 ]
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)
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 { }