Path: blob/master/include/net/inet_connection_sock.h
10817 views
/*1* NET Generic infrastructure for INET connection oriented protocols.2*3* Definitions for inet_connection_sock4*5* Authors: Many people, see the TCP sources6*7* From code originally in TCP8*9* This program is free software; you can redistribute it and/or10* modify it under the terms of the GNU General Public License11* as published by the Free Software Foundation; either version12* 2 of the License, or (at your option) any later version.13*/14#ifndef _INET_CONNECTION_SOCK_H15#define _INET_CONNECTION_SOCK_H1617#include <linux/compiler.h>18#include <linux/string.h>19#include <linux/timer.h>20#include <linux/poll.h>2122#include <net/inet_sock.h>23#include <net/request_sock.h>2425#define INET_CSK_DEBUG 12627/* Cancel timers, when they are not required. */28#undef INET_CSK_CLEAR_TIMERS2930struct inet_bind_bucket;31struct tcp_congestion_ops;3233/*34* Pointers to address related TCP functions35* (i.e. things that depend on the address family)36*/37struct inet_connection_sock_af_ops {38int (*queue_xmit)(struct sk_buff *skb, struct flowi *fl);39void (*send_check)(struct sock *sk, struct sk_buff *skb);40int (*rebuild_header)(struct sock *sk);41int (*conn_request)(struct sock *sk, struct sk_buff *skb);42struct sock *(*syn_recv_sock)(struct sock *sk, struct sk_buff *skb,43struct request_sock *req,44struct dst_entry *dst);45struct inet_peer *(*get_peer)(struct sock *sk, bool *release_it);46u16 net_header_len;47u16 sockaddr_len;48int (*setsockopt)(struct sock *sk, int level, int optname,49char __user *optval, unsigned int optlen);50int (*getsockopt)(struct sock *sk, int level, int optname,51char __user *optval, int __user *optlen);52#ifdef CONFIG_COMPAT53int (*compat_setsockopt)(struct sock *sk,54int level, int optname,55char __user *optval, unsigned int optlen);56int (*compat_getsockopt)(struct sock *sk,57int level, int optname,58char __user *optval, int __user *optlen);59#endif60void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);61int (*bind_conflict)(const struct sock *sk,62const struct inet_bind_bucket *tb);63};6465/** inet_connection_sock - INET connection oriented sock66*67* @icsk_accept_queue: FIFO of established children68* @icsk_bind_hash: Bind node69* @icsk_timeout: Timeout70* @icsk_retransmit_timer: Resend (no ack)71* @icsk_rto: Retransmit timeout72* @icsk_pmtu_cookie Last pmtu seen by socket73* @icsk_ca_ops Pluggable congestion control hook74* @icsk_af_ops Operations which are AF_INET{4,6} specific75* @icsk_ca_state: Congestion control state76* @icsk_retransmits: Number of unrecovered [RTO] timeouts77* @icsk_pending: Scheduled timer event78* @icsk_backoff: Backoff79* @icsk_syn_retries: Number of allowed SYN (or equivalent) retries80* @icsk_probes_out: unanswered 0 window probes81* @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options)82* @icsk_ack: Delayed ACK control data83* @icsk_mtup; MTU probing control data84*/85struct inet_connection_sock {86/* inet_sock has to be the first member! */87struct inet_sock icsk_inet;88struct request_sock_queue icsk_accept_queue;89struct inet_bind_bucket *icsk_bind_hash;90unsigned long icsk_timeout;91struct timer_list icsk_retransmit_timer;92struct timer_list icsk_delack_timer;93__u32 icsk_rto;94__u32 icsk_pmtu_cookie;95const struct tcp_congestion_ops *icsk_ca_ops;96const struct inet_connection_sock_af_ops *icsk_af_ops;97unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);98__u8 icsk_ca_state;99__u8 icsk_retransmits;100__u8 icsk_pending;101__u8 icsk_backoff;102__u8 icsk_syn_retries;103__u8 icsk_probes_out;104__u16 icsk_ext_hdr_len;105struct {106__u8 pending; /* ACK is pending */107__u8 quick; /* Scheduled number of quick acks */108__u8 pingpong; /* The session is interactive */109__u8 blocked; /* Delayed ACK was blocked by socket lock */110__u32 ato; /* Predicted tick of soft clock */111unsigned long timeout; /* Currently scheduled timeout */112__u32 lrcvtime; /* timestamp of last received data packet */113__u16 last_seg_size; /* Size of last incoming segment */114__u16 rcv_mss; /* MSS used for delayed ACK decisions */115} icsk_ack;116struct {117int enabled;118119/* Range of MTUs to search */120int search_high;121int search_low;122123/* Information on the current probe. */124int probe_size;125} icsk_mtup;126u32 icsk_ca_priv[16];127u32 icsk_user_timeout;128#define ICSK_CA_PRIV_SIZE (16 * sizeof(u32))129};130131#define ICSK_TIME_RETRANS 1 /* Retransmit timer */132#define ICSK_TIME_DACK 2 /* Delayed ack timer */133#define ICSK_TIME_PROBE0 3 /* Zero window probe timer */134135static inline struct inet_connection_sock *inet_csk(const struct sock *sk)136{137return (struct inet_connection_sock *)sk;138}139140static inline void *inet_csk_ca(const struct sock *sk)141{142return (void *)inet_csk(sk)->icsk_ca_priv;143}144145extern struct sock *inet_csk_clone(struct sock *sk,146const struct request_sock *req,147const gfp_t priority);148149enum inet_csk_ack_state_t {150ICSK_ACK_SCHED = 1,151ICSK_ACK_TIMER = 2,152ICSK_ACK_PUSHED = 4,153ICSK_ACK_PUSHED2 = 8154};155156extern void inet_csk_init_xmit_timers(struct sock *sk,157void (*retransmit_handler)(unsigned long),158void (*delack_handler)(unsigned long),159void (*keepalive_handler)(unsigned long));160extern void inet_csk_clear_xmit_timers(struct sock *sk);161162static inline void inet_csk_schedule_ack(struct sock *sk)163{164inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;165}166167static inline int inet_csk_ack_scheduled(const struct sock *sk)168{169return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;170}171172static inline void inet_csk_delack_init(struct sock *sk)173{174memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));175}176177extern void inet_csk_delete_keepalive_timer(struct sock *sk);178extern void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);179180#ifdef INET_CSK_DEBUG181extern const char inet_csk_timer_bug_msg[];182#endif183184static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)185{186struct inet_connection_sock *icsk = inet_csk(sk);187188if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {189icsk->icsk_pending = 0;190#ifdef INET_CSK_CLEAR_TIMERS191sk_stop_timer(sk, &icsk->icsk_retransmit_timer);192#endif193} else if (what == ICSK_TIME_DACK) {194icsk->icsk_ack.blocked = icsk->icsk_ack.pending = 0;195#ifdef INET_CSK_CLEAR_TIMERS196sk_stop_timer(sk, &icsk->icsk_delack_timer);197#endif198}199#ifdef INET_CSK_DEBUG200else {201pr_debug("%s", inet_csk_timer_bug_msg);202}203#endif204}205206/*207* Reset the retransmission timer208*/209static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,210unsigned long when,211const unsigned long max_when)212{213struct inet_connection_sock *icsk = inet_csk(sk);214215if (when > max_when) {216#ifdef INET_CSK_DEBUG217pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",218sk, what, when, current_text_addr());219#endif220when = max_when;221}222223if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {224icsk->icsk_pending = what;225icsk->icsk_timeout = jiffies + when;226sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);227} else if (what == ICSK_TIME_DACK) {228icsk->icsk_ack.pending |= ICSK_ACK_TIMER;229icsk->icsk_ack.timeout = jiffies + when;230sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);231}232#ifdef INET_CSK_DEBUG233else {234pr_debug("%s", inet_csk_timer_bug_msg);235}236#endif237}238239extern struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);240241extern struct request_sock *inet_csk_search_req(const struct sock *sk,242struct request_sock ***prevp,243const __be16 rport,244const __be32 raddr,245const __be32 laddr);246extern int inet_csk_bind_conflict(const struct sock *sk,247const struct inet_bind_bucket *tb);248extern int inet_csk_get_port(struct sock *sk, unsigned short snum);249250extern struct dst_entry* inet_csk_route_req(struct sock *sk,251struct flowi4 *fl4,252const struct request_sock *req);253extern struct dst_entry* inet_csk_route_child_sock(struct sock *sk,254struct sock *newsk,255const struct request_sock *req);256257static inline void inet_csk_reqsk_queue_add(struct sock *sk,258struct request_sock *req,259struct sock *child)260{261reqsk_queue_add(&inet_csk(sk)->icsk_accept_queue, req, sk, child);262}263264extern void inet_csk_reqsk_queue_hash_add(struct sock *sk,265struct request_sock *req,266unsigned long timeout);267268static inline void inet_csk_reqsk_queue_removed(struct sock *sk,269struct request_sock *req)270{271if (reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req) == 0)272inet_csk_delete_keepalive_timer(sk);273}274275static inline void inet_csk_reqsk_queue_added(struct sock *sk,276const unsigned long timeout)277{278if (reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue) == 0)279inet_csk_reset_keepalive_timer(sk, timeout);280}281282static inline int inet_csk_reqsk_queue_len(const struct sock *sk)283{284return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);285}286287static inline int inet_csk_reqsk_queue_young(const struct sock *sk)288{289return reqsk_queue_len_young(&inet_csk(sk)->icsk_accept_queue);290}291292static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)293{294return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);295}296297static inline void inet_csk_reqsk_queue_unlink(struct sock *sk,298struct request_sock *req,299struct request_sock **prev)300{301reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req, prev);302}303304static inline void inet_csk_reqsk_queue_drop(struct sock *sk,305struct request_sock *req,306struct request_sock **prev)307{308inet_csk_reqsk_queue_unlink(sk, req, prev);309inet_csk_reqsk_queue_removed(sk, req);310reqsk_free(req);311}312313extern void inet_csk_reqsk_queue_prune(struct sock *parent,314const unsigned long interval,315const unsigned long timeout,316const unsigned long max_rto);317318extern void inet_csk_destroy_sock(struct sock *sk);319320/*321* LISTEN is a special case for poll..322*/323static inline unsigned int inet_csk_listen_poll(const struct sock *sk)324{325return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ?326(POLLIN | POLLRDNORM) : 0;327}328329extern int inet_csk_listen_start(struct sock *sk, const int nr_table_entries);330extern void inet_csk_listen_stop(struct sock *sk);331332extern void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);333334extern int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,335char __user *optval, int __user *optlen);336extern int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,337char __user *optval, unsigned int optlen);338#endif /* _INET_CONNECTION_SOCK_H */339340341