Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1 | #ifndef _CCID_H |
| 2 | #define _CCID_H |
| 3 | /* |
| 4 | * net/dccp/ccid.h |
| 5 | * |
| 6 | * An implementation of the DCCP protocol |
| 7 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 8 | * |
| 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. |
| 14 | */ |
| 15 | |
| 16 | #include <net/sock.h> |
Arnaldo Carvalho de Melo | 88f964d | 2005-09-18 00:19:32 -0700 | [diff] [blame] | 17 | #include <linux/compiler.h> |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 18 | #include <linux/dccp.h> |
| 19 | #include <linux/list.h> |
| 20 | #include <linux/module.h> |
| 21 | |
| 22 | #define CCID_MAX 255 |
| 23 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 24 | struct tcp_info; |
| 25 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 26 | struct ccid_operations { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 27 | unsigned char ccid_id; |
| 28 | const char *ccid_name; |
| 29 | struct module *ccid_owner; |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 30 | kmem_cache_t *ccid_hc_rx_slab; |
| 31 | __u32 ccid_hc_rx_obj_size; |
| 32 | kmem_cache_t *ccid_hc_tx_slab; |
| 33 | __u32 ccid_hc_tx_obj_size; |
| 34 | int (*ccid_hc_rx_init)(struct ccid *ccid, struct sock *sk); |
| 35 | int (*ccid_hc_tx_init)(struct ccid *ccid, struct sock *sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 36 | void (*ccid_hc_rx_exit)(struct sock *sk); |
| 37 | void (*ccid_hc_tx_exit)(struct sock *sk); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 38 | void (*ccid_hc_rx_packet_recv)(struct sock *sk, |
| 39 | struct sk_buff *skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 40 | int (*ccid_hc_rx_parse_options)(struct sock *sk, |
| 41 | unsigned char option, |
| 42 | unsigned char len, u16 idx, |
| 43 | unsigned char* value); |
Arnaldo Carvalho de Melo | 2d0817d | 2006-03-20 22:32:06 -0800 | [diff] [blame^] | 44 | int (*ccid_hc_rx_insert_options)(struct sock *sk, |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 45 | struct sk_buff *skb); |
Arnaldo Carvalho de Melo | 2d0817d | 2006-03-20 22:32:06 -0800 | [diff] [blame^] | 46 | int (*ccid_hc_tx_insert_options)(struct sock *sk, |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 47 | struct sk_buff *skb); |
| 48 | void (*ccid_hc_tx_packet_recv)(struct sock *sk, |
| 49 | struct sk_buff *skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 50 | int (*ccid_hc_tx_parse_options)(struct sock *sk, |
| 51 | unsigned char option, |
| 52 | unsigned char len, u16 idx, |
| 53 | unsigned char* value); |
| 54 | int (*ccid_hc_tx_send_packet)(struct sock *sk, |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 55 | struct sk_buff *skb, int len); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 56 | void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more, |
| 57 | int len); |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 58 | void (*ccid_hc_rx_get_info)(struct sock *sk, |
| 59 | struct tcp_info *info); |
| 60 | void (*ccid_hc_tx_get_info)(struct sock *sk, |
| 61 | struct tcp_info *info); |
Arnaldo Carvalho de Melo | 88f964d | 2005-09-18 00:19:32 -0700 | [diff] [blame] | 62 | int (*ccid_hc_rx_getsockopt)(struct sock *sk, |
| 63 | const int optname, int len, |
| 64 | u32 __user *optval, |
| 65 | int __user *optlen); |
| 66 | int (*ccid_hc_tx_getsockopt)(struct sock *sk, |
| 67 | const int optname, int len, |
| 68 | u32 __user *optval, |
| 69 | int __user *optlen); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 72 | extern int ccid_register(struct ccid_operations *ccid_ops); |
| 73 | extern int ccid_unregister(struct ccid_operations *ccid_ops); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 74 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 75 | struct ccid { |
| 76 | struct ccid_operations *ccid_ops; |
| 77 | char ccid_priv[0]; |
| 78 | }; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 79 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 80 | static inline void *ccid_priv(const struct ccid *ccid) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 81 | { |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 82 | return (void *)ccid->ccid_priv; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 85 | extern struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx, |
| 86 | gfp_t gfp); |
| 87 | |
| 88 | extern struct ccid *ccid_hc_rx_new(unsigned char id, struct sock *sk, |
| 89 | gfp_t gfp); |
| 90 | extern struct ccid *ccid_hc_tx_new(unsigned char id, struct sock *sk, |
| 91 | gfp_t gfp); |
| 92 | |
| 93 | extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk); |
| 94 | extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk); |
| 95 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 96 | static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 97 | struct sk_buff *skb, int len) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 98 | { |
| 99 | int rc = 0; |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 100 | if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL) |
| 101 | rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb, len); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 102 | return rc; |
| 103 | } |
| 104 | |
| 105 | static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, |
| 106 | int more, int len) |
| 107 | { |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 108 | if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL) |
| 109 | ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, |
| 113 | struct sk_buff *skb) |
| 114 | { |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 115 | if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL) |
| 116 | ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, |
| 120 | struct sk_buff *skb) |
| 121 | { |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 122 | if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL) |
| 123 | ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, |
| 127 | unsigned char option, |
| 128 | unsigned char len, u16 idx, |
| 129 | unsigned char* value) |
| 130 | { |
| 131 | int rc = 0; |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 132 | if (ccid->ccid_ops->ccid_hc_tx_parse_options != NULL) |
| 133 | rc = ccid->ccid_ops->ccid_hc_tx_parse_options(sk, option, len, idx, |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 134 | value); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 135 | return rc; |
| 136 | } |
| 137 | |
| 138 | static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, |
| 139 | unsigned char option, |
| 140 | unsigned char len, u16 idx, |
| 141 | unsigned char* value) |
| 142 | { |
| 143 | int rc = 0; |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 144 | if (ccid->ccid_ops->ccid_hc_rx_parse_options != NULL) |
| 145 | rc = ccid->ccid_ops->ccid_hc_rx_parse_options(sk, option, len, idx, value); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 146 | return rc; |
| 147 | } |
| 148 | |
Arnaldo Carvalho de Melo | 2d0817d | 2006-03-20 22:32:06 -0800 | [diff] [blame^] | 149 | static inline int ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, |
| 150 | struct sk_buff *skb) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 151 | { |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 152 | if (ccid->ccid_ops->ccid_hc_tx_insert_options != NULL) |
Arnaldo Carvalho de Melo | 2d0817d | 2006-03-20 22:32:06 -0800 | [diff] [blame^] | 153 | return ccid->ccid_ops->ccid_hc_tx_insert_options(sk, skb); |
| 154 | return 0; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Arnaldo Carvalho de Melo | 2d0817d | 2006-03-20 22:32:06 -0800 | [diff] [blame^] | 157 | static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, |
| 158 | struct sk_buff *skb) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 159 | { |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 160 | if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL) |
Arnaldo Carvalho de Melo | 2d0817d | 2006-03-20 22:32:06 -0800 | [diff] [blame^] | 161 | return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb); |
| 162 | return 0; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 163 | } |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 164 | |
| 165 | static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk, |
| 166 | struct tcp_info *info) |
| 167 | { |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 168 | if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL) |
| 169 | ccid->ccid_ops->ccid_hc_rx_get_info(sk, info); |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk, |
| 173 | struct tcp_info *info) |
| 174 | { |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 175 | if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL) |
| 176 | ccid->ccid_ops->ccid_hc_tx_get_info(sk, info); |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 177 | } |
Arnaldo Carvalho de Melo | 88f964d | 2005-09-18 00:19:32 -0700 | [diff] [blame] | 178 | |
| 179 | static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, |
| 180 | const int optname, int len, |
| 181 | u32 __user *optval, int __user *optlen) |
| 182 | { |
| 183 | int rc = -ENOPROTOOPT; |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 184 | if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL) |
| 185 | rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len, |
Arnaldo Carvalho de Melo | 88f964d | 2005-09-18 00:19:32 -0700 | [diff] [blame] | 186 | optval, optlen); |
| 187 | return rc; |
| 188 | } |
| 189 | |
| 190 | static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk, |
| 191 | const int optname, int len, |
| 192 | u32 __user *optval, int __user *optlen) |
| 193 | { |
| 194 | int rc = -ENOPROTOOPT; |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 195 | if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL) |
| 196 | rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len, |
Arnaldo Carvalho de Melo | 88f964d | 2005-09-18 00:19:32 -0700 | [diff] [blame] | 197 | optval, optlen); |
| 198 | return rc; |
| 199 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 200 | #endif /* _CCID_H */ |