1 /* SPDX-License-Identifier: GPL-2.0-only */ << 2 #ifndef _CCID_H 1 #ifndef _CCID_H 3 #define _CCID_H 2 #define _CCID_H 4 /* 3 /* 5 * net/dccp/ccid.h 4 * net/dccp/ccid.h 6 * 5 * 7 * An implementation of the DCCP protocol 6 * An implementation of the DCCP protocol 8 * Arnaldo Carvalho de Melo <acme@conectiva.c 7 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 9 * 8 * 10 * CCID infrastructure 9 * CCID infrastructure >> 10 * >> 11 * This program is free software; you can redistribute it and/or modify it >> 12 * under the terms of the GNU General Public License version 2 as >> 13 * published by the Free Software Foundation. 11 */ 14 */ 12 15 13 #include <net/sock.h> 16 #include <net/sock.h> 14 #include <linux/compiler.h> 17 #include <linux/compiler.h> 15 #include <linux/dccp.h> 18 #include <linux/dccp.h> 16 #include <linux/list.h> 19 #include <linux/list.h> 17 #include <linux/module.h> 20 #include <linux/module.h> 18 21 19 /* maximum value for a CCID (RFC 4340, 19.5) * 22 /* maximum value for a CCID (RFC 4340, 19.5) */ 20 #define CCID_MAX 255 23 #define CCID_MAX 255 21 #define CCID_SLAB_NAME_LENGTH 32 24 #define CCID_SLAB_NAME_LENGTH 32 22 25 23 struct tcp_info; 26 struct tcp_info; 24 27 25 /** 28 /** 26 * struct ccid_operations - Interface to Co 29 * struct ccid_operations - Interface to Congestion-Control Infrastructure 27 * 30 * 28 * @ccid_id: numerical CCID ID (up to %CCID_M 31 * @ccid_id: numerical CCID ID (up to %CCID_MAX, cf. table 5 in RFC 4340, 10.) 29 * @ccid_ccmps: the CCMPS including network/t 32 * @ccid_ccmps: the CCMPS including network/transport headers (0 when disabled) 30 * @ccid_name: alphabetical identifier string 33 * @ccid_name: alphabetical identifier string for @ccid_id 31 * @ccid_hc_{r,t}x_slab: memory pool for the 34 * @ccid_hc_{r,t}x_slab: memory pool for the receiver/sender half-connection 32 * @ccid_hc_{r,t}x_obj_size: size of the rece 35 * @ccid_hc_{r,t}x_obj_size: size of the receiver/sender half-connection socket 33 * 36 * 34 * @ccid_hc_{r,t}x_init: CCID-specific initia 37 * @ccid_hc_{r,t}x_init: CCID-specific initialisation routine (before startup) 35 * @ccid_hc_{r,t}x_exit: CCID-specific cleanu 38 * @ccid_hc_{r,t}x_exit: CCID-specific cleanup routine (before destruction) 36 * @ccid_hc_rx_packet_recv: implements the HC 39 * @ccid_hc_rx_packet_recv: implements the HC-receiver side 37 * @ccid_hc_{r,t}x_parse_options: parsing rou 40 * @ccid_hc_{r,t}x_parse_options: parsing routine for CCID/HC-specific options 38 * @ccid_hc_{r,t}x_insert_options: insert rou 41 * @ccid_hc_{r,t}x_insert_options: insert routine for CCID/HC-specific options 39 * @ccid_hc_tx_packet_recv: implements feedba 42 * @ccid_hc_tx_packet_recv: implements feedback processing for the HC-sender 40 * @ccid_hc_tx_send_packet: implements the se 43 * @ccid_hc_tx_send_packet: implements the sending part of the HC-sender 41 * @ccid_hc_tx_packet_sent: does accounting f 44 * @ccid_hc_tx_packet_sent: does accounting for packets in flight by HC-sender 42 * @ccid_hc_{r,t}x_get_info: INET_DIAG inform 45 * @ccid_hc_{r,t}x_get_info: INET_DIAG information for HC-receiver/sender 43 * @ccid_hc_{r,t}x_getsockopt: socket options 46 * @ccid_hc_{r,t}x_getsockopt: socket options specific to HC-receiver/sender 44 */ 47 */ 45 struct ccid_operations { 48 struct ccid_operations { 46 unsigned char ccid_id; 49 unsigned char ccid_id; 47 __u32 ccid_ccmps; 50 __u32 ccid_ccmps; 48 const char *ccid_name; 51 const char *ccid_name; 49 struct kmem_cache *ccid_hc_rx_sl 52 struct kmem_cache *ccid_hc_rx_slab, 50 *ccid_hc_tx_sl 53 *ccid_hc_tx_slab; 51 char ccid_hc_rx_sla 54 char ccid_hc_rx_slab_name[CCID_SLAB_NAME_LENGTH]; 52 char ccid_hc_tx_sla 55 char ccid_hc_tx_slab_name[CCID_SLAB_NAME_LENGTH]; 53 __u32 ccid_hc_rx_obj 56 __u32 ccid_hc_rx_obj_size, 54 ccid_hc_tx_obj 57 ccid_hc_tx_obj_size; 55 /* Interface Routines */ 58 /* Interface Routines */ 56 int (*ccid_hc_rx_init)(str 59 int (*ccid_hc_rx_init)(struct ccid *ccid, struct sock *sk); 57 int (*ccid_hc_tx_init)(str 60 int (*ccid_hc_tx_init)(struct ccid *ccid, struct sock *sk); 58 void (*ccid_hc_rx_exit)(str 61 void (*ccid_hc_rx_exit)(struct sock *sk); 59 void (*ccid_hc_tx_exit)(str 62 void (*ccid_hc_tx_exit)(struct sock *sk); 60 void (*ccid_hc_rx_packet_re 63 void (*ccid_hc_rx_packet_recv)(struct sock *sk, 61 64 struct sk_buff *skb); 62 int (*ccid_hc_rx_parse_opt 65 int (*ccid_hc_rx_parse_options)(struct sock *sk, u8 pkt, 63 66 u8 opt, u8 *val, u8 len); 64 int (*ccid_hc_rx_insert_op 67 int (*ccid_hc_rx_insert_options)(struct sock *sk, 65 68 struct sk_buff *skb); 66 void (*ccid_hc_tx_packet_re 69 void (*ccid_hc_tx_packet_recv)(struct sock *sk, 67 70 struct sk_buff *skb); 68 int (*ccid_hc_tx_parse_opt 71 int (*ccid_hc_tx_parse_options)(struct sock *sk, u8 pkt, 69 72 u8 opt, u8 *val, u8 len); 70 int (*ccid_hc_tx_send_pack 73 int (*ccid_hc_tx_send_packet)(struct sock *sk, 71 74 struct sk_buff *skb); 72 void (*ccid_hc_tx_packet_se 75 void (*ccid_hc_tx_packet_sent)(struct sock *sk, 73 76 unsigned int len); 74 void (*ccid_hc_rx_get_info) 77 void (*ccid_hc_rx_get_info)(struct sock *sk, 75 78 struct tcp_info *info); 76 void (*ccid_hc_tx_get_info) 79 void (*ccid_hc_tx_get_info)(struct sock *sk, 77 80 struct tcp_info *info); 78 int (*ccid_hc_rx_getsockop 81 int (*ccid_hc_rx_getsockopt)(struct sock *sk, 79 82 const int optname, int len, 80 83 u32 __user *optval, 81 84 int __user *optlen); 82 int (*ccid_hc_tx_getsockop 85 int (*ccid_hc_tx_getsockopt)(struct sock *sk, 83 86 const int optname, int len, 84 87 u32 __user *optval, 85 88 int __user *optlen); 86 }; 89 }; 87 90 88 extern struct ccid_operations ccid2_ops; 91 extern struct ccid_operations ccid2_ops; 89 #ifdef CONFIG_IP_DCCP_CCID3 92 #ifdef CONFIG_IP_DCCP_CCID3 90 extern struct ccid_operations ccid3_ops; 93 extern struct ccid_operations ccid3_ops; 91 #endif 94 #endif 92 95 93 int ccid_initialize_builtins(void); 96 int ccid_initialize_builtins(void); 94 void ccid_cleanup_builtins(void); 97 void ccid_cleanup_builtins(void); 95 98 96 struct ccid { 99 struct ccid { 97 struct ccid_operations *ccid_ops; 100 struct ccid_operations *ccid_ops; 98 char ccid_priv[]; !! 101 char ccid_priv[0]; 99 }; 102 }; 100 103 101 static inline void *ccid_priv(const struct cci 104 static inline void *ccid_priv(const struct ccid *ccid) 102 { 105 { 103 return (void *)ccid->ccid_priv; 106 return (void *)ccid->ccid_priv; 104 } 107 } 105 108 106 bool ccid_support_check(u8 const *ccid_array, 109 bool ccid_support_check(u8 const *ccid_array, u8 array_len); 107 int ccid_get_builtin_ccids(u8 **ccid_array, u8 110 int ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len); 108 int ccid_getsockopt_builtin_ccids(struct sock 111 int ccid_getsockopt_builtin_ccids(struct sock *sk, int len, 109 char __user 112 char __user *, int __user *); 110 113 111 struct ccid *ccid_new(const u8 id, struct sock 114 struct ccid *ccid_new(const u8 id, struct sock *sk, bool rx); 112 115 113 static inline int ccid_get_current_rx_ccid(str 116 static inline int ccid_get_current_rx_ccid(struct dccp_sock *dp) 114 { 117 { 115 struct ccid *ccid = dp->dccps_hc_rx_cc 118 struct ccid *ccid = dp->dccps_hc_rx_ccid; 116 119 117 if (ccid == NULL || ccid->ccid_ops == 120 if (ccid == NULL || ccid->ccid_ops == NULL) 118 return -1; 121 return -1; 119 return ccid->ccid_ops->ccid_id; 122 return ccid->ccid_ops->ccid_id; 120 } 123 } 121 124 122 static inline int ccid_get_current_tx_ccid(str 125 static inline int ccid_get_current_tx_ccid(struct dccp_sock *dp) 123 { 126 { 124 struct ccid *ccid = dp->dccps_hc_tx_cc 127 struct ccid *ccid = dp->dccps_hc_tx_ccid; 125 128 126 if (ccid == NULL || ccid->ccid_ops == 129 if (ccid == NULL || ccid->ccid_ops == NULL) 127 return -1; 130 return -1; 128 return ccid->ccid_ops->ccid_id; 131 return ccid->ccid_ops->ccid_id; 129 } 132 } 130 133 131 void ccid_hc_rx_delete(struct ccid *ccid, stru 134 void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk); 132 void ccid_hc_tx_delete(struct ccid *ccid, stru 135 void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk); 133 136 134 /* 137 /* 135 * Congestion control of queued data packets v 138 * Congestion control of queued data packets via CCID decision. 136 * 139 * 137 * The TX CCID performs its congestion-control 140 * The TX CCID performs its congestion-control by indicating whether and when a 138 * queued packet may be sent, using the return 141 * queued packet may be sent, using the return code of ccid_hc_tx_send_packet(). 139 * The following modes are supported via the s 142 * The following modes are supported via the symbolic constants below: 140 * - timer-based pacing (CCID returns a del 143 * - timer-based pacing (CCID returns a delay value in milliseconds); 141 * - autonomous dequeueing (CCID internally sc 144 * - autonomous dequeueing (CCID internally schedules dccps_xmitlet). 142 */ 145 */ 143 146 144 enum ccid_dequeueing_decision { 147 enum ccid_dequeueing_decision { 145 CCID_PACKET_SEND_AT_ONCE = 0x000 148 CCID_PACKET_SEND_AT_ONCE = 0x00000, /* "green light": no delay */ 146 CCID_PACKET_DELAY_MAX = 0x0FF 149 CCID_PACKET_DELAY_MAX = 0x0FFFF, /* maximum delay in msecs */ 147 CCID_PACKET_DELAY = 0x100 150 CCID_PACKET_DELAY = 0x10000, /* CCID msec-delay mode */ 148 CCID_PACKET_WILL_DEQUEUE_LATER = 0x200 151 CCID_PACKET_WILL_DEQUEUE_LATER = 0x20000, /* CCID autonomous mode */ 149 CCID_PACKET_ERR = 0xF00 152 CCID_PACKET_ERR = 0xF0000, /* error condition */ 150 }; 153 }; 151 154 152 static inline int ccid_packet_dequeue_eval(con 155 static inline int ccid_packet_dequeue_eval(const int return_code) 153 { 156 { 154 if (return_code < 0) 157 if (return_code < 0) 155 return CCID_PACKET_ERR; 158 return CCID_PACKET_ERR; 156 if (return_code == 0) 159 if (return_code == 0) 157 return CCID_PACKET_SEND_AT_ONC 160 return CCID_PACKET_SEND_AT_ONCE; 158 if (return_code <= CCID_PACKET_DELAY_M 161 if (return_code <= CCID_PACKET_DELAY_MAX) 159 return CCID_PACKET_DELAY; 162 return CCID_PACKET_DELAY; 160 return return_code; 163 return return_code; 161 } 164 } 162 165 163 static inline int ccid_hc_tx_send_packet(struc 166 static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, 164 struc 167 struct sk_buff *skb) 165 { 168 { 166 if (ccid->ccid_ops->ccid_hc_tx_send_pa 169 if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL) 167 return ccid->ccid_ops->ccid_hc 170 return ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb); 168 return CCID_PACKET_SEND_AT_ONCE; 171 return CCID_PACKET_SEND_AT_ONCE; 169 } 172 } 170 173 171 static inline void ccid_hc_tx_packet_sent(stru 174 static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, 172 unsi 175 unsigned int len) 173 { 176 { 174 if (ccid->ccid_ops->ccid_hc_tx_packet_ 177 if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL) 175 ccid->ccid_ops->ccid_hc_tx_pac 178 ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, len); 176 } 179 } 177 180 178 static inline void ccid_hc_rx_packet_recv(stru 181 static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, 179 stru 182 struct sk_buff *skb) 180 { 183 { 181 if (ccid->ccid_ops->ccid_hc_rx_packet_ 184 if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL) 182 ccid->ccid_ops->ccid_hc_rx_pac 185 ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb); 183 } 186 } 184 187 185 static inline void ccid_hc_tx_packet_recv(stru 188 static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, 186 stru 189 struct sk_buff *skb) 187 { 190 { 188 if (ccid->ccid_ops->ccid_hc_tx_packet_ 191 if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL) 189 ccid->ccid_ops->ccid_hc_tx_pac 192 ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb); 190 } 193 } 191 194 192 /** 195 /** 193 * ccid_hc_tx_parse_options - Parse CCID-spe 196 * ccid_hc_tx_parse_options - Parse CCID-specific options sent by the receiver 194 * @pkt: type of packet that @opt appears on ( 197 * @pkt: type of packet that @opt appears on (RFC 4340, 5.1) 195 * @opt: the CCID-specific option type (RFC 43 198 * @opt: the CCID-specific option type (RFC 4340, 5.8 and 10.3) 196 * @val: value of @opt 199 * @val: value of @opt 197 * @len: length of @val in bytes 200 * @len: length of @val in bytes 198 */ 201 */ 199 static inline int ccid_hc_tx_parse_options(str 202 static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, 200 u8 203 u8 pkt, u8 opt, u8 *val, u8 len) 201 { 204 { 202 if (!ccid || !ccid->ccid_ops->ccid_hc_ !! 205 if (ccid->ccid_ops->ccid_hc_tx_parse_options == NULL) 203 return 0; 206 return 0; 204 return ccid->ccid_ops->ccid_hc_tx_pars 207 return ccid->ccid_ops->ccid_hc_tx_parse_options(sk, pkt, opt, val, len); 205 } 208 } 206 209 207 /** 210 /** 208 * ccid_hc_rx_parse_options - Parse CCID-spe 211 * ccid_hc_rx_parse_options - Parse CCID-specific options sent by the sender 209 * Arguments are analogous to ccid_hc_tx_parse 212 * Arguments are analogous to ccid_hc_tx_parse_options() 210 */ 213 */ 211 static inline int ccid_hc_rx_parse_options(str 214 static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, 212 u8 215 u8 pkt, u8 opt, u8 *val, u8 len) 213 { 216 { 214 if (!ccid || !ccid->ccid_ops->ccid_hc_ !! 217 if (ccid->ccid_ops->ccid_hc_rx_parse_options == NULL) 215 return 0; 218 return 0; 216 return ccid->ccid_ops->ccid_hc_rx_pars 219 return ccid->ccid_ops->ccid_hc_rx_parse_options(sk, pkt, opt, val, len); 217 } 220 } 218 221 219 static inline int ccid_hc_rx_insert_options(st 222 static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, 220 st 223 struct sk_buff *skb) 221 { 224 { 222 if (ccid->ccid_ops->ccid_hc_rx_insert_ 225 if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL) 223 return ccid->ccid_ops->ccid_hc 226 return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb); 224 return 0; 227 return 0; 225 } 228 } 226 229 227 static inline void ccid_hc_rx_get_info(struct 230 static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk, 228 struct 231 struct tcp_info *info) 229 { 232 { 230 if (ccid->ccid_ops->ccid_hc_rx_get_inf 233 if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL) 231 ccid->ccid_ops->ccid_hc_rx_get 234 ccid->ccid_ops->ccid_hc_rx_get_info(sk, info); 232 } 235 } 233 236 234 static inline void ccid_hc_tx_get_info(struct 237 static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk, 235 struct 238 struct tcp_info *info) 236 { 239 { 237 if (ccid->ccid_ops->ccid_hc_tx_get_inf 240 if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL) 238 ccid->ccid_ops->ccid_hc_tx_get 241 ccid->ccid_ops->ccid_hc_tx_get_info(sk, info); 239 } 242 } 240 243 241 static inline int ccid_hc_rx_getsockopt(struct 244 static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, 242 const 245 const int optname, int len, 243 u32 __ 246 u32 __user *optval, int __user *optlen) 244 { 247 { 245 int rc = -ENOPROTOOPT; 248 int rc = -ENOPROTOOPT; 246 if (ccid != NULL && ccid->ccid_ops->cc 249 if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL) 247 rc = ccid->ccid_ops->ccid_hc_r 250 rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len, 248 251 optval, optlen); 249 return rc; 252 return rc; 250 } 253 } 251 254 252 static inline int ccid_hc_tx_getsockopt(struct 255 static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk, 253 const 256 const int optname, int len, 254 u32 __ 257 u32 __user *optval, int __user *optlen) 255 { 258 { 256 int rc = -ENOPROTOOPT; 259 int rc = -ENOPROTOOPT; 257 if (ccid != NULL && ccid->ccid_ops->cc 260 if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL) 258 rc = ccid->ccid_ops->ccid_hc_t 261 rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len, 259 262 optval, optlen); 260 return rc; 263 return rc; 261 } 264 } 262 #endif /* _CCID_H */ 265 #endif /* _CCID_H */ 263 266
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.