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> |
| 17 | #include <linux/dccp.h> |
| 18 | #include <linux/list.h> |
| 19 | #include <linux/module.h> |
| 20 | |
| 21 | #define CCID_MAX 255 |
| 22 | |
| 23 | struct ccid { |
| 24 | unsigned char ccid_id; |
| 25 | const char *ccid_name; |
| 26 | struct module *ccid_owner; |
| 27 | int (*ccid_init)(struct sock *sk); |
| 28 | void (*ccid_exit)(struct sock *sk); |
| 29 | int (*ccid_hc_rx_init)(struct sock *sk); |
| 30 | int (*ccid_hc_tx_init)(struct sock *sk); |
| 31 | void (*ccid_hc_rx_exit)(struct sock *sk); |
| 32 | void (*ccid_hc_tx_exit)(struct sock *sk); |
| 33 | void (*ccid_hc_rx_packet_recv)(struct sock *sk, struct sk_buff *skb); |
| 34 | int (*ccid_hc_rx_parse_options)(struct sock *sk, |
| 35 | unsigned char option, |
| 36 | unsigned char len, u16 idx, |
| 37 | unsigned char* value); |
| 38 | void (*ccid_hc_rx_insert_options)(struct sock *sk, struct sk_buff *skb); |
| 39 | void (*ccid_hc_tx_insert_options)(struct sock *sk, struct sk_buff *skb); |
| 40 | void (*ccid_hc_tx_packet_recv)(struct sock *sk, struct sk_buff *skb); |
| 41 | int (*ccid_hc_tx_parse_options)(struct sock *sk, |
| 42 | unsigned char option, |
| 43 | unsigned char len, u16 idx, |
| 44 | unsigned char* value); |
| 45 | int (*ccid_hc_tx_send_packet)(struct sock *sk, |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame^] | 46 | struct sk_buff *skb, int len); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 47 | void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more, int len); |
| 48 | }; |
| 49 | |
| 50 | extern int ccid_register(struct ccid *ccid); |
| 51 | extern int ccid_unregister(struct ccid *ccid); |
| 52 | |
| 53 | extern struct ccid *ccid_init(unsigned char id, struct sock *sk); |
| 54 | extern void ccid_exit(struct ccid *ccid, struct sock *sk); |
| 55 | |
| 56 | static inline void __ccid_get(struct ccid *ccid) |
| 57 | { |
| 58 | __module_get(ccid->ccid_owner); |
| 59 | } |
| 60 | |
| 61 | 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^] | 62 | struct sk_buff *skb, int len) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 63 | { |
| 64 | int rc = 0; |
| 65 | if (ccid->ccid_hc_tx_send_packet != NULL) |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame^] | 66 | rc = ccid->ccid_hc_tx_send_packet(sk, skb, len); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 67 | return rc; |
| 68 | } |
| 69 | |
| 70 | static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, |
| 71 | int more, int len) |
| 72 | { |
| 73 | if (ccid->ccid_hc_tx_packet_sent != NULL) |
| 74 | ccid->ccid_hc_tx_packet_sent(sk, more, len); |
| 75 | } |
| 76 | |
| 77 | static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk) |
| 78 | { |
| 79 | int rc = 0; |
| 80 | if (ccid->ccid_hc_rx_init != NULL) |
| 81 | rc = ccid->ccid_hc_rx_init(sk); |
| 82 | return rc; |
| 83 | } |
| 84 | |
| 85 | static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk) |
| 86 | { |
| 87 | int rc = 0; |
| 88 | if (ccid->ccid_hc_tx_init != NULL) |
| 89 | rc = ccid->ccid_hc_tx_init(sk); |
| 90 | return rc; |
| 91 | } |
| 92 | |
| 93 | static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk) |
| 94 | { |
| 95 | if (ccid->ccid_hc_rx_exit != NULL) |
| 96 | ccid->ccid_hc_rx_exit(sk); |
| 97 | } |
| 98 | |
| 99 | static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk) |
| 100 | { |
| 101 | if (ccid->ccid_hc_tx_exit != NULL) |
| 102 | ccid->ccid_hc_tx_exit(sk); |
| 103 | } |
| 104 | |
| 105 | static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, |
| 106 | struct sk_buff *skb) |
| 107 | { |
| 108 | if (ccid->ccid_hc_rx_packet_recv != NULL) |
| 109 | ccid->ccid_hc_rx_packet_recv(sk, skb); |
| 110 | } |
| 111 | |
| 112 | static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, |
| 113 | struct sk_buff *skb) |
| 114 | { |
| 115 | if (ccid->ccid_hc_tx_packet_recv != NULL) |
| 116 | ccid->ccid_hc_tx_packet_recv(sk, skb); |
| 117 | } |
| 118 | |
| 119 | static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, |
| 120 | unsigned char option, |
| 121 | unsigned char len, u16 idx, |
| 122 | unsigned char* value) |
| 123 | { |
| 124 | int rc = 0; |
| 125 | if (ccid->ccid_hc_tx_parse_options != NULL) |
| 126 | rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx, value); |
| 127 | return rc; |
| 128 | } |
| 129 | |
| 130 | static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, |
| 131 | unsigned char option, |
| 132 | unsigned char len, u16 idx, |
| 133 | unsigned char* value) |
| 134 | { |
| 135 | int rc = 0; |
| 136 | if (ccid->ccid_hc_rx_parse_options != NULL) |
| 137 | rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value); |
| 138 | return rc; |
| 139 | } |
| 140 | |
| 141 | static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, |
| 142 | struct sk_buff *skb) |
| 143 | { |
| 144 | if (ccid->ccid_hc_tx_insert_options != NULL) |
| 145 | ccid->ccid_hc_tx_insert_options(sk, skb); |
| 146 | } |
| 147 | |
| 148 | static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, |
| 149 | struct sk_buff *skb) |
| 150 | { |
| 151 | if (ccid->ccid_hc_rx_insert_options != NULL) |
| 152 | ccid->ccid_hc_rx_insert_options(sk, skb); |
| 153 | } |
| 154 | #endif /* _CCID_H */ |