diff options
author | Arnaldo Carvalho de Melo <acme@mandriva.com> | 2006-03-20 22:21:44 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-03-20 22:21:44 -0500 |
commit | 91f0ebf7b6d5cb2b6e818d48587566144821babe (patch) | |
tree | 505c66f36bd72014d7eacb7a04ea011bae2e9a3a /net/dccp/ccids | |
parent | f38c39d6ce8226519455a6dfe91c2ad84f363f6f (diff) |
[DCCP] CCID: Improve CCID infrastructure
1. No need for ->ccid_init nor ->ccid_exit, this is what module_{init,exit}
does and anynways neither ccid2 nor ccid3 were using it.
2. Rename struct ccid to struct ccid_operations and introduce struct ccid
with a pointer to ccid_operations and rigth after it the rx or tx
private state.
3. Remove the pointer to the state of the half connections from struct
dccp_sock, now its derived thru ccid_priv() from the ccid pointer.
Now we also can implement the setsockopt for changing the CCID easily as
no ccid init routines can affect struct dccp_sock in any way that prevents
other CCIDs from working if a CCID switch operation is asked by apps.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dccp/ccids')
-rw-r--r-- | net/dccp/ccids/ccid2.c | 55 | ||||
-rw-r--r-- | net/dccp/ccids/ccid2.h | 16 | ||||
-rw-r--r-- | net/dccp/ccids/ccid3.c | 34 | ||||
-rw-r--r-- | net/dccp/ccids/ccid3.h | 5 |
4 files changed, 34 insertions, 76 deletions
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c index 3328d23c4be7..b40c4569a820 100644 --- a/net/dccp/ccids/ccid2.c +++ b/net/dccp/ccids/ccid2.c | |||
@@ -52,16 +52,6 @@ static int ccid2_debug; | |||
52 | 52 | ||
53 | static const int ccid2_seq_len = 128; | 53 | static const int ccid2_seq_len = 128; |
54 | 54 | ||
55 | static inline struct ccid2_hc_tx_sock *ccid2_hc_tx_sk(const struct sock *sk) | ||
56 | { | ||
57 | return dccp_sk(sk)->dccps_hc_tx_ccid_private; | ||
58 | } | ||
59 | |||
60 | static inline struct ccid2_hc_rx_sock *ccid2_hc_rx_sk(const struct sock *sk) | ||
61 | { | ||
62 | return dccp_sk(sk)->dccps_hc_rx_ccid_private; | ||
63 | } | ||
64 | |||
65 | #ifdef CCID2_DEBUG | 55 | #ifdef CCID2_DEBUG |
66 | static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx) | 56 | static void ccid2_hc_tx_check_sanity(const struct ccid2_hc_tx_sock *hctx) |
67 | { | 57 | { |
@@ -707,19 +697,12 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
707 | ccid2_hc_tx_check_sanity(hctx); | 697 | ccid2_hc_tx_check_sanity(hctx); |
708 | } | 698 | } |
709 | 699 | ||
710 | static int ccid2_hc_tx_init(struct sock *sk) | 700 | static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk) |
711 | { | 701 | { |
712 | struct dccp_sock *dp = dccp_sk(sk); | 702 | struct ccid2_hc_tx_sock *hctx = ccid_priv(ccid); |
713 | struct ccid2_hc_tx_sock *hctx; | ||
714 | int seqcount = ccid2_seq_len; | 703 | int seqcount = ccid2_seq_len; |
715 | int i; | 704 | int i; |
716 | 705 | ||
717 | dp->dccps_hc_tx_ccid_private = kzalloc(sizeof(*hctx), gfp_any()); | ||
718 | if (dp->dccps_hc_tx_ccid_private == NULL) | ||
719 | return -ENOMEM; | ||
720 | |||
721 | hctx = ccid2_hc_tx_sk(sk); | ||
722 | |||
723 | /* XXX init variables with proper values */ | 706 | /* XXX init variables with proper values */ |
724 | hctx->ccid2hctx_cwnd = 1; | 707 | hctx->ccid2hctx_cwnd = 1; |
725 | hctx->ccid2hctx_ssthresh = 10; | 708 | hctx->ccid2hctx_ssthresh = 10; |
@@ -728,11 +711,9 @@ static int ccid2_hc_tx_init(struct sock *sk) | |||
728 | /* XXX init ~ to window size... */ | 711 | /* XXX init ~ to window size... */ |
729 | hctx->ccid2hctx_seqbuf = kmalloc(sizeof(*hctx->ccid2hctx_seqbuf) * | 712 | hctx->ccid2hctx_seqbuf = kmalloc(sizeof(*hctx->ccid2hctx_seqbuf) * |
730 | seqcount, gfp_any()); | 713 | seqcount, gfp_any()); |
731 | if (hctx->ccid2hctx_seqbuf == NULL) { | 714 | if (hctx->ccid2hctx_seqbuf == NULL) |
732 | kfree(dp->dccps_hc_tx_ccid_private); | ||
733 | dp->dccps_hc_tx_ccid_private = NULL; | ||
734 | return -ENOMEM; | 715 | return -ENOMEM; |
735 | } | 716 | |
736 | for (i = 0; i < (seqcount - 1); i++) { | 717 | for (i = 0; i < (seqcount - 1); i++) { |
737 | hctx->ccid2hctx_seqbuf[i].ccid2s_next = | 718 | hctx->ccid2hctx_seqbuf[i].ccid2s_next = |
738 | &hctx->ccid2hctx_seqbuf[i + 1]; | 719 | &hctx->ccid2hctx_seqbuf[i + 1]; |
@@ -763,15 +744,11 @@ static int ccid2_hc_tx_init(struct sock *sk) | |||
763 | 744 | ||
764 | static void ccid2_hc_tx_exit(struct sock *sk) | 745 | static void ccid2_hc_tx_exit(struct sock *sk) |
765 | { | 746 | { |
766 | struct dccp_sock *dp = dccp_sk(sk); | ||
767 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); | 747 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
768 | 748 | ||
769 | ccid2_hc_tx_kill_rto_timer(sk); | 749 | ccid2_hc_tx_kill_rto_timer(sk); |
770 | |||
771 | kfree(hctx->ccid2hctx_seqbuf); | 750 | kfree(hctx->ccid2hctx_seqbuf); |
772 | 751 | hctx->ccid2hctx_seqbuf = NULL; | |
773 | kfree(dp->dccps_hc_tx_ccid_private); | ||
774 | dp->dccps_hc_tx_ccid_private = NULL; | ||
775 | } | 752 | } |
776 | 753 | ||
777 | static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | 754 | static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) |
@@ -791,33 +768,17 @@ static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
791 | } | 768 | } |
792 | } | 769 | } |
793 | 770 | ||
794 | static int ccid2_hc_rx_init(struct sock *sk) | 771 | static struct ccid_operations ccid2 = { |
795 | { | ||
796 | struct dccp_sock *dp = dccp_sk(sk); | ||
797 | dp->dccps_hc_rx_ccid_private = kzalloc(sizeof(struct ccid2_hc_rx_sock), | ||
798 | gfp_any()); | ||
799 | return dp->dccps_hc_rx_ccid_private == NULL ? -ENOMEM : 0; | ||
800 | } | ||
801 | |||
802 | static void ccid2_hc_rx_exit(struct sock *sk) | ||
803 | { | ||
804 | struct dccp_sock *dp = dccp_sk(sk); | ||
805 | |||
806 | kfree(dp->dccps_hc_rx_ccid_private); | ||
807 | dp->dccps_hc_rx_ccid_private = NULL; | ||
808 | } | ||
809 | |||
810 | static struct ccid ccid2 = { | ||
811 | .ccid_id = 2, | 772 | .ccid_id = 2, |
812 | .ccid_name = "ccid2", | 773 | .ccid_name = "ccid2", |
813 | .ccid_owner = THIS_MODULE, | 774 | .ccid_owner = THIS_MODULE, |
775 | .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock), | ||
814 | .ccid_hc_tx_init = ccid2_hc_tx_init, | 776 | .ccid_hc_tx_init = ccid2_hc_tx_init, |
815 | .ccid_hc_tx_exit = ccid2_hc_tx_exit, | 777 | .ccid_hc_tx_exit = ccid2_hc_tx_exit, |
816 | .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet, | 778 | .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet, |
817 | .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent, | 779 | .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent, |
818 | .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv, | 780 | .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv, |
819 | .ccid_hc_rx_init = ccid2_hc_rx_init, | 781 | .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock), |
820 | .ccid_hc_rx_exit = ccid2_hc_rx_exit, | ||
821 | .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv, | 782 | .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv, |
822 | }; | 783 | }; |
823 | 784 | ||
diff --git a/net/dccp/ccids/ccid2.h b/net/dccp/ccids/ccid2.h index 0b08c90955a9..451a87464fa5 100644 --- a/net/dccp/ccids/ccid2.h +++ b/net/dccp/ccids/ccid2.h | |||
@@ -20,6 +20,13 @@ | |||
20 | #ifndef _DCCP_CCID2_H_ | 20 | #ifndef _DCCP_CCID2_H_ |
21 | #define _DCCP_CCID2_H_ | 21 | #define _DCCP_CCID2_H_ |
22 | 22 | ||
23 | #include <linux/dccp.h> | ||
24 | #include <linux/timer.h> | ||
25 | #include <linux/types.h> | ||
26 | #include "../ccid.h" | ||
27 | |||
28 | struct sock; | ||
29 | |||
23 | struct ccid2_seq { | 30 | struct ccid2_seq { |
24 | u64 ccid2s_seq; | 31 | u64 ccid2s_seq; |
25 | unsigned long ccid2s_sent; | 32 | unsigned long ccid2s_sent; |
@@ -66,4 +73,13 @@ struct ccid2_hc_rx_sock { | |||
66 | int ccid2hcrx_data; | 73 | int ccid2hcrx_data; |
67 | }; | 74 | }; |
68 | 75 | ||
76 | static inline struct ccid2_hc_tx_sock *ccid2_hc_tx_sk(const struct sock *sk) | ||
77 | { | ||
78 | return ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid); | ||
79 | } | ||
80 | |||
81 | static inline struct ccid2_hc_rx_sock *ccid2_hc_rx_sk(const struct sock *sk) | ||
82 | { | ||
83 | return ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid); | ||
84 | } | ||
69 | #endif /* _DCCP_CCID2_H_ */ | 85 | #endif /* _DCCP_CCID2_H_ */ |
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c index f9e16db09bef..0587f52e4af1 100644 --- a/net/dccp/ccids/ccid3.c +++ b/net/dccp/ccids/ccid3.c | |||
@@ -647,17 +647,10 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, | |||
647 | return rc; | 647 | return rc; |
648 | } | 648 | } |
649 | 649 | ||
650 | static int ccid3_hc_tx_init(struct sock *sk) | 650 | static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk) |
651 | { | 651 | { |
652 | struct dccp_sock *dp = dccp_sk(sk); | 652 | struct dccp_sock *dp = dccp_sk(sk); |
653 | struct ccid3_hc_tx_sock *hctx; | 653 | struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid); |
654 | |||
655 | dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any()); | ||
656 | if (dp->dccps_hc_tx_ccid_private == NULL) | ||
657 | return -ENOMEM; | ||
658 | |||
659 | hctx = ccid3_hc_tx_sk(sk); | ||
660 | memset(hctx, 0, sizeof(*hctx)); | ||
661 | 654 | ||
662 | if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && | 655 | if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && |
663 | dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE) | 656 | dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE) |
@@ -680,7 +673,6 @@ static int ccid3_hc_tx_init(struct sock *sk) | |||
680 | 673 | ||
681 | static void ccid3_hc_tx_exit(struct sock *sk) | 674 | static void ccid3_hc_tx_exit(struct sock *sk) |
682 | { | 675 | { |
683 | struct dccp_sock *dp = dccp_sk(sk); | ||
684 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 676 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
685 | 677 | ||
686 | BUG_ON(hctx == NULL); | 678 | BUG_ON(hctx == NULL); |
@@ -690,9 +682,6 @@ static void ccid3_hc_tx_exit(struct sock *sk) | |||
690 | 682 | ||
691 | /* Empty packet history */ | 683 | /* Empty packet history */ |
692 | dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist); | 684 | dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist); |
693 | |||
694 | kfree(dp->dccps_hc_tx_ccid_private); | ||
695 | dp->dccps_hc_tx_ccid_private = NULL; | ||
696 | } | 685 | } |
697 | 686 | ||
698 | /* | 687 | /* |
@@ -1039,20 +1028,13 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
1039 | } | 1028 | } |
1040 | } | 1029 | } |
1041 | 1030 | ||
1042 | static int ccid3_hc_rx_init(struct sock *sk) | 1031 | static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk) |
1043 | { | 1032 | { |
1044 | struct dccp_sock *dp = dccp_sk(sk); | 1033 | struct dccp_sock *dp = dccp_sk(sk); |
1045 | struct ccid3_hc_rx_sock *hcrx; | 1034 | struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid); |
1046 | 1035 | ||
1047 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); | 1036 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
1048 | 1037 | ||
1049 | dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any()); | ||
1050 | if (dp->dccps_hc_rx_ccid_private == NULL) | ||
1051 | return -ENOMEM; | ||
1052 | |||
1053 | hcrx = ccid3_hc_rx_sk(sk); | ||
1054 | memset(hcrx, 0, sizeof(*hcrx)); | ||
1055 | |||
1056 | if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && | 1038 | if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && |
1057 | dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE) | 1039 | dp->dccps_packet_size <= TFRC_MAX_PACKET_SIZE) |
1058 | hcrx->ccid3hcrx_s = dp->dccps_packet_size; | 1040 | hcrx->ccid3hcrx_s = dp->dccps_packet_size; |
@@ -1071,7 +1053,6 @@ static int ccid3_hc_rx_init(struct sock *sk) | |||
1071 | static void ccid3_hc_rx_exit(struct sock *sk) | 1053 | static void ccid3_hc_rx_exit(struct sock *sk) |
1072 | { | 1054 | { |
1073 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); | 1055 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
1074 | struct dccp_sock *dp = dccp_sk(sk); | ||
1075 | 1056 | ||
1076 | BUG_ON(hcrx == NULL); | 1057 | BUG_ON(hcrx == NULL); |
1077 | 1058 | ||
@@ -1082,9 +1063,6 @@ static void ccid3_hc_rx_exit(struct sock *sk) | |||
1082 | 1063 | ||
1083 | /* Empty loss interval history */ | 1064 | /* Empty loss interval history */ |
1084 | dccp_li_hist_purge(ccid3_li_hist, &hcrx->ccid3hcrx_li_hist); | 1065 | dccp_li_hist_purge(ccid3_li_hist, &hcrx->ccid3hcrx_li_hist); |
1085 | |||
1086 | kfree(dp->dccps_hc_rx_ccid_private); | ||
1087 | dp->dccps_hc_rx_ccid_private = NULL; | ||
1088 | } | 1066 | } |
1089 | 1067 | ||
1090 | static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) | 1068 | static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) |
@@ -1170,10 +1148,11 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len, | |||
1170 | return 0; | 1148 | return 0; |
1171 | } | 1149 | } |
1172 | 1150 | ||
1173 | static struct ccid ccid3 = { | 1151 | static struct ccid_operations ccid3 = { |
1174 | .ccid_id = 3, | 1152 | .ccid_id = 3, |
1175 | .ccid_name = "ccid3", | 1153 | .ccid_name = "ccid3", |
1176 | .ccid_owner = THIS_MODULE, | 1154 | .ccid_owner = THIS_MODULE, |
1155 | .ccid_hc_tx_obj_size = sizeof(struct ccid3_hc_tx_sock), | ||
1177 | .ccid_hc_tx_init = ccid3_hc_tx_init, | 1156 | .ccid_hc_tx_init = ccid3_hc_tx_init, |
1178 | .ccid_hc_tx_exit = ccid3_hc_tx_exit, | 1157 | .ccid_hc_tx_exit = ccid3_hc_tx_exit, |
1179 | .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, | 1158 | .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, |
@@ -1181,6 +1160,7 @@ static struct ccid ccid3 = { | |||
1181 | .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, | 1160 | .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, |
1182 | .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options, | 1161 | .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options, |
1183 | .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, | 1162 | .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, |
1163 | .ccid_hc_rx_obj_size = sizeof(struct ccid3_hc_rx_sock), | ||
1184 | .ccid_hc_rx_init = ccid3_hc_rx_init, | 1164 | .ccid_hc_rx_init = ccid3_hc_rx_init, |
1185 | .ccid_hc_rx_exit = ccid3_hc_rx_exit, | 1165 | .ccid_hc_rx_exit = ccid3_hc_rx_exit, |
1186 | .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options, | 1166 | .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options, |
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h index 0bde4583d091..f18b96d4e5a2 100644 --- a/net/dccp/ccids/ccid3.h +++ b/net/dccp/ccids/ccid3.h | |||
@@ -41,6 +41,7 @@ | |||
41 | #include <linux/time.h> | 41 | #include <linux/time.h> |
42 | #include <linux/types.h> | 42 | #include <linux/types.h> |
43 | #include <linux/tfrc.h> | 43 | #include <linux/tfrc.h> |
44 | #include "../ccid.h" | ||
44 | 45 | ||
45 | #define TFRC_MIN_PACKET_SIZE 16 | 46 | #define TFRC_MIN_PACKET_SIZE 16 |
46 | #define TFRC_STD_PACKET_SIZE 256 | 47 | #define TFRC_STD_PACKET_SIZE 256 |
@@ -135,12 +136,12 @@ struct ccid3_hc_rx_sock { | |||
135 | 136 | ||
136 | static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) | 137 | static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) |
137 | { | 138 | { |
138 | return dccp_sk(sk)->dccps_hc_tx_ccid_private; | 139 | return ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid); |
139 | } | 140 | } |
140 | 141 | ||
141 | static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) | 142 | static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) |
142 | { | 143 | { |
143 | return dccp_sk(sk)->dccps_hc_rx_ccid_private; | 144 | return ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid); |
144 | } | 145 | } |
145 | 146 | ||
146 | #endif /* _DCCP_CCID3_H_ */ | 147 | #endif /* _DCCP_CCID3_H_ */ |