Commit 7160b90e authored by Jon Grimm's avatar Jon Grimm

[SCTP] Add some macros to clean up code.

sctp_state(asoc, STATE)  // Is asoc in this state?
sctp_style(sk, STYLE)    // Is sock this style?
sctp_sstate(sk, SS_STATE) // Is sock in this state?
parent 6fd8c252
...@@ -132,53 +132,53 @@ extern int sctp_register_pf(struct sctp_pf *, sa_family_t); ...@@ -132,53 +132,53 @@ extern int sctp_register_pf(struct sctp_pf *, sa_family_t);
/* /*
* sctp/socket.c * sctp/socket.c
*/ */
extern int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb); int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb);
extern int sctp_inet_listen(struct socket *sock, int backlog); int sctp_inet_listen(struct socket *sock, int backlog);
extern void sctp_write_space(struct sock *sk); void sctp_write_space(struct sock *sk);
extern unsigned int sctp_poll(struct file *file, struct socket *sock, unsigned int sctp_poll(struct file *file, struct socket *sock,
poll_table *wait); poll_table *wait);
/* /*
* sctp/primitive.c * sctp/primitive.c
*/ */
extern int sctp_primitive_ASSOCIATE(struct sctp_association *, void *arg); int sctp_primitive_ASSOCIATE(struct sctp_association *, void *arg);
extern int sctp_primitive_SHUTDOWN(struct sctp_association *, void *arg); int sctp_primitive_SHUTDOWN(struct sctp_association *, void *arg);
extern int sctp_primitive_ABORT(struct sctp_association *, void *arg); int sctp_primitive_ABORT(struct sctp_association *, void *arg);
extern int sctp_primitive_SEND(struct sctp_association *, void *arg); int sctp_primitive_SEND(struct sctp_association *, void *arg);
extern int sctp_primitive_REQUESTHEARTBEAT(struct sctp_association *, void *arg); int sctp_primitive_REQUESTHEARTBEAT(struct sctp_association *, void *arg);
/* /*
* sctp/crc32c.c * sctp/crc32c.c
*/ */
extern __u32 sctp_start_cksum(__u8 *ptr, __u16 count); __u32 sctp_start_cksum(__u8 *ptr, __u16 count);
extern __u32 sctp_update_cksum(__u8 *ptr, __u16 count, __u32 cksum); __u32 sctp_update_cksum(__u8 *ptr, __u16 count, __u32 cksum);
extern __u32 sctp_end_cksum(__u32 cksum); __u32 sctp_end_cksum(__u32 cksum);
extern __u32 sctp_update_copy_cksum(__u8 *, __u8 *, __u16 count, __u32 cksum); __u32 sctp_update_copy_cksum(__u8 *, __u8 *, __u16 count, __u32 cksum);
/* /*
* sctp/input.c * sctp/input.c
*/ */
extern int sctp_rcv(struct sk_buff *skb); int sctp_rcv(struct sk_buff *skb);
extern void sctp_v4_err(struct sk_buff *skb, u32 info); void sctp_v4_err(struct sk_buff *skb, u32 info);
extern void sctp_hash_established(struct sctp_association *); void sctp_hash_established(struct sctp_association *);
extern void __sctp_hash_established(struct sctp_association *); void __sctp_hash_established(struct sctp_association *);
extern void sctp_unhash_established(struct sctp_association *); void sctp_unhash_established(struct sctp_association *);
extern void __sctp_unhash_established(struct sctp_association *); void __sctp_unhash_established(struct sctp_association *);
extern void sctp_hash_endpoint(struct sctp_endpoint *); void sctp_hash_endpoint(struct sctp_endpoint *);
extern void __sctp_hash_endpoint(struct sctp_endpoint *); void __sctp_hash_endpoint(struct sctp_endpoint *);
extern void sctp_unhash_endpoint(struct sctp_endpoint *); void sctp_unhash_endpoint(struct sctp_endpoint *);
extern void __sctp_unhash_endpoint(struct sctp_endpoint *); void __sctp_unhash_endpoint(struct sctp_endpoint *);
extern struct sctp_association *__sctp_lookup_association( struct sctp_association *__sctp_lookup_association(
const union sctp_addr *, const union sctp_addr *,
const union sctp_addr *, const union sctp_addr *,
struct sctp_transport **); struct sctp_transport **);
extern struct sock *sctp_err_lookup(int family, struct sk_buff *, struct sock *sctp_err_lookup(int family, struct sk_buff *,
struct sctphdr *, struct sctp_endpoint **, struct sctphdr *, struct sctp_endpoint **,
struct sctp_association **, struct sctp_association **,
struct sctp_transport **); struct sctp_transport **);
extern void sctp_err_finish(struct sock *, struct sctp_endpoint *, void sctp_err_finish(struct sock *, struct sctp_endpoint *,
struct sctp_association *); struct sctp_association *);
extern void sctp_icmp_frag_needed(struct sock *, struct sctp_association *, void sctp_icmp_frag_needed(struct sock *, struct sctp_association *,
struct sctp_transport *t, __u32 pmtu); struct sctp_transport *t, __u32 pmtu);
/* /*
...@@ -293,8 +293,8 @@ atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0) ...@@ -293,8 +293,8 @@ atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0)
#define SCTP_DBG_OBJCNT_ENTRY(name) \ #define SCTP_DBG_OBJCNT_ENTRY(name) \
{.label= #name, .counter= &sctp_dbg_objcnt_## name} {.label= #name, .counter= &sctp_dbg_objcnt_## name}
extern void sctp_dbg_objcnt_init(void); void sctp_dbg_objcnt_init(void);
extern void sctp_dbg_objcnt_exit(void); void sctp_dbg_objcnt_exit(void);
#else #else
...@@ -307,8 +307,8 @@ static inline void sctp_dbg_objcnt_exit(void) { return; } ...@@ -307,8 +307,8 @@ static inline void sctp_dbg_objcnt_exit(void) { return; }
#endif /* CONFIG_SCTP_DBG_OBJCOUNT */ #endif /* CONFIG_SCTP_DBG_OBJCOUNT */
#if defined CONFIG_SYSCTL #if defined CONFIG_SYSCTL
extern void sctp_sysctl_register(void); void sctp_sysctl_register(void);
extern void sctp_sysctl_unregister(void); void sctp_sysctl_unregister(void);
#else #else
static inline void sctp_sysctl_register(void) { return; } static inline void sctp_sysctl_register(void) { return; }
static inline void sctp_sysctl_unregister(void) { return; } static inline void sctp_sysctl_unregister(void) { return; }
...@@ -319,9 +319,9 @@ static inline void sctp_sysctl_unregister(void) { return; } ...@@ -319,9 +319,9 @@ static inline void sctp_sysctl_unregister(void) { return; }
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
extern int sctp_v6_init(void); int sctp_v6_init(void);
extern void sctp_v6_exit(void); void sctp_v6_exit(void);
extern void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
int type, int code, int offset, __u32 info); int type, int code, int offset, __u32 info);
#else /* #ifdef defined(CONFIG_IPV6) */ #else /* #ifdef defined(CONFIG_IPV6) */
...@@ -349,7 +349,6 @@ static inline sctp_assoc_t sctp_assoc2id(const struct sctp_association *asoc) ...@@ -349,7 +349,6 @@ static inline sctp_assoc_t sctp_assoc2id(const struct sctp_association *asoc)
return (sctp_assoc_t) asoc; return (sctp_assoc_t) asoc;
} }
/* Look up the association by its id. */ /* Look up the association by its id. */
struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id); struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id);
...@@ -484,7 +483,7 @@ static inline void tv_add(const struct timeval *entered, struct timeval *leaved) ...@@ -484,7 +483,7 @@ static inline void tv_add(const struct timeval *entered, struct timeval *leaved)
extern struct proto sctp_prot; extern struct proto sctp_prot;
extern struct proc_dir_entry *proc_net_sctp; extern struct proc_dir_entry *proc_net_sctp;
extern void sctp_put_port(struct sock *sk); void sctp_put_port(struct sock *sk);
/* Static inline functions. */ /* Static inline functions. */
...@@ -575,4 +574,23 @@ struct sctp6_sock { ...@@ -575,4 +574,23 @@ struct sctp6_sock {
#define sctp_sk(__sk) (&((struct sctp_sock *)__sk)->sctp) #define sctp_sk(__sk) (&((struct sctp_sock *)__sk)->sctp)
#define sctp_style(sk, style) __sctp_style((sk), (SCTP_SOCKET_##style))
int static inline __sctp_style(struct sock *sk, sctp_socket_type_t style)
{
return sctp_sk(sk)->type == style;
}
#define sctp_state(asoc, state) __sctp_state((asoc), (SCTP_STATE_##state))
int static inline __sctp_state(struct sctp_association *asoc,
sctp_state_t state)
{
return asoc->state == state;
}
#define sctp_sstate(sk, state) __sctp_sstate((sk), (SCTP_SS_##state))
int static inline __sctp_sstate(struct sock *sk, sctp_sock_state_t state)
{
return sk->state == state;
}
#endif /* __net_sctp_h__ */ #endif /* __net_sctp_h__ */
...@@ -212,9 +212,8 @@ sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep, ...@@ -212,9 +212,8 @@ sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
* on the TCP-style socket exceed the max backlog, respond with an * on the TCP-style socket exceed the max backlog, respond with an
* ABORT. * ABORT.
*/ */
if ((SCTP_SS_LISTENING != sk->state) || if (!sctp_sstate(sk, LISTENING) ||
((SCTP_SOCKET_TCP == sctp_sk(sk)->type) && (sctp_style(sk, TCP) && (sk->ack_backlog >= sk->max_ack_backlog)))
(sk->ack_backlog >= sk->max_ack_backlog)))
return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
/* Verify the INIT chunk before processing it. */ /* Verify the INIT chunk before processing it. */
...@@ -1191,7 +1190,7 @@ static sctp_disposition_t sctp_sf_do_unexpected_init( ...@@ -1191,7 +1190,7 @@ static sctp_disposition_t sctp_sf_do_unexpected_init(
* since there are no peer addresses to check against. * since there are no peer addresses to check against.
* Upon return an ABORT will have been sent if needed. * Upon return an ABORT will have been sent if needed.
*/ */
if (asoc->state != SCTP_STATE_COOKIE_WAIT) { if (!sctp_state(asoc, COOKIE_WAIT)) {
if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
commands)) { commands)) {
retval = SCTP_DISPOSITION_CONSUME; retval = SCTP_DISPOSITION_CONSUME;
......
...@@ -108,7 +108,7 @@ struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id) ...@@ -108,7 +108,7 @@ struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id)
/* If this is not a UDP-style socket, assoc id should be /* If this is not a UDP-style socket, assoc id should be
* ignored. * ignored.
*/ */
if (SCTP_SOCKET_UDP != sctp_sk(sk)->type) { if (!sctp_style(sk, UDP)) {
if (!list_empty(&sctp_sk(sk)->ep->asocs)) if (!list_empty(&sctp_sk(sk)->ep->asocs))
asoc = list_entry(sctp_sk(sk)->ep->asocs.next, asoc = list_entry(sctp_sk(sk)->ep->asocs.next,
struct sctp_association, asocs); struct sctp_association, asocs);
...@@ -693,8 +693,7 @@ SCTP_STATIC void sctp_close(struct sock *sk, long timeout) ...@@ -693,8 +693,7 @@ SCTP_STATIC void sctp_close(struct sock *sk, long timeout)
* belongs to a TCP-style listening socket that is not * belongs to a TCP-style listening socket that is not
* yet accepted. * yet accepted.
*/ */
if ((SCTP_SOCKET_TCP == sctp_sk(sk)->type) && if (sctp_style(sk, TCP) && sctp_state(asoc, CLOSED)) {
(SCTP_STATE_CLOSED == asoc->state)) {
sctp_unhash_established(asoc); sctp_unhash_established(asoc);
sctp_association_free(asoc); sctp_association_free(asoc);
} else } else
...@@ -795,8 +794,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, ...@@ -795,8 +794,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
SCTP_DEBUG_PRINTK("Using endpoint: %s.\n", ep->debug_name); SCTP_DEBUG_PRINTK("Using endpoint: %s.\n", ep->debug_name);
if ((SCTP_SOCKET_TCP == sp->type) && if (sctp_style(sk, TCP) && (SCTP_SS_ESTABLISHED != sk->state)) {
(SCTP_SS_ESTABLISHED != sk->state)) {
err = -EPIPE; err = -EPIPE;
goto out_nounlock; goto out_nounlock;
} }
...@@ -814,7 +812,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, ...@@ -814,7 +812,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
* the address we will send to. * the address we will send to.
* For a peeled-off socket, msg_name is ignored. * For a peeled-off socket, msg_name is ignored.
*/ */
if ((SCTP_SOCKET_UDP_HIGH_BANDWIDTH != sp->type) && msg->msg_name) { if (!sctp_style(sk, UDP_HIGH_BANDWIDTH) && msg->msg_name) {
int msg_namelen = msg->msg_namelen; int msg_namelen = msg->msg_namelen;
err = sctp_verify_addr(sk, (union sctp_addr *)msg->msg_name, err = sctp_verify_addr(sk, (union sctp_addr *)msg->msg_name,
...@@ -901,8 +899,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, ...@@ -901,8 +899,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
* happen when an accepted socket has an association that is * happen when an accepted socket has an association that is
* already CLOSED. * already CLOSED.
*/ */
if ((SCTP_STATE_CLOSED == asoc->state) && if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP)) {
(SCTP_SOCKET_TCP == sp->type)) {
err = -EPIPE; err = -EPIPE;
goto out_unlock; goto out_unlock;
} }
...@@ -1196,8 +1193,7 @@ SCTP_STATIC int sctp_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -1196,8 +1193,7 @@ SCTP_STATIC int sctp_recvmsg(struct kiocb *iocb, struct sock *sk,
sctp_lock_sock(sk); sctp_lock_sock(sk);
if ((SCTP_SOCKET_TCP == sp->type) && if (sctp_style(sk, TCP) && (SCTP_SS_ESTABLISHED != sk->state)) {
(SCTP_SS_ESTABLISHED != sk->state)) {
err = -ENOTCONN; err = -ENOTCONN;
goto out; goto out;
} }
...@@ -1304,7 +1300,7 @@ static int sctp_setsockopt_autoclose(struct sock *sk, char *optval, ...@@ -1304,7 +1300,7 @@ static int sctp_setsockopt_autoclose(struct sock *sk, char *optval,
struct sctp_opt *sp = sctp_sk(sk); struct sctp_opt *sp = sctp_sk(sk);
/* Applicable to UDP-style socket only */ /* Applicable to UDP-style socket only */
if (SCTP_SOCKET_TCP == sp->type) if (sctp_style(sk, TCP))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (optlen != sizeof(int)) if (optlen != sizeof(int))
return -EINVAL; return -EINVAL;
...@@ -1635,9 +1631,8 @@ SCTP_STATIC int sctp_connect(struct sock *sk, struct sockaddr *uaddr, ...@@ -1635,9 +1631,8 @@ SCTP_STATIC int sctp_connect(struct sock *sk, struct sockaddr *uaddr,
* is already connected. * is already connected.
* It cannot be done even on a TCP-style listening socket. * It cannot be done even on a TCP-style listening socket.
*/ */
if ((SCTP_SS_ESTABLISHED == sk->state) || if (sctp_sstate(sk, ESTABLISHED) ||
((SCTP_SOCKET_TCP == sp->type) && (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))) {
(SCTP_SS_LISTENING == sk->state))) {
err = -EISCONN; err = -EISCONN;
goto out_unlock; goto out_unlock;
} }
...@@ -1746,12 +1741,12 @@ SCTP_STATIC struct sock *sctp_accept(struct sock *sk, int flags, int *err) ...@@ -1746,12 +1741,12 @@ SCTP_STATIC struct sock *sctp_accept(struct sock *sk, int flags, int *err)
sp = sctp_sk(sk); sp = sctp_sk(sk);
ep = sp->ep; ep = sp->ep;
if (SCTP_SOCKET_TCP != sp->type) { if (!sctp_style(sk, TCP)) {
error = -EOPNOTSUPP; error = -EOPNOTSUPP;
goto out; goto out;
} }
if (SCTP_SS_LISTENING != sk->state) { if (!sctp_sstate(sk, LISTENING)) {
error = -EINVAL; error = -EINVAL;
goto out; goto out;
} }
...@@ -1847,7 +1842,7 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk) ...@@ -1847,7 +1842,7 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
* enable the events needed. By default, UDP-style * enable the events needed. By default, UDP-style
* sockets enable io and association change notifications. * sockets enable io and association change notifications.
*/ */
if (SCTP_SOCKET_UDP == sp->type) { if (sctp_style(sk, UDP)) {
sp->subscribe.sctp_data_io_event = 1; sp->subscribe.sctp_data_io_event = 1;
sp->subscribe.sctp_association_event = 1; sp->subscribe.sctp_association_event = 1;
} }
...@@ -1928,7 +1923,7 @@ SCTP_STATIC void sctp_shutdown(struct sock *sk, int how) ...@@ -1928,7 +1923,7 @@ SCTP_STATIC void sctp_shutdown(struct sock *sk, int how)
struct sctp_endpoint *ep; struct sctp_endpoint *ep;
struct sctp_association *asoc; struct sctp_association *asoc;
if (SCTP_SOCKET_TCP != sctp_sk(sk)->type) if (!sctp_style(sk, TCP))
return; return;
if (how & SEND_SHUTDOWN) { if (how & SEND_SHUTDOWN) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment