110 likes | 316 Views
Concept of sockets. Reading: Chapter 26. Sockets. Common interface network programming Underneath, there are lots of protocol specific sockets (protocol families) PF_INET (for Internet protocol family) PF_PACKET (for directly accessing network device)
E N D
Concept of sockets Reading: Chapter 26 FSU CIS 5930 Internet Protocols
Sockets • Common interface network programming • Underneath, there are lots of protocol specific sockets (protocol families) • PF_INET (for Internet protocol family) • PF_PACKET (for directly accessing network device) • PF_NETLINK (not for transporting data, but rather for configuring Linux network kernel) FSU CIS 5930 Internet Protocols
BSD sockets BSD Sockets PF_INET sockets PF_PACKET PF_NETLINK … SOCK_STREAM SOCK_DGRAM SOCK_RAW NETLINK_ROUTE NETLINK_SKIP NETLINK_USERSOCK NETLINK_FIREWALL NETLINK_ARPD NETLINK_ROUTE6 NETLINK_IP6_FW NETLINK_DNRTMSG NETLINK_TAPBASE TCP UDP IP Network device FSU CIS 5930 Internet Protocols
sys_socketcall() • Linux kernel has only one socket-related system call • sys_socketcall(int call, unsigned long *args) • Parameter “call” specifies the desired call (function) • SYS_SOCKET, SYS_BIND, SYS_CONNECT … • sys_socketcall dispatch processing to different functions based on “call” FSU CIS 5930 Internet Protocols
Socket structure Struct socket { socket_state state; unsigned long flags; struct proto_ops *ops; struct inode *inode; struct fasync_struct *fasync_list; struct file *file; struct sock *sk; wait_queue_head_t wait; short type; unsigned char passcred } FSU CIS 5930 Internet Protocols
What happens when you call socket() • In socket programming library • socket() sys_socketcall(SYS_SOCKET, ) • In sys_socketcall(): • case SYS_SOCKET: • sys_socket() • sys_socket() • Create/initialize socket structure (sock_create) • Allocate file descriptor (sock_map_fd()) FSU CIS 5930 Internet Protocols
sock_create/sock_map_fd • sock_create() • Some sanity checking • Allocating socket structure/inode (sock_alloc()) • Calling net_faimilies[family]->create() for family specific handling • sock_alloc() • Reserving an inode, allocating/initializing socket structure • Sock_map_fd() • Allocating file descriptor, filling in the file entry FSU CIS 5930 Internet Protocols
Protocol specific create() • Filling other fields of socket structure • In particular, struct proto_ops *ops; • Protocol specific function processing, such bind, connect, etc. • Example of processing flow: sendto() socket call • sys_socketcall(SYS_SENDTO, ) • sys_sendto() • sock_sendmsg() • sock->ops->sendmsg() FSU CIS 5930 Internet Protocols
Protocol specific sockets • Central structure of all protocol specific sockets • struct sock • PF_INET • PF_PACKET • PF_NETLINK FSU CIS 5930 Internet Protocols
PF_INET sockets • inet_create() • Initializing sock structure • Filling in protocol specific ops • Filling in transport protocol specific functions, if desirable. FSU CIS 5930 Internet Protocols
PF_PACKET • By passing transport and network layers • Packet_sendmsg() • It will directly access the network device • dev_queue_xmit() • Similarly, packets passed to application directly • packet_rcv() is installed for incoming packets FSU CIS 5930 Internet Protocols