aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_ipv4.c
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2008-04-17 23:45:16 -0400
committerYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2008-06-11 14:46:30 -0400
commit9501f9722922f2e80e1f9dc6682311d65c2b5690 (patch)
treeca8195e04ea63e8273801030ce26527fe5a8a7c7 /net/ipv4/tcp_ipv4.c
parent8d26d76dd4a4c87ef037a44a42a0608ffc730199 (diff)
tcp md5sig: Let the caller pass appropriate key for tcp_v{4,6}_do_calc_md5_hash().
As we do for other socket/timewait-socket specific parameters, let the callers pass appropriate arguments to tcp_v{4,6}_do_calc_md5_hash(). Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Diffstat (limited to 'net/ipv4/tcp_ipv4.c')
-rw-r--r--net/ipv4/tcp_ipv4.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index e331cdbd0953..f7ff2a64a7f0 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -96,6 +96,12 @@ static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
96static int tcp_v4_do_calc_md5_hash(char *md5_hash, struct tcp_md5sig_key *key, 96static int tcp_v4_do_calc_md5_hash(char *md5_hash, struct tcp_md5sig_key *key,
97 __be32 saddr, __be32 daddr, 97 __be32 saddr, __be32 daddr,
98 struct tcphdr *th, unsigned int tcplen); 98 struct tcphdr *th, unsigned int tcplen);
99#else
100static inline
101struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk, __be32 addr)
102{
103 return NULL;
104}
99#endif 105#endif
100 106
101struct inet_hashinfo __cacheline_aligned tcp_hashinfo = { 107struct inet_hashinfo __cacheline_aligned tcp_hashinfo = {
@@ -604,9 +610,9 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
604 outside socket context is ugly, certainly. What can I do? 610 outside socket context is ugly, certainly. What can I do?
605 */ 611 */
606 612
607static void tcp_v4_send_ack(struct tcp_timewait_sock *twsk, 613static void tcp_v4_send_ack(struct sk_buff *skb, u32 seq, u32 ack,
608 struct sk_buff *skb, u32 seq, u32 ack, 614 u32 win, u32 ts, int oif,
609 u32 win, u32 ts) 615 struct tcp_md5sig_key *key)
610{ 616{
611 struct tcphdr *th = tcp_hdr(skb); 617 struct tcphdr *th = tcp_hdr(skb);
612 struct { 618 struct {
@@ -618,10 +624,6 @@ static void tcp_v4_send_ack(struct tcp_timewait_sock *twsk,
618 ]; 624 ];
619 } rep; 625 } rep;
620 struct ip_reply_arg arg; 626 struct ip_reply_arg arg;
621#ifdef CONFIG_TCP_MD5SIG
622 struct tcp_md5sig_key *key;
623 struct tcp_md5sig_key tw_key;
624#endif
625 627
626 memset(&rep.th, 0, sizeof(struct tcphdr)); 628 memset(&rep.th, 0, sizeof(struct tcphdr));
627 memset(&arg, 0, sizeof(arg)); 629 memset(&arg, 0, sizeof(arg));
@@ -647,23 +649,6 @@ static void tcp_v4_send_ack(struct tcp_timewait_sock *twsk,
647 rep.th.window = htons(win); 649 rep.th.window = htons(win);
648 650
649#ifdef CONFIG_TCP_MD5SIG 651#ifdef CONFIG_TCP_MD5SIG
650 /*
651 * The SKB holds an imcoming packet, but may not have a valid ->sk
652 * pointer. This is especially the case when we're dealing with a
653 * TIME_WAIT ack, because the sk structure is long gone, and only
654 * the tcp_timewait_sock remains. So the md5 key is stashed in that
655 * structure, and we use it in preference. I believe that (twsk ||
656 * skb->sk) holds true, but we program defensively.
657 */
658 if (!twsk && skb->sk) {
659 key = tcp_v4_md5_do_lookup(skb->sk, ip_hdr(skb)->daddr);
660 } else if (twsk && twsk->tw_md5_keylen) {
661 tw_key.key = twsk->tw_md5_key;
662 tw_key.keylen = twsk->tw_md5_keylen;
663 key = &tw_key;
664 } else
665 key = NULL;
666
667 if (key) { 652 if (key) {
668 int offset = (ts) ? 3 : 0; 653 int offset = (ts) ? 3 : 0;
669 654
@@ -685,8 +670,8 @@ static void tcp_v4_send_ack(struct tcp_timewait_sock *twsk,
685 ip_hdr(skb)->saddr, /* XXX */ 670 ip_hdr(skb)->saddr, /* XXX */
686 arg.iov[0].iov_len, IPPROTO_TCP, 0); 671 arg.iov[0].iov_len, IPPROTO_TCP, 0);
687 arg.csumoffset = offsetof(struct tcphdr, check) / 2; 672 arg.csumoffset = offsetof(struct tcphdr, check) / 2;
688 if (twsk) 673 if (oif)
689 arg.bound_dev_if = twsk->tw_sk.tw_bound_dev_if; 674 arg.bound_dev_if = oif;
690 675
691 ip_send_reply(dev_net(skb->dev)->ipv4.tcp_sock, skb, 676 ip_send_reply(dev_net(skb->dev)->ipv4.tcp_sock, skb,
692 &arg, arg.iov[0].iov_len); 677 &arg, arg.iov[0].iov_len);
@@ -699,9 +684,12 @@ static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb)
699 struct inet_timewait_sock *tw = inet_twsk(sk); 684 struct inet_timewait_sock *tw = inet_twsk(sk);
700 struct tcp_timewait_sock *tcptw = tcp_twsk(sk); 685 struct tcp_timewait_sock *tcptw = tcp_twsk(sk);
701 686
702 tcp_v4_send_ack(tcptw, skb, tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt, 687 tcp_v4_send_ack(skb, tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt,
703 tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale, 688 tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale,
704 tcptw->tw_ts_recent); 689 tcptw->tw_ts_recent,
690 tw->tw_bound_dev_if,
691 tcp_twsk_md5_key(tcptw)
692 );
705 693
706 inet_twsk_put(tw); 694 inet_twsk_put(tw);
707} 695}
@@ -709,9 +697,11 @@ static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb)
709static void tcp_v4_reqsk_send_ack(struct sk_buff *skb, 697static void tcp_v4_reqsk_send_ack(struct sk_buff *skb,
710 struct request_sock *req) 698 struct request_sock *req)
711{ 699{
712 tcp_v4_send_ack(NULL, skb, tcp_rsk(req)->snt_isn + 1, 700 tcp_v4_send_ack(skb, tcp_rsk(req)->snt_isn + 1,
713 tcp_rsk(req)->rcv_isn + 1, req->rcv_wnd, 701 tcp_rsk(req)->rcv_isn + 1, req->rcv_wnd,
714 req->ts_recent); 702 req->ts_recent,
703 0,
704 tcp_v4_md5_do_lookup(skb->sk, ip_hdr(skb)->daddr));
715} 705}
716 706
717/* 707/*