Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


❑ typespecifies the numeric identifier of the protocol type.
❑ stateindicates the connection state of the socket by means of the following values (SSstands for
socket state):
<net.h>
typedef enum {
SS_FREE = 0, /* not allocated */
SS_UNCONNECTED, /* unconnected to any socket */
SS_CONNECTING, /* in process of connecting */
SS_CONNECTED, /* connected to socket */
SS_DISCONNECTING /* in process of disconnecting */
} socket_state;
The values listed here havenothingin common with the state values used by the protocols of the
transport layer when connections are set up and closed. They denote general states relevant to
the outside world (i.e., to user programs).
❑ fileis a pointer to thefileinstance of a pseudo-file for communication with the socket (as
discussed earlier, user applications use normal file descriptors to perform network operations).

The definition ofsocketis not tied to a specific protocol. This explains whyproto_opsis used as a
pointer to a data structure that, in turn, holds pointers to protocol-specific functions to handle the socket:


struct proto_ops {
int family;
struct module *owner;
int (*release) (struct socket *sock);
int (*bind) (struct socket *sock,
struct sockaddr *myaddr,
int sockaddr_len);
int (*connect) (struct socket *sock,
struct sockaddr *vaddr,
int sockaddr_len, int flags);
int (*socketpair)(struct socket *sock1,
struct socket *sock2);
int (*accept) (struct socket *sock,
struct socket *newsock, int flags);
int (*getname) (struct socket *sock,
struct sockaddr *addr,
int *sockaddr_len, int peer);
unsigned int (*poll) (struct file *file, struct socket *sock,
struct poll_table_struct *wait);
int (*ioctl) (struct socket *sock, unsigned int cmd,
unsigned long arg);
int (*compat_ioctl) (struct socket *sock, unsigned int cmd,
unsigned long arg);
int (*listen) (struct socket *sock, int len);
int (*shutdown) (struct socket *sock, int flags);
int (*setsockopt)(struct socket *sock, int level,
int optname, char __user *optval, int optlen);
int (*getsockopt)(struct socket *sock, int level,
Free download pdf