📄 sock.h
字号:
struct dn_scp dn;#endif#if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE) struct packet_opt *af_packet;#endif#if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE) x25_cb *x25;#endif#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) ax25_cb *ax25;#endif#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE) nr_cb *nr;#endif#if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE) rose_cb *rose;#endif#ifdef CONFIG_NETLINK struct netlink_opt af_netlink;#endif#if defined(CONFIG_ECONET) || defined(CONFIG_ECONET_MODULE) struct econet_opt *af_econet;#endif#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE) struct irda_sock *irda;#endif } protinfo; /* IP 'private area' or will be eventually. */ int ip_ttl; /* TTL setting */ int ip_tos; /* TOS */ unsigned ip_cmsg_flags; struct ip_options *opt; unsigned char ip_hdrincl; /* Include headers ? */ __u8 ip_mc_ttl; /* Multicasting TTL */ __u8 ip_mc_loop; /* Loopback */ __u8 ip_recverr; __u8 ip_pmtudisc; int ip_mc_index; /* Multicast device index */ __u32 ip_mc_addr; struct ip_mc_socklist *ip_mc_list; /* Group array */ /* This part is used for the timeout functions (timer.c). */ int timeout; /* What are we waiting for? */ struct timer_list timer; /* This is the sock cleanup timer. */ struct timeval stamp; /* Identd */ struct socket *socket; /* RPC layer private data */ void *user_data; /* Callbacks */ void (*state_change)(struct sock *sk); void (*data_ready)(struct sock *sk,int bytes); void (*write_space)(struct sock *sk); void (*error_report)(struct sock *sk); int (*backlog_rcv) (struct sock *sk, struct sk_buff *skb); void (*destruct)(struct sock *sk);};/* IP protocol blocks we attach to sockets. * socket layer -> transport layer interface * transport -> network interface is defined by struct inet_proto */struct proto { /* These must be first. */ struct sock *sklist_next; struct sock *sklist_prev; void (*close)(struct sock *sk, long timeout); int (*connect)(struct sock *sk, struct sockaddr *uaddr, int addr_len); struct sock * (*accept) (struct sock *sk, int flags); void (*retransmit)(struct sock *sk, int all); void (*write_wakeup)(struct sock *sk); void (*read_wakeup)(struct sock *sk); unsigned int (*poll)(struct file * file, struct socket *sock, struct poll_table_struct *wait); int (*ioctl)(struct sock *sk, int cmd, unsigned long arg); int (*init)(struct sock *sk); int (*destroy)(struct sock *sk); void (*shutdown)(struct sock *sk, int how); int (*setsockopt)(struct sock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct sock *sk, int level, int optname, char *optval, int *option); int (*sendmsg)(struct sock *sk, struct msghdr *msg, int len); int (*recvmsg)(struct sock *sk, struct msghdr *msg, int len, int noblock, int flags, int *addr_len); int (*bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len); int (*backlog_rcv) (struct sock *sk, struct sk_buff *skb); /* Keeping track of sk's, looking them up, and port selection methods. */ void (*hash)(struct sock *sk); void (*unhash)(struct sock *sk); int (*get_port)(struct sock *sk, unsigned short snum); unsigned short max_header; unsigned long retransmits; char name[32]; int inuse, highestinuse;};#define TIME_WRITE 1 /* Not yet used */#define TIME_RETRANS 2 /* Retransmit timer */#define TIME_DACK 3 /* Delayed ack timer */#define TIME_CLOSE 4#define TIME_KEEPOPEN 5#define TIME_DESTROY 6#define TIME_DONE 7 /* Used to absorb those last few packets */#define TIME_PROBE0 8/* About 10 seconds */#define SOCK_DESTROY_TIME (10*HZ)/* Sockets 0-1023 can't be bound to unless you are superuser */#define PROT_SOCK 1024#define SHUTDOWN_MASK 3#define RCV_SHUTDOWN 1#define SEND_SHUTDOWN 2/* Per-protocol hash table implementations use this to make sure * nothing changes. */#define SOCKHASH_LOCK() start_bh_atomic()#define SOCKHASH_UNLOCK() end_bh_atomic()/* Some things in the kernel just want to get at a protocols * entire socket list commensurate, thus... */static __inline__ void __add_to_prot_sklist(struct sock *sk){ struct proto *p = sk->prot; sk->sklist_prev = (struct sock *) p; sk->sklist_next = p->sklist_next; p->sklist_next->sklist_prev = sk; p->sklist_next = sk; /* Charge the protocol. */ sk->prot->inuse += 1; if(sk->prot->highestinuse < sk->prot->inuse) sk->prot->highestinuse = sk->prot->inuse;}static __inline__ void add_to_prot_sklist(struct sock *sk){ SOCKHASH_LOCK(); if(!sk->sklist_next) __add_to_prot_sklist(sk); SOCKHASH_UNLOCK();}static __inline__ void del_from_prot_sklist(struct sock *sk){ SOCKHASH_LOCK(); if(sk->sklist_next) { sk->sklist_next->sklist_prev = sk->sklist_prev; sk->sklist_prev->sklist_next = sk->sklist_next; sk->sklist_next = NULL; sk->prot->inuse--; } SOCKHASH_UNLOCK();}/* * Used by processes to "lock" a socket state, so that * interrupts and bottom half handlers won't change it * from under us. It essentially blocks any incoming * packets, so that we won't get any new data or any * packets that change the state of the socket. * * Note the 'barrier()' calls: gcc may not move a lock * "downwards" or a unlock "upwards" when optimizing. */extern void __release_sock(struct sock *sk);static inline void lock_sock(struct sock *sk){#if 0/* debugging code: the test isn't even 100% correct, but it can catch bugs *//* Note that a double lock is ok in theory - it's just _usually_ a bug *//* Actually it can easily happen with multiple writers */ if (atomic_read(&sk->sock_readers)) { printk("double lock on socket at %p\n", gethere());here: }#endif atomic_inc(&sk->sock_readers); synchronize_bh();}static inline void release_sock(struct sock *sk){ barrier(); if (atomic_dec_and_test(&sk->sock_readers)) __release_sock(sk);}/* * This might not be the most appropriate place for this two * but since they are used by a lot of the net related code * at least they get declared on a include that is common to all */static __inline__ int min(unsigned int a, unsigned int b){ if (a > b) a = b; return a;}static __inline__ int max(unsigned int a, unsigned int b){ if (a < b) a = b; return a;}extern struct sock * sk_alloc(int family, int priority, int zero_it);extern void sk_free(struct sock *sk);extern void destroy_sock(struct sock *sk);extern struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force, int priority);extern struct sk_buff *sock_rmalloc(struct sock *sk, unsigned long size, int force, int priority);extern void sock_wfree(struct sk_buff *skb);extern void sock_rfree(struct sk_buff *skb);extern unsigned long sock_rspace(struct sock *sk);extern unsigned long sock_wspace(struct sock *sk);extern int sock_setsockopt(struct socket *sock, int level, int op, char *optval, int optlen);extern int sock_getsockopt(struct socket *sock, int level, int op, char *optval, int *optlen);extern struct sk_buff *sock_alloc_send_skb(struct sock *sk, unsigned long size, unsigned long fallback, int noblock, int *errcode);extern void *sock_kmalloc(struct sock *sk, int size, int priority);extern void sock_kfree_s(struct sock *sk, void *mem, int size);/* * Functions to fill in entries in struct proto_ops when a protocol * does not implement a particular function. */extern int sock_no_dup(struct socket *, struct socket *);extern int sock_no_release(struct socket *, struct socket *);extern int sock_no_bind(struct socket *, struct sockaddr *, int);extern int sock_no_connect(struct socket *, struct sockaddr *, int, int);extern int sock_no_socketpair(struct socket *, struct socket *);extern int sock_no_accept(struct socket *, struct socket *, int);extern int sock_no_getname(struct socket *, struct sockaddr *, int *, int);extern unsigned int sock_no_poll(struct file *, struct socket *, struct poll_table_struct *);extern int sock_no_ioctl(struct socket *, unsigned int, unsigned long);extern int sock_no_listen(struct socket *, int);extern int sock_no_shutdown(struct socket *, int);extern int sock_no_getsockopt(struct socket *, int , int, char *, int *);extern int sock_no_setsockopt(struct socket *, int, int, char *, int);extern int sock_no_fcntl(struct socket *, unsigned int, unsigned long);extern int sock_no_sendmsg(struct socket *, struct msghdr *, int, struct scm_cookie *);extern int sock_no_recvmsg(struct socket *, struct msghdr *, int, struct scm_cookie *);/* * Default socket callbacks and setup code */ extern void sock_def_callback1(struct sock *);extern void sock_def_callback2(struct sock *, int);extern void sock_def_callback3(struct sock *);extern void sock_def_destruct(struct sock *);/* Initialise core socket variables */extern void sock_init_data(struct socket *sock, struct sock *sk);extern void sklist_remove_socket(struct sock **list, struct sock *sk);extern void sklist_insert_socket(struct sock **list, struct sock *sk);extern void sklist_destroy_socket(struct sock **list, struct sock *sk);#ifdef CONFIG_FILTER/* * Run the filter code and then cut skb->data to correct size returned by * sk_run_filter. If pkt_len is 0 we toss packet. If skb->len is smaller * than pkt_len we keep whole skb->data. */extern __inline__ int sk_filter(struct sk_buff *skb, struct sk_filter *filter){ int pkt_len; pkt_len = sk_run_filter(skb, filter->insns, filter->len); if(!pkt_len) return 1; /* Toss Packet */ else skb_trim(skb, pkt_len); return 0;}extern __inline__ void sk_filter_release(struct sock *sk, struct sk_filter *fp){ unsigned int size = sk_filter_len(fp); atomic_sub(size, &sk->omem_alloc); if (atomic_dec_and_test(&fp->refcnt)) kfree_s(fp, size);}extern __inline__ void sk_filter_charge(struct sock *sk, struct sk_filter *fp){ atomic_inc(&fp->refcnt); atomic_add(sk_filter_len(fp), &sk->omem_alloc);}#endif /* CONFIG_FILTER *//* * Queue a received datagram if it will fit. Stream and sequenced * protocols can't normally use this as they need to fit buffers in * and play with them. * * Inlined as it's very short and called for pretty much every * packet ever received. */extern __inline__ void skb_set_owner_w(struct sk_buff *skb, struct sock *sk){ skb->sk = sk; skb->destructor = sock_wfree; atomic_add(skb->truesize, &sk->wmem_alloc);}extern __inline__ void skb_set_owner_r(struct sk_buff *skb, struct sock *sk){ skb->sk = sk; skb->destructor = sock_rfree; atomic_add(skb->truesize, &sk->rmem_alloc);}extern __inline__ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb){#ifdef CONFIG_FILTER struct sk_filter *filter;#endif /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces number of warnings when compiling with -W --ANK */ if (atomic_read(&sk->rmem_alloc) + skb->truesize >= (unsigned)sk->rcvbuf) return -ENOMEM;#ifdef CONFIG_FILTER if ((filter = sk->filter) != NULL && sk_filter(skb, filter)) return -EPERM; /* Toss packet */#endif /* CONFIG_FILTER */ skb_set_owner_r(skb, sk); skb_queue_tail(&sk->receive_queue, skb); if (!sk->dead) sk->data_ready(sk,skb->len); return 0;}extern __inline__ int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb){ /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces number of warnings when compiling with -W --ANK */ if (atomic_read(&sk->rmem_alloc) + skb->truesize >= (unsigned)sk->rcvbuf) return -ENOMEM; skb_set_owner_r(skb, sk); skb_queue_tail(&sk->error_queue,skb); if (!sk->dead) sk->data_ready(sk,skb->len); return 0;}/* * Recover an error report and clear atomically */ extern __inline__ int sock_error(struct sock *sk){ int err=xchg(&sk->err,0); return -err;}extern __inline__ unsigned long sock_wspace(struct sock *sk){ int amt = 0; if (!(sk->shutdown & SEND_SHUTDOWN)) { amt = sk->sndbuf - atomic_read(&sk->wmem_alloc); if (amt < 0) amt = 0; } return amt;}/* * Default write policy as shown to user space via poll/select/SIGIO * Kernel internally doesn't use the MIN_WRITE_SPACE threshold. */extern __inline__ int sock_writeable(struct sock *sk) { return sock_wspace(sk) >= MIN_WRITE_SPACE;}/* * Declarations from timer.c */ extern struct sock *timer_base;extern void net_delete_timer (struct sock *);extern void net_reset_timer (struct sock *, int, unsigned long);extern void net_timer (unsigned long);extern __inline__ int gfp_any(void){ return in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;}/* * Enable debug/info messages */#if 1#define NETDEBUG(x) do { } while (0)#else#define NETDEBUG(x) do { x; } while (0)#endif#endif /* _SOCK_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -