aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_ipv4.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/tcp_ipv4.c')
-rw-r--r--net/ipv4/tcp_ipv4.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 7963e03f1068..0ea10eefa60f 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -92,7 +92,7 @@ EXPORT_SYMBOL(sysctl_tcp_low_latency);
92static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk, 92static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
93 __be32 addr); 93 __be32 addr);
94static int tcp_v4_md5_hash_hdr(char *md5_hash, struct tcp_md5sig_key *key, 94static int tcp_v4_md5_hash_hdr(char *md5_hash, struct tcp_md5sig_key *key,
95 __be32 daddr, __be32 saddr, struct tcphdr *th); 95 __be32 daddr, __be32 saddr, const struct tcphdr *th);
96#else 96#else
97static inline 97static inline
98struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk, __be32 addr) 98struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk, __be32 addr)
@@ -104,7 +104,7 @@ struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk, __be32 addr)
104struct inet_hashinfo tcp_hashinfo; 104struct inet_hashinfo tcp_hashinfo;
105EXPORT_SYMBOL(tcp_hashinfo); 105EXPORT_SYMBOL(tcp_hashinfo);
106 106
107static inline __u32 tcp_v4_init_sequence(struct sk_buff *skb) 107static inline __u32 tcp_v4_init_sequence(const struct sk_buff *skb)
108{ 108{
109 return secure_tcp_sequence_number(ip_hdr(skb)->daddr, 109 return secure_tcp_sequence_number(ip_hdr(skb)->daddr,
110 ip_hdr(skb)->saddr, 110 ip_hdr(skb)->saddr,
@@ -552,7 +552,7 @@ static void __tcp_v4_send_check(struct sk_buff *skb,
552/* This routine computes an IPv4 TCP checksum. */ 552/* This routine computes an IPv4 TCP checksum. */
553void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb) 553void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb)
554{ 554{
555 struct inet_sock *inet = inet_sk(sk); 555 const struct inet_sock *inet = inet_sk(sk);
556 556
557 __tcp_v4_send_check(skb, inet->inet_saddr, inet->inet_daddr); 557 __tcp_v4_send_check(skb, inet->inet_saddr, inet->inet_daddr);
558} 558}
@@ -590,7 +590,7 @@ int tcp_v4_gso_send_check(struct sk_buff *skb)
590 590
591static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb) 591static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
592{ 592{
593 struct tcphdr *th = tcp_hdr(skb); 593 const struct tcphdr *th = tcp_hdr(skb);
594 struct { 594 struct {
595 struct tcphdr th; 595 struct tcphdr th;
596#ifdef CONFIG_TCP_MD5SIG 596#ifdef CONFIG_TCP_MD5SIG
@@ -652,6 +652,7 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
652 arg.flags = (sk && inet_sk(sk)->transparent) ? IP_REPLY_ARG_NOSRCCHECK : 0; 652 arg.flags = (sk && inet_sk(sk)->transparent) ? IP_REPLY_ARG_NOSRCCHECK : 0;
653 653
654 net = dev_net(skb_dst(skb)->dev); 654 net = dev_net(skb_dst(skb)->dev);
655 arg.tos = ip_hdr(skb)->tos;
655 ip_send_reply(net->ipv4.tcp_sock, skb, ip_hdr(skb)->saddr, 656 ip_send_reply(net->ipv4.tcp_sock, skb, ip_hdr(skb)->saddr,
656 &arg, arg.iov[0].iov_len); 657 &arg, arg.iov[0].iov_len);
657 658
@@ -666,9 +667,9 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
666static void tcp_v4_send_ack(struct sk_buff *skb, u32 seq, u32 ack, 667static void tcp_v4_send_ack(struct sk_buff *skb, u32 seq, u32 ack,
667 u32 win, u32 ts, int oif, 668 u32 win, u32 ts, int oif,
668 struct tcp_md5sig_key *key, 669 struct tcp_md5sig_key *key,
669 int reply_flags) 670 int reply_flags, u8 tos)
670{ 671{
671 struct tcphdr *th = tcp_hdr(skb); 672 const struct tcphdr *th = tcp_hdr(skb);
672 struct { 673 struct {
673 struct tcphdr th; 674 struct tcphdr th;
674 __be32 opt[(TCPOLEN_TSTAMP_ALIGNED >> 2) 675 __be32 opt[(TCPOLEN_TSTAMP_ALIGNED >> 2)
@@ -726,7 +727,7 @@ static void tcp_v4_send_ack(struct sk_buff *skb, u32 seq, u32 ack,
726 arg.csumoffset = offsetof(struct tcphdr, check) / 2; 727 arg.csumoffset = offsetof(struct tcphdr, check) / 2;
727 if (oif) 728 if (oif)
728 arg.bound_dev_if = oif; 729 arg.bound_dev_if = oif;
729 730 arg.tos = tos;
730 ip_send_reply(net->ipv4.tcp_sock, skb, ip_hdr(skb)->saddr, 731 ip_send_reply(net->ipv4.tcp_sock, skb, ip_hdr(skb)->saddr,
731 &arg, arg.iov[0].iov_len); 732 &arg, arg.iov[0].iov_len);
732 733
@@ -743,7 +744,8 @@ static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb)
743 tcptw->tw_ts_recent, 744 tcptw->tw_ts_recent,
744 tw->tw_bound_dev_if, 745 tw->tw_bound_dev_if,
745 tcp_twsk_md5_key(tcptw), 746 tcp_twsk_md5_key(tcptw),
746 tw->tw_transparent ? IP_REPLY_ARG_NOSRCCHECK : 0 747 tw->tw_transparent ? IP_REPLY_ARG_NOSRCCHECK : 0,
748 tw->tw_tos
747 ); 749 );
748 750
749 inet_twsk_put(tw); 751 inet_twsk_put(tw);
@@ -757,7 +759,8 @@ static void tcp_v4_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
757 req->ts_recent, 759 req->ts_recent,
758 0, 760 0,
759 tcp_v4_md5_do_lookup(sk, ip_hdr(skb)->daddr), 761 tcp_v4_md5_do_lookup(sk, ip_hdr(skb)->daddr),
760 inet_rsk(req)->no_srccheck ? IP_REPLY_ARG_NOSRCCHECK : 0); 762 inet_rsk(req)->no_srccheck ? IP_REPLY_ARG_NOSRCCHECK : 0,
763 ip_hdr(skb)->tos);
761} 764}
762 765
763/* 766/*
@@ -1090,7 +1093,7 @@ static int tcp_v4_md5_hash_pseudoheader(struct tcp_md5sig_pool *hp,
1090} 1093}
1091 1094
1092static int tcp_v4_md5_hash_hdr(char *md5_hash, struct tcp_md5sig_key *key, 1095static int tcp_v4_md5_hash_hdr(char *md5_hash, struct tcp_md5sig_key *key,
1093 __be32 daddr, __be32 saddr, struct tcphdr *th) 1096 __be32 daddr, __be32 saddr, const struct tcphdr *th)
1094{ 1097{
1095 struct tcp_md5sig_pool *hp; 1098 struct tcp_md5sig_pool *hp;
1096 struct hash_desc *desc; 1099 struct hash_desc *desc;
@@ -1122,12 +1125,12 @@ clear_hash_noput:
1122} 1125}
1123 1126
1124int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key, 1127int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
1125 struct sock *sk, struct request_sock *req, 1128 const struct sock *sk, const struct request_sock *req,
1126 struct sk_buff *skb) 1129 const struct sk_buff *skb)
1127{ 1130{
1128 struct tcp_md5sig_pool *hp; 1131 struct tcp_md5sig_pool *hp;
1129 struct hash_desc *desc; 1132 struct hash_desc *desc;
1130 struct tcphdr *th = tcp_hdr(skb); 1133 const struct tcphdr *th = tcp_hdr(skb);
1131 __be32 saddr, daddr; 1134 __be32 saddr, daddr;
1132 1135
1133 if (sk) { 1136 if (sk) {
@@ -1172,7 +1175,7 @@ clear_hash_noput:
1172} 1175}
1173EXPORT_SYMBOL(tcp_v4_md5_hash_skb); 1176EXPORT_SYMBOL(tcp_v4_md5_hash_skb);
1174 1177
1175static int tcp_v4_inbound_md5_hash(struct sock *sk, struct sk_buff *skb) 1178static int tcp_v4_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb)
1176{ 1179{
1177 /* 1180 /*
1178 * This gets called for each TCP segment that arrives 1181 * This gets called for each TCP segment that arrives
@@ -1182,10 +1185,10 @@ static int tcp_v4_inbound_md5_hash(struct sock *sk, struct sk_buff *skb)
1182 * o MD5 hash and we're not expecting one. 1185 * o MD5 hash and we're not expecting one.
1183 * o MD5 hash and its wrong. 1186 * o MD5 hash and its wrong.
1184 */ 1187 */
1185 __u8 *hash_location = NULL; 1188 const __u8 *hash_location = NULL;
1186 struct tcp_md5sig_key *hash_expected; 1189 struct tcp_md5sig_key *hash_expected;
1187 const struct iphdr *iph = ip_hdr(skb); 1190 const struct iphdr *iph = ip_hdr(skb);
1188 struct tcphdr *th = tcp_hdr(skb); 1191 const struct tcphdr *th = tcp_hdr(skb);
1189 int genhash; 1192 int genhash;
1190 unsigned char newhash[16]; 1193 unsigned char newhash[16];
1191 1194
@@ -1248,7 +1251,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
1248{ 1251{
1249 struct tcp_extend_values tmp_ext; 1252 struct tcp_extend_values tmp_ext;
1250 struct tcp_options_received tmp_opt; 1253 struct tcp_options_received tmp_opt;
1251 u8 *hash_location; 1254 const u8 *hash_location;
1252 struct request_sock *req; 1255 struct request_sock *req;
1253 struct inet_request_sock *ireq; 1256 struct inet_request_sock *ireq;
1254 struct tcp_sock *tp = tcp_sk(sk); 1257 struct tcp_sock *tp = tcp_sk(sk);
@@ -1588,7 +1591,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
1588#endif 1591#endif
1589 1592
1590 if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */ 1593 if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */
1591 sock_rps_save_rxhash(sk, skb->rxhash); 1594 sock_rps_save_rxhash(sk, skb);
1592 if (tcp_rcv_established(sk, skb, tcp_hdr(skb), skb->len)) { 1595 if (tcp_rcv_established(sk, skb, tcp_hdr(skb), skb->len)) {
1593 rsk = sk; 1596 rsk = sk;
1594 goto reset; 1597 goto reset;
@@ -1605,7 +1608,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
1605 goto discard; 1608 goto discard;
1606 1609
1607 if (nsk != sk) { 1610 if (nsk != sk) {
1608 sock_rps_save_rxhash(nsk, skb->rxhash); 1611 sock_rps_save_rxhash(nsk, skb);
1609 if (tcp_child_process(sk, nsk, skb)) { 1612 if (tcp_child_process(sk, nsk, skb)) {
1610 rsk = nsk; 1613 rsk = nsk;
1611 goto reset; 1614 goto reset;
@@ -1613,7 +1616,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
1613 return 0; 1616 return 0;
1614 } 1617 }
1615 } else 1618 } else
1616 sock_rps_save_rxhash(sk, skb->rxhash); 1619 sock_rps_save_rxhash(sk, skb);
1617 1620
1618 if (tcp_rcv_state_process(sk, skb, tcp_hdr(skb), skb->len)) { 1621 if (tcp_rcv_state_process(sk, skb, tcp_hdr(skb), skb->len)) {
1619 rsk = sk; 1622 rsk = sk;
@@ -1645,7 +1648,7 @@ EXPORT_SYMBOL(tcp_v4_do_rcv);
1645int tcp_v4_rcv(struct sk_buff *skb) 1648int tcp_v4_rcv(struct sk_buff *skb)
1646{ 1649{
1647 const struct iphdr *iph; 1650 const struct iphdr *iph;
1648 struct tcphdr *th; 1651 const struct tcphdr *th;
1649 struct sock *sk; 1652 struct sock *sk;
1650 int ret; 1653 int ret;
1651 struct net *net = dev_net(skb->dev); 1654 struct net *net = dev_net(skb->dev);
@@ -1680,7 +1683,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
1680 skb->len - th->doff * 4); 1683 skb->len - th->doff * 4);
1681 TCP_SKB_CB(skb)->ack_seq = ntohl(th->ack_seq); 1684 TCP_SKB_CB(skb)->ack_seq = ntohl(th->ack_seq);
1682 TCP_SKB_CB(skb)->when = 0; 1685 TCP_SKB_CB(skb)->when = 0;
1683 TCP_SKB_CB(skb)->flags = iph->tos; 1686 TCP_SKB_CB(skb)->ip_dsfield = ipv4_get_dsfield(iph);
1684 TCP_SKB_CB(skb)->sacked = 0; 1687 TCP_SKB_CB(skb)->sacked = 0;
1685 1688
1686 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest); 1689 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
@@ -1809,7 +1812,7 @@ EXPORT_SYMBOL(tcp_v4_get_peer);
1809 1812
1810void *tcp_v4_tw_get_peer(struct sock *sk) 1813void *tcp_v4_tw_get_peer(struct sock *sk)
1811{ 1814{
1812 struct inet_timewait_sock *tw = inet_twsk(sk); 1815 const struct inet_timewait_sock *tw = inet_twsk(sk);
1813 1816
1814 return inet_getpeer_v4(tw->tw_daddr, 1); 1817 return inet_getpeer_v4(tw->tw_daddr, 1);
1815} 1818}
@@ -2381,7 +2384,7 @@ void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo)
2381} 2384}
2382EXPORT_SYMBOL(tcp_proc_unregister); 2385EXPORT_SYMBOL(tcp_proc_unregister);
2383 2386
2384static void get_openreq4(struct sock *sk, struct request_sock *req, 2387static void get_openreq4(const struct sock *sk, const struct request_sock *req,
2385 struct seq_file *f, int i, int uid, int *len) 2388 struct seq_file *f, int i, int uid, int *len)
2386{ 2389{
2387 const struct inet_request_sock *ireq = inet_rsk(req); 2390 const struct inet_request_sock *ireq = inet_rsk(req);
@@ -2411,9 +2414,9 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
2411{ 2414{
2412 int timer_active; 2415 int timer_active;
2413 unsigned long timer_expires; 2416 unsigned long timer_expires;
2414 struct tcp_sock *tp = tcp_sk(sk); 2417 const struct tcp_sock *tp = tcp_sk(sk);
2415 const struct inet_connection_sock *icsk = inet_csk(sk); 2418 const struct inet_connection_sock *icsk = inet_csk(sk);
2416 struct inet_sock *inet = inet_sk(sk); 2419 const struct inet_sock *inet = inet_sk(sk);
2417 __be32 dest = inet->inet_daddr; 2420 __be32 dest = inet->inet_daddr;
2418 __be32 src = inet->inet_rcv_saddr; 2421 __be32 src = inet->inet_rcv_saddr;
2419 __u16 destp = ntohs(inet->inet_dport); 2422 __u16 destp = ntohs(inet->inet_dport);
@@ -2462,7 +2465,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
2462 len); 2465 len);
2463} 2466}
2464 2467
2465static void get_timewait4_sock(struct inet_timewait_sock *tw, 2468static void get_timewait4_sock(const struct inet_timewait_sock *tw,
2466 struct seq_file *f, int i, int *len) 2469 struct seq_file *f, int i, int *len)
2467{ 2470{
2468 __be32 dest, src; 2471 __be32 dest, src;