49 #ifndef __net_sctp_h__
50 #define __net_sctp_h__
65 #include <linux/types.h>
66 #include <linux/slab.h>
68 #include <linux/tty.h>
74 #if IS_ENABLED(CONFIG_IPV6)
79 #include <asm/uaccess.h>
89 #ifdef CONFIG_SCTP_DBG_MSG
96 #ifdef CONFIG_IP_SCTP_MODULE
97 #define SCTP_PROTOSW_FLAG 0
99 #define SCTP_PROTOSW_FLAG INET_PROTOSW_PERMANENT
107 #define SCTP_STATIC static
170 struct sock *oldsk,
struct sock *newsk);
201 #include <test_frame.h>
205 #define sctp_spin_lock_irqsave(lock, flags) spin_lock_irqsave(lock, flags)
206 #define sctp_spin_unlock_irqrestore(lock, flags) \
207 spin_unlock_irqrestore(lock, flags)
208 #define sctp_local_bh_disable() local_bh_disable()
209 #define sctp_local_bh_enable() local_bh_enable()
210 #define sctp_spin_lock(lock) spin_lock(lock)
211 #define sctp_spin_unlock(lock) spin_unlock(lock)
212 #define sctp_write_lock(lock) write_lock(lock)
213 #define sctp_write_unlock(lock) write_unlock(lock)
214 #define sctp_read_lock(lock) read_lock(lock)
215 #define sctp_read_unlock(lock) read_unlock(lock)
218 #define sctp_lock_sock(sk) lock_sock(sk)
219 #define sctp_release_sock(sk) release_sock(sk)
220 #define sctp_bh_lock_sock(sk) bh_lock_sock(sk)
221 #define sctp_bh_unlock_sock(sk) bh_unlock_sock(sk)
224 #define SCTP_INC_STATS(net, field) SNMP_INC_STATS((net)->sctp.sctp_statistics, field)
225 #define SCTP_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->sctp.sctp_statistics, field)
226 #define SCTP_INC_STATS_USER(net, field) SNMP_INC_STATS_USER((net)->sctp.sctp_statistics, field)
227 #define SCTP_DEC_STATS(net, field) SNMP_DEC_STATS((net)->sctp.sctp_statistics, field)
270 #define SCTP_MIB_MAX __SCTP_MIB_MAX
278 extern int sctp_debug_flag;
279 #define SCTP_DEBUG_PRINTK(fmt, args...) \
281 if (sctp_debug_flag) \
282 printk(KERN_DEBUG pr_fmt(fmt), ##args); \
284 #define SCTP_DEBUG_PRINTK_CONT(fmt, args...) \
286 if (sctp_debug_flag) \
287 pr_cont(fmt, ##args); \
289 #define SCTP_DEBUG_PRINTK_IPADDR(fmt_lead, fmt_trail, \
290 args_lead, addr, args_trail...) \
292 const union sctp_addr *_addr = (addr); \
293 if (sctp_debug_flag) { \
294 if (_addr->sa.sa_family == AF_INET6) { \
296 pr_fmt(fmt_lead "%pI6" fmt_trail), \
298 &_addr->v6.sin6_addr, \
302 pr_fmt(fmt_lead "%pI4" fmt_trail), \
304 &_addr->v4.sin_addr.s_addr, \
309 #define SCTP_ENABLE_DEBUG { sctp_debug_flag = 1; }
310 #define SCTP_DISABLE_DEBUG { sctp_debug_flag = 0; }
312 #define SCTP_ASSERT(expr, str, func) \
314 SCTP_DEBUG_PRINTK("Assertion Failed: %s(%s) at %s:%s:%d\n", \
315 str, (#expr), __FILE__, __func__, __LINE__); \
321 #define SCTP_DEBUG_PRINTK(whatever...)
322 #define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
323 #define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
324 #define SCTP_ENABLE_DEBUG
325 #define SCTP_DISABLE_DEBUG
326 #define SCTP_ASSERT(expr, str, func)
334 #ifdef CONFIG_SCTP_DBG_OBJCNT
336 extern atomic_t sctp_dbg_objcnt_sock;
338 extern atomic_t sctp_dbg_objcnt_assoc;
339 extern atomic_t sctp_dbg_objcnt_transport;
340 extern atomic_t sctp_dbg_objcnt_chunk;
341 extern atomic_t sctp_dbg_objcnt_bind_addr;
342 extern atomic_t sctp_dbg_objcnt_bind_bucket;
343 extern atomic_t sctp_dbg_objcnt_addr;
344 extern atomic_t sctp_dbg_objcnt_ssnmap;
345 extern atomic_t sctp_dbg_objcnt_datamsg;
346 extern atomic_t sctp_dbg_objcnt_keys;
349 #define SCTP_DBG_OBJCNT_INC(name) \
350 atomic_inc(&sctp_dbg_objcnt_## name)
351 #define SCTP_DBG_OBJCNT_DEC(name) \
352 atomic_dec(&sctp_dbg_objcnt_## name)
353 #define SCTP_DBG_OBJCNT(name) \
354 atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0)
359 #define SCTP_DBG_OBJCNT_ENTRY(name) \
360 {.label= #name, .counter= &sctp_dbg_objcnt_## name}
367 #define SCTP_DBG_OBJCNT_INC(name)
368 #define SCTP_DBG_OBJCNT_DEC(name)
375 #if defined CONFIG_SYSCTL
388 #define SCTP_SAT_LEN(x) (sizeof(struct sctp_paramhdr) + (x) * sizeof(__u16))
390 #if IS_ENABLED(CONFIG_IPV6)
423 #define sctp_skb_for_each(pos, head, tmp) \
424 skb_queue_walk_safe(head, pos, tmp)
435 skb_queue_splice_tail_init(list, head);
453 if (list->
next != list) {
457 INIT_LIST_HEAD(result);
466 static inline void sctp_skb_set_owner_r(
struct sk_buff *
skb,
struct sock *
sk)
481 static inline int sctp_list_single_entry(
struct list_head *
head)
483 return (head->
next != head) && (head->
next == head->
prev);
489 static __u32 sctp_rand;
497 sctp_rand ^= (sctp_rand << 12);
498 sctp_rand ^= (sctp_rand >> 20);
503 ret = sctp_rand % rto - (rto >> 1);
513 frag -= sp->
pf->af->net_header_len;
536 #define sctp_walk_params(pos, chunk, member)\
537 _sctp_walk_params((pos), (chunk), ntohs((chunk)->chunk_hdr.length), member)
539 #define _sctp_walk_params(pos, chunk, end, member)\
540 for (pos.v = chunk->member;\
541 pos.v <= (void *)chunk + end - ntohs(pos.p->length) &&\
542 ntohs(pos.p->length) >= sizeof(sctp_paramhdr_t);\
543 pos.v += WORD_ROUND(ntohs(pos.p->length)))
545 #define sctp_walk_errors(err, chunk_hdr)\
546 _sctp_walk_errors((err), (chunk_hdr), ntohs((chunk_hdr)->length))
548 #define _sctp_walk_errors(err, chunk_hdr, end)\
549 for (err = (sctp_errhdr_t *)((void *)chunk_hdr + \
550 sizeof(sctp_chunkhdr_t));\
551 (void *)err <= (void *)chunk_hdr + end - ntohs(err->length) &&\
552 ntohs(err->length) >= sizeof(sctp_errhdr_t); \
553 err = (sctp_errhdr_t *)((void *)err + WORD_ROUND(ntohs(err->length))))
555 #define sctp_walk_fwdtsn(pos, chunk)\
556 _sctp_walk_fwdtsn((pos), (chunk), ntohs((chunk)->chunk_hdr->length) - sizeof(struct sctp_fwdtsn_chunk))
558 #define _sctp_walk_fwdtsn(pos, chunk, end)\
559 for (pos = chunk->subh.fwdtsn_hdr->skip;\
560 (void *)pos <= (void *)chunk->subh.fwdtsn_hdr->skip + end - sizeof(struct sctp_fwdtsn_skip);\
564 #define WORD_ROUND(s) (((s)+3)&~3)
567 #define t_new(type, flags) (type *)kzalloc(sizeof(type), flags)
570 #define tv_lt(s, t) \
571 (s.tv_sec < t.tv_sec || (s.tv_sec == t.tv_sec && s.tv_usec < t.tv_usec))
574 #define TIMEVAL_ADD(tv1, tv2) \
576 suseconds_t usecs = (tv2).tv_usec + (tv1).tv_usec; \
577 time_t secs = (tv2).tv_sec + (tv1).tv_sec; \
579 if (usecs >= 1000000) { \
583 (tv2).tv_sec = secs; \
584 (tv2).tv_usec = usecs; \
599 static inline int ipver2af(
__u8 ipver)
625 static inline int sctp_sanity_check(
void)
629 "SCTP: ulpevent does not fit in skb!\n",
return 0);
642 static inline int sctp_ep_hashfn(
struct net *net,
__u16 lport)
648 static inline int sctp_assoc_hashfn(
struct net *net,
__u16 lport,
__u16 rport)
650 int h = (lport << 16) + rport + net_hash_mix(net);
659 static inline int sctp_vtag_hashfn(
__u16 lport,
__u16 rport,
__u32 vtag)
661 int h = (lport << 16) + rport;
666 #define sctp_for_each_hentry(epb, node, head) \
667 hlist_for_each_entry(epb, node, head, node)
670 #define sctp_style(sk, style) __sctp_style((sk), (SCTP_SOCKET_##style))
673 return sctp_sk(sk)->type == style;
677 #define sctp_state(asoc, state) __sctp_state((asoc), (SCTP_STATE_##state))
685 #define sctp_sstate(sk, state) __sctp_sstate((sk), (SCTP_SS_##state))
688 return sk->sk_state ==
state;
695 addr->
v4.sin_port = addr->
v6.sin6_port;
696 addr->
v4.sin_addr.s_addr = addr->
v6.sin6_addr.s6_addr32[3];
703 addr->
v6.sin6_port = addr->
v4.sin_port;
704 addr->
v6.sin6_addr.s6_addr32[3] = addr->
v4.sin_addr.s_addr;
705 addr->
v6.sin6_addr.s6_addr32[0] = 0;
706 addr->
v6.sin6_addr.s6_addr32[1] = 0;
707 addr->
v6.sin6_addr.s6_addr32[2] =
htonl(0x0000ffff);
715 if (t->
dst && !dst_check(t->
dst, 0)) {