• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Based on include/net/tcp.h
4  * Authors:	Ross Biro
5  *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
6  *
7  * Based on include/linux/tcp.h
8  * Author:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
9  *
10  *		This program is free software; you can redistribute it and/or
11  *		modify it under the terms of the GNU General Public License
12  *		as published by the Free Software Foundation; either version
13  *		2 of the License, or (at your option) any later version.
14  *
15  * NewIP INET
16  * An implementation of the TCP/IP protocol suite for the LINUX
17  * operating system. NewIP INET is implemented using the  BSD Socket
18  * interface as the means of communication with the user level.
19  *
20  * Definitions for the NewIP TCP module.
21  */
22 #ifndef _TCP_NIP_H
23 #define _TCP_NIP_H
24 
25 #define FASTRETRANS_DEBUG 1
26 
27 #include <linux/list.h>
28 #include <linux/tcp.h>
29 #include <linux/bug.h>
30 #include <linux/slab.h>
31 #include <linux/cache.h>
32 #include <linux/percpu.h>
33 #include <linux/skbuff.h>
34 #include <linux/kref.h>
35 #include <linux/ktime.h>
36 
37 #include <net/inet_connection_sock.h>
38 #include <net/inet_timewait_sock.h>
39 #include <net/inet_hashtables.h>
40 #include <net/checksum.h>
41 #include <net/request_sock.h>
42 #include <net/sock.h>
43 #include <net/snmp.h>
44 #include <net/ip.h>
45 #include <net/tcp_states.h>
46 #include <net/inet_ecn.h>
47 #include <net/dst.h>
48 
49 #include <net/tcp.h>
50 #include <net/nip.h>
51 #include <net/ninet_connection_sock.h>
52 #include <linux/seq_file.h>
53 #include <linux/memcontrol.h>
54 
55 extern struct proto tcp_nip_prot;
56 
57 #define TCP_HDR_LEN_OFFSET 6
58 #define TCP_HDR_LEN_POS_PAYLOAD 12
59 #define TCP_NIP_4BYTE_PAYLOAD 2
60 
61 #define TCP_OPT_MSS_PAYLOAD 24
62 #define TCP_OLEN_MSS_PAYLOAD 16
63 
64 #define TCP_NUM_2 2
65 #define TCP_NUM_4 4
66 
67 #define TCP_ARRAY_INDEX_2 2
68 
69 #define TCP_NIP_KEEPALIVE_CYCLE_MS_DIVISOR 20
70 #define TCP_NIP_CSK_KEEPALIVE_CYCLE 10
71 
72 #define TCP_NIP_WINDOW_MAX 65535U
73 
74 #define TCP_NIP_WRITE_TIMER_DEFERRED  (TCP_MTU_REDUCED_DEFERRED + 1)
75 #define TCP_NIP_DELACK_TIMER_DEFERRED (TCP_NIP_WRITE_TIMER_DEFERRED + 1)
76 
77 /* init */
78 int tcp_nip_init(void);
79 void tcp_nip_exit(void);
80 
81 void tcp_nip_done(struct sock *sk);
82 int tcp_direct_connect(struct sock *sk, void __user *arg);
83 void tcp_nip_rcv_established(
84 	struct sock *sk,
85 	struct sk_buff *skb,
86 	const struct tcphdr *th,
87 	unsigned int len);
88 
89 void __tcp_nip_push_pending_frames(
90 	struct sock *sk,
91 	unsigned int cur_mss,
92 	int nonagle);
93 
94 u32 __nip_tcp_select_window(struct sock *sk);
95 unsigned short nip_get_output_checksum_tcp(struct sk_buff *skb, struct nip_addr src_addr,
96 					   struct nip_addr dst_addr);
97 void tcp_nip_rearm_rto(struct sock *sk);
98 
99 int tcp_nip_rcv_state_process(struct sock *sk, struct sk_buff *skb);
100 
101 /* tcp_nip_output */
102 int tcp_nip_transmit_skb(
103 	struct sock *sk,
104 	struct sk_buff *skb,
105 	int clone_it,
106 	gfp_t gfp_mask);
107 int __tcp_nip_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs);
108 int tcp_nip_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs);
109 void tcp_nip_send_fin(struct sock *sk);
110 void tcp_nip_send_active_reset(struct sock *sk, gfp_t priority);
111 void tcp_nip_send_probe0(struct sock *sk);
112 int tcp_nip_write_wakeup(struct sock *sk, int mib);
113 
114 /* tcp_nip_timer */
115 void tcp_nip_init_xmit_timers(struct sock *sk);
116 void tcp_nip_clear_xmit_timers(struct sock *sk);
117 void tcp_nip_delack_timer_handler(struct sock *sk);
118 void tcp_nip_write_timer_handler(struct sock *sk);
119 void tcp_nip_check_space(struct sock *sk);
120 
tcp_nip_send_head(const struct sock * sk)121 static inline struct sk_buff *tcp_nip_send_head(const struct sock *sk)
122 {
123 	return sk->sk_send_head;
124 }
125 
tcp_nip_add_write_queue_tail(struct sock * sk,struct sk_buff * skb)126 static inline void tcp_nip_add_write_queue_tail(
127 	struct sock *sk,
128 	struct sk_buff *skb)
129 {
130 	__skb_queue_tail(&sk->sk_write_queue, skb);
131 
132 	if (sk->sk_send_head == NULL)
133 		sk->sk_send_head = skb;
134 }
135 
tcp_nip_write_queue_purge(struct sock * sk)136 static inline void tcp_nip_write_queue_purge(struct sock *sk)
137 {
138 	struct sk_buff *skb;
139 
140 	while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) {
141 		tcp_skb_tsorted_anchor_cleanup(skb);
142 		sk_wmem_free_skb(sk, skb);
143 	}
144 
145 	tcp_clear_all_retrans_hints(tcp_sk(sk));
146 	sk->sk_send_head = NULL;
147 	tcp_sk(sk)->packets_out = 0;
148 	inet_csk(sk)->icsk_backoff = 0;
149 }
150 
tcp_nip_write_queue_empty(struct sock * sk)151 static inline bool tcp_nip_write_queue_empty(struct sock *sk)
152 {
153 	return skb_queue_empty(&sk->sk_write_queue);
154 }
155 
tcp_nip_sk(const struct sock * sk)156 static inline struct tcp_nip_sock *tcp_nip_sk(const struct sock *sk)
157 {
158 	return (struct tcp_nip_sock *)sk;
159 }
160 
tcp_nip_rsk(const struct request_sock * req)161 static inline struct tcp_nip_request_sock *tcp_nip_rsk(const struct request_sock *req)
162 {
163 	return (struct tcp_nip_request_sock *)req;
164 }
165 
tcp_nip_modify_send_head(struct sock * sk,const struct sk_buff * skb)166 static inline void tcp_nip_modify_send_head(struct sock *sk, const struct sk_buff *skb)
167 {
168 	if (tcp_skb_is_last(sk, skb))
169 		sk->sk_send_head = NULL;
170 }
171 
172 /* connect */
173 int __tcp_nip_connect(struct sock *sk);
174 int _tcp_nip_conn_request(struct request_sock_ops *rsk_ops,
175 			  const struct tcp_request_sock_ops *af_ops,
176 			  struct sock *sk, struct sk_buff *skb);
177 struct sk_buff *tcp_nip_make_synack(
178 	const struct sock *sk,
179 	struct dst_entry *dst,
180 	struct request_sock *req,
181 	struct tcp_fastopen_cookie *foc,
182 	enum tcp_synack_type synack_type);
183 int nip_send_synack(struct request_sock *req, struct sk_buff *skb);
184 struct sock *tcp_nip_check_req(struct sock *sk, struct sk_buff *skb,
185 			   struct request_sock *req);
186 int tcp_nip_child_process(struct sock *parent, struct sock *child,
187 		      struct sk_buff *skb);
188 int tcp_nip_rtx_synack(const struct sock *sk, struct request_sock *req);
189 
190 /* client send ack */
191 void tcp_nip_send_ack(struct sock *sk);
192 struct sock *tcp_nip_create_openreq_child(const struct sock *sk,
193 				      struct request_sock *req,
194 				      struct sk_buff *skb);
195 void tcp_nip_initialize_rcv_mss(struct sock *sk);
196 
197 /* release */
198 void tcp_nip_release_cb(struct sock *sk);
199 
200 void tcp_nip_keepalive_enable(struct sock *sk);
201 void tcp_nip_keepalive_disable(struct sock *sk);
202 
203 #endif  /* _NIP_TCP_H */
204