18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci#ifndef _CCID_H 38c2ecf20Sopenharmony_ci#define _CCID_H 48c2ecf20Sopenharmony_ci/* 58c2ecf20Sopenharmony_ci * net/dccp/ccid.h 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * An implementation of the DCCP protocol 88c2ecf20Sopenharmony_ci * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * CCID infrastructure 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <net/sock.h> 148c2ecf20Sopenharmony_ci#include <linux/compiler.h> 158c2ecf20Sopenharmony_ci#include <linux/dccp.h> 168c2ecf20Sopenharmony_ci#include <linux/list.h> 178c2ecf20Sopenharmony_ci#include <linux/module.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* maximum value for a CCID (RFC 4340, 19.5) */ 208c2ecf20Sopenharmony_ci#define CCID_MAX 255 218c2ecf20Sopenharmony_ci#define CCID_SLAB_NAME_LENGTH 32 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistruct tcp_info; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/** 268c2ecf20Sopenharmony_ci * struct ccid_operations - Interface to Congestion-Control Infrastructure 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * @ccid_id: numerical CCID ID (up to %CCID_MAX, cf. table 5 in RFC 4340, 10.) 298c2ecf20Sopenharmony_ci * @ccid_ccmps: the CCMPS including network/transport headers (0 when disabled) 308c2ecf20Sopenharmony_ci * @ccid_name: alphabetical identifier string for @ccid_id 318c2ecf20Sopenharmony_ci * @ccid_hc_{r,t}x_slab: memory pool for the receiver/sender half-connection 328c2ecf20Sopenharmony_ci * @ccid_hc_{r,t}x_obj_size: size of the receiver/sender half-connection socket 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * @ccid_hc_{r,t}x_init: CCID-specific initialisation routine (before startup) 358c2ecf20Sopenharmony_ci * @ccid_hc_{r,t}x_exit: CCID-specific cleanup routine (before destruction) 368c2ecf20Sopenharmony_ci * @ccid_hc_rx_packet_recv: implements the HC-receiver side 378c2ecf20Sopenharmony_ci * @ccid_hc_{r,t}x_parse_options: parsing routine for CCID/HC-specific options 388c2ecf20Sopenharmony_ci * @ccid_hc_{r,t}x_insert_options: insert routine for CCID/HC-specific options 398c2ecf20Sopenharmony_ci * @ccid_hc_tx_packet_recv: implements feedback processing for the HC-sender 408c2ecf20Sopenharmony_ci * @ccid_hc_tx_send_packet: implements the sending part of the HC-sender 418c2ecf20Sopenharmony_ci * @ccid_hc_tx_packet_sent: does accounting for packets in flight by HC-sender 428c2ecf20Sopenharmony_ci * @ccid_hc_{r,t}x_get_info: INET_DIAG information for HC-receiver/sender 438c2ecf20Sopenharmony_ci * @ccid_hc_{r,t}x_getsockopt: socket options specific to HC-receiver/sender 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_cistruct ccid_operations { 468c2ecf20Sopenharmony_ci unsigned char ccid_id; 478c2ecf20Sopenharmony_ci __u32 ccid_ccmps; 488c2ecf20Sopenharmony_ci const char *ccid_name; 498c2ecf20Sopenharmony_ci struct kmem_cache *ccid_hc_rx_slab, 508c2ecf20Sopenharmony_ci *ccid_hc_tx_slab; 518c2ecf20Sopenharmony_ci char ccid_hc_rx_slab_name[CCID_SLAB_NAME_LENGTH]; 528c2ecf20Sopenharmony_ci char ccid_hc_tx_slab_name[CCID_SLAB_NAME_LENGTH]; 538c2ecf20Sopenharmony_ci __u32 ccid_hc_rx_obj_size, 548c2ecf20Sopenharmony_ci ccid_hc_tx_obj_size; 558c2ecf20Sopenharmony_ci /* Interface Routines */ 568c2ecf20Sopenharmony_ci int (*ccid_hc_rx_init)(struct ccid *ccid, struct sock *sk); 578c2ecf20Sopenharmony_ci int (*ccid_hc_tx_init)(struct ccid *ccid, struct sock *sk); 588c2ecf20Sopenharmony_ci void (*ccid_hc_rx_exit)(struct sock *sk); 598c2ecf20Sopenharmony_ci void (*ccid_hc_tx_exit)(struct sock *sk); 608c2ecf20Sopenharmony_ci void (*ccid_hc_rx_packet_recv)(struct sock *sk, 618c2ecf20Sopenharmony_ci struct sk_buff *skb); 628c2ecf20Sopenharmony_ci int (*ccid_hc_rx_parse_options)(struct sock *sk, u8 pkt, 638c2ecf20Sopenharmony_ci u8 opt, u8 *val, u8 len); 648c2ecf20Sopenharmony_ci int (*ccid_hc_rx_insert_options)(struct sock *sk, 658c2ecf20Sopenharmony_ci struct sk_buff *skb); 668c2ecf20Sopenharmony_ci void (*ccid_hc_tx_packet_recv)(struct sock *sk, 678c2ecf20Sopenharmony_ci struct sk_buff *skb); 688c2ecf20Sopenharmony_ci int (*ccid_hc_tx_parse_options)(struct sock *sk, u8 pkt, 698c2ecf20Sopenharmony_ci u8 opt, u8 *val, u8 len); 708c2ecf20Sopenharmony_ci int (*ccid_hc_tx_send_packet)(struct sock *sk, 718c2ecf20Sopenharmony_ci struct sk_buff *skb); 728c2ecf20Sopenharmony_ci void (*ccid_hc_tx_packet_sent)(struct sock *sk, 738c2ecf20Sopenharmony_ci unsigned int len); 748c2ecf20Sopenharmony_ci void (*ccid_hc_rx_get_info)(struct sock *sk, 758c2ecf20Sopenharmony_ci struct tcp_info *info); 768c2ecf20Sopenharmony_ci void (*ccid_hc_tx_get_info)(struct sock *sk, 778c2ecf20Sopenharmony_ci struct tcp_info *info); 788c2ecf20Sopenharmony_ci int (*ccid_hc_rx_getsockopt)(struct sock *sk, 798c2ecf20Sopenharmony_ci const int optname, int len, 808c2ecf20Sopenharmony_ci u32 __user *optval, 818c2ecf20Sopenharmony_ci int __user *optlen); 828c2ecf20Sopenharmony_ci int (*ccid_hc_tx_getsockopt)(struct sock *sk, 838c2ecf20Sopenharmony_ci const int optname, int len, 848c2ecf20Sopenharmony_ci u32 __user *optval, 858c2ecf20Sopenharmony_ci int __user *optlen); 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ciextern struct ccid_operations ccid2_ops; 898c2ecf20Sopenharmony_ci#ifdef CONFIG_IP_DCCP_CCID3 908c2ecf20Sopenharmony_ciextern struct ccid_operations ccid3_ops; 918c2ecf20Sopenharmony_ci#endif 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ciint ccid_initialize_builtins(void); 948c2ecf20Sopenharmony_civoid ccid_cleanup_builtins(void); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistruct ccid { 978c2ecf20Sopenharmony_ci struct ccid_operations *ccid_ops; 988c2ecf20Sopenharmony_ci char ccid_priv[]; 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistatic inline void *ccid_priv(const struct ccid *ccid) 1028c2ecf20Sopenharmony_ci{ 1038c2ecf20Sopenharmony_ci return (void *)ccid->ccid_priv; 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cibool ccid_support_check(u8 const *ccid_array, u8 array_len); 1078c2ecf20Sopenharmony_ciint ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len); 1088c2ecf20Sopenharmony_ciint ccid_getsockopt_builtin_ccids(struct sock *sk, int len, 1098c2ecf20Sopenharmony_ci char __user *, int __user *); 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistruct ccid *ccid_new(const u8 id, struct sock *sk, bool rx); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic inline int ccid_get_current_rx_ccid(struct dccp_sock *dp) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci struct ccid *ccid = dp->dccps_hc_rx_ccid; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci if (ccid == NULL || ccid->ccid_ops == NULL) 1188c2ecf20Sopenharmony_ci return -1; 1198c2ecf20Sopenharmony_ci return ccid->ccid_ops->ccid_id; 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic inline int ccid_get_current_tx_ccid(struct dccp_sock *dp) 1238c2ecf20Sopenharmony_ci{ 1248c2ecf20Sopenharmony_ci struct ccid *ccid = dp->dccps_hc_tx_ccid; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci if (ccid == NULL || ccid->ccid_ops == NULL) 1278c2ecf20Sopenharmony_ci return -1; 1288c2ecf20Sopenharmony_ci return ccid->ccid_ops->ccid_id; 1298c2ecf20Sopenharmony_ci} 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_civoid ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk); 1328c2ecf20Sopenharmony_civoid ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci/* 1358c2ecf20Sopenharmony_ci * Congestion control of queued data packets via CCID decision. 1368c2ecf20Sopenharmony_ci * 1378c2ecf20Sopenharmony_ci * The TX CCID performs its congestion-control by indicating whether and when a 1388c2ecf20Sopenharmony_ci * queued packet may be sent, using the return code of ccid_hc_tx_send_packet(). 1398c2ecf20Sopenharmony_ci * The following modes are supported via the symbolic constants below: 1408c2ecf20Sopenharmony_ci * - timer-based pacing (CCID returns a delay value in milliseconds); 1418c2ecf20Sopenharmony_ci * - autonomous dequeueing (CCID internally schedules dccps_xmitlet). 1428c2ecf20Sopenharmony_ci */ 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cienum ccid_dequeueing_decision { 1458c2ecf20Sopenharmony_ci CCID_PACKET_SEND_AT_ONCE = 0x00000, /* "green light": no delay */ 1468c2ecf20Sopenharmony_ci CCID_PACKET_DELAY_MAX = 0x0FFFF, /* maximum delay in msecs */ 1478c2ecf20Sopenharmony_ci CCID_PACKET_DELAY = 0x10000, /* CCID msec-delay mode */ 1488c2ecf20Sopenharmony_ci CCID_PACKET_WILL_DEQUEUE_LATER = 0x20000, /* CCID autonomous mode */ 1498c2ecf20Sopenharmony_ci CCID_PACKET_ERR = 0xF0000, /* error condition */ 1508c2ecf20Sopenharmony_ci}; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistatic inline int ccid_packet_dequeue_eval(const int return_code) 1538c2ecf20Sopenharmony_ci{ 1548c2ecf20Sopenharmony_ci if (return_code < 0) 1558c2ecf20Sopenharmony_ci return CCID_PACKET_ERR; 1568c2ecf20Sopenharmony_ci if (return_code == 0) 1578c2ecf20Sopenharmony_ci return CCID_PACKET_SEND_AT_ONCE; 1588c2ecf20Sopenharmony_ci if (return_code <= CCID_PACKET_DELAY_MAX) 1598c2ecf20Sopenharmony_ci return CCID_PACKET_DELAY; 1608c2ecf20Sopenharmony_ci return return_code; 1618c2ecf20Sopenharmony_ci} 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistatic inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, 1648c2ecf20Sopenharmony_ci struct sk_buff *skb) 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL) 1678c2ecf20Sopenharmony_ci return ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb); 1688c2ecf20Sopenharmony_ci return CCID_PACKET_SEND_AT_ONCE; 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, 1728c2ecf20Sopenharmony_ci unsigned int len) 1738c2ecf20Sopenharmony_ci{ 1748c2ecf20Sopenharmony_ci if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL) 1758c2ecf20Sopenharmony_ci ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, len); 1768c2ecf20Sopenharmony_ci} 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistatic inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, 1798c2ecf20Sopenharmony_ci struct sk_buff *skb) 1808c2ecf20Sopenharmony_ci{ 1818c2ecf20Sopenharmony_ci if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL) 1828c2ecf20Sopenharmony_ci ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb); 1838c2ecf20Sopenharmony_ci} 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_cistatic inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, 1868c2ecf20Sopenharmony_ci struct sk_buff *skb) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL) 1898c2ecf20Sopenharmony_ci ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb); 1908c2ecf20Sopenharmony_ci} 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/** 1938c2ecf20Sopenharmony_ci * ccid_hc_tx_parse_options - Parse CCID-specific options sent by the receiver 1948c2ecf20Sopenharmony_ci * @pkt: type of packet that @opt appears on (RFC 4340, 5.1) 1958c2ecf20Sopenharmony_ci * @opt: the CCID-specific option type (RFC 4340, 5.8 and 10.3) 1968c2ecf20Sopenharmony_ci * @val: value of @opt 1978c2ecf20Sopenharmony_ci * @len: length of @val in bytes 1988c2ecf20Sopenharmony_ci */ 1998c2ecf20Sopenharmony_cistatic inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, 2008c2ecf20Sopenharmony_ci u8 pkt, u8 opt, u8 *val, u8 len) 2018c2ecf20Sopenharmony_ci{ 2028c2ecf20Sopenharmony_ci if (!ccid || !ccid->ccid_ops->ccid_hc_tx_parse_options) 2038c2ecf20Sopenharmony_ci return 0; 2048c2ecf20Sopenharmony_ci return ccid->ccid_ops->ccid_hc_tx_parse_options(sk, pkt, opt, val, len); 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci/** 2088c2ecf20Sopenharmony_ci * ccid_hc_rx_parse_options - Parse CCID-specific options sent by the sender 2098c2ecf20Sopenharmony_ci * Arguments are analogous to ccid_hc_tx_parse_options() 2108c2ecf20Sopenharmony_ci */ 2118c2ecf20Sopenharmony_cistatic inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, 2128c2ecf20Sopenharmony_ci u8 pkt, u8 opt, u8 *val, u8 len) 2138c2ecf20Sopenharmony_ci{ 2148c2ecf20Sopenharmony_ci if (!ccid || !ccid->ccid_ops->ccid_hc_rx_parse_options) 2158c2ecf20Sopenharmony_ci return 0; 2168c2ecf20Sopenharmony_ci return ccid->ccid_ops->ccid_hc_rx_parse_options(sk, pkt, opt, val, len); 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistatic inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, 2208c2ecf20Sopenharmony_ci struct sk_buff *skb) 2218c2ecf20Sopenharmony_ci{ 2228c2ecf20Sopenharmony_ci if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL) 2238c2ecf20Sopenharmony_ci return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb); 2248c2ecf20Sopenharmony_ci return 0; 2258c2ecf20Sopenharmony_ci} 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_cistatic inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk, 2288c2ecf20Sopenharmony_ci struct tcp_info *info) 2298c2ecf20Sopenharmony_ci{ 2308c2ecf20Sopenharmony_ci if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL) 2318c2ecf20Sopenharmony_ci ccid->ccid_ops->ccid_hc_rx_get_info(sk, info); 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_cistatic inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk, 2358c2ecf20Sopenharmony_ci struct tcp_info *info) 2368c2ecf20Sopenharmony_ci{ 2378c2ecf20Sopenharmony_ci if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL) 2388c2ecf20Sopenharmony_ci ccid->ccid_ops->ccid_hc_tx_get_info(sk, info); 2398c2ecf20Sopenharmony_ci} 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_cistatic inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, 2428c2ecf20Sopenharmony_ci const int optname, int len, 2438c2ecf20Sopenharmony_ci u32 __user *optval, int __user *optlen) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci int rc = -ENOPROTOOPT; 2468c2ecf20Sopenharmony_ci if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL) 2478c2ecf20Sopenharmony_ci rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len, 2488c2ecf20Sopenharmony_ci optval, optlen); 2498c2ecf20Sopenharmony_ci return rc; 2508c2ecf20Sopenharmony_ci} 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_cistatic inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk, 2538c2ecf20Sopenharmony_ci const int optname, int len, 2548c2ecf20Sopenharmony_ci u32 __user *optval, int __user *optlen) 2558c2ecf20Sopenharmony_ci{ 2568c2ecf20Sopenharmony_ci int rc = -ENOPROTOOPT; 2578c2ecf20Sopenharmony_ci if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL) 2588c2ecf20Sopenharmony_ci rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len, 2598c2ecf20Sopenharmony_ci optval, optlen); 2608c2ecf20Sopenharmony_ci return rc; 2618c2ecf20Sopenharmony_ci} 2628c2ecf20Sopenharmony_ci#endif /* _CCID_H */ 263