0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include <linux/types.h>
0029 #include <linux/compiler.h>
0030 #include <linux/slab.h>
0031 #include <linux/in.h>
0032 #include <net/sctp/command.h>
0033 #include <net/sctp/sctp.h>
0034
0035 #ifndef __sctp_sm_h__
0036 #define __sctp_sm_h__
0037
0038
0039
0040
0041 enum sctp_disposition {
0042 SCTP_DISPOSITION_DISCARD,
0043 SCTP_DISPOSITION_CONSUME,
0044 SCTP_DISPOSITION_NOMEM,
0045 SCTP_DISPOSITION_DELETE_TCB,
0046 SCTP_DISPOSITION_ABORT,
0047 SCTP_DISPOSITION_VIOLATION,
0048 SCTP_DISPOSITION_NOT_IMPL,
0049 SCTP_DISPOSITION_ERROR,
0050 SCTP_DISPOSITION_BUG,
0051 };
0052
0053 typedef enum sctp_disposition (sctp_state_fn_t) (
0054 struct net *net,
0055 const struct sctp_endpoint *ep,
0056 const struct sctp_association *asoc,
0057 const union sctp_subtype type,
0058 void *arg,
0059 struct sctp_cmd_seq *commands);
0060 typedef void (sctp_timer_event_t) (struct timer_list *);
0061 struct sctp_sm_table_entry {
0062 sctp_state_fn_t *fn;
0063 const char *name;
0064 };
0065
0066
0067
0068
0069
0070
0071 sctp_state_fn_t sctp_sf_not_impl;
0072 sctp_state_fn_t sctp_sf_bug;
0073
0074
0075 sctp_state_fn_t sctp_sf_timer_ignore;
0076
0077
0078 sctp_state_fn_t sctp_sf_do_9_1_abort;
0079 sctp_state_fn_t sctp_sf_cookie_wait_abort;
0080 sctp_state_fn_t sctp_sf_cookie_echoed_abort;
0081 sctp_state_fn_t sctp_sf_shutdown_pending_abort;
0082 sctp_state_fn_t sctp_sf_shutdown_sent_abort;
0083 sctp_state_fn_t sctp_sf_shutdown_ack_sent_abort;
0084 sctp_state_fn_t sctp_sf_do_5_1B_init;
0085 sctp_state_fn_t sctp_sf_do_5_1C_ack;
0086 sctp_state_fn_t sctp_sf_do_5_1D_ce;
0087 sctp_state_fn_t sctp_sf_do_5_1E_ca;
0088 sctp_state_fn_t sctp_sf_do_4_C;
0089 sctp_state_fn_t sctp_sf_eat_data_6_2;
0090 sctp_state_fn_t sctp_sf_eat_data_fast_4_4;
0091 sctp_state_fn_t sctp_sf_eat_sack_6_2;
0092 sctp_state_fn_t sctp_sf_operr_notify;
0093 sctp_state_fn_t sctp_sf_t1_init_timer_expire;
0094 sctp_state_fn_t sctp_sf_t1_cookie_timer_expire;
0095 sctp_state_fn_t sctp_sf_t2_timer_expire;
0096 sctp_state_fn_t sctp_sf_t4_timer_expire;
0097 sctp_state_fn_t sctp_sf_t5_timer_expire;
0098 sctp_state_fn_t sctp_sf_sendbeat_8_3;
0099 sctp_state_fn_t sctp_sf_beat_8_3;
0100 sctp_state_fn_t sctp_sf_backbeat_8_3;
0101 sctp_state_fn_t sctp_sf_do_9_2_final;
0102 sctp_state_fn_t sctp_sf_do_9_2_shutdown;
0103 sctp_state_fn_t sctp_sf_do_9_2_shut_ctsn;
0104 sctp_state_fn_t sctp_sf_do_ecn_cwr;
0105 sctp_state_fn_t sctp_sf_do_ecne;
0106 sctp_state_fn_t sctp_sf_ootb;
0107 sctp_state_fn_t sctp_sf_pdiscard;
0108 sctp_state_fn_t sctp_sf_violation;
0109 sctp_state_fn_t sctp_sf_discard_chunk;
0110 sctp_state_fn_t sctp_sf_do_5_2_1_siminit;
0111 sctp_state_fn_t sctp_sf_do_5_2_2_dupinit;
0112 sctp_state_fn_t sctp_sf_do_5_2_3_initack;
0113 sctp_state_fn_t sctp_sf_do_5_2_4_dupcook;
0114 sctp_state_fn_t sctp_sf_unk_chunk;
0115 sctp_state_fn_t sctp_sf_do_8_5_1_E_sa;
0116 sctp_state_fn_t sctp_sf_cookie_echoed_err;
0117 sctp_state_fn_t sctp_sf_do_asconf;
0118 sctp_state_fn_t sctp_sf_do_asconf_ack;
0119 sctp_state_fn_t sctp_sf_do_reconf;
0120 sctp_state_fn_t sctp_sf_do_9_2_reshutack;
0121 sctp_state_fn_t sctp_sf_eat_fwd_tsn;
0122 sctp_state_fn_t sctp_sf_eat_fwd_tsn_fast;
0123 sctp_state_fn_t sctp_sf_eat_auth;
0124
0125
0126 sctp_state_fn_t sctp_sf_do_prm_asoc;
0127 sctp_state_fn_t sctp_sf_do_prm_send;
0128 sctp_state_fn_t sctp_sf_do_9_2_prm_shutdown;
0129 sctp_state_fn_t sctp_sf_cookie_wait_prm_shutdown;
0130 sctp_state_fn_t sctp_sf_cookie_echoed_prm_shutdown;
0131 sctp_state_fn_t sctp_sf_do_9_1_prm_abort;
0132 sctp_state_fn_t sctp_sf_cookie_wait_prm_abort;
0133 sctp_state_fn_t sctp_sf_cookie_echoed_prm_abort;
0134 sctp_state_fn_t sctp_sf_shutdown_pending_prm_abort;
0135 sctp_state_fn_t sctp_sf_shutdown_sent_prm_abort;
0136 sctp_state_fn_t sctp_sf_shutdown_ack_sent_prm_abort;
0137 sctp_state_fn_t sctp_sf_error_closed;
0138 sctp_state_fn_t sctp_sf_error_shutdown;
0139 sctp_state_fn_t sctp_sf_ignore_primitive;
0140 sctp_state_fn_t sctp_sf_do_prm_requestheartbeat;
0141 sctp_state_fn_t sctp_sf_do_prm_asconf;
0142 sctp_state_fn_t sctp_sf_do_prm_reconf;
0143
0144
0145 sctp_state_fn_t sctp_sf_do_no_pending_tsn;
0146 sctp_state_fn_t sctp_sf_do_9_2_start_shutdown;
0147 sctp_state_fn_t sctp_sf_do_9_2_shutdown_ack;
0148 sctp_state_fn_t sctp_sf_ignore_other;
0149 sctp_state_fn_t sctp_sf_cookie_wait_icmp_abort;
0150
0151
0152 sctp_state_fn_t sctp_sf_do_6_3_3_rtx;
0153 sctp_state_fn_t sctp_sf_send_reconf;
0154 sctp_state_fn_t sctp_sf_send_probe;
0155 sctp_state_fn_t sctp_sf_do_6_2_sack;
0156 sctp_state_fn_t sctp_sf_autoclose_timer_expire;
0157
0158
0159 __u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
0160 const struct sctp_sm_table_entry *sctp_sm_lookup_event(
0161 struct net *net,
0162 enum sctp_event_type event_type,
0163 enum sctp_state state,
0164 union sctp_subtype event_subtype);
0165 int sctp_chunk_iif(const struct sctp_chunk *);
0166 struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
0167 struct sctp_chunk *,
0168 gfp_t gfp);
0169 __u32 sctp_generate_verification_tag(void);
0170 void sctp_populate_tie_tags(__u8 *cookie, __u32 curTag, __u32 hisTag);
0171
0172
0173 struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
0174 const struct sctp_bind_addr *bp,
0175 gfp_t gfp, int vparam_len);
0176 struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
0177 const struct sctp_chunk *chunk,
0178 const gfp_t gfp, const int unkparam_len);
0179 struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *asoc,
0180 const struct sctp_chunk *chunk);
0181 struct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *asoc,
0182 const struct sctp_chunk *chunk);
0183 struct sctp_chunk *sctp_make_cwr(const struct sctp_association *asoc,
0184 const __u32 lowest_tsn,
0185 const struct sctp_chunk *chunk);
0186 struct sctp_chunk *sctp_make_idata(const struct sctp_association *asoc,
0187 __u8 flags, int paylen, gfp_t gfp);
0188 struct sctp_chunk *sctp_make_ifwdtsn(const struct sctp_association *asoc,
0189 __u32 new_cum_tsn, size_t nstreams,
0190 struct sctp_ifwdtsn_skip *skiplist);
0191 struct sctp_chunk *sctp_make_datafrag_empty(const struct sctp_association *asoc,
0192 const struct sctp_sndrcvinfo *sinfo,
0193 int len, __u8 flags, gfp_t gfp);
0194 struct sctp_chunk *sctp_make_ecne(const struct sctp_association *asoc,
0195 const __u32 lowest_tsn);
0196 struct sctp_chunk *sctp_make_sack(struct sctp_association *asoc);
0197 struct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc,
0198 const struct sctp_chunk *chunk);
0199 struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc,
0200 const struct sctp_chunk *chunk);
0201 struct sctp_chunk *sctp_make_shutdown_complete(
0202 const struct sctp_association *asoc,
0203 const struct sctp_chunk *chunk);
0204 int sctp_init_cause(struct sctp_chunk *chunk, __be16 cause, size_t paylen);
0205 struct sctp_chunk *sctp_make_abort(const struct sctp_association *asoc,
0206 const struct sctp_chunk *chunk,
0207 const size_t hint);
0208 struct sctp_chunk *sctp_make_abort_no_data(const struct sctp_association *asoc,
0209 const struct sctp_chunk *chunk,
0210 __u32 tsn);
0211 struct sctp_chunk *sctp_make_abort_user(const struct sctp_association *asoc,
0212 struct msghdr *msg, size_t msg_len);
0213 struct sctp_chunk *sctp_make_abort_violation(
0214 const struct sctp_association *asoc,
0215 const struct sctp_chunk *chunk,
0216 const __u8 *payload,
0217 const size_t paylen);
0218 struct sctp_chunk *sctp_make_violation_paramlen(
0219 const struct sctp_association *asoc,
0220 const struct sctp_chunk *chunk,
0221 struct sctp_paramhdr *param);
0222 struct sctp_chunk *sctp_make_violation_max_retrans(
0223 const struct sctp_association *asoc,
0224 const struct sctp_chunk *chunk);
0225 struct sctp_chunk *sctp_make_new_encap_port(
0226 const struct sctp_association *asoc,
0227 const struct sctp_chunk *chunk);
0228 struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
0229 const struct sctp_transport *transport,
0230 __u32 probe_size);
0231 struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc,
0232 const struct sctp_chunk *chunk,
0233 const void *payload,
0234 const size_t paylen);
0235 struct sctp_chunk *sctp_make_pad(const struct sctp_association *asoc, int len);
0236 struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,
0237 const struct sctp_chunk *chunk,
0238 __be16 cause_code, const void *payload,
0239 size_t paylen, size_t reserve_tail);
0240
0241 struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
0242 union sctp_addr *laddr,
0243 struct sockaddr *addrs,
0244 int addrcnt, __be16 flags);
0245 struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
0246 union sctp_addr *addr);
0247 bool sctp_verify_asconf(const struct sctp_association *asoc,
0248 struct sctp_chunk *chunk, bool addr_param_needed,
0249 struct sctp_paramhdr **errp);
0250 struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
0251 struct sctp_chunk *asconf);
0252 int sctp_process_asconf_ack(struct sctp_association *asoc,
0253 struct sctp_chunk *asconf_ack);
0254 struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
0255 __u32 new_cum_tsn, size_t nstreams,
0256 struct sctp_fwdtsn_skip *skiplist);
0257 struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc,
0258 __u16 key_id);
0259 struct sctp_chunk *sctp_make_strreset_req(const struct sctp_association *asoc,
0260 __u16 stream_num, __be16 *stream_list,
0261 bool out, bool in);
0262 struct sctp_chunk *sctp_make_strreset_tsnreq(
0263 const struct sctp_association *asoc);
0264 struct sctp_chunk *sctp_make_strreset_addstrm(
0265 const struct sctp_association *asoc,
0266 __u16 out, __u16 in);
0267 struct sctp_chunk *sctp_make_strreset_resp(const struct sctp_association *asoc,
0268 __u32 result, __u32 sn);
0269 struct sctp_chunk *sctp_make_strreset_tsnresp(struct sctp_association *asoc,
0270 __u32 result, __u32 sn,
0271 __u32 sender_tsn,
0272 __u32 receiver_tsn);
0273 bool sctp_verify_reconf(const struct sctp_association *asoc,
0274 struct sctp_chunk *chunk,
0275 struct sctp_paramhdr **errp);
0276 void sctp_chunk_assign_tsn(struct sctp_chunk *chunk);
0277 void sctp_chunk_assign_ssn(struct sctp_chunk *chunk);
0278
0279
0280 struct sctp_chunk *sctp_process_strreset_outreq(
0281 struct sctp_association *asoc,
0282 union sctp_params param,
0283 struct sctp_ulpevent **evp);
0284 struct sctp_chunk *sctp_process_strreset_inreq(
0285 struct sctp_association *asoc,
0286 union sctp_params param,
0287 struct sctp_ulpevent **evp);
0288 struct sctp_chunk *sctp_process_strreset_tsnreq(
0289 struct sctp_association *asoc,
0290 union sctp_params param,
0291 struct sctp_ulpevent **evp);
0292 struct sctp_chunk *sctp_process_strreset_addstrm_out(
0293 struct sctp_association *asoc,
0294 union sctp_params param,
0295 struct sctp_ulpevent **evp);
0296 struct sctp_chunk *sctp_process_strreset_addstrm_in(
0297 struct sctp_association *asoc,
0298 union sctp_params param,
0299 struct sctp_ulpevent **evp);
0300 struct sctp_chunk *sctp_process_strreset_resp(
0301 struct sctp_association *asoc,
0302 union sctp_params param,
0303 struct sctp_ulpevent **evp);
0304
0305
0306
0307 int sctp_do_sm(struct net *net, enum sctp_event_type event_type,
0308 union sctp_subtype subtype, enum sctp_state state,
0309 struct sctp_endpoint *ep, struct sctp_association *asoc,
0310 void *event_arg, gfp_t gfp);
0311
0312
0313 void sctp_generate_t3_rtx_event(struct timer_list *t);
0314 void sctp_generate_heartbeat_event(struct timer_list *t);
0315 void sctp_generate_reconf_event(struct timer_list *t);
0316 void sctp_generate_probe_event(struct timer_list *t);
0317 void sctp_generate_proto_unreach_event(struct timer_list *t);
0318
0319 void sctp_ootb_pkt_free(struct sctp_packet *packet);
0320
0321 struct sctp_association *sctp_unpack_cookie(
0322 const struct sctp_endpoint *ep,
0323 const struct sctp_association *asoc,
0324 struct sctp_chunk *chunk,
0325 gfp_t gfp, int *err,
0326 struct sctp_chunk **err_chk_p);
0327
0328
0329 __u32 sctp_generate_tag(const struct sctp_endpoint *ep);
0330 __u32 sctp_generate_tsn(const struct sctp_endpoint *ep);
0331
0332
0333 extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
0334
0335
0336
0337 static inline __u16 sctp_data_size(struct sctp_chunk *chunk)
0338 {
0339 __u16 size;
0340
0341 size = ntohs(chunk->chunk_hdr->length);
0342 size -= sctp_datachk_len(&chunk->asoc->stream);
0343
0344 return size;
0345 }
0346
0347
0348 #define TSN_lt(a,b) \
0349 (typecheck(__u32, a) && \
0350 typecheck(__u32, b) && \
0351 ((__s32)((a) - (b)) < 0))
0352
0353 #define TSN_lte(a,b) \
0354 (typecheck(__u32, a) && \
0355 typecheck(__u32, b) && \
0356 ((__s32)((a) - (b)) <= 0))
0357
0358
0359 #define MID_lt(a, b) \
0360 (typecheck(__u32, a) && \
0361 typecheck(__u32, b) && \
0362 ((__s32)((a) - (b)) < 0))
0363
0364
0365 #define SSN_lt(a,b) \
0366 (typecheck(__u16, a) && \
0367 typecheck(__u16, b) && \
0368 ((__s16)((a) - (b)) < 0))
0369
0370
0371 #define ADDIP_SERIAL_gte(a,b) \
0372 (typecheck(__u32, a) && \
0373 typecheck(__u32, b) && \
0374 ((__s32)((b) - (a)) <= 0))
0375
0376
0377 static inline int
0378 sctp_vtag_verify(const struct sctp_chunk *chunk,
0379 const struct sctp_association *asoc)
0380 {
0381
0382
0383
0384
0385
0386
0387 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
0388 return 0;
0389
0390 chunk->transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
0391 return 1;
0392 }
0393
0394
0395
0396
0397 static inline int
0398 sctp_vtag_verify_either(const struct sctp_chunk *chunk,
0399 const struct sctp_association *asoc)
0400 {
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422 if ((!sctp_test_T_bit(chunk) &&
0423 (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)) ||
0424 (sctp_test_T_bit(chunk) && asoc->c.peer_vtag &&
0425 (ntohl(chunk->sctp_hdr->vtag) == asoc->c.peer_vtag))) {
0426 return 1;
0427 }
0428
0429 return 0;
0430 }
0431
0432 #endif